|
22 | 22 | import android.content.pm.PackageManager.NameNotFoundException;
|
23 | 23 | import android.preference.PreferenceManager;
|
24 | 24 |
|
25 |
| - |
26 | 25 | /**
|
27 | 26 | * Class to show a dialog with the latest changes for the current app version.
|
28 | 27 | */
|
29 | 28 | public class WhatsNewDialog extends ChangeLogDialog {
|
30 |
| - private static final String WHATS_NEW_LAST_SHOWN = "whats_new_last_shown"; |
| 29 | + private static final String WHATS_NEW_LAST_SHOWN = "whats_new_last_shown"; |
31 | 30 |
|
32 |
| - public WhatsNewDialog(final Context context) { |
33 |
| - super(context); |
34 |
| - } |
| 31 | + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); |
35 | 32 |
|
36 |
| - //Get the current app version |
37 |
| - private int getAppVersionCode() { |
38 |
| - try { |
39 |
| - final PackageInfo packageInfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0); |
40 |
| - return packageInfo.versionCode; |
41 |
| - } catch (NameNotFoundException ignored) { |
42 |
| - return 0; |
43 |
| - } |
44 |
| - } |
| 33 | + public WhatsNewDialog(final Context context) { |
| 34 | + super(context); |
| 35 | + } |
45 | 36 |
|
46 |
| - public void forceShow() { |
47 |
| - //Show only the changes from this version (if available) |
48 |
| - show(getAppVersionCode()); |
| 37 | + //Get the current app version |
| 38 | + private int getAppVersionCode() { |
| 39 | + try { |
| 40 | + final PackageInfo packageInfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0); |
| 41 | + return packageInfo.versionCode; |
| 42 | + } catch (NameNotFoundException ignored) { |
| 43 | + return 0; |
49 | 44 | }
|
| 45 | + } |
50 | 46 |
|
51 |
| - @Override |
52 |
| - public void show() { |
53 |
| - //ToDo check if version is shown |
54 |
| - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); |
55 |
| - final int versionShown = prefs.getInt(WHATS_NEW_LAST_SHOWN, 0); |
56 |
| - if (versionShown != getAppVersionCode()) { |
57 |
| - //This version is new, show only the changes from this version (if available) |
58 |
| - show(getAppVersionCode()); |
| 47 | + public void forceShow() { |
| 48 | + //Show only the changes from this version (if available) |
| 49 | + show(getAppVersionCode()); |
| 50 | + } |
59 | 51 |
|
60 |
| - //Update last shown version |
61 |
| - final SharedPreferences.Editor edit = prefs.edit(); |
62 |
| - edit.putInt(WHATS_NEW_LAST_SHOWN, getAppVersionCode()); |
63 |
| - edit.commit(); |
64 |
| - } |
65 |
| - if(mOnDismissListener != null) { |
66 |
| - mOnDismissListener.onDismiss(null); |
67 |
| - } |
| 52 | + @Override |
| 53 | + public void show() { |
| 54 | + //ToDo check if version is shown |
| 55 | + final int versionShown = prefs.getInt(WHATS_NEW_LAST_SHOWN, 0); |
| 56 | + final int appVersionCode = getAppVersionCode(); |
| 57 | + if (versionShown != appVersionCode) { |
| 58 | + //This version is new, show only the changes from this version (if available) |
| 59 | + show(appVersionCode); |
| 60 | + |
| 61 | + //Update last shown version |
| 62 | + updateLastShown(); |
| 63 | + } else if(mOnDismissListener != null) { |
| 64 | + mOnDismissListener.onDismiss(null); |
68 | 65 | }
|
| 66 | + } |
| 67 | + |
| 68 | + public void updateLastShown() { |
| 69 | + final SharedPreferences.Editor edit = prefs.edit(); |
| 70 | + edit.putInt(WHATS_NEW_LAST_SHOWN, getAppVersionCode()); |
| 71 | + edit.commit(); |
| 72 | + } |
69 | 73 | }
|
| 74 | + |
0 commit comments