From 722c9092856424c883eaa6aad04405ae43bc37ed Mon Sep 17 00:00:00 2001 From: Rey Koxha Date: Sun, 27 May 2018 18:47:23 +0200 Subject: [PATCH] Update for Android Developer Studio 3 --- app/build.gradle | 69 ++++++++++--------- .../webview/nodebb/activity/MainActivity.java | 4 +- .../nodebb/utility/DownloadUtility.java | 46 ++++--------- .../webview/nodebb/utility/MediaUtility.java | 8 +-- .../webview/nodebb/utility/NetworkInf.java | 3 + .../nodebb/utility/NetworkManager.java | 3 + build.gradle | 6 +- gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 9 files changed, 68 insertions(+), 75 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7a4beb7..e04391a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,39 +5,56 @@ // gradle wrapper Create Gradle Wrapper +buildscript { + repositories { + maven { url 'https://plugins.gradle.org/m2/'} + } + dependencies { + classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.10.1, 0.99.99]' + classpath 'com.google.gms:google-services:3.2.0' + } +} +apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin' + +repositories { + maven { url 'https://maven.google.com' } +} + final VERSION_MAJOR = 3 // Max 2 digits final VERSION_MINOR = 0 // Max 2 digits final VERSION_PATCH = 0 // Max 2 digits final VERSION_BUILD = 0 // Max 3 digits - apply plugin: 'com.android.application' - dependencies { - compile 'com.android.support:support-v4:25.1.1' - compile 'com.android.support:appcompat-v7:25.1.1' - compile "com.google.android.gms:play-services-base:10.2.0" - compile "com.google.android.gms:play-services-analytics:10.2.0" - compile "com.google.android.gms:play-services-ads:10.2.0" - compile "com.google.android.gms:play-services-gcm:10.2.0" - compile "com.google.android.gms:play-services-location:10.2.0" - compile 'com.onesignal:OneSignal:3.+@aar' - compile 'commons-io:commons-io:2.4' + implementation 'com.android.support:support-v4:27.1.1' + implementation 'com.android.support:appcompat-v7:27.1.1' + implementation "com.google.android.gms:play-services-base:15.0.1" + implementation "com.google.android.gms:play-services-analytics:16.0.0" + implementation "com.google.android.gms:play-services-ads:15.0.1" + implementation "com.google.android.gms:play-services-gcm:15.0.1" + implementation "com.google.android.gms:play-services-location:15.0.1" + implementation 'com.google.firebase:firebase-core:16.0.0' + implementation 'com.google.firebase:firebase-messaging:17.0.0' + implementation 'com.google.firebase:firebase-auth:16.0.1' + implementation 'com.google.firebase:firebase-database:16.0.1' + implementation 'com.onesignal:OneSignal:[3.9.1, 3.99.99]' + implementation 'commons-io:commons-io:2.6' } android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 27 + buildToolsVersion '27.0.3' defaultConfig { multiDexEnabled true minSdkVersion 19 - targetSdkVersion 25 + targetSdkVersion 27 versionCode VERSION_MAJOR*10000000 + VERSION_MINOR*100000 + VERSION_PATCH*1000 + VERSION_BUILD versionName "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" @@ -80,25 +97,11 @@ android } } - applicationVariants.all - { - variant -> - if(variant.buildType.name.equals("release")) - { - variant.outputs.each - { - output -> - def outputFile = output.outputFile - def date = new Date() - if(outputFile!=null && outputFile.name.endsWith('.apk')) - { - def fileName = outputFile.name.replace( - "app", - "WebApp-" + defaultConfig.versionName + "-" + defaultConfig.versionCode) - output.outputFile = new File((String) outputFile.parent, (String) fileName) - } - } - } + applicationVariants.all { variant -> + variant.outputs.all { output -> + def newApkName = applicationId + "-" + variant.versionName + "(" + variant.versionCode + ")" + ".apk"; + outputFileName = new File(variant.name, newApkName); + } } } diff --git a/app/src/main/java/com/webview/nodebb/activity/MainActivity.java b/app/src/main/java/com/webview/nodebb/activity/MainActivity.java index 32546d2..1f071ff 100644 --- a/app/src/main/java/com/webview/nodebb/activity/MainActivity.java +++ b/app/src/main/java/com/webview/nodebb/activity/MainActivity.java @@ -10,7 +10,7 @@ import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.widget.Toolbar; import android.view.Menu; @@ -27,7 +27,7 @@ import com.webview.nodebb.fragment.MainFragment; -public class MainActivity extends ActionBarActivity { +public class MainActivity extends AppCompatActivity { private DrawerLayout mDrawerLayout; private ActionBarDrawerToggle mDrawerToggle; private ListView mDrawerListView; diff --git a/app/src/main/java/com/webview/nodebb/utility/DownloadUtility.java b/app/src/main/java/com/webview/nodebb/utility/DownloadUtility.java index 72ce4a2..8380192 100644 --- a/app/src/main/java/com/webview/nodebb/utility/DownloadUtility.java +++ b/app/src/main/java/com/webview/nodebb/utility/DownloadUtility.java @@ -13,38 +13,20 @@ public class DownloadUtility { public static void downloadFile(Context context, String url, String fileName) { - if(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.HONEYCOMB_MR2) - { - DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); - - // Download Directory - request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName); - - // Media Scanner - request.allowScanningByMediaScanner(); - - // Download completed - request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); - - // Start download - DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); - manager.enqueue(request); - } - else - { - try - { - if(url!=null) - { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - context.startActivity(intent); - } - } - catch(android.content.ActivityNotFoundException e) - { - // FAILURE - } - } + DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); + + // Download Directory + request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName); + + // Media Scanner + request.allowScanningByMediaScanner(); + + // Download completed + request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); + + // Start download + DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); + manager.enqueue(request); } diff --git a/app/src/main/java/com/webview/nodebb/utility/MediaUtility.java b/app/src/main/java/com/webview/nodebb/utility/MediaUtility.java index 339a6bb..39ddbcc 100644 --- a/app/src/main/java/com/webview/nodebb/utility/MediaUtility.java +++ b/app/src/main/java/com/webview/nodebb/utility/MediaUtility.java @@ -90,7 +90,7 @@ else if ("file".equalsIgnoreCase(uri.getScheme())) { * @param selectionArgs (Optional) Selection arguments used in the query. * @return The value of the _data column, which is typically a file path. */ - public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { + private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_data"; final String[] projection = {column}; @@ -112,7 +112,7 @@ public static String getDataColumn(Context context, Uri uri, String selection, S * @param uri The Uri to check. * @return Whether the Uri authority is ExternalStorageProvider. */ - public static boolean isExternalStorageDocument(Uri uri) { + private static boolean isExternalStorageDocument(Uri uri) { return "com.android.externalstorage.documents".equals(uri.getAuthority()); } @@ -121,7 +121,7 @@ public static boolean isExternalStorageDocument(Uri uri) { * @param uri The Uri to check. * @return Whether the Uri authority is DownloadsProvider. */ - public static boolean isDownloadsDocument(Uri uri) { + private static boolean isDownloadsDocument(Uri uri) { return "com.android.providers.downloads.documents".equals(uri.getAuthority()); } @@ -130,7 +130,7 @@ public static boolean isDownloadsDocument(Uri uri) { * @param uri The Uri to check. * @return Whether the Uri authority is MediaProvider. */ - public static boolean isMediaDocument(Uri uri) { + private static boolean isMediaDocument(Uri uri) { return "com.android.providers.media.documents".equals(uri.getAuthority()); } } diff --git a/app/src/main/java/com/webview/nodebb/utility/NetworkInf.java b/app/src/main/java/com/webview/nodebb/utility/NetworkInf.java index 8ea0578..93f4237 100644 --- a/app/src/main/java/com/webview/nodebb/utility/NetworkInf.java +++ b/app/src/main/java/com/webview/nodebb/utility/NetworkInf.java @@ -9,6 +9,7 @@ public class NetworkInf { // Checks if online public static boolean isOnline(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + assert connectivityManager != null; NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); return (networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected()); } @@ -16,6 +17,7 @@ public static boolean isOnline(Context context) { // WiFi or Data public static int getType(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + assert connectivityManager != null; NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null) { @@ -28,6 +30,7 @@ public static int getType(Context context) { // Returns human readable name public static String getTypeName(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + assert connectivityManager != null; NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null) { diff --git a/app/src/main/java/com/webview/nodebb/utility/NetworkManager.java b/app/src/main/java/com/webview/nodebb/utility/NetworkManager.java index ef174fb..afe05c7 100644 --- a/app/src/main/java/com/webview/nodebb/utility/NetworkManager.java +++ b/app/src/main/java/com/webview/nodebb/utility/NetworkManager.java @@ -9,6 +9,7 @@ public class NetworkManager { public static boolean isOnline(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + assert connectivityManager != null; NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); return (networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected()); } @@ -16,6 +17,7 @@ public static boolean isOnline(Context context) { public static int getType(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + assert connectivityManager != null; NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null) { @@ -29,6 +31,7 @@ public static int getType(Context context) { public static String getTypeName(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + assert connectivityManager != null; NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null) { diff --git a/build.gradle b/build.gradle index d039e1d..f5cf62c 100644 --- a/build.gradle +++ b/build.gradle @@ -3,18 +3,20 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.android.tools.build:gradle:3.1.2' } } allprojects { repositories { jcenter() + google() } } task wrapper(type: Wrapper) { - gradleVersion = '3.5' + gradleVersion = '4.7' } diff --git a/gradle.properties b/gradle.properties index 8fe1bcf..ba8fd79 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,4 +19,4 @@ keystore.file=extras/keystore/WebApp.keystore keystore.properties=extras/keystore/WebApp.properties -org.gradle.java.home=C:/Program Files/Java/jdk1.8.0_121 +org.gradle.java.home=C:/Program Files/Java/jdk1.8.0_172 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0bd37e0..5afe476 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://downloads.gradle.org/distributions/gradle-4.7-all.zip