From 6da8c368fa9ee3c2d6c53cf18304e168998ea053 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 2 Nov 2019 23:07:07 -0700 Subject: [PATCH] Fixes to android lollipop Notification icons now has color Coping title or other text in manga info is now a snackbar, shows the type of text copied --- .../data/download/DownloadNotifier.kt | 3 ++- .../data/library/LibraryUpdateService.kt | 5 +++-- .../tachiyomi/data/updater/UpdaterJob.kt | 3 ++- .../tachiyomi/data/updater/UpdaterNotifier.kt | 3 ++- .../ui/manga/info/MangaInfoController.kt | 20 +++++++++++-------- .../kanade/tachiyomi/util/ViewExtensions.kt | 8 ++++---- app/src/main/res/values/themes.xml | 2 +- 7 files changed, 26 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt index bedcd43a54..e20f5b2a28 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.data.download import android.content.Context import android.graphics.BitmapFactory import androidx.core.app.NotificationCompat +import androidx.core.content.ContextCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.download.model.DownloadQueue @@ -219,7 +220,7 @@ internal class DownloadNotifier(private val context: Context) { clearActions() setAutoCancel(true) setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context)) - color = context.getResourceColor(R.attr.colorAccent) + color = ContextCompat.getColor(context, R.color.colorAccentLight) setProgress(0, 0, false) } notification.show(Notifications.ID_DOWNLOAD_CHAPTER_ERROR) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index dd2fbe4006..969879be4d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -10,6 +10,7 @@ import android.os.Build import android.os.IBinder import android.os.PowerManager import androidx.core.app.NotificationCompat +import androidx.core.content.ContextCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category @@ -90,7 +91,7 @@ class LibraryUpdateService( .setLargeIcon(notificationBitmap) .setOngoing(true) .setOnlyAlertOnce(true) - .setColor(getResourceColor(R.attr.colorAccent)) + .setColor(ContextCompat.getColor(this, R.color.colorAccentLight)) .addAction(R.drawable.ic_clear_grey_24dp_img, getString(android.R.string.cancel), cancelIntent) } @@ -463,7 +464,7 @@ class LibraryUpdateService( setSmallIcon(R.drawable.ic_book_white_24dp) setLargeIcon(notificationBitmap) setContentTitle(getString(R.string.notification_new_chapters)) - color = getResourceColor(R.attr.colorAccent) + color = ContextCompat.getColor(applicationContext, R.color.colorAccentLight) if (newUpdates.size > 1) { setContentText(getString(R.string.notification_new_chapters_text, newUpdates.size)) setStyle(NotificationCompat.BigTextStyle().bigText(newUpdates.joinToString("\n"))) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt index 6b69afabb5..deda43a7a9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.data.updater import android.app.PendingIntent import android.content.Intent import androidx.core.app.NotificationCompat +import androidx.core.content.ContextCompat import com.evernote.android.job.Job import com.evernote.android.job.JobManager import com.evernote.android.job.JobRequest @@ -28,7 +29,7 @@ class UpdaterJob : Job() { setContentTitle(context.getString(R.string.app_name)) setContentText(context.getString(R.string.update_check_notification_update_available)) setSmallIcon(android.R.drawable.stat_sys_download_done) - color = context.getResourceColor(R.attr.colorAccent) + color = ContextCompat.getColor(context, R.color.colorAccentLight) // Download action addAction(android.R.drawable.stat_sys_download_done, context.getString(R.string.action_download), diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterNotifier.kt index 18575f8fa1..81023f6096 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterNotifier.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.data.updater import android.content.Context import android.net.Uri import androidx.core.app.NotificationCompat +import androidx.core.content.ContextCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.NotificationHandler import eu.kanade.tachiyomi.data.notification.NotificationReceiver @@ -96,7 +97,7 @@ internal class UpdaterNotifier(private val context: Context) { setSmallIcon(android.R.drawable.stat_sys_warning) setOnlyAlertOnce(false) setProgress(0, 0, false) - color = context.getResourceColor(R.attr.colorAccent) + color = ContextCompat.getColor(context, R.color.colorAccentLight) // Retry action addAction(R.drawable.ic_refresh_grey_24dp_img, context.getString(R.string.action_retry), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index aa17339f45..5aefb15c03 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -101,7 +101,8 @@ class MangaInfoController : NucleusController(), swipe_refresh.refreshes().subscribeUntilDestroy { fetchMangaFromSource() } manga_full_title.longClicks().subscribeUntilDestroy { - copyToClipboard(view.context.getString(R.string.title), manga_full_title.text.toString()) + copyToClipboard(view.context.getString(R.string.title), manga_full_title.text + .toString(), R.string.manga_info_full_title_label) } manga_full_title.clicks().subscribeUntilDestroy { @@ -109,7 +110,8 @@ class MangaInfoController : NucleusController(), } manga_artist.longClicks().subscribeUntilDestroy { - copyToClipboard(manga_artist_label.text.toString(), manga_artist.text.toString()) + copyToClipboard(manga_artist_label.text.toString(), manga_artist.text.toString(), R + .string.manga_info_artist_label) } manga_artist.clicks().subscribeUntilDestroy { @@ -117,7 +119,8 @@ class MangaInfoController : NucleusController(), } manga_author.longClicks().subscribeUntilDestroy { - copyToClipboard(manga_author.text.toString(), manga_author.text.toString()) + copyToClipboard(manga_author.text.toString(), manga_author.text.toString(), R.string + .manga_info_author_label) } manga_author.clicks().subscribeUntilDestroy { @@ -125,13 +128,14 @@ class MangaInfoController : NucleusController(), } manga_summary.longClicks().subscribeUntilDestroy { - copyToClipboard(view.context.getString(R.string.description), manga_summary.text.toString()) + copyToClipboard(view.context.getString(R.string.description), manga_summary.text + .toString(), R.string.description) } //manga_genres_tags.setOnTagClickListener { tag -> performGlobalSearch(tag) } manga_cover.longClicks().subscribeUntilDestroy { - copyToClipboard(view.context.getString(R.string.title), presenter.manga.title) + copyToClipboard(view.context.getString(R.string.title), presenter.manga.title, R.string.manga_info_full_title_label) } container = (view as ViewGroup).findViewById(R.id.manga_info_layout) as? View val bottomM = manga_genres_tags.marginBottom @@ -569,7 +573,7 @@ class MangaInfoController : NucleusController(), * @param label Label to show to the user describing the content * @param content the actual text to copy to the board */ - private fun copyToClipboard(label: String, content: String) { + private fun copyToClipboard(label: String, content: String, resId: Int) { if (content.isBlank()) return val activity = activity ?: return @@ -578,8 +582,8 @@ class MangaInfoController : NucleusController(), val clipboard = activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager clipboard.setPrimaryClip(ClipData.newPlainText(label, content)) - activity.toast(view.context.getString(R.string.copied_to_clipboard, content.truncateCenter(20)), - Toast.LENGTH_SHORT) + snack = container?.snack(view.context.getString(R.string.copied_to_clipboard, view.context + .getString(resId))) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt index 8558cf1ccc..7b8009e7ab 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt @@ -55,10 +55,10 @@ Unit)? = null): Snackbar { if (f != null) { snack.f() } - snack.view.doOnApplyWindowInsets { v, insets, padding -> - //v.setPadding(padding.left, 0, padding.right, 0) - v.updateLayoutParams { - if (Build.VERSION.SDK_INT < 23) { + if (Build.VERSION.SDK_INT < 23) { + val view = if (this !is CoordinatorLayout) this else snack.view + view.doOnApplyWindowInsets { _, insets, _ -> + snack.view.updateLayoutParams { bottomMargin = 12 + insets.systemWindowInsetBottom } } diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index d6084bfebc..ce52db94c8 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -40,7 +40,7 @@ @color/iconColorLight @android:color/transparent - @color/colorPrimary + #B3000000