-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: view subscriptions in settings
- Loading branch information
1 parent
f1d16ba
commit 6c1176a
Showing
14 changed files
with
221 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/src/main/java/ani/dantotsu/settings/SubscriptionItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ani.dantotsu.settings | ||
|
||
import android.content.Intent | ||
import android.view.View | ||
import androidx.core.content.ContextCompat | ||
import ani.dantotsu.R | ||
import ani.dantotsu.databinding.ItemSubscriptionBinding | ||
import ani.dantotsu.media.MediaDetailsActivity | ||
import ani.dantotsu.notifications.subscription.SubscriptionHelper | ||
import com.xwray.groupie.GroupieAdapter | ||
import com.xwray.groupie.Item | ||
import com.xwray.groupie.viewbinding.BindableItem | ||
|
||
class SubscriptionItem( | ||
val id: Int, | ||
private val media: SubscriptionHelper.Companion.SubscribeMedia, | ||
private val adapter: GroupieAdapter | ||
) : BindableItem<ItemSubscriptionBinding>() { | ||
private lateinit var binding: ItemSubscriptionBinding | ||
override fun bind(p0: ItemSubscriptionBinding, p1: Int) { | ||
val context = p0.root.context | ||
binding = p0 | ||
val parserName = if (media.isAnime) | ||
SubscriptionHelper.getAnimeParser(media.id).name | ||
else | ||
SubscriptionHelper.getMangaParser(media.id).name | ||
val mediaName = media.name | ||
val showName = "$mediaName - $parserName" | ||
binding.subscriptionName.text = showName | ||
binding.root.setOnClickListener { | ||
ContextCompat.startActivity( | ||
context, | ||
Intent(context, MediaDetailsActivity::class.java).putExtra( | ||
"mediaId", media.id | ||
), | ||
null | ||
) | ||
} | ||
binding.deleteSubscription.setOnClickListener { | ||
SubscriptionHelper.deleteSubscription(id, true) | ||
adapter.remove(this) | ||
} | ||
} | ||
|
||
override fun getLayout(): Int { | ||
return R.layout.item_subscription | ||
} | ||
|
||
override fun initializeViewBinding(p0: View): ItemSubscriptionBinding { | ||
return ItemSubscriptionBinding.bind(p0) | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/ani/dantotsu/settings/SubscriptionsBottomDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package ani.dantotsu.settings | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import ani.dantotsu.BottomSheetDialogFragment | ||
import ani.dantotsu.R | ||
import ani.dantotsu.databinding.BottomSheetRecyclerBinding | ||
import ani.dantotsu.notifications.subscription.SubscriptionHelper | ||
import com.xwray.groupie.GroupieAdapter | ||
|
||
class SubscriptionsBottomDialog : BottomSheetDialogFragment() { | ||
private var _binding: BottomSheetRecyclerBinding? = null | ||
private val binding get() = _binding!! | ||
private val adapter: GroupieAdapter = GroupieAdapter() | ||
private var subscriptions: Map<Int, SubscriptionHelper.Companion.SubscribeMedia> = mapOf() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
_binding = BottomSheetRecyclerBinding.inflate(inflater, container, false) | ||
return _binding?.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
binding.repliesRecyclerView.adapter = adapter | ||
binding.repliesRecyclerView.layoutManager = LinearLayoutManager( | ||
context, | ||
LinearLayoutManager.VERTICAL, | ||
false | ||
) | ||
val context = requireContext() | ||
binding.title.text = context.getString(R.string.subscriptions) | ||
binding.replyButton.visibility = View.GONE | ||
subscriptions.forEach { (id, media) -> | ||
adapter.add(SubscriptionItem(id, media, adapter)) | ||
} | ||
} | ||
|
||
override fun onDestroyView() { | ||
_binding = null | ||
super.onDestroyView() | ||
} | ||
|
||
companion object { | ||
fun newInstance(subscriptions: Map<Int, SubscriptionHelper.Companion.SubscribeMedia>): SubscriptionsBottomDialog { | ||
val dialog = SubscriptionsBottomDialog() | ||
dialog.subscriptions = subscriptions | ||
return dialog | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginVertical="16dp" | ||
android:layout_marginHorizontal="8dp" | ||
android:orientation="horizontal" | ||
tools:ignore="UseCompoundDrawables"> | ||
|
||
<TextView | ||
android:id="@+id/subscriptionName" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_vertical" | ||
android:layout_weight="1" | ||
android:fontFamily="@font/poppins_bold" | ||
android:text="@string/placeholder" | ||
android:textSize="16sp" /> | ||
|
||
<ImageView | ||
android:id="@+id/deleteSubscription" | ||
android:layout_width="28dp" | ||
android:layout_height="28dp" | ||
android:layout_gravity="center_vertical" | ||
android:layout_marginEnd="8dp" | ||
android:contentDescription="@string/delete" | ||
android:src="@drawable/ic_circle_cancel" | ||
app:tint="?attr/colorOnBackground" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters