2021-06-10 23:00:22 +00:00
|
|
|
package com.lagradost.cloudstream3.ui.settings
|
|
|
|
|
|
|
|
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
|
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-20 07:33:50 +00:00
|
|
|
import com.lagradost.cloudstream3.BuildConfig
|
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
|
2024-03-17 02:37:09 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR
|
|
|
|
import com.lagradost.cloudstream3.ui.settings.Globals.TV
|
|
|
|
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
|
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper
|
2024-03-13 23:04:58 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.clipboardHelper
|
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
|
2024-03-24 23:59:55 +00:00
|
|
|
import java.text.DateFormat
|
|
|
|
import java.text.SimpleDateFormat
|
|
|
|
import java.util.Date
|
|
|
|
import java.util.Locale
|
|
|
|
import java.util.TimeZone
|
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-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() {
|
2024-03-17 02:37:09 +00:00
|
|
|
if (isLayout(TV or EMULATOR)) {
|
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() {
|
2024-03-17 02:37:09 +00:00
|
|
|
if (isLayout(TV or EMULATOR)) {
|
2023-11-02 19:50:49 +00:00
|
|
|
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() {
|
2024-03-17 02:37:09 +00:00
|
|
|
if (isLayout(TV or EMULATOR)) {
|
2023-11-10 14:36:38 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2024-03-17 02:37:09 +00:00
|
|
|
UIHelper.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
|
|
|
}
|
|
|
|
}
|
2024-03-17 02:37:09 +00:00
|
|
|
UIHelper.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
|
|
|
|
}
|
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-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)
|
|
|
|
}
|
2024-03-17 02:37:09 +00:00
|
|
|
if (isLayout(TV)) {
|
2023-07-14 00:28:49 +00:00
|
|
|
isFocusable = true
|
|
|
|
isFocusableInTouchMode = true
|
|
|
|
}
|
2022-05-27 16:39:00 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-18 21:22:39 +00:00
|
|
|
|
|
|
|
// Default focus on TV
|
2024-03-17 02:37:09 +00:00
|
|
|
if (isLayout(TV)) {
|
2023-09-18 21:22:39 +00:00
|
|
|
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)
|
2024-03-24 23:59:55 +00:00
|
|
|
val buildTimestamp = SimpleDateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG,
|
|
|
|
Locale.getDefault()
|
|
|
|
).apply { timeZone = TimeZone.getTimeZone("UTC")
|
|
|
|
}.format(Date(BuildConfig.BUILD_DATE)).replace("UTC", "")
|
|
|
|
|
|
|
|
binding?.buildDate?.text = buildTimestamp
|
|
|
|
binding?.appVersionInfo?.setOnLongClickListener {
|
|
|
|
clipboardHelper(txt(R.string.extension_version), "$appVersion $commitInfo $buildTimestamp")
|
2024-03-13 23:04:58 +00:00
|
|
|
true
|
|
|
|
}
|
2021-11-04 10:42:51 +00:00
|
|
|
}
|
2023-10-13 22:34:26 +00:00
|
|
|
}
|