Skip to content

Commit

Permalink
chore: cleanup pt 3
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush2622 committed Apr 30, 2024
1 parent 390ce9a commit fdb7f45
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 93 deletions.
11 changes: 9 additions & 2 deletions app/src/main/java/ani/dantotsu/home/status/Stories.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import android.view.animation.LinearInterpolator
import android.widget.ProgressBar
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.core.app.ActivityOptionsCompat
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.fragment.app.FragmentActivity
import ani.dantotsu.R
import ani.dantotsu.blurImage
Expand Down Expand Up @@ -363,7 +365,6 @@ constructor(
.putExtra("userId", story.userId),
null)
}

fun visible(isList: Boolean){
val visible = if (isList) View.VISIBLE else View.GONE
val gone = if (isList) View.GONE else View.VISIBLE
Expand Down Expand Up @@ -400,7 +401,13 @@ constructor(
binding.coverImage.setOnClickListener{
ContextCompat.startActivity(context, Intent(context, MediaDetailsActivity::class.java)
.putExtra("mediaId", story.media?.id),
null)
ActivityOptionsCompat.makeSceneTransitionAnimation(
activity,
binding.coverImage,
ViewCompat.getTransitionName(binding.coverImage)!!
).toBundle()
)

}

}
Expand Down
44 changes: 22 additions & 22 deletions app/src/main/java/ani/dantotsu/media/manga/MangaChapterAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ani.dantotsu.databinding.ItemEpisodeCompactBinding
import ani.dantotsu.media.Media
import ani.dantotsu.media.MediaNameAdapter
import ani.dantotsu.setAnimation
import ani.dantotsu.util.customAlertDialog
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.text.SimpleDateFormat
Expand Down Expand Up @@ -209,16 +210,15 @@ class MangaChapterAdapter(
fragment.onMangaChapterStopDownloadClick(chapterNumber)
return@setOnClickListener
} else if (downloadedChapters.contains(chapterNumber)) {
val builder = AlertDialog.Builder(currContext(), R.style.MyPopup)
builder.setTitle("Delete Chapter")
builder.setMessage("Are you sure you want to delete ${chapterNumber}?")
builder.setPositiveButton("Yes") { _, _ ->
fragment.onMangaChapterRemoveDownloadClick(chapterNumber)
it.context.customAlertDialog().apply {
setTitle("Delete Chapter")
setMessage("Are you sure you want to delete ${chapterNumber}?")
setPosButton(R.string.delete) {
fragment.onMangaChapterRemoveDownloadClick(chapterNumber)
}
setNegButton(R.string.cancel)
show()
}
builder.setNegativeButton("No") { _, _ ->
}
val dialog = builder.show()
dialog.window?.setDimAmount(0.8f)
return@setOnClickListener
} else {
fragment.onMangaChapterDownloadClick(chapterNumber)
Expand All @@ -228,20 +228,20 @@ class MangaChapterAdapter(
}
binding.itemDownload.setOnLongClickListener {
//Alert dialog asking for the number of chapters to download
val alertDialog = AlertDialog.Builder(currContext(), R.style.MyPopup)
alertDialog.setTitle("Multi Chapter Downloader")
alertDialog.setMessage("Enter the number of chapters to download")
val input = NumberPicker(currContext())
input.minValue = 1
input.maxValue = itemCount - bindingAdapterPosition
input.value = 1
alertDialog.setView(input)
alertDialog.setPositiveButton("OK") { _, _ ->
downloadNChaptersFrom(bindingAdapterPosition, input.value)
it.context.customAlertDialog().apply {
setTitle("Multi Chapter Downloader")
setMessage("Enter the number of chapters to download")
val input = NumberPicker(currContext())
input.minValue = 1
input.maxValue = itemCount - bindingAdapterPosition
input.value = 1
setCustomView(input)
setPosButton("OK") {
downloadNChaptersFrom(bindingAdapterPosition, input.value)
}
setNegButton("Cancel")
show()
}
alertDialog.setNegativeButton("Cancel") { dialog, _ -> dialog.cancel() }
val dialog = alertDialog.show()
dialog.window?.setDimAmount(0.8f)
true
}

Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/ani/dantotsu/offline/OfflineFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.fragment.app.Fragment
import ani.dantotsu.R
Expand All @@ -30,10 +31,15 @@ class OfflineFragment : Fragment() {
offline = PrefManager.getVal(PrefName.OfflineMode)
binding.noInternet.text =
if (offline) "Offline Mode" else getString(R.string.no_internet)
binding.refreshButton.visibility = if (offline) View.GONE else View.VISIBLE
binding.refreshButton.text = if (offline) "Go Online" else getString(R.string.refresh)
binding.refreshButton.setOnClickListener {
if (isOnline(requireContext())) {
if (offline && isOnline(requireContext())) {
PrefManager.setVal(PrefName.OfflineMode, false)
startMainActivity(requireActivity())
} else {
if (isOnline(requireContext()) ) {
startMainActivity(requireActivity())
}
}
}
return binding.root
Expand Down
25 changes: 11 additions & 14 deletions app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.app.AlertDialog
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -17,6 +16,8 @@ import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.databinding.BottomSheetSettingsBinding
import ani.dantotsu.download.anime.OfflineAnimeFragment
import ani.dantotsu.download.manga.OfflineMangaFragment
import ani.dantotsu.getAppString
import ani.dantotsu.getThemeColor
import ani.dantotsu.home.AnimeFragment
import ani.dantotsu.home.HomeFragment
import ani.dantotsu.home.LoginFragment
Expand All @@ -32,6 +33,7 @@ import ani.dantotsu.setSafeOnClickListener
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.startMainActivity
import ani.dantotsu.util.customAlertDialog
import eu.kanade.tachiyomi.util.system.getSerializableCompat
import java.util.Timer
import kotlin.concurrent.schedule
Expand Down Expand Up @@ -59,10 +61,7 @@ class SettingsDialogFragment : BottomSheetDialogFragment() {
super.onViewCreated(view, savedInstanceState)
val window = dialog?.window
window?.statusBarColor = Color.CYAN
val typedValue = TypedValue()
val theme = requireContext().theme
theme.resolveAttribute(com.google.android.material.R.attr.colorSurface, typedValue, true)
window?.navigationBarColor = typedValue.data
window?.navigationBarColor = requireContext().getThemeColor(com.google.android.material.R.attr.colorSurface)
val notificationIcon = if (Anilist.unreadNotificationCount > 0) {
R.drawable.ic_round_notifications_active_24
} else {
Expand All @@ -73,18 +72,16 @@ class SettingsDialogFragment : BottomSheetDialogFragment() {
if (Anilist.token != null) {
binding.settingsLogin.setText(R.string.logout)
binding.settingsLogin.setOnClickListener {
val alertDialog = AlertDialog.Builder(requireContext(), R.style.MyPopup)
.setTitle("Logout")
.setMessage("Are you sure you want to logout?")
.setPositiveButton("Yes") { _, _ ->
requireContext().customAlertDialog().apply{
setTitle(R.string.logout)
setMessage(R.string.logout_confirm)
setPosButton(R.string.yes) {
Anilist.removeSavedToken()
dismiss()
startMainActivity(requireActivity())
}
.setNegativeButton("No") { _, _ -> }
.create()
alertDialog.window?.setDimAmount(0.8f)
alertDialog.show()
setNegButton(R.string.no)
show()
}
}
binding.settingsUsername.text = Anilist.username
binding.settingsUserAvatar.loadImage(Anilist.avatar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.util.customAlertDialog
import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager
import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager
Expand Down Expand Up @@ -169,27 +170,27 @@ class SettingsExtensionsActivity : AppCompatActivity() {
val editText = dialogView.userAgentTextBox.apply {
hint = getString(R.string.anime_add_repository)
}
val alertDialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.anime_add_repository).setView(dialogView.root)
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
context.customAlertDialog().apply {
setTitle(R.string.anime_add_repository)
setCustomView(dialogView.root)
setPosButton(getString(R.string.ok)) {
if (!editText.text.isNullOrBlank()) processUserInput(
editText.text.toString(),
MediaType.ANIME,
it.attachView
)
dialog.dismiss()
}.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}.create()

processEditorAction(
alertDialog,
editText,
MediaType.ANIME,
it.attachView
)
alertDialog.show()
alertDialog.window?.setDimAmount(0.8f)
}
setNegButton(getString(R.string.cancel))
attach { dialog ->
processEditorAction(
dialog,
editText,
MediaType.ANIME,
it.attachView
)
}
show()
}
},
attach = {
setExtensionOutput(it.attachView, MediaType.ANIME)
Expand Down
47 changes: 17 additions & 30 deletions app/src/main/java/ani/dantotsu/settings/SettingsMangaActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.util.customAlertDialog
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get

Expand Down Expand Up @@ -80,23 +81,16 @@ class SettingsMangaActivity : AppCompatActivity() {
desc = getString(R.string.purge_manga_downloads_desc),
icon = R.drawable.ic_round_delete_24,
onClick = {
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.purge_manga_downloads)
.setMessage(
getString(
R.string.purge_confirm,
getString(R.string.manga)
)
)
.setPositiveButton(R.string.yes) { dialog, _ ->
context.customAlertDialog().apply {
setTitle(R.string.purge_manga_downloads)
setMessage(R.string.purge_confirm, getString(R.string.manga))
setPosButton(R.string.yes, onClick = {
val downloadsManager = Injekt.get<DownloadsManager>()
downloadsManager.purgeDownloads(MediaType.MANGA)
dialog.dismiss()
}.setNegativeButton(R.string.no) { dialog, _ ->
dialog.dismiss()
}.create()
dialog.window?.setDimAmount(0.8f)
dialog.show()
})
setNegButton(R.string.no)
show()
}
}

),
Expand All @@ -106,23 +100,16 @@ class SettingsMangaActivity : AppCompatActivity() {
desc = getString(R.string.purge_novel_downloads_desc),
icon = R.drawable.ic_round_delete_24,
onClick = {
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.purge_novel_downloads)
.setMessage(
getString(
R.string.purge_confirm,
getString(R.string.novels)
)
)
.setPositiveButton(R.string.yes) { dialog, _ ->
context.customAlertDialog().apply {
setTitle(R.string.purge_novel_downloads)
setMessage(R.string.purge_confirm, getString(R.string.novels))
setPosButton(R.string.yes) {
val downloadsManager = Injekt.get<DownloadsManager>()
downloadsManager.purgeDownloads(MediaType.NOVEL)
dialog.dismiss()
}.setNegativeButton(R.string.no) { dialog, _ ->
dialog.dismiss()
}.create()
dialog.window?.setDimAmount(0.8f)
dialog.show()
}
setNegButton(R.string.no)
show()
}
}
),
Settings(
Expand Down
Loading

0 comments on commit fdb7f45

Please sign in to comment.