mirror of
https://github.com/Michatec/Radio.git
synced 2026-03-31 23:46:28 +02:00
refactor(helpers): minor code cleanup and documentation fixes
This commit is contained in:
@@ -27,28 +27,6 @@ class ThemeSelectionDialog(private var themeSelectionDialogListener: ThemeSelect
|
||||
private lateinit var dialog: AlertDialog
|
||||
|
||||
|
||||
/* Update radio buttons to reflect current theme */
|
||||
private fun updateRadioButtons(
|
||||
context: Context,
|
||||
radioFollowSystem: RadioButton,
|
||||
radioLight: RadioButton,
|
||||
radioDark: RadioButton
|
||||
) {
|
||||
val currentTheme = AppThemeHelper.getCurrentTheme(context)
|
||||
when (currentTheme) {
|
||||
context.getString(R.string.pref_theme_selection_mode_device_default) -> {
|
||||
radioFollowSystem.isChecked = true
|
||||
}
|
||||
context.getString(R.string.pref_theme_selection_mode_light) -> {
|
||||
radioLight.isChecked = true
|
||||
}
|
||||
context.getString(R.string.pref_theme_selection_mode_dark) -> {
|
||||
radioDark.isChecked = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Construct and show dialog */
|
||||
fun show(context: Context) {
|
||||
// prepare dialog builder
|
||||
|
||||
@@ -53,7 +53,7 @@ object BackupHelper {
|
||||
Snackbar.make(view, R.string.toastmessage_restored, Snackbar.LENGTH_LONG).show()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||
// bypass "ZipException" for Android 14 or above applications when zip file names contain ".." or start with "/"
|
||||
// bypass "ZipException" for Android 14 or above applications when zip file names contain "." or start with "/"
|
||||
dalvik.system.ZipPathValidator.clearCallback()
|
||||
}
|
||||
|
||||
|
||||
@@ -299,7 +299,7 @@ object CollectionHelper {
|
||||
}
|
||||
|
||||
|
||||
/* Returns the children stations under under root (simple media library structure: root > stations) */
|
||||
/* Returns the children stations under root (simple media library structure: root > stations) */
|
||||
fun getChildren(context: Context, collection: Collection): List<MediaItem> {
|
||||
val mediaItems: MutableList<MediaItem> = mutableListOf()
|
||||
collection.stations.forEach { station ->
|
||||
|
||||
@@ -17,14 +17,14 @@ object DateTimeHelper {
|
||||
|
||||
|
||||
/* Main class variables */
|
||||
private const val pattern: String = "EEE, dd MMM yyyy HH:mm:ss Z"
|
||||
private val dateFormat: SimpleDateFormat = SimpleDateFormat(pattern, Locale.ENGLISH)
|
||||
private const val PATTERN: String = "EEE, dd MMM yyyy HH:mm:ss Z"
|
||||
private val dateFormat: SimpleDateFormat = SimpleDateFormat(PATTERN, Locale.ENGLISH)
|
||||
|
||||
|
||||
/* Converts RFC 2822 string representation of a date to DATE */
|
||||
fun convertFromRfc2822(dateString: String): Date {
|
||||
val date: Date = try {
|
||||
// parse date string using standard pattern
|
||||
// parse date string using standard PATTERN
|
||||
dateFormat.parse((dateString)) ?: Keys.DEFAULT_DATE
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Unable to parse. Trying an alternative Date format. $e")
|
||||
@@ -37,7 +37,7 @@ object DateTimeHelper {
|
||||
|
||||
/* Converts a DATE to its RFC 2822 string representation */
|
||||
fun convertToRfc2822(date: Date): String {
|
||||
val dateFormat = SimpleDateFormat(pattern, Locale.ENGLISH)
|
||||
val dateFormat = SimpleDateFormat(PATTERN, Locale.ENGLISH)
|
||||
return dateFormat.format(date)
|
||||
}
|
||||
|
||||
|
||||
@@ -370,7 +370,7 @@ object DownloadHelper {
|
||||
private fun determineAllowedNetworkTypes(type: Int, ignoreWifiRestriction: Boolean): Int {
|
||||
var allowedNetworkTypes: Int =
|
||||
(DownloadManager.Request.NETWORK_WIFI or DownloadManager.Request.NETWORK_MOBILE)
|
||||
// restrict download of audio files to WiFi if necessary
|
||||
// restrict download of audio files to Wi-Fi if necessary
|
||||
if (type == Keys.FILE_TYPE_AUDIO) {
|
||||
if (!ignoreWifiRestriction && !PreferencesHelper.downloadOverMobile()) {
|
||||
allowedNetworkTypes = DownloadManager.Request.NETWORK_WIFI
|
||||
|
||||
@@ -115,7 +115,7 @@ object NetworkHelper {
|
||||
}
|
||||
|
||||
|
||||
/* Creates a http connection from given url string */
|
||||
/* Creates an http connection from given url string */
|
||||
private fun createConnection(urlString: String, redirectCount: Int = 0): HttpURLConnection? {
|
||||
var connection: HttpURLConnection? = null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user