Merge pull request #1774 from Bnyro/master

cleanup
This commit is contained in:
Bnyro 2022-11-06 10:11:48 +01:00 committed by GitHub
commit 6b515c2cd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 55 additions and 49 deletions

View File

@ -1,11 +0,0 @@
package com.github.libretube.constants
/**
* object for saving the download type
*/
object DownloadType {
const val AUDIO = 0
const val VIDEO = 1
const val AUDIO_VIDEO = 2
const val NONE = 3
}

View File

@ -1,7 +0,0 @@
package com.github.libretube.constants
object ShareObjectType {
const val VIDEO = 0
const val PLAYLIST = 1
const val CHANNEL = 2
}

View File

@ -0,0 +1,11 @@
package com.github.libretube.enums
/**
* object for saving the download type
*/
enum class DownloadType {
AUDIO,
VIDEO,
AUDIO_VIDEO,
NONE
}

View File

@ -0,0 +1,7 @@
package com.github.libretube.enums
enum class ShareObjectType {
VIDEO,
PLAYLIST,
CHANNEL
}

View File

@ -2,11 +2,12 @@ package com.github.libretube.obj
import android.graphics.Bitmap import android.graphics.Bitmap
import com.github.libretube.api.obj.Streams import com.github.libretube.api.obj.Streams
import com.github.libretube.enums.DownloadType
data class DownloadedFile( data class DownloadedFile(
val name: String, val name: String,
val size: Long, val size: Long,
val type: Int, val type: DownloadType,
var metadata: Streams? = null, var metadata: Streams? = null,
var thumbnail: Bitmap? = null var thumbnail: Bitmap? = null
) )

View File

@ -15,7 +15,7 @@ import com.github.libretube.R
import com.github.libretube.constants.DOWNLOAD_CHANNEL_ID import com.github.libretube.constants.DOWNLOAD_CHANNEL_ID
import com.github.libretube.constants.DOWNLOAD_FAILURE_NOTIFICATION_ID import com.github.libretube.constants.DOWNLOAD_FAILURE_NOTIFICATION_ID
import com.github.libretube.constants.DOWNLOAD_SUCCESS_NOTIFICATION_ID import com.github.libretube.constants.DOWNLOAD_SUCCESS_NOTIFICATION_ID
import com.github.libretube.constants.DownloadType import com.github.libretube.enums.DownloadType
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.util.DownloadHelper import com.github.libretube.util.DownloadHelper
import java.io.File import java.io.File
@ -25,7 +25,7 @@ class DownloadService : Service() {
private lateinit var videoName: String private lateinit var videoName: String
private lateinit var videoUrl: String private lateinit var videoUrl: String
private lateinit var audioUrl: String private lateinit var audioUrl: String
private var downloadType: Int = 3 private var downloadType: DownloadType = DownloadType.NONE
private var videoDownloadId: Long? = null private var videoDownloadId: Long? = null
private var audioDownloadId: Long? = null private var audioDownloadId: Long? = null

View File

@ -8,10 +8,10 @@ import androidx.fragment.app.DialogFragment
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.constants.PIPED_FRONTEND_URL import com.github.libretube.constants.PIPED_FRONTEND_URL
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.constants.ShareObjectType
import com.github.libretube.constants.YOUTUBE_FRONTEND_URL import com.github.libretube.constants.YOUTUBE_FRONTEND_URL
import com.github.libretube.databinding.DialogShareBinding import com.github.libretube.databinding.DialogShareBinding
import com.github.libretube.db.DatabaseHolder.Companion.Database import com.github.libretube.db.DatabaseHolder.Companion.Database
import com.github.libretube.enums.ShareObjectType
import com.github.libretube.extensions.awaitQuery import com.github.libretube.extensions.awaitQuery
import com.github.libretube.obj.ShareData import com.github.libretube.obj.ShareData
import com.github.libretube.util.PreferenceHelper import com.github.libretube.util.PreferenceHelper
@ -19,7 +19,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
class ShareDialog( class ShareDialog(
private val id: String, private val id: String,
private val shareObjectType: Int, private val shareObjectType: ShareObjectType,
private val shareData: ShareData, private val shareData: ShareData,
private val position: Long? = null private val position: Long? = null
) : DialogFragment() { ) : DialogFragment() {

View File

@ -13,8 +13,8 @@ import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.SubscriptionHelper import com.github.libretube.api.SubscriptionHelper
import com.github.libretube.api.obj.ChannelTab import com.github.libretube.api.obj.ChannelTab
import com.github.libretube.constants.IntentData import com.github.libretube.constants.IntentData
import com.github.libretube.constants.ShareObjectType
import com.github.libretube.databinding.FragmentChannelBinding import com.github.libretube.databinding.FragmentChannelBinding
import com.github.libretube.enums.ShareObjectType
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.formatShort import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID

View File

@ -42,12 +42,12 @@ import com.github.libretube.api.obj.ChapterSegment
import com.github.libretube.api.obj.SegmentData import com.github.libretube.api.obj.SegmentData
import com.github.libretube.constants.IntentData import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.constants.ShareObjectType
import com.github.libretube.databinding.DoubleTapOverlayBinding import com.github.libretube.databinding.DoubleTapOverlayBinding
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
import com.github.libretube.databinding.FragmentPlayerBinding import com.github.libretube.databinding.FragmentPlayerBinding
import com.github.libretube.db.DatabaseHelper import com.github.libretube.db.DatabaseHelper
import com.github.libretube.db.DatabaseHolder.Companion.Database import com.github.libretube.db.DatabaseHolder.Companion.Database
import com.github.libretube.enums.ShareObjectType
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.awaitQuery import com.github.libretube.extensions.awaitQuery
import com.github.libretube.extensions.formatShort import com.github.libretube.extensions.formatShort

View File

@ -6,8 +6,8 @@ import android.widget.Toast
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.obj.PlaylistId import com.github.libretube.api.obj.PlaylistId
import com.github.libretube.constants.ShareObjectType
import com.github.libretube.databinding.DialogTextPreferenceBinding import com.github.libretube.databinding.DialogTextPreferenceBinding
import com.github.libretube.enums.ShareObjectType
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.extensions.toastFromMainThread import com.github.libretube.extensions.toastFromMainThread
import com.github.libretube.obj.ShareData import com.github.libretube.obj.ShareData

View File

@ -5,7 +5,7 @@ import android.widget.Toast
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.constants.IntentData import com.github.libretube.constants.IntentData
import com.github.libretube.constants.ShareObjectType import com.github.libretube.enums.ShareObjectType
import com.github.libretube.extensions.toStreamItem import com.github.libretube.extensions.toStreamItem
import com.github.libretube.obj.ShareData import com.github.libretube.obj.ShareData
import com.github.libretube.ui.dialogs.AddToPlaylistDialog import com.github.libretube.ui.dialogs.AddToPlaylistDialog

View File

@ -2,7 +2,7 @@ package com.github.libretube.util
import android.content.Context import android.content.Context
import android.os.Build import android.os.Build
import com.github.libretube.constants.DownloadType import com.github.libretube.enums.DownloadType
import com.github.libretube.extensions.createDir import com.github.libretube.extensions.createDir
import com.github.libretube.obj.DownloadedFile import com.github.libretube.obj.DownloadedFile
import java.io.File import java.io.File

View File

@ -1,6 +1,8 @@
package com.github.libretube.util package com.github.libretube.util
import android.content.Context import android.content.Context
import android.content.res.Configuration
import android.content.res.Resources
import android.os.Build import android.os.Build
import android.telephony.TelephonyManager import android.telephony.TelephonyManager
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
@ -11,32 +13,35 @@ object LocaleHelper {
fun updateLanguage(context: Context) { fun updateLanguage(context: Context) {
val languageName = PreferenceHelper.getString(PreferenceKeys.LANGUAGE, "sys") val languageName = PreferenceHelper.getString(PreferenceKeys.LANGUAGE, "sys")
if (languageName == "sys") { val locale = when {
updateLocaleConf(context, Locale.getDefault()) languageName == "sys" -> Locale.getDefault()
} else if (languageName.contains("-") == true) { languageName.contains("-") == true -> {
val languageParts = languageName.split("-") val languageParts = languageName.split("-")
val locale = Locale( Locale(
languageParts[0], languageParts[0],
languageParts[1] languageParts[1].replace("r", "")
) )
updateLocaleConf(context, locale)
} else {
val locale = Locale(languageName)
updateLocaleConf(context, locale)
} }
else -> Locale(languageName)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) updateResources(context, locale)
updateResourcesLegacy(context, locale)
} }
private fun updateLocaleConf(context: Context, locale: Locale) { private fun updateResources(context: Context, locale: Locale) {
// Change API Language
Locale.setDefault(locale) Locale.setDefault(locale)
val configuration: Configuration = context.resources.configuration
configuration.setLocale(locale)
context.createConfigurationContext(configuration)
}
// Change App Language
val res = context.resources
val dm = res.displayMetrics
val conf = res.configuration
conf.setLocale(locale)
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
res.updateConfiguration(conf, dm) private fun updateResourcesLegacy(context: Context, locale: Locale) {
Locale.setDefault(locale)
val resources: Resources = context.resources
val configuration: Configuration = resources.getConfiguration()
configuration.locale = locale
resources.updateConfiguration(configuration, resources.getDisplayMetrics())
} }
fun getDetectedCountry(context: Context, defaultCountryIsoCode: String): String { fun getDetectedCountry(context: Context, defaultCountryIsoCode: String): String {