Skip to content

Commit

Permalink
2th attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
Sadwhy committed Jan 6, 2024
1 parent 01fcfd9 commit 089f129
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 101 deletions.
1 change: 1 addition & 0 deletions .github/workflows/beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- dev
-Dunno
paths-ignore:
- '**/README.md'

Expand Down
108 changes: 48 additions & 60 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,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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
}

}


Expand Down
70 changes: 39 additions & 31 deletions app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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<Boolean>("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()
}
}

Expand Down
21 changes: 12 additions & 9 deletions app/src/main/res/layout/bottom_sheet_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<Button
android:id="@+id/image_search"
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/settingsDownloads"
style="@style/Widget.Material3.Button.TextButton"
android:layout_width="match_parent"
android:layout_height="64dp"
Expand All @@ -104,17 +103,21 @@
android:insetBottom="0dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:text="@string/search_by_image"
android:text="@string/offlineMode"
android:textAlignment="viewStart"
android:textAllCaps="false"
android:textColor="?attr/colorOnBackground"
app:cornerRadius="0dp"
app:icon="@drawable/ic_round_image_search_24"
app:icon="@drawable/ic_round_download_24"
app:iconPadding="16dp"
app:iconSize="24dp" />
app:iconSize="24dp"
app:drawableTint="?attr/colorPrimary"
app:showText="false"
app:thumbTint="@color/button_switch_track"
android:checked="false"/>

<Button
android:id="@+id/settingsDownloads"
android:id="@+id/image_search"
style="@style/Widget.Material3.Button.TextButton"
android:layout_width="match_parent"
android:layout_height="64dp"
Expand All @@ -123,12 +126,12 @@
android:insetBottom="0dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:text="@string/downloads"
android:text="@string/search_by_image"
android:textAlignment="viewStart"
android:textAllCaps="false"
android:textColor="?attr/colorOnBackground"
app:cornerRadius="0dp"
app:icon="@drawable/ic_round_download_24"
app:icon="@drawable/ic_round_image_search_24"
app:iconPadding="16dp"
app:iconSize="24dp" />

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@

<string name="anilist_settings">Anilist Settings</string>
<string name="extension_settings">Extensions</string>
<string name="downloads">Downloads</string>
<string name="offlineMode">Offline Mode</string>
<string name="settings">Settings</string>
<string name="extensions">Extensions</string>
<string name="player_settings">Player Settings</string>
Expand Down

0 comments on commit 089f129

Please sign in to comment.