Commit 5d55932e authored by Geoffrey Métais's avatar Geoffrey Métais

Settings keys refactoring

Fix #874
parent 83e2cb3f
......@@ -20,9 +20,9 @@
package org.videolan.tools
open class SingletonHolder<out T, in A>(creator: (A) -> T) {
open class SingletonHolder<T, in A>(creator: (A) -> T) {
private var creator: ((A) -> T)? = creator
@Volatile private var instance: T? = null
@Volatile protected var instance: T? = null
fun getInstance(arg: A) = instance ?: synchronized(this) {
val i2 = instance
......
......@@ -4,15 +4,6 @@
android:key="video_category"
android:title="@string/video_prefs_category">
<ListPreference
android:defaultValue="6"
android:entries="@array/video_min_group_length_list"
android:entryValues="@array/video_min_group_length_values"
android:key="video_min_group_length"
android:persistent="true"
android:summary="@string/video_min_group_length_summary"
android:title="@string/video_min_group_length_title" />
<CheckBoxPreference
android:defaultValue="true"
android:key="media_seen"
......
......@@ -177,7 +177,7 @@ object ExternalMonitor : BroadcastReceiver(), LifecycleObserver, CoroutineScope
@ObsoleteCoroutinesApi
private fun checkNewStorages(ctx: Context) {
if (VLCApplication.mlInstance.isStarted) {
val scanOpt = if (AndroidDevices.showTvUi(ctx)) ML_SCAN_ON
val scanOpt = if (Settings.showTvUi) ML_SCAN_ON
else Settings.getInstance(ctx).getInt(KEY_MEDIALIBRARY_SCAN, -1)
if (scanOpt == ML_SCAN_ON)
AppScope.launch { ContextCompat.startForegroundService(ctx,Intent(ACTION_CHECK_STORAGES, null, ctx, MediaParsingService::class.java)) }
......
......@@ -445,7 +445,7 @@ fun Context.rescan() {
fun Context.startMedialibrary(firstRun: Boolean = false, upgrade: Boolean = false, parse: Boolean = true) = AppScope.launch {
if (Medialibrary.getInstance().isStarted || !Permissions.canReadStorage(this@startMedialibrary)) return@launch
val prefs = withContext(Dispatchers.IO) { Settings.getInstance(this@startMedialibrary) }
val scanOpt = if (AndroidDevices.showTvUi(this@startMedialibrary)) ML_SCAN_ON else prefs.getInt(KEY_MEDIALIBRARY_SCAN, -1)
val scanOpt = if (Settings.showTvUi) ML_SCAN_ON else prefs.getInt(KEY_MEDIALIBRARY_SCAN, -1)
if (parse && scanOpt == -1) {
if (dbExists()) prefs.edit().putInt(KEY_MEDIALIBRARY_SCAN, ML_SCAN_ON).apply()
}
......
......@@ -569,7 +569,7 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
NotificationHelper.createNotificationChannels(ctx.applicationContext)
startForeground(3, notification)
isForeground = true
if (isVideoPlaying || AndroidDevices.showTvUi(this) || stopped) hideNotification(true)
if (isVideoPlaying || Settings.showTvUi || stopped) hideNotification(true)
}
private fun sendStartSessionIdIntent() {
......@@ -649,7 +649,7 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private fun showNotificationInternal() {
if (!AndroidDevices.isAndroidTv && AndroidDevices.showTvUi(this)) return
if (!AndroidDevices.isAndroidTv && Settings.showTvUi) return
if (isPlayingPopup || !hasRenderer() && isVideoPlaying) {
hideNotificationInternal(true)
return
......
......@@ -58,19 +58,19 @@ class VLCApplication : Application() {
}
override fun onDisplay(dialog: Dialog.LoginDialog) {
val key = DialogActivity.KEY_LOGIN + sDialogCounter++
val key = DialogActivity.KEY_LOGIN + dialogCounter++
fireDialog(dialog, key)
}
override fun onDisplay(dialog: Dialog.QuestionDialog) {
if (!Util.byPassChromecastDialog(dialog)) {
val key = DialogActivity.KEY_QUESTION + sDialogCounter++
val key = DialogActivity.KEY_QUESTION + dialogCounter++
fireDialog(dialog, key)
}
}
override fun onDisplay(dialog: Dialog.ProgressDialog) {
val key = DialogActivity.KEY_PROGRESS + sDialogCounter++
val key = DialogActivity.KEY_PROGRESS + dialogCounter++
fireDialog(dialog, key)
}
......@@ -100,7 +100,6 @@ class VLCApplication : Application() {
// Set the locale for API < 24 and set application resources and direction for API >=24
UiTools.setLocale(appContext!!)
})
showVideoThumbs = Settings.getInstance(baseContext).getBoolean("show_video_thumbnails", true)
runIO(Runnable {
if (AndroidUtil.isOOrLater)
......@@ -149,13 +148,11 @@ class VLCApplication : Application() {
@Volatile
private var instance: Application? = null
var sPlayerSleepTime: Calendar? = null
var playerSleepTime: Calendar? = null
private val sDataMap = SimpleArrayMap<String, WeakReference<Any>>()
private val dataMap = SimpleArrayMap<String, WeakReference<Any>>()
private var sDialogCounter = 0
var showVideoThumbs = true
private var dialogCounter = 0
// Property to get the new locale only on restart to prevent change the locale partially on runtime
var locale: String? = ""
......@@ -187,23 +184,23 @@ class VLCApplication : Application() {
* @return the main resources from the Application
*/
val appResources: Resources
get() = appContext!!.resources
get() = appContext.resources
fun storeData(key: String, data: Any) {
sDataMap.put(key, WeakReference(data))
dataMap.put(key, WeakReference(data))
}
fun getData(key: String): Any? {
val wr = sDataMap.remove(key)
val wr = dataMap.remove(key)
return wr?.get()
}
fun hasData(key: String): Boolean {
return sDataMap.containsKey(key)
return dataMap.containsKey(key)
}
fun clearData() {
sDataMap.clear()
dataMap.clear()
}
val mlInstance: Medialibrary
......
......@@ -201,7 +201,7 @@ open class AudioPlayerContainerActivity : BaseActivity(), CoroutineScope by Main
fun showTipViewIfNeeded(stubId: Int, settingKey: String) {
if (BuildConfig.DEBUG) return
val vsc = findViewById<View>(stubId)
if (vsc != null && !settings.getBoolean(settingKey, false) && !AndroidDevices.showTvUi(this)) {
if (vsc != null && !settings.getBoolean(settingKey, false) && !Settings.showTvUi) {
val v = (vsc as ViewStubCompat).inflate()
v.setOnClickListener { removeTipViewIfDisplayed() }
val okGotIt = v.findViewById<TextView>(R.id.okgotit_button)
......
......@@ -3,14 +3,12 @@ package org.videolan.vlc.gui
import android.content.SharedPreferences
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import org.videolan.vlc.R
import org.videolan.vlc.util.AndroidDevices
import org.videolan.vlc.gui.helpers.applyTheme
import org.videolan.vlc.util.Settings
open class BaseActivity : AppCompatActivity() {
protected lateinit var settings: SharedPreferences
lateinit var settings: SharedPreferences
override fun onCreate(savedInstanceState: Bundle?) {
settings = Settings.getInstance(this)
......@@ -18,20 +16,4 @@ open class BaseActivity : AppCompatActivity() {
applyTheme()
super.onCreate(savedInstanceState)
}
private fun applyTheme() {
if (AndroidDevices.showTvUi(this)) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
setTheme(R.style.Theme_VLC_Black)
return
}
if (settings.contains("app_theme")) {
AppCompatDelegate.setDefaultNightMode(Integer.valueOf(settings.getString("app_theme", "-1")!!))
} else if (settings.contains("daynight") || settings.contains("enable_black_theme")) { // legacy support
val daynight = settings.getBoolean("daynight", false)
val dark = settings.getBoolean("enable_black_theme", false)
val mode = if (dark) AppCompatDelegate.MODE_NIGHT_YES else if (daynight) AppCompatDelegate.MODE_NIGHT_AUTO else AppCompatDelegate.MODE_NIGHT_NO
AppCompatDelegate.setDefaultNightMode(mode)
}
}
}
......@@ -115,7 +115,7 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager
private fun setupNavigationView() {
navigationView = findViewById(R.id.navigation)
navigationView!!.menu.findItem(R.id.nav_history).isVisible = settings.getBoolean(PreferencesFragment.PLAYBACK_HISTORY, true)
navigationView!!.menu.findItem(R.id.nav_history).isVisible = settings.getBoolean(PLAYBACK_HISTORY, true)
}
override fun onPostCreate(savedInstanceState: Bundle?) {
......@@ -308,16 +308,16 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == ACTIVITY_RESULT_PREFERENCES) {
when (resultCode) {
PreferencesActivity.RESULT_RESCAN -> this.reloadLibrary()
PreferencesActivity.RESULT_RESTART, PreferencesActivity.RESULT_RESTART_APP -> {
val intent = Intent(this@MainActivity, if (resultCode == PreferencesActivity.RESULT_RESTART_APP) StartActivity::class.java else MainActivity::class.java)
RESULT_RESCAN -> this.reloadLibrary()
RESULT_RESTART, RESULT_RESTART_APP -> {
val intent = Intent(this@MainActivity, if (resultCode == RESULT_RESTART_APP) StartActivity::class.java else MainActivity::class.java)
finish()
startActivity(intent)
}
PreferencesActivity.RESULT_UPDATE_SEEN_MEDIA -> for (fragment in supportFragmentManager.fragments)
RESULT_UPDATE_SEEN_MEDIA -> for (fragment in supportFragmentManager.fragments)
if (fragment is VideoGridFragment)
fragment.updateSeenMediaMarker()
PreferencesActivity.RESULT_UPDATE_ARTISTS -> {
RESULT_UPDATE_ARTISTS -> {
val fragment = currentFragment
if (fragment is AudioBrowserFragment) fragment.viewModel.refresh()
}
......@@ -325,7 +325,7 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager
} else if (requestCode == ACTIVITY_RESULT_OPEN && resultCode == Activity.RESULT_OK) {
MediaUtils.openUri(this, data!!.data)
} else if (requestCode == ACTIVITY_RESULT_SECONDARY) {
if (resultCode == PreferencesActivity.RESULT_RESCAN) {
if (resultCode == RESULT_RESCAN) {
forceRefresh(currentFragment)
}
}
......
......@@ -15,7 +15,6 @@ import android.view.View
import android.view.WindowManager
import android.view.inputmethod.EditorInfo
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.recyclerview.widget.LinearLayoutManager
......@@ -27,12 +26,12 @@ import org.videolan.vlc.R
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.databinding.SearchActivityBinding
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.helpers.applyTheme
import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.util.Settings
import org.videolan.vlc.util.runIO
import org.videolan.vlc.util.runOnMainThread
open class SearchActivity : AppCompatActivity(), TextWatcher, TextView.OnEditorActionListener {
open class SearchActivity : BaseActivity(), TextWatcher, TextView.OnEditorActionListener {
private lateinit var medialibrary: Medialibrary
private lateinit var binding: SearchActivityBinding
......@@ -40,8 +39,7 @@ open class SearchActivity : AppCompatActivity(), TextWatcher, TextView.OnEditorA
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (Settings.getInstance(this).getBoolean("enable_black_theme", false))
setTheme(R.style.Theme_VLC_Black)
applyTheme()
val intent = intent
binding = DataBindingUtil.setContentView(this, R.layout.search_activity)
binding.handler = clickHandler
......
......@@ -39,13 +39,13 @@ import org.videolan.vlc.gui.audio.AudioAlbumsSongsFragment
import org.videolan.vlc.gui.audio.AudioBrowserFragment
import org.videolan.vlc.gui.browser.StorageBrowserFragment
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.preferences.PreferencesActivity
import org.videolan.vlc.gui.tv.TvUtil
import org.videolan.vlc.gui.video.VideoGridFragment
import org.videolan.vlc.reloadLibrary
import org.videolan.vlc.rescan
import org.videolan.vlc.util.AndroidDevices
import org.videolan.vlc.util.KEY_FOLDER
import org.videolan.vlc.util.RESULT_RESCAN
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
......@@ -97,7 +97,7 @@ class SecondaryActivity : ContentActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == ACTIVITY_RESULT_SECONDARY) {
if (resultCode == PreferencesActivity.RESULT_RESCAN) this.reloadLibrary()
if (resultCode == RESULT_RESCAN) this.reloadLibrary()
}
}
......
......@@ -46,16 +46,12 @@ import org.videolan.vlc.gui.AudioPlayerContainerActivity
import org.videolan.vlc.gui.ContentActivity
import org.videolan.vlc.gui.PlaylistActivity
import org.videolan.vlc.gui.SecondaryActivity
import org.videolan.vlc.gui.preferences.PreferencesActivity
import org.videolan.vlc.gui.view.FastScroller
import org.videolan.vlc.gui.view.RecyclerSectionItemDecoration
import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
import org.videolan.vlc.reloadLibrary
import org.videolan.vlc.util.CTX_PLAY_ALL
import org.videolan.vlc.util.KEY_AUDIO_CURRENT_TAB
import org.videolan.vlc.util.Settings
import org.videolan.vlc.util.WeakHandler
import org.videolan.vlc.util.*
import org.videolan.vlc.viewmodels.mobile.AudioBrowserViewModel
import org.videolan.vlc.viewmodels.mobile.getViewModel
import java.util.*
......@@ -114,7 +110,7 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>(), SwipeRef
val intent = Intent(applicationContext, SecondaryActivity::class.java)
intent.putExtra("fragment", SecondaryActivity.STORAGE_BROWSER)
startActivity(intent)
setResult(PreferencesActivity.RESULT_RESTART)
setResult(RESULT_RESTART)
}
}
}
......
......@@ -48,6 +48,7 @@ import org.videolan.vlc.databinding.BrowserItemSeparatorBinding
import org.videolan.vlc.gui.DiffUtilAdapter
import org.videolan.vlc.gui.helpers.SelectorViewHolder
import org.videolan.vlc.util.AndroidDevices
import org.videolan.vlc.util.Settings
import org.videolan.vlc.util.UPDATE_SELECTION
import java.util.*
......@@ -233,7 +234,7 @@ open class BaseBrowserAdapter() : DiffUtilAdapter<MediaLibraryItem, BaseBrowserA
override fun onLongClick(v: View): Boolean {
val position = layoutPosition
if (getItem(position).itemType == TYPE_STORAGE && AndroidDevices.showTvUi(itemView.context)) {
if (getItem(position).itemType == TYPE_STORAGE && Settings.showTvUi) {
binding.browserCheckbox.toggle()
onCheckBoxClick(binding.browserCheckbox)
return true
......
......@@ -91,7 +91,7 @@ class StorageBrowserFragment : FileBrowserFragment(), EntryPointsEventsCb {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if (isRootDirectory && AndroidDevices.showTvUi(view.context)) {
if (isRootDirectory && Settings.showTvUi) {
snack = com.google.android.material.snackbar.Snackbar.make(view, R.string.tv_settings_hint, com.google.android.material.snackbar.Snackbar.LENGTH_INDEFINITE)
if (AndroidUtil.isLolliPopOrLater) snack?.view?.elevation = view.resources.getDimensionPixelSize(R.dimen.audio_player_elevation).toFloat()
}
......
......@@ -33,11 +33,11 @@ import android.widget.EditText
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import org.videolan.libvlc.Dialog
import org.videolan.vlc.R
import org.videolan.vlc.databinding.VlcLoginDialogBinding
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.preferences.PreferencesActivity
import org.videolan.vlc.util.AndroidDevices
import org.videolan.vlc.util.LOGIN_STORE
import org.videolan.vlc.util.Settings
import org.videolan.vlc.databinding.VlcLoginDialogBinding
class VlcLoginDialog : VlcDialog<Dialog.LoginDialog, VlcLoginDialogBinding>(), View.OnFocusChangeListener {
......@@ -50,7 +50,7 @@ class VlcLoginDialog : VlcDialog<Dialog.LoginDialog, VlcLoginDialogBinding>(), V
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if (AndroidDevices.showTvUi(view.context) && !AndroidDevices.hasPlayServices) {
if (Settings.showTvUi && !AndroidDevices.hasPlayServices) {
binding.login.onFocusChangeListener = this
binding.password.onFocusChangeListener = this
}
......@@ -65,12 +65,12 @@ class VlcLoginDialog : VlcDialog<Dialog.LoginDialog, VlcLoginDialogBinding>(), V
fun onLogin(v: View) {
vlcDialog.postLogin(binding.login.text.toString().trim(),
binding.password.text.toString().trim(), binding.store.isChecked)
mSettings.edit().putBoolean(PreferencesActivity.LOGIN_STORE, binding.store.isChecked).apply()
mSettings.edit().putBoolean(LOGIN_STORE, binding.store.isChecked).apply()
dismiss()
}
fun store(): Boolean {
return mSettings.getBoolean(PreferencesActivity.LOGIN_STORE, true)
return mSettings.getBoolean(LOGIN_STORE, true)
}
override fun onFocusChange(v: View, hasFocus: Boolean) {
......
......@@ -27,6 +27,7 @@ import org.videolan.vlc.databinding.AudioBrowserTvItemBinding
import org.videolan.vlc.gui.tv.TvUtil
import org.videolan.vlc.util.AppScope
import org.videolan.vlc.util.HttpImageLoader
import org.videolan.vlc.util.Settings
import org.videolan.vlc.util.ThumbnailsProvider
import org.videolan.vlc.util.ThumbnailsProvider.obtainBitmap
......@@ -48,7 +49,7 @@ fun loadImage(v: View, item: MediaLibraryItem?) {
return
}
val isMedia = item.itemType == MediaLibraryItem.TYPE_MEDIA
if (isMedia && (item as MediaWrapper).type == MediaWrapper.TYPE_VIDEO && !VLCApplication.showVideoThumbs) {
if (isMedia && (item as MediaWrapper).type == MediaWrapper.TYPE_VIDEO && !Settings.showVideoThumbs) {
updateImageView(UiTools.getDefaultVideoDrawable(v.context).bitmap, v, binding)
return
}
......
......@@ -71,7 +71,6 @@ class PlayerOptionsDelegate(val activity: AppCompatActivity, val service: Playba
private val primary = activity is VideoPlayerActivity && activity.displayManager.isPrimary
private val video = activity is VideoPlayerActivity
private val res = activity.resources
private val tvUi by lazy(LazyThreadSafetyMode.NONE) { AndroidDevices.showTvUi(activity) }
private val settings = Settings.getInstance(activity)
private lateinit var abrBinding: PlayerOptionItemBinding
private lateinit var ptBinding: PlayerOptionItemBinding
......@@ -103,7 +102,7 @@ class PlayerOptionsDelegate(val activity: AppCompatActivity, val service: Playba
options.add(PlayerOption(playerOptionType, ID_JUMP_TO, R.attr.ic_jumpto_normal_style, res.getString(R.string.jump_to_time)))
options.add(PlayerOption(playerOptionType, ID_EQUALIZER, R.attr.ic_equalizer_normal_style, res.getString(R.string.equalizer)))
if (video) {
if (primary && !tvUi && service.audioTracksCount > 0)
if (primary && !Settings.showTvUi && service.audioTracksCount > 0)
options.add(PlayerOption(playerOptionType, ID_PLAY_AS_AUDIO, R.attr.ic_playasaudio_on, res.getString(R.string.play_as_audio)))
if (primary && AndroidDevices.pipAllowed && !AndroidDevices.isDex(activity))
options.add(PlayerOption(playerOptionType, ID_POPUP_VIDEO, R.attr.ic_popup_dim, res.getString(R.string.ctx_pip_title)))
......@@ -151,7 +150,7 @@ class PlayerOptionsDelegate(val activity: AppCompatActivity, val service: Playba
}
setup()
rootView.visibility = View.VISIBLE
if (AndroidDevices.showTvUi(activity)) AppScope.launch {
if (Settings.showTvUi) AppScope.launch {
delay(100L)
val position = (recyclerview.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
(recyclerview.layoutManager as LinearLayoutManager).findViewByPosition(position)?.requestFocus()
......@@ -172,7 +171,7 @@ class PlayerOptionsDelegate(val activity: AppCompatActivity, val service: Playba
PlayerOptionType.ADVANCED -> {
when (option.id) {
ID_SLEEP -> {
if (VLCApplication.sPlayerSleepTime == null)
if (VLCApplication.playerSleepTime == null)
showFragment(ID_SLEEP)
else {
activity.setSleep(null)
......@@ -283,12 +282,12 @@ class PlayerOptionsDelegate(val activity: AppCompatActivity, val service: Playba
}
private fun initSleep() {
sleepBinding.optionTitle.text = if (VLCApplication.sPlayerSleepTime == null) {
sleepBinding.optionTitle.text = if (VLCApplication.playerSleepTime == null) {
sleepBinding.optionIcon.setImageResource(UiTools.getResourceFromAttribute(activity, R.attr.ic_sleep_normal_style))
null
} else {
sleepBinding.optionIcon.setImageResource(R.drawable.ic_sleep_on)
DateFormat.getTimeFormat(activity).format(VLCApplication.sPlayerSleepTime!!.time)
DateFormat.getTimeFormat(activity).format(VLCApplication.playerSleepTime!!.time)
}
}
......@@ -420,7 +419,7 @@ fun Context.setSleep(time: Calendar?) {
if (time != null) alarmMgr.set(AlarmManager.RTC_WAKEUP, time.timeInMillis, sleepPendingIntent)
else alarmMgr.cancel(sleepPendingIntent)
VLCApplication.sPlayerSleepTime = time
VLCApplication.playerSleepTime = time
}
class PlayerOption(val type: PlayerOptionType, val id: Int, val icon: Int, val title: String)
......
......@@ -76,11 +76,13 @@ import java.util.TreeMap
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContextCompat
import androidx.databinding.BindingAdapter
import androidx.fragment.app.FragmentActivity
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.vlc.gui.BaseActivity
import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
@ObsoleteCoroutinesApi
......@@ -601,3 +603,19 @@ fun setTouchListener(view: View, onTouchListener: View.OnTouchListener?) {
fun isSelected(v: View, isSelected: Boolean?) {
v.isSelected = isSelected!!
}
fun BaseActivity.applyTheme() {
if (Settings.showTvUi) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
setTheme(R.style.Theme_VLC_Black)
return
}
if (settings.contains(KEY_APP_THEME)) {
AppCompatDelegate.setDefaultNightMode(Integer.valueOf(settings.getString(KEY_APP_THEME, "-1")!!))
} else if (settings.contains(KEY_DAYNIGHT) || settings.contains(KEY_BLACK_THEME)) { // legacy support
val daynight = settings.getBoolean(KEY_DAYNIGHT, false)
val dark = settings.getBoolean(KEY_BLACK_THEME, false)
val mode = if (dark) AppCompatDelegate.MODE_NIGHT_YES else if (daynight) AppCompatDelegate.MODE_NIGHT_AUTO else AppCompatDelegate.MODE_NIGHT_NO
AppCompatDelegate.setDefaultNightMode(mode)
}
}
......@@ -53,10 +53,10 @@ import org.videolan.vlc.gui.dialogs.showContext
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.tv.browser.interfaces.BrowserFragmentInterface
import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.util.AndroidDevices
import org.videolan.vlc.util.CTX_ADD_TO_PLAYLIST
import org.videolan.vlc.util.CTX_APPEND
import org.videolan.vlc.util.CTX_RENAME
import org.videolan.vlc.util.Settings
import org.videolan.vlc.viewmodels.StreamsModel
const val TAG = "VLC/MrlPanelFragment"
......@@ -91,7 +91,7 @@ class MRLPanelFragment : Fragment(), View.OnKeyListener, TextView.OnEditorAction
adapter = MRLAdapter(listEventActor)
val recyclerView = binding.mrlList
if (AndroidDevices.showTvUi(requireActivity())) {
if (Settings.showTvUi) {
val gridLayoutManager = GridLayoutManager(activity, 2)
recyclerView.addItemDecoration(object : RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
......
......@@ -18,7 +18,6 @@ import org.videolan.vlc.MediaParsingService
import org.videolan.vlc.R
import org.videolan.vlc.gui.MainActivity
import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate
import org.videolan.vlc.gui.preferences.PreferencesActivity
import org.videolan.vlc.gui.view.NonSwipeableViewPager
import org.videolan.vlc.startMedialibrary
import org.videolan.vlc.util.*
......@@ -126,14 +125,14 @@ class OnboardingActivity : AppCompatActivity(), ViewPager.OnPageChangeListener,
}
private fun completeOnBoarding() {
setResult(PreferencesActivity.RESULT_RESTART)
setResult(RESULT_RESTART)
Settings.getInstance(this)
.edit()
.putInt(PREF_FIRST_RUN, BuildConfig.VERSION_CODE)
.putBoolean(ONBOARDING_DONE_KEY, true)
.putInt(KEY_MEDIALIBRARY_SCAN, if (viewModel.scanStorages) ML_SCAN_ON else ML_SCAN_OFF)
.putInt("fragment_id", if (viewModel.scanStorages) R.id.nav_video else R.id.nav_directories)
.putString("app_theme", viewModel.theme.toString())
.putString(KEY_APP_THEME, viewModel.theme.toString())
.apply()
if (!viewModel.scanStorages) MediaParsingService.preselectedStorages.clear()
startMedialibrary(firstRun = true, upgrade = true, parse = viewModel.scanStorages)
......
......@@ -20,12 +20,9 @@
package org.videolan.vlc.gui.preferences
import android.app.Activity
import android.os.Bundle
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.widget.Toolbar
import androidx.core.view.ViewCompat
import com.google.android.material.appbar.AppBarLayout
......@@ -33,18 +30,18 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.vlc.PlaybackService
import org.videolan.vlc.R
import org.videolan.vlc.util.Settings
import org.videolan.vlc.gui.BaseActivity
import org.videolan.vlc.util.RESULT_RESTART
import org.videolan.vlc.util.RESULT_RESTART_APP
import org.videolan.vlc.util.RESULT_UPDATE_ARTISTS
@ObsoleteCoroutinesApi
@ExperimentalCoroutinesApi
class PreferencesActivity : AppCompatActivity() {
class PreferencesActivity : BaseActivity() {
private var mAppBarLayout: AppBarLayout? = null
override fun onCreate(savedInstanceState: Bundle?) {
/* Theme must be applied before super.onCreate */
applyTheme()
super.onCreate(savedInstanceState)
setContentView(R.layout.preferences_activity)
......@@ -71,18 +68,6 @@ class PreferencesActivity : AppCompatActivity() {
return super.onOptionsItemSelected(item)
}
private fun applyTheme() {
val pref = Settings.getInstance(this)
if (pref.contains("app_theme")) {
AppCompatDelegate.setDefaultNightMode(Integer.valueOf(pref.getString("app_theme", "-1")!!))
} else if (pref.contains("daynight") || pref.contains("enable_black_theme")) { // legacy support
val daynight = pref.getBoolean("daynight", false)
val dark = pref.getBoolean("enable_black_theme", false)
val mode = if (dark) AppCompatDelegate.MODE_NIGHT_YES else if (daynight) AppCompatDelegate.MODE_NIGHT_AUTO else AppCompatDelegate.MODE_NIGHT_NO
AppCompatDelegate.setDefaultNightMode(mode)
}
}
fun restartMediaPlayer() {
val le = PlaybackService.restartPlayer
if (le.hasObservers()) le.value = true
......@@ -111,27 +96,4 @@ class PreferencesActivity : AppCompatActivity() {
val le = PlaybackService.headSetDetection
if (le.hasObservers()) le.value = detect
}
companion object {
const val TAG = "VLC/PreferencesActivity"
val NAME = "VlcSharedPreferences"
const val VIDEO_RESUME_TIME = "VideoResumeTime"
const val VIDEO_PAUSED = "VideoPaused"
const val VIDEO_SPEED = "VideoSpeed"
const val VIDEO_RESTORE = "video_restore"
const val VIDEO_RATE = "video_rate"
const val VIDEO_RATIO = "video_ratio"
const val AUTO_RESCAN = "auto_rescan"
const val LOGIN_STORE = "store_login"
const val KEY_PLAYBACK_RATE = "playback_rate"
const val KEY_PLAYBACK_SPEED_PERSIST = "playback_speed"
const val KEY_VIDEO_APP_SWITCH = "video_action_switch"
const val RESULT_RESCAN = Activity.RESULT_FIRST_USER + 1
const val RESULT_RESTART = Activity.RESULT_FIRST_USER + 2
const val RESULT_RESTART_APP = Activity.RESULT_FIRST_USER + 3
const val RESULT_UPDATE_SEEN_MEDIA = Activity.RESULT_FIRST_USER + 4
const val RESULT_UPDATE_ARTISTS = Activity.RESULT_FIRST_USER + 5
}
}
......@@ -32,6 +32,7 @@ import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.libvlc.util.HWDecoderUtil
import org.videolan.vlc.R
import org.videolan.vlc.util.AUDIO_DUCKING
import org.videolan.vlc.util.KEY_ARTISTS_SHOW_ALL
import org.videolan.vlc.util.VLCInstance
......@@ -49,7 +50,7 @@ class PreferencesAudio : BasePreferenceFragment(), SharedPreferences.OnSharedPre
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
findPreference("audio_ducking").isVisible = !AndroidUtil.isOOrLater
findPreference(AUDIO_DUCKING).isVisible = !AndroidUtil.isOOrLater
val aout = HWDecoderUtil.getAudioOutputFromDevice()
if (aout != HWDecoderUtil.AudioOutput.ALL) {
/* no AudioOutput choice */
......
......@@ -38,19 +38,17 @@ import org.videolan.vlc.R
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.gui.SecondaryActivity
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.util.PLAYBACK_HISTORY
import org.videolan.vlc.util.Permissions
import org.videolan.vlc.util.RESULT_RESTART
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
class PreferencesFragment : BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener {
override fun getXml(): Int {
return R.xml.preferences
}
override fun getXml() = R.xml.preferences
override fun getTitleId(): Int {
return R.string.preferences
}
override fun getTitleId() = R.string.preferences
override fun onStart() {
super.onStart()
......@@ -78,7 +76,7 @@ class PreferencesFragment : BasePreferenceFragment(), SharedPreferences.OnShared
val intent = Intent(activity.applicationContext, SecondaryActivity::class.java)
intent.putExtra("fragment", SecondaryActivity.STORAGE_BROWSER)
startActivity(intent)
activity.setResult(PreferencesActivity.RESULT_RESTART)
activity.setResult(RESULT_RESTART)
}