Skip to content

Commit

Permalink
feat: long click "continue Watching" to see hidden items
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush2622 committed May 4, 2024
1 parent aae80f6 commit 7aa0951
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ class AnilistQueries {

suspend fun initHomePage(): Map<String, ArrayList<*>> {
val removeList = PrefManager.getCustomVal("removeList", setOf<Int>())
val removedMedia = ArrayList<Media>()
val toShow: List<Boolean> =
PrefManager.getVal(PrefName.HomeLayout) // anime continue, anime fav, anime planned, manga continue, manga fav, manga planned, recommendations
var query = """{"""
Expand Down Expand Up @@ -465,6 +466,8 @@ class AnilistQueries {
if (m.id !in removeList) {
m.cameFromContinue = true
subMap[m.id] = m
} else {
removedMedia.add(m)
}
}
}
Expand All @@ -475,6 +478,8 @@ class AnilistQueries {
if (m.id !in removeList) {
m.cameFromContinue = true
subMap[m.id] = m
} else {
removedMedia.add(m)
}
}
}
Expand Down Expand Up @@ -512,6 +517,8 @@ class AnilistQueries {
if (m.id !in removeList) {
m.cameFromContinue = true
subMap[m.id] = m
} else {
removedMedia.add(m)
}
}
}
Expand Down Expand Up @@ -542,6 +549,8 @@ class AnilistQueries {
val m = Media(i).apply { isFav = true }
if (m.id !in removeList) {
returnArray.add(m)
} else {
removedMedia.add(m)
}
}
}
Expand Down Expand Up @@ -643,6 +652,7 @@ class AnilistQueries {
list.addAll(0, anilistActivities)
returnMap["status"] = ArrayList(list)
}
returnMap["hidden"] = removedMedia.distinctBy { it.id } as ArrayList<Media>
}
return returnMap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ class AnilistHomeViewModel : ViewModel() {

fun getRecommendation(): LiveData<ArrayList<Media>> = recommendation

private val userStatus: MutableLiveData<ArrayList<User>> =
MutableLiveData<ArrayList<User>>(null)

fun getUserStatus(): LiveData<ArrayList<User>> = userStatus

private val hidden: MutableLiveData<ArrayList<Media>> =
MutableLiveData<ArrayList<Media>>(null)

fun getHidden(): LiveData<ArrayList<Media>> = hidden
@Suppress("UNCHECKED_CAST")
suspend fun initHomePage() {
val res = Anilist.query.initHomePage()
Expand All @@ -91,12 +100,10 @@ class AnilistHomeViewModel : ViewModel() {
res["favoriteManga"]?.let { mangaFav.postValue(it as ArrayList<Media>?) }
res["plannedManga"]?.let { mangaPlanned.postValue(it as ArrayList<Media>?) }
res["recommendations"]?.let { recommendation.postValue(it as ArrayList<Media>?) }
res["hidden"]?.let { hidden.postValue(it as ArrayList<Media>?) }
res["status"]?.let { userStatus.postValue(it as ArrayList<User>?) }
}
private val userStatus: MutableLiveData<ArrayList<User>> =
MutableLiveData<ArrayList<User>>(null)

fun getUserStatus(): LiveData<ArrayList<User>> = userStatus

suspend fun loadMain(context: FragmentActivity) {
Anilist.getSavedToken()
Expand Down
32 changes: 31 additions & 1 deletion app/src/main/java/ani/dantotsu/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ class HomeFragment : Fragment() {
binding.homeFavAnime,
binding.homeFavAnimeMore,
getString(R.string.fav_anime)

)

initRecyclerView(
Expand Down Expand Up @@ -376,6 +375,37 @@ class HomeFragment : Fragment() {
}

}
model.getHidden().observe(viewLifecycleOwner) {
if (it != null) {
if (it.isNotEmpty()) {
binding.homeHiddenItemsRecyclerView.adapter = MediaAdaptor(0, it, requireActivity())
binding.homeHiddenItemsRecyclerView.layoutManager = LinearLayoutManager(
requireContext(),
LinearLayoutManager.HORIZONTAL,
false
)
binding.homeContinueWatch.setOnLongClickListener {
binding.homeHiddenItemsContainer.visibility = View.VISIBLE
binding.homeHiddenItemsRecyclerView.layoutAnimation =
LayoutAnimationController(setSlideIn(), 0.25f)
true
}
binding.homeHiddenItemsMore.setSafeOnClickListener { _ ->
ContextCompat.startActivity(
requireActivity(), Intent(requireActivity(), MediaListViewActivity::class.java)
.putExtra("title", getString(R.string.hidden))
.putExtra("media", it),
null
)
}
binding.homeHiddenItemsTitle.setOnLongClickListener {
binding.homeHiddenItemsContainer.visibility = View.GONE
true
}
}
}
}

binding.homeUserAvatarContainer.startAnimation(setSlideUp())

model.empty.observe(viewLifecycleOwner)
Expand Down
52 changes: 51 additions & 1 deletion app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,56 @@
tools:orientation="horizontal" />
</FrameLayout>

<LinearLayout
android:id="@+id/homeHiddenItemsContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:ignore="UseCompoundDrawables">

<TextView
android:id="@+id/homeHiddenItemsTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_weight="1"
android:fontFamily="@font/poppins_bold"
android:padding="8dp"
android:text="@string/hidden"
android:textSize="16sp" />

<ImageView
android:id="@+id/homeHiddenItemsMore"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="16dp"
android:fontFamily="@font/poppins_bold"
android:padding="8dp"
android:src="@drawable/arrow_mark"
android:textSize="16sp"
tools:ignore="ContentDescription" />
</LinearLayout>

<ani.dantotsu.FadingEdgeRecyclerView
android:id="@+id/homeHiddenItemsRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:requiresFadingEdge="horizontal"
tools:itemCount="4"
tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_media_compact"
tools:orientation="horizontal" />
</LinearLayout>

<LinearLayout
android:id="@+id/homeContinueWatchingContainer"
android:layout_width="match_parent"
Expand Down Expand Up @@ -827,8 +877,8 @@
android:id="@+id/homePlannedManga"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="24dp"
android:layout_weight="1"
android:fontFamily="@font/poppins_bold"
android:padding="8dp"
android:text="@string/planned_manga"
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 @@ -973,4 +973,5 @@ Non quae tempore quo provident laudantium qui illo dolor vel quia dolor et exerc
<string name="copy_report">Copy Report</string>
<string name="share_as_file">Share as file</string>
<string name="hide_in_home_screen">Hide in Home Screen</string>
<string name="hidden">Hidden</string>
</resources>

0 comments on commit 7aa0951

Please sign in to comment.