[Android] Onboarding: detect already existing DB

Geoffrey Métais git at videolan.org
Thu May 2 11:54:00 CEST 2019


vlc-android | branch: 3.1.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu May  2 10:22:27 2019 +0200| [d655fb76ca2f84834a0388a5f22118d3c89dfd31] | committer: Geoffrey Métais

Onboarding: detect already existing DB

> https://code.videolan.org/videolan/vlc-android/commit/d655fb76ca2f84834a0388a5f22118d3c89dfd31
---

 vlc-android/src/org/videolan/vlc/StartActivity.java   | 19 +++++++++++--------
 .../videolan/vlc/gui/onboarding/OnboardingActivity.kt |  6 +++---
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/StartActivity.java b/vlc-android/src/org/videolan/vlc/StartActivity.java
index 1d326eb72..a61558b7b 100644
--- a/vlc-android/src/org/videolan/vlc/StartActivity.java
+++ b/vlc-android/src/org/videolan/vlc/StartActivity.java
@@ -31,6 +31,9 @@ import android.os.Bundle;
 import android.provider.MediaStore;
 import android.text.TextUtils;
 
+import androidx.core.content.ContextCompat;
+import androidx.fragment.app.FragmentActivity;
+
 import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.vlc.gui.MainActivity;
 import org.videolan.vlc.gui.SearchActivity;
@@ -44,8 +47,6 @@ import org.videolan.vlc.util.Constants;
 import org.videolan.vlc.util.FileUtils;
 import org.videolan.vlc.util.Settings;
 
-import androidx.core.content.ContextCompat;
-import androidx.fragment.app.FragmentActivity;
 import videolan.org.commontools.TvChannelUtilsKt;
 
 public class StartActivity extends FragmentActivity {
@@ -85,8 +86,8 @@ public class StartActivity extends FragmentActivity {
         /* Check if it's the first run */
         final boolean firstRun = savedVersionNumber == -1;
         final boolean upgrade = firstRun || savedVersionNumber != currentVersionNumber;
-        if (upgrade) settings.edit().putInt(Constants.PREF_FIRST_RUN, currentVersionNumber).apply();
         final boolean tv = showTvUi();
+        if (upgrade && (tv || !firstRun)) settings.edit().putInt(Constants.PREF_FIRST_RUN, currentVersionNumber).apply();
         // Route search query
         if (Intent.ACTION_SEARCH.equals(action) || "com.google.android.gms.actions.SEARCH_ACTION".equals(action)) {
             startActivity(intent.setClass(this, tv ? org.videolan.vlc.gui.tv.SearchActivity.class : SearchActivity.class));
@@ -115,14 +116,18 @@ public class StartActivity extends FragmentActivity {
     }
 
     private void startApplication(final boolean tv, final boolean firstRun, final boolean upgrade, final int target) {
-        final boolean onboarding = !tv && !Settings.INSTANCE.getInstance(StartActivity.this).getBoolean(OnboardingActivityKt.ONBOARDING_DONE_KEY, false);
+        final SharedPreferences settings = Settings.INSTANCE.getInstance(StartActivity.this);
+        final boolean onboarding = !tv && !settings.getBoolean(OnboardingActivityKt.ONBOARDING_DONE_KEY, false);
         // Start Medialibrary from background to workaround Dispatchers.Main causing ANR
         // cf https://github.com/Kotlin/kotlinx.coroutines/issues/878
-        if (!onboarding) {
+        if (!onboarding || !firstRun) {
             new Thread(new Runnable() {
                 @Override
                 public void run() {
                     MediaParsingServiceKt.startMedialibrary(StartActivity.this, firstRun, upgrade, true);
+                    if (onboarding) {
+                        settings.edit().putBoolean(OnboardingActivityKt.ONBOARDING_DONE_KEY, true).apply();
+                    }
                 }
             }).start();
             final Intent intent = new Intent(StartActivity.this, tv ? MainTvActivity.class : MainActivity.class)
@@ -131,9 +136,7 @@ public class StartActivity extends FragmentActivity {
             if (tv && getIntent().hasExtra(Constants.EXTRA_PATH)) intent.putExtra(Constants.EXTRA_PATH, getIntent().getStringExtra(Constants.EXTRA_PATH));
             if (target != 0) intent.putExtra(Constants.EXTRA_TARGET, target);
             startActivity(intent);
-        } else {
-            OnboardingActivityKt.startOnboarding(StartActivity.this);
-        }
+        } else OnboardingActivityKt.startOnboarding(StartActivity.this);
     }
 
     private void startPlaybackFromApp(Intent intent) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt b/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
index 5440dceed..0b4e40fad 100644
--- a/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
@@ -13,11 +13,11 @@ import androidx.appcompat.app.AppCompatActivity
 import androidx.core.content.ContextCompat
 import androidx.viewpager.widget.ViewPager
 import kotlinx.coroutines.*
+import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.MediaParsingService
 import org.videolan.vlc.R
 import org.videolan.vlc.gui.MainActivity
 import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate
-import org.videolan.vlc.gui.preferences.PreferencesActivity
 import org.videolan.vlc.gui.view.NonSwipeableViewPager
 import org.videolan.vlc.startMedialibrary
 import org.videolan.vlc.util.*
@@ -125,10 +125,10 @@ class OnboardingActivity : AppCompatActivity(), ViewPager.OnPageChangeListener,
     }
 
     private fun completeOnBoarding() {
-        setResult(PreferencesActivity.RESULT_RESTART)
         Settings.getInstance(this)
                 .edit()
                 .putBoolean(ONBOARDING_DONE_KEY, true)
+                .putInt(PREF_FIRST_RUN, BuildConfig.VERSION_CODE)
                 .putInt(KEY_MEDIALIBRARY_SCAN, if (viewModel.scanStorages) ML_SCAN_ON else ML_SCAN_OFF)
                 .putInt("fragment_id", if (viewModel.scanStorages) R.id.nav_video else R.id.nav_directories)
                 .putString("app_theme", viewModel.theme.toString())
@@ -226,4 +226,4 @@ class OnboardingActivity : AppCompatActivity(), ViewPager.OnPageChangeListener,
     }
 }
 
-fun Activity.startOnboarding() = startActivityForResult(Intent(this, OnboardingActivity::class.java), ACTIVITY_RESULT_PREFERENCES)
+fun Activity.startOnboarding() = startActivity(Intent(this, OnboardingActivity::class.java))



More information about the Android mailing list