Commit 67d39a97 authored by Geoffrey Métais's avatar Geoffrey Métais Committed by Geoffrey Métais
Browse files

Move Settings to tools module

parent d58bbca4
......@@ -26,6 +26,7 @@ android {
dependencies {
api "androidx.appcompat:appcompat:$rootProject.ext.androidxAppcompatVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.ext.archVersion"
implementation "androidx.preference:preference:$androidxPreferencesVersion"
api "androidx.tvprovider:tvprovider:$rootProject.ext.androidxLeanbackVersion"
implementation("com.squareup.okhttp3:logging-interceptor:4.2.1")
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
......
package org.videolan.vlc.util
package org.videolan.tools
import android.app.Activity
import android.content.Context
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.os.Build
import android.telephony.TelephonyManager
import androidx.preference.PreferenceManager
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.tools.SingletonHolder
import org.videolan.vlc.util.Settings.init
import org.videolan.tools.Settings.init
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
object Settings : SingletonHolder<SharedPreferences, Context>({ PreferenceManager.getDefaultSharedPreferences(it).also { prefs -> init(prefs) } }) {
object Settings : SingletonHolder<SharedPreferences, Context>({ init(it) }) {
var showVideoThumbs = true
var tvUI = false
var listTitleEllipsize = 0
var overrideTvUI = false
lateinit var device : DeviceInfo
private set
fun init(prefs: SharedPreferences) {
fun init(context: Context) : SharedPreferences{
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
showVideoThumbs = prefs.getBoolean(SHOW_VIDEO_THUMBNAILS, true)
tvUI = prefs.getBoolean(PREF_TV_UI, false)
listTitleEllipsize = prefs.getString(LIST_TITLE_ELLIPSIZE, "0")?.toInt() ?: 0
device = DeviceInfo(context)
return prefs
}
val showTvUi : Boolean
get() = !overrideTvUI && AndroidDevices.isTv || tvUI
get() = !overrideTvUI && device.isTv || tvUI
}
const val KEY_CURRENT_SETTINGS_VERSION = "current_settings_version"
......@@ -84,3 +89,19 @@ const val CRASH_DONT_ASK_AGAIN = "crash_dont_ask_again"
const val PLAYBACK_HISTORY = "playback_history"
const val RESUME_PLAYBACK = "resume_playback"
const val AUDIO_DUCKING = "audio_ducking"
class DeviceInfo(context: Context) {
val pm = context.packageManager
val tm =context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
val isPhone = tm.phoneType != TelephonyManager.PHONE_TYPE_NONE
val hasTsp = pm.hasSystemFeature("android.hardware.touchscreen")
val isAndroidTv = pm.hasSystemFeature("android.software.leanback")
val watchDevices = isAndroidTv && Build.MODEL.startsWith("Bouygtel")
val isChromeBook = pm.hasSystemFeature("org.chromium.arc.device_management")
val isTv = isAndroidTv || !isChromeBook && !hasTsp
val isAmazon = "Amazon" == Build.MANUFACTURER
val hasPiP = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && pm.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)
|| Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isAndroidTv
val pipAllowed = hasPiP || hasTsp && Build.VERSION.SDK_INT < Build.VERSION_CODES.O
}
\ No newline at end of file
......@@ -40,7 +40,7 @@ import org.videolan.vlc.database.helpers.*
import org.videolan.vlc.database.models.BrowserFav
import org.videolan.vlc.database.models.ExternalSub
import org.videolan.vlc.database.models.Slave
import org.videolan.vlc.util.Settings
import org.videolan.tools.Settings
import org.videolan.resources.TYPE_NETWORK_FAV
import org.videolan.vlc.util.TestUtil
import org.videolan.vlc.util.getValue
......
......@@ -24,7 +24,7 @@ import org.videolan.vlc.gui.DiffUtilAdapter
import org.videolan.vlc.gui.MainActivity
import org.videolan.vlc.gui.helpers.SelectorViewHolder
import org.videolan.resources.EXTRA_TARGET
import org.videolan.vlc.util.Settings
import org.videolan.tools.Settings
@ObsoleteCoroutinesApi
@ExperimentalCoroutinesApi
......
......@@ -13,7 +13,7 @@ import org.videolan.vlc.BaseUITest
import org.videolan.vlc.PreferenceMatchers
import org.videolan.vlc.R
import org.videolan.vlc.onPreferenceRow
import org.videolan.vlc.util.Settings
import org.videolan.tools.Settings
abstract class BasePreferenceUITest : BaseUITest() {
val settings: SharedPreferences = Settings.getInstance(context)
......
......@@ -11,8 +11,8 @@ import org.junit.Test
import org.videolan.vlc.PreferenceMatchers.withKey
import org.videolan.vlc.R
import org.videolan.vlc.onPreferenceRow
import org.videolan.vlc.util.KEY_PLAYBACK_SPEED_PERSIST
import org.videolan.vlc.util.RESUME_PLAYBACK
import org.videolan.tools.KEY_PLAYBACK_SPEED_PERSIST
import org.videolan.tools.RESUME_PLAYBACK
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
......
......@@ -17,9 +17,9 @@ import org.videolan.vlc.PreferenceMatchers.withKey
import org.videolan.vlc.R
import org.videolan.vlc.gui.SecondaryActivity
import org.videolan.vlc.onPreferenceRow
import org.videolan.vlc.util.KEY_VIDEO_APP_SWITCH
import org.videolan.vlc.util.PLAYBACK_HISTORY
import org.videolan.vlc.util.SCREEN_ORIENTATION
import org.videolan.tools.KEY_VIDEO_APP_SWITCH
import org.videolan.tools.PLAYBACK_HISTORY
import org.videolan.tools.SCREEN_ORIENTATION
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
......
......@@ -8,6 +8,7 @@ import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.hamcrest.Matchers.equalTo
import org.junit.Rule
import org.junit.Test
import org.videolan.tools.*
import org.videolan.vlc.PreferenceMatchers.withKey
import org.videolan.vlc.R
import org.videolan.vlc.gui.helpers.UiTools
......
......@@ -8,6 +8,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.junit.Rule
import org.junit.Test
import org.videolan.tools.*
import org.videolan.vlc.PreferenceMatchers.withKey
import org.videolan.vlc.R
import org.videolan.vlc.onPreferenceRow
......
......@@ -259,7 +259,6 @@ dependencies {
implementation "androidx.recyclerview:recyclerview:$rootProject.ext.androidxRecyclerviewVersion"
implementation "com.google.android.material:material:$rootProject.ext.androidxMaterialVersion"
implementation "androidx.annotation:annotation:$rootProject.ext.androidxAnnotationVersion"
implementation "androidx.preference:preference:$androidxPreferencesVersion"
implementation "androidx.constraintlayout:constraintlayout:$rootProject.ext.constraintLayoutVersion"
implementation 'androidx.multidex:multidex:2.0.1'
implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.ext.archVersion"
......
......@@ -45,6 +45,9 @@ import kotlinx.coroutines.channels.actor
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.resources.ACTION_CHECK_STORAGES
import org.videolan.tools.KEY_MEDIALIBRARY_SCAN
import org.videolan.tools.ML_SCAN_ON
import org.videolan.tools.Settings
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.helpers.hf.OtgAccess
import org.videolan.vlc.util.*
......
......@@ -51,6 +51,10 @@ import org.videolan.vlc.gui.SendCrashActivity
import org.videolan.vlc.gui.helpers.NotificationHelper
import org.videolan.moviepedia.MoviepediaIndexer
import org.videolan.resources.*
import org.videolan.tools.KEY_MEDIALIBRARY_SCAN
import org.videolan.tools.ML_SCAN_OFF
import org.videolan.tools.ML_SCAN_ON
import org.videolan.tools.Settings
import org.videolan.vlc.repository.DirectoryRepository
import org.videolan.vlc.util.*
import org.videolan.vlc.util.Util.readAsset
......
......@@ -57,6 +57,7 @@ import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.resources.*
import org.videolan.tools.Settings
import org.videolan.tools.safeOffer
import org.videolan.vlc.gui.helpers.AudioUtil
import org.videolan.vlc.gui.helpers.BitmapUtil
......
......@@ -41,6 +41,8 @@ import kotlinx.coroutines.launch
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.MLServiceLocator
import org.videolan.resources.*
import org.videolan.tools.BETA_WELCOME
import org.videolan.tools.Settings
import org.videolan.tools.awaitAppIsForegroung
import org.videolan.vlc.gui.BetaWelcomeActivity
import org.videolan.vlc.gui.MainActivity
......
......@@ -44,6 +44,7 @@ import org.videolan.libvlc.MediaFactory
import org.videolan.libvlc.interfaces.ILibVLCFactory
import org.videolan.libvlc.interfaces.IMediaFactory
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.tools.Settings
import org.videolan.tools.isStarted
import org.videolan.tools.wrap
import org.videolan.vlc.gui.SendCrashActivity
......
......@@ -29,7 +29,7 @@ import kotlinx.coroutines.launch
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.repository.BrowserFavRepository
import org.videolan.vlc.util.AndroidDevices
import org.videolan.vlc.util.Settings
import org.videolan.tools.Settings
private const val DIR_TABLE_NAME = "directories_table"
private const val MEDIA_TABLE_NAME = "media_table"
......
......@@ -18,7 +18,7 @@ import android.view.MenuItem;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.util.Settings;
import org.videolan.tools.Settings;
import java.util.ArrayList;
import java.util.Arrays;
......
......@@ -50,6 +50,8 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.delay
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.tools.PREF_AUDIOPLAYER_TIPS_SHOWN
import org.videolan.tools.Settings
import org.videolan.tools.setVisibility
import org.videolan.vlc.*
import org.videolan.vlc.gui.audio.AudioPlayer
......
......@@ -9,7 +9,7 @@ import org.videolan.tools.KeyHelper
import org.videolan.vlc.gui.helpers.applyTheme
import org.videolan.vlc.util.DialogDelegate
import org.videolan.vlc.util.IDialogHandler
import org.videolan.vlc.util.Settings
import org.videolan.tools.Settings
import org.videolan.vlc.util.getContextWithLocale
abstract class BaseActivity : AppCompatActivity(), IDialogHandler {
......
......@@ -43,7 +43,7 @@ import org.videolan.vlc.gui.dialogs.RenderersDialog
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.interfaces.Filterable
import org.videolan.vlc.util.AndroidDevices
import org.videolan.vlc.util.Settings
import org.videolan.tools.Settings
import org.videolan.vlc.util.Util
@ObsoleteCoroutinesApi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment