Skip to content

Commit

Permalink
fix: separate update,delete buttons | TOS, privpol
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Dec 31, 2024
1 parent 43dee6e commit 116de63
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 117 deletions.
9 changes: 6 additions & 3 deletions app/src/main/java/ani/dantotsu/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import ani.dantotsu.others.calc.CalcActivity
import ani.dantotsu.profile.ProfileActivity
import ani.dantotsu.profile.activity.FeedActivity
import ani.dantotsu.profile.notification.NotificationActivity
import ani.dantotsu.settings.AddRepositoryBottomSheet
import ani.dantotsu.settings.ExtensionsActivity
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefManager.asLiveBool
Expand Down Expand Up @@ -457,9 +458,11 @@ class MainActivity : AppCompatActivity() {
}
val savedRepos: Set<String> = PrefManager.getVal(prefName)
val newRepos = savedRepos.toMutableSet()
newRepos.add(url)
PrefManager.setVal(prefName, newRepos)
toast("${if (uri.scheme == "tachiyomi") "Manga" else "Anime"} Extension Repo added")
AddRepositoryBottomSheet.addRepoWarning(this) {
newRepos.add(url)
PrefManager.setVal(prefName, newRepos)
toast("${if (uri.scheme == "tachiyomi") "Manga" else "Anime"} Extension Repo added")
}
return
}
if (intent.type == null) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

suspend fun getUserId(context: Context, block: () -> Unit) {
if (!Anilist.initialized) {
if (!Anilist.initialized && PrefManager.getVal<String>(PrefName.AnilistToken) != "") {
if (Anilist.query.getUserData()) {
tryWithSuspend {
if (MAL.token != null && !MAL.query.getUserData())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class NovelExtensionManager(private val context: Context) {
*
* @param pkgName The package name of the application to uninstall.
*/
fun uninstallExtension(pkgName: String, context: Context) {
fun uninstallExtension(pkgName: String) {
installer.uninstallApk(pkgName)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ani.dantotsu.settings

import android.content.Context
import android.os.Bundle
import android.view.KeyEvent
import android.view.LayoutInflater
Expand All @@ -12,6 +13,7 @@ import ani.dantotsu.R
import ani.dantotsu.databinding.BottomSheetAddRepositoryBinding
import ani.dantotsu.databinding.ItemRepoBinding
import ani.dantotsu.media.MediaType
import ani.dantotsu.util.customAlertDialog
import com.xwray.groupie.GroupieAdapter
import com.xwray.groupie.viewbinding.BindableItem

Expand Down Expand Up @@ -72,8 +74,12 @@ class AddRepositoryBottomSheet : BottomSheetDialogFragment() {
val input = binding.repositoryInput.text.toString()
val error = isValidUrl(input)
if (error == null) {
onRepositoryAdded?.invoke(input, mediaType)
dismiss()
context?.let { context ->
addRepoWarning(context) {
onRepositoryAdded?.invoke(input, mediaType)
dismiss()
}
}
} else {
binding.repositoryInput.error = error
}
Expand All @@ -86,11 +92,16 @@ class AddRepositoryBottomSheet : BottomSheetDialogFragment() {
binding.repositoryInput.setOnEditorActionListener { textView, action, keyEvent ->
if (action == EditorInfo.IME_ACTION_DONE ||
(keyEvent?.action == KeyEvent.ACTION_UP && keyEvent.keyCode == KeyEvent.KEYCODE_ENTER)) {
if (!textView.text.isNullOrBlank()) {
val error = isValidUrl(textView.text.toString())
val url = textView.text.toString()
if (url.isNotBlank()) {
val error = isValidUrl(url)
if (error == null) {
onRepositoryAdded?.invoke(textView.text.toString(), mediaType)
dismiss()
context?.let { context ->
addRepoWarning(context) {
onRepositoryAdded?.invoke(url, mediaType)
dismiss()
}
}
return@setOnEditorActionListener true
} else {
binding.repositoryInput.error = error
Expand Down Expand Up @@ -121,6 +132,16 @@ class AddRepositoryBottomSheet : BottomSheetDialogFragment() {
}

companion object {
fun addRepoWarning(context: Context, onRepositoryAdded: () -> Unit) {
context.customAlertDialog()
.setTitle(R.string.warning)
.setMessage(R.string.add_repository_warning)
.setPosButton(R.string.ok) {
onRepositoryAdded.invoke()
}
.setNegButton(R.string.cancel) { }
.show()
}
fun newInstance(
mediaType: MediaType,
repositories: List<String>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ani.dantotsu.settings

import android.app.AlertDialog
import android.app.NotificationManager
import android.content.Context
import android.os.Bundle
Expand Down Expand Up @@ -44,13 +43,10 @@ import kotlinx.coroutines.launch
import rx.android.schedulers.AndroidSchedulers
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.util.Collections
import java.util.Locale


class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {


private var _binding: FragmentExtensionsBinding? = null
private val binding get() = _binding!!
private lateinit var extensionsRecyclerView: RecyclerView
Expand Down Expand Up @@ -122,15 +118,20 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {
.show()
}
},
{ pkg, forceDelete ->
if (isAdded) { // Check if the fragment is currently added to its activity
val context = requireContext() // Store context in a variable
{ pkg ->
if (isAdded) {
animeExtensionManager.uninstallExtension(pkg.pkgName)
snackString("Extension uninstalled")
}
}, { pkg ->
if (isAdded) {
val context = requireContext()
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager // Initialize NotificationManager once
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

if (pkg.hasUpdate && !forceDelete) {
if (pkg.hasUpdate) {
animeExtensionManager.updateExtension(pkg)
.observeOn(AndroidSchedulers.mainThread()) // Observe on main thread
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ installStep ->
val builder = NotificationCompat.Builder(
Expand All @@ -145,7 +146,7 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {
},
{ error ->
Injekt.get<CrashlyticsInterface>().logException(error)
Logger.log(error) // Log the error
Logger.log(error)
val builder = NotificationCompat.Builder(
context,
Notifications.CHANNEL_DOWNLOADER_ERROR
Expand All @@ -171,14 +172,13 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {
}
)
} else {
animeExtensionManager.uninstallExtension(pkg.pkgName)
snackString("Extension uninstalled")
snackString("No update available")
}

}
}, skipIcons
)


override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -198,17 +198,10 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {
viewHolder: RecyclerView.ViewHolder,
target: RecyclerView.ViewHolder
): Boolean {
val newList = extensionsAdapter.currentList.toMutableList()
val fromPosition = viewHolder.absoluteAdapterPosition
val toPosition = target.absoluteAdapterPosition
if (fromPosition < toPosition) { //probably need to switch to a recyclerview adapter
for (i in fromPosition until toPosition) {
Collections.swap(newList, i, i + 1)
}
} else {
for (i in fromPosition downTo toPosition + 1) {
Collections.swap(newList, i, i - 1)
}
val newList = extensionsAdapter.currentList.toMutableList().apply {
add(toPosition, removeAt(fromPosition))
}
extensionsAdapter.submitList(newList)
return true
Expand Down Expand Up @@ -270,7 +263,8 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {

private class AnimeExtensionsAdapter(
private val onSettingsClicked: (AnimeExtension.Installed) -> Unit,
private val onUninstallClicked: (AnimeExtension.Installed, Boolean) -> Unit,
private val onUninstallClicked: (AnimeExtension.Installed) -> Unit,
private val onUpdateClicked: (AnimeExtension.Installed) -> Unit,
val skipIcons: Boolean
) : ListAdapter<AnimeExtension.Installed, AnimeExtensionsAdapter.ViewHolder>(
DIFF_CALLBACK_INSTALLED
Expand Down Expand Up @@ -304,20 +298,19 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {
holder.extensionIconImageView.setImageDrawable(extension.icon)
}
if (extension.hasUpdate) {
holder.closeTextView.setImageResource(R.drawable.ic_round_sync_24)
holder.updateView.isVisible = true
} else {
holder.closeTextView.setImageResource(R.drawable.ic_round_delete_24)
holder.updateView.isVisible = false
}
holder.closeTextView.setOnClickListener {
onUninstallClicked(extension, false)
holder.deleteView.setOnClickListener {
onUninstallClicked(extension)
}
holder.updateView.setOnClickListener {
onUpdateClicked(extension)
}
holder.settingsImageView.setOnClickListener {
onSettingsClicked(extension)
}
holder.closeTextView.setOnLongClickListener {
onUninstallClicked(extension, true)
true
}
}

fun filter(query: String, currentList: List<AnimeExtension.Installed>) {
Expand All @@ -337,7 +330,8 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {
view.findViewById(R.id.extensionVersionTextView)
val settingsImageView: ImageView = view.findViewById(R.id.settingsImageView)
val extensionIconImageView: ImageView = view.findViewById(R.id.extensionIconImageView)
val closeTextView: ImageView = view.findViewById(R.id.closeTextView)
val deleteView: ImageView = view.findViewById(R.id.deleteTextView)
val updateView: ImageView = view.findViewById(R.id.updateTextView)
}

companion object {
Expand Down
Loading

0 comments on commit 116de63

Please # to comment.