diff --git a/.github/workflows/beta.yml b/.github/workflows/beta.yml index 56617b4513..292fd0afc1 100644 --- a/.github/workflows/beta.yml +++ b/.github/workflows/beta.yml @@ -4,6 +4,7 @@ on: push: branches: - dev + -Dunno paths-ignore: - '**/README.md' diff --git a/app/src/main/java/ani/dantotsu/MainActivity.kt b/app/src/main/java/ani/dantotsu/MainActivity.kt index 3b8c4bbaeb..1fb435ac3a 100644 --- a/app/src/main/java/ani/dantotsu/MainActivity.kt +++ b/app/src/main/java/ani/dantotsu/MainActivity.kt @@ -11,14 +11,12 @@ import android.os.Bundle import android.os.Handler import android.os.Looper import android.provider.Settings -import android.util.Log import android.view.View import android.view.ViewGroup import android.view.animation.AnticipateInterpolator import android.widget.TextView import androidx.activity.addCallback import androidx.activity.viewModels -import androidx.annotation.OptIn import androidx.appcompat.app.AppCompatActivity import androidx.core.animation.doOnEnd import androidx.core.content.ContextCompat @@ -28,14 +26,11 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope -import androidx.media3.common.util.UnstableApi -import androidx.media3.exoplayer.offline.Download import androidx.viewpager2.adapter.FragmentStateAdapter import ani.dantotsu.connections.anilist.Anilist import ani.dantotsu.connections.anilist.AnilistHomeViewModel import ani.dantotsu.databinding.ActivityMainBinding import ani.dantotsu.databinding.SplashScreenBinding -import ani.dantotsu.download.video.Helper import ani.dantotsu.home.AnimeFragment import ani.dantotsu.home.HomeFragment import ani.dantotsu.home.LoginFragment @@ -50,7 +45,6 @@ import ani.dantotsu.themes.ThemeManager import io.noties.markwon.Markwon import io.noties.markwon.SoftBreakAddsNewLinePlugin import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -66,7 +60,7 @@ class MainActivity : AppCompatActivity() { private var uiSettings = UserInterfaceSettings() - @OptIn(UnstableApi::class) override fun onCreate(savedInstanceState: Bundle?) { + override fun onCreate(savedInstanceState: Bundle?) { ThemeManager(this).applyTheme() LangSet.setLocale(this) super.onCreate(savedInstanceState) @@ -79,10 +73,16 @@ class MainActivity : AppCompatActivity() { val backgroundDrawable = _bottomBar.background as GradientDrawable val currentColor = backgroundDrawable.color?.defaultColor ?: 0 - val semiTransparentColor = (currentColor and 0x00FFFFFF) or 0xF0000000.toInt() + val semiTransparentColor = (currentColor and 0x00FFFFFF) or 0xE8000000.toInt() backgroundDrawable.setColor(semiTransparentColor) _bottomBar.background = backgroundDrawable } + val colorOverflow = this.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) + .getBoolean("colorOverflow", false) + if (!colorOverflow) { + _bottomBar.background = ContextCompat.getDrawable(this, R.drawable.bottom_nav_gray) + + } var doubleBackToExitPressedOnce = false @@ -149,41 +149,48 @@ class MainActivity : AppCompatActivity() { } if (!isOnline(this)) { - snackString(this@MainActivity.getString(R.string.no_internet_connection)) - startActivity(Intent(this, NoInternet::class.java)) - } else { - val model: AnilistHomeViewModel by viewModels() - model.genres.observe(this) { - 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 + snackString(this@MainActivity.getString(R.string.no_internet_connection)) + startActivity(Intent(this, NoInternet::class.java)) + getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) + .edit() + .putBoolean("offlineMode", true) + .apply()} else { + getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) + .edit() + .putBoolean("offlineMode", false) + .apply() + val model: AnilistHomeViewModel by viewModels() + model.genres.observe(this) { it -> + 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) { @@ -242,25 +249,6 @@ class MainActivity : AppCompatActivity() { } } - GlobalScope.launch(Dispatchers.IO) { - val index = Helper.downloadManager(this@MainActivity).downloadIndex - val downloadCursor = index.getDownloads() - while (downloadCursor.moveToNext()) { - val download = downloadCursor.download - Log.e("Downloader", download.request.uri.toString()) - Log.e("Downloader", download.request.id.toString()) - Log.e("Downloader", download.request.mimeType.toString()) - Log.e("Downloader", download.request.data.size.toString()) - Log.e("Downloader", download.bytesDownloaded.toString()) - Log.e("Downloader", download.state.toString()) - Log.e("Downloader", download.failureReason.toString()) - - if (download.state == Download.STATE_FAILED) { //simple cleanup - Helper.downloadManager(this@MainActivity).removeDownload(download.request.id) - } - } - } - } diff --git a/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt b/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt index aa51b08d38..ae30b6f0cb 100644 --- a/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt +++ b/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt @@ -95,6 +95,21 @@ class SettingsDialogFragment() : BottomSheetDialogFragment() { "incognito", false ) + + currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) + ?.getBoolean("offlineMode", false) ?: false + + binding.settingsDownloads.isChecked = + context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.getBoolean( + "offlineMode", + false + ) ?: false + + var offlineMode = context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) + ?.getBoolean( + "offlineMode", + false + ) binding.settingsExtensionSettings.setSafeOnClickListener { startActivity(Intent(activity, ExtensionsActivity::class.java)) @@ -112,38 +127,31 @@ 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)) - } - } - - PageType.HOME -> { - val intent = Intent(activity, DownloadContainerActivity::class.java) - intent.putExtra("FRAGMENT_CLASS_NAME", OfflineMangaFragment::class.java.name) - startActivity(intent) - } + binding.settingsDownloads.setOnCheckedChangeListener { _, isChecked -> + if (!isChecked) { + startMainActivity(requireActivity()) + } else { + when (pageType) { + PageType.MANGA -> { + val intent = Intent(activity, DownloadContainerActivity::class.java) + intent.putExtra("FRAGMENT_CLASS_NAME", OfflineMangaFragment::class.java.name) + startActivity(intent) } - - dismiss() + PageType.ANIME -> { + val intent = Intent(activity, DownloadContainerActivity::class.java) + intent.putExtra("FRAGMENT_CLASS_NAME", OfflineMangaFragment::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) + } + } + } + context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit() + ?.putBoolean("offlineMode", isChecked)?.apply() + dismiss() } } diff --git a/app/src/main/res/layout/bottom_sheet_settings.xml b/app/src/main/res/layout/bottom_sheet_settings.xml index 566ed5aac5..c0ddb79bc3 100644 --- a/app/src/main/res/layout/bottom_sheet_settings.xml +++ b/app/src/main/res/layout/bottom_sheet_settings.xml @@ -88,14 +88,13 @@ android:text="@string/incognito_mode" android:textAlignment="viewStart" android:textColor="?attr/colorOnBackground" - android:layout_marginStart="4dp" app:cornerRadius="0dp" app:drawableTint="?attr/colorPrimary" app:showText="false" app:thumbTint="@color/button_switch_track" /> -