nice transition for offline mode

This commit is contained in:
rebelonion 2024-01-22 22:51:51 -06:00
parent f70ce39fb7
commit 9c67a7e357
4 changed files with 49 additions and 18 deletions

View file

@ -25,6 +25,10 @@ import android.widget.TextView
import androidx.annotation.OptIn import androidx.annotation.OptIn
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.cardview.widget.CardView import androidx.cardview.widget.CardView
import androidx.core.app.ActivityOptionsCompat
import androidx.core.content.ContextCompat
import androidx.core.util.Pair
import androidx.core.view.ViewCompat
import androidx.core.view.marginBottom import androidx.core.view.marginBottom
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.media3.common.util.UnstableApi import androidx.media3.common.util.UnstableApi
@ -187,9 +191,17 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
return@let return@let
} }
MediaDetailsActivity.mediaSingleton = mediaModel MediaDetailsActivity.mediaSingleton = mediaModel
startActivity( ContextCompat.startActivity(
requireActivity(),
Intent(requireContext(), MediaDetailsActivity::class.java) Intent(requireContext(), MediaDetailsActivity::class.java)
.putExtra("download", true) .putExtra("download", true),
ActivityOptionsCompat.makeSceneTransitionAnimation(
requireActivity(),
Pair.create(
requireActivity().findViewById<ImageView>(R.id.itemCompactImage),
ViewCompat.getTransitionName(requireActivity().findViewById(R.id.itemCompactImage))
),
).toBundle()
) )
} ?: run { } ?: run {
snackString("no media found") snackString("no media found")

View file

@ -51,8 +51,8 @@ class OfflineMangaAdapter(
val itemScore = view.findViewById<TextView>(R.id.itemCompactScore) val itemScore = view.findViewById<TextView>(R.id.itemCompactScore)
val itemScoreBG = view.findViewById<View>(R.id.itemCompactScoreBG) val itemScoreBG = view.findViewById<View>(R.id.itemCompactScoreBG)
val ongoing = view.findViewById<CardView>(R.id.itemCompactOngoing) val ongoing = view.findViewById<CardView>(R.id.itemCompactOngoing)
val totalchapter = view.findViewById<TextView>(R.id.itemCompactTotal) val totalChapter = view.findViewById<TextView>(R.id.itemCompactTotal)
val typeimage = view.findViewById<ImageView>(R.id.itemCompactTypeImage) val typeImage = view.findViewById<ImageView>(R.id.itemCompactTypeImage)
val type = view.findViewById<TextView>(R.id.itemCompactRelation) val type = view.findViewById<TextView>(R.id.itemCompactRelation)
val typeView = view.findViewById<LinearLayout>(R.id.itemCompactType) val typeView = view.findViewById<LinearLayout>(R.id.itemCompactType)
@ -61,16 +61,16 @@ class OfflineMangaAdapter(
val chapters = view.findViewById<TextView>(R.id.itemTotal) val chapters = view.findViewById<TextView>(R.id.itemTotal)
chapters.text = " Chapters" chapters.text = " Chapters"
bannerView.setImageURI(item.banner) bannerView.setImageURI(item.banner)
totalchapter.text = item.totalChapter totalChapter.text = item.totalChapter
} else if (style == 1) { } else if (style == 1) {
val readchapter = val readChapter =
view.findViewById<TextView>(R.id.itemCompactUserProgress) // for compact view view.findViewById<TextView>(R.id.itemCompactUserProgress) // for compact view
readchapter.text = item.readChapter readChapter.text = item.readChapter
totalchapter.text = " | " + item.totalChapter totalChapter.text = " | " + item.totalChapter
} }
// Bind item data to the views // Bind item data to the views
typeimage.setImageResource(if (item.type == "Novel") R.drawable.ic_round_book_24 else R.drawable.ic_round_import_contacts_24) typeImage.setImageResource(if (item.type == "Novel") R.drawable.ic_round_book_24 else R.drawable.ic_round_import_contacts_24)
type.text = item.type type.text = item.type
typeView.visibility = View.VISIBLE typeView.visibility = View.VISIBLE
imageView.setImageURI(item.image) imageView.setImageURI(item.image)

View file

@ -23,6 +23,10 @@ import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.cardview.widget.CardView import androidx.cardview.widget.CardView
import androidx.core.app.ActivityOptionsCompat
import androidx.core.content.ContextCompat
import androidx.core.util.Pair
import androidx.core.view.ViewCompat
import androidx.core.view.marginBottom import androidx.core.view.marginBottom
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import ani.dantotsu.R import ani.dantotsu.R
@ -62,7 +66,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
private var downloads: List<OfflineMangaModel> = listOf() private var downloads: List<OfflineMangaModel> = listOf()
private lateinit var gridView: GridView private lateinit var gridView: GridView
private lateinit var adapter: OfflineMangaAdapter private lateinit var adapter: OfflineMangaAdapter
private lateinit var total : TextView private lateinit var total: TextView
private var uiSettings: UserInterfaceSettings = private var uiSettings: UserInterfaceSettings =
loadData("ui_settings") ?: UserInterfaceSettings() loadData("ui_settings") ?: UserInterfaceSettings()
@ -132,7 +136,8 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
layoutList.setOnClickListener { layoutList.setOnClickListener {
selected(it as ImageView) selected(it as ImageView)
style = 0 style = 0
requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit().putInt("offline_view", style!!).apply() requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit()
.putInt("offline_view", style!!).apply()
gridView.visibility = View.GONE gridView.visibility = View.GONE
gridView = view.findViewById(R.id.gridView) gridView = view.findViewById(R.id.gridView)
adapter.notifyNewGrid() adapter.notifyNewGrid()
@ -143,13 +148,15 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
layoutcompact.setOnClickListener { layoutcompact.setOnClickListener {
selected(it as ImageView) selected(it as ImageView)
style = 1 style = 1
requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit().putInt("offline_view", style!!).apply() requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit()
.putInt("offline_view", style!!).apply()
gridView.visibility = View.GONE gridView.visibility = View.GONE
gridView = view.findViewById(R.id.gridView1) gridView = view.findViewById(R.id.gridView1)
adapter.notifyNewGrid() adapter.notifyNewGrid()
grid() grid()
} }
gridView = if (style == 0) view.findViewById(R.id.gridView) else view.findViewById(R.id.gridView1) gridView =
if (style == 0) view.findViewById(R.id.gridView) else view.findViewById(R.id.gridView1)
total = view.findViewById(R.id.total) total = view.findViewById(R.id.total)
grid() grid()
return view return view
@ -164,7 +171,8 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
adapter = OfflineMangaAdapter(requireContext(), downloads, this) adapter = OfflineMangaAdapter(requireContext(), downloads, this)
gridView.adapter = adapter gridView.adapter = adapter
gridView.scheduleLayoutAnimation() gridView.scheduleLayoutAnimation()
total.text = if (gridView.count > 0) "Manga and Novels (${gridView.count})" else "Empty List" total.text =
if (gridView.count > 0) "Manga and Novels (${gridView.count})" else "Empty List"
gridView.setOnItemClickListener { _, _, position, _ -> gridView.setOnItemClickListener { _, _, position, _ ->
// Get the OfflineMangaModel that was clicked // Get the OfflineMangaModel that was clicked
val item = adapter.getItem(position) as OfflineMangaModel val item = adapter.getItem(position) as OfflineMangaModel
@ -172,10 +180,19 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
downloadManager.mangaDownloadedTypes.firstOrNull { it.title == item.title } downloadManager.mangaDownloadedTypes.firstOrNull { it.title == item.title }
?: downloadManager.novelDownloadedTypes.firstOrNull { it.title == item.title } ?: downloadManager.novelDownloadedTypes.firstOrNull { it.title == item.title }
media?.let { media?.let {
startActivity( ContextCompat.startActivity(
requireActivity(),
Intent(requireContext(), MediaDetailsActivity::class.java) Intent(requireContext(), MediaDetailsActivity::class.java)
.putExtra("media", getMedia(it)) .putExtra("media", getMedia(it))
.putExtra("download", true) .putExtra("download", true),
ActivityOptionsCompat.makeSceneTransitionAnimation(
requireActivity(),
Pair.create(
gridView.getChildAt(position)
.findViewById<ImageView>(R.id.itemCompactImage),
ViewCompat.getTransitionName(requireActivity().findViewById(R.id.itemCompactImage))
)
).toBundle()
) )
} ?: run { } ?: run {
snackString("no media found") snackString("no media found")
@ -200,7 +217,8 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
downloadManager.removeMedia(item.title, type) downloadManager.removeMedia(item.title, type)
getDownloads() getDownloads()
adapter.setItems(downloads) adapter.setItems(downloads)
total.text = if (gridView.count > 0) "Manga and Novels (${gridView.count})" else "Empty List" total.text =
if (gridView.count > 0) "Manga and Novels (${gridView.count})" else "Empty List"
} }
builder.setNegativeButton("No") { _, _ -> builder.setNegativeButton("No") { _, _ ->
// Do nothing // Do nothing

View file

@ -392,7 +392,8 @@ class MediaAdaptor(
Intent(activity, MediaDetailsActivity::class.java).putExtra( Intent(activity, MediaDetailsActivity::class.java).putExtra(
"media", "media",
media as Serializable media as Serializable
), if (itemCompactImage != null) { ),
if (itemCompactImage != null) {
ActivityOptionsCompat.makeSceneTransitionAnimation( ActivityOptionsCompat.makeSceneTransitionAnimation(
activity, activity,
Pair.create( Pair.create(