From 28dac50d84058050f7800203a5e8b36f5b211eb0 Mon Sep 17 00:00:00 2001 From: Gregor Santner Date: Sat, 18 Nov 2017 20:04:59 +0100 Subject: [PATCH] Update and improve buildscript --- app/build.gradle | 61 +++++++++++-------- .../gsantner/opoc/ui/LanguagePreference.java | 5 +- .../net/gsantner/opoc/util/ActivityUtils.java | 24 ++++++++ .../net/gsantner/opoc/util/ContextUtils.java | 14 ----- build.gradle | 32 ++++++++-- 5 files changed, 90 insertions(+), 46 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 3a80e281..c40e8a58 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,28 +1,20 @@ apply plugin: 'com.android.application' - -ext { - version_sdk = [ - compileSdk: 27, - minSdk : 17, - ] - version_lib = [ - appcompat : "27.0.0", - butterknife: "8.8.1", - netcipher : "2.0.0-alpha1", - ] +if (enable_plugin_kotlin) { + apply plugin: 'kotlin-android' + apply plugin: 'kotlin-android-extensions' + apply plugin: 'kotlin-kapt' } - android { - compileSdkVersion version_sdk.compileSdk + compileSdkVersion version_setup_compileSdk flavorDimensions "default" defaultConfig { - minSdkVersion version_sdk.minSdk - targetSdkVersion version_sdk.compileSdk + minSdkVersion version_setup_minSdk + targetSdkVersion version_setup_targetSdk buildConfigField "boolean", "IS_TEST_BUILD", "false" buildConfigField "boolean", "IS_GPLAY_BUILD", "false" - buildConfigField("String[]", "APPLICATION_LANGUAGES", '{' + getUsedAndroidLanguages().collect {"\"${it}\""}.join(",") + '}') + buildConfigField "String[]", "APPLICATION_LANGUAGES", "${getUsedAndroidLanguages()}" buildConfigField "String", "GITHASH", "\"${getGitHash()}\"" applicationId "com.github.dfa.diaspora_android" @@ -47,12 +39,18 @@ android { } } + sourceSets { + if (enable_plugin_kotlin) { + main.java.srcDirs += 'src/main/kotlin' + } + } + productFlavors { flavorDefault { } /* -flavorGplay { + flavorGplay { buildConfigField "boolean", "IS_GPLAY_BUILD", "true" }*/ flavorTest { @@ -78,19 +76,30 @@ dependencies { testImplementation 'junit:junit:4.12' // Android standard libs - implementation "com.android.support:appcompat-v7:${version_lib.appcompat}" - implementation "com.android.support:design:${version_lib.appcompat}" - implementation "com.android.support:support-v4:${version_lib.appcompat}" - implementation "com.android.support:customtabs:${version_lib.appcompat}" - implementation "com.android.support:cardview-v7:${version_lib.appcompat}" + implementation "com.android.support:appcompat-v7:${version_library_appcompat}" + implementation "com.android.support:design:${version_library_appcompat}" + implementation "com.android.support:support-v4:${version_library_appcompat}" + implementation "com.android.support:customtabs:${version_library_appcompat}" + implementation "com.android.support:cardview-v7:${version_library_appcompat}" // UI libraries implementation "com.github.DASAR:ShiftColorPicker:v0.5" // Tool libraries - implementation "com.jakewharton:butterknife:${version_lib.butterknife}" - implementation "info.guardianproject.netcipher:netcipher:${version_lib.netcipher}" - implementation "info.guardianproject.netcipher:netcipher-webkit:${version_lib.netcipher}" + implementation "info.guardianproject.netcipher:netcipher:${version_library_netcipher}" + implementation "info.guardianproject.netcipher:netcipher-webkit:${version_library_netcipher}" + implementation "com.jakewharton:butterknife:${version_library_butterknife}" + if (enable_plugin_kotlin) { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$version_plugin_kotlin" + } - annotationProcessor "com.jakewharton:butterknife-compiler:${version_lib.butterknife}" + // Processors + def anpros = ["com.jakewharton:butterknife-compiler:${version_library_butterknife}"] + for (anpro in anpros) { + if (enable_plugin_kotlin) { + kapt anpro + } else { + annotationProcessor anpro + } + } } diff --git a/app/src/main/java/net/gsantner/opoc/ui/LanguagePreference.java b/app/src/main/java/net/gsantner/opoc/ui/LanguagePreference.java index 6898c4a2..4bda3ba1 100644 --- a/app/src/main/java/net/gsantner/opoc/ui/LanguagePreference.java +++ b/app/src/main/java/net/gsantner/opoc/ui/LanguagePreference.java @@ -51,6 +51,7 @@ import android.content.Context; import android.os.Build; import android.preference.ListPreference; import android.support.annotation.Nullable; +import android.text.TextUtils; import android.util.AttributeSet; import net.gsantner.opoc.util.ContextUtils; @@ -155,7 +156,9 @@ public class LanguagePreference extends ListPreference { @Override public CharSequence getSummary() { Locale locale = new ContextUtils(getContext()).getLocaleByAndroidCode(getValue()); - return super.getSummary() + "\n\n" + summarizeLocale(locale); + String prefix = TextUtils.isEmpty(super.getSummary()) + ? "" : super.getSummary() + "\n\n"; + return prefix + summarizeLocale(locale); } public String getSystemLanguageName() { diff --git a/app/src/main/java/net/gsantner/opoc/util/ActivityUtils.java b/app/src/main/java/net/gsantner/opoc/util/ActivityUtils.java index e25c9bf2..033e53e4 100644 --- a/app/src/main/java/net/gsantner/opoc/util/ActivityUtils.java +++ b/app/src/main/java/net/gsantner/opoc/util/ActivityUtils.java @@ -12,8 +12,11 @@ package net.gsantner.opoc.util; import android.app.Activity; +import android.content.ActivityNotFoundException; import android.content.DialogInterface; import android.content.Intent; +import android.net.Uri; +import android.os.Build; import android.support.annotation.StringRes; import android.support.design.widget.Snackbar; import android.support.v7.app.AlertDialog; @@ -96,6 +99,13 @@ public class ActivityUtils extends net.gsantner.opoc.util.ContextUtils { } } + public void showSoftKeyboard() { + InputMethodManager inputMethodManager = (InputMethodManager) _activity.getSystemService(Activity.INPUT_METHOD_SERVICE); + if (_activity.getCurrentFocus() != null && _activity.getCurrentFocus().getWindowToken() != null) { + inputMethodManager.showSoftInput(_activity.getCurrentFocus(), InputMethodManager.SHOW_FORCED); + } + } + public void showDialogWithHtmlTextView(@StringRes int resTitleId, String html) { showDialogWithHtmlTextView(resTitleId, html, true, null); } @@ -129,4 +139,18 @@ public class ActivityUtils extends net.gsantner.opoc.util.ContextUtils { } _activity.getWindow().setAttributes(attrs); } + + public void showRateOnGplayDialog() { + String pkgId = "details?id=" + _activity.getPackageName(); + Intent goToMarket = new Intent(Intent.ACTION_VIEW, Uri.parse("market://" + pkgId)); + goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | + (Build.VERSION.SDK_INT >= 21 ? Intent.FLAG_ACTIVITY_NEW_DOCUMENT : Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) | + Intent.FLAG_ACTIVITY_MULTIPLE_TASK); + try { + _activity.startActivity(goToMarket); + } catch (ActivityNotFoundException e) { + _activity.startActivity(new Intent(Intent.ACTION_VIEW, + Uri.parse("http://play.google.com/store/apps/" + pkgId))); + } + } } diff --git a/app/src/main/java/net/gsantner/opoc/util/ContextUtils.java b/app/src/main/java/net/gsantner/opoc/util/ContextUtils.java index 2e02b16b..d5102d85 100644 --- a/app/src/main/java/net/gsantner/opoc/util/ContextUtils.java +++ b/app/src/main/java/net/gsantner/opoc/util/ContextUtils.java @@ -543,18 +543,4 @@ public class ContextUtils { } return this; } - - public void showRateOnGplayDialog() { - String pkgId = "details?id=" + _context.getPackageName(); - Intent goToMarket = new Intent(Intent.ACTION_VIEW, Uri.parse("market://" + pkgId)); - goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | - (Build.VERSION.SDK_INT >= 21 ? Intent.FLAG_ACTIVITY_NEW_DOCUMENT : Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) | - Intent.FLAG_ACTIVITY_MULTIPLE_TASK); - try { - _context.startActivity(goToMarket); - } catch (ActivityNotFoundException e) { - _context.startActivity(new Intent(Intent.ACTION_VIEW, - Uri.parse("http://play.google.com/store/apps/" + pkgId))); - } - } } diff --git a/build.gradle b/build.gradle index 3d47db6c..d549a863 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,23 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.version_setup_compileSdk = 27 + ext.version_setup_minSdk = 17 + ext.version_setup_targetSdk = ext.version_setup_compileSdk + ext.version_setup_buildTools = "27.0.1" // Specifying optional + + // https://developer.android.com/topic/libraries/support-library/revisions.html + ext.version_library_appcompat = "27.0.1" + // https://github.com/JakeWharton/butterknife/releases + ext.version_library_butterknife = "8.8.1" + // https://github.com/atlassian/commonmark-java/releases + ext.version_library_commonmark = "0.10.0" + // https://github.com/guardianproject/NetCipher/releases + ext.version_library_netcipher = "2.0.0-alpha1" + // https://github.com/JetBrains/kotlin/blob/master/ReadMe.md + ext.version_plugin_kotlin = "1.1.60" + ext.enable_plugin_kotlin = false + repositories { jcenter() google() @@ -8,6 +25,9 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.0.0' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' + if (project.enable_plugin_kotlin) { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$version_plugin_kotlin" + } // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -27,15 +47,17 @@ task clean(type: Delete) { delete rootProject.buildDir } -final String[] ROOT_TO_RAW_COPYFILES = ["README.md", "LICENSE.md", "CHANGELOG.md", "CONTRIBUTORS.md"] +final String[] ROOT_TO_RAW_COPYFILES = ["README.md", "CHANGELOG.md", "CONTRIBUTORS.md","LICENSE.txt","LICENSE.md","LICENSE"] task copyRepoFiles(type: Copy) { from rootProject.files(ROOT_TO_RAW_COPYFILES) into "app/src/main/res/raw" - rename { String fileName -> fileName.replace(fileName, fileName.toLowerCase()) } -} ; tasks.copyRepoFiles.execute() + rename { String fileName -> fileName.replace(fileName, fileName.toLowerCase()) } +}; tasks.copyRepoFiles.execute() + @SuppressWarnings(["UnnecessaryQualifiedReference", "SpellCheckingInspection", "GroovyUnusedDeclaration"]) -static String[] getUsedAndroidLanguages() { +// Returns used android languages as a buildConfig array: {'de', 'it', ..}" +static String getUsedAndroidLanguages() { Set langs = new HashSet<>() new File('.').eachFileRecurse(groovy.io.FileType.DIRECTORIES) { final foldername = it.name @@ -47,7 +69,7 @@ static String[] getUsedAndroidLanguages() { } } } - return langs.toArray(new String[langs.size()]) + return '{' + langs.collect { "\"${it}\"" }.join(",") + '}' } ext.getGitHash = { ->