From 79742f415bec098776b7b6c40fee7dd355aa6518 Mon Sep 17 00:00:00 2001 From: aayush262 Date: Sun, 30 Jun 2024 22:29:30 +0530 Subject: [PATCH] feat: something --- .../dantotsu/connections/anilist/Anilist.kt | 1 + .../java/ani/dantotsu/home/AnimeFragment.kt | 18 ++++++++++------ .../java/ani/dantotsu/home/MangaFragment.kt | 20 ++++++++++++------ .../notification/NotificationActivity.kt | 4 ++-- .../dantotsu/settings/SubscriptionSource.kt | 21 +++++++++---------- app/src/main/res/layout/fragment_home.xml | 3 +-- app/src/main/res/layout/item_extension.xml | 1 - .../main/res/layout/item_extension_select.xml | 1 - 8 files changed, 40 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/connections/anilist/Anilist.kt b/app/src/main/java/ani/dantotsu/connections/anilist/Anilist.kt index 51f3bc9df0..a712aba381 100644 --- a/app/src/main/java/ani/dantotsu/connections/anilist/Anilist.kt +++ b/app/src/main/java/ani/dantotsu/connections/anilist/Anilist.kt @@ -191,6 +191,7 @@ object Anilist { ) val remaining = json.headers["X-RateLimit-Remaining"]?.toIntOrNull() ?: -1 Logger.log("Remaining requests: $remaining") + println("Remaining requests: $remaining") if (json.code == 429) { val retry = json.headers["Retry-After"]?.toIntOrNull() ?: -1 val passedLimitReset = json.headers["X-RateLimit-Reset"]?.toLongOrNull() ?: 0 diff --git a/app/src/main/java/ani/dantotsu/home/AnimeFragment.kt b/app/src/main/java/ani/dantotsu/home/AnimeFragment.kt index f9a9f596c2..877138856f 100644 --- a/app/src/main/java/ani/dantotsu/home/AnimeFragment.kt +++ b/app/src/main/java/ani/dantotsu/home/AnimeFragment.kt @@ -38,6 +38,7 @@ import ani.dantotsu.snackString import ani.dantotsu.statusBarHeight import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -289,15 +290,20 @@ class AnimeFragment : Fragment() { } } } - model.loaded = true - model.loadTrending(1) - model.loadAll() + } + model.loaded = true + val loadTrending = async(Dispatchers.IO) { model.loadTrending(1) } + val loadAll = async(Dispatchers.IO) { model.loadAll() } + val loadPopular = async(Dispatchers.IO) { model.loadPopular( - "ANIME", sort = Anilist.sortBy[1], onList = PrefManager.getVal( - PrefName.PopularAnimeList - ) + "ANIME", + sort = Anilist.sortBy[1], + onList = PrefManager.getVal(PrefName.PopularAnimeList) ) } + loadTrending.await() + loadAll.await() + loadPopular.await() live.postValue(false) _binding?.animeRefresh?.isRefreshing = false running = false diff --git a/app/src/main/java/ani/dantotsu/home/MangaFragment.kt b/app/src/main/java/ani/dantotsu/home/MangaFragment.kt index c878c58459..0ed19510ec 100644 --- a/app/src/main/java/ani/dantotsu/home/MangaFragment.kt +++ b/app/src/main/java/ani/dantotsu/home/MangaFragment.kt @@ -35,6 +35,7 @@ import ani.dantotsu.snackString import ani.dantotsu.statusBarHeight import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -274,15 +275,22 @@ class MangaFragment : Fragment() { } } } - model.loaded = true - model.loadTrending() - model.loadAll() + } + model.loaded = true + val loadTrending = async(Dispatchers.IO) { model.loadTrending() } + val loadAll = async(Dispatchers.IO) { model.loadAll() } + val loadPopular = async(Dispatchers.IO) { model.loadPopular( - "MANGA", sort = Anilist.sortBy[1], onList = PrefManager.getVal( - PrefName.PopularMangaList - ) + "MANGA", + sort = Anilist.sortBy[1], + onList = PrefManager.getVal(PrefName.PopularAnimeList) ) } + + loadTrending.await() + loadAll.await() + loadPopular.await() + live.postValue(false) _binding?.mangaRefresh?.isRefreshing = false running = false diff --git a/app/src/main/java/ani/dantotsu/profile/notification/NotificationActivity.kt b/app/src/main/java/ani/dantotsu/profile/notification/NotificationActivity.kt index bd5fad0bd6..05412474b6 100644 --- a/app/src/main/java/ani/dantotsu/profile/notification/NotificationActivity.kt +++ b/app/src/main/java/ani/dantotsu/profile/notification/NotificationActivity.kt @@ -79,8 +79,8 @@ class NotificationActivity : AppCompatActivity() { override fun getItemCount(): Int = if (id != -1) 1 else 4 override fun createFragment(position: Int): Fragment = when (position) { - 0 -> newInstance(USER) - 1 -> newInstance(if (id != -1) ONE else MEDIA, id) + 0 -> newInstance(if (id != -1) ONE else USER, id) + 1 -> newInstance(MEDIA) 2 -> newInstance(SUBSCRIPTION) 3 -> newInstance(COMMENT) else -> newInstance(MEDIA) diff --git a/app/src/main/java/ani/dantotsu/settings/SubscriptionSource.kt b/app/src/main/java/ani/dantotsu/settings/SubscriptionSource.kt index 80975159d9..6740b148d4 100644 --- a/app/src/main/java/ani/dantotsu/settings/SubscriptionSource.kt +++ b/app/src/main/java/ani/dantotsu/settings/SubscriptionSource.kt @@ -8,6 +8,7 @@ import android.view.ViewGroup import ani.dantotsu.R import ani.dantotsu.databinding.ItemExtensionBinding import ani.dantotsu.notifications.subscription.SubscriptionHelper +import ani.dantotsu.util.customAlertDialog import com.xwray.groupie.GroupieAdapter import com.xwray.groupie.viewbinding.BindableItem @@ -26,14 +27,13 @@ class SubscriptionSource( binding.extensionNameTextView.text = parserName updateSubscriptionCount() binding.extensionSubscriptions.visibility = View.VISIBLE - - binding.extensionSubscriptions.setOnClickListener(null) binding.root.setOnClickListener { isExpanded = !isExpanded toggleSubscriptions() } - binding.subscriptionCount.setOnClickListener { + binding.root.setOnLongClickListener { showRemoveAllSubscriptionsDialog(it.context) + true } binding.extensionIconImageView.visibility = View.VISIBLE val layoutParams = binding.extensionIconImageView.layoutParams as ViewGroup.MarginLayoutParams @@ -58,14 +58,13 @@ class SubscriptionSource( } private fun showRemoveAllSubscriptionsDialog(context: Context) { - AlertDialog.Builder(context, R.style.MyPopup) - .setTitle(R.string.remove_all_subscriptions) - .setMessage(context.getString(R.string.remove_all_subscriptions_desc, parserName)) - .setPositiveButton(R.string.apply) { _, _ -> - removeAllSubscriptions() - } - .setNegativeButton(R.string.cancel, null) - .show() + context.customAlertDialog().apply{ + setTitle(R.string.remove_all_subscriptions) + setMessage(R.string.remove_all_subscriptions_desc, parserName) + setPosButton(R.string.ok) { removeAllSubscriptions() } + setNegButton(R.string.cancel) + show() + } } private fun removeAllSubscriptions() { diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 48159e9c9f..d68cd3a9f6 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -314,10 +314,9 @@ android:id="@+id/homeUserStatusContainer" android:layout_width="match_parent" android:layout_height="wrap_content" - android:minHeight="100dp" + android:minHeight="120dp" android:layout_marginVertical="8dp" android:visibility="gone"> - diff --git a/app/src/main/res/layout/item_extension_select.xml b/app/src/main/res/layout/item_extension_select.xml index 98af9cad99..cb2729720d 100644 --- a/app/src/main/res/layout/item_extension_select.xml +++ b/app/src/main/res/layout/item_extension_select.xml @@ -4,7 +4,6 @@ android:id="@+id/extensionCardView" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/colorSurface" android:orientation="horizontal" android:paddingTop="10dp" android:paddingBottom="10dp">