From 9c0abdeb814cfc3893d98b91a4fecfe27ba3662e Mon Sep 17 00:00:00 2001 From: inorichi Date: Sat, 12 Dec 2015 02:08:47 +0100 Subject: [PATCH] Show version (commit count) and build time in the 'about' section --- app/build.gradle | 26 +++++++++ .../ui/setting/SettingsAboutFragment.java | 57 +++++++++++++++++++ .../ui/setting/SettingsActivity.java | 10 +++- app/src/main/res/values/keys.xml | 4 ++ app/src/main/res/values/strings.xml | 5 ++ app/src/main/res/xml/pref_about.xml | 20 +++++++ app/src/main/res/xml/pref_main.xml | 9 ++- 7 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsAboutFragment.java create mode 100644 app/src/main/res/xml/pref_about.xml diff --git a/app/build.gradle b/app/build.gradle index 6320b231e9..85bbaa86ba 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,3 +1,5 @@ +import java.text.SimpleDateFormat + apply plugin: 'android-sdk-manager' apply plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt' @@ -7,6 +9,26 @@ retrolambda { jvmArgs '-noverify' } +ext { + // Git is needed in your system PATH for these commands to work. + // If it's not installed, you can return a random value as a workaround + getCommitCount = { + return "git rev-list --count master".execute().text.trim() + // return "1" + } + + getGitSha = { + return 'git rev-parse --short HEAD'.execute().text.trim() + // return "1" + } + + getBuildTime = { + def df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'") + df.setTimeZone(TimeZone.getTimeZone("UTC")) + return df.format(new Date()) + } +} + android { compileSdkVersion 23 buildToolsVersion "23.0.2" @@ -19,6 +41,10 @@ android { testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" versionCode 1 versionName "1.0" + + buildConfigField "String", "COMMIT_COUNT", "\"${getCommitCount()}\"" + buildConfigField "String", "COMMIT_SHA", "\"${getGitSha()}\"" + buildConfigField "String", "BUILD_TIME", "\"${getBuildTime()}\"" } compileOptions { diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsAboutFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsAboutFragment.java new file mode 100644 index 0000000000..0bb2f6369d --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsAboutFragment.java @@ -0,0 +1,57 @@ +package eu.kanade.mangafeed.ui.setting; + +import android.os.Bundle; +import android.preference.Preference; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; + +import eu.kanade.mangafeed.BuildConfig; +import eu.kanade.mangafeed.R; + +public class SettingsAboutFragment extends SettingsNestedFragment { + + public static SettingsNestedFragment newInstance(int resourcePreference, int resourceTitle) { + SettingsNestedFragment fragment = new SettingsAboutFragment(); + fragment.setArgs(resourcePreference, resourceTitle); + return fragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { + + Preference version = findPreference(getString(R.string.pref_version)); + Preference buildTime = findPreference(getString(R.string.pref_build_time)); + + version.setSummary(BuildConfig.DEBUG ? "r" + BuildConfig.COMMIT_COUNT : + BuildConfig.VERSION_NAME); + + buildTime.setSummary(getFormattedBuildTime()); + + return super.onCreateView(inflater, container, savedState); + } + + private String getFormattedBuildTime() { + try { + DateFormat inputDf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); + inputDf.setTimeZone(TimeZone.getTimeZone("UTC")); + Date date = inputDf.parse(BuildConfig.BUILD_TIME); + + DateFormat outputDf = DateFormat.getDateTimeInstance( + DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault()); + outputDf.setTimeZone(TimeZone.getDefault()); + + return outputDf.format(date); + } catch (ParseException e) { + // Do nothing + } + return ""; + } +} diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsActivity.java index e97381c816..a2b5910744 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsActivity.java @@ -50,19 +50,23 @@ public class SettingsActivity extends BaseActivity { registerSubpreference(R.string.pref_category_reader_key, SettingsNestedFragment.newInstance( - R.xml.pref_reader, R.string.pref_category_reader)); + R.xml.pref_reader, R.string.pref_category_reader)); registerSubpreference(R.string.pref_category_downloads_key, SettingsDownloadsFragment.newInstance( - R.xml.pref_downloads, R.string.pref_category_downloads)); + R.xml.pref_downloads, R.string.pref_category_downloads)); registerSubpreference(R.string.pref_category_accounts_key, SettingsAccountsFragment.newInstance( - R.xml.pref_accounts, R.string.pref_category_accounts)); + R.xml.pref_accounts, R.string.pref_category_accounts)); registerSubpreference(R.string.pref_category_cache_key, SettingsCacheFragment.newInstance( R.xml.pref_cache, R.string.pref_category_cache)); + + registerSubpreference(R.string.pref_category_about_key, + SettingsAboutFragment.newInstance( + R.xml.pref_about, R.string.pref_category_about)); } @Override diff --git a/app/src/main/res/values/keys.xml b/app/src/main/res/values/keys.xml index 476821e346..d57249ab30 100644 --- a/app/src/main/res/values/keys.xml +++ b/app/src/main/res/values/keys.xml @@ -4,6 +4,7 @@ pref_category_accounts_key pref_category_downloads_key pref_category_cache_key + pref_category_about_key pref_default_viewer_key pref_hide_status_bar_key @@ -19,4 +20,7 @@ pref_chapter_cache_size_key pref_clear_chapter_cache_key + + pref_version + pref_build_time \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a923b15480..0114985235 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -39,6 +39,7 @@ Accounts Downloads Cache + About Hide status bar @@ -64,6 +65,10 @@ Cache cleared. %1$d files have been deleted An error occurred clearing cache + + Version + Build time + Send crash reports Help fixing bugs. Sensitive data is not sent diff --git a/app/src/main/res/xml/pref_about.xml b/app/src/main/res/xml/pref_about.xml new file mode 100644 index 0000000000..baa2030856 --- /dev/null +++ b/app/src/main/res/xml/pref_about.xml @@ -0,0 +1,20 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_main.xml b/app/src/main/res/xml/pref_main.xml index 0709cdd556..71245cb60f 100644 --- a/app/src/main/res/xml/pref_main.xml +++ b/app/src/main/res/xml/pref_main.xml @@ -21,10 +21,9 @@ android:persistent="false" android:title="@string/pref_category_cache" /> - + \ No newline at end of file