From 155cbf686d59cd0172debc000c6883741b8e84a5 Mon Sep 17 00:00:00 2001 From: Nicholas Thomson Date: Thu, 11 Jun 2015 14:42:32 -0700 Subject: [PATCH] Add version info in preferences/advanced Fixes #3324 Closes #3404 --- .../AdvancedPreferenceFragment.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/preferences/AdvancedPreferenceFragment.java b/src/org/thoughtcrime/securesms/preferences/AdvancedPreferenceFragment.java index 0531a40379..684df211c7 100644 --- a/src/org/thoughtcrime/securesms/preferences/AdvancedPreferenceFragment.java +++ b/src/org/thoughtcrime/securesms/preferences/AdvancedPreferenceFragment.java @@ -4,11 +4,14 @@ import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.Preference; import android.provider.ContactsContract; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v4.preference.PreferenceFragment; import android.util.Log; import android.widget.Toast; @@ -51,8 +54,9 @@ public class AdvancedPreferenceFragment extends PreferenceFragment { initializePushMessagingToggle(); initializeIdentitySelection(); - this.findPreference(SUBMIT_DEBUG_LOG_PREF) - .setOnPreferenceClickListener(new SubmitDebugLogListener()); + Preference submitDebugLog = this.findPreference(SUBMIT_DEBUG_LOG_PREF); + submitDebugLog.setOnPreferenceClickListener(new SubmitDebugLogListener()); + submitDebugLog.setSummary(getVersion(getActivity())); } @Override @@ -97,6 +101,20 @@ public class AdvancedPreferenceFragment extends PreferenceFragment { } } + private @NonNull String getVersion(@Nullable Context context) { + try { + if (context == null) return ""; + + String app = context.getString(R.string.app_name); + String version = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; + + return String.format("%s %s", app, version); + } catch (PackageManager.NameNotFoundException e) { + Log.w(TAG, e); + return context.getString(R.string.app_name); + } + } + private class IdentityPreferenceClickListener implements Preference.OnPreferenceClickListener { @Override public boolean onPreferenceClick(Preference preference) {