Code Cleanup and Formatting and i18n4k dependency

This commit is contained in:
shabinder 2021-07-14 02:15:09 +05:30
parent c591842fb4
commit 116530cc3c
80 changed files with 315 additions and 328 deletions

View File

@ -23,6 +23,7 @@ plugins {
kotlin("android") kotlin("android")
id("kotlin-parcelize") id("kotlin-parcelize")
id("org.jetbrains.compose") id("org.jetbrains.compose")
id("ktlint-setup")
} }
group = "com.shabinder" group = "com.shabinder"

View File

@ -42,7 +42,8 @@ class App: Application(), KoinComponent {
val tracker: Tracker by lazy { val tracker: Tracker by lazy {
TrackerBuilder.createDefault( TrackerBuilder.createDefault(
"https://matomo.spotiflyer.ml/matomo.php", 1) "https://matomo.spotiflyer.ml/matomo.php", 1
)
.build(Matomo.getInstance(this)).apply { .build(Matomo.getInstance(this)).apply {
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
/*Timber.plant(DebugTree()) /*Timber.plant(DebugTree())

View File

@ -98,7 +98,6 @@ import org.koin.android.ext.android.inject
import org.matomo.sdk.extra.TrackHelper import org.matomo.sdk.extra.TrackHelper
import java.io.File import java.io.File
@ExperimentalAnimationApi @ExperimentalAnimationApi
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
@ -248,7 +247,6 @@ class MainActivity : ComponentActivity() {
} }
/*END: Foreground Service Handlers*/ /*END: Foreground Service Handlers*/
@Composable @Composable
private fun isInternetAvailableState(): State<Boolean?> { private fun isInternetAvailableState(): State<Boolean?> {
return internetAvailability.observeAsState() return internetAvailability.observeAsState()
@ -281,7 +279,8 @@ class MainActivity : ComponentActivity() {
override val platformActions = object : PlatformActions { override val platformActions = object : PlatformActions {
override val imageCacheDir: String = applicationContext.cacheDir.absolutePath + File.separator override val imageCacheDir: String = applicationContext.cacheDir.absolutePath + File.separator
override val sharedPreferences = applicationContext.getSharedPreferences(SharedPreferencesKey, override val sharedPreferences = applicationContext.getSharedPreferences(
SharedPreferencesKey,
MODE_PRIVATE MODE_PRIVATE
) )
@ -406,9 +405,11 @@ class MainActivity : ComponentActivity() {
.withActivity(this) .withActivity(this)
.withFragmentManager(fragmentManager) .withFragmentManager(fragmentManager)
.withMemoryBar(true) .withMemoryBar(true)
.setTheme(StorageChooser.Theme(applicationContext).apply { .setTheme(
StorageChooser.Theme(applicationContext).apply {
scheme = applicationContext.resources.getIntArray(R.array.default_dark) scheme = applicationContext.resources.getIntArray(R.array.default_dark)
}) }
)
.setDialogTitle(Strings.setDownloadDirectory()) .setDialogTitle(Strings.setDownloadDirectory())
.allowCustomPath(true) .allowCustomPath(true)
.setType(StorageChooser.DIRECTORY_CHOOSER) .setType(StorageChooser.DIRECTORY_CHOOSER)

View File

@ -133,18 +133,18 @@ class ForegroundService : LifecycleService() {
updateNotification() updateNotification()
} }
trackList.forEach { for (track in trackList) {
trackStatusFlowMap[it.title] = DownloadStatus.Queued trackStatusFlowMap[track.title] = DownloadStatus.Queued
lifecycleScope.launch { lifecycleScope.launch {
downloadService.value.execute { downloadService.value.execute {
fetcher.findMp3DownloadLink(it).fold( fetcher.findMp3DownloadLink(track).fold(
success = { url -> success = { url ->
enqueueDownload(url, it) enqueueDownload(url, track)
}, },
failure = { error -> failure = { error ->
failed++ failed++
updateNotification() updateNotification()
trackStatusFlowMap[it.title] = DownloadStatus.Failed(error) trackStatusFlowMap[track.title] = DownloadStatus.Failed(error)
} }
) )
} }

View File

@ -24,4 +24,3 @@ fun cleanFiles(dir: File) {
} }
} catch (e: Exception) { e.printStackTrace() } } catch (e: Exception) { e.printStackTrace() }
} }

View File

@ -75,21 +75,30 @@ fun NetworkDialog(
Text("Retry",color = Color.Black,fontSize = 18.sp,textAlign = TextAlign.Center) Text("Retry",color = Color.Black,fontSize = 18.sp,textAlign = TextAlign.Center)
Icon(Icons.Rounded.SyncProblem,"Check Network Connection Again") Icon(Icons.Rounded.SyncProblem,"Check Network Connection Again")
} }
*/}, */
title = { Text(Strings.noInternetConnection(), },
title = {
Text(
Strings.noInternetConnection(),
style = SpotiFlyerTypography.h5, style = SpotiFlyerTypography.h5,
textAlign = TextAlign.Center) }, textAlign = TextAlign.Center
)
},
backgroundColor = Color.DarkGray, backgroundColor = Color.DarkGray,
text = { text = {
Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) { Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) {
Spacer(modifier = Modifier.padding(8.dp)) Spacer(modifier = Modifier.padding(8.dp))
Row(verticalAlignment = Alignment.CenterVertically, Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(vertical = 6.dp) modifier = Modifier.fillMaxWidth().padding(vertical = 6.dp)
) { ) {
Image(Icons.Rounded.CloudOff, Image(
Strings.noInternetConnection(),Modifier.size(42.dp),colorFilter = ColorFilter.tint( Icons.Rounded.CloudOff,
Strings.noInternetConnection(), Modifier.size(42.dp),
colorFilter = ColorFilter.tint(
colorOffWhite colorOffWhite
)) )
)
Spacer(modifier = Modifier.padding(start = 16.dp)) Spacer(modifier = Modifier.padding(start = 16.dp))
Text( Text(
text = Strings.checkInternetConnection(), text = Strings.checkInternetConnection(),
@ -97,8 +106,8 @@ fun NetworkDialog(
) )
} }
} }
} },
,shape = SpotiFlyerShapes.medium shape = SpotiFlyerShapes.medium
) )
} }
} }

View File

@ -64,12 +64,14 @@ fun PermissionDialog(
) { ) {
Text(Strings.grantPermissions(), color = Color.Black, fontSize = 18.sp, textAlign = TextAlign.Center) Text(Strings.grantPermissions(), color = Color.Black, fontSize = 18.sp, textAlign = TextAlign.Center)
} }
},title = { Text(Strings.requiredPermissions(),style = SpotiFlyerTypography.h5,textAlign = TextAlign.Center) }, },
title = { Text(Strings.requiredPermissions(), style = SpotiFlyerTypography.h5, textAlign = TextAlign.Center) },
backgroundColor = Color.DarkGray, backgroundColor = Color.DarkGray,
text = { text = {
Column { Column {
Spacer(modifier = Modifier.padding(8.dp)) Spacer(modifier = Modifier.padding(8.dp))
Row(verticalAlignment = Alignment.CenterVertically, Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(vertical = 6.dp) modifier = Modifier.fillMaxWidth().padding(vertical = 6.dp)
) { ) {
Icon(Icons.Rounded.SdStorage, Strings.storagePermission()) Icon(Icons.Rounded.SdStorage, Strings.storagePermission())

View File

@ -5,7 +5,6 @@ import android.content.Context
import android.content.pm.PackageInfo import android.content.pm.PackageInfo
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.util.Base64 import android.util.Base64
import android.util.Log
import com.shabinder.spotiflyer.App import com.shabinder.spotiflyer.App
import java.security.MessageDigest import java.security.MessageDigest

View File

@ -43,15 +43,17 @@ fun Activity.checkIfLatestVersion() {
} }
fun Activity.checkPermissions(): Boolean = ContextCompat fun Activity.checkPermissions(): Boolean = ContextCompat
.checkSelfPermission(this, .checkSelfPermission(
Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED this,
&& Manifest.permission.WRITE_EXTERNAL_STORAGE
) == PackageManager.PERMISSION_GRANTED &&
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
ContextCompat.checkSelfPermission(this, ContextCompat.checkSelfPermission(
Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) == PackageManager.PERMISSION_GRANTED this,
Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
) == PackageManager.PERMISSION_GRANTED
} else true } else true
@SuppressLint("BatteryLife", "ObsoleteSdkInt") @SuppressLint("BatteryLife", "ObsoleteSdkInt")
fun Activity.disableDozeMode(requestCode: Int) { fun Activity.disableDozeMode(requestCode: Int) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

View File

@ -2,7 +2,6 @@ package com.shabinder.spotiflyer.utils.autoclear
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import com.shabinder.common.requireNotNull
import com.shabinder.spotiflyer.utils.autoclear.AutoClear.Companion.TRIGGER import com.shabinder.spotiflyer.utils.autoclear.AutoClear.Companion.TRIGGER
import com.shabinder.spotiflyer.utils.autoclear.lifecycleobservers.LifecycleCreateAndDestroyObserver import com.shabinder.spotiflyer.utils.autoclear.lifecycleobservers.LifecycleCreateAndDestroyObserver
import com.shabinder.spotiflyer.utils.autoclear.lifecycleobservers.LifecycleResumeAndPauseObserver import com.shabinder.spotiflyer.utils.autoclear.lifecycleobservers.LifecycleResumeAndPauseObserver

View File

@ -31,9 +31,8 @@ allprojects {
maven(url = "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") maven(url = "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
} }
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach { tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions { dependsOn(":common:data-models:generateI18n4kFiles")
jvmTarget = "1.8" kotlinOptions { jvmTarget = "1.8" }
}
} }
afterEvaluate { afterEvaluate {
project.extensions.findByType<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension>()?.let { kmpExt -> project.extensions.findByType<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension>()?.let { kmpExt ->

View File

@ -19,26 +19,14 @@ plugins {
id("org.jlleitschuh.gradle.ktlint-idea") id("org.jlleitschuh.gradle.ktlint-idea")
} }
subprojects {
apply(plugin = "org.jlleitschuh.gradle.ktlint")
apply(plugin = "org.jlleitschuh.gradle.ktlint-idea")
repositories {
// Required to download KtLint
mavenCentral()
}
ktlint { ktlint {
android.set(true)
outputToConsole.set(true) outputToConsole.set(true)
ignoreFailures.set(true) ignoreFailures.set(true)
coloredOutput.set(true) coloredOutput.set(true)
verbose.set(true) verbose.set(true)
disabledRules.set(setOf("filename,no-wildcard-imports"))
filter { filter {
exclude("**/generated/**") exclude("**/generated/**")
exclude("**/build/**") exclude("**/build/**")
} }
} }
// Optionally configure plugin
/*configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
debug.set(true)
}*/
}

View File

@ -186,9 +186,12 @@ fun TrackCard(
is DownloadStatus.Failed -> { is DownloadStatus.Failed -> {
val (openErrorDialog, dismissErrorDialog) = ErrorInfoDialog((track.downloaded as DownloadStatus.Failed).error) val (openErrorDialog, dismissErrorDialog) = ErrorInfoDialog((track.downloaded as DownloadStatus.Failed).error)
Icon(Icons.Rounded.Info,Strings.downloadError(),tint = lightGray,modifier = Modifier.size(42.dp).clickable { Icon(
Icons.Rounded.Info, Strings.downloadError(), tint = lightGray,
modifier = Modifier.size(42.dp).clickable {
openErrorDialog() openErrorDialog()
}.padding(start = 4.dp,end = 12.dp)) }.padding(start = 4.dp, end = 12.dp)
)
DownloadImageError( DownloadImageError(
Modifier.clickable( Modifier.clickable(

View File

@ -98,7 +98,6 @@ fun SpotiFlyerPreferenceContent(component: SpotiFlyerPreference) {
) )
} }
} }
} }
Spacer(Modifier.padding(top = 12.dp)) Spacer(Modifier.padding(top = 12.dp))
@ -157,7 +156,6 @@ fun SpotiFlyerPreferenceContent(component: SpotiFlyerPreference) {
} }
Spacer(modifier = Modifier.padding(top = 8.dp)) Spacer(modifier = Modifier.padding(top = 8.dp))
} }
} }
@OptIn(ExperimentalAnimationApi::class) @OptIn(ExperimentalAnimationApi::class)

View File

@ -4,7 +4,6 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.platform.Font import androidx.compose.ui.text.platform.Font
actual fun montserratFont() = FontFamily( actual fun montserratFont() = FontFamily(
Font("font/montserrat_light.ttf", FontWeight.Light), Font("font/montserrat_light.ttf", FontWeight.Light),
Font("font/montserrat_regular.ttf", FontWeight.Normal), Font("font/montserrat_regular.ttf", FontWeight.Normal),

View File

@ -130,7 +130,6 @@ inline fun <V, E : Throwable> Event<V, E>.unwrap(failure: (E) -> Nothing): V =
inline fun <V, E : Throwable> Event<V, E>.unwrapError(success: (V) -> Nothing): E = inline fun <V, E : Throwable> Event<V, E>.unwrapError(success: (V) -> Nothing): E =
apply { component1()?.let(success) }.component2()!! apply { component1()?.let(success) }.component2()!!
sealed class Event<out V : Any?, out E : Throwable> : ReadOnlyProperty<Any?, V> { sealed class Event<out V : Any?, out E : Throwable> : ReadOnlyProperty<Any?, V> {
open operator fun component1(): V? = null open operator fun component1(): V? = null

View File

@ -93,7 +93,6 @@ suspend inline fun <V : Any?, U : Any> SuspendableEvent<V, *>.fanout(
): SuspendableEvent<Pair<V, U>, *> = ): SuspendableEvent<Pair<V, U>, *> =
flatMap { outer -> other().map { outer to it } } flatMap { outer -> other().map { outer to it } }
suspend fun <V : Any?, E : Throwable> List<SuspendableEvent<V, E>>.lift(): SuspendableEvent<List<V>, E> = fold( suspend fun <V : Any?, E : Throwable> List<SuspendableEvent<V, E>>.lift(): SuspendableEvent<List<V>, E> = fold(
SuspendableEvent.Success<MutableList<V>, E>(mutableListOf<V>()) as SuspendableEvent<MutableList<V>, E> SuspendableEvent.Success<MutableList<V>, E>(mutableListOf<V>()) as SuspendableEvent<MutableList<V>, E>
) { acc, result -> ) { acc, result ->
@ -172,5 +171,4 @@ sealed class SuspendableEvent<out V : Any?, out E : Throwable>: ReadOnlyProperty
crossinline block: suspend () -> V crossinline block: suspend () -> V
): SuspendableEvent<V, Throwable> = of(block) ): SuspendableEvent<V, Throwable> = of(block)
} }
} }

View File

@ -5,5 +5,4 @@ class SuspendedValidation<out E : Throwable>(vararg resultSequence: SuspendableE
val failures: List<E> = resultSequence.filterIsInstance<SuspendableEvent.Failure<*, E>>().map { it.getThrowable() } val failures: List<E> = resultSequence.filterIsInstance<SuspendableEvent.Failure<*, E>>().map { it.getThrowable() }
val hasFailure = failures.isNotEmpty() val hasFailure = failures.isNotEmpty()
} }

View File

@ -28,9 +28,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.io.IOException
import java.lang.Exception import java.lang.Exception
import java.net.InetSocketAddress
import java.net.URL import java.net.URL
import javax.net.ssl.HttpsURLConnection import javax.net.ssl.HttpsURLConnection

View File

@ -17,7 +17,6 @@ class PreferenceManager(settings: Settings): Settings by settings {
val isAnalyticsEnabled get() = getBooleanOrNull(ANALYTICS_KEY) ?: false val isAnalyticsEnabled get() = getBooleanOrNull(ANALYTICS_KEY) ?: false
fun toggleAnalytics(enabled: Boolean) = putBoolean(ANALYTICS_KEY, enabled) fun toggleAnalytics(enabled: Boolean) = putBoolean(ANALYTICS_KEY, enabled)
/* DOWNLOAD DIRECTORY */ /* DOWNLOAD DIRECTORY */
val downloadDir get() = getStringOrNull(DIR_KEY) val downloadDir get() = getStringOrNull(DIR_KEY)
fun setDownloadDirectory(newBasePath: String) = putString(DIR_KEY, newBasePath) fun setDownloadDirectory(newBasePath: String) = putString(DIR_KEY, newBasePath)
@ -33,7 +32,6 @@ class PreferenceManager(settings: Settings): Settings by settings {
} }
fun setDonationOffset(offset: Int = 5) = putInt(DONATION_INTERVAL, offset) fun setDonationOffset(offset: Int = 5) = putInt(DONATION_INTERVAL, offset)
/* TO CHECK IF THIS IS APP's FIRST LAUNCH */ /* TO CHECK IF THIS IS APP's FIRST LAUNCH */
val isFirstLaunch get() = getBooleanOrNull(FIRST_LAUNCH) ?: true val isFirstLaunch get() = getBooleanOrNull(FIRST_LAUNCH) ?: true
fun firstLaunchDone() = putBoolean(FIRST_LAUNCH, false) fun firstLaunchDone() = putBoolean(FIRST_LAUNCH, false)

View File

@ -25,7 +25,6 @@ import com.shabinder.common.models.gaana.GaanaSong
import io.ktor.client.* import io.ktor.client.*
import io.ktor.client.request.* import io.ktor.client.request.*
private const val TOKEN = "b2e6d7fbc136547a940516e9b77e5990" private const val TOKEN = "b2e6d7fbc136547a940516e9b77e5990"
private val BASE_URL get() = "${corsApi}https://api.gaana.com" private val BASE_URL get() = "${corsApi}https://api.gaana.com"

View File

@ -28,7 +28,6 @@ dependencies {
implementation(project(":common:list")) implementation(project(":common:list"))
implementation(project(":common:list")) implementation(project(":common:list"))
// Decompose // Decompose
implementation(Decompose.decompose) implementation(Decompose.decompose)
implementation(Decompose.extensionsCompose) implementation(Decompose.extensionsCompose)

View File

@ -20,6 +20,7 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat
plugins { plugins {
kotlin("multiplatform") kotlin("multiplatform")
id("org.jetbrains.compose") id("org.jetbrains.compose")
id("ktlint-setup")
} }
group = "com.shabinder" group = "com.shabinder"

View File

@ -56,7 +56,6 @@ import java.net.URI
import javax.swing.JFileChooser import javax.swing.JFileChooser
import javax.swing.JFileChooser.APPROVE_OPTION import javax.swing.JFileChooser.APPROVE_OPTION
private val koin = initKoin(enableNetworkLogs = true).koin private val koin = initKoin(enableNetworkLogs = true).koin
private lateinit var showToast: (String) -> Unit private lateinit var showToast: (String) -> Unit
private val tracker: PiwikTracker by lazy { private val tracker: PiwikTracker by lazy {

View File

@ -4,7 +4,6 @@ import org.piwik.java.tracking.PiwikRequest
import org.piwik.java.tracking.PiwikTracker import org.piwik.java.tracking.PiwikTracker
import java.net.URL import java.net.URL
fun PiwikTracker.trackAsync( fun PiwikTracker.trackAsync(
baseURL: String = "https://com.shabinder.spotiflyer/", baseURL: String = "https://com.shabinder.spotiflyer/",
requestBuilder: PiwikRequest.() -> Unit = {} requestBuilder: PiwikRequest.() -> Unit = {}

View File

@ -22,7 +22,7 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html # http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process. # Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings. # The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m org.gradle.jvmargs=-Xmx3072m
# When configured, Gradle will run in incubating parallel mode. # When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit # This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects

View File

@ -19,7 +19,6 @@ internal object GithubService {
private const val baseURL = Common.GITHUB_API private const val baseURL = Common.GITHUB_API
suspend fun getGithubRepoReleasesInfo( suspend fun getGithubRepoReleasesInfo(
ownerName: String, ownerName: String,
repoName: String, repoName: String,

View File

@ -1,7 +1,7 @@
package models.github package models.github
import kotlinx.serialization.json.JsonNames
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonNames
@Serializable @Serializable
data class Reactions( data class Reactions(

View File

@ -83,7 +83,6 @@ private suspend fun getDownloadCard(
return downloadCard return downloadCard
} }
fun getDownloadCardHtml( fun getDownloadCardHtml(
count: Int, count: Int,
date: String, // ex: 06 Jun 2021 date: String, // ex: 06 Jun 2021