From 84e300482a4a8837079d6c15bac3855420203e13 Mon Sep 17 00:00:00 2001 From: Sadwhy <99601717+Sadwhy@users.noreply.github.com> Date: Sat, 13 Jan 2024 23:13:54 +0600 Subject: [PATCH] Incognito and download switch (#121) * Offline Mode and incognito Switch * fix * Fix 1 * Update MainActivity.kt * Update MainActivity.kt --------- Co-authored-by: rebel onion <87634197+rebelonion@users.noreply.github.com> --- app/src/main/AndroidManifest.xml | 1 - .../main/java/ani/dantotsu/MainActivity.kt | 99 ++++++++-------- .../download/DownloadContainerActivity.kt | 25 ---- .../download/manga/OfflineMangaFragment.kt | 18 +-- .../ani/dantotsu/home/AnimePageAdapter.kt | 1 + .../java/ani/dantotsu/home/HomeFragment.kt | 15 ++- .../ani/dantotsu/home/MangaPageAdapter.kt | 1 + .../ani/dantotsu/offline/OfflineFragment.kt | 7 +- .../ani/dantotsu/settings/SettingsActivity.kt | 10 -- .../settings/SettingsDialogFragment.kt | 110 ++++++++++++------ app/src/main/res/layout/activity_settings.xml | 19 --- .../main/res/layout/bottom_sheet_settings.xml | 44 +++++-- app/src/main/res/layout/fragment_offline.xml | 1 + app/src/main/res/values/strings.xml | 1 + 14 files changed, 182 insertions(+), 170 deletions(-) delete mode 100644 app/src/main/java/ani/dantotsu/download/DownloadContainerActivity.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b97d9e6e67..b72b3304cc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -234,7 +234,6 @@ - + if (it != null) { + if (it) { + val navbar = binding.includedNavbar.navbar + bottomBar = navbar + navbar.visibility = View.VISIBLE + binding.mainProgressBar.visibility = View.GONE + val mainViewPager = binding.viewpager + mainViewPager.isUserInputEnabled = false + mainViewPager.adapter = ViewPagerAdapter(supportFragmentManager, lifecycle) + mainViewPager.setPageTransformer(ZoomOutPageTransformer(uiSettings)) + navbar.setOnTabSelectListener(object : + AnimatedBottomBar.OnTabSelectListener { + override fun onTabSelected( + lastIndex: Int, + lastTab: AnimatedBottomBar.Tab?, + newIndex: Int, + newTab: AnimatedBottomBar.Tab + ) { + navbar.animate().translationZ(12f).setDuration(200).start() + selectedOption = newIndex + mainViewPager.setCurrentItem(newIndex, false) } - } + }) + navbar.selectTabAt(selectedOption) + mainViewPager.post { mainViewPager.setCurrentItem(selectedOption, false) } + } else { + binding.mainProgressBar.visibility = View.GONE + } } + } //Load Data if (!load) { scope.launch(Dispatchers.IO) { @@ -236,15 +243,13 @@ class MainActivity : AppCompatActivity() { .setData(Uri.parse("package:$packageName")) ) } - dismiss() } }.show(supportFragmentManager, "dialog") } } } - GlobalScope.launch(Dispatchers.IO) { - val index = Helper.downloadManager(this@MainActivity).downloadIndex + val index = Helper.downloadManager(this@MainActivity).downloadIndex val downloadCursor = index.getDownloads() while (downloadCursor.moveToNext()) { val download = downloadCursor.download @@ -262,6 +267,8 @@ class MainActivity : AppCompatActivity() { } } + + } @@ -281,4 +288,4 @@ class MainActivity : AppCompatActivity() { } } -} \ No newline at end of file +} diff --git a/app/src/main/java/ani/dantotsu/download/DownloadContainerActivity.kt b/app/src/main/java/ani/dantotsu/download/DownloadContainerActivity.kt deleted file mode 100644 index 21f0a9100c..0000000000 --- a/app/src/main/java/ani/dantotsu/download/DownloadContainerActivity.kt +++ /dev/null @@ -1,25 +0,0 @@ -package ani.dantotsu.download - -import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity -import androidx.fragment.app.Fragment -import ani.dantotsu.R -import ani.dantotsu.others.LangSet -import ani.dantotsu.themes.ThemeManager - -class DownloadContainerActivity : AppCompatActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - LangSet.setLocale(this) - ThemeManager(this).applyTheme() - setContentView(R.layout.activity_container) - - val fragmentClassName = intent.getStringExtra("FRAGMENT_CLASS_NAME") - val fragment = Class.forName(fragmentClassName).newInstance() as Fragment - - supportFragmentManager.beginTransaction() - .replace(R.id.fragment_container, fragment) - .commit() - } -} \ No newline at end of file diff --git a/app/src/main/java/ani/dantotsu/download/manga/OfflineMangaFragment.kt b/app/src/main/java/ani/dantotsu/download/manga/OfflineMangaFragment.kt index ea1812dc22..735a007e02 100644 --- a/app/src/main/java/ani/dantotsu/download/manga/OfflineMangaFragment.kt +++ b/app/src/main/java/ani/dantotsu/download/manga/OfflineMangaFragment.kt @@ -1,7 +1,6 @@ package ani.dantotsu.download.manga import android.animation.ObjectAnimator -import android.annotation.SuppressLint import android.content.Context import android.content.Intent import android.net.Uri @@ -21,7 +20,6 @@ import android.widget.AbsListView import android.widget.AutoCompleteTextView import android.widget.GridView import android.widget.ImageView -import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.cardview.widget.CardView import androidx.fragment.app.Fragment @@ -59,7 +57,6 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener { private lateinit var gridView: GridView private lateinit var adapter: OfflineMangaAdapter - @SuppressLint("SetTextI18n") override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -79,14 +76,8 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener { val animeUserAvatar = view.findViewById(R.id.offlineMangaUserAvatar) animeUserAvatar.setSafeOnClickListener { - animeUserAvatar.setSafeOnClickListener { - val dialogFragment = SettingsDialogFragment.newInstance(SettingsDialogFragment.Companion.PageType.HOME) - dialogFragment.show( - (it.context as AppCompatActivity).supportFragmentManager, - "dialog" - ) - } - + val dialogFragment = SettingsDialogFragment.newInstance2(SettingsDialogFragment.Companion.PageType2.OfflineMANGA) + dialogFragment.show((it.context as AppCompatActivity).supportFragmentManager, "dialog") } val colorOverflow = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) @@ -180,6 +171,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener { snackString("no media found") } } + val total = view.findViewById(R.id.total) total.text = if (gridView.count > 0) "Manga and Novels (${gridView.count})" else "Empty List" gridView.setOnItemLongClickListener { parent, view, position, id -> @@ -198,7 +190,6 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener { downloadManager.removeMedia(item.title, type) getDownloads() adapter.setItems(downloads) - } builder.setNegativeButton("No") { _, _ -> // Do nothing @@ -207,6 +198,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener { dialog.window?.setDimAmount(0.8f) true } + return view } @@ -390,4 +382,4 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener { interface OfflineMangaSearchListener { fun onSearchQuery(query: String) -} \ No newline at end of file +} diff --git a/app/src/main/java/ani/dantotsu/home/AnimePageAdapter.kt b/app/src/main/java/ani/dantotsu/home/AnimePageAdapter.kt index d843b2dcc8..c0dcefe4b4 100644 --- a/app/src/main/java/ani/dantotsu/home/AnimePageAdapter.kt +++ b/app/src/main/java/ani/dantotsu/home/AnimePageAdapter.kt @@ -93,6 +93,7 @@ class AnimePageAdapter : RecyclerView.Adapter("ui_settings") ?: UserInterfaceSettings() - + setIncognito() fun load() { if (activity != null && _binding != null) lifecycleScope.launch(Dispatchers.Main) { binding.homeUserName.text = Anilist.username @@ -361,11 +358,9 @@ class HomeFragment : Fragment() { } } } - - override fun onResume() { - if (!model.loaded) Refresh.activity[1]!!.postValue(true) + private fun setIncognito() { val incognito = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) - ?.getBoolean("incognito", false) ?: false + ?.getBoolean("incognito", false) ?: false if(incognito) { val uiSettings = loadData("ui_settings") ?: UserInterfaceSettings() binding.incognitoTextView.visibility = View.VISIBLE @@ -381,6 +376,10 @@ class HomeFragment : Fragment() { } else { binding.incognitoTextView.visibility = View.GONE } + } + override fun onResume() { + if (!model.loaded) Refresh.activity[1]!!.postValue(true) + setIncognito() super.onResume() } } \ No newline at end of file diff --git a/app/src/main/java/ani/dantotsu/home/MangaPageAdapter.kt b/app/src/main/java/ani/dantotsu/home/MangaPageAdapter.kt index b04ebbd205..f882f8eb96 100644 --- a/app/src/main/java/ani/dantotsu/home/MangaPageAdapter.kt +++ b/app/src/main/java/ani/dantotsu/home/MangaPageAdapter.kt @@ -98,6 +98,7 @@ class MangaPageAdapter : RecyclerView.Adapter - getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() - .putBoolean("incognito", isChecked).apply() - } - var previousStart: View = when (uiSettings.defaultStartUpTab) { 0 -> binding.uiSettingsAnime 1 -> binding.uiSettingsHome diff --git a/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt b/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt index b94490ec98..a52707d153 100644 --- a/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt +++ b/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt @@ -1,40 +1,42 @@ package ani.dantotsu.settings -import android.app.DownloadManager -import android.content.ActivityNotFoundException import android.content.Intent +import android.content.Context import android.graphics.Color -import android.net.Uri import android.os.Bundle import android.util.TypedValue import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.core.content.ContextCompat import ani.dantotsu.BottomSheetDialogFragment import ani.dantotsu.R +import ani.dantotsu.MainActivity import ani.dantotsu.connections.anilist.Anilist import ani.dantotsu.databinding.BottomSheetSettingsBinding -import ani.dantotsu.download.DownloadContainerActivity import ani.dantotsu.download.manga.OfflineMangaFragment -import ani.dantotsu.loadData import ani.dantotsu.loadImage import ani.dantotsu.openLinkInBrowser import ani.dantotsu.others.imagesearch.ImageSearchActivity import ani.dantotsu.setSafeOnClickListener import ani.dantotsu.startMainActivity -import ani.dantotsu.toast +import ani.dantotsu.currContext +import ani.dantotsu.home.AnimeFragment +import ani.dantotsu.home.HomeFragment +import ani.dantotsu.home.LoginFragment +import ani.dantotsu.home.MangaFragment +import ani.dantotsu.home.NoInternet +import ani.dantotsu.offline.OfflineFragment - -class SettingsDialogFragment() : BottomSheetDialogFragment() { +class SettingsDialogFragment() : BottomSheetDialogFragment() { private var _binding: BottomSheetSettingsBinding? = null private val binding get() = _binding!! private lateinit var pageType: PageType - + private lateinit var pageType2: PageType2 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) pageType = arguments?.getSerializable("pageType") as? PageType ?: PageType.HOME + pageType2 = arguments?.getSerializable("pageType2") as? PageType2 ?: PageType2.OfflineMANGA // changed when offline home page comes } override fun onCreateView( inflater: LayoutInflater, @@ -72,6 +74,16 @@ class SettingsDialogFragment() : BottomSheetDialogFragment() { } } + binding.settingsIncognito.isChecked = + context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.getBoolean( + "incognito", + false + ) ?: false + + binding.settingsIncognito.setOnCheckedChangeListener { _, isChecked -> + context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit() + ?.putBoolean("incognito", isChecked)?.apply() + } binding.settingsExtensionSettings.setSafeOnClickListener { startActivity(Intent(activity, ExtensionsActivity::class.java)) dismiss() @@ -88,40 +100,53 @@ class SettingsDialogFragment() : BottomSheetDialogFragment() { startActivity(Intent(activity, ImageSearchActivity::class.java)) dismiss() } - binding.settingsDownloads.setSafeOnClickListener { - when (pageType) { - PageType.MANGA -> { - val intent = Intent(activity, DownloadContainerActivity::class.java) - intent.putExtra("FRAGMENT_CLASS_NAME", OfflineMangaFragment::class.java.name) - startActivity(intent) - } - PageType.ANIME -> { - try { - val arrayOfFiles = - ContextCompat.getExternalFilesDirs(requireContext(), null) - startActivity( - if (loadData("sd_dl") == true && arrayOfFiles.size > 1 && arrayOfFiles[0] != null && arrayOfFiles[1] != null) { - val parentDirectory = arrayOfFiles[1].toString() - val intent = Intent(Intent.ACTION_VIEW) - intent.setDataAndType(Uri.parse(parentDirectory), "resource/folder") - } else Intent(DownloadManager.ACTION_VIEW_DOWNLOADS) - ) - } catch (e: ActivityNotFoundException) { - toast(getString(R.string.file_manager_not_found)) + binding.settingsDownloads.isChecked = + context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.getBoolean("offlineMode", false) ?: false + binding.settingsDownloads.setOnCheckedChangeListener { _, isChecked -> + + if (!isChecked) { + when (pageType2) { + PageType2.OfflineMANGA -> { + val intent = Intent(activity, MainActivity::class.java) + intent.putExtra("FRAGMENT_CLASS_NAME", MangaFragment::class.java.name) + startActivity(intent) + } + PageType2.OfflineHOME -> { //no offline home for now + val intent = Intent(activity, MainActivity::class.java) + intent.putExtra("FRAGMENT_CLASS_NAME", if (Anilist.token != null) HomeFragment::class.java.name else LoginFragment::class.java.name) + startActivity(intent) + } + PageType2.OfflineANIME -> { //no offline anime for now + val intent = Intent(activity, MainActivity::class.java) + intent.putExtra("FRAGMENT_CLASS_NAME", AnimeFragment::class.java.name) + startActivity(intent) } } - - PageType.HOME -> { - val intent = Intent(activity, DownloadContainerActivity::class.java) - intent.putExtra("FRAGMENT_CLASS_NAME", OfflineMangaFragment::class.java.name) - startActivity(intent) + } else { + when (pageType) { + PageType.MANGA -> { + val intent = Intent(activity, NoInternet::class.java) + intent.putExtra("FRAGMENT_CLASS_NAME", OfflineMangaFragment::class.java.name) + startActivity(intent) + } + PageType.ANIME -> { + val intent = Intent(activity, NoInternet::class.java) + intent.putExtra("FRAGMENT_CLASS_NAME", OfflineFragment::class.java.name) + startActivity(intent) + } + PageType.HOME -> { + val intent = Intent(activity, NoInternet::class.java) + intent.putExtra("FRAGMENT_CLASS_NAME", OfflineFragment::class.java.name) + startActivity(intent) + } } } - dismiss() + context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit() + ?.putBoolean("offlineMode", isChecked)?.apply() + } } - } override fun onDestroyView() { super.onDestroyView() @@ -132,7 +157,9 @@ class SettingsDialogFragment() : BottomSheetDialogFragment() { enum class PageType { MANGA, ANIME, HOME } - + enum class PageType2 { + OfflineMANGA, OfflineANIME, OfflineHOME + } fun newInstance(pageType: PageType): SettingsDialogFragment { val fragment = SettingsDialogFragment() val args = Bundle() @@ -140,5 +167,12 @@ class SettingsDialogFragment() : BottomSheetDialogFragment() { fragment.arguments = args return fragment } + fun newInstance2(pageType: PageType2): SettingsDialogFragment { + val fragment = SettingsDialogFragment() + val args = Bundle() + args.putSerializable("pageType", pageType) + fragment.arguments = args + return fragment + } } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index adffeae90a..52c9591597 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -335,25 +335,6 @@ app:drawableEndCompat="@drawable/ic_round_arrow_drop_down_24" tools:ignore="TextContrastCheck" /> - - + + -