add apk installer options for memeUI

This commit is contained in:
Blatzar 2022-12-21 15:19:49 +01:00
parent e2fc946d91
commit d727099c29
5 changed files with 89 additions and 24 deletions

View file

@ -10,7 +10,7 @@ import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import com.lagradost.cloudstream3.CommonActivity import androidx.preference.PreferenceManager
import com.lagradost.cloudstream3.CommonActivity.showToast import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.mvvm.logError 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.BackupUtils.restorePrompt
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate 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.dismissSafe
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
import com.lagradost.cloudstream3.utils.VideoDownloadManager import com.lagradost.cloudstream3.utils.VideoDownloadManager
@ -124,6 +125,32 @@ class SettingsUpdates : PreferenceFragmentCompat() {
return@setOnPreferenceClickListener true 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 { getPref(R.string.manual_check_update_key)?.setOnPreferenceClickListener {
ioSafe { ioSafe {
if (activity?.runAutoUpdate(false) == false) { if (activity?.runAutoUpdate(false) == false) {

View file

@ -15,6 +15,7 @@ import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.CommonActivity.showToast import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.utils.AppUtils.parseJson import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.sync.withLock
import okio.BufferedSink import okio.BufferedSink
@ -292,23 +293,36 @@ class InAppUpdater {
builder.apply { builder.apply {
setPositiveButton(R.string.update) { _, _ -> setPositiveButton(R.string.update) { _, _ ->
showToast(context, R.string.download_started, Toast.LENGTH_LONG) showToast(context, R.string.download_started, Toast.LENGTH_LONG)
val intent = PackageInstallerService.getIntent(
context, val currentInstaller =
update.updateURL settingsManager.getInt(
) getString(R.string.apk_installer_key),
ContextCompat.startForegroundService(context, intent) 0
// ioSafe { )
// if (
// !downloadUpdate(update.updateURL) when (currentInstaller) {
// ) // New method
// runOnUiThread { 0 -> {
// showToast( val intent = PackageInstallerService.getIntent(
// context, context,
// R.string.download_failed, update.updateURL
// Toast.LENGTH_LONG )
// ) 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) { _, _ -> } setNegativeButton(R.string.cancel) { _, _ -> }

View file

@ -33,6 +33,16 @@
<item>6</item> <item>6</item>
</array> </array>
<array name="apk_installer_pref">
<item>@string/apk_installer_package_installer</item>
<item>@string/apk_installer_legacy</item>
</array>
<array name="apk_installer_values">
<item>0</item>
<item>1</item>
</array>
<array name="player_pref_names"> <array name="player_pref_names">
<item>@string/player_settings_play_in_app</item> <item>@string/player_settings_play_in_app</item>
<item>@string/player_settings_play_in_vlc</item> <item>@string/player_settings_play_in_vlc</item>

View file

@ -18,6 +18,7 @@
<string name="player_pref_key" translatable="false">player_pref_key</string> <string name="player_pref_key" translatable="false">player_pref_key</string>
<string name="prefer_limit_title_key" translatable="false">prefer_limit_title_key</string> <string name="prefer_limit_title_key" translatable="false">prefer_limit_title_key</string>
<string name="prefer_limit_title_rez_key" translatable="false">prefer_limit_title_rez_key</string> <string name="prefer_limit_title_rez_key" translatable="false">prefer_limit_title_rez_key</string>
<string name="apk_installer_key" translatable="false">apk_installer_key</string>
<string name="video_buffer_size_key" translatable="false">video_buffer_size_key</string> <string name="video_buffer_size_key" translatable="false">video_buffer_size_key</string>
<string name="video_buffer_length_key" translatable="false">video_buffer_length_key</string> <string name="video_buffer_length_key" translatable="false">video_buffer_length_key</string>
<string name="video_buffer_clear_key" translatable="false">video_buffer_clear_key</string> <string name="video_buffer_clear_key" translatable="false">video_buffer_clear_key</string>
@ -243,6 +244,8 @@
<string name="updates_settings_des">Automatically search for new updates on start</string> <string name="updates_settings_des">Automatically search for new updates on start</string>
<string name="uprereleases_settings">Update to prereleases</string> <string name="uprereleases_settings">Update to prereleases</string>
<string name="uprereleases_settings_des">Search for prerelease updates instead of full releases only</string> <string name="uprereleases_settings_des">Search for prerelease updates instead of full releases only</string>
<string name="apk_installer_settings">APK Installer</string>
<string name="apk_installer_settings_des">Some phones do not support the new package installer. Try the legacy option if updates do not install. </string>
<string name="github">Github</string> <string name="github">Github</string>
<string name="lightnovel">Light novel app by the same devs</string> <string name="lightnovel">Light novel app by the same devs</string>
<string name="anim">Anime app by the same devs</string> <string name="anim">Anime app by the same devs</string>
@ -590,4 +593,8 @@
<string name="update_notification_downloading">Downloading app update…</string> <string name="update_notification_downloading">Downloading app update…</string>
<string name="update_notification_installing">Installing app update…</string> <string name="update_notification_installing">Installing app update…</string>
<string name="update_notification_failed">Could not install the new version of the app</string> <string name="update_notification_failed">Could not install the new version of the app</string>
<string name="apk_installer_legacy">Legacy</string>
<string name="apk_installer_package_installer">PackageInstaller</string>
</resources> </resources>

View file

@ -6,6 +6,19 @@
app:icon="@drawable/ic_baseline_system_update_24" app:icon="@drawable/ic_baseline_system_update_24"
app:key="@string/manual_check_update_key" app:key="@string/manual_check_update_key"
app:summary="@string/app_version" /> app:summary="@string/app_version" />
<SwitchPreference
android:icon="@drawable/ic_baseline_developer_mode_24"
android:summary="@string/uprereleases_settings_des"
android:title="@string/uprereleases_settings"
app:defaultValue="@bool/is_prerelease"
app:key="@string/prerelease_update_key" />
<Preference
android:icon="@drawable/netflix_download"
android:key="@string/apk_installer_key"
android:title="@string/apk_installer_settings"
android:summary="@string/apk_installer_settings_des"
/>
<Preference <Preference
android:icon="@drawable/baseline_save_as_24" android:icon="@drawable/baseline_save_as_24"
@ -45,12 +58,6 @@
android:title="@string/updates_settings" android:title="@string/updates_settings"
app:defaultValue="true" app:defaultValue="true"
app:key="@string/auto_update_key" /> app:key="@string/auto_update_key" />
<SwitchPreference
android:icon="@drawable/ic_baseline_developer_mode_24"
android:summary="@string/uprereleases_settings_des"
android:title="@string/uprereleases_settings"
app:defaultValue="@bool/is_prerelease"
app:key="@string/prerelease_update_key" />
<Preference <Preference
android:icon="@drawable/ic_baseline_construction_24" android:icon="@drawable/ic_baseline_construction_24"
android:title="Redo setup process" android:title="Redo setup process"