Skip to content

Commit

Permalink
Save version code and name in shared preferences
Browse files Browse the repository at this point in the history
... such that a Changelog can be shown in future releases
  • Loading branch information
flackbash committed Feb 13, 2022
1 parent 92d02ae commit 83ac0a3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.content.Loader;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.os.Bundle;
Expand Down Expand Up @@ -260,6 +261,27 @@ public void onDestroyActionMode(ActionMode actionMode) {
// This needs to be a receiver for global broadcasts, as the deleteIntent is broadcast by
// Android's notification framework
registerReceiver(mRemoveNotificationReceiver, new IntentFilter(MediaPlayerService.BROADCAST_REMOVE_NOTIFICATION));

// Extract version code and version name of the app
PackageInfo pInfo = null;
try {
pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (pInfo != null) {
int previousVersionCode = mSharedPreferences.getInt(getString(R.string.preference_version_code_key), Integer.parseInt(getString(R.string.preference_version_code_default)));
int versionCode = pInfo.versionCode;
String versionName = pInfo.versionName;
if (previousVersionCode != versionCode) {
// TODO: Show Changelog
// Save new version code and name
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putInt(getString(R.string.preference_version_code_key), versionCode);
editor.putString(getString(R.string.preference_version_name_key), versionName);
editor.apply();
}
}
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/donttranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<string name="preference_playback_speed_key" translatable="false">preference_playback_speed</string>
<string name="preference_playback_speed_default" translatable="false">100</string>
<string name="preference_playback_speed_minimum" translatable="false">50</string>
<string name="preference_version_code_key" translatable="false">app_version_code</string>
<string name="preference_version_code_default" translatable="false">0</string>
<string name="preference_version_name_key" translatable="false">app_version_name</string>
<string name="preference_version_name_default" translatable="false">0</string>

<!-- Settings strings -->
<string name="settings_autoplay_key" translatable="false">autoplay</string>
Expand Down

0 comments on commit 83ac0a3

Please sign in to comment.