Skip to content

Commit

Permalink
feat: longclicklistener for AL profile now accessible everywhere (#228)
Browse files Browse the repository at this point in the history
* feat: added longclicklistener for AL profile in AnimePageAdapter and MangaPageAdapter

* feat: add delete to smaller media bottom sheet
  • Loading branch information
sneazy-ibo authored Mar 9, 2024
1 parent 7504bb9 commit 7f36eba
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 14 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/ani/dantotsu/home/AnimePageAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import ani.dantotsu.media.CalendarActivity
import ani.dantotsu.media.GenreActivity
import ani.dantotsu.media.MediaAdaptor
import ani.dantotsu.media.SearchActivity
import ani.dantotsu.profile.ProfileActivity
import ani.dantotsu.px
import ani.dantotsu.setSafeOnClickListener
import ani.dantotsu.setSlideIn
Expand Down Expand Up @@ -94,6 +95,15 @@ class AnimePageAdapter : RecyclerView.Adapter<AnimePageAdapter.AnimePageViewHold
SettingsDialogFragment.newInstance(SettingsDialogFragment.Companion.PageType.ANIME)
dialogFragment.show((it.context as AppCompatActivity).supportFragmentManager, "dialog")
}
binding.animeUserAvatar.setOnLongClickListener { view ->
ContextCompat.startActivity(
view.context,
Intent(view.context, ProfileActivity::class.java)
.putExtra("userId", Anilist.userid),null
)
false
}

binding.animeNotificationCount.visibility = if (Anilist.unreadNotificationCount > 0) View.VISIBLE else View.GONE
binding.animeNotificationCount.text = Anilist.unreadNotificationCount.toString()

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/ani/dantotsu/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class HomeFragment : Fragment() {
binding.homeUserAvatarContainer.setOnLongClickListener {
ContextCompat.startActivity(
requireContext(), Intent(requireContext(), ProfileActivity::class.java)
.putExtra("userId", Anilist.userid), null
.putExtra("userId", Anilist.userid),null
)
false
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/ani/dantotsu/home/MangaPageAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ani.dantotsu.loadImage
import ani.dantotsu.media.GenreActivity
import ani.dantotsu.media.MediaAdaptor
import ani.dantotsu.media.SearchActivity
import ani.dantotsu.profile.ProfileActivity
import ani.dantotsu.px
import ani.dantotsu.setSafeOnClickListener
import ani.dantotsu.setSlideIn
Expand Down Expand Up @@ -90,6 +91,14 @@ class MangaPageAdapter : RecyclerView.Adapter<MangaPageAdapter.MangaPageViewHold
SettingsDialogFragment.newInstance(SettingsDialogFragment.Companion.PageType.MANGA)
dialogFragment.show((it.context as AppCompatActivity).supportFragmentManager, "dialog")
}
binding.mangaUserAvatar.setOnLongClickListener { view ->
ContextCompat.startActivity(
view.context,
Intent(view.context, ProfileActivity::class.java)
.putExtra("userId", Anilist.userid),null
)
false
}

binding.mangaSearchBar.setEndIconOnClickListener {
binding.mangaSearchBarText.performClick()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@ class MediaListDialogSmallFragment : BottomSheetDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding.mediaListContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> { bottomMargin += navBarHeight }
val scope = viewLifecycleOwner.lifecycleScope
binding.mediaListDelete.setOnClickListener {
val id = media.userListId
if (id != null) {
viewLifecycleOwner.lifecycleScope.launch {
withContext(Dispatchers.IO) {
try {
Anilist.mutation.deleteList(id)
MAL.query.deleteList(media.anime != null, media.idMAL)
} catch (e: Exception) {
withContext(Dispatchers.Main) {
snackString("Failed to delete because of... ${e.message}")
}
return@withContext
}
}
withContext(Dispatchers.Main) {
Refresh.all()
snackString(getString(R.string.deleted_from_list))
dismissAllowingStateLoss()
}
}
} else {
snackString(getString(R.string.no_list_id))
Refresh.all()
}
}

binding.mediaListProgressBar.visibility = View.GONE
binding.mediaListLayout.visibility = View.VISIBLE
Expand Down
47 changes: 34 additions & 13 deletions app/src/main/res/layout/bottom_sheet_media_list_small.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,43 @@
android:fontFamily="@font/poppins_bold"
android:text="@string/list_private" />

<Button
android:id="@+id/mediaListSave"
style="@style/Widget.Material3.Button.OutlinedButton"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginTop="24dp"
android:fontFamily="@font/poppins_bold"
android:insetTop="0dp"
android:insetBottom="0dp"
android:padding="8dp"
android:text="@string/save"
android:textSize="16sp"
app:cornerRadius="16dp"
app:strokeColor="?attr/colorPrimaryContainer" />
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:orientation="horizontal">

<Button
android:id="@+id/mediaListDelete"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="128dp"
android:layout_height="56dp"
android:layout_gravity="center"
android:fontFamily="@font/poppins_bold"
android:insetTop="0dp"
android:insetBottom="0dp"
android:padding="8dp"
android:text="@string/delete"
android:textSize="16sp"
app:cornerRadius="16dp"
app:strokeColor="?attr/colorPrimaryContainer" />

<Button
android:id="@+id/mediaListSave"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:fontFamily="@font/poppins_bold"
android:insetTop="0dp"
android:insetBottom="0dp"
android:padding="8dp"
android:text="@string/save"
android:textSize="16sp"
app:cornerRadius="16dp"
app:strokeColor="?attr/colorPrimaryContainer" />
</LinearLayout>
</LinearLayout>

<androidx.cardview.widget.CardView
Expand Down

0 comments on commit 7f36eba

Please sign in to comment.