chore: cleanup pt 3
This commit is contained in:
parent
390ce9a022
commit
fdb7f45a3d
10 changed files with 257 additions and 93 deletions
|
@ -14,7 +14,9 @@ import android.view.animation.LinearInterpolator
|
||||||
import android.widget.ProgressBar
|
import android.widget.ProgressBar
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import androidx.constraintlayout.widget.ConstraintSet
|
import androidx.constraintlayout.widget.ConstraintSet
|
||||||
|
import androidx.core.app.ActivityOptionsCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import ani.dantotsu.R
|
import ani.dantotsu.R
|
||||||
import ani.dantotsu.blurImage
|
import ani.dantotsu.blurImage
|
||||||
|
@ -363,7 +365,6 @@ constructor(
|
||||||
.putExtra("userId", story.userId),
|
.putExtra("userId", story.userId),
|
||||||
null)
|
null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun visible(isList: Boolean){
|
fun visible(isList: Boolean){
|
||||||
val visible = if (isList) View.VISIBLE else View.GONE
|
val visible = if (isList) View.VISIBLE else View.GONE
|
||||||
val gone = if (isList) View.GONE else View.VISIBLE
|
val gone = if (isList) View.GONE else View.VISIBLE
|
||||||
|
@ -400,7 +401,13 @@ constructor(
|
||||||
binding.coverImage.setOnClickListener{
|
binding.coverImage.setOnClickListener{
|
||||||
ContextCompat.startActivity(context, Intent(context, MediaDetailsActivity::class.java)
|
ContextCompat.startActivity(context, Intent(context, MediaDetailsActivity::class.java)
|
||||||
.putExtra("mediaId", story.media?.id),
|
.putExtra("mediaId", story.media?.id),
|
||||||
null)
|
ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||||
|
activity,
|
||||||
|
binding.coverImage,
|
||||||
|
ViewCompat.getTransitionName(binding.coverImage)!!
|
||||||
|
).toBundle()
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import ani.dantotsu.databinding.ItemEpisodeCompactBinding
|
||||||
import ani.dantotsu.media.Media
|
import ani.dantotsu.media.Media
|
||||||
import ani.dantotsu.media.MediaNameAdapter
|
import ani.dantotsu.media.MediaNameAdapter
|
||||||
import ani.dantotsu.setAnimation
|
import ani.dantotsu.setAnimation
|
||||||
|
import ani.dantotsu.util.customAlertDialog
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
|
@ -209,16 +210,15 @@ class MangaChapterAdapter(
|
||||||
fragment.onMangaChapterStopDownloadClick(chapterNumber)
|
fragment.onMangaChapterStopDownloadClick(chapterNumber)
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
} else if (downloadedChapters.contains(chapterNumber)) {
|
} else if (downloadedChapters.contains(chapterNumber)) {
|
||||||
val builder = AlertDialog.Builder(currContext(), R.style.MyPopup)
|
it.context.customAlertDialog().apply {
|
||||||
builder.setTitle("Delete Chapter")
|
setTitle("Delete Chapter")
|
||||||
builder.setMessage("Are you sure you want to delete ${chapterNumber}?")
|
setMessage("Are you sure you want to delete ${chapterNumber}?")
|
||||||
builder.setPositiveButton("Yes") { _, _ ->
|
setPosButton(R.string.delete) {
|
||||||
fragment.onMangaChapterRemoveDownloadClick(chapterNumber)
|
fragment.onMangaChapterRemoveDownloadClick(chapterNumber)
|
||||||
|
}
|
||||||
|
setNegButton(R.string.cancel)
|
||||||
|
show()
|
||||||
}
|
}
|
||||||
builder.setNegativeButton("No") { _, _ ->
|
|
||||||
}
|
|
||||||
val dialog = builder.show()
|
|
||||||
dialog.window?.setDimAmount(0.8f)
|
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
} else {
|
} else {
|
||||||
fragment.onMangaChapterDownloadClick(chapterNumber)
|
fragment.onMangaChapterDownloadClick(chapterNumber)
|
||||||
|
@ -228,20 +228,20 @@ class MangaChapterAdapter(
|
||||||
}
|
}
|
||||||
binding.itemDownload.setOnLongClickListener {
|
binding.itemDownload.setOnLongClickListener {
|
||||||
//Alert dialog asking for the number of chapters to download
|
//Alert dialog asking for the number of chapters to download
|
||||||
val alertDialog = AlertDialog.Builder(currContext(), R.style.MyPopup)
|
it.context.customAlertDialog().apply {
|
||||||
alertDialog.setTitle("Multi Chapter Downloader")
|
setTitle("Multi Chapter Downloader")
|
||||||
alertDialog.setMessage("Enter the number of chapters to download")
|
setMessage("Enter the number of chapters to download")
|
||||||
val input = NumberPicker(currContext())
|
val input = NumberPicker(currContext())
|
||||||
input.minValue = 1
|
input.minValue = 1
|
||||||
input.maxValue = itemCount - bindingAdapterPosition
|
input.maxValue = itemCount - bindingAdapterPosition
|
||||||
input.value = 1
|
input.value = 1
|
||||||
alertDialog.setView(input)
|
setCustomView(input)
|
||||||
alertDialog.setPositiveButton("OK") { _, _ ->
|
setPosButton("OK") {
|
||||||
downloadNChaptersFrom(bindingAdapterPosition, input.value)
|
downloadNChaptersFrom(bindingAdapterPosition, input.value)
|
||||||
|
}
|
||||||
|
setNegButton("Cancel")
|
||||||
|
show()
|
||||||
}
|
}
|
||||||
alertDialog.setNegativeButton("Cancel") { dialog, _ -> dialog.cancel() }
|
|
||||||
val dialog = alertDialog.show()
|
|
||||||
dialog.window?.setDimAmount(0.8f)
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import ani.dantotsu.R
|
import ani.dantotsu.R
|
||||||
|
@ -30,10 +31,15 @@ class OfflineFragment : Fragment() {
|
||||||
offline = PrefManager.getVal(PrefName.OfflineMode)
|
offline = PrefManager.getVal(PrefName.OfflineMode)
|
||||||
binding.noInternet.text =
|
binding.noInternet.text =
|
||||||
if (offline) "Offline Mode" else getString(R.string.no_internet)
|
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 {
|
binding.refreshButton.setOnClickListener {
|
||||||
if (isOnline(requireContext())) {
|
if (offline && isOnline(requireContext())) {
|
||||||
|
PrefManager.setVal(PrefName.OfflineMode, false)
|
||||||
startMainActivity(requireActivity())
|
startMainActivity(requireActivity())
|
||||||
|
} else {
|
||||||
|
if (isOnline(requireContext()) ) {
|
||||||
|
startMainActivity(requireActivity())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return binding.root
|
return binding.root
|
||||||
|
|
|
@ -4,7 +4,6 @@ import android.app.AlertDialog
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.TypedValue
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -17,6 +16,8 @@ import ani.dantotsu.connections.anilist.Anilist
|
||||||
import ani.dantotsu.databinding.BottomSheetSettingsBinding
|
import ani.dantotsu.databinding.BottomSheetSettingsBinding
|
||||||
import ani.dantotsu.download.anime.OfflineAnimeFragment
|
import ani.dantotsu.download.anime.OfflineAnimeFragment
|
||||||
import ani.dantotsu.download.manga.OfflineMangaFragment
|
import ani.dantotsu.download.manga.OfflineMangaFragment
|
||||||
|
import ani.dantotsu.getAppString
|
||||||
|
import ani.dantotsu.getThemeColor
|
||||||
import ani.dantotsu.home.AnimeFragment
|
import ani.dantotsu.home.AnimeFragment
|
||||||
import ani.dantotsu.home.HomeFragment
|
import ani.dantotsu.home.HomeFragment
|
||||||
import ani.dantotsu.home.LoginFragment
|
import ani.dantotsu.home.LoginFragment
|
||||||
|
@ -32,6 +33,7 @@ import ani.dantotsu.setSafeOnClickListener
|
||||||
import ani.dantotsu.settings.saving.PrefManager
|
import ani.dantotsu.settings.saving.PrefManager
|
||||||
import ani.dantotsu.settings.saving.PrefName
|
import ani.dantotsu.settings.saving.PrefName
|
||||||
import ani.dantotsu.startMainActivity
|
import ani.dantotsu.startMainActivity
|
||||||
|
import ani.dantotsu.util.customAlertDialog
|
||||||
import eu.kanade.tachiyomi.util.system.getSerializableCompat
|
import eu.kanade.tachiyomi.util.system.getSerializableCompat
|
||||||
import java.util.Timer
|
import java.util.Timer
|
||||||
import kotlin.concurrent.schedule
|
import kotlin.concurrent.schedule
|
||||||
|
@ -59,10 +61,7 @@ class SettingsDialogFragment : BottomSheetDialogFragment() {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
val window = dialog?.window
|
val window = dialog?.window
|
||||||
window?.statusBarColor = Color.CYAN
|
window?.statusBarColor = Color.CYAN
|
||||||
val typedValue = TypedValue()
|
window?.navigationBarColor = requireContext().getThemeColor(com.google.android.material.R.attr.colorSurface)
|
||||||
val theme = requireContext().theme
|
|
||||||
theme.resolveAttribute(com.google.android.material.R.attr.colorSurface, typedValue, true)
|
|
||||||
window?.navigationBarColor = typedValue.data
|
|
||||||
val notificationIcon = if (Anilist.unreadNotificationCount > 0) {
|
val notificationIcon = if (Anilist.unreadNotificationCount > 0) {
|
||||||
R.drawable.ic_round_notifications_active_24
|
R.drawable.ic_round_notifications_active_24
|
||||||
} else {
|
} else {
|
||||||
|
@ -73,18 +72,16 @@ class SettingsDialogFragment : BottomSheetDialogFragment() {
|
||||||
if (Anilist.token != null) {
|
if (Anilist.token != null) {
|
||||||
binding.settingsLogin.setText(R.string.logout)
|
binding.settingsLogin.setText(R.string.logout)
|
||||||
binding.settingsLogin.setOnClickListener {
|
binding.settingsLogin.setOnClickListener {
|
||||||
val alertDialog = AlertDialog.Builder(requireContext(), R.style.MyPopup)
|
requireContext().customAlertDialog().apply{
|
||||||
.setTitle("Logout")
|
setTitle(R.string.logout)
|
||||||
.setMessage("Are you sure you want to logout?")
|
setMessage(R.string.logout_confirm)
|
||||||
.setPositiveButton("Yes") { _, _ ->
|
setPosButton(R.string.yes) {
|
||||||
Anilist.removeSavedToken()
|
Anilist.removeSavedToken()
|
||||||
dismiss()
|
|
||||||
startMainActivity(requireActivity())
|
startMainActivity(requireActivity())
|
||||||
}
|
}
|
||||||
.setNegativeButton("No") { _, _ -> }
|
setNegButton(R.string.no)
|
||||||
.create()
|
show()
|
||||||
alertDialog.window?.setDimAmount(0.8f)
|
}
|
||||||
alertDialog.show()
|
|
||||||
}
|
}
|
||||||
binding.settingsUsername.text = Anilist.username
|
binding.settingsUsername.text = Anilist.username
|
||||||
binding.settingsUserAvatar.loadImage(Anilist.avatar)
|
binding.settingsUserAvatar.loadImage(Anilist.avatar)
|
||||||
|
|
|
@ -24,6 +24,7 @@ import ani.dantotsu.settings.saving.PrefManager
|
||||||
import ani.dantotsu.settings.saving.PrefName
|
import ani.dantotsu.settings.saving.PrefName
|
||||||
import ani.dantotsu.statusBarHeight
|
import ani.dantotsu.statusBarHeight
|
||||||
import ani.dantotsu.themes.ThemeManager
|
import ani.dantotsu.themes.ThemeManager
|
||||||
|
import ani.dantotsu.util.customAlertDialog
|
||||||
import eu.kanade.domain.base.BasePreferences
|
import eu.kanade.domain.base.BasePreferences
|
||||||
import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager
|
import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager
|
||||||
import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager
|
import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager
|
||||||
|
@ -169,27 +170,27 @@ class SettingsExtensionsActivity : AppCompatActivity() {
|
||||||
val editText = dialogView.userAgentTextBox.apply {
|
val editText = dialogView.userAgentTextBox.apply {
|
||||||
hint = getString(R.string.anime_add_repository)
|
hint = getString(R.string.anime_add_repository)
|
||||||
}
|
}
|
||||||
val alertDialog = AlertDialog.Builder(context, R.style.MyPopup)
|
context.customAlertDialog().apply {
|
||||||
.setTitle(R.string.anime_add_repository).setView(dialogView.root)
|
setTitle(R.string.anime_add_repository)
|
||||||
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
|
setCustomView(dialogView.root)
|
||||||
|
setPosButton(getString(R.string.ok)) {
|
||||||
if (!editText.text.isNullOrBlank()) processUserInput(
|
if (!editText.text.isNullOrBlank()) processUserInput(
|
||||||
editText.text.toString(),
|
editText.text.toString(),
|
||||||
MediaType.ANIME,
|
MediaType.ANIME,
|
||||||
it.attachView
|
it.attachView
|
||||||
)
|
)
|
||||||
dialog.dismiss()
|
}
|
||||||
}.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
|
setNegButton(getString(R.string.cancel))
|
||||||
dialog.dismiss()
|
attach { dialog ->
|
||||||
}.create()
|
processEditorAction(
|
||||||
|
dialog,
|
||||||
processEditorAction(
|
editText,
|
||||||
alertDialog,
|
MediaType.ANIME,
|
||||||
editText,
|
it.attachView
|
||||||
MediaType.ANIME,
|
)
|
||||||
it.attachView
|
}
|
||||||
)
|
show()
|
||||||
alertDialog.show()
|
}
|
||||||
alertDialog.window?.setDimAmount(0.8f)
|
|
||||||
},
|
},
|
||||||
attach = {
|
attach = {
|
||||||
setExtensionOutput(it.attachView, MediaType.ANIME)
|
setExtensionOutput(it.attachView, MediaType.ANIME)
|
||||||
|
|
|
@ -19,6 +19,7 @@ import ani.dantotsu.settings.saving.PrefManager
|
||||||
import ani.dantotsu.settings.saving.PrefName
|
import ani.dantotsu.settings.saving.PrefName
|
||||||
import ani.dantotsu.statusBarHeight
|
import ani.dantotsu.statusBarHeight
|
||||||
import ani.dantotsu.themes.ThemeManager
|
import ani.dantotsu.themes.ThemeManager
|
||||||
|
import ani.dantotsu.util.customAlertDialog
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
|
||||||
|
@ -80,23 +81,16 @@ class SettingsMangaActivity : AppCompatActivity() {
|
||||||
desc = getString(R.string.purge_manga_downloads_desc),
|
desc = getString(R.string.purge_manga_downloads_desc),
|
||||||
icon = R.drawable.ic_round_delete_24,
|
icon = R.drawable.ic_round_delete_24,
|
||||||
onClick = {
|
onClick = {
|
||||||
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
|
context.customAlertDialog().apply {
|
||||||
.setTitle(R.string.purge_manga_downloads)
|
setTitle(R.string.purge_manga_downloads)
|
||||||
.setMessage(
|
setMessage(R.string.purge_confirm, getString(R.string.manga))
|
||||||
getString(
|
setPosButton(R.string.yes, onClick = {
|
||||||
R.string.purge_confirm,
|
|
||||||
getString(R.string.manga)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setPositiveButton(R.string.yes) { dialog, _ ->
|
|
||||||
val downloadsManager = Injekt.get<DownloadsManager>()
|
val downloadsManager = Injekt.get<DownloadsManager>()
|
||||||
downloadsManager.purgeDownloads(MediaType.MANGA)
|
downloadsManager.purgeDownloads(MediaType.MANGA)
|
||||||
dialog.dismiss()
|
})
|
||||||
}.setNegativeButton(R.string.no) { dialog, _ ->
|
setNegButton(R.string.no)
|
||||||
dialog.dismiss()
|
show()
|
||||||
}.create()
|
}
|
||||||
dialog.window?.setDimAmount(0.8f)
|
|
||||||
dialog.show()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
),
|
),
|
||||||
|
@ -106,23 +100,16 @@ class SettingsMangaActivity : AppCompatActivity() {
|
||||||
desc = getString(R.string.purge_novel_downloads_desc),
|
desc = getString(R.string.purge_novel_downloads_desc),
|
||||||
icon = R.drawable.ic_round_delete_24,
|
icon = R.drawable.ic_round_delete_24,
|
||||||
onClick = {
|
onClick = {
|
||||||
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
|
context.customAlertDialog().apply {
|
||||||
.setTitle(R.string.purge_novel_downloads)
|
setTitle(R.string.purge_novel_downloads)
|
||||||
.setMessage(
|
setMessage(R.string.purge_confirm, getString(R.string.novels))
|
||||||
getString(
|
setPosButton(R.string.yes) {
|
||||||
R.string.purge_confirm,
|
|
||||||
getString(R.string.novels)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setPositiveButton(R.string.yes) { dialog, _ ->
|
|
||||||
val downloadsManager = Injekt.get<DownloadsManager>()
|
val downloadsManager = Injekt.get<DownloadsManager>()
|
||||||
downloadsManager.purgeDownloads(MediaType.NOVEL)
|
downloadsManager.purgeDownloads(MediaType.NOVEL)
|
||||||
dialog.dismiss()
|
}
|
||||||
}.setNegativeButton(R.string.no) { dialog, _ ->
|
setNegButton(R.string.no)
|
||||||
dialog.dismiss()
|
show()
|
||||||
}.create()
|
}
|
||||||
dialog.window?.setDimAmount(0.8f)
|
|
||||||
dialog.show()
|
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
Settings(
|
Settings(
|
||||||
|
|
170
app/src/main/java/ani/dantotsu/util/AlertDialogBuilder.kt
Normal file
170
app/src/main/java/ani/dantotsu/util/AlertDialogBuilder.kt
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
package ani.dantotsu.util
|
||||||
|
|
||||||
|
import android.app.AlertDialog
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.View
|
||||||
|
import ani.dantotsu.R
|
||||||
|
|
||||||
|
class AlertDialogBuilder(private val context: Context) {
|
||||||
|
private var title: String? = null
|
||||||
|
private var message: String? = null
|
||||||
|
private var posButtonTitle: String? = null
|
||||||
|
private var negButtonTitle: String? = null
|
||||||
|
private var neutralButtonTitle: String? = null
|
||||||
|
private var onPositiveButtonClick: (() -> Unit)? = null
|
||||||
|
private var onNegativeButtonClick: (() -> Unit)? = null
|
||||||
|
private var onNeutralButtonClick: (() -> Unit)? = null
|
||||||
|
private var items: Array<String>? = null
|
||||||
|
private var checkedItems: BooleanArray? = null
|
||||||
|
private var onItemsSelected: ((BooleanArray) -> Unit)? = null
|
||||||
|
private var selectedItemIndex: Int = -1
|
||||||
|
private var onItemSelected: ((Int) -> Unit)? = null
|
||||||
|
private var customView: View? = null
|
||||||
|
private var attach: ((dialog: AlertDialog) -> Unit)? = null
|
||||||
|
fun setTitle(title: String?): AlertDialogBuilder {
|
||||||
|
this.title = title
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setTitle(int: Int, formatArgs: Int? = null): AlertDialogBuilder {
|
||||||
|
this.title = context.getString(int, formatArgs)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setMessage(message: String?): AlertDialogBuilder {
|
||||||
|
this.message = message
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setMessage(stringInt: Int, vararg formatArgs: Any): AlertDialogBuilder {
|
||||||
|
this.message = context.getString(stringInt, *formatArgs)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setCustomView(view: View): AlertDialogBuilder {
|
||||||
|
this.customView = view
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setPosButton(title: String?, onClick: (() -> Unit)? = null): AlertDialogBuilder {
|
||||||
|
this.posButtonTitle = title
|
||||||
|
this.onPositiveButtonClick = onClick
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setPosButton(
|
||||||
|
int: Int,
|
||||||
|
formatArgs: Int? = null,
|
||||||
|
onClick: (() -> Unit)? = null
|
||||||
|
): AlertDialogBuilder {
|
||||||
|
this.posButtonTitle = context.getString(int, formatArgs)
|
||||||
|
this.onPositiveButtonClick = onClick
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setNegButton(title: String?, onClick: (() -> Unit)? = null): AlertDialogBuilder {
|
||||||
|
this.negButtonTitle = title
|
||||||
|
this.onNegativeButtonClick = onClick
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setNegButton(
|
||||||
|
int: Int,
|
||||||
|
formatArgs: Int? = null,
|
||||||
|
onClick: (() -> Unit)? = null
|
||||||
|
): AlertDialogBuilder {
|
||||||
|
this.negButtonTitle = context.getString(int, formatArgs)
|
||||||
|
this.onNegativeButtonClick = onClick
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setNeutralButton(title: String?, onClick: (() -> Unit)? = null): AlertDialogBuilder {
|
||||||
|
this.negButtonTitle = title
|
||||||
|
this.onNegativeButtonClick = onClick
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setNeutralButton(
|
||||||
|
int: Int,
|
||||||
|
formatArgs: Int? = null,
|
||||||
|
onClick: (() -> Unit)? = null
|
||||||
|
): AlertDialogBuilder {
|
||||||
|
this.negButtonTitle = context.getString(int, formatArgs)
|
||||||
|
this.onNegativeButtonClick = onClick
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun attach(attach: ((dialog: AlertDialog) -> Unit)?): AlertDialogBuilder {
|
||||||
|
this.attach = attach
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun singleChoiceItems(
|
||||||
|
items: Array<String>,
|
||||||
|
selectedItemIndex: Int = -1,
|
||||||
|
onItemSelected: (Int) -> Unit
|
||||||
|
): AlertDialogBuilder {
|
||||||
|
this.items = items
|
||||||
|
this.selectedItemIndex = selectedItemIndex
|
||||||
|
this.onItemSelected = onItemSelected
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun multiChoiceItems(
|
||||||
|
items: Array<String>,
|
||||||
|
checkedItems: BooleanArray? = null,
|
||||||
|
onItemsSelected: (BooleanArray) -> Unit
|
||||||
|
): AlertDialogBuilder {
|
||||||
|
this.items = items
|
||||||
|
this.checkedItems = checkedItems ?: BooleanArray(items.size) { false }
|
||||||
|
this.onItemsSelected = onItemsSelected
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun show() {
|
||||||
|
val builder = AlertDialog.Builder(context, R.style.MyPopup)
|
||||||
|
if (title != null) builder.setTitle(title)
|
||||||
|
if (message != null) builder.setMessage(message)
|
||||||
|
if (customView != null) builder.setView(customView)
|
||||||
|
if (items != null) {
|
||||||
|
if (onItemSelected != null) {
|
||||||
|
builder.setSingleChoiceItems(items, selectedItemIndex) { _, which ->
|
||||||
|
selectedItemIndex = which
|
||||||
|
onItemSelected?.invoke(which)
|
||||||
|
}
|
||||||
|
} else if (checkedItems != null && onItemsSelected != null) {
|
||||||
|
builder.setMultiChoiceItems(items, checkedItems) { _, which, isChecked ->
|
||||||
|
checkedItems?.set(which, isChecked)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (posButtonTitle != null) {
|
||||||
|
builder.setPositiveButton(posButtonTitle) { dialog, _ ->
|
||||||
|
onPositiveButtonClick?.invoke()
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (negButtonTitle != null) {
|
||||||
|
builder.setNegativeButton(negButtonTitle) { dialog, _ ->
|
||||||
|
onNegativeButtonClick?.invoke()
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (neutralButtonTitle != null) {
|
||||||
|
builder.setNeutralButton(neutralButtonTitle) { dialog, _ ->
|
||||||
|
onNeutralButtonClick?.invoke()
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builder.setCancelable(false)
|
||||||
|
val dialog = builder.create()
|
||||||
|
attach?.invoke(dialog)
|
||||||
|
dialog.window?.setDimAmount(0.8f)
|
||||||
|
dialog.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Context.customAlertDialog(): AlertDialogBuilder {
|
||||||
|
return AlertDialogBuilder(this)
|
||||||
|
}
|
|
@ -64,7 +64,7 @@
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/refreshButton"
|
android:id="@+id/refreshButton"
|
||||||
android:layout_width="150dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="64dp"
|
android:layout_height="64dp"
|
||||||
android:layout_gravity="bottom|center_horizontal"
|
android:layout_gravity="bottom|center_horizontal"
|
||||||
android:layout_margin="128dp"
|
android:layout_margin="128dp"
|
||||||
|
|
|
@ -115,7 +115,7 @@
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="8dp"
|
android:layout_marginVertical="8dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:minHeight="92dp"
|
android:minHeight="92dp"
|
||||||
|
@ -147,9 +147,8 @@
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/itemDownload"
|
android:id="@+id/itemDownload"
|
||||||
android:layout_width="24dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:layout_marginEnd="5dp"
|
|
||||||
android:background="@android:color/transparent"
|
android:background="@android:color/transparent"
|
||||||
app:srcCompat="@drawable/ic_download_24"
|
app:srcCompat="@drawable/ic_download_24"
|
||||||
app:tint="?attr/colorOnBackground"
|
app:tint="?attr/colorOnBackground"
|
||||||
|
|
|
@ -11,9 +11,6 @@
|
||||||
<item name="windowNoTitle">true</item>
|
<item name="windowNoTitle">true</item>
|
||||||
<item name="android:windowContentTransitions">true</item>
|
<item name="android:windowContentTransitions">true</item>
|
||||||
<item name="android:fontFamily">@font/poppins</item>
|
<item name="android:fontFamily">@font/poppins</item>
|
||||||
<item name="android:dialogTheme">@style/MyPopup</item>
|
|
||||||
<item name="android:alertDialogTheme">@style/MyPopup</item>
|
|
||||||
<item name="android:alertDialogStyle">@style/MyPopup</item>
|
|
||||||
<item name="shapeAppearanceLargeComponent">@style/ShapeAppearanceOverlay.Demo</item>
|
<item name="shapeAppearanceLargeComponent">@style/ShapeAppearanceOverlay.Demo</item>
|
||||||
<item name="android:ambientShadowAlpha">0.08</item>
|
<item name="android:ambientShadowAlpha">0.08</item>
|
||||||
<item name="android:spotShadowAlpha">0.08</item>
|
<item name="android:spotShadowAlpha">0.08</item>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue