Skip to content

Commit

Permalink
[optimize|doc] Optimize the Group edit page; modify the equals method…
Browse files Browse the repository at this point in the history
… of the GroupBean; update README
  • Loading branch information
SkyD666 committed Jun 2, 2024
1 parent 0719b8b commit df36159
Show file tree
Hide file tree
Showing 22 changed files with 402 additions and 391 deletions.
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,16 @@
2. **Automatically update RSS** subscriptions
3. **Download enclosures** (enclosure tags) of **torrent or magnet** links in RSS articles
4. **Seeding** downloaded files
5. **Play downloaded videos**
6. Support variable playback **speed**, **long press** to speed up playback
7. **Double-finger** gesture to **rotate and zoom** video
5. **Play media enclosures or downloaded videos**
6. Support variable playback **speed**, setup **audio track**, **subtitle track**, etc
7. **Double-finger** gesture to **rotate and zoom** video, **long press** to speed up playback
8. **Swipe** on the video to **control volume**, **brightness**, and **playback position**
9. **Searching** existing **RSS subscription content**
10. **Play other videos on the phone**
11. Support **dark mode**
12. ......

## 🚧 Todo

1. Automatically **download new videos**
3. **Float** video playback **window**
4. **Automatically** play the **next video**
11. Support **custom MPV player**
12. Support **import and export** subscriptions via **OPML**
13. Support **dark mode**
14. ......

## 🤩 Screenshots

Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
minSdk = 24
targetSdk = 34
versionCode = 17
versionName = "1.1-beta43"
versionName = "1.1-beta44"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/skyd/anivu/model/bean/GroupBean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ open class GroupBean(
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is GroupBean) return false
return groupId == other.groupId

if (groupId != other.groupId) return false
if (name != other.name) return false

return true
}

override fun hashCode(): Int {
return groupId.hashCode()
var result = groupId.hashCode()
result = 31 * result + name.hashCode()
return result
}

object DefaultGroup :
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/skyd/anivu/model/db/dao/FeedDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ interface FeedDao {
)
suspend fun getFeedsNotIn(groupIds: List<String>): List<FeedViewBean>

@Transaction
@Query(
"""
SELECT * FROM $FEED_VIEW_NAME
WHERE :groupId IS NULL AND ${FeedBean.GROUP_ID_COLUMN} IS NULL OR
${FeedBean.GROUP_ID_COLUMN} = :groupId
"""
)
suspend fun getFeedsByGroupId(groupId: String?): List<FeedViewBean>

@Transaction
@RawQuery(observedEntities = [FeedBean::class, ArticleBean::class])
fun getFeedPagingSource(sql: SupportSQLiteQuery): PagingSource<Int, FeedViewBean>
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/skyd/anivu/model/db/dao/GroupDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ interface GroupDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun setGroup(groupBean: GroupBean)

@Transaction
@Query("SELECT * FROM `$GROUP_TABLE_NAME` WHERE ${GroupBean.GROUP_ID_COLUMN} = :groupId")
suspend fun getGroupById(groupId: String): GroupBean

@Transaction
@Delete
suspend fun removeGroup(groupBean: GroupBean): Int
Expand All @@ -37,6 +41,13 @@ interface GroupDao {
@Query("DELETE FROM `$GROUP_TABLE_NAME` WHERE ${GroupBean.GROUP_ID_COLUMN} = :groupId")
suspend fun removeGroup(groupId: String): Int

@Transaction
@Query(
"UPDATE `$GROUP_TABLE_NAME` SET ${GroupBean.NAME_COLUMN} = :name " +
"WHERE ${GroupBean.GROUP_ID_COLUMN} = :groupId"
)
suspend fun renameGroup(groupId: String, name: String): Int

@Transaction
suspend fun removeGroupWithFeed(groupId: String): Int {
removeGroup(groupId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import androidx.paging.PagingConfig
import androidx.paging.PagingData
import com.skyd.anivu.base.BaseRepository
import com.skyd.anivu.model.bean.ArticleWithFeed
import com.skyd.anivu.model.bean.GroupBean
import com.skyd.anivu.model.db.dao.ArticleDao
import com.skyd.anivu.model.db.dao.FeedDao
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flatMapConcat
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject
Expand All @@ -28,6 +30,15 @@ class ArticleRepository @Inject constructor(
}.flow.flowOn(Dispatchers.IO)
}

fun refreshGroupArticles(groupId: String?): Flow<Unit> {
return flow {
val realGroupId = if (groupId == GroupBean.DEFAULT_GROUP_ID) null else groupId
emit(feedDao.getFeedsByGroupId(realGroupId).map { it.feed.url })
}.flatMapConcat {
refreshArticleList(it)
}.flowOn(Dispatchers.IO)
}

fun refreshArticleList(feedUrls: List<String>): Flow<Unit> {
return flow {
emit(coroutineScope {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ class FeedRepository @Inject constructor(
else flowOf(groupDao.removeGroupWithFeed(groupId)).flowOn(Dispatchers.IO)
}

suspend fun renameGroup(groupId: String, name: String): Flow<GroupBean> {
return if (groupId == GroupBean.DEFAULT_GROUP_ID) flow {
emit(GroupBean.DefaultGroup)
} else flow {
groupDao.renameGroup(groupId, name)
emit(groupDao.getGroupById(groupId))
}.flowOn(Dispatchers.IO)
}

suspend fun moveGroupFeedsTo(fromGroupId: String, toGroupId: String): Flow<Int> {
val realFromGroupId = if (fromGroupId == GroupBean.DEFAULT_GROUP_ID) null else fromGroupId
val realToGroupId = if (toGroupId == GroupBean.DEFAULT_GROUP_ID) null else toGroupId
Expand All @@ -66,7 +75,7 @@ class FeedRepository @Inject constructor(
url: String,
groupId: String?,
nickname: String?,
): Flow<Unit> {
): Flow<FeedBean> {
return flow {
val realNickname = if (nickname.isNullOrBlank()) null else nickname
val realGroupId =
Expand All @@ -79,7 +88,8 @@ class FeedRepository @Inject constructor(
)
)
}
emit(feedDao.setFeedWithArticle(feedWithArticleBean))
feedDao.setFeedWithArticle(feedWithArticleBean)
emit(feedWithArticleBean.feed)
}.flowOn(Dispatchers.IO)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class DefaultGroup1Proxy(
onExpandChange = group1Proxy.onExpandChange,
isEmpty = group1Proxy.isEmpty,
onShowAllArticles = group1Proxy.onShowAllArticles,
onDelete = group1Proxy.onDelete,
onFeedsMoveTo = group1Proxy.onMoveFeedsTo,
onEdit = group1Proxy.onEdit,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,29 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.outlined.KeyboardArrowUp
import androidx.compose.material.icons.outlined.MoveUp
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.skyd.anivu.R
import com.skyd.anivu.model.bean.GroupBean
import com.skyd.anivu.ui.component.AniVuIconButton
import com.skyd.anivu.ui.component.dialog.DeleteWarningDialog
import com.skyd.anivu.ui.component.lazyverticalgrid.adapter.LazyGridAdapter

open class Group1Proxy(
val isExpand: (GroupBean) -> Boolean = { false },
val onExpandChange: (GroupBean, Boolean) -> Unit = { _, _ -> },
val isEmpty: (index: Int) -> Boolean,
val onShowAllArticles: (GroupBean) -> Unit = { },
val onDelete: ((GroupBean) -> Unit)? = null,
val onMoveFeedsTo: ((from: GroupBean) -> Unit)? = null,
val onEdit: ((GroupBean) -> Unit)? = null,
) : LazyGridAdapter.Proxy<GroupBean>() {
@Composable
override fun Draw(index: Int, data: GroupBean) {
Expand All @@ -51,8 +41,7 @@ open class Group1Proxy(
onExpandChange = onExpandChange,
isEmpty = isEmpty,
onShowAllArticles = onShowAllArticles,
onDelete = onDelete,
onFeedsMoveTo = onMoveFeedsTo,
onEdit = onEdit,
)
}
}
Expand All @@ -67,12 +56,9 @@ fun Group1Item(
onExpandChange: (GroupBean, Boolean) -> Unit,
isEmpty: (index: Int) -> Boolean,
onShowAllArticles: (GroupBean) -> Unit,
onDelete: ((GroupBean) -> Unit)? = null,
onFeedsMoveTo: ((GroupBean) -> Unit)? = null,
onEdit: ((GroupBean) -> Unit)? = null,
) {
var expand by remember(data) { mutableStateOf(initExpand(data)) }
var expandMenu by rememberSaveable { mutableStateOf(false) }
var openDeleteWarningDialog by rememberSaveable { mutableStateOf(false) }

val backgroundShapeCorner: Dp by animateDpAsState(
targetValue = if (expand && !isEmpty(index)) 0.dp else SHAPE_CORNER_DP,
Expand All @@ -93,7 +79,9 @@ fun Group1Item(
)
.background(color = MaterialTheme.colorScheme.surfaceContainer)
.combinedClickable(
onLongClick = { expandMenu = true },
onLongClick = if (onEdit == null) null else {
{ onEdit(data) }
},
onClick = { onShowAllArticles(data) },
)
.padding(start = 20.dp, end = 8.dp)
Expand All @@ -120,43 +108,5 @@ fun Group1Item(
contentDescription = null,
rotate = expandIconRotate,
)

DropdownMenu(
expanded = expandMenu,
onDismissRequest = { expandMenu = false },
) {
DropdownMenuItem(
text = { Text(text = stringResource(id = R.string.delete)) },
leadingIcon = {
Icon(imageVector = Icons.Outlined.Delete, contentDescription = null)
},
enabled = onDelete != null && data.groupId != GroupBean.DEFAULT_GROUP_ID,
onClick = {
openDeleteWarningDialog = true
expandMenu = false
},
)
DropdownMenuItem(
text = { Text(text = stringResource(id = R.string.feed_screen_group_feeds_move_to)) },
leadingIcon = {
Icon(imageVector = Icons.Outlined.MoveUp, contentDescription = null)
},
enabled = onFeedsMoveTo != null,
onClick = {
onFeedsMoveTo?.invoke(data)
expandMenu = false
},
)
}
}

DeleteWarningDialog(
visible = openDeleteWarningDialog,
title = stringResource(id = R.string.feed_screen_delete_group_warning_title),
text = stringResource(id = R.string.feed_screen_delete_group_warning, data.name),
confirmText = stringResource(id = R.string.delete),
onConfirm = { onDelete?.invoke(data) },
onDismiss = { openDeleteWarningDialog = false },
onDismissRequest = { openDeleteWarningDialog = false },
)
}
Loading

0 comments on commit df36159

Please sign in to comment.