From 760e423b9bcff11b30e76ff2e83a260e0013d35d Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Mon, 27 Nov 2017 22:06:25 +0100 Subject: [PATCH] Split LabelRepository off the MessageRepository --- .../java/ch/dissem/apps/abit/MainActivity.kt | 4 +- .../abit/adapter/SwipeableMessageAdapter.kt | 2 +- .../abit/repository/AndroidLabelRepository.kt | 113 +++++++++++ .../repository/AndroidMessageRepository.kt | 183 +++++------------- .../ch/dissem/apps/abit/service/Singleton.kt | 51 ++--- .../java/ch/dissem/apps/abit/util/Exports.kt | 9 +- .../repository/AndroidLabelRepositoryTest.kt | 60 ++++++ .../AndroidMessageRepositoryTest.kt | 135 ++++++------- .../AndroidProofOfWorkRepositoryTest.kt | 8 +- .../dissem/bitmessage/repository/TestBase.kt | 68 ++++--- build.gradle | 2 +- 11 files changed, 356 insertions(+), 279 deletions(-) create mode 100644 app/src/main/java/ch/dissem/apps/abit/repository/AndroidLabelRepository.kt create mode 100644 app/src/test/java/ch/dissem/bitmessage/repository/AndroidLabelRepositoryTest.kt diff --git a/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt b/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt index dd470fa..59f578f 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt +++ b/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt @@ -28,7 +28,7 @@ import android.widget.RelativeLayout import ch.dissem.apps.abit.drawer.ProfileImageListener import ch.dissem.apps.abit.drawer.ProfileSelectionListener import ch.dissem.apps.abit.listener.ListSelectionListener -import ch.dissem.apps.abit.repository.AndroidMessageRepository.Companion.LABEL_ARCHIVE +import ch.dissem.apps.abit.repository.AndroidLabelRepository.Companion.LABEL_ARCHIVE import ch.dissem.apps.abit.service.Singleton import ch.dissem.apps.abit.synchronization.SyncAdapter import ch.dissem.apps.abit.util.Labels @@ -278,7 +278,7 @@ class MainActivity : AppCompatActivity(), ListSelectionListener { } doAsync { - val labels = bmc.messages.getLabels() + val labels = bmc.labels.getLabels() uiThread { if (intent.hasExtra(EXTRA_SHOW_LABEL)) { diff --git a/app/src/main/java/ch/dissem/apps/abit/adapter/SwipeableMessageAdapter.kt b/app/src/main/java/ch/dissem/apps/abit/adapter/SwipeableMessageAdapter.kt index a5d2c22..76804c0 100644 --- a/app/src/main/java/ch/dissem/apps/abit/adapter/SwipeableMessageAdapter.kt +++ b/app/src/main/java/ch/dissem/apps/abit/adapter/SwipeableMessageAdapter.kt @@ -28,7 +28,7 @@ import android.widget.ImageView import android.widget.TextView import ch.dissem.apps.abit.Identicon import ch.dissem.apps.abit.R -import ch.dissem.apps.abit.repository.AndroidMessageRepository.Companion.LABEL_ARCHIVE +import ch.dissem.apps.abit.repository.AndroidLabelRepository.Companion.LABEL_ARCHIVE import ch.dissem.apps.abit.util.Assets import ch.dissem.apps.abit.util.Strings.prepareMessageExtract import ch.dissem.bitmessage.entity.Plaintext diff --git a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidLabelRepository.kt b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidLabelRepository.kt new file mode 100644 index 0000000..27f490a --- /dev/null +++ b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidLabelRepository.kt @@ -0,0 +1,113 @@ +/* + * Copyright 2015 Christian Basler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.dissem.apps.abit.repository + +import android.content.ContentValues +import android.content.Context +import android.database.Cursor +import android.database.DatabaseUtils +import ch.dissem.apps.abit.util.Labels +import ch.dissem.bitmessage.entity.valueobject.Label +import ch.dissem.bitmessage.ports.AbstractLabelRepository +import ch.dissem.bitmessage.ports.MessageRepository +import java.util.* + +/** + * [MessageRepository] implementation using the Android SQL API. + */ +class AndroidLabelRepository(private val sql: SqlHelper, private val context: Context) : AbstractLabelRepository() { + + override fun find(where: String): List