From d727099c294bf9948c39310be8d1cd18df68fa67 Mon Sep 17 00:00:00 2001
From: Blatzar <46196380+Blatzar@users.noreply.github.com>
Date: Wed, 21 Dec 2022 15:19:49 +0100
Subject: [PATCH] add apk installer options for memeUI
---
.../ui/settings/SettingsUpdates.kt | 29 ++++++++++-
.../cloudstream3/utils/InAppUpdater.kt | 48 ++++++++++++-------
app/src/main/res/values/array.xml | 10 ++++
app/src/main/res/values/strings.xml | 7 +++
app/src/main/res/xml/settings_updates.xml | 19 +++++---
5 files changed, 89 insertions(+), 24 deletions(-)
diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt
index d6a8be78..65dd7885 100644
--- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt
+++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt
@@ -10,7 +10,7 @@ import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.navigation.fragment.findNavController
import androidx.preference.PreferenceFragmentCompat
-import com.lagradost.cloudstream3.CommonActivity
+import androidx.preference.PreferenceManager
import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.mvvm.logError
@@ -21,6 +21,7 @@ import com.lagradost.cloudstream3.utils.BackupUtils.backup
import com.lagradost.cloudstream3.utils.BackupUtils.restorePrompt
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate
+import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
import com.lagradost.cloudstream3.utils.VideoDownloadManager
@@ -124,6 +125,32 @@ class SettingsUpdates : PreferenceFragmentCompat() {
return@setOnPreferenceClickListener true
}
+ getPref(R.string.apk_installer_key)?.setOnPreferenceClickListener {
+ val settingsManager = PreferenceManager.getDefaultSharedPreferences(it.context)
+
+ val prefNames = resources.getStringArray(R.array.apk_installer_pref)
+ val prefValues = resources.getIntArray(R.array.apk_installer_values)
+
+ val currentInstaller =
+ settingsManager.getInt(getString(R.string.apk_installer_key), 0)
+
+ activity?.showBottomDialog(
+ prefNames.toList(),
+ prefValues.indexOf(currentInstaller),
+ getString(R.string.app_layout),
+ true,
+ {}) {
+ try {
+ settingsManager.edit()
+ .putInt(getString(R.string.apk_installer_key), prefValues[it])
+ .apply()
+ } catch (e: Exception) {
+ logError(e)
+ }
+ }
+ return@setOnPreferenceClickListener true
+ }
+
getPref(R.string.manual_check_update_key)?.setOnPreferenceClickListener {
ioSafe {
if (activity?.runAutoUpdate(false) == false) {
diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt
index 30981ba4..1a671499 100644
--- a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt
+++ b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt
@@ -15,6 +15,7 @@ import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
+import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import okio.BufferedSink
@@ -292,23 +293,36 @@ class InAppUpdater {
builder.apply {
setPositiveButton(R.string.update) { _, _ ->
showToast(context, R.string.download_started, Toast.LENGTH_LONG)
- val intent = PackageInstallerService.getIntent(
- context,
- update.updateURL
- )
- ContextCompat.startForegroundService(context, intent)
-// ioSafe {
-// if (
-// !downloadUpdate(update.updateURL)
-// )
-// runOnUiThread {
-// showToast(
-// context,
-// R.string.download_failed,
-// Toast.LENGTH_LONG
-// )
-// }
-// }
+
+ val currentInstaller =
+ settingsManager.getInt(
+ getString(R.string.apk_installer_key),
+ 0
+ )
+
+ when (currentInstaller) {
+ // New method
+ 0 -> {
+ val intent = PackageInstallerService.getIntent(
+ context,
+ update.updateURL
+ )
+ ContextCompat.startForegroundService(context, intent)
+ }
+ // Legacy
+ 1 -> {
+ ioSafe {
+ if (!downloadUpdate(update.updateURL))
+ runOnUiThread {
+ showToast(
+ context,
+ R.string.download_failed,
+ Toast.LENGTH_LONG
+ )
+ }
+ }
+ }
+ }
}
setNegativeButton(R.string.cancel) { _, _ -> }
diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml
index 3554beb2..6aff7a59 100644
--- a/app/src/main/res/values/array.xml
+++ b/app/src/main/res/values/array.xml
@@ -33,6 +33,16 @@
- 6
+
+ - @string/apk_installer_package_installer
+ - @string/apk_installer_legacy
+
+
+ - 0
+ - 1
+
+
+
- @string/player_settings_play_in_app
- @string/player_settings_play_in_vlc
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b3d91267..559f7e3d 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -18,6 +18,7 @@
player_pref_key
prefer_limit_title_key
prefer_limit_title_rez_key
+ apk_installer_key
video_buffer_size_key
video_buffer_length_key
video_buffer_clear_key
@@ -243,6 +244,8 @@
Automatically search for new updates on start
Update to prereleases
Search for prerelease updates instead of full releases only
+ APK Installer
+ Some phones do not support the new package installer. Try the legacy option if updates do not install.
Github
Light novel app by the same devs
Anime app by the same devs
@@ -590,4 +593,8 @@
Downloading app update…
Installing app update…
Could not install the new version of the app
+
+ Legacy
+ PackageInstaller
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/settings_updates.xml b/app/src/main/res/xml/settings_updates.xml
index cc743e4d..6434a7ef 100644
--- a/app/src/main/res/xml/settings_updates.xml
+++ b/app/src/main/res/xml/settings_updates.xml
@@ -6,6 +6,19 @@
app:icon="@drawable/ic_baseline_system_update_24"
app:key="@string/manual_check_update_key"
app:summary="@string/app_version" />
+
+
+
-