mirror of
https://github.com/Shabinder/SpotiFlyer.git
synced 2024-12-22 20:57:54 +01:00
SuspendableEvent and other Deprecated Code Fixes
This commit is contained in:
parent
7da3147b69
commit
9b447c3a9d
@ -86,6 +86,7 @@ class MainActivity : ComponentActivity() {
|
||||
private lateinit var queryReceiver: BroadcastReceiver
|
||||
private val internetAvailability by lazy { ConnectionLiveData(applicationContext) }
|
||||
private val tracker get() = (application as App).tracker
|
||||
private val visibleChild get(): SpotiFlyerRoot.Child = root.routerState.value.activeChild.instance
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -149,9 +150,7 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
private fun initialise() {
|
||||
val isGithubRelease = checkAppSignature(this).also {
|
||||
Log.i("SpotiFlyer Github Rel.:",it.toString())
|
||||
}
|
||||
val isGithubRelease = checkAppSignature(this)
|
||||
/*
|
||||
* Only Send an `Update Notification` on Github Release Builds
|
||||
* and Track Downloads for all other releases like F-Droid,
|
||||
@ -170,42 +169,6 @@ class MainActivity : ComponentActivity() {
|
||||
return internetAvailability.observeAsState()
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private fun setUpOnPrefClickListener() {
|
||||
// Initialize Builder
|
||||
val chooser = StorageChooser.Builder()
|
||||
.withActivity(this)
|
||||
.withFragmentManager(fragmentManager)
|
||||
.withMemoryBar(true)
|
||||
.setTheme(StorageChooser.Theme(applicationContext).apply {
|
||||
scheme = applicationContext.resources.getIntArray(R.array.default_dark)
|
||||
})
|
||||
.setDialogTitle("Set Download Directory")
|
||||
.allowCustomPath(true)
|
||||
.setType(StorageChooser.DIRECTORY_CHOOSER)
|
||||
.build()
|
||||
|
||||
// get path that the user has chosen
|
||||
chooser.setOnSelectListener { path ->
|
||||
Log.d("Setting Base Path", path)
|
||||
val f = File(path)
|
||||
if (f.canWrite()) {
|
||||
// hell yeah :)
|
||||
dir.setDownloadDirectory(path)
|
||||
showPopUpMessage(
|
||||
"Download Directory Set to:\n${dir.defaultDir()} "
|
||||
)
|
||||
}else{
|
||||
showPopUpMessage(
|
||||
"NO WRITE ACCESS on \n$path ,\nReverting Back to Previous"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Show dialog whenever you want by
|
||||
chooser.show()
|
||||
}
|
||||
|
||||
private fun showPopUpMessage(string: String, long: Boolean = false) {
|
||||
android.widget.Toast.makeText(
|
||||
applicationContext,
|
||||
@ -256,12 +219,7 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
override fun setDownloadDirectoryAction() = setUpOnPrefClickListener()
|
||||
|
||||
override fun queryActiveTracks() {
|
||||
val serviceIntent = Intent(this@MainActivity, ForegroundService::class.java).apply {
|
||||
action = "query"
|
||||
}
|
||||
ContextCompat.startForegroundService(this@MainActivity, serviceIntent)
|
||||
}
|
||||
override fun queryActiveTracks() = this@MainActivity.queryActiveTracks()
|
||||
|
||||
override fun giveDonation() {
|
||||
openPlatform("",platformLink = "https://razorpay.com/payment-button/pl_GnKuuDBdBu0ank/view/?utm_source=payment_button&utm_medium=button&utm_campaign=payment_button")
|
||||
@ -337,6 +295,48 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
)
|
||||
|
||||
private fun queryActiveTracks() {
|
||||
val serviceIntent = Intent(this@MainActivity, ForegroundService::class.java).apply {
|
||||
action = "query"
|
||||
}
|
||||
ContextCompat.startForegroundService(this@MainActivity, serviceIntent)
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private fun setUpOnPrefClickListener() {
|
||||
// Initialize Builder
|
||||
val chooser = StorageChooser.Builder()
|
||||
.withActivity(this)
|
||||
.withFragmentManager(fragmentManager)
|
||||
.withMemoryBar(true)
|
||||
.setTheme(StorageChooser.Theme(applicationContext).apply {
|
||||
scheme = applicationContext.resources.getIntArray(R.array.default_dark)
|
||||
})
|
||||
.setDialogTitle("Set Download Directory")
|
||||
.allowCustomPath(true)
|
||||
.setType(StorageChooser.DIRECTORY_CHOOSER)
|
||||
.build()
|
||||
|
||||
// get path that the user has chosen
|
||||
chooser.setOnSelectListener { path ->
|
||||
Log.d("Setting Base Path", path)
|
||||
val f = File(path)
|
||||
if (f.canWrite()) {
|
||||
// hell yeah :)
|
||||
dir.setDownloadDirectory(path)
|
||||
showPopUpMessage(
|
||||
"Download Directory Set to:\n${dir.defaultDir()} "
|
||||
)
|
||||
}else{
|
||||
showPopUpMessage(
|
||||
"NO WRITE ACCESS on \n$path ,\nReverting Back to Previous"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Show dialog whenever you want by
|
||||
chooser.show()
|
||||
}
|
||||
|
||||
@SuppressLint("ObsoleteSdkInt")
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
@ -418,6 +418,10 @@ class MainActivity : ComponentActivity() {
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
initializeBroadcast()
|
||||
if(visibleChild is SpotiFlyerRoot.Child.List) {
|
||||
// Update Track List Statuses when Returning to App
|
||||
queryActiveTracks()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
@ -161,7 +161,7 @@ sealed class Event<out V : Any?, out E : Throwable>: ReadOnlyProperty<Any?, V> {
|
||||
class Failure<out E : Throwable>(val error: E) : Event<Nothing, E>() {
|
||||
override fun component2(): E = error
|
||||
|
||||
override val value: Nothing = throw error
|
||||
override val value: Nothing get() = throw error
|
||||
|
||||
fun getThrowable(): E = error
|
||||
|
||||
|
@ -134,7 +134,7 @@ sealed class SuspendableEvent<out V : Any?, out E : Throwable>: ReadOnlyProperty
|
||||
override fun component1(): V? = null
|
||||
override fun component2(): E? = error
|
||||
|
||||
override val value: V = throw error
|
||||
override val value: V get() = throw error
|
||||
|
||||
fun getThrowable(): E = error
|
||||
|
||||
@ -158,7 +158,9 @@ sealed class SuspendableEvent<out V : Any?, out E : Throwable>: ReadOnlyProperty
|
||||
return value?.let { Success<V, Nothing>(it) } ?: error(fail())
|
||||
}
|
||||
|
||||
suspend inline fun <V : Any?, E : Throwable> of(crossinline block: suspend () -> V): SuspendableEvent<V, E> = try {
|
||||
suspend inline fun <V : Any?, E : Throwable> of(
|
||||
crossinline block: suspend () -> V
|
||||
): SuspendableEvent<V, E> = try {
|
||||
Success(block())
|
||||
} catch (ex: Throwable) {
|
||||
Failure(ex as E)
|
||||
|
@ -6,7 +6,7 @@ package com.shabinder.common.di.saavn
|
||||
fun String.escape(): String {
|
||||
val output = StringBuilder()
|
||||
for (element in this) {
|
||||
val chx = element.toInt()
|
||||
val chx = element.code
|
||||
if (chx != 0) {
|
||||
when (element) {
|
||||
'\n' -> {
|
||||
@ -76,7 +76,7 @@ fun String.unescape(): String {
|
||||
/*if (!x.isLetterOrDigit()) {
|
||||
throw RuntimeException("Bad character in unicode escape.")
|
||||
}*/
|
||||
hex.append(x.toLowerCase())
|
||||
hex.append(x.lowercaseChar())
|
||||
}
|
||||
i += 4 // consume those four digits.
|
||||
val code = hex.toString().toInt(16)
|
||||
|
@ -22,7 +22,7 @@ package com.shabinder.common.di.utils
|
||||
// Gist: https://gist.github.com/fluidsonic/ba32de21c156bbe8424c8d5fc20dcd8e
|
||||
|
||||
import com.shabinder.common.di.dispatcherIO
|
||||
import io.ktor.utils.io.core.Closeable
|
||||
import io.ktor.utils.io.core.*
|
||||
import kotlinx.atomicfu.atomic
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
@ -96,7 +96,7 @@ class ParallelExecutor(
|
||||
return
|
||||
|
||||
var change = expectedCount - actualCount
|
||||
while (change > 0 && killQueue.poll() != null)
|
||||
while (change > 0 && killQueue.tryReceive().getOrNull() != null)
|
||||
change -= 1
|
||||
|
||||
if (change > 0)
|
||||
@ -104,7 +104,7 @@ class ParallelExecutor(
|
||||
repeat(change) { launchProcessor() }
|
||||
}
|
||||
else
|
||||
repeat(-change) { killQueue.offer(Unit) }
|
||||
repeat(-change) { killQueue.trySend(Unit).isSuccess }
|
||||
}
|
||||
|
||||
private class Operation<Result>(
|
||||
|
@ -33,7 +33,7 @@ import com.shabinder.common.models.PlatformQueryResult
|
||||
import com.shabinder.common.models.TrackDetails
|
||||
import com.shabinder.common.models.methods
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.collect
|
||||
|
||||
internal class SpotiFlyerListStoreProvider(
|
||||
private val dir: Dir,
|
||||
@ -80,7 +80,7 @@ internal class SpotiFlyerListStoreProvider(
|
||||
)
|
||||
}
|
||||
|
||||
downloadProgressFlow.collectLatest { map ->
|
||||
downloadProgressFlow.collect { map ->
|
||||
logger.d(map.size.toString(), "ListStore: flow Updated")
|
||||
val updatedTrackList = getState().trackList.updateTracksStatuses(map)
|
||||
if (updatedTrackList.isNotEmpty()) dispatch(Result.UpdateTrackList(updatedTrackList))
|
||||
|
Loading…
Reference in New Issue
Block a user