From 59c626b4a8bd47556378fd3dbc6e66b65ee5b1b9 Mon Sep 17 00:00:00 2001 From: len Date: Sat, 19 Nov 2016 14:46:49 +0100 Subject: [PATCH] Add an extension function to limit the number of characters in a string. Dependency updates --- app/build.gradle | 6 +++--- .../data/library/LibraryUpdateService.kt | 15 ++++++--------- .../eu/kanade/tachiyomi/util/StringExtensions.kt | 13 +++++++++++++ 3 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/util/StringExtensions.kt diff --git a/app/build.gradle b/app/build.gradle index e80db108f2..1c3a399310 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -114,7 +114,7 @@ dependencies { compile 'com.android.support:multidex:1.0.1' // Job scheduling - compile 'com.evernote:android-job:1.1.2' + compile 'com.evernote:android-job:1.1.3' compile 'com.google.android.gms:play-services-gcm:9.8.0' // ReactiveX @@ -140,7 +140,7 @@ dependencies { compile 'com.github.bmoliveira:snake-yaml:v1.18-android' // JavaScript engine - compile 'com.squareup.duktape:duktape-android:1.0.0' + compile 'com.squareup.duktape:duktape-android:1.1.0' // Disk cache compile 'com.jakewharton:disklrucache:2.0.2' @@ -200,7 +200,7 @@ dependencies { } buildscript { - ext.kotlin_version = '1.0.5' + ext.kotlin_version = '1.0.5-2' repositories { mavenCentral() } 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 14f5b3ee08..1844549ff8 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 @@ -20,10 +20,7 @@ import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.source.SourceManager import eu.kanade.tachiyomi.data.source.online.OnlineSource import eu.kanade.tachiyomi.ui.main.MainActivity -import eu.kanade.tachiyomi.util.AndroidComponentUtil -import eu.kanade.tachiyomi.util.notification -import eu.kanade.tachiyomi.util.notificationManager -import eu.kanade.tachiyomi.util.syncChaptersWithSource +import eu.kanade.tachiyomi.util.* import rx.Observable import rx.Subscription import rx.schedulers.Schedulers @@ -330,7 +327,7 @@ class LibraryUpdateService : Service() { append(getString(R.string.notification_new_chapters)) for (manga in updates) { append("\n") - append(manga.title) + append(manga.title.chop(30)) } } if (!failedUpdates.isEmpty()) { @@ -338,7 +335,7 @@ class LibraryUpdateService : Service() { append(getString(R.string.notification_manga_update_failed)) for (manga in failedUpdates) { append("\n") - append(manga.title) + append(manga.title.chop(30)) } } toString() @@ -370,7 +367,7 @@ class LibraryUpdateService : Service() { * @param body the body of the notification. */ private fun showNotification(title: String, body: String) { - notificationManager.notify(notificationId, notification() { + notificationManager.notify(notificationId, notification { setSmallIcon(R.drawable.ic_refresh_white_24dp_img) setLargeIcon(notificationBitmap) setContentTitle(title) @@ -386,7 +383,7 @@ class LibraryUpdateService : Service() { * @param total the total progress. */ private fun showProgressNotification(manga: Manga, current: Int, total: Int, cancelIntent: PendingIntent) { - notificationManager.notify(notificationId, notification() { + notificationManager.notify(notificationId, notification { setSmallIcon(R.drawable.ic_refresh_white_24dp_img) setLargeIcon(notificationBitmap) setContentTitle(manga.title) @@ -407,7 +404,7 @@ class LibraryUpdateService : Service() { val title = getString(R.string.notification_update_completed) val body = getUpdatedMangasBody(updates, failed) - notificationManager.notify(notificationId, notification() { + notificationManager.notify(notificationId, notification { setSmallIcon(R.drawable.ic_refresh_white_24dp_img) setLargeIcon(notificationBitmap) setContentTitle(title) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/StringExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/StringExtensions.kt new file mode 100644 index 0000000000..9a997bae87 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/util/StringExtensions.kt @@ -0,0 +1,13 @@ +package eu.kanade.tachiyomi.util + +/** + * Replaces the given string to have at most [count] characters using [replacement] at its end. + * If [replacement] is longer than [count] an exception will be thrown when `length > count`. + */ +fun String.chop(count: Int, replacement: String = "..."): String { + return if (length > count) + take(count - replacement.length) + replacement + else + this + +}