Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 51 additions & 23 deletions app/src/main/java/com/lagradost/cloudstream3/ui/WatchType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,67 @@ package com.lagradost.cloudstream3.ui
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.syncproviders.SyncAPI

/**
* Enum class representing watch states for library.
*
* @property internalId The unique ID used internally to identify the watch type and to store data. This value must never be changed.
* @property stringRes The string resource ID representing the watch type name.
* @property iconRes The drawable resource ID representing the watch type icon.
*/
enum class WatchType(val internalId: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int) {
WATCHING(0, R.string.type_watching, R.drawable.ic_baseline_bookmark_24),
COMPLETED(1, R.string.type_completed, R.drawable.ic_baseline_bookmark_24),
ONHOLD(2, R.string.type_on_hold, R.drawable.ic_baseline_bookmark_24),
DROPPED(3, R.string.type_dropped, R.drawable.ic_baseline_bookmark_24),
PLANTOWATCH(4, R.string.type_plan_to_watch, R.drawable.ic_baseline_bookmark_24),
NONE(5, R.string.type_none, R.drawable.ic_baseline_add_24);
WATCHING(internalId = 0, R.string.type_watching, R.drawable.ic_baseline_bookmark_24),
COMPLETED(internalId = 1, R.string.type_completed, R.drawable.ic_baseline_bookmark_24),
ONHOLD(internalId = 2, R.string.type_on_hold, R.drawable.ic_baseline_bookmark_24),
DROPPED(internalId = 3, R.string.type_dropped, R.drawable.ic_baseline_bookmark_24),
PLANTOWATCH(internalId = 4, R.string.type_plan_to_watch, R.drawable.ic_baseline_bookmark_24),

// Any types with negative internal IDs, or those for which the order is important,
// should be placed at the bottom. This ensures that we don't need to worry about
// their internal IDs when adding new types in the future.
NOTINTERESTED(internalId = -2, R.string.type_not_interested, R.drawable.ic_baseline_bookmark_24),
NONE(internalId = -1, R.string.type_none, R.drawable.ic_baseline_add_24);

companion object {
/**
* Finds a [WatchType] corresponding to the given [internalId].
*
* @param id The internal ID to search for.
* @return The corresponding [WatchType], or [NONE] if no match is found.
*/
fun fromInternalId(id: Int?) = entries.find { value -> value.internalId == id } ?: NONE
}
}

/**
* Enum class representing various watch states for when using a remote library in [SyncAPI].
*
* @property internalId The unique ID used internally to identify the watch type and to store data locally. This value must never be changed.
* @property stringRes The string resource ID representing the watch type name.
* @property iconRes The drawable resource ID representing the watch type icon.
*/
enum class SyncWatchType(val internalId: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int) {
/*
-1 -> None
0 -> Watching
1 -> Completed
2 -> OnHold
3 -> Dropped
4 -> PlanToWatch
5 -> ReWatching
*/
NONE(-1, R.string.type_none, R.drawable.ic_baseline_add_24),
WATCHING(0, R.string.type_watching, R.drawable.ic_baseline_bookmark_24),
COMPLETED(1, R.string.type_completed, R.drawable.ic_baseline_bookmark_24),
ONHOLD(2, R.string.type_on_hold, R.drawable.ic_baseline_bookmark_24),
DROPPED(3, R.string.type_dropped, R.drawable.ic_baseline_bookmark_24),
PLANTOWATCH(4, R.string.type_plan_to_watch, R.drawable.ic_baseline_bookmark_24),
REWATCHING(5, R.string.type_re_watching, R.drawable.ic_baseline_bookmark_24);
NONE(internalId = -1, R.string.type_none, R.drawable.ic_baseline_add_24),
WATCHING(internalId = 0, R.string.type_watching, R.drawable.ic_baseline_bookmark_24),
COMPLETED(internalId = 1, R.string.type_completed, R.drawable.ic_baseline_bookmark_24),
ONHOLD(internalId = 2, R.string.type_on_hold, R.drawable.ic_baseline_bookmark_24),
DROPPED(internalId = 3, R.string.type_dropped, R.drawable.ic_baseline_bookmark_24),
PLANTOWATCH(internalId = 4, R.string.type_plan_to_watch, R.drawable.ic_baseline_bookmark_24),
REWATCHING(internalId = 5, R.string.type_re_watching, R.drawable.ic_baseline_bookmark_24),

// Any types with negative internal IDs, or those for which the order is important,
// should be placed at the bottom, except for "NONE", which has a negative ID but is
// placed at the top for UI reasons.
NOTINTERESTED(internalId = -2, R.string.type_not_interested, R.drawable.ic_baseline_bookmark_24);

companion object {
/**
* Finds a [SyncWatchType] corresponding to the given [internalId].
*
* @param id The internal ID to search for.
* @return The corresponding [SyncWatchType], or [NONE] if no match is found.
*/
fun fromInternalId(id: Int?) = entries.find { value -> value.internalId == id } ?: NONE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ class HomeParentItemAdapterPreview(
Pair(itemView.findViewById(R.id.home_type_completed_btt), WatchType.COMPLETED),
Pair(itemView.findViewById(R.id.home_type_dropped_btt), WatchType.DROPPED),
Pair(itemView.findViewById(R.id.home_type_on_hold_btt), WatchType.ONHOLD),
Pair(itemView.findViewById(R.id.home_plan_to_watch_btt), WatchType.PLANTOWATCH),
Pair(itemView.findViewById(R.id.home_type_plan_to_watch_btt), WatchType.PLANTOWATCH),
Pair(itemView.findViewById(R.id.home_type_not_interested_btt), WatchType.NOTINTERESTED),
)

private val toggleListHolder: ChipGroup? = itemView.findViewById(R.id.home_type_holder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.mvvm.observe
import com.lagradost.cloudstream3.mvvm.observeNullable
import com.lagradost.cloudstream3.services.SubscriptionWorkManager
import com.lagradost.cloudstream3.ui.SyncWatchType
import com.lagradost.cloudstream3.ui.WatchType
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_LONG_CLICK
Expand Down Expand Up @@ -929,23 +930,19 @@ open class ResultFragmentPhone : FullScreenPlayer() {
}
context?.let { ctx ->
val arrayAdapter = ArrayAdapter<String>(ctx, R.layout.sort_bottom_single_choice)
/*
-1 -> None
0 -> Watching
1 -> Completed
2 -> OnHold
3 -> Dropped
4 -> PlanToWatch
5 -> ReWatching
*/
/**
* @see SyncWatchType.internalId
* For the corresponding values.
*/
val items = listOf(
R.string.none,
R.string.type_watching,
R.string.type_completed,
R.string.type_on_hold,
R.string.type_dropped,
R.string.type_plan_to_watch,
R.string.type_re_watching
R.string.type_re_watching,
R.string.type_not_interested
).map { ctx.getString(it) }
arrayAdapter.addAll(items)
syncBinding?.apply {
Expand Down
20 changes: 15 additions & 5 deletions app/src/main/res/layout/fragment_home_head.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@
android:layout_height="wrap_content"

android:nextFocusLeft="@id/nav_rail_view"
android:nextFocusRight="@id/home_plan_to_watch_btt"
android:nextFocusRight="@id/home_type_plan_to_watch_btt"
android:text="@string/type_watching" />

<com.google.android.material.chip.Chip
android:id="@+id/home_plan_to_watch_btt"
android:id="@+id/home_type_plan_to_watch_btt"
style="@style/ChipFilled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -252,7 +252,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:nextFocusLeft="@id/home_plan_to_watch_btt"
android:nextFocusLeft="@id/home_type_plan_to_watch_btt"
android:nextFocusRight="@id/home_type_dropped_btt"
android:text="@string/type_on_hold" />

Expand All @@ -270,10 +270,20 @@
android:id="@+id/home_type_completed_btt"
style="@style/ChipFilled"
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:nextFocusLeft="@id/home_type_dropped_btt"
android:nextFocusRight="@id/home_type_not_interested_btt"
android:text="@string/type_completed" />

<com.google.android.material.chip.Chip
android:id="@+id/home_type_not_interested_btt"
style="@style/ChipFilled"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:nextFocusLeft="@id/home_type_completed_btt"
android:text="@string/type_not_interested" />
</com.google.android.material.chip.ChipGroup>

</HorizontalScrollView>
Expand All @@ -299,4 +309,4 @@
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/home_result_grid" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
18 changes: 15 additions & 3 deletions app/src/main/res/layout/fragment_home_head_tv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,14 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:nextFocusLeft="@id/nav_rail_view"
android:nextFocusRight="@id/home_plan_to_watch_btt"
android:nextFocusRight="@id/home_type_plan_to_watch_btt"

android:nextFocusUp="@id/home_watch_child_recyclerview"
android:nextFocusDown="@id/home_bookmarked_child_recyclerview"
android:text="@string/type_watching" />

<com.google.android.material.chip.Chip
android:id="@+id/home_plan_to_watch_btt"
android:id="@+id/home_type_plan_to_watch_btt"
style="@style/ChipFilled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -326,7 +326,7 @@
style="@style/ChipFilled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:nextFocusLeft="@id/home_plan_to_watch_btt"
android:nextFocusLeft="@id/home_type_plan_to_watch_btt"
android:nextFocusRight="@id/home_type_dropped_btt"

android:nextFocusUp="@id/home_watch_child_recyclerview"
Expand All @@ -351,10 +351,22 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:nextFocusLeft="@id/home_type_dropped_btt"
android:nextFocusRight="@id/home_type_not_interested_btt"

android:nextFocusUp="@id/home_watch_child_recyclerview"
android:nextFocusDown="@id/home_bookmarked_child_recyclerview"
android:text="@string/type_completed" />

<com.google.android.material.chip.Chip
android:id="@+id/home_type_not_interested_btt"
style="@style/ChipFilled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:nextFocusLeft="@id/home_type_completed_btt"

android:nextFocusUp="@id/home_watch_child_recyclerview"
android:nextFocusDown="@id/home_bookmarked_child_recyclerview"
android:text="@string/type_not_interested" />
</com.google.android.material.chip.ChipGroup>
</HorizontalScrollView>

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 @@ -132,6 +132,7 @@
<string name="type_plan_to_watch">Plan to Watch</string>
<string name="type_none" translatable="false">@string/none</string>
<string name="type_re_watching">Rewatching</string>
<string name="type_not_interested">Not Interested</string>
<string name="play_movie_button">Play Movie</string>
<string name="play_trailer_button">Play Trailer</string>
<string name="play_livestream_button">Play Livestream</string>
Expand Down