-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature|optimize|fix] Supports setting the max cache size and max ba…
…ck cache size of the player; Search, Article screen support show empty tips; fix long title on media library screen; optimize code
- Loading branch information
Showing
23 changed files
with
491 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/skyd/anivu/model/preference/player/PlayerMaxBackCacheSizePreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.skyd.anivu.model.preference.player | ||
|
||
import android.content.Context | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.longPreferencesKey | ||
import com.skyd.anivu.base.BasePreference | ||
import com.skyd.anivu.ext.dataStore | ||
import com.skyd.anivu.ext.put | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
object PlayerMaxBackCacheSizePreference : BasePreference<Long> { | ||
private const val PLAYER_MAX_CACHE_SIZE = "playerMaxBackCacheSize" | ||
override val default = 20L * 1024 * 1024 // 20 MB | ||
|
||
val key = longPreferencesKey(PLAYER_MAX_CACHE_SIZE) | ||
|
||
fun put(context: Context, scope: CoroutineScope, value: Long) { | ||
scope.launch(Dispatchers.IO) { | ||
context.dataStore.put(key, value) | ||
} | ||
} | ||
|
||
override fun fromPreferences(preferences: Preferences): Long = preferences[key] ?: default | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/skyd/anivu/model/preference/player/PlayerMaxCacheSizePreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.skyd.anivu.model.preference.player | ||
|
||
import android.content.Context | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.longPreferencesKey | ||
import com.skyd.anivu.base.BasePreference | ||
import com.skyd.anivu.ext.dataStore | ||
import com.skyd.anivu.ext.put | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
object PlayerMaxCacheSizePreference : BasePreference<Long> { | ||
private const val PLAYER_MAX_CACHE_SIZE = "playerMaxCacheSize" | ||
override val default = 10L * 1024 * 1024 // 10 MB | ||
|
||
val key = longPreferencesKey(PLAYER_MAX_CACHE_SIZE) | ||
|
||
fun put(context: Context, scope: CoroutineScope, value: Long) { | ||
scope.launch(Dispatchers.IO) { | ||
context.dataStore.put(key, value) | ||
} | ||
} | ||
|
||
override fun fromPreferences(preferences: Preferences): Long = preferences[key] ?: default | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
app/src/main/java/com/skyd/anivu/ui/component/AnimatedPlaceholder.kt
This file was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
app/src/main/java/com/skyd/anivu/ui/component/Placeholder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.skyd.anivu.ui.component | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.BoxScope | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.sizeIn | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import com.skyd.anivu.R | ||
|
||
@Composable | ||
fun EmptyPlaceholder( | ||
modifier: Modifier = Modifier, | ||
contentPadding: PaddingValues = PaddingValues(), | ||
) { | ||
AnimatedPlaceholder( | ||
modifier = modifier, | ||
contentPadding = contentPadding, | ||
resId = R.raw.lottie_empty_1, | ||
tip = stringResource(id = R.string.empty_tip_1), | ||
) | ||
} | ||
|
||
@Composable | ||
fun AnimatedPlaceholder( | ||
modifier: Modifier = Modifier, | ||
contentPadding: PaddingValues = PaddingValues(), | ||
@androidx.annotation.RawRes resId: Int, | ||
tip: String, | ||
) { | ||
WithTextPlaceholder( | ||
modifier = modifier, | ||
contentPadding = contentPadding, | ||
text = tip, | ||
) { | ||
AniVuLottieAnimation(resId = resId) | ||
} | ||
} | ||
|
||
@Composable | ||
fun WithTextPlaceholder( | ||
modifier: Modifier = Modifier, | ||
contentPadding: PaddingValues = PaddingValues(), | ||
text: String, | ||
content: @Composable BoxScope.() -> Unit, | ||
) { | ||
BasePlaceholder( | ||
modifier = modifier, | ||
contentPadding = contentPadding, | ||
) { | ||
Column( | ||
modifier = Modifier.padding(vertical = 20.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
) { | ||
Box( | ||
modifier = Modifier.sizeIn(maxHeight = 240.dp, maxWidth = 220.dp), | ||
contentAlignment = Alignment.Center, | ||
content = content, | ||
) | ||
Text( | ||
modifier = Modifier.padding(top = 10.dp), | ||
text = text, | ||
textAlign = TextAlign.Center, | ||
style = MaterialTheme.typography.bodyLarge, | ||
color = MaterialTheme.colorScheme.onBackground, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun CircularProgressPlaceholder( | ||
modifier: Modifier = Modifier, | ||
contentPadding: PaddingValues = PaddingValues(), | ||
) { | ||
BasePlaceholder( | ||
modifier = modifier, | ||
contentPadding = contentPadding, | ||
) { | ||
CircularProgressIndicator() | ||
} | ||
} | ||
|
||
@Composable | ||
fun BasePlaceholder( | ||
modifier: Modifier = Modifier, | ||
contentPadding: PaddingValues = PaddingValues(), | ||
content: @Composable BoxScope.() -> Unit, | ||
) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.then(modifier) | ||
.padding(contentPadding), | ||
contentAlignment = Alignment.Center, | ||
content = content, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.