fix build timestamp

This commit is contained in:
Andrew Dolgov 2017-06-01 12:19:13 +03:00
parent ab20010954
commit 4582e6afef
2 changed files with 9 additions and 17 deletions

View File

@ -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
}

View File

@ -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();
}
}