[Android] Check app upgrade in StartActivity
Geoffrey Métais
git at videolan.org
Mon Feb 13 17:36:26 CET 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Feb 13 17:21:38 2017 +0100| [34a4b14d6d30910a6ae6b367c4898fe12bfb8c1b] | committer: Geoffrey Métais
Check app upgrade in StartActivity
> https://code.videolan.org/videolan/vlc-android/commit/34a4b14d6d30910a6ae6b367c4898fe12bfb8c1b
---
.../src/org/videolan/vlc/StartActivity.java | 25 ++++++++++++++++++++--
.../src/org/videolan/vlc/gui/MainActivity.java | 17 +--------------
2 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/StartActivity.java b/vlc-android/src/org/videolan/vlc/StartActivity.java
index f6321c5..2720f75 100644
--- a/vlc-android/src/org/videolan/vlc/StartActivity.java
+++ b/vlc-android/src/org/videolan/vlc/StartActivity.java
@@ -25,6 +25,7 @@ package org.videolan.vlc;
import android.app.Activity;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils;
@@ -43,9 +44,23 @@ public class StartActivity extends Activity {
public final static String TAG = "VLC/StartActivity";
+ private static final String PREF_FIRST_RUN = "first_run";
+ public static final String EXTRA_FIRST_RUN = "extra_first_run";
+ public static final String EXTRA_UPGRADE = "extra_upgrade";
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ /* Get the current version from package */
+ SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
+ int currentVersionNumber = BuildConfig.VERSION_CODE;
+ int savedVersionNumber = settings.getInt(PREF_FIRST_RUN, -1);
+ /* Check if it's the first run */
+ boolean firstRun = savedVersionNumber == -1;
+ boolean upgrade = firstRun || savedVersionNumber != currentVersionNumber;
+ if (upgrade)
+ settings.edit().putInt(PREF_FIRST_RUN, currentVersionNumber).apply();
+
Intent intent = getIntent();
if (intent != null && TextUtils.equals(intent.getAction(), Intent.ACTION_VIEW) && intent.getData() != null) {
intent.setDataAndType(intent.getData(), intent.getType());
@@ -58,8 +73,14 @@ public class StartActivity extends Activity {
startService(new Intent(MediaParsingService.ACTION_INIT, null, this, MediaParsingService.class));
if (intent != null && TextUtils.equals(intent.getAction(), AudioPlayerContainerActivity.ACTION_SHOW_PLAYER))
startActivity(new Intent(this, showTvUi() ? AudioPlayerActivity.class : MainActivity.class));
- else
- startActivity(new Intent(this, showTvUi() ? MainTvActivity.class : MainActivity.class));
+ else {
+ Intent activityIntent = new Intent(this, showTvUi() ? MainTvActivity.class : MainActivity.class);
+ if (firstRun)
+ activityIntent.putExtra(EXTRA_FIRST_RUN, true);
+ if (upgrade)
+ activityIntent.putExtra(EXTRA_UPGRADE, true);
+ startActivity(activityIntent);
+ }
}
finish();
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 99e7c49..136ecca 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -108,8 +108,6 @@ import java.util.List;
public class MainActivity extends AudioPlayerContainerActivity implements FilterQueryProvider, NavigationView.OnNavigationItemSelectedListener, ExtensionManagerService.ExtensionManagerActivity, SearchView.OnQueryTextListener, MenuItemCompat.OnActionExpandListener {
public final static String TAG = "VLC/MainActivity";
- private static final String PREF_FIRST_RUN = "first_run";
-
private static final int ACTIVITY_RESULT_PREFERENCES = 1;
private static final int ACTIVITY_RESULT_OPEN = 2;
public static final int ACTIVITY_RESULT_SECONDARY = 3;
@@ -128,8 +126,6 @@ public class MainActivity extends AudioPlayerContainerActivity implements Filter
private int mCurrentFragmentId;
- private int mVersionNumber = -1;
- private boolean mFirstRun = false;
private boolean mScanNeeded = false;
private Menu mMenu;
@@ -151,17 +147,6 @@ public class MainActivity extends AudioPlayerContainerActivity implements Filter
/* Enable the indeterminate progress feature */
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
- /* Get the current version from package */
- mVersionNumber = BuildConfig.VERSION_CODE;
-
- /* Check if it's the first run */
- mFirstRun = mSettings.getInt(PREF_FIRST_RUN, -1) != mVersionNumber;
- if (mFirstRun) {
- Editor editor = mSettings.edit();
- editor.putInt(PREF_FIRST_RUN, mVersionNumber);
- editor.apply();
- }
-
Permissions.checkReadStoragePermission(this, false);
/*** Start initializing the UI ***/
@@ -208,7 +193,7 @@ public class MainActivity extends AudioPlayerContainerActivity implements Filter
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
- if (mFirstRun) {
+ if (getIntent().getBooleanExtra(StartActivity.EXTRA_UPGRADE, false)) {
/*
* The sliding menu is automatically opened when the user closes
* the info dialog. If (for any reason) the dialog is not shown,
More information about the Android
mailing list