diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 2831cb257c8e1047f4d29645260686a8b0b1ab62..3f7ec2d3babd5df70691db956bb3757077a62a5d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -88,52 +88,71 @@ android { } } -val appCompatVersion = "27.0.2" -val appArchVersion = "1.1.0" dependencies { implementation(kotlin("stdlib", "1.2.21")) - implementation(appCompat("appcompat-v7")) - implementation(appCompat("design")) - implementation(appCompat("customtabs")) - implementation(appCompat("cardview-v7")) - implementation(appCompat("recyclerview-v7")) - implementation(appCompat("constraint", "constraint-layout", version = "1.0.2")) - - implementation("io.reactivex.rxjava2", "rxjava", "2.1.9") + // App Compat + withVersion("27.0.2") { + implementation("com.android.support", "appcompat-v7", version) + implementation("com.android.support", "design", version) + implementation("com.android.support", "customtabs", version) + implementation("com.android.support", "cardview-v7", version) + implementation("com.android.support", "recyclerview-v7", version) + } + implementation("com.android.support.constraint", "constraint-layout", "1.0.2") - implementation(appArch("lifecycle", "extensions")) - implementation(appArch("lifecycle", "reactivestreams")) - kapt(appArch("lifecycle", "compiler")) + // App Arch Lifecycle + withVersion("1.1.0") { + implementation("android.arch.lifecycle", "extensions", version) + implementation("android.arch.lifecycle", "reactivestreams", version) + kapt("android.arch.lifecycle", "compiler", version) + } - implementation(appArch("persistence.room", "runtime", "1.1.0-alpha2")) - implementation(appArch("persistence.room", "rxjava2", "1.1.0-alpha2")) - kapt(appArch("persistence.room", "compiler", "1.1.0-alpha2")) + // App Arch Persistence + withVersion("1.1.0-alpha2") { + implementation("android.arch.persistence.room", "runtime", version) + implementation("android.arch.persistence.room", "rxjava2", version) + kapt("android.arch.persistence.room", "compiler", version) + testImplementation("android.arch.persistence.room", "testing", version) + } - implementation(appArch("paging", "runtime", version = "1.0.0-alpha5")) { + // App Arch Paging + implementation("android.arch.paging", "runtime", "1.0.0-alpha5") { exclude(group = "junit", module = "junit") } - implementation("me.zhanghai.android.materialprogressbar", "library", "1.4.2") - + // Utility + implementation("io.reactivex.rxjava2", "rxjava", "2.1.9") implementation("org.threeten", "threetenbp", "1.3.6", classifier = "no-tzdb") + implementation("org.jetbrains", "annotations", "15.0") + withVersion("2.14.1") { + implementation("com.google.dagger", "dagger-android", version) + implementation("com.google.dagger", "dagger-android-support", version) - implementation("com.jakewharton", "butterknife", "8.8.1") - kapt("com.jakewharton", "butterknife-compiler", "8.8.1") + kapt("com.google.dagger", "dagger-android-processor", version) + kapt("com.google.dagger", "dagger-compiler", version) + } + withVersion("8.8.1") { + implementation("com.jakewharton", "butterknife", version) + kapt("com.jakewharton", "butterknife-compiler", version) + } + // Quassel implementation(project(":lib")) { exclude(group = "org.threeten", module = "threetenbp") } - implementation(project(":malheur")) - implementation("org.jetbrains", "annotations", "15.0") - - testImplementation(appArch("persistence.room", "testing", "1.0.0")) - testImplementation("junit", "junit", "4.12") + // UI + implementation("me.zhanghai.android.materialprogressbar", "library", "1.4.2") - androidTestImplementation("com.android.support.test", "runner", "1.0.1") - androidTestImplementation("com.android.support.test", "rules", "1.0.1") + // Quality Assurance + implementation(project(":malheur")) + testImplementation("junit", "junit", "4.12") + withVersion("1.0.1") { + androidTestImplementation("com.android.support.test", "runner", version) + androidTestImplementation("com.android.support.test", "rules", version) + } androidTestImplementation("com.android.support.test.espresso", "espresso-core", "3.0.1") } @@ -167,27 +186,4 @@ fun Project.properties(fileName: String): Properties? { val props = Properties() props.load(file.inputStream()) return props -} - -/** - * Builds the dependency notation for the named AppCompat [module] at the given [version]. - * - * @param module simple name of the AppCompat module, for example "cardview-v7". - * @param version optional desired version, null implies [appCompatVersion]. - */ -fun appCompat(module: String, submodule: String? = null, version: String? = null) - = if (submodule != null) { - "com.android.support.$module:$submodule:${version ?: appCompatVersion}" -} else { - "com.android.support:$module:${version ?: appCompatVersion}" -} - -/** - * Builds the dependency notation for the named AppArch [module] at the given [version]. - * - * @param module simple name of the AppArch module, for example "persistence.room". - * @param submodule simple name of the AppArch submodule, for example "runtime". - * @param version optional desired version, null implies [appCompatVersion]. - */ -fun appArch(module: String, submodule: String, version: String? = null) - = "android.arch.$module:$submodule:${version ?: appArchVersion}" +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 10e5e5f1b1ce46435a002512cbac4ba6bc8ed767..a6839415a8537b7ed338f6be54601e4704cec5c7 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -39,4 +39,6 @@ # Kotlin stuff -dontnote kotlin.** # Gson --dontnote com.google.gson.** \ No newline at end of file +-dontnote com.google.gson.** +# Dagger +-dontwarn com.google.errorprone.annotations.* \ No newline at end of file diff --git a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/ChatActivity.kt b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/ChatActivity.kt index c62795a305069f569f0d5e52a6b6d23a9b659db2..6d22c4ca94af489a36c3887220a3d704369f7c2d 100644 --- a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/ChatActivity.kt +++ b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/ChatActivity.kt @@ -22,6 +22,7 @@ import de.kuschku.quasseldroid_ng.Keys import de.kuschku.quasseldroid_ng.R import de.kuschku.quasseldroid_ng.persistence.AccountDatabase import de.kuschku.quasseldroid_ng.persistence.QuasselDatabase +import de.kuschku.quasseldroid_ng.ui.settings.data.BacklogSettings import de.kuschku.quasseldroid_ng.ui.viewmodel.QuasselViewModel import de.kuschku.quasseldroid_ng.util.AndroidHandlerThread import de.kuschku.quasseldroid_ng.util.helper.* @@ -54,6 +55,8 @@ class ChatActivity : ServiceBoundActivity() { private lateinit var database: QuasselDatabase + private var backlogSettings = BacklogSettings() + override fun onCreate(savedInstanceState: Bundle?) { handler.onCreate() super.onCreate(savedInstanceState) @@ -177,6 +180,21 @@ class ChatActivity : ServiceBoundActivity() { android.R.id.home -> { drawerToggle.onOptionsItemSelected(item) } + R.id.clear -> { + handler.post { + viewModel.sessionManager { manager -> + viewModel.getBuffer().let { buffer -> + manager.backlogStorage.clearMessages(buffer) + manager.backlogManager?.requestBacklog( + bufferId = buffer, + last = -1, + limit = backlogSettings.dynamicAmount + ) + } + } + } + true + } R.id.disconnect -> { handler.post { getSharedPreferences(Keys.Status.NAME, Context.MODE_PRIVATE).editApply { diff --git a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/MessageListFragment.kt b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/MessageListFragment.kt index 34ab9c155d4cc767bb33aa2634fa108598956297..1861c7a248b08721a0d109fb2f166965207e1e89 100644 --- a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/MessageListFragment.kt +++ b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/MessageListFragment.kt @@ -18,6 +18,7 @@ import de.kuschku.libquassel.protocol.MsgId import de.kuschku.libquassel.quassel.syncables.BufferSyncer import de.kuschku.quasseldroid_ng.R import de.kuschku.quasseldroid_ng.persistence.QuasselDatabase +import de.kuschku.quasseldroid_ng.ui.settings.data.BacklogSettings import de.kuschku.quasseldroid_ng.ui.viewmodel.QuasselViewModel import de.kuschku.quasseldroid_ng.util.AndroidHandlerThread import de.kuschku.quasseldroid_ng.util.helper.* @@ -41,6 +42,8 @@ class MessageListFragment : ServiceBoundFragment() { private var lastBuffer: BufferId? = null + private var backlogSettings = BacklogSettings() + override fun onCreate(savedInstanceState: Bundle?) { handler.onCreate() super.onCreate(savedInstanceState) @@ -84,9 +87,9 @@ class MessageListFragment : ServiceBoundFragment() { LivePagedListBuilder( database.message().findByBufferIdPaged(it), PagedList.Config.Builder() - .setPageSize(20) - .setPrefetchDistance(20) - .setInitialLoadSizeHint(20) + .setPageSize(backlogSettings.dynamicAmount) + .setPrefetchDistance(backlogSettings.dynamicAmount) + .setInitialLoadSizeHint(backlogSettings.dynamicAmount) .setEnablePlaceholders(true) .build() ).setBoundaryCallback(boundaryCallback).build() @@ -174,7 +177,7 @@ class MessageListFragment : ServiceBoundFragment() { last = database.message().findFirstByBufferId( bufferId )?.messageId ?: -1, - limit = 20 + limit = backlogSettings.dynamicAmount ) } } diff --git a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/settings/data/BacklogSettings.kt b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/settings/data/BacklogSettings.kt new file mode 100644 index 0000000000000000000000000000000000000000..f72172969267f4fc249b5f10398dec2e626db9b5 --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/settings/data/BacklogSettings.kt @@ -0,0 +1,5 @@ +package de.kuschku.quasseldroid_ng.ui.settings.data + +data class BacklogSettings( + val dynamicAmount: Int = 20 +) \ No newline at end of file diff --git a/app/src/main/res/menu/activity_main.xml b/app/src/main/res/menu/activity_main.xml index 2079987d43c463a713a0b0cfabb024151a0dd39f..3c59fa43cf96dd2ab926dff538fed5ebf89de8aa 100644 --- a/app/src/main/res/menu/activity_main.xml +++ b/app/src/main/res/menu/activity_main.xml @@ -1,5 +1,8 @@ <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> + <item + android:id="@+id/clear" + android:title="Clear Backlog" /> <item android:id="@+id/settings" android:title="Settings" /> diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000000000000000000000000000000000000..d5c75922b75b14abde8fdb8c715a105032ff0f50 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,5 @@ +import org.gradle.kotlin.dsl.`kotlin-dsl` + +plugins { + `kotlin-dsl` +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/VersionContext.kt b/buildSrc/src/main/kotlin/VersionContext.kt new file mode 100644 index 0000000000000000000000000000000000000000..288212239f7d382d3fe1bb0127e85ed9b5e23032 --- /dev/null +++ b/buildSrc/src/main/kotlin/VersionContext.kt @@ -0,0 +1,5 @@ +data class VersionContext(val version: String) + +inline fun withVersion(version: String, f: VersionContext.() -> Unit) { + VersionContext(version).f() +} \ No newline at end of file diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index a7cc8e972d494df2da30f674aafce818391cf192..38f2d1c3a87a9298335375fc4821a0d922f42cb1 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -13,14 +13,14 @@ val appCompatVersion = "27.0.2" dependencies { implementation(kotlin("stdlib", "1.2.21")) - implementation(appCompat("support-annotations")) + implementation("com.android.support", "support-annotations", "27.0.2") implementation("org.threeten", "threetenbp", "1.3.6") implementation("io.reactivex.rxjava2:rxjava:2.1.9") implementation(project(":invokerannotations")) kapt(project(":invokergenerator")) - testImplementation("junit:junit:4.12") + testImplementation("junit", "junit", "4.12") } /* @@ -33,12 +33,3 @@ tasks.withType(KotlinCompile::class.java) { } } */ - -/** - * Builds the dependency notation for the named AppCompat [module] at the given [version]. - * - * @param module simple name of the AppCompat module, for example "cardview-v7". - * @param version optional desired version, null implies [appCompatVersion]. - */ -fun appCompat(module: String, version: String? = null) - = "com.android.support:$module:${version ?: appCompatVersion}"