From 65c2b9d71525b5a08da09b3351d16cd49925c076 Mon Sep 17 00:00:00 2001 From: jakepurple13 Date: Thu, 8 Apr 2021 13:01:54 -0400 Subject: [PATCH] - changed the ItemListAdapter.kt to have checkadapterinterface for anime showing favorites and possible adding it to press and hold in manga --- .../com/programmersbox/uiviews/AllFragment.kt | 19 ++++++++++++++++++- .../programmersbox/uiviews/ItemListAdapter.kt | 15 +++++++++++---- .../programmersbox/uiviews/RecentFragment.kt | 17 +++++++++++++++++ .../programmersbox/animeworld/AnimeAdapter.kt | 9 +-------- .../src/main/res/layout/anime_list_item.xml | 1 + .../com/programmersbox/mangaworld/MangaApp.kt | 2 +- .../mangaworld/MangaGalleryAdapter.kt | 5 +++++ 7 files changed, 54 insertions(+), 14 deletions(-) diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/AllFragment.kt b/UIViews/src/main/java/com/programmersbox/uiviews/AllFragment.kt index 8c5bd4ed6..e0fdffe12 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/AllFragment.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/AllFragment.kt @@ -12,13 +12,17 @@ import com.google.android.material.textfield.TextInputLayout import com.jakewharton.rxbinding2.widget.textChanges import com.programmersbox.dragswipe.DragSwipeAdapter import com.programmersbox.dragswipe.DragSwipeDiffUtil +import com.programmersbox.favoritesdatabase.DbModel +import com.programmersbox.favoritesdatabase.ItemDatabase import com.programmersbox.helpfulutils.runOnUIThread import com.programmersbox.models.ApiService import com.programmersbox.models.ItemModel import com.programmersbox.models.sourcePublish import com.programmersbox.uiviews.utils.EndlessScrollingListener +import com.programmersbox.uiviews.utils.FirebaseDb import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable +import io.reactivex.rxkotlin.Flowables import io.reactivex.rxkotlin.addTo import io.reactivex.rxkotlin.subscribeBy import io.reactivex.schedulers.Schedulers @@ -32,7 +36,7 @@ import java.util.concurrent.TimeUnit * Use the [AllFragment.newInstance] factory method to * create an instance of this fragment. */ -class AllFragment() : BaseListFragment() { +class AllFragment : BaseListFragment() { private val disposable: CompositeDisposable = CompositeDisposable() private var count = 1 @@ -41,12 +45,24 @@ class AllFragment() : BaseListFragment() { private val currentList = mutableListOf() + private val dao by lazy { ItemDatabase.getInstance(requireContext()).itemDao() } + private val itemListener = FirebaseDb.FirebaseListener() + override fun viewCreated(view: View, savedInstanceState: Bundle?) { super.viewCreated(view, savedInstanceState) val rv = view.findViewById(R.id.allList) val refresh = view.findViewById(R.id.allRefresh) + Flowables.combineLatest( + itemListener.getAllShowsFlowable(), + dao.getAllFavorites() + ) { f, d -> (f + d).groupBy(DbModel::url).map { it.value.maxByOrNull(DbModel::numChapters)!! } } + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { adapter.update(it) { s, d -> s.url == d.url } } + .addTo(disposable) + rv?.apply { adapter = this@AllFragment.adapter layoutManager = createLayoutManager(this@AllFragment.requireContext()) @@ -125,6 +141,7 @@ class AllFragment() : BaseListFragment() { override fun onDestroy() { super.onDestroy() disposable.dispose() + itemListener.unregister() } companion object { diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/ItemListAdapter.kt b/UIViews/src/main/java/com/programmersbox/uiviews/ItemListAdapter.kt index a6341ffb6..732f822b8 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/ItemListAdapter.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/ItemListAdapter.kt @@ -4,16 +4,23 @@ import android.content.Context import android.view.View import androidx.navigation.findNavController import androidx.recyclerview.widget.RecyclerView +import com.programmersbox.dragswipe.CheckAdapter +import com.programmersbox.dragswipe.CheckAdapterInterface import com.programmersbox.dragswipe.DragSwipeAdapter -import com.programmersbox.loggingutils.Loged +import com.programmersbox.favoritesdatabase.DbModel import com.programmersbox.models.ItemModel abstract class ItemListAdapter( protected val context: Context, - private val baseListFragment: BaseListFragment -) : DragSwipeAdapter() { + private val baseListFragment: BaseListFragment, + check: CheckAdapter = CheckAdapter() +) : DragSwipeAdapter(), CheckAdapterInterface by check { + init { + check.adapter = this + } + protected fun onClick(v: View, itemModel: ItemModel) { - val direction = if(baseListFragment is RecentFragment) RecentFragmentDirections.actionRecentFragment2ToDetailsFragment2(itemModel) + val direction = if (baseListFragment is RecentFragment) RecentFragmentDirections.actionRecentFragment2ToDetailsFragment2(itemModel) else AllFragmentDirections.actionAllFragment2ToDetailsFragment3(itemModel) v.findNavController().navigate(direction) } diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/RecentFragment.kt b/UIViews/src/main/java/com/programmersbox/uiviews/RecentFragment.kt index 7ae2ca0c6..42f8a6039 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/RecentFragment.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/RecentFragment.kt @@ -5,11 +5,15 @@ import android.view.View import androidx.fragment.app.Fragment import androidx.recyclerview.widget.RecyclerView import androidx.swiperefreshlayout.widget.SwipeRefreshLayout +import com.programmersbox.favoritesdatabase.DbModel +import com.programmersbox.favoritesdatabase.ItemDatabase import com.programmersbox.models.ApiService import com.programmersbox.models.sourcePublish import com.programmersbox.uiviews.utils.EndlessScrollingListener +import com.programmersbox.uiviews.utils.FirebaseDb import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable +import io.reactivex.rxkotlin.Flowables import io.reactivex.rxkotlin.addTo import io.reactivex.rxkotlin.subscribeBy import io.reactivex.schedulers.Schedulers @@ -27,12 +31,24 @@ class RecentFragment : BaseListFragment() { private var count = 1 + private val dao by lazy { ItemDatabase.getInstance(requireContext()).itemDao() } + private val itemListener = FirebaseDb.FirebaseListener() + override fun viewCreated(view: View, savedInstanceState: Bundle?) { super.viewCreated(view, savedInstanceState) val rv = view.findViewById(R.id.recentList) val refresh = view.findViewById(R.id.recentRefresh) + Flowables.combineLatest( + itemListener.getAllShowsFlowable(), + dao.getAllFavorites() + ) { f, d -> (f + d).groupBy(DbModel::url).map { it.value.maxByOrNull(DbModel::numChapters)!! } } + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { adapter.update(it) { s, d -> s.url == d.url } } + .addTo(disposable) + rv?.apply { adapter = this@RecentFragment.adapter layoutManager = createLayoutManager(this@RecentFragment.requireContext()) @@ -76,6 +92,7 @@ class RecentFragment : BaseListFragment() { override fun onDestroy() { super.onDestroy() disposable.dispose() + itemListener.unregister() } companion object { diff --git a/animeworld/src/main/java/com/programmersbox/animeworld/AnimeAdapter.kt b/animeworld/src/main/java/com/programmersbox/animeworld/AnimeAdapter.kt index 8902253d9..f665ff3e8 100644 --- a/animeworld/src/main/java/com/programmersbox/animeworld/AnimeAdapter.kt +++ b/animeworld/src/main/java/com/programmersbox/animeworld/AnimeAdapter.kt @@ -4,8 +4,6 @@ import android.content.Context import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.programmersbox.animeworld.databinding.AnimeListItemBinding -import com.programmersbox.dragswipe.CheckAdapter -import com.programmersbox.dragswipe.CheckAdapterInterface import com.programmersbox.favoritesdatabase.DbModel import com.programmersbox.helpfulutils.layoutInflater import com.programmersbox.models.ItemModel @@ -17,12 +15,7 @@ import com.programmersbox.uiviews.ItemListAdapter class AnimeAdapter( context: Context, baseListFragment: BaseListFragment, - check: CheckAdapter = CheckAdapter() -) : ItemListAdapter(context, baseListFragment), CheckAdapterInterface by check { - - init { - check.adapter = this - } +) : ItemListAdapter(context, baseListFragment) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AnimeHolder = AnimeHolder(AnimeListItemBinding.inflate(context.layoutInflater, parent, false)) diff --git a/animeworld/src/main/res/layout/anime_list_item.xml b/animeworld/src/main/res/layout/anime_list_item.xml index eb72f65c4..855405a87 100644 --- a/animeworld/src/main/res/layout/anime_list_item.xml +++ b/animeworld/src/main/res/layout/anime_list_item.xml @@ -34,6 +34,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" + android:layout_gravity="center_vertical" android:gravity="center_vertical" android:minLines="2" android:text="@{show.title}" diff --git a/mangaworld/src/main/java/com/programmersbox/mangaworld/MangaApp.kt b/mangaworld/src/main/java/com/programmersbox/mangaworld/MangaApp.kt index 9a4201381..ef53166c5 100644 --- a/mangaworld/src/main/java/com/programmersbox/mangaworld/MangaApp.kt +++ b/mangaworld/src/main/java/com/programmersbox/mangaworld/MangaApp.kt @@ -10,7 +10,7 @@ class MangaApp : OtakuApp() { override fun onCreated() { logo = R.mipmap.ic_launcher - notificationLogo = R.drawable.manga_world_round_logo//R.mipmap.ic_launcher_foreground + notificationLogo = R.drawable.manga_world_round_logo MangaContext.context = this diff --git a/mangaworld/src/main/java/com/programmersbox/mangaworld/MangaGalleryAdapter.kt b/mangaworld/src/main/java/com/programmersbox/mangaworld/MangaGalleryAdapter.kt index 9dc05d4d2..f9c9aecab 100644 --- a/mangaworld/src/main/java/com/programmersbox/mangaworld/MangaGalleryAdapter.kt +++ b/mangaworld/src/main/java/com/programmersbox/mangaworld/MangaGalleryAdapter.kt @@ -6,6 +6,7 @@ import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide import com.bumptech.glide.load.resource.bitmap.RoundedCorners +import com.programmersbox.favoritesdatabase.DbModel import com.programmersbox.helpfulutils.layoutInflater import com.programmersbox.mangaworld.databinding.MangaGalleryItemBinding import com.programmersbox.models.ItemModel @@ -42,6 +43,10 @@ class MangaGalleryAdapter(context: Context, baseListFragment: BaseListFragment) } } + override val currentList: MutableList get() = mutableListOf() + override val previousList: MutableList get() = mutableListOf() + override fun update(list: List, check: (ItemModel, DbModel) -> Boolean) {} + } class GalleryHolder(private val binding: MangaGalleryItemBinding) : RecyclerView.ViewHolder(binding.root) {