Skip to content

Commit

Permalink
Incognito and download switch (#121)
Browse files Browse the repository at this point in the history
* Offline Mode and incognito Switch

* fix

* Fix 1

* Update MainActivity.kt

* Update MainActivity.kt

---------

Co-authored-by: rebel onion <[email protected]>
  • Loading branch information
Sadwhy and rebelonion authored Jan 13, 2024
1 parent 46b84ff commit 84e3004
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 170 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".download.DownloadContainerActivity" />
<activity
android:name="eu.kanade.tachiyomi.extension.manga.util.MangaExtensionInstallActivity"
android:exported="false"
Expand Down
99 changes: 53 additions & 46 deletions app/src/main/java/ani/dantotsu/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,14 +26,12 @@ 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.App.Companion.context
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
Expand All @@ -50,7 +46,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
Expand All @@ -66,7 +61,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)
Expand All @@ -79,10 +74,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
Expand Down Expand Up @@ -147,43 +148,49 @@ class MainActivity : AppCompatActivity() {
bottomMargin = navBarHeight
}
}

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) {
Expand Down Expand Up @@ -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
Expand All @@ -262,6 +267,8 @@ class MainActivity : AppCompatActivity() {
}
}



}


Expand All @@ -281,4 +288,4 @@ class MainActivity : AppCompatActivity() {
}
}

}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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?,
Expand All @@ -79,14 +76,8 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {

val animeUserAvatar = view.findViewById<ShapeableImageView>(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)
Expand Down Expand Up @@ -180,6 +171,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
snackString("no media found")
}
}

val total = view.findViewById<TextView>(R.id.total)
total.text = if (gridView.count > 0) "Manga and Novels (${gridView.count})" else "Empty List"
gridView.setOnItemLongClickListener { parent, view, position, id ->
Expand All @@ -198,7 +190,6 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
downloadManager.removeMedia(item.title, type)
getDownloads()
adapter.setItems(downloads)

}
builder.setNegativeButton("No") { _, _ ->
// Do nothing
Expand All @@ -207,6 +198,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
dialog.window?.setDimAmount(0.8f)
true
}

return view
}

Expand Down Expand Up @@ -390,4 +382,4 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {

interface OfflineMangaSearchListener {
fun onSearchQuery(query: String)
}
}
1 change: 1 addition & 0 deletions app/src/main/java/ani/dantotsu/home/AnimePageAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class AnimePageAdapter : RecyclerView.Adapter<AnimePageAdapter.AnimePageViewHold
)
}

setIncognito()
binding.animeSearchBar.setEndIconOnClickListener {
binding.animeSearchBarText.performClick()
}
Expand Down
15 changes: 7 additions & 8 deletions app/src/main/java/ani/dantotsu/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package ani.dantotsu.home

import android.animation.ObjectAnimator
import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.graphics.drawable.Animatable
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.view.animation.LayoutAnimationController
import androidx.core.content.ContextCompat
import androidx.core.view.updateLayoutParams
Expand All @@ -22,7 +20,6 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import ani.dantotsu.App
import ani.dantotsu.R
import ani.dantotsu.Refresh
import ani.dantotsu.bottomBar
Expand Down Expand Up @@ -75,7 +72,7 @@ class HomeFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val scope = lifecycleScope
var uiSettings = loadData<UserInterfaceSettings>("ui_settings") ?: UserInterfaceSettings()

setIncognito()
fun load() {
if (activity != null && _binding != null) lifecycleScope.launch(Dispatchers.Main) {
binding.homeUserName.text = Anilist.username
Expand Down Expand Up @@ -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<UserInterfaceSettings>("ui_settings") ?: UserInterfaceSettings()
binding.incognitoTextView.visibility = View.VISIBLE
Expand All @@ -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()
}
}
1 change: 1 addition & 0 deletions app/src/main/java/ani/dantotsu/home/MangaPageAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class MangaPageAdapter : RecyclerView.Adapter<MangaPageAdapter.MangaPageViewHold
dialogFragment.show((it.context as AppCompatActivity).supportFragmentManager, "dialog")
}

setIncognito()
binding.mangaSearchBar.setEndIconOnClickListener {
binding.mangaSearchBarText.performClick()
}
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/ani/dantotsu/offline/OfflineFragment.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ani.dantotsu.offline

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -8,6 +9,8 @@ import androidx.core.view.updateLayoutParams
import androidx.fragment.app.Fragment
import ani.dantotsu.databinding.FragmentOfflineBinding
import ani.dantotsu.isOnline
import ani.dantotsu.App
import ani.dantotsu.R
import ani.dantotsu.navBarHeight
import ani.dantotsu.startMainActivity
import ani.dantotsu.statusBarHeight
Expand All @@ -23,8 +26,10 @@ class OfflineFragment : Fragment() {
topMargin = statusBarHeight
bottomMargin = navBarHeight
}
val offline = App.context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.getBoolean("offlineMode", false) ?: false
binding.noInternet.text = if (!isOnline(requireContext())) getString(R.string.no_internet) else "OFFLINE MODE"
binding.refreshButton.setOnClickListener {
if (isOnline(requireContext())) {
if (!isOnline(requireContext()) && offline) {
startMainActivity(requireActivity())
}
}
Expand Down
Loading

0 comments on commit 84e3004

Please sign in to comment.