Skip to content
This repository was archived by the owner on Jul 18, 2026. It is now read-only.

Commit 47abe9f

Browse files
authored
Merge pull request #210 from misaka10032w/develop
[Add] 搜索结果页增加已播放状态标记功能,可在设置中关闭
2 parents 9023b46 + 8ef6d4f commit 47abe9f

15 files changed

Lines changed: 70 additions & 2 deletions

File tree

app/src/main/java/com/yenaly/han1meviewer/Preferences.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ object Preferences {
132132
val videoQuality: String
133133
get() = preferenceSp.getString(HomeSettingsFragment.DEFAULT_VIDEO_QUALITY, "1080P") ?: "1080P"
134134

135+
val showPlayedIndicator: Boolean
136+
get() = preferenceSp.getBoolean(HomeSettingsFragment.SHOW_PLAYED_INDICATOR,true)
137+
135138
val fakeLauncherIcon: String
136139
get() = preferenceSp.getString(
137140
HomeSettingsFragment.FAKE_LAUNCHER_ICON,

app/src/main/java/com/yenaly/han1meviewer/logic/DatabaseRepo.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ object DatabaseRepo {
202202

203203
suspend fun findBy(videoCode: String) =
204204
watchHistoryDao.findBy(videoCode)
205+
206+
suspend fun getWatched(resultList: List<String>) =
207+
watchHistoryDao.getWatchedCodes(resultList)
205208
}
206209

207210
object HanimeDownload {

app/src/main/java/com/yenaly/han1meviewer/logic/dao/WatchHistoryDao.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ abstract class WatchHistoryDao {
3030
@Query("SELECT * FROM WatchHistoryEntity WHERE (`videoCode` = :videoCode) LIMIT 1")
3131
abstract suspend fun findBy(videoCode: String): WatchHistoryEntity?
3232

33+
@Query("SELECT videoCode FROM WatchHistoryEntity WHERE videoCode IN (:codes)")
34+
abstract suspend fun getWatchedCodes(codes: List<String>): List<String>
35+
3336
@Query("UPDATE WatchHistoryEntity SET progress = :progress WHERE videoCode = :videoCode")
3437
abstract suspend fun updateProgress(videoCode: String, progress: Long)
3538

app/src/main/java/com/yenaly/han1meviewer/logic/model/HanimeInfo.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ data class HanimeInfo(
2626
override var itemType: Int,
2727
override val reviews: String? = "",
2828
override val currentArtist: String? = "",
29+
val watched: Boolean ?= false,
2930
): VideoItemType , HanimeInfoType {
3031
companion object {
3132
const val NORMAL = 0

app/src/main/java/com/yenaly/han1meviewer/ui/adapter/HanimeVideoRvAdapter.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import coil.load
1414
import com.chad.library.adapter4.BaseQuickAdapter
1515
import com.chad.library.adapter4.viewholder.QuickViewHolder
1616
import com.itxca.spannablex.spannable
17+
import com.yenaly.han1meviewer.Preferences
1718
import com.yenaly.han1meviewer.R
1819
import com.yenaly.han1meviewer.VIDEO_LAYOUT_MATCH_PARENT
1920
import com.yenaly.han1meviewer.VIDEO_LAYOUT_WRAP_CONTENT
@@ -76,6 +77,8 @@ class HanimeVideoRvAdapter(
7677
crossfade(true)
7778
}
7879
holder.getView<TextView>(R.id.title).text = item.title
80+
if (Preferences.showPlayedIndicator)
81+
holder.getView<ImageView>(R.id.watched_icon).isVisible = item.watched == true
7982
}
8083

8184
HanimeInfo.NORMAL -> {
@@ -121,6 +124,8 @@ class HanimeVideoRvAdapter(
121124
item.artist.text()
122125
}
123126
}
127+
if (Preferences.showPlayedIndicator)
128+
holder.getView<ImageView>(R.id.watched_icon).isVisible = item.watched == true
124129
}
125130
}
126131
}

app/src/main/java/com/yenaly/han1meviewer/ui/fragment/settings/HomeSettingsFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class HomeSettingsFragment : YenalySettingsFragment(R.xml.settings_home) {
8181
companion object {
8282
const val VIDEO_LANGUAGE = "video_language"
8383
const val DEFAULT_VIDEO_QUALITY = "default_video_quality"
84-
84+
const val SHOW_PLAYED_INDICATOR = "show_played_indicator"
8585
const val ALLOW_PIP_MDOE = "allow_pip_mode"
8686
const val PLAYER_SETTINGS = "player_settings"
8787
const val H_KEYFRAME_SETTINGS = "h_keyframe_settings"

app/src/main/java/com/yenaly/han1meviewer/ui/viewmodel/SearchViewModel.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import kotlinx.coroutines.flow.flowOn
2626
import kotlinx.coroutines.flow.getAndUpdate
2727
import kotlinx.coroutines.flow.update
2828
import kotlinx.coroutines.launch
29+
import kotlinx.coroutines.withContext
2930

3031
/**
3132
* @project Hanime1
@@ -121,7 +122,18 @@ class SearchViewModel(
121122
if (prev is PageLoadingState.Loading) _searchFlow.value = emptyList()
122123
_searchFlow.update { prevList ->
123124
when (state) {
124-
is PageLoadingState.Success -> prevList + state.info
125+
// is PageLoadingState.Success -> prevList + state.info
126+
is PageLoadingState.Success -> {
127+
val list = state.info
128+
val codes = list.map { it.videoCode }
129+
val watchedCodes= withContext(Dispatchers.IO) {
130+
DatabaseRepo.WatchHistory.getWatched(codes).toSet()
131+
}
132+
val updatedList = list.map { item ->
133+
item.copy(watched = watchedCodes.contains(item.videoCode))
134+
}
135+
prevList + updatedList
136+
}
125137
is PageLoadingState.Loading -> emptyList()
126138
else -> prevList
127139
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="oval">
4+
<solid android:color="?attr/colorSurfaceVariant"/>
5+
</shape>

app/src/main/res/layout/item_hanime_video.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@
5555
android:gravity="center"
5656
android:text="@string/now_playing"
5757
android:textColor="?attr/colorSurface" />
58+
<ImageView
59+
android:id="@+id/watched_icon"
60+
android:layout_width="20dp"
61+
android:layout_height="20dp"
62+
android:layout_gravity="top|end"
63+
android:layout_margin="6dp"
64+
android:contentDescription="@null"
65+
android:src="@drawable/ic_baseline_check_circle_24"
66+
android:background="@drawable/icon_circle_bg"
67+
android:visibility="gone"
68+
tools:visibility="visible"/>
5869

5970
<androidx.constraintlayout.widget.ConstraintLayout
6071
android:layout_width="match_parent"

app/src/main/res/layout/item_hanime_video_simplified.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@
4343
android:contentDescription="@null"
4444
app:shapeAppearanceOverlay="@style/TopRoundCornerImageView" />
4545

46+
<ImageView
47+
android:id="@+id/watched_icon"
48+
android:layout_width="20dp"
49+
android:layout_height="20dp"
50+
android:layout_gravity="top|end"
51+
android:layout_margin="6dp"
52+
android:contentDescription="@null"
53+
android:src="@drawable/ic_baseline_check_circle_24"
54+
android:background="@drawable/icon_circle_bg"
55+
android:visibility="gone"
56+
tools:visibility="visible"/>
4657
</FrameLayout>
4758

4859
<TextView

0 commit comments

Comments
 (0)