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
|
2022-06-04 00:11:32 +00:00
|
|
|
import androidx.annotation.StringRes
|
2022-06-03 17:18:13 +00:00
|
|
|
import androidx.core.view.isVisible
|
2022-05-15 18:38:32 +00:00
|
|
|
import androidx.fragment.app.Fragment
|
2022-08-06 23:43:39 +00:00
|
|
|
import androidx.navigation.fragment.findNavController
|
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
|
2021-06-10 23:00:22 +00:00
|
|
|
import com.lagradost.cloudstream3.R
|
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
|
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-05-15 18:38:32 +00:00
|
|
|
import kotlinx.android.synthetic.main.main_settings.*
|
2022-06-04 00:11:32 +00:00
|
|
|
import kotlinx.android.synthetic.main.settings_title_top.*
|
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
|
|
|
|
|
|
|
|
fun PreferenceFragmentCompat?.getPref(id: Int): Preference? {
|
|
|
|
if (this == null) return null
|
|
|
|
|
|
|
|
return try {
|
|
|
|
findPreference(getString(id))
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
|
|
|
null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-09 13:50:55 +00:00
|
|
|
fun PreferenceFragmentCompat?.setUpToolbar(@StringRes title: Int) {
|
2022-06-04 00:11:32 +00:00
|
|
|
if (this == null) return
|
|
|
|
settings_toolbar?.apply {
|
|
|
|
setTitle(title)
|
|
|
|
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
|
|
|
|
setNavigationOnClickListener {
|
|
|
|
activity?.onBackPressed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
context.fixPaddingStatusbar(settings_toolbar)
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun Context.isTvSettings(): Boolean {
|
|
|
|
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-03-04 15:39:56 +00:00
|
|
|
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-03-04 15:39:56 +00:00
|
|
|
fun Context.isEmulatorSettings(): Boolean {
|
2022-02-18 19:54:55 +00:00
|
|
|
return getLayoutInt() == 2
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-15 18:38:32 +00:00
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?,
|
|
|
|
): View? {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-05-27 16:39:00 +00:00
|
|
|
val isTrueTv = context?.isTrueTvSettings() == true
|
|
|
|
|
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
|
|
|
|
if (settings_profile_pic?.setImage(
|
|
|
|
pic,
|
|
|
|
errorImageDrawable = HomeFragment.errorProfilePic
|
|
|
|
) == true
|
|
|
|
) {
|
|
|
|
settings_profile_text?.text = login.name
|
|
|
|
settings_profile?.isVisible = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-27 16:39:00 +00:00
|
|
|
listOf(
|
2022-06-09 13:50:55 +00:00
|
|
|
Pair(settings_general, R.id.action_navigation_settings_to_navigation_settings_general),
|
2022-05-27 16:39:00 +00:00
|
|
|
Pair(settings_player, R.id.action_navigation_settings_to_navigation_settings_player),
|
|
|
|
Pair(settings_credits, R.id.action_navigation_settings_to_navigation_settings_account),
|
|
|
|
Pair(settings_ui, R.id.action_navigation_settings_to_navigation_settings_ui),
|
|
|
|
Pair(settings_lang, R.id.action_navigation_settings_to_navigation_settings_lang),
|
|
|
|
Pair(settings_updates, R.id.action_navigation_settings_to_navigation_settings_updates),
|
2022-08-06 23:43:39 +00:00
|
|
|
Pair(settings_extensions, R.id.action_navigation_settings_to_navigation_settings_extensions),
|
2022-05-27 16:39:00 +00:00
|
|
|
).forEach { (view, navigationId) ->
|
|
|
|
view?.apply {
|
|
|
|
setOnClickListener {
|
|
|
|
navigate(navigationId)
|
|
|
|
}
|
|
|
|
if (isTrueTv) {
|
|
|
|
isFocusable = true
|
|
|
|
isFocusableInTouchMode = true
|
|
|
|
}
|
|
|
|
}
|
2021-09-23 18:08:57 +00:00
|
|
|
}
|
2021-11-04 10:42:51 +00:00
|
|
|
}
|
2022-05-15 18:38:32 +00:00
|
|
|
}
|