2021-06-10 23:00:22 +00:00
|
|
|
package com.lagradost.cloudstream3.ui.settings
|
|
|
|
|
2021-10-30 18:14:12 +00:00
|
|
|
import android.app.UiModeManager
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.res.Configuration
|
2021-12-16 23:45:20 +00:00
|
|
|
import android.os.Build
|
2021-06-10 23:00:22 +00:00
|
|
|
import android.os.Bundle
|
2022-05-15 18:38:32 +00:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2023-07-30 03:05:13 +00:00
|
|
|
import android.widget.ImageView
|
2022-06-04 00:11:32 +00:00
|
|
|
import androidx.annotation.StringRes
|
2023-07-30 03:05:13 +00:00
|
|
|
import androidx.core.view.children
|
2022-06-03 17:18:13 +00:00
|
|
|
import androidx.core.view.isVisible
|
2023-11-02 19:50:49 +00:00
|
|
|
import androidx.core.view.updateLayoutParams
|
2022-05-15 18:38:32 +00:00
|
|
|
import androidx.fragment.app.Fragment
|
2021-08-07 01:53:45 +00:00
|
|
|
import androidx.preference.Preference
|
2021-06-10 23:00:22 +00:00
|
|
|
import androidx.preference.PreferenceFragmentCompat
|
2021-08-30 21:42:58 +00:00
|
|
|
import androidx.preference.PreferenceManager
|
2023-11-02 19:50:49 +00:00
|
|
|
import com.google.android.material.appbar.AppBarLayout
|
2023-07-14 00:28:49 +00:00
|
|
|
import com.google.android.material.appbar.MaterialToolbar
|
2024-03-08 00:45:20 +00:00
|
|
|
import com.lagradost.cloudstream3.AcraApplication.Companion.context
|
2021-06-10 23:00:22 +00:00
|
|
|
import com.lagradost.cloudstream3.R
|
2023-07-14 00:28:49 +00:00
|
|
|
import com.lagradost.cloudstream3.databinding.MainSettingsBinding
|
2021-09-02 14:06:43 +00:00
|
|
|
import com.lagradost.cloudstream3.mvvm.logError
|
2022-06-07 16:38:24 +00:00
|
|
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers
|
2022-06-03 17:18:13 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.home.HomeFragment
|
2024-03-13 23:04:58 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.result.txt
|
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.clipboardHelper
|
2022-06-04 00:11:32 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
|
2022-05-15 18:38:32 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
2022-06-03 17:18:13 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
2022-08-21 20:13:53 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.toPx
|
2021-11-01 15:33:46 +00:00
|
|
|
import java.io.File
|
2021-09-02 14:06:43 +00:00
|
|
|
|
2022-05-15 18:38:32 +00:00
|
|
|
class SettingsFragment : Fragment() {
|
2021-10-30 18:14:12 +00:00
|
|
|
companion object {
|
2022-05-15 18:38:32 +00:00
|
|
|
var beneneCount = 0
|
|
|
|
|
2023-07-14 00:28:49 +00:00
|
|
|
private var isTv: Boolean = false
|
|
|
|
private var isTrueTv: Boolean = false
|
2022-08-28 23:52:15 +00:00
|
|
|
|
2022-05-15 18:38:32 +00:00
|
|
|
fun PreferenceFragmentCompat?.getPref(id: Int): Preference? {
|
|
|
|
if (this == null) return null
|
|
|
|
|
|
|
|
return try {
|
|
|
|
findPreference(getString(id))
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
|
|
|
null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-21 20:13:53 +00:00
|
|
|
/**
|
|
|
|
* On TV you cannot properly scroll to the bottom of settings, this fixes that.
|
|
|
|
* */
|
|
|
|
fun PreferenceFragmentCompat.setPaddingBottom() {
|
2022-08-28 23:52:15 +00:00
|
|
|
if (isTvSettings()) {
|
2022-08-21 20:13:53 +00:00
|
|
|
listView?.setPadding(0, 0, 0, 100.toPx)
|
|
|
|
}
|
|
|
|
}
|
2023-11-02 19:50:49 +00:00
|
|
|
fun PreferenceFragmentCompat.setToolBarScrollFlags() {
|
|
|
|
if (isTvSettings()) {
|
|
|
|
val settingsAppbar = view?.findViewById<MaterialToolbar>(R.id.settings_toolbar)
|
2022-08-21 20:13:53 +00:00
|
|
|
|
2023-11-02 19:50:49 +00:00
|
|
|
settingsAppbar?.updateLayoutParams<AppBarLayout.LayoutParams> {
|
|
|
|
scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-10 14:36:38 +00:00
|
|
|
fun Fragment?.setToolBarScrollFlags() {
|
|
|
|
if (isTvSettings()) {
|
|
|
|
val settingsAppbar = this?.view?.findViewById<MaterialToolbar>(R.id.settings_toolbar)
|
|
|
|
|
|
|
|
settingsAppbar?.updateLayoutParams<AppBarLayout.LayoutParams> {
|
|
|
|
scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-07 21:11:13 +00:00
|
|
|
fun Fragment?.setUpToolbar(title: String) {
|
|
|
|
if (this == null) return
|
2023-07-14 00:28:49 +00:00
|
|
|
val settingsToolbar = view?.findViewById<MaterialToolbar>(R.id.settings_toolbar) ?: return
|
|
|
|
|
|
|
|
settingsToolbar.apply {
|
2022-08-07 21:11:13 +00:00
|
|
|
setTitle(title)
|
|
|
|
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
|
|
|
|
setNavigationOnClickListener {
|
2023-11-10 23:48:53 +00:00
|
|
|
activity?.onBackPressedDispatcher?.onBackPressed()
|
2022-08-07 21:11:13 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-14 00:28:49 +00:00
|
|
|
fixPaddingStatusbar(settingsToolbar)
|
2022-08-07 21:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fun Fragment?.setUpToolbar(@StringRes title: Int) {
|
2022-06-04 00:11:32 +00:00
|
|
|
if (this == null) return
|
2023-07-14 00:28:49 +00:00
|
|
|
val settingsToolbar = view?.findViewById<MaterialToolbar>(R.id.settings_toolbar) ?: return
|
|
|
|
|
|
|
|
settingsToolbar.apply {
|
2022-06-04 00:11:32 +00:00
|
|
|
setTitle(title)
|
|
|
|
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
|
2023-07-30 03:05:13 +00:00
|
|
|
children.firstOrNull { it is ImageView }?.tag = getString(R.string.tv_no_focus_tag)
|
2022-06-04 00:11:32 +00:00
|
|
|
setNavigationOnClickListener {
|
2023-11-10 23:48:53 +00:00
|
|
|
activity?.onBackPressedDispatcher?.onBackPressed()
|
2022-06-04 00:11:32 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-14 00:28:49 +00:00
|
|
|
fixPaddingStatusbar(settingsToolbar)
|
2022-06-04 00:11:32 +00:00
|
|
|
}
|
|
|
|
|
2022-05-15 18:38:32 +00:00
|
|
|
fun getFolderSize(dir: File): Long {
|
|
|
|
var size: Long = 0
|
|
|
|
dir.listFiles()?.let {
|
|
|
|
for (file in it) {
|
|
|
|
size += if (file.isFile) {
|
|
|
|
// System.out.println(file.getName() + " " + file.length());
|
|
|
|
file.length()
|
|
|
|
} else getFolderSize(file)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
2022-03-04 15:39:56 +00:00
|
|
|
private fun Context.getLayoutInt(): Int {
|
2021-10-30 18:14:12 +00:00
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
2022-02-18 19:29:48 +00:00
|
|
|
return settingsManager.getInt(this.getString(R.string.app_layout_key), -1)
|
|
|
|
}
|
|
|
|
|
2022-08-28 23:52:15 +00:00
|
|
|
private fun Context.isTvSettings(): Boolean {
|
2022-02-18 19:29:48 +00:00
|
|
|
var value = getLayoutInt()
|
2021-10-30 18:14:12 +00:00
|
|
|
if (value == -1) {
|
|
|
|
value = if (isAutoTv()) 1 else 0
|
|
|
|
}
|
2022-02-18 19:29:48 +00:00
|
|
|
return value == 1 || value == 2
|
|
|
|
}
|
|
|
|
|
2022-08-28 23:52:15 +00:00
|
|
|
private fun Context.isTrueTvSettings(): Boolean {
|
2022-03-29 21:50:07 +00:00
|
|
|
var value = getLayoutInt()
|
|
|
|
if (value == -1) {
|
|
|
|
value = if (isAutoTv()) 1 else 0
|
|
|
|
}
|
|
|
|
return value == 1
|
2021-10-30 18:14:12 +00:00
|
|
|
}
|
|
|
|
|
2022-08-28 23:52:15 +00:00
|
|
|
fun Context.updateTv() {
|
|
|
|
isTrueTv = isTrueTvSettings()
|
|
|
|
isTv = isTvSettings()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun isTrueTvSettings(): Boolean {
|
|
|
|
return isTrueTv
|
|
|
|
}
|
|
|
|
|
|
|
|
fun isTvSettings(): Boolean {
|
|
|
|
return isTv
|
|
|
|
}
|
|
|
|
|
2022-03-04 15:39:56 +00:00
|
|
|
fun Context.isEmulatorSettings(): Boolean {
|
2022-02-18 19:54:55 +00:00
|
|
|
return getLayoutInt() == 2
|
|
|
|
}
|
|
|
|
|
2024-03-08 00:45:20 +00:00
|
|
|
// phone exclusive
|
|
|
|
fun isTruePhone(): Boolean {
|
|
|
|
return !isTrueTvSettings() && !isTvSettings() && context?.isEmulatorSettings() != true
|
|
|
|
}
|
|
|
|
|
2021-10-30 18:14:12 +00:00
|
|
|
private fun Context.isAutoTv(): Boolean {
|
|
|
|
val uiModeManager = getSystemService(Context.UI_MODE_SERVICE) as UiModeManager?
|
2022-05-05 21:50:08 +00:00
|
|
|
// AFT = Fire TV
|
2022-05-28 14:52:36 +00:00
|
|
|
val model = Build.MODEL.lowercase()
|
2022-05-15 18:38:32 +00:00
|
|
|
return uiModeManager?.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION || Build.MODEL.contains(
|
|
|
|
"AFT"
|
2022-05-28 14:52:36 +00:00
|
|
|
) || model.contains("firestick") || model.contains("fire tv") || model.contains("chromecast")
|
2021-10-30 18:14:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-14 00:28:49 +00:00
|
|
|
override fun onDestroyView() {
|
|
|
|
binding = null
|
|
|
|
super.onDestroyView()
|
|
|
|
}
|
|
|
|
|
|
|
|
var binding: MainSettingsBinding? = null
|
2022-05-15 18:38:32 +00:00
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?,
|
2023-07-14 00:28:49 +00:00
|
|
|
): View {
|
|
|
|
val localBinding = MainSettingsBinding.inflate(inflater, container, false)
|
|
|
|
binding = localBinding
|
|
|
|
return localBinding.root
|
|
|
|
//return inflater.inflate(R.layout.main_settings, container, false)
|
2021-11-08 18:13:39 +00:00
|
|
|
}
|
|
|
|
|
2022-05-15 18:38:32 +00:00
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
fun navigate(id: Int) {
|
|
|
|
activity?.navigate(id, Bundle())
|
2021-11-07 22:10:19 +00:00
|
|
|
}
|
|
|
|
|
2023-07-16 00:25:36 +00:00
|
|
|
// used to debug leaks showToast(activity,"${VideoDownloadManager.downloadStatusEvent.size} : ${VideoDownloadManager.downloadProgressEvent.size}")
|
|
|
|
|
2022-08-28 23:52:15 +00:00
|
|
|
val isTrueTv = isTrueTvSettings()
|
2022-05-27 16:39:00 +00:00
|
|
|
|
2022-06-07 16:38:24 +00:00
|
|
|
for (syncApi in accountManagers) {
|
2022-06-03 17:18:13 +00:00
|
|
|
val login = syncApi.loginInfo()
|
|
|
|
val pic = login?.profilePicture ?: continue
|
2023-07-14 00:28:49 +00:00
|
|
|
if (binding?.settingsProfilePic?.setImage(
|
2022-06-03 17:18:13 +00:00
|
|
|
pic,
|
|
|
|
errorImageDrawable = HomeFragment.errorProfilePic
|
|
|
|
) == true
|
|
|
|
) {
|
2023-07-14 00:28:49 +00:00
|
|
|
binding?.settingsProfileText?.text = login.name
|
|
|
|
binding?.settingsProfile?.isVisible = true
|
2022-06-03 17:18:13 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2023-07-14 00:28:49 +00:00
|
|
|
binding?.apply {
|
|
|
|
listOf(
|
2023-10-13 22:34:26 +00:00
|
|
|
settingsGeneral to R.id.action_navigation_global_to_navigation_settings_general,
|
|
|
|
settingsPlayer to R.id.action_navigation_global_to_navigation_settings_player,
|
|
|
|
settingsCredits to R.id.action_navigation_global_to_navigation_settings_account,
|
|
|
|
settingsUi to R.id.action_navigation_global_to_navigation_settings_ui,
|
|
|
|
settingsProviders to R.id.action_navigation_global_to_navigation_settings_providers,
|
|
|
|
settingsUpdates to R.id.action_navigation_global_to_navigation_settings_updates,
|
|
|
|
settingsExtensions to R.id.action_navigation_global_to_navigation_settings_extensions,
|
2023-07-14 00:28:49 +00:00
|
|
|
).forEach { (view, navigationId) ->
|
|
|
|
view.apply {
|
|
|
|
setOnClickListener {
|
|
|
|
navigate(navigationId)
|
|
|
|
}
|
|
|
|
if (isTrueTv) {
|
|
|
|
isFocusable = true
|
|
|
|
isFocusableInTouchMode = true
|
|
|
|
}
|
2022-05-27 16:39:00 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-18 21:22:39 +00:00
|
|
|
|
|
|
|
// Default focus on TV
|
|
|
|
if (isTrueTv) {
|
|
|
|
settingsGeneral.requestFocus()
|
|
|
|
}
|
2021-09-23 18:08:57 +00:00
|
|
|
}
|
2024-03-13 23:04:58 +00:00
|
|
|
|
|
|
|
val appVersion = getString(R.string.app_version)
|
|
|
|
val commitInfo = getString(R.string.commit_hash)
|
|
|
|
|
|
|
|
binding?.appVersionInfo?.setOnLongClickListener{
|
|
|
|
clipboardHelper(txt(R.string.extension_version), "$appVersion $commitInfo")
|
|
|
|
true
|
|
|
|
}
|
2021-11-04 10:42:51 +00:00
|
|
|
}
|
2023-10-13 22:34:26 +00:00
|
|
|
}
|