Skip to content

Commit

Permalink
[optimize|fix] Optimize the feed page error display; fix the wrong do…
Browse files Browse the repository at this point in the history
…wnload progress indicator; optimize the download notification channel display name
  • Loading branch information
SkyD666 committed Aug 21, 2024
1 parent 9e3178c commit 1e80983
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 41 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
minSdk = 24
targetSdk = 35
versionCode = 22
versionName = "2.1-alpha16"
versionName = "2.1-alpha17"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.core.app.TaskStackBuilder
import androidx.core.net.toUri
import androidx.work.CoroutineWorker
import androidx.work.ExistingWorkPolicy
Expand Down Expand Up @@ -286,8 +285,7 @@ class DownloadTorrentWorker(context: Context, parameters: WorkerParameters) :
private fun createForegroundInfo(): ForegroundInfo {
val title = name.ifNullOfBlank { applicationContext.getString(R.string.downloading) }
// This PendingIntent can be used to cancel the worker
val cancelIntent = WorkManager.getInstance(applicationContext)
.createCancelPendingIntent(id)
val cancelIntent = WorkManager.getInstance(applicationContext).createCancelPendingIntent(id)
val contentIntent = PendingIntent.getActivity(
applicationContext,
0,
Expand Down Expand Up @@ -335,7 +333,9 @@ class DownloadTorrentWorker(context: Context, parameters: WorkerParameters) :
@RequiresApi(Build.VERSION_CODES.O)
private fun createChannel() {
val channel = NotificationChannel(
CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW
CHANNEL_ID,
applicationContext.getString(R.string.torrent_download_channel_name),
NotificationManager.IMPORTANCE_LOW,
)
notificationManager.createNotificationChannel(channel)
}
Expand Down Expand Up @@ -527,7 +527,6 @@ class DownloadTorrentWorker(context: Context, parameters: WorkerParameters) :
const val STATE = "state"
const val TORRENT_LINK_UUID = "torrentLinkUuid"
const val CHANNEL_ID = "downloadTorrent"
const val CHANNEL_NAME = "downloadMessage"

private val coroutineScope = CoroutineScope(Dispatchers.IO)

Expand Down
20 changes: 15 additions & 5 deletions app/src/main/java/com/skyd/anivu/ui/component/Toast.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
package com.skyd.anivu.ui.component

import android.os.Handler
import android.os.Looper
import android.widget.Toast
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import com.skyd.anivu.appContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

private var uiThreadHandler: Handler = Handler(Looper.getMainLooper())
private val scope = CoroutineScope(Dispatchers.Main.immediate)

fun CharSequence.showToast(duration: Int = Toast.LENGTH_SHORT) {
uiThreadHandler.post {
val toast = Toast.makeText(appContext, this, duration)
scope.launch {
val toast = Toast.makeText(appContext, this@showToast, duration)
toast.duration = duration
toast.show()
}
}

@Composable
fun Toast(vararg keys: Any?, text: CharSequence, duration: Int = Toast.LENGTH_SHORT) {
LaunchedEffect(*keys) {
text.showToast(duration)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ArrowUpward
import androidx.compose.material.icons.outlined.Refresh
Expand Down Expand Up @@ -380,6 +382,9 @@ private fun ArticleList(
key = { _, item -> (item as ArticleWithFeed).articleWithEnclosure.article.articleId },
)
} else {
EmptyPlaceholder(contentPadding = contentPadding)
EmptyPlaceholder(
modifier = Modifier.verticalScroll(rememberScrollState()),
contentPadding = contentPadding,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ fun DownloadItem(
}
}

Column(
modifier = Modifier.padding(16.dp)
) {
Column(modifier = Modifier.padding(16.dp)) {
Text(
text = data.name,
style = MaterialTheme.typography.bodyMedium,
Expand Down Expand Up @@ -198,7 +196,8 @@ fun DownloadItem(
ProgressIndicator(
modifier = Modifier
.padding(top = 6.dp)
.fillMaxWidth(), data = data
.fillMaxWidth(),
data = data,
)
}
}
Expand All @@ -209,8 +208,6 @@ private fun ProgressIndicator(
data: DownloadInfoBean
) {
when (data.downloadState) {
DownloadInfoBean.DownloadState.Seeding,
DownloadInfoBean.DownloadState.SeedingPaused,
DownloadInfoBean.DownloadState.Downloading,
DownloadInfoBean.DownloadState.StorageMovedFailed,
DownloadInfoBean.DownloadState.ErrorPaused,
Expand All @@ -219,6 +216,8 @@ private fun ProgressIndicator(
}

DownloadInfoBean.DownloadState.Init -> LinearProgressIndicator(modifier = modifier)
DownloadInfoBean.DownloadState.Seeding,
DownloadInfoBean.DownloadState.SeedingPaused,
DownloadInfoBean.DownloadState.Completed -> LinearProgressIndicator(
modifier = modifier,
progress = { 1f },
Expand Down
32 changes: 9 additions & 23 deletions app/src/main/java/com/skyd/anivu/ui/screen/feed/FeedScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import com.skyd.anivu.ui.component.AniVuIconButton
import com.skyd.anivu.ui.component.AniVuTopBar
import com.skyd.anivu.ui.component.AniVuTopBarStyle
import com.skyd.anivu.ui.component.ClipboardTextField
import com.skyd.anivu.ui.component.Toast
import com.skyd.anivu.ui.component.dialog.AniVuDialog
import com.skyd.anivu.ui.component.dialog.TextFieldDialog
import com.skyd.anivu.ui.component.dialog.WaitingDialog
Expand Down Expand Up @@ -285,32 +286,17 @@ private fun FeedList(
is FeedEvent.AddFeedResultEvent.Failed ->
snackbarHostState.showSnackbarWithLaunchedEffect(message = event.msg, key1 = event)

is FeedEvent.EditFeedResultEvent.Failed ->
snackbarHostState.showSnackbarWithLaunchedEffect(message = event.msg, key1 = event)

is FeedEvent.InitFeetListResultEvent.Failed ->
snackbarHostState.showSnackbarWithLaunchedEffect(message = event.msg, key1 = event)

is FeedEvent.RemoveFeedResultEvent.Failed ->
snackbarHostState.showSnackbarWithLaunchedEffect(message = event.msg, key1 = event)

is FeedEvent.RefreshFeedResultEvent.Failed ->
snackbarHostState.showSnackbarWithLaunchedEffect(message = event.msg, key1 = event)

is FeedEvent.CreateGroupResultEvent.Failed ->
snackbarHostState.showSnackbarWithLaunchedEffect(message = event.msg, key1 = event)

is FeedEvent.MoveFeedsToGroupResultEvent.Failed ->
snackbarHostState.showSnackbarWithLaunchedEffect(message = event.msg, key1 = event)

is FeedEvent.DeleteGroupResultEvent.Failed ->
snackbarHostState.showSnackbarWithLaunchedEffect(message = event.msg, key1 = event)

is FeedEvent.EditGroupResultEvent.Failed ->
snackbarHostState.showSnackbarWithLaunchedEffect(message = event.msg, key1 = event)

is FeedEvent.ReadAllResultEvent.Failed ->
snackbarHostState.showSnackbarWithLaunchedEffect(message = event.msg, key1 = event)
is FeedEvent.EditFeedResultEvent.Failed -> Toast(event, text = event.msg)
is FeedEvent.RemoveFeedResultEvent.Failed -> Toast(event, text = event.msg)
is FeedEvent.RefreshFeedResultEvent.Failed -> Toast(event, text = event.msg)
is FeedEvent.CreateGroupResultEvent.Failed -> Toast(event, text = event.msg)
is FeedEvent.MoveFeedsToGroupResultEvent.Failed -> Toast(event, text = event.msg)
is FeedEvent.DeleteGroupResultEvent.Failed -> Toast(event, text = event.msg)
is FeedEvent.EditGroupResultEvent.Failed -> Toast(event, text = event.msg)
is FeedEvent.ReadAllResultEvent.Failed -> Toast(event, text = event.msg)

is FeedEvent.EditFeedResultEvent.Success -> LaunchedEffect(event) {
if (openEditFeedDialog != null) openEditFeedDialog = event.feed
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
<string name="player_config_screen_cache_category">缓存</string>
<string name="player_config_screen_max_cache_size">最大前向缓存大小</string>
<string name="player_config_screen_max_back_cache_size">最大保留缓存大小</string>
<string name="torrent_download_channel_name">下载任务</string>
<plurals name="feed_screen_read_all_result">
<item quantity="other">已读 %d 项</item>
</plurals>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
<string name="player_config_screen_cache_category">Cache</string>
<string name="player_config_screen_max_cache_size">Max cache size</string>
<string name="player_config_screen_max_back_cache_size">Max back cache size</string>
<string name="torrent_download_channel_name">Download task</string>
<plurals name="feed_screen_read_all_result">
<item quantity="one">Read %d item</item>
<item quantity="other">Read %d items</item>
Expand Down

0 comments on commit 1e80983

Please sign in to comment.