From d1db2d60ec65db7b66855097e84ab57fda9a89d8 Mon Sep 17 00:00:00 2001 From: len Date: Sun, 5 Jun 2016 23:40:27 +0200 Subject: [PATCH] Fix #329. Add confirmation before removing favorite manga on multiple selection. Add new proguard rules --- app/build.gradle | 2 +- app/proguard-rules.pro | 10 ++++++++- .../tachiyomi/data/source/SourceManager.kt | 4 +++- .../data/source/online/english/Mangafox.kt | 1 - .../tachiyomi/ui/download/DownloadFragment.kt | 5 ++--- .../tachiyomi/ui/library/LibraryFragment.kt | 21 ++++++++++++------- .../tachiyomi/ui/library/LibraryPresenter.kt | 2 +- .../tachiyomi/util/ContextExtensions.kt | 10 +++++++++ app/src/main/res/values/strings.xml | 1 + 9 files changed, 41 insertions(+), 15 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1c04ab86a6..94432f6920 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -117,7 +117,7 @@ dependencies { compile 'com.f2prateek.rx.preferences:rx-preferences:1.0.1' // Network client - compile "com.squareup.okhttp3:okhttp:3.3.0" + compile "com.squareup.okhttp3:okhttp:3.3.1" // REST compile "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION" diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 3b5677c1e7..fa7a7b8b51 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -118,4 +118,12 @@ # Keep the support library -keep class org.acra.** { *; } --keep interface org.acra.** { *; } \ No newline at end of file +-keep interface org.acra.** { *; } + +# SnakeYaml +-keep class org.yaml.snakeyaml.** { public protected private *; } +-keep class org.yaml.snakeyaml.** { public protected private *; } +-dontwarn org.yaml.snakeyaml.** + +# Duktape +-keep class com.squareup.duktape.** { *; } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/SourceManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/SourceManager.kt index 7a64f34014..b504b1af1f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/SourceManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/SourceManager.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.data.source +import android.Manifest.permission.READ_EXTERNAL_STORAGE import android.content.Context import android.os.Environment import eu.kanade.tachiyomi.R @@ -9,6 +10,7 @@ import eu.kanade.tachiyomi.data.source.online.english.* import eu.kanade.tachiyomi.data.source.online.russian.Mangachan import eu.kanade.tachiyomi.data.source.online.russian.Mintmanga import eu.kanade.tachiyomi.data.source.online.russian.Readmanga +import eu.kanade.tachiyomi.util.hasPermission import org.yaml.snakeyaml.Yaml import timber.log.Timber import java.io.File @@ -54,7 +56,7 @@ open class SourceManager(private val context: Context) { val parsersDir = File(Environment.getExternalStorageDirectory().absolutePath + File.separator + context.getString(R.string.app_name), "parsers") - if (parsersDir.exists()) { + if (parsersDir.exists() && context.hasPermission(READ_EXTERNAL_STORAGE)) { val yaml = Yaml() for (file in parsersDir.listFiles().filter { it.extension == "yml" }) { try { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt index 660ac0e121..3884d77b1c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt @@ -111,7 +111,6 @@ class Mangafox(context: Context, override val id: Int) : ParsedOnlineSource(cont document.select("select.m").first().select("option:not([value=0])").forEach { pages.add(Page(pages.size, "$url/${it.attr("value")}.html")) } - pages.getOrNull(0)?.imageUrl = imageUrlParse(document) } // Not used, overrides parent. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.kt index a3846dac6b..7d5eb50274 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.kt @@ -134,7 +134,7 @@ class DownloadFragment : BaseRxFragment() { // Set clear button visibility. clearButton = menu.findItem(R.id.clear_queue).apply { - if (adapter.itemCount > 0) { + if (!presenter.downloadQueue.isEmpty()) { isVisible = true } } @@ -147,7 +147,6 @@ class DownloadFragment : BaseRxFragment() { R.id.clear_queue -> { DownloadService.stop(activity) presenter.clearQueue() - clearButton?.isVisible = false } else -> return super.onOptionsItemSelected(item) } @@ -223,7 +222,7 @@ class DownloadFragment : BaseRxFragment() { isRunning = running startButton?.isVisible = !running && !presenter.downloadQueue.isEmpty() pauseButton?.isVisible = running - clearButton?.isVisible = running + clearButton?.isVisible = !presenter.downloadQueue.isEmpty() // Check if download queue is empty and update information accordingly. setInformationView() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt index cbd0a3aed3..0558eb9f6d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt @@ -313,13 +313,8 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback changeSelectedCover(presenter.selectedMangas) destroyActionModeIfNeeded() } - R.id.action_move_to_category -> { - moveMangasToCategories(presenter.selectedMangas) - } - R.id.action_delete -> { - presenter.deleteMangas() - destroyActionModeIfNeeded() - } + R.id.action_move_to_category -> moveMangasToCategories(presenter.selectedMangas) + R.id.action_delete -> showDeleteMangaDialog() else -> return false } return true @@ -409,6 +404,18 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback .show() } + private fun showDeleteMangaDialog() { + MaterialDialog.Builder(activity) + .content(R.string.confirm_delete_manga) + .positiveText(android.R.string.yes) + .negativeText(android.R.string.no) + .onPositive { dialog, action -> + presenter.removeMangaFromLibrary() + destroyActionModeIfNeeded() + } + .show() + } + /** * Creates the action mode if it's not created already. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 0a8330067c..7413b446fb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -236,7 +236,7 @@ class LibraryPresenter : BasePresenter() { /** * Remove the selected manga from the library. */ - fun deleteMangas() { + fun removeMangaFromLibrary() { // Create a set of the list val mangaToDelete = selectedMangas.toSet() diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ContextExtensions.kt index 4dc11e3a22..e073ddb0d0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ContextExtensions.kt @@ -4,8 +4,10 @@ import android.app.AlarmManager import android.app.Notification import android.app.NotificationManager import android.content.Context +import android.content.pm.PackageManager import android.support.annotation.StringRes import android.support.v4.app.NotificationCompat +import android.support.v4.content.ContextCompat import android.widget.Toast /** @@ -37,6 +39,14 @@ inline fun Context.notification(func: NotificationCompat.Builder.() -> Unit): No return builder.build() } +/** + * Checks if the give permission is granted. + * @param permission the permission to check. + * @return true if it has permissions. + */ +fun Context.hasPermission(permission: String) + = ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED + /** * Property to get the notification manager from the context. */ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1d8f621e04..8cf2594853 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -193,6 +193,7 @@ Title or author… Selected Updating category + Are you sure you want to remove selected manga? This source requires you to log in