fuck android (((also fixes)))

This commit is contained in:
LagradOst 2021-12-12 03:33:17 +01:00
parent ef91102daf
commit 486cea39c5
16 changed files with 248 additions and 229 deletions

View file

@ -31,7 +31,7 @@
<activity <activity
android:exported="true" android:exported="true"
android:name=".MainActivity" android:name=".MainActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden|navigation" android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden|navigation"
android:label="@string/app_name" android:label="@string/app_name"
android:resizeableActivity="true" android:resizeableActivity="true"
android:supportsPictureInPicture="true"> android:supportsPictureInPicture="true">

View file

@ -19,6 +19,7 @@ import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.navigation.NavDestination
import androidx.navigation.findNavController import androidx.navigation.findNavController
import androidx.navigation.ui.setupWithNavController import androidx.navigation.ui.setupWithNavController
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
@ -87,6 +88,38 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
override fun onConfigurationChanged(newConfig: Configuration) { override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig) super.onConfigurationChanged(newConfig)
updateLocale() // android fucks me by chaining lang when rotating the phone 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 //private var mCastSession: CastSession? = null
@ -553,30 +586,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
val navRail = findViewById<NavigationRailView?>(R.id.nav_rail_view) val navRail = findViewById<NavigationRailView?>(R.id.nav_rail_view)
navRail?.setupWithNavController(navController) navRail?.setupWithNavController(navController)
navController.addOnDestinationChangedListener { _, destination, _ -> navController.addOnDestinationChangedListener { _, destination, _ ->
this.hideKeyboard() updateNavBar(destination)
// 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
} }
/*nav_view.setOnNavigationItemSelectedListener { item -> /*nav_view.setOnNavigationItemSelectedListener { item ->

View file

@ -30,6 +30,7 @@ import com.lagradost.cloudstream3.utils.CastHelper.awaitLinks
import com.lagradost.cloudstream3.utils.CastHelper.getMediaInfo import com.lagradost.cloudstream3.utils.CastHelper.getMediaInfo
import com.lagradost.cloudstream3.utils.DataStore.toKotlinObject import com.lagradost.cloudstream3.utils.DataStore.toKotlinObject
import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
import org.json.JSONObject import org.json.JSONObject
import kotlin.concurrent.thread 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) loadMirror(which)
bottomSheetDialog.dismiss() bottomSheetDialog.dismissSafe(activity)
} }
} }
} }
} }

View file

@ -6,6 +6,7 @@ import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import com.lagradost.cloudstream3.MainActivity import com.lagradost.cloudstream3.MainActivity
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.ui.player.PlayerFragment import com.lagradost.cloudstream3.ui.player.PlayerFragment
import com.lagradost.cloudstream3.ui.player.UriData import com.lagradost.cloudstream3.ui.player.UriData
import com.lagradost.cloudstream3.utils.AppUtils.getNameFull import com.lagradost.cloudstream3.utils.AppUtils.getNameFull
@ -34,6 +35,7 @@ object DownloadButtonSetup {
} }
} }
try {
builder.setTitle(R.string.delete_file) builder.setTitle(R.string.delete_file)
.setMessage( .setMessage(
ctx.getString(R.string.delete_message).format( ctx.getString(R.string.delete_message).format(
@ -47,6 +49,10 @@ object DownloadButtonSetup {
.setPositiveButton(R.string.delete, dialogClickListener) .setPositiveButton(R.string.delete, dialogClickListener)
.setNegativeButton(R.string.cancel, dialogClickListener) .setNegativeButton(R.string.cancel, dialogClickListener)
.show() .show()
} catch (e : Exception) {
logError(e)
// ye you somehow fucked up formatting did you?
}
} }
} }
DOWNLOAD_ACTION_PAUSE_DOWNLOAD -> { DOWNLOAD_ACTION_PAUSE_DOWNLOAD -> {

View file

@ -45,6 +45,7 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.removeLastWatched
import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultWatchState import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultWatchState
import com.lagradost.cloudstream3.utils.Event import com.lagradost.cloudstream3.utils.Event
import com.lagradost.cloudstream3.utils.HOMEPAGE_API 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.fixPaddingStatusbar
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbarView import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbarView
import com.lagradost.cloudstream3.utils.UIHelper.getGridIsCompact 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.popupMenuNoIconsAndNoStringRes
import com.lagradost.cloudstream3.utils.UIHelper.setImage import com.lagradost.cloudstream3.utils.UIHelper.setImage
import com.lagradost.cloudstream3.widget.CenterZoomLayoutManager import com.lagradost.cloudstream3.widget.CenterZoomLayoutManager
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_home.* import kotlinx.android.synthetic.main.fragment_home.*
import java.util.* import java.util.*
@ -72,7 +74,7 @@ class HomeFragment : Fragment() {
val titleHolder = bottomSheetDialogBuilder.findViewById<FrameLayout>(R.id.home_expanded_drag_down)!! val titleHolder = bottomSheetDialogBuilder.findViewById<FrameLayout>(R.id.home_expanded_drag_down)!!
titleHolder.setOnClickListener { titleHolder.setOnClickListener {
bottomSheetDialogBuilder.dismiss() bottomSheetDialogBuilder.dismissSafe(this)
} }
// Span settings // Span settings
@ -81,7 +83,7 @@ class HomeFragment : Fragment() {
recycle.adapter = SearchAdapter(item.list, recycle) { callback -> recycle.adapter = SearchAdapter(item.list, recycle) { callback ->
handleSearchClickCallback(this, callback) handleSearchClickCallback(this, callback)
if (callback.action == SEARCH_ACTION_LOAD || callback.action == SEARCH_ACTION_PLAY_FILE) { if (callback.action == SEARCH_ACTION_LOAD || callback.action == SEARCH_ACTION_PLAY_FILE) {
bottomSheetDialogBuilder.dismiss() bottomSheetDialogBuilder.dismissSafe(this)
} }
} }

View file

@ -88,6 +88,7 @@ import com.lagradost.cloudstream3.utils.DataStore.setKey
import com.lagradost.cloudstream3.utils.DataStoreHelper.setLastWatched import com.lagradost.cloudstream3.utils.DataStoreHelper.setLastWatched
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute 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.getNavigationBarHeight
import com.lagradost.cloudstream3.utils.UIHelper.getStatusBarHeight import com.lagradost.cloudstream3.utils.UIHelper.getStatusBarHeight
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
@ -125,12 +126,12 @@ const val OPENING_PERCENTAGE = 50
const val AUTOLOAD_NEXT_EPISODE_PERCENTAGE = 80 const val AUTOLOAD_NEXT_EPISODE_PERCENTAGE = 80
enum class PlayerEventType(val value: Int) { enum class PlayerEventType(val value: Int) {
Stop(-1), //Stop(-1),
Pause(0), Pause(0),
Play(1), Play(1),
SeekForward(2), SeekForward(2),
SeekBack(3), SeekBack(3),
SkipCurrentChapter(4), //SkipCurrentChapter(4),
NextEpisode(5), NextEpisode(5),
PrevEpisode(5), PrevEpisode(5),
PlayPauseToggle(7), 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) listOf(0.5f, 0.75f, 0.85f, 1f, 1.15f, 1.25f, 1.4f, 1.5f, 1.75f, 2f)
val speedIndex = speedsNumbers.indexOf(playbackSpeed) val speedIndex = speedsNumbers.indexOf(playbackSpeed)
context?.let { ctx -> activity?.let { act ->
ctx.showDialog( act.showDialog(
speedsText, speedsText,
speedIndex, speedIndex,
ctx.getString(R.string.player_speed), act.getString(R.string.player_speed),
false, false,
{ {
activity?.hideSystemUI() activity?.hideSystemUI()
@ -1236,7 +1237,7 @@ class PlayerFragment : Fragment() {
autoHide() autoHide()
saveArguments() saveArguments()
SubtitlesFragment.push(activity) SubtitlesFragment.push(activity)
sourceDialog.dismiss() sourceDialog.dismissSafe(activity)
} }
var sourceIndex = 0 var sourceIndex = 0
var startSource = 0 var startSource = 0
@ -1297,7 +1298,7 @@ class PlayerFragment : Fragment() {
} }
cancelButton.setOnClickListener { cancelButton.setOnClickListener {
sourceDialog.dismiss() sourceDialog.dismissSafe(activity)
} }
applyButton.setOnClickListener { applyButton.setOnClickListener {
@ -1324,7 +1325,7 @@ class PlayerFragment : Fragment() {
if (init) { if (init) {
initPlayer(getCurrentUrl()) initPlayer(getCurrentUrl())
} }
sourceDialog.dismiss() sourceDialog.dismissSafe(activity)
} }
} }
} }
@ -1796,12 +1797,16 @@ class PlayerFragment : Fragment() {
} }
private fun getCurrentUrl(): ExtractorLink? { private fun getCurrentUrl(): ExtractorLink? {
try {
val urls = getUrls() ?: return null val urls = getUrls() ?: return null
for (i in urls) { for (i in urls) {
if (i.getId() == playerData.mirrorId) { if (i.getId() == playerData.mirrorId) {
return i return i
} }
} }
} catch (e : Exception) {
return null
}
return null return null
} }
@ -2189,11 +2194,11 @@ class PlayerFragment : Fragment() {
setUpstreamDataSourceFactory(getDataSourceFactory()) setUpstreamDataSourceFactory(getDataSourceFactory())
} }
val _exoPlayer = val exoPlayerBuilder =
ExoPlayer.Builder(requireContext()) ExoPlayer.Builder(requireContext())
.setTrackSelector(trackSelector) .setTrackSelector(trackSelector)
exoPlayer = _exoPlayer.build().apply { exoPlayer = exoPlayerBuilder.build().apply {
playWhenReady = isPlayerPlaying playWhenReady = isPlayerPlaying
seekTo(currentWindow, playbackPosition) seekTo(currentWindow, playbackPosition)
setMediaSource( setMediaSource(

View file

@ -61,6 +61,7 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
import com.lagradost.cloudstream3.utils.UIHelper.checkWrite import com.lagradost.cloudstream3.utils.UIHelper.checkWrite
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute 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.fixPaddingStatusbar
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
import com.lagradost.cloudstream3.utils.UIHelper.navigate import com.lagradost.cloudstream3.utils.UIHelper.navigate
@ -393,7 +394,7 @@ class ResultFragment : Fragment() {
val data = viewModel.loadEpisode(episodeClick.data, isCasting) val data = viewModel.loadEpisode(episodeClick.data, isCasting)
if (currentLoadingCount != currentLoad) return false if (currentLoadingCount != currentLoad) return false
loadingDialog?.dismiss() loadingDialog?.dismissSafe(activity)
when (data) { when (data) {
is Resource.Success -> { is Resource.Success -> {
@ -627,7 +628,7 @@ class ResultFragment : Fragment() {
verifiedOptions.toTypedArray() verifiedOptions.toTypedArray()
) { _, which -> ) { _, which ->
handleAction(EpisodeClickEvent(verifiedOptionsValues[which], episodeClick.data)) handleAction(EpisodeClickEvent(verifiedOptionsValues[which], episodeClick.data))
dialog?.dismiss() dialog?.dismissSafe(activity)
} }
dialog = builder.create() dialog = builder.create()
@ -636,6 +637,7 @@ class ResultFragment : Fragment() {
} }
ACTION_COPY_LINK -> { ACTION_COPY_LINK -> {
activity?.let { act -> activity?.let { act ->
try {
acquireSingeExtractorLink(act.getString(R.string.episode_action_copy_link)) { link -> acquireSingeExtractorLink(act.getString(R.string.episode_action_copy_link)) { link ->
val serviceClipboard = val serviceClipboard =
(act.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager?) (act.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager?)
@ -644,6 +646,10 @@ class ResultFragment : Fragment() {
serviceClipboard.setPrimaryClip(clip) serviceClipboard.setPrimaryClip(clip)
showToast(act, R.string.copy_link_toast, Toast.LENGTH_SHORT) showToast(act, R.string.copy_link_toast, Toast.LENGTH_SHORT)
} }
} catch (e: Exception) {
showToast(act, e.toString(), Toast.LENGTH_LONG)
logError(e)
}
} }
} }
@ -668,6 +674,7 @@ class ResultFragment : Fragment() {
ACTION_PLAY_EPISODE_IN_VLC_PLAYER -> { ACTION_PLAY_EPISODE_IN_VLC_PLAYER -> {
activity?.let { act -> activity?.let { act ->
try {
if (!act.checkWrite()) { if (!act.checkWrite()) {
act.requestRW() act.requestRW()
if (act.checkWrite()) return@main if (act.checkWrite()) return@main
@ -720,6 +727,10 @@ class ResultFragment : Fragment() {
vlcIntent.component = VLC_COMPONENT vlcIntent.component = VLC_COMPONENT
act.setKey(VLC_LAST_ID_KEY, episodeClick.data.id) act.setKey(VLC_LAST_ID_KEY, episodeClick.data.id)
act.startActivityForResult(vlcIntent, VLC_REQUEST_CODE) act.startActivityForResult(vlcIntent, VLC_REQUEST_CODE)
} catch (e: Exception) {
logError(e)
showToast(act, e.toString(), Toast.LENGTH_LONG)
}
} }
} }
@ -797,7 +808,7 @@ class ResultFragment : Fragment() {
} }
result_bookmark_fab?.setOnClickListener { fab -> result_bookmark_fab?.setOnClickListener { fab ->
fab.context.showBottomDialog( activity?.showBottomDialog(
WatchType.values().map { fab.context.getString(it.stringRes) }.toList(), WatchType.values().map { fab.context.getString(it.stringRes) }.toList(),
watchType.ordinal, watchType.ordinal,
fab.context.getString(R.string.action_add_to_bookmarks), fab.context.getString(R.string.action_add_to_bookmarks),

View file

@ -449,6 +449,7 @@ class ResultViewModel : ViewModel() {
data: String, data: String,
isCasting: Boolean, isCasting: Boolean,
): Resource<EpisodeData> { ): Resource<EpisodeData> {
println("LOAD EPISODE FFS")
if (_allEpisodes.value?.contains(id) == true) { if (_allEpisodes.value?.contains(id) == true) {
_allEpisodes.value?.remove(id) _allEpisodes.value?.remove(id)
} }

View file

@ -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.getKey
import com.lagradost.cloudstream3.utils.DataStore.setKey import com.lagradost.cloudstream3.utils.DataStore.setKey
import com.lagradost.cloudstream3.utils.SEARCH_PROVIDER_TOGGLE 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.fixPaddingStatusbar
import com.lagradost.cloudstream3.utils.UIHelper.getGridIsCompact import com.lagradost.cloudstream3.utils.UIHelper.getGridIsCompact
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
@ -255,11 +256,11 @@ class SearchFragment : Fragment() {
providersActive = activeApis providersActive = activeApis
typesActive = activeTypes typesActive = activeTypes
dialog.dismiss() dialog.dismissSafe(activity)
} }
cancelButton.setOnClickListener { cancelButton.setOnClickListener {
dialog.dismiss() dialog.dismissSafe(activity)
} }
//listView.setSelection(selectedIndex) //listView.setSelection(selectedIndex)

View file

@ -45,6 +45,7 @@ import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog
import com.lagradost.cloudstream3.utils.SubtitleHelper 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.hideKeyboard
import com.lagradost.cloudstream3.utils.UIHelper.setImage import com.lagradost.cloudstream3.utils.UIHelper.setImage
import com.lagradost.cloudstream3.utils.VideoDownloadManager.getBasePath import com.lagradost.cloudstream3.utils.VideoDownloadManager.getBasePath
@ -147,7 +148,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
} }
api.accountIndex = ogIndex api.accountIndex = ogIndex
val adapter = AccountAdapter(items, R.layout.account_single) { val adapter = AccountAdapter(items, R.layout.account_single) {
dialog?.dismiss() dialog?.dismissSafe(activity)
api.changeAccount(it.view.context, it.card.accountIndex) api.changeAccount(it.view.context, it.card.accountIndex)
} }
val list = dialog.findViewById<RecyclerView>(R.id.account_list) val list = dialog.findViewById<RecyclerView>(R.id.account_list)
@ -163,14 +164,14 @@ class SettingsFragment : PreferenceFragmentCompat() {
dialog.findViewById<TextView>(R.id.account_logout)?.setOnClickListener { dialog.findViewById<TextView>(R.id.account_logout)?.setOnClickListener {
it.context?.let { ctx -> it.context?.let { ctx ->
api.logOut(ctx) api.logOut(ctx)
dialog.dismiss() dialog.dismissSafe(activity)
} }
} }
dialog.findViewById<TextView>(R.id.account_name)?.text = info.name ?: context.getString(R.string.no_data) dialog.findViewById<TextView>(R.id.account_name)?.text = info.name ?: context.getString(R.string.no_data)
dialog.findViewById<TextView>(R.id.account_site)?.text = api.name dialog.findViewById<TextView>(R.id.account_site)?.text = api.name
dialog.findViewById<TextView>(R.id.account_switch_account)?.setOnClickListener { dialog.findViewById<TextView>(R.id.account_switch_account)?.setOnClickListener {
dialog.dismiss() dialog.dismissSafe(activity)
showAccountSwitch(it.context, api) showAccountSwitch(it.context, api)
} }
} }
@ -178,6 +179,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
hideKeyboard() hideKeyboard()
setPreferencesFromResource(R.xml.settings, rootKey) setPreferencesFromResource(R.xml.settings, rootKey)
val updatePreference = findPreference<Preference>(getString(R.string.manual_check_update_key))!! val updatePreference = findPreference<Preference>(getString(R.string.manual_check_update_key))!!
val localePreference = findPreference<Preference>(getString(R.string.locale_key))!! val localePreference = findPreference<Preference>(getString(R.string.locale_key))!!
val benenePreference = findPreference<Preference>(getString(R.string.benene_count))!! val benenePreference = findPreference<Preference>(getString(R.string.benene_count))!!
@ -191,6 +193,12 @@ class SettingsFragment : PreferenceFragmentCompat() {
val colorPrimaryPreference = findPreference<Preference>(getString(R.string.primary_color_key))!! val colorPrimaryPreference = findPreference<Preference>(getString(R.string.primary_color_key))!!
val preferedMediaTypePreference = findPreference<Preference>(getString(R.string.prefer_media_type_key))!! val preferedMediaTypePreference = findPreference<Preference>(getString(R.string.prefer_media_type_key))!!
val appThemePreference = findPreference<Preference>(getString(R.string.app_theme_key))!! val appThemePreference = findPreference<Preference>(getString(R.string.app_theme_key))!!
val subPreference = findPreference<Preference>(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)) val syncApis = listOf(Pair(R.string.mal_key, malApi), Pair(R.string.anilist_key, aniListApi))
for (sync in syncApis) { for (sync in syncApis) {
@ -233,7 +241,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
currentList.add(dublist.indexOf(i)) currentList.add(dublist.indexOf(i))
} }
context?.showMultiDialog( activity?.showMultiDialog(
names, names,
currentList, currentList,
getString(R.string.display_subbed_dubbed_settings), getString(R.string.display_subbed_dubbed_settings),
@ -276,7 +284,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
Pair(it, fullName) Pair(it, fullName)
} }
context?.showMultiDialog( activity?.showMultiDialog(
names.map { it.second }, names.map { it.second },
currentList, currentList,
getString(R.string.provider_lang_settings), getString(R.string.provider_lang_settings),
@ -299,12 +307,16 @@ class SettingsFragment : PreferenceFragmentCompat() {
// DOES NOT WORK ON SCOPED STORAGE. // DOES NOT WORK ON SCOPED STORAGE.
val secondaryDir = if (isScopedStorage) null else Environment.getExternalStorageDirectory().absolutePath + val secondaryDir = if (isScopedStorage) null else Environment.getExternalStorageDirectory().absolutePath +
File.separator + resources.getString(R.string.app_name_download_path) 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) + (first +
requireContext().getExternalFilesDirs("").mapNotNull { it.path } + requireContext().getExternalFilesDirs("").mapNotNull { it.path } +
currentDir).filterNotNull().distinct() currentDir)
} catch (e: Exception) {
first
}).filterNotNull().distinct()
} }
downloadPathPreference.setOnPreferenceClickListener { downloadPathPreference.setOnPreferenceClickListener {
@ -314,7 +326,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
val currentDir = val currentDir =
settingsManager.getString(getString(R.string.download_path_pref), null) ?: getDownloadDir().toString() settingsManager.getString(getString(R.string.download_path_pref), null) ?: getDownloadDir().toString()
context?.showBottomDialog( activity?.showBottomDialog(
dirs + listOf("Custom"), dirs + listOf("Custom"),
dirs.indexOf(currentDir), dirs.indexOf(currentDir),
getString(R.string.download_path_pref), getString(R.string.download_path_pref),
@ -342,7 +354,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
val currentPrefMedia = val currentPrefMedia =
settingsManager.getInt(getString(R.string.preferred_media_settings), 0) settingsManager.getInt(getString(R.string.preferred_media_settings), 0)
context?.showBottomDialog( activity?.showBottomDialog(
prefNames.toList(), prefNames.toList(),
prefValues.indexOf(currentPrefMedia), prefValues.indexOf(currentPrefMedia),
getString(R.string.preferred_media_settings), getString(R.string.preferred_media_settings),
@ -352,7 +364,11 @@ class SettingsFragment : PreferenceFragmentCompat() {
.putInt(getString(R.string.preferred_media_settings), prefValues[it]) .putInt(getString(R.string.preferred_media_settings), prefValues[it])
.apply() .apply()
val apilist = AppUtils.filterProviderByPreferredMedia(apis, prefValues[it]) 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?.setKey(HOMEPAGE_API, apiRandom)
(context ?: AcraApplication.context)?.let { ctx -> app.initClient(ctx) } (context ?: AcraApplication.context)?.let { ctx -> app.initClient(ctx) }
} }
@ -366,7 +382,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
val currentLayout = val currentLayout =
settingsManager.getInt(getString(R.string.app_layout_key), -1) settingsManager.getInt(getString(R.string.app_layout_key), -1)
context?.showBottomDialog(
activity?.showBottomDialog(
prefNames.toList(), prefNames.toList(),
prefValues.indexOf(currentLayout), prefValues.indexOf(currentLayout),
getString(R.string.app_layout), getString(R.string.app_layout),
@ -390,7 +407,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
val currentLayout = val currentLayout =
settingsManager.getString(getString(R.string.primary_color_key), prefValues.first()) settingsManager.getString(getString(R.string.primary_color_key), prefValues.first())
context?.showBottomDialog(
activity?.showBottomDialog(
prefNames.toList(), prefNames.toList(),
prefValues.indexOf(currentLayout), prefValues.indexOf(currentLayout),
getString(R.string.primary_color_settings), getString(R.string.primary_color_settings),
@ -414,7 +432,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
val currentLayout = val currentLayout =
settingsManager.getString(getString(R.string.app_theme_key), prefValues.first()) settingsManager.getString(getString(R.string.app_theme_key), prefValues.first())
context?.showBottomDialog(
activity?.showBottomDialog(
prefNames.toList(), prefNames.toList(),
prefValues.indexOf(currentLayout), prefValues.indexOf(currentLayout),
getString(R.string.app_theme_settings), getString(R.string.app_theme_settings),
@ -441,7 +460,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
getString(R.string.watch_quality_pref), getString(R.string.watch_quality_pref),
Qualities.values().last().value Qualities.values().last().value
) )
context?.showBottomDialog(
activity?.showBottomDialog(
prefNames.toList(), prefNames.toList(),
prefValues.indexOf(currentQuality), prefValues.indexOf(currentQuality),
getString(R.string.watch_quality_pref), getString(R.string.watch_quality_pref),
@ -460,7 +480,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
val currentDns = val currentDns =
settingsManager.getInt(getString(R.string.dns_pref), 0) settingsManager.getInt(getString(R.string.dns_pref), 0)
context?.showBottomDialog(
activity?.showBottomDialog(
prefNames.toList(), prefNames.toList(),
prefValues.indexOf(currentDns), prefValues.indexOf(currentDns),
getString(R.string.dns_pref), 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( if (beneneCount <= 0) getString(R.string.benene_count_text_none) else getString(R.string.benene_count_text).format(
beneneCount beneneCount
) )
benenePreference.setOnPreferenceClickListener { benenePreference.setOnPreferenceClickListener {
try { try {
beneneCount++ beneneCount++
@ -516,7 +538,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
val languageCodes = tempLangs.map { it.third } val languageCodes = tempLangs.map { it.third }
val languageNames = tempLangs.map { "${it.first} ${it.second}" } val languageNames = tempLangs.map { "${it.first} ${it.second}" }
val index = languageCodes.indexOf(current) val index = languageCodes.indexOf(current)
pref?.context?.showDialog(
activity?.showDialog(
languageNames, index, getString(R.string.app_language), true, { } languageNames, index, getString(R.string.app_language), true, { }
) { languageIndex -> ) { languageIndex ->
try { try {
@ -540,13 +563,4 @@ class SettingsFragment : PreferenceFragmentCompat() {
val conf = res.configuration val conf = res.configuration
return conf?.locale?.language ?: "en" 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)
}
} }

View file

@ -232,7 +232,7 @@ class SubtitlesFragment : Fragment() {
) )
//showBottomDialog //showBottomDialog
textView.context.showDialog( activity?.showDialog(
elevationTypes.map { it.second }, elevationTypes.map { it.second },
elevationTypes.map { it.first }.indexOf(state.elevation), elevationTypes.map { it.first }.indexOf(state.elevation),
(textView as TextView).text.toString(), (textView as TextView).text.toString(),
@ -263,7 +263,7 @@ class SubtitlesFragment : Fragment() {
) )
//showBottomDialog //showBottomDialog
textView.context.showDialog( activity?.showDialog(
edgeTypes.map { it.second }, edgeTypes.map { it.second },
edgeTypes.map { it.first }.indexOf(state.edgeType), edgeTypes.map { it.first }.indexOf(state.edgeType),
(textView as TextView).text.toString(), (textView as TextView).text.toString(),
@ -314,7 +314,7 @@ class SubtitlesFragment : Fragment() {
) )
//showBottomDialog //showBottomDialog
textView.context.showDialog( activity?.showDialog(
fontSizes.map { it.second }, fontSizes.map { it.second },
fontSizes.map { it.first }.indexOf(state.fixedTextSize), fontSizes.map { it.first }.indexOf(state.fixedTextSize),
(textView as TextView).text.toString(), (textView as TextView).text.toString(),
@ -353,7 +353,7 @@ class SubtitlesFragment : Fragment() {
) )
//showBottomDialog //showBottomDialog
textView.context.showDialog( activity?.showDialog(
fontTypes.map { it.second }, fontTypes.map { it.second },
fontTypes.map { it.first }.indexOf(state.typeface), fontTypes.map { it.first }.indexOf(state.typeface),
(textView as TextView).text.toString(), (textView as TextView).text.toString(),
@ -379,7 +379,7 @@ class SubtitlesFragment : Fragment() {
langMap.addAll(SubtitleHelper.languages) langMap.addAll(SubtitleHelper.languages)
val lang639_1 = langMap.map { it.ISO_639_1 } val lang639_1 = langMap.map { it.ISO_639_1 }
textView.context.showDialog( activity?.showDialog(
langMap.map { it.languageName }, langMap.map { it.languageName },
lang639_1.indexOf(textView.context.getAutoSelectLanguageISO639_1()), lang639_1.indexOf(textView.context.getAutoSelectLanguageISO639_1()),
(textView as TextView).text.toString(), (textView as TextView).text.toString(),
@ -402,7 +402,7 @@ class SubtitlesFragment : Fragment() {
val keys = textView.context.getDownloadSubsLanguageISO639_1() val keys = textView.context.getDownloadSubsLanguageISO639_1()
val keyMap = keys.map { lang639_1.indexOf(it) }.filter { it >= 0 } val keyMap = keys.map { lang639_1.indexOf(it) }.filter { it >= 0 }
textView.context.showMultiDialog( activity?.showMultiDialog(
langMap.map { it.languageName }, langMap.map { it.languageName },
keyMap, keyMap,
(textView as TextView).text.toString(), (textView as TextView).text.toString(),

View file

@ -1,7 +1,7 @@
package com.lagradost.cloudstream3.utils package com.lagradost.cloudstream3.utils
import android.app.Activity
import android.app.Dialog import android.app.Dialog
import android.content.Context
import android.widget.* import android.widget.*
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible import androidx.core.view.isVisible
@ -10,9 +10,10 @@ import androidx.core.view.marginRight
import androidx.core.view.marginTop import androidx.core.view.marginTop
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
object SingleSelectionHelper { object SingleSelectionHelper {
fun Context.showDialog( fun Activity.showDialog(
dialog: Dialog, dialog: Dialog,
items: List<String>, items: List<String>,
selectedIndex: List<Int>, selectedIndex: List<Int>,
@ -70,7 +71,7 @@ object SingleSelectionHelper {
} }
} else { } else {
callback.invoke(listOf(which)) callback.invoke(listOf(which))
dialog.dismiss() dialog.dismissSafe(this)
} }
} }
if (realShowApply) { if (realShowApply) {
@ -81,15 +82,15 @@ object SingleSelectionHelper {
list.add(index) list.add(index)
} }
callback.invoke(list) callback.invoke(list)
dialog.dismiss() dialog.dismissSafe(this)
} }
cancelButton.setOnClickListener { cancelButton.setOnClickListener {
dialog.dismiss() dialog.dismissSafe(this)
} }
} }
} }
fun Context.showMultiDialog( fun Activity.showMultiDialog(
items: List<String>, items: List<String>,
selectedIndex: List<Int>, selectedIndex: List<Int>,
name: String, name: String,
@ -104,7 +105,7 @@ object SingleSelectionHelper {
showDialog(dialog, items, selectedIndex, name, true, true, callback, dismissCallback) showDialog(dialog, items, selectedIndex, name, true, true, callback, dismissCallback)
} }
fun Context.showDialog( fun Activity.showDialog(
items: List<String>, items: List<String>,
selectedIndex: Int, selectedIndex: Int,
name: String, name: String,
@ -130,7 +131,7 @@ object SingleSelectionHelper {
} }
/** Only for a low amount of items */ /** Only for a low amount of items */
fun Context.showBottomDialog( fun Activity.showBottomDialog(
items: List<String>, items: List<String>,
selectedIndex: Int, selectedIndex: Int,
name: String, name: String,

View file

@ -4,6 +4,7 @@ import android.Manifest
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.app.AppOpsManager import android.app.AppOpsManager
import android.app.Dialog
import android.content.Context import android.content.Context
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.res.Resources import android.content.res.Resources
@ -293,8 +294,13 @@ object UIHelper {
} }
fun Context.shouldShowPIPMode(isInPlayer: Boolean): Boolean { fun Context.shouldShowPIPMode(isInPlayer: Boolean): Boolean {
return try {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
return settingsManager?.getBoolean("pip_enabled", true) ?: true && isInPlayer settingsManager?.getBoolean(getString(R.string.pip_enabled_key), true) ?: true && isInPlayer
} catch (e : Exception) {
logError(e)
false
}
} }
@RequiresApi(Build.VERSION_CODES.O) @RequiresApi(Build.VERSION_CODES.O)
@ -319,6 +325,12 @@ object UIHelper {
inputMethodManager?.showSoftInput(view, 0) inputMethodManager?.showSoftInput(view, 0)
} }
fun Dialog?.dismissSafe(activity: Activity?) {
if (this?.isShowing == true && activity?.isFinishing == false) {
this.dismiss()
}
}
/**id, stringRes */ /**id, stringRes */
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
fun View.popupMenuNoIcons( fun View.popupMenuNoIcons(

View file

@ -1,63 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/homeRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|keyboard|navigation"
android:paddingTop="0dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<com.google.android.material.navigationrail.NavigationRailView
android:layout_width="62dp"
android:layout_height="match_parent"
android:id="@+id/nav_rail_view"
android:background="?attr/primaryGrayBackground"
app:itemTextColor="@color/item_select_color"
app:itemIconTint="@color/item_select_color"
app:menuGravity="center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:labelVisibilityMode="unlabeled"
app:menu="@menu/bottom_nav_menu">
</com.google.android.material.navigationrail.NavigationRailView>
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@id/cast_mini_controller_holder"
app:navGraph="@navigation/mobile_navigation"
app:layout_constraintStart_toEndOf="@id/nav_rail_view"
app:layout_constraintEnd_toEndOf="parent"/>
<LinearLayout
app:layout_constraintStart_toEndOf="@+id/nav_rail_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_height="100dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/cast_mini_controller_holder"
>
<!--com.google.android.gms.cast.framework.media.widget.MiniControllerFragment-->
<fragment
app:customCastBackgroundColor="?attr/primaryGrayBackground"
app:castControlButtons="@array/cast_mini_controller_control_buttons"
android:id="@+id/cast_mini_controller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
class="com.lagradost.cloudstream3.ui.MyMiniControllerFragment"
tools:ignore="FragmentTagUsage">
</fragment>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>

View file

@ -11,6 +11,22 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_width="match_parent"> android:layout_width="match_parent">
<com.google.android.material.navigationrail.NavigationRailView
android:layout_width="62dp"
android:layout_height="match_parent"
android:id="@+id/nav_rail_view"
android:background="?attr/primaryGrayBackground"
app:itemTextColor="@color/item_select_color"
app:itemIconTint="@color/item_select_color"
app:menuGravity="center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:labelVisibilityMode="unlabeled"
app:menu="@menu/bottom_nav_menu">
</com.google.android.material.navigationrail.NavigationRailView>
<com.google.android.material.bottomnavigation.BottomNavigationView <com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view" android:id="@+id/nav_view"
android:layout_width="0dp" android:layout_width="0dp"
@ -28,17 +44,20 @@
<fragment <fragment
android:id="@+id/nav_host_fragment" android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment" android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:defaultNavHost="true" app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation"
app:layout_constraintStart_toEndOf="@+id/nav_rail_view"
app:layout_constraintBottom_toTopOf="@+id/cast_mini_controller_holder" app:layout_constraintBottom_toTopOf="@+id/cast_mini_controller_holder"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation"
app:layout_constraintEnd_toEndOf="parent"/> app:layout_constraintEnd_toEndOf="parent"/>
<LinearLayout <LinearLayout
tools:layout_height="100dp" tools:layout_height="100dp"
android:layout_width="match_parent" android:layout_width="0dp"
app:layout_constraintStart_toEndOf="@+id/nav_rail_view"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/nav_view" app:layout_constraintBottom_toTopOf="@+id/nav_view"
android:id="@+id/cast_mini_controller_holder" android:id="@+id/cast_mini_controller_holder"
> >

View file

@ -140,7 +140,7 @@
<string name="delete">Verwijderen</string> <string name="delete">Verwijderen</string>
<string name="pause">Pauze</string> <string name="pause">Pauze</string>
<string name="resume">Hervat</string> <string name="resume">Hervat</string>
<string name="delete_message">Dit wordt zeker permanent verwijderd %a\Weet u het zeker?</string> <string name="delete_message">Dit wordt zeker permanent verwijderd %s\nWeet u het zeker?</string>
<string name="status_ongoing">Lopend</string> <string name="status_ongoing">Lopend</string>
<string name="status_completed">Voltooid</string> <string name="status_completed">Voltooid</string>