From 486cea39c5ade982033dd6bd7d24205efd5760da Mon Sep 17 00:00:00 2001 From: LagradOst Date: Sun, 12 Dec 2021 03:33:17 +0100 Subject: [PATCH] fuck android (((also fixes))) --- app/src/main/AndroidManifest.xml | 2 +- .../lagradost/cloudstream3/MainActivity.kt | 58 ++++---- .../cloudstream3/ui/ControllerActivity.kt | 6 +- .../ui/download/DownloadButtonSetup.kt | 28 ++-- .../cloudstream3/ui/home/HomeFragment.kt | 6 +- .../cloudstream3/ui/player/PlayerFragment.kt | 33 +++-- .../cloudstream3/ui/result/ResultFragment.kt | 133 ++++++++++-------- .../cloudstream3/ui/result/ResultViewModel.kt | 1 + .../cloudstream3/ui/search/SearchFragment.kt | 5 +- .../ui/settings/SettingsFragment.kt | 70 +++++---- .../ui/subtitles/SubtitlesFragment.kt | 12 +- .../utils/SingleSelectionHelper.kt | 17 +-- .../lagradost/cloudstream3/utils/UIHelper.kt | 16 ++- .../main/res/layout-land/activity_main.xml | 63 --------- app/src/main/res/layout/activity_main.xml | 25 +++- app/src/main/res/values-nl/strings.xml | 2 +- 16 files changed, 248 insertions(+), 229 deletions(-) delete mode 100644 app/src/main/res/layout-land/activity_main.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f10f5b9d..14f6475f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -31,7 +31,7 @@ diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index 9385b560..b43177f2 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -19,6 +19,7 @@ import androidx.annotation.StringRes import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.SearchView import androidx.core.view.isVisible +import androidx.navigation.NavDestination import androidx.navigation.findNavController import androidx.navigation.ui.setupWithNavController import androidx.preference.PreferenceManager @@ -87,6 +88,38 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) updateLocale() // android fucks me by chaining lang when rotating the phone + findNavController(R.id.nav_host_fragment).currentDestination?.let { updateNavBar(it) } + } + + private fun updateNavBar(destination : NavDestination) { + this.hideKeyboard() + + // Fucks up anime info layout since that has its own layout + cast_mini_controller_holder?.isVisible = + !listOf(R.id.navigation_results, R.id.navigation_player).contains(destination.id) + + val isNavVisible = listOf( + R.id.navigation_home, + R.id.navigation_search, + R.id.navigation_downloads, + R.id.navigation_settings, + R.id.navigation_download_child + ).contains(destination.id) + + val landscape = when(resources.configuration.orientation) { + Configuration.ORIENTATION_LANDSCAPE -> { + true + } + Configuration.ORIENTATION_PORTRAIT -> { + false + } + else -> { + false + } + } + + nav_view?.isVisible = isNavVisible && !landscape + nav_rail_view?.isVisible = isNavVisible && landscape } //private var mCastSession: CastSession? = null @@ -553,30 +586,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { val navRail = findViewById(R.id.nav_rail_view) navRail?.setupWithNavController(navController) navController.addOnDestinationChangedListener { _, destination, _ -> - this.hideKeyboard() - // nav_view.hideKeyboard() - /*if (destination.id != R.id.navigation_player) { - requestedOrientation = if (settingsManager?.getBoolean("force_landscape", false) == true) { - ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE - } else { - ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - } - }*/ - - // Fucks up anime info layout since that has its own layout - cast_mini_controller_holder?.isVisible = - !listOf(R.id.navigation_results, R.id.navigation_player).contains(destination.id) - - val isNavVisible = listOf( - R.id.navigation_home, - R.id.navigation_search, - R.id.navigation_downloads, - R.id.navigation_settings, - R.id.navigation_download_child - ).contains(destination.id) - - nav_view?.isVisible = isNavVisible - navRail?.isVisible = isNavVisible + updateNavBar(destination) } /*nav_view.setOnNavigationItemSelectedListener { item -> diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/ControllerActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/ControllerActivity.kt index f7c82afa..c4d2d52d 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/ControllerActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/ControllerActivity.kt @@ -30,6 +30,7 @@ import com.lagradost.cloudstream3.utils.CastHelper.awaitLinks import com.lagradost.cloudstream3.utils.CastHelper.getMediaInfo import com.lagradost.cloudstream3.utils.DataStore.toKotlinObject import com.lagradost.cloudstream3.utils.ExtractorLink +import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe import org.json.JSONObject import kotlin.concurrent.thread @@ -156,7 +157,7 @@ class SelectSourceController(val view: ImageView, val activity: ControllerActivi } } } - bottomSheetDialog.dismiss() + bottomSheetDialog.dismissSafe(activity) } } @@ -220,9 +221,8 @@ class SelectSourceController(val view: ImageView, val activity: ControllerActivi } loadMirror(which) - bottomSheetDialog.dismiss() + bottomSheetDialog.dismissSafe(activity) } - } } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt index 0669b8d2..72d1cfc8 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt @@ -6,6 +6,7 @@ import android.widget.Toast import androidx.appcompat.app.AlertDialog import com.lagradost.cloudstream3.MainActivity import com.lagradost.cloudstream3.R +import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.ui.player.PlayerFragment import com.lagradost.cloudstream3.ui.player.UriData import com.lagradost.cloudstream3.utils.AppUtils.getNameFull @@ -34,19 +35,24 @@ object DownloadButtonSetup { } } - builder.setTitle(R.string.delete_file) - .setMessage( - ctx.getString(R.string.delete_message).format( - ctx.getNameFull( - click.data.name, - click.data.episode, - click.data.season + try { + builder.setTitle(R.string.delete_file) + .setMessage( + ctx.getString(R.string.delete_message).format( + ctx.getNameFull( + click.data.name, + click.data.episode, + click.data.season + ) ) ) - ) - .setPositiveButton(R.string.delete, dialogClickListener) - .setNegativeButton(R.string.cancel, dialogClickListener) - .show() + .setPositiveButton(R.string.delete, dialogClickListener) + .setNegativeButton(R.string.cancel, dialogClickListener) + .show() + } catch (e : Exception) { + logError(e) + // ye you somehow fucked up formatting did you? + } } } DOWNLOAD_ACTION_PAUSE_DOWNLOAD -> { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt index c87bf30a..dd5a7605 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt @@ -45,6 +45,7 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.removeLastWatched import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultWatchState import com.lagradost.cloudstream3.utils.Event import com.lagradost.cloudstream3.utils.HOMEPAGE_API +import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbarView import com.lagradost.cloudstream3.utils.UIHelper.getGridIsCompact @@ -52,6 +53,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIcons import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIconsAndNoStringRes import com.lagradost.cloudstream3.utils.UIHelper.setImage import com.lagradost.cloudstream3.widget.CenterZoomLayoutManager +import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.fragment_home.* import java.util.* @@ -72,7 +74,7 @@ class HomeFragment : Fragment() { val titleHolder = bottomSheetDialogBuilder.findViewById(R.id.home_expanded_drag_down)!! titleHolder.setOnClickListener { - bottomSheetDialogBuilder.dismiss() + bottomSheetDialogBuilder.dismissSafe(this) } // Span settings @@ -81,7 +83,7 @@ class HomeFragment : Fragment() { recycle.adapter = SearchAdapter(item.list, recycle) { callback -> handleSearchClickCallback(this, callback) if (callback.action == SEARCH_ACTION_LOAD || callback.action == SEARCH_ACTION_PLAY_FILE) { - bottomSheetDialogBuilder.dismiss() + bottomSheetDialogBuilder.dismissSafe(this) } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt index 32f5f6a1..0a759b08 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt @@ -88,6 +88,7 @@ import com.lagradost.cloudstream3.utils.DataStore.setKey import com.lagradost.cloudstream3.utils.DataStoreHelper.setLastWatched import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute +import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe import com.lagradost.cloudstream3.utils.UIHelper.getNavigationBarHeight import com.lagradost.cloudstream3.utils.UIHelper.getStatusBarHeight import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard @@ -125,12 +126,12 @@ const val OPENING_PERCENTAGE = 50 const val AUTOLOAD_NEXT_EPISODE_PERCENTAGE = 80 enum class PlayerEventType(val value: Int) { - Stop(-1), + //Stop(-1), Pause(0), Play(1), SeekForward(2), SeekBack(3), - SkipCurrentChapter(4), + //SkipCurrentChapter(4), NextEpisode(5), PrevEpisode(5), PlayPauseToggle(7), @@ -1189,11 +1190,11 @@ class PlayerFragment : Fragment() { listOf(0.5f, 0.75f, 0.85f, 1f, 1.15f, 1.25f, 1.4f, 1.5f, 1.75f, 2f) val speedIndex = speedsNumbers.indexOf(playbackSpeed) - context?.let { ctx -> - ctx.showDialog( + activity?.let { act -> + act.showDialog( speedsText, speedIndex, - ctx.getString(R.string.player_speed), + act.getString(R.string.player_speed), false, { activity?.hideSystemUI() @@ -1236,7 +1237,7 @@ class PlayerFragment : Fragment() { autoHide() saveArguments() SubtitlesFragment.push(activity) - sourceDialog.dismiss() + sourceDialog.dismissSafe(activity) } var sourceIndex = 0 var startSource = 0 @@ -1297,7 +1298,7 @@ class PlayerFragment : Fragment() { } cancelButton.setOnClickListener { - sourceDialog.dismiss() + sourceDialog.dismissSafe(activity) } applyButton.setOnClickListener { @@ -1324,7 +1325,7 @@ class PlayerFragment : Fragment() { if (init) { initPlayer(getCurrentUrl()) } - sourceDialog.dismiss() + sourceDialog.dismissSafe(activity) } } } @@ -1796,11 +1797,15 @@ class PlayerFragment : Fragment() { } private fun getCurrentUrl(): ExtractorLink? { - val urls = getUrls() ?: return null - for (i in urls) { - if (i.getId() == playerData.mirrorId) { - return i + try { + val urls = getUrls() ?: return null + for (i in urls) { + if (i.getId() == playerData.mirrorId) { + return i + } } + } catch (e : Exception) { + return null } return null @@ -2189,11 +2194,11 @@ class PlayerFragment : Fragment() { setUpstreamDataSourceFactory(getDataSourceFactory()) } - val _exoPlayer = + val exoPlayerBuilder = ExoPlayer.Builder(requireContext()) .setTrackSelector(trackSelector) - exoPlayer = _exoPlayer.build().apply { + exoPlayer = exoPlayerBuilder.build().apply { playWhenReady = isPlayerPlaying seekTo(currentWindow, playbackPosition) setMediaSource( diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt index f6f9b876..cf1adba0 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt @@ -61,6 +61,7 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog import com.lagradost.cloudstream3.utils.UIHelper.checkWrite import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute +import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard import com.lagradost.cloudstream3.utils.UIHelper.navigate @@ -393,7 +394,7 @@ class ResultFragment : Fragment() { val data = viewModel.loadEpisode(episodeClick.data, isCasting) if (currentLoadingCount != currentLoad) return false - loadingDialog?.dismiss() + loadingDialog?.dismissSafe(activity) when (data) { is Resource.Success -> { @@ -627,7 +628,7 @@ class ResultFragment : Fragment() { verifiedOptions.toTypedArray() ) { _, which -> handleAction(EpisodeClickEvent(verifiedOptionsValues[which], episodeClick.data)) - dialog?.dismiss() + dialog?.dismissSafe(activity) } dialog = builder.create() @@ -636,13 +637,18 @@ class ResultFragment : Fragment() { } ACTION_COPY_LINK -> { activity?.let { act -> - acquireSingeExtractorLink(act.getString(R.string.episode_action_copy_link)) { link -> - val serviceClipboard = - (act.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager?) - ?: return@acquireSingeExtractorLink - val clip = ClipData.newPlainText(link.name, link.url) - serviceClipboard.setPrimaryClip(clip) - showToast(act, R.string.copy_link_toast, Toast.LENGTH_SHORT) + try { + acquireSingeExtractorLink(act.getString(R.string.episode_action_copy_link)) { link -> + val serviceClipboard = + (act.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager?) + ?: return@acquireSingeExtractorLink + val clip = ClipData.newPlainText(link.name, link.url) + serviceClipboard.setPrimaryClip(clip) + showToast(act, R.string.copy_link_toast, Toast.LENGTH_SHORT) + } + } catch (e: Exception) { + showToast(act, e.toString(), Toast.LENGTH_LONG) + logError(e) } } } @@ -668,58 +674,63 @@ class ResultFragment : Fragment() { ACTION_PLAY_EPISODE_IN_VLC_PLAYER -> { activity?.let { act -> - if (!act.checkWrite()) { - act.requestRW() - if (act.checkWrite()) return@main - } - val data = currentLinks ?: return@main - val subs = currentSubs - - val outputDir = act.cacheDir - val outputFile = withContext(Dispatchers.IO) { - File.createTempFile("mirrorlist", ".m3u8", outputDir) - } - var text = "#EXTM3U" - if (subs != null) { - for (sub in subs.values) { - text += "\n#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"subs\",NAME=\"${sub.lang}\",DEFAULT=NO,AUTOSELECT=NO,FORCED=NO,LANGUAGE=\"${sub.lang}\",URI=\"${sub.url}\"" + try { + if (!act.checkWrite()) { + act.requestRW() + if (act.checkWrite()) return@main } + val data = currentLinks ?: return@main + val subs = currentSubs + + val outputDir = act.cacheDir + val outputFile = withContext(Dispatchers.IO) { + File.createTempFile("mirrorlist", ".m3u8", outputDir) + } + var text = "#EXTM3U" + if (subs != null) { + for (sub in subs.values) { + text += "\n#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"subs\",NAME=\"${sub.lang}\",DEFAULT=NO,AUTOSELECT=NO,FORCED=NO,LANGUAGE=\"${sub.lang}\",URI=\"${sub.url}\"" + } + } + for (link in data.sortedBy { -it.quality }) { + text += "\n#EXTINF:, ${link.name}\n${link.url}" + } + outputFile.writeText(text) + + val vlcIntent = Intent(VLC_INTENT_ACTION_RESULT) + + vlcIntent.setPackage(VLC_PACKAGE) + vlcIntent.addFlags(FLAG_GRANT_PERSISTABLE_URI_PERMISSION) + vlcIntent.addFlags(FLAG_GRANT_PREFIX_URI_PERMISSION) + vlcIntent.addFlags(FLAG_GRANT_READ_URI_PERMISSION) + vlcIntent.addFlags(FLAG_GRANT_WRITE_URI_PERMISSION) + + vlcIntent.setDataAndType( + FileProvider.getUriForFile( + act, + act.applicationContext.packageName + ".provider", + outputFile + ), "video/*" + ) + + val startId = VLC_FROM_PROGRESS + + var position = startId + if (startId == VLC_FROM_START) { + position = 1 + } else if (startId == VLC_FROM_PROGRESS) { + position = 0 + } + + vlcIntent.putExtra("position", position) + + vlcIntent.component = VLC_COMPONENT + act.setKey(VLC_LAST_ID_KEY, episodeClick.data.id) + act.startActivityForResult(vlcIntent, VLC_REQUEST_CODE) + } catch (e: Exception) { + logError(e) + showToast(act, e.toString(), Toast.LENGTH_LONG) } - for (link in data.sortedBy { -it.quality }) { - text += "\n#EXTINF:, ${link.name}\n${link.url}" - } - outputFile.writeText(text) - - val vlcIntent = Intent(VLC_INTENT_ACTION_RESULT) - - vlcIntent.setPackage(VLC_PACKAGE) - vlcIntent.addFlags(FLAG_GRANT_PERSISTABLE_URI_PERMISSION) - vlcIntent.addFlags(FLAG_GRANT_PREFIX_URI_PERMISSION) - vlcIntent.addFlags(FLAG_GRANT_READ_URI_PERMISSION) - vlcIntent.addFlags(FLAG_GRANT_WRITE_URI_PERMISSION) - - vlcIntent.setDataAndType( - FileProvider.getUriForFile( - act, - act.applicationContext.packageName + ".provider", - outputFile - ), "video/*" - ) - - val startId = VLC_FROM_PROGRESS - - var position = startId - if (startId == VLC_FROM_START) { - position = 1 - } else if (startId == VLC_FROM_PROGRESS) { - position = 0 - } - - vlcIntent.putExtra("position", position) - - vlcIntent.component = VLC_COMPONENT - act.setKey(VLC_LAST_ID_KEY, episodeClick.data.id) - act.startActivityForResult(vlcIntent, VLC_REQUEST_CODE) } } @@ -786,7 +797,7 @@ class ResultFragment : Fragment() { result_bookmark_button?.text = getString(watchType.stringRes) result_bookmark_fab?.text = getString(watchType.stringRes) - if(watchType == WatchType.NONE) { + if (watchType == WatchType.NONE) { result_bookmark_fab?.context?.colorFromAttribute(R.attr.white) } else { result_bookmark_fab?.context?.colorFromAttribute(R.attr.colorPrimary) @@ -797,7 +808,7 @@ class ResultFragment : Fragment() { } result_bookmark_fab?.setOnClickListener { fab -> - fab.context.showBottomDialog( + activity?.showBottomDialog( WatchType.values().map { fab.context.getString(it.stringRes) }.toList(), watchType.ordinal, fab.context.getString(R.string.action_add_to_bookmarks), diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel.kt index d1466380..75ebc5bb 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel.kt @@ -449,6 +449,7 @@ class ResultViewModel : ViewModel() { data: String, isCasting: Boolean, ): Resource { + println("LOAD EPISODE FFS") if (_allEpisodes.value?.contains(id) == true) { _allEpisodes.value?.remove(id) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt index c49e3be5..279954f0 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt @@ -33,6 +33,7 @@ import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSet import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStore.setKey import com.lagradost.cloudstream3.utils.SEARCH_PROVIDER_TOGGLE +import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar import com.lagradost.cloudstream3.utils.UIHelper.getGridIsCompact import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard @@ -255,11 +256,11 @@ class SearchFragment : Fragment() { providersActive = activeApis typesActive = activeTypes - dialog.dismiss() + dialog.dismissSafe(activity) } cancelButton.setOnClickListener { - dialog.dismiss() + dialog.dismissSafe(activity) } //listView.setSelection(selectedIndex) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt index 65df438d..90c9d592 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt @@ -45,6 +45,7 @@ import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog import com.lagradost.cloudstream3.utils.SubtitleHelper +import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard import com.lagradost.cloudstream3.utils.UIHelper.setImage import com.lagradost.cloudstream3.utils.VideoDownloadManager.getBasePath @@ -147,7 +148,7 @@ class SettingsFragment : PreferenceFragmentCompat() { } api.accountIndex = ogIndex val adapter = AccountAdapter(items, R.layout.account_single) { - dialog?.dismiss() + dialog?.dismissSafe(activity) api.changeAccount(it.view.context, it.card.accountIndex) } val list = dialog.findViewById(R.id.account_list) @@ -163,14 +164,14 @@ class SettingsFragment : PreferenceFragmentCompat() { dialog.findViewById(R.id.account_logout)?.setOnClickListener { it.context?.let { ctx -> api.logOut(ctx) - dialog.dismiss() + dialog.dismissSafe(activity) } } dialog.findViewById(R.id.account_name)?.text = info.name ?: context.getString(R.string.no_data) dialog.findViewById(R.id.account_site)?.text = api.name dialog.findViewById(R.id.account_switch_account)?.setOnClickListener { - dialog.dismiss() + dialog.dismissSafe(activity) showAccountSwitch(it.context, api) } } @@ -178,6 +179,7 @@ class SettingsFragment : PreferenceFragmentCompat() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { hideKeyboard() setPreferencesFromResource(R.xml.settings, rootKey) + val updatePreference = findPreference(getString(R.string.manual_check_update_key))!! val localePreference = findPreference(getString(R.string.locale_key))!! val benenePreference = findPreference(getString(R.string.benene_count))!! @@ -191,6 +193,12 @@ class SettingsFragment : PreferenceFragmentCompat() { val colorPrimaryPreference = findPreference(getString(R.string.primary_color_key))!! val preferedMediaTypePreference = findPreference(getString(R.string.prefer_media_type_key))!! val appThemePreference = findPreference(getString(R.string.app_theme_key))!! + val subPreference = findPreference(getString(R.string.subtitle_settings_key))!! + + subPreference.setOnPreferenceClickListener { + SubtitlesFragment.push(activity, false) + return@setOnPreferenceClickListener true + } val syncApis = listOf(Pair(R.string.mal_key, malApi), Pair(R.string.anilist_key, aniListApi)) for (sync in syncApis) { @@ -233,7 +241,7 @@ class SettingsFragment : PreferenceFragmentCompat() { currentList.add(dublist.indexOf(i)) } - context?.showMultiDialog( + activity?.showMultiDialog( names, currentList, getString(R.string.display_subbed_dubbed_settings), @@ -276,7 +284,7 @@ class SettingsFragment : PreferenceFragmentCompat() { Pair(it, fullName) } - context?.showMultiDialog( + activity?.showMultiDialog( names.map { it.second }, currentList, getString(R.string.provider_lang_settings), @@ -299,12 +307,16 @@ class SettingsFragment : PreferenceFragmentCompat() { // DOES NOT WORK ON SCOPED STORAGE. val secondaryDir = if (isScopedStorage) null else Environment.getExternalStorageDirectory().absolutePath + File.separator + resources.getString(R.string.app_name_download_path) + val first = listOf(defaultDir, secondaryDir) + return (try { + val currentDir = context?.getBasePath()?.let { it.first?.filePath ?: it.second } - val currentDir = context?.getBasePath()?.let { it.first?.filePath ?: it.second } - - return (listOf(defaultDir, secondaryDir) + - requireContext().getExternalFilesDirs("").mapNotNull { it.path } + - currentDir).filterNotNull().distinct() + (first + + requireContext().getExternalFilesDirs("").mapNotNull { it.path } + + currentDir) + } catch (e: Exception) { + first + }).filterNotNull().distinct() } downloadPathPreference.setOnPreferenceClickListener { @@ -314,7 +326,7 @@ class SettingsFragment : PreferenceFragmentCompat() { val currentDir = settingsManager.getString(getString(R.string.download_path_pref), null) ?: getDownloadDir().toString() - context?.showBottomDialog( + activity?.showBottomDialog( dirs + listOf("Custom"), dirs.indexOf(currentDir), getString(R.string.download_path_pref), @@ -342,7 +354,7 @@ class SettingsFragment : PreferenceFragmentCompat() { val currentPrefMedia = settingsManager.getInt(getString(R.string.preferred_media_settings), 0) - context?.showBottomDialog( + activity?.showBottomDialog( prefNames.toList(), prefValues.indexOf(currentPrefMedia), getString(R.string.preferred_media_settings), @@ -352,7 +364,11 @@ class SettingsFragment : PreferenceFragmentCompat() { .putInt(getString(R.string.preferred_media_settings), prefValues[it]) .apply() val apilist = AppUtils.filterProviderByPreferredMedia(apis, prefValues[it]) - val apiRandom = if (apilist.size > 0) { apilist.random().name } else { "" } + val apiRandom = if (apilist.size > 0) { + apilist.random().name + } else { + "" + } context?.setKey(HOMEPAGE_API, apiRandom) (context ?: AcraApplication.context)?.let { ctx -> app.initClient(ctx) } } @@ -366,7 +382,8 @@ class SettingsFragment : PreferenceFragmentCompat() { val currentLayout = settingsManager.getInt(getString(R.string.app_layout_key), -1) - context?.showBottomDialog( + + activity?.showBottomDialog( prefNames.toList(), prefValues.indexOf(currentLayout), getString(R.string.app_layout), @@ -390,7 +407,8 @@ class SettingsFragment : PreferenceFragmentCompat() { val currentLayout = settingsManager.getString(getString(R.string.primary_color_key), prefValues.first()) - context?.showBottomDialog( + + activity?.showBottomDialog( prefNames.toList(), prefValues.indexOf(currentLayout), getString(R.string.primary_color_settings), @@ -414,7 +432,8 @@ class SettingsFragment : PreferenceFragmentCompat() { val currentLayout = settingsManager.getString(getString(R.string.app_theme_key), prefValues.first()) - context?.showBottomDialog( + + activity?.showBottomDialog( prefNames.toList(), prefValues.indexOf(currentLayout), getString(R.string.app_theme_settings), @@ -441,7 +460,8 @@ class SettingsFragment : PreferenceFragmentCompat() { getString(R.string.watch_quality_pref), Qualities.values().last().value ) - context?.showBottomDialog( + + activity?.showBottomDialog( prefNames.toList(), prefValues.indexOf(currentQuality), getString(R.string.watch_quality_pref), @@ -460,7 +480,8 @@ class SettingsFragment : PreferenceFragmentCompat() { val currentDns = settingsManager.getInt(getString(R.string.dns_pref), 0) - context?.showBottomDialog( + + activity?.showBottomDialog( prefNames.toList(), prefValues.indexOf(currentDns), getString(R.string.dns_pref), @@ -481,6 +502,7 @@ class SettingsFragment : PreferenceFragmentCompat() { if (beneneCount <= 0) getString(R.string.benene_count_text_none) else getString(R.string.benene_count_text).format( beneneCount ) + benenePreference.setOnPreferenceClickListener { try { beneneCount++ @@ -516,7 +538,8 @@ class SettingsFragment : PreferenceFragmentCompat() { val languageCodes = tempLangs.map { it.third } val languageNames = tempLangs.map { "${it.first} ${it.second}" } val index = languageCodes.indexOf(current) - pref?.context?.showDialog( + + activity?.showDialog( languageNames, index, getString(R.string.app_language), true, { } ) { languageIndex -> try { @@ -540,13 +563,4 @@ class SettingsFragment : PreferenceFragmentCompat() { val conf = res.configuration return conf?.locale?.language ?: "en" } - - override fun onPreferenceTreeClick(preference: Preference?): Boolean { - if (preference != null) { - if (preference.key == getString(R.string.subtitle_settings_key)) { - SubtitlesFragment.push(activity, false) - } - } - return super.onPreferenceTreeClick(preference) - } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt index cab9427a..5051d1b5 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt @@ -232,7 +232,7 @@ class SubtitlesFragment : Fragment() { ) //showBottomDialog - textView.context.showDialog( + activity?.showDialog( elevationTypes.map { it.second }, elevationTypes.map { it.first }.indexOf(state.elevation), (textView as TextView).text.toString(), @@ -263,7 +263,7 @@ class SubtitlesFragment : Fragment() { ) //showBottomDialog - textView.context.showDialog( + activity?.showDialog( edgeTypes.map { it.second }, edgeTypes.map { it.first }.indexOf(state.edgeType), (textView as TextView).text.toString(), @@ -314,7 +314,7 @@ class SubtitlesFragment : Fragment() { ) //showBottomDialog - textView.context.showDialog( + activity?.showDialog( fontSizes.map { it.second }, fontSizes.map { it.first }.indexOf(state.fixedTextSize), (textView as TextView).text.toString(), @@ -353,7 +353,7 @@ class SubtitlesFragment : Fragment() { ) //showBottomDialog - textView.context.showDialog( + activity?.showDialog( fontTypes.map { it.second }, fontTypes.map { it.first }.indexOf(state.typeface), (textView as TextView).text.toString(), @@ -379,7 +379,7 @@ class SubtitlesFragment : Fragment() { langMap.addAll(SubtitleHelper.languages) val lang639_1 = langMap.map { it.ISO_639_1 } - textView.context.showDialog( + activity?.showDialog( langMap.map { it.languageName }, lang639_1.indexOf(textView.context.getAutoSelectLanguageISO639_1()), (textView as TextView).text.toString(), @@ -402,7 +402,7 @@ class SubtitlesFragment : Fragment() { val keys = textView.context.getDownloadSubsLanguageISO639_1() val keyMap = keys.map { lang639_1.indexOf(it) }.filter { it >= 0 } - textView.context.showMultiDialog( + activity?.showMultiDialog( langMap.map { it.languageName }, keyMap, (textView as TextView).text.toString(), diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/SingleSelectionHelper.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/SingleSelectionHelper.kt index 66592160..67fe99e7 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/SingleSelectionHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/SingleSelectionHelper.kt @@ -1,7 +1,7 @@ package com.lagradost.cloudstream3.utils +import android.app.Activity import android.app.Dialog -import android.content.Context import android.widget.* import androidx.appcompat.app.AlertDialog import androidx.core.view.isVisible @@ -10,9 +10,10 @@ import androidx.core.view.marginRight import androidx.core.view.marginTop import com.google.android.material.bottomsheet.BottomSheetDialog import com.lagradost.cloudstream3.R +import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe object SingleSelectionHelper { - fun Context.showDialog( + fun Activity.showDialog( dialog: Dialog, items: List, selectedIndex: List, @@ -70,7 +71,7 @@ object SingleSelectionHelper { } } else { callback.invoke(listOf(which)) - dialog.dismiss() + dialog.dismissSafe(this) } } if (realShowApply) { @@ -81,15 +82,15 @@ object SingleSelectionHelper { list.add(index) } callback.invoke(list) - dialog.dismiss() + dialog.dismissSafe(this) } cancelButton.setOnClickListener { - dialog.dismiss() + dialog.dismissSafe(this) } } } - fun Context.showMultiDialog( + fun Activity.showMultiDialog( items: List, selectedIndex: List, name: String, @@ -104,7 +105,7 @@ object SingleSelectionHelper { showDialog(dialog, items, selectedIndex, name, true, true, callback, dismissCallback) } - fun Context.showDialog( + fun Activity.showDialog( items: List, selectedIndex: Int, name: String, @@ -130,7 +131,7 @@ object SingleSelectionHelper { } /** Only for a low amount of items */ - fun Context.showBottomDialog( + fun Activity.showBottomDialog( items: List, selectedIndex: Int, name: String, diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt index 31a15334..50d3de29 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt @@ -4,6 +4,7 @@ import android.Manifest import android.annotation.SuppressLint import android.app.Activity import android.app.AppOpsManager +import android.app.Dialog import android.content.Context import android.content.pm.PackageManager import android.content.res.Resources @@ -293,8 +294,13 @@ object UIHelper { } fun Context.shouldShowPIPMode(isInPlayer: Boolean): Boolean { - val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) - return settingsManager?.getBoolean("pip_enabled", true) ?: true && isInPlayer + return try { + val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) + settingsManager?.getBoolean(getString(R.string.pip_enabled_key), true) ?: true && isInPlayer + } catch (e : Exception) { + logError(e) + false + } } @RequiresApi(Build.VERSION_CODES.O) @@ -319,6 +325,12 @@ object UIHelper { inputMethodManager?.showSoftInput(view, 0) } + fun Dialog?.dismissSafe(activity: Activity?) { + if (this?.isShowing == true && activity?.isFinishing == false) { + this.dismiss() + } + } + /**id, stringRes */ @SuppressLint("RestrictedApi") fun View.popupMenuNoIcons( diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml deleted file mode 100644 index 59fd05e9..00000000 --- a/app/src/main/res/layout-land/activity_main.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4deb00ad..f577b1d5 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -11,6 +11,22 @@ + + + + diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 6af2cb75..22a456e0 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -140,7 +140,7 @@ Verwijderen Pauze Hervat - Dit wordt zeker permanent verwijderd %a\Weet u het zeker? + Dit wordt zeker permanent verwijderd %s\nWeet u het zeker? Lopend Voltooid