mirror of
https://github.com/Shabinder/SpotiFlyer.git
synced 2024-11-22 09:04:32 +01:00
Revert Back to old/gold java.io.File!
- SAF is painfully slow. - SAF brings nothing but more issues and hacks. - External SdCard write Access wont be fixed (NO SAF).
This commit is contained in:
parent
d9ba60dbbf
commit
3e2032713f
@ -270,6 +270,43 @@ class MainActivity : ComponentActivity() {
|
|||||||
|
|
||||||
override val isInternetAvailable get() = internetAvailability.value ?: true
|
override val isInternetAvailable get() = internetAvailability.value ?: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Analytics Will Only Be Sent if User Granted us the Permission
|
||||||
|
* */
|
||||||
|
override val analytics = object: Analytics {
|
||||||
|
override fun appLaunchEvent() {
|
||||||
|
if(dir.isAnalyticsEnabled){
|
||||||
|
TrackHelper.track()
|
||||||
|
.event("events","App_Launch")
|
||||||
|
.name("App Launch").with(tracker)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun homeScreenVisit() {
|
||||||
|
if(dir.isAnalyticsEnabled){
|
||||||
|
// HomeScreen Visit Event
|
||||||
|
TrackHelper.track().screen("/main_activity/home_screen")
|
||||||
|
.title("HomeScreen").with(tracker)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun listScreenVisit() {
|
||||||
|
if(dir.isAnalyticsEnabled){
|
||||||
|
// ListScreen Visit Event
|
||||||
|
TrackHelper.track().screen("/main_activity/list_screen")
|
||||||
|
.title("ListScreen").with(tracker)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun donationDialogVisit() {
|
||||||
|
if (dir.isAnalyticsEnabled) {
|
||||||
|
// Donation Dialog Open Event
|
||||||
|
TrackHelper.track().screen("/main_activity/donation_dialog")
|
||||||
|
.title("DonationDialog").with(tracker)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -38,6 +38,11 @@ import java.io.InputStream
|
|||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ignore Deprecation
|
||||||
|
* Deprecation is only a Suggestion P-)
|
||||||
|
* */
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
actual class Dir actual constructor(
|
actual class Dir actual constructor(
|
||||||
private val logger: Kermit,
|
private val logger: Kermit,
|
||||||
private val settings: Settings,
|
private val settings: Settings,
|
||||||
@ -45,6 +50,16 @@ actual class Dir actual constructor(
|
|||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
const val DirKey = "downloadDir"
|
const val DirKey = "downloadDir"
|
||||||
|
const val AnalyticsKey = "analytics"
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Do we have Analytics Permission?
|
||||||
|
* - Defaults to `False`
|
||||||
|
* */
|
||||||
|
actual val isAnalyticsEnabled get() = settings.getBooleanOrNull(AnalyticsKey) ?: false
|
||||||
|
|
||||||
|
actual fun enableAnalytics() {
|
||||||
|
settings.putBoolean(AnalyticsKey,true)
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun setDownloadDirectory(newBasePath:String) = settings.putString(DirKey,newBasePath)
|
actual fun setDownloadDirectory(newBasePath:String) = settings.putString(DirKey,newBasePath)
|
||||||
@ -74,6 +89,7 @@ actual class Dir actual constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
actual suspend fun clearCache(): Unit = withContext(dispatcherIO) {
|
actual suspend fun clearCache(): Unit = withContext(dispatcherIO) {
|
||||||
File(imageCacheDir()).deleteRecursively()
|
File(imageCacheDir()).deleteRecursively()
|
||||||
}
|
}
|
||||||
@ -93,8 +109,8 @@ actual class Dir actual constructor(
|
|||||||
/*Make intermediate Dirs if they don't exist yet*/
|
/*Make intermediate Dirs if they don't exist yet*/
|
||||||
songFile.parentFile?.mkdirs()
|
songFile.parentFile?.mkdirs()
|
||||||
}
|
}
|
||||||
|
// Write Bytes to Media File
|
||||||
if(mp3ByteArray.isNotEmpty()) songFile.writeBytes(mp3ByteArray)
|
songFile.writeBytes(mp3ByteArray)
|
||||||
|
|
||||||
when (trackDetails.outputFilePath.substringAfterLast('.')) {
|
when (trackDetails.outputFilePath.substringAfterLast('.')) {
|
||||||
".mp3" -> {
|
".mp3" -> {
|
||||||
@ -140,9 +156,6 @@ actual class Dir actual constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (e:Exception){
|
}catch (e:Exception){
|
||||||
withContext(Dispatchers.Main){
|
|
||||||
//Toast.makeText(appContext,"Could Not Create File:\n${songFile.absolutePath}",Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
if(songFile.exists()) songFile.delete()
|
if(songFile.exists()) songFile.delete()
|
||||||
logger.e { "${songFile.absolutePath} could not be created" }
|
logger.e { "${songFile.absolutePath} could not be created" }
|
||||||
}
|
}
|
||||||
@ -167,6 +180,7 @@ actual class Dir actual constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("BlockingMethodInNonBlockingContext")
|
||||||
actual suspend fun cacheImage(image: Any, path: String):Unit = withContext(dispatcherIO) {
|
actual suspend fun cacheImage(image: Any, path: String):Unit = withContext(dispatcherIO) {
|
||||||
try {
|
try {
|
||||||
FileOutputStream(path).use { out ->
|
FileOutputStream(path).use { out ->
|
||||||
@ -177,6 +191,7 @@ actual class Dir actual constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("BlockingMethodInNonBlockingContext")
|
||||||
private suspend fun freshImage(url: String): Bitmap? = withContext(dispatcherIO) {
|
private suspend fun freshImage(url: String): Bitmap? = withContext(dispatcherIO) {
|
||||||
try {
|
try {
|
||||||
val source = URL(url)
|
val source = URL(url)
|
||||||
|
@ -37,6 +37,8 @@ expect class Dir (
|
|||||||
spotiFlyerDatabase: SpotiFlyerDatabase,
|
spotiFlyerDatabase: SpotiFlyerDatabase,
|
||||||
) {
|
) {
|
||||||
val db: Database?
|
val db: Database?
|
||||||
|
val isAnalyticsEnabled:Boolean
|
||||||
|
fun enableAnalytics()
|
||||||
fun isPresent(path: String): Boolean
|
fun isPresent(path: String): Boolean
|
||||||
fun fileSeparator(): String
|
fun fileSeparator(): String
|
||||||
fun defaultDir(): String
|
fun defaultDir(): String
|
||||||
|
Loading…
Reference in New Issue
Block a user