From 4582e6afefa4e2ebe9e036df3fd6e9b93cf8d3bc Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 1 Jun 2017 12:19:13 +0300 Subject: [PATCH] fix build timestamp --- org.fox.ttrss/build.gradle | 1 + .../org/fox/ttrss/PreferencesFragment.java | 25 ++++++------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/org.fox.ttrss/build.gradle b/org.fox.ttrss/build.gradle index 2354165f..d0ef2199 100755 --- a/org.fox.ttrss/build.gradle +++ b/org.fox.ttrss/build.gradle @@ -6,6 +6,7 @@ android { defaultConfig { applicationId "org.fox.ttrss" + buildConfigField "long", "TIMESTAMP", System.currentTimeMillis() + "L" minSdkVersion 16 targetSdkVersion 23 // we're not targeting SDK 25 because of this: https://issuetracker.google.com/issues/37103380#makechanges } diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/PreferencesFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/PreferencesFragment.java index 046ee6f0..3f10b83b 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/PreferencesFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/PreferencesFragment.java @@ -9,6 +9,7 @@ import android.preference.PreferenceFragment; import java.io.IOException; import java.text.SimpleDateFormat; +import java.util.Date; import java.util.Locale; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -27,11 +28,11 @@ public class PreferencesFragment extends PreferenceFragment { public void onResume() { super.onResume(); - String version = "?"; - int versionCode = -1; - String buildTimestamp = "N/A"; - try { + String version; + int versionCode; + String buildTimestamp; + Activity activity = getActivity(); PackageInfo packageInfo = activity.getPackageManager(). @@ -40,24 +41,14 @@ public class PreferencesFragment extends PreferenceFragment { version = packageInfo.versionName; versionCode = packageInfo.versionCode; - ApplicationInfo appInfo = activity.getPackageManager(). - getApplicationInfo(activity.getPackageName(), 0); - - ZipFile zf = new ZipFile(appInfo.sourceDir); - ZipEntry ze = zf.getEntry("classes.dex"); - long time = ze.getTime(); - - buildTimestamp = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss", - Locale.getDefault()).format(time); - - findPreference("version").setSummary(getString(R.string.prefs_version, version, versionCode)); + + buildTimestamp = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(new Date(BuildConfig.TIMESTAMP)); + findPreference("build_timestamp").setSummary(getString(R.string.prefs_build_timestamp, buildTimestamp)); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); } }