Add version info in preferences/advanced

Fixes #3324
Closes #3404
This commit is contained in:
Nicholas Thomson 2015-06-11 14:42:32 -07:00 committed by Moxie Marlinspike
parent 219a403f36
commit 155cbf686d

View File

@ -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) {