stop refresh entire page on grid change / hide scroll to top button

This commit is contained in:
Finnley Somdahl 2023-12-27 06:24:24 -06:00
parent 38c5ae447a
commit d177087ae6
3 changed files with 40 additions and 13 deletions

View file

@ -21,6 +21,7 @@ class OfflineMangaAdapter(
private val inflater: LayoutInflater = private val inflater: LayoutInflater =
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
private var originalItems: List<OfflineMangaModel> = items private var originalItems: List<OfflineMangaModel> = items
private var style = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getInt("offline_view", 0)
override fun getCount(): Int { override fun getCount(): Int {
return items.size return items.size
@ -37,15 +38,10 @@ class OfflineMangaAdapter(
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View { override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
val style = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getInt("offline_view", 0) val view: View = convertView ?: when(style) {
0 -> inflater.inflate(R.layout.item_media_large, parent, false) // large view
var view = convertView 1 -> inflater.inflate(R.layout.item_media_compact, parent, false) // compact view
else -> inflater.inflate(R.layout.item_media_compact, parent, false) // compact view
if (view == null && style == 0 ) {
view = inflater.inflate(R.layout.item_media_large, parent, false) // large view
}
else if (view == null && style == 1){
view = inflater.inflate(R.layout.item_media_compact, parent, false) // compact view
} }
val item = getItem(position) as OfflineMangaModel val item = getItem(position) as OfflineMangaModel
@ -69,7 +65,7 @@ class OfflineMangaAdapter(
else if (style == 1){ else if (style == 1){
val readchapter = view.findViewById<TextView>(R.id.itemCompactUserProgress) // for compact view val readchapter = 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
@ -104,4 +100,9 @@ class OfflineMangaAdapter(
this.originalItems = items this.originalItems = items
notifyDataSetChanged() notifyDataSetChanged()
} }
fun notifyNewGrid(){
style = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getInt("offline_view", 0)
notifyDataSetChanged()
}
} }

View file

@ -15,6 +15,7 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.animation.OvershootInterpolator import android.view.animation.OvershootInterpolator
import android.widget.AbsListView
import android.widget.AutoCompleteTextView import android.widget.AutoCompleteTextView
import android.widget.GridView import android.widget.GridView
import android.widget.ImageView import android.widget.ImageView
@ -128,7 +129,11 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
style = 0 style = 0
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit() context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit()
?.putInt("offline_view", style!!)?.apply() ?.putInt("offline_view", style!!)?.apply()
recreate(requireActivity()) gridView.visibility = View.GONE
gridView = view.findViewById(R.id.gridView)
gridView.adapter = adapter
gridView.visibility = View.VISIBLE
adapter.notifyNewGrid()
} }
@ -137,7 +142,11 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
style = 1 style = 1
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit() context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit()
?.putInt("offline_view", style!!)?.apply() ?.putInt("offline_view", style!!)?.apply()
recreate(requireActivity()) gridView.visibility = View.GONE
gridView = view.findViewById(R.id.gridView1)
gridView.adapter = adapter
gridView.visibility = View.VISIBLE
adapter.notifyNewGrid()
} }
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)
@ -229,9 +238,25 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
} }
scrollTop.setOnClickListener { scrollTop.setOnClickListener {
//TODO: scroll to top gridView.smoothScrollToPosition(0)
} }
// Assuming 'scrollTop' is a view that you want to hide/show
scrollTop.visibility = View.GONE
gridView.setOnScrollListener(object : AbsListView.OnScrollListener {
override fun onScrollStateChanged(view: AbsListView, scrollState: Int) {
// Implement behavior for different scroll states if needed
}
override fun onScroll(view: AbsListView, firstVisibleItem: Int, visibleItemCount: Int, totalItemCount: Int) {
val first = view.getChildAt(0)
val visibility = first != null && first.top < -height
scrollTop.visibility = if (visibility) View.VISIBLE else View.GONE
}
})
} }
override fun onResume() { override fun onResume() {

View file

@ -35,6 +35,7 @@
android:hint="@string/manga" android:hint="@string/manga"
android:textColorHint="@color/bg_opp" android:textColorHint="@color/bg_opp"
android:transitionName="@string/search" android:transitionName="@string/search"
android:fontFamily="@font/poppins_bold"
app:boxBackgroundColor="?attr/colorPrimaryContainer" app:boxBackgroundColor="?attr/colorPrimaryContainer"
app:boxCornerRadiusBottomEnd="28dp" app:boxCornerRadiusBottomEnd="28dp"
app:boxCornerRadiusBottomStart="28dp" app:boxCornerRadiusBottomStart="28dp"