[Android] Improve Onboarding launch

Geoffrey Métais git at videolan.org
Tue Mar 12 10:11:26 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey at videolan.org> | Tue Mar 12 10:11:26 2019 +0100| [14045a75f7c004055ce0d8c4b6859739fbf42ebe] | committer: Geoffrey Métais

Improve Onboarding launch

- Launch onboarding from StartActivity instead of MainActivity
- Launch it until it's been completed

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

 .../src/org/videolan/vlc/StartActivity.java        | 19 ++++++++++--------
 .../src/org/videolan/vlc/gui/MainActivity.java     |  5 +----
 .../vlc/gui/onboarding/OnboardingActivity.kt       | 23 +++++++++++-----------
 3 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/StartActivity.java b/vlc-android/src/org/videolan/vlc/StartActivity.java
index 7f65ce656..d476a4e04 100644
--- a/vlc-android/src/org/videolan/vlc/StartActivity.java
+++ b/vlc-android/src/org/videolan/vlc/StartActivity.java
@@ -85,7 +85,7 @@ 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();
+        if (upgrade && !firstRun) settings.edit().putInt(Constants.PREF_FIRST_RUN, currentVersionNumber).apply();
         final boolean tv = showTvUi();
         // Route search query
         if (Intent.ACTION_SEARCH.equals(action) || "com.google.android.gms.actions.SEARCH_ACTION".equals(action)) {
@@ -115,22 +115,25 @@ public class StartActivity extends FragmentActivity {
     }
 
     private void startApplication(final boolean tv, final boolean firstRun, final boolean upgrade, final int target) {
+        final boolean onboarding = firstRun && !tv && !Settings.INSTANCE.getInstance(StartActivity.this).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 (!firstRun || tv || Settings.INSTANCE.getInstance(StartActivity.this).getBoolean(OnboardingActivityKt.ONBOARDING_DONE_KEY, false)) {
+        if (!onboarding) {
             new Thread(new Runnable() {
                 @Override
                 public void run() {
                     MediaParsingServiceKt.startMedialibrary(StartActivity.this, firstRun, upgrade, true);
                 }
             }).start();
+            final Intent intent = new Intent(StartActivity.this, tv ? MainTvActivity.class : MainActivity.class)
+                    .putExtra(Constants.EXTRA_FIRST_RUN, firstRun)
+                    .putExtra(Constants.EXTRA_UPGRADE, upgrade);
+            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);
         }
-        final Intent intent = new Intent(StartActivity.this, tv ? MainTvActivity.class : MainActivity.class)
-                .putExtra(Constants.EXTRA_FIRST_RUN, firstRun)
-                .putExtra(Constants.EXTRA_UPGRADE, upgrade);
-        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);
     }
 
     private void startPlaybackFromApp(Intent intent) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index a9c44709f..e523a1c79 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -113,10 +113,7 @@ public class MainActivity extends ContentActivity implements ExtensionManagerSer
                     }
                 }, 500);
             }
-            if (getIntent().getBooleanExtra(Constants.EXTRA_FIRST_RUN, false)
-                    && !mSettings.getBoolean(OnboardingActivityKt.ONBOARDING_DONE_KEY, false)) {
-                OnboardingActivityKt.startOnboarding(MainActivity.this);
-            } else Permissions.checkReadStoragePermission(MainActivity.this, false);
+            Permissions.checkReadStoragePermission(MainActivity.this, false);
         }
 
         /* Set up the action bar */
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 fe254f74c..c7b0e52ee 100644
--- a/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
@@ -13,8 +13,10 @@ 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
@@ -105,7 +107,7 @@ class OnboardingActivity : AppCompatActivity(), ViewPager.OnPageChangeListener,
             }
         }
 
-        doneButton.setOnClickListener { finish() }
+        doneButton.setOnClickListener { completeOnBoarding() }
 
         val count = viewModel.adapterCount
 
@@ -126,18 +128,15 @@ class OnboardingActivity : AppCompatActivity(), ViewPager.OnPageChangeListener,
                 .putBoolean(ONBOARDING_DONE_KEY, true)
                 .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)
+                .putInt(PREF_FIRST_RUN, BuildConfig.VERSION_CODE)
                 .apply()
-        launch {
-            if (!viewModel.scanStorages) {
-                MediaParsingService.preselectedStorages.clear()
-            }
-            startMedialibrary(firstRun = true, upgrade = true, parse = viewModel.scanStorages)
-        }
-    }
-
-    override fun finish() {
-        completeOnBoarding()
-        super.finish()
+        if (!viewModel.scanStorages) MediaParsingService.preselectedStorages.clear()
+        startMedialibrary(firstRun = true, upgrade = true, parse = viewModel.scanStorages)
+        val intent = Intent(this at OnboardingActivity, MainActivity::class.java)
+                .putExtra(EXTRA_FIRST_RUN, true)
+                .putExtra(EXTRA_UPGRADE, true)
+        startActivity(intent)
+        finish()
     }
 
     override fun onBackPressed() {



More information about the Android mailing list