mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
commit
6b515c2cd3
@ -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
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package com.github.libretube.constants
|
||||
|
||||
object ShareObjectType {
|
||||
const val VIDEO = 0
|
||||
const val PLAYLIST = 1
|
||||
const val CHANNEL = 2
|
||||
}
|
11
app/src/main/java/com/github/libretube/enums/DownloadType.kt
Normal file
11
app/src/main/java/com/github/libretube/enums/DownloadType.kt
Normal file
@ -0,0 +1,11 @@
|
||||
package com.github.libretube.enums
|
||||
|
||||
/**
|
||||
* object for saving the download type
|
||||
*/
|
||||
enum class DownloadType {
|
||||
AUDIO,
|
||||
VIDEO,
|
||||
AUDIO_VIDEO,
|
||||
NONE
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.github.libretube.enums
|
||||
|
||||
enum class ShareObjectType {
|
||||
VIDEO,
|
||||
PLAYLIST,
|
||||
CHANNEL
|
||||
}
|
@ -2,11 +2,12 @@ package com.github.libretube.obj
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import com.github.libretube.api.obj.Streams
|
||||
import com.github.libretube.enums.DownloadType
|
||||
|
||||
data class DownloadedFile(
|
||||
val name: String,
|
||||
val size: Long,
|
||||
val type: Int,
|
||||
val type: DownloadType,
|
||||
var metadata: Streams? = null,
|
||||
var thumbnail: Bitmap? = null
|
||||
)
|
||||
|
@ -15,7 +15,7 @@ import com.github.libretube.R
|
||||
import com.github.libretube.constants.DOWNLOAD_CHANNEL_ID
|
||||
import com.github.libretube.constants.DOWNLOAD_FAILURE_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.util.DownloadHelper
|
||||
import java.io.File
|
||||
@ -25,7 +25,7 @@ class DownloadService : Service() {
|
||||
private lateinit var videoName: String
|
||||
private lateinit var videoUrl: String
|
||||
private lateinit var audioUrl: String
|
||||
private var downloadType: Int = 3
|
||||
private var downloadType: DownloadType = DownloadType.NONE
|
||||
|
||||
private var videoDownloadId: Long? = null
|
||||
private var audioDownloadId: Long? = null
|
||||
|
@ -8,10 +8,10 @@ import androidx.fragment.app.DialogFragment
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.constants.PIPED_FRONTEND_URL
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.constants.ShareObjectType
|
||||
import com.github.libretube.constants.YOUTUBE_FRONTEND_URL
|
||||
import com.github.libretube.databinding.DialogShareBinding
|
||||
import com.github.libretube.db.DatabaseHolder.Companion.Database
|
||||
import com.github.libretube.enums.ShareObjectType
|
||||
import com.github.libretube.extensions.awaitQuery
|
||||
import com.github.libretube.obj.ShareData
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
@ -19,7 +19,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class ShareDialog(
|
||||
private val id: String,
|
||||
private val shareObjectType: Int,
|
||||
private val shareObjectType: ShareObjectType,
|
||||
private val shareData: ShareData,
|
||||
private val position: Long? = null
|
||||
) : DialogFragment() {
|
||||
|
@ -13,8 +13,8 @@ import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.api.SubscriptionHelper
|
||||
import com.github.libretube.api.obj.ChannelTab
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.constants.ShareObjectType
|
||||
import com.github.libretube.databinding.FragmentChannelBinding
|
||||
import com.github.libretube.enums.ShareObjectType
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.extensions.formatShort
|
||||
import com.github.libretube.extensions.toID
|
||||
|
@ -42,12 +42,12 @@ import com.github.libretube.api.obj.ChapterSegment
|
||||
import com.github.libretube.api.obj.SegmentData
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.constants.ShareObjectType
|
||||
import com.github.libretube.databinding.DoubleTapOverlayBinding
|
||||
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
||||
import com.github.libretube.databinding.FragmentPlayerBinding
|
||||
import com.github.libretube.db.DatabaseHelper
|
||||
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.awaitQuery
|
||||
import com.github.libretube.extensions.formatShort
|
||||
|
@ -6,8 +6,8 @@ import android.widget.Toast
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.api.obj.PlaylistId
|
||||
import com.github.libretube.constants.ShareObjectType
|
||||
import com.github.libretube.databinding.DialogTextPreferenceBinding
|
||||
import com.github.libretube.enums.ShareObjectType
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.extensions.toastFromMainThread
|
||||
import com.github.libretube.obj.ShareData
|
||||
|
@ -5,7 +5,7 @@ import android.widget.Toast
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
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.obj.ShareData
|
||||
import com.github.libretube.ui.dialogs.AddToPlaylistDialog
|
||||
|
@ -2,7 +2,7 @@ package com.github.libretube.util
|
||||
|
||||
import android.content.Context
|
||||
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.obj.DownloadedFile
|
||||
import java.io.File
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.github.libretube.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.os.Build
|
||||
import android.telephony.TelephonyManager
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
@ -11,32 +13,35 @@ object LocaleHelper {
|
||||
|
||||
fun updateLanguage(context: Context) {
|
||||
val languageName = PreferenceHelper.getString(PreferenceKeys.LANGUAGE, "sys")
|
||||
if (languageName == "sys") {
|
||||
updateLocaleConf(context, Locale.getDefault())
|
||||
} else if (languageName.contains("-") == true) {
|
||||
val languageParts = languageName.split("-")
|
||||
val locale = Locale(
|
||||
languageParts[0],
|
||||
languageParts[1]
|
||||
)
|
||||
updateLocaleConf(context, locale)
|
||||
} else {
|
||||
val locale = Locale(languageName)
|
||||
updateLocaleConf(context, locale)
|
||||
val locale = when {
|
||||
languageName == "sys" -> Locale.getDefault()
|
||||
languageName.contains("-") == true -> {
|
||||
val languageParts = languageName.split("-")
|
||||
Locale(
|
||||
languageParts[0],
|
||||
languageParts[1].replace("r", "")
|
||||
)
|
||||
}
|
||||
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) {
|
||||
// Change API Language
|
||||
private fun updateResources(context: Context, locale: 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")
|
||||
res.updateConfiguration(conf, dm)
|
||||
@Suppress("DEPRECATION")
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user