Split up app module into domain/data/presentation

This commit is contained in:
Moez Bhatti
2018-03-22 00:32:07 -04:00
parent 4ef97ab854
commit d7d202392c
282 changed files with 1153 additions and 482 deletions
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import repository.SyncRepository
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
open class ContactSync @Inject constructor(private val syncManager: SyncRepository) : Interactor<Unit>() {
override fun buildObservable(params: Unit): Flowable<Long> {
return Flowable.just(System.currentTimeMillis())
.doOnNext { syncManager.syncContacts() }
.map { startTime -> System.currentTimeMillis() - startTime }
.map { elapsed -> TimeUnit.MILLISECONDS.toSeconds(elapsed) }
.doOnNext { seconds -> Timber.v("Completed sync in $seconds seconds") }
}
}
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class DeleteConversation @Inject constructor(
private val messageRepo: MessageRepository,
private val updateBadge: UpdateBadge
): Interactor<Long>() {
override fun buildObservable(params: Long): Flowable<*> {
return Flowable.just(Unit)
.doOnNext { messageRepo.deleteConversation(params) }
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
}
}
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class DeleteMessage @Inject constructor(
private val messageRepository: MessageRepository,
private val updateBadge: UpdateBadge
) : Interactor<Long>() {
override fun buildObservable(params: Long): Flowable<*> {
return Flowable.just(params)
.doOnNext { messageId -> messageRepository.deleteMessage(messageId) }
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
}
}
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import manager.KeyManager
import repository.SyncRepository
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
class FullSync @Inject constructor(
private val syncManager: SyncRepository,
private val keys: KeyManager
) : Interactor<Unit>() {
override fun buildObservable(params: Unit): Flowable<Long> {
return Flowable.just(System.currentTimeMillis())
.doOnNext { keys.reset() }
.doOnNext { syncManager.syncMessages(true) }
.map { startTime -> System.currentTimeMillis() - startTime }
.map { elapsed -> TimeUnit.MILLISECONDS.toSeconds(elapsed) }
.doOnNext { seconds -> Timber.v("Completed sync in $seconds seconds") }
}
}
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.schedulers.Schedulers
abstract class Interactor<in Params>: Disposable {
private val disposables: CompositeDisposable = CompositeDisposable()
abstract fun buildObservable(params: Params): Flowable<*>
fun execute(params: Params, onComplete: () -> Unit = {}) {
disposables += buildObservable(params)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnComplete(onComplete)
.subscribe()
}
override fun dispose() {
return disposables.dispose()
}
override fun isDisposed(): Boolean {
return disposables.isDisposed
}
}
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkAllSeen @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Unit>() {
override fun buildObservable(params: Unit): Flowable<Unit> {
return Flowable.just(Unit)
.doOnNext { messageRepo.markAllSeen() }
}
}
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkArchived @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
override fun buildObservable(params: Long): Flowable<Unit> {
return Flowable.just(Unit)
.doOnNext { messageRepo.markArchived(params) }
}
}
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkBlocked @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
override fun buildObservable(params: Long): Flowable<Unit> {
return Flowable.just(Unit)
.doOnNext { messageRepo.markBlocked(params) }
}
}
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkDelivered @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
override fun buildObservable(params: Long): Flowable<Unit> {
return Flowable.just(Unit)
.doOnNext { messageRepo.markDelivered(params) }
}
}
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkDeliveryFailed @Inject constructor(
private val messageRepo: MessageRepository
) : Interactor<MarkDeliveryFailed.Params>() {
data class Params(val id: Long, val resultCode: Int)
override fun buildObservable(params: Params): Flowable<Unit> {
return Flowable.just(Unit)
.doOnNext { messageRepo.markDeliveryFailed(params.id, params.resultCode) }
}
}
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import manager.NotificationManager
import repository.MessageRepository
import javax.inject.Inject
class MarkFailed @Inject constructor(
private val messageRepo: MessageRepository,
private val notificationManager: NotificationManager
) : Interactor<MarkFailed.Params>() {
data class Params(val id: Long, val resultCode: Int)
override fun buildObservable(params: Params): Flowable<Unit> {
return Flowable.just(Unit)
.doOnNext { messageRepo.markFailed(params.id, params.resultCode) }
.doOnNext { notificationManager.notifyFailed(params.id) }
}
}
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import manager.NotificationManager
import repository.MessageRepository
import javax.inject.Inject
class MarkRead @Inject constructor(
private val messageRepo: MessageRepository,
private val notificationManager: NotificationManager,
private val updateBadge: UpdateBadge
) : Interactor<Long>() {
override fun buildObservable(params: Long): Flowable<*> {
return Flowable.just(Unit)
.doOnNext { messageRepo.markRead(params) }
.doOnNext { notificationManager.update(params) }
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
}
}
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkSeen @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
override fun buildObservable(params: Long): Flowable<Unit> {
return Flowable.just(Unit)
.doOnNext { messageRepo.markSeen(params) }
}
}
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkSent @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
override fun buildObservable(params: Long): Flowable<Unit> {
return Flowable.just(Unit)
.doOnNext { messageRepo.markSent(params) }
}
}
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkUnarchived @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
override fun buildObservable(params: Long): Flowable<Unit> {
return Flowable.just(Unit)
.doOnNext { messageRepo.markUnarchived(params) }
}
}
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkUnblocked @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
override fun buildObservable(params: Long): Flowable<Unit> {
return Flowable.just(Unit)
.doOnNext { messageRepo.markUnblocked(params) }
}
}
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import manager.PermissionManager
import repository.SyncRepository
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
open class PartialSync @Inject constructor(
private val syncManager: SyncRepository,
private val permissions: PermissionManager
) : Interactor<Unit>() {
override fun buildObservable(params: Unit): Flowable<Long> {
return Flowable.just(System.currentTimeMillis())
.skipWhile { !permissions.hasSmsAndContacts() }
.doOnNext { syncManager.syncMessages() }
.map { startTime -> System.currentTimeMillis() - startTime }
.map { elapsed -> TimeUnit.MILLISECONDS.toSeconds(elapsed) }
.doOnNext { seconds -> Timber.v("Completed sync in $seconds seconds") }
}
}
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import model.Message
import repository.MessageRepository
import javax.inject.Inject
class RetrySending @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Message>() {
override fun buildObservable(params: Message): Flowable<Message> {
// We don't want to touch the supplied message on another thread in case it's a live realm
// object, so copy the required fields into a new object that is safe to pass around threads
val message = Message().apply {
id = params.id
type = params.type
threadId = params.threadId
address = params.address
body = params.body
}
return Flowable.just(message)
.filter { message.isSms() } // TODO support resending failed MMS
.doOnNext { messageRepo.markSending(message.id) }
.doOnNext { messageRepo.sendSms(message) }
}
}
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import android.content.Context
import android.provider.MediaStore
import androidx.net.toUri
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class SaveImage @Inject constructor(
private val context: Context,
private val messageRepo: MessageRepository
) : Interactor<Long>() {
override fun buildObservable(params: Long): Flowable<*> {
return Flowable.just(params)
.map { partId -> messageRepo.getPart(partId) }
.map { part -> part.image }
.map { uriString -> uriString.toUri() }
.map { uri -> MediaStore.Images.Media.getBitmap(context.contentResolver, uri) }
.doOnNext { bitmap -> MediaStore.Images.Media.insertImage(context.contentResolver, bitmap, "title", "description") }
}
}
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import android.net.Uri
import io.reactivex.Flowable
import model.Message
import repository.SyncRepository
import javax.inject.Inject
class SyncMessage @Inject constructor(private val syncManager: SyncRepository) : Interactor<Uri>() {
override fun buildObservable(params: Uri): Flowable<Message> {
return Flowable.just(params)
.flatMap { uri -> syncManager.syncMessage(uri) }
}
}
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package interactor
import io.reactivex.Flowable
import manager.WidgetManager
import repository.MessageRepository
import javax.inject.Inject
class UpdateBadge @Inject constructor(
private val messageRepo: MessageRepository,
private val widgetManager: WidgetManager
) : Interactor<Unit>() {
override fun buildObservable(params: Unit): Flowable<*> {
return Flowable.just(params)
.map { messageRepo.getUnreadMessageCount() }
.map { count -> count.toInt() }
.doOnNext { count -> widgetManager.updateUnreadCount(count) }
}
}
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package manager
interface AnalyticsManager {
fun track(event: String)
}
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package manager
/**
* Helper class for generating incrementing ids for messages
*/
interface KeyManager {
/**
* Should be called when a new sync is being started
*/
fun reset()
/**
* Returns a valid ID that can be used to store a new message
*/
fun newId(): Long
}
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package manager
interface NotificationManager {
fun update(threadId: Long)
fun notifyFailed(threadId: Long)
fun createNotificationChannel(threadId: Long)
fun buildNotificationChannelId(threadId: Long): String
}
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package manager
interface PermissionManager {
fun hasSmsAndContacts(): Boolean
}
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package manager
interface WidgetManager {
fun updateUnreadCount(count: Int)
}
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package mapper
import android.database.Cursor
import model.Contact
interface CursorToContact : Mapper<Cursor, Contact> {
fun getContactsCursor(): Cursor
}
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package mapper
import android.database.Cursor
import model.Conversation
interface CursorToConversation : Mapper<Cursor, Conversation> {
fun getConversationsCursor(lastSync: Long = 0): Cursor
fun getConversationCursor(threadId: Long): Cursor
}
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package mapper
import android.database.Cursor
import android.provider.Telephony.*
import model.Message
import timber.log.Timber
import java.util.*
interface CursorToMessage : Mapper<Pair<Cursor, CursorToMessage.MessageColumns>, Message> {
fun getMessagesCursor(): Cursor
fun getMessageCursor(id: Long): Cursor
class MessageColumns(private val cursor: Cursor) {
val msgType by lazy { getColumnIndex(MmsSms.TYPE_DISCRIMINATOR_COLUMN) }
val msgId by lazy { getColumnIndex(MmsSms._ID) }
val date by lazy { getColumnIndex(Mms.DATE) }
val dateSent by lazy { getColumnIndex(Mms.DATE_SENT) }
val read by lazy { getColumnIndex(Mms.READ) }
val threadId by lazy { getColumnIndex(Mms.THREAD_ID) }
val locked by lazy { getColumnIndex(Mms.LOCKED) }
val smsAddress by lazy { getColumnIndex(Sms.ADDRESS) }
val smsBody by lazy { getColumnIndex(Sms.BODY) }
val smsSeen by lazy { getColumnIndex(Sms.SEEN) }
val smsType by lazy { getColumnIndex(Sms.TYPE) }
val smsStatus by lazy { getColumnIndex(Sms.STATUS) }
val smsErrorCode by lazy { getColumnIndex(Sms.ERROR_CODE) }
val mmsSubject by lazy { getColumnIndex(Mms.SUBJECT) }
val mmsSubjectCharset by lazy { getColumnIndex(Mms.SUBJECT_CHARSET) }
val mmsSeen by lazy { getColumnIndex(Mms.SEEN) }
val mmsMessageType by lazy { getColumnIndex(Mms.MESSAGE_TYPE) }
val mmsMessageBox by lazy { getColumnIndex(Mms.MESSAGE_BOX) }
val mmsDeliveryReport by lazy { getColumnIndex(Mms.DELIVERY_REPORT) }
val mmsReadReport by lazy { getColumnIndex(Mms.READ_REPORT) }
val mmsErrorType by lazy { getColumnIndex(MmsSms.PendingMessages.ERROR_TYPE) }
val mmsStatus by lazy { getColumnIndex(Mms.STATUS) }
private fun getColumnIndex(columnsName: String) = try {
cursor.getColumnIndexOrThrow(columnsName)
} catch (e: Exception) {
Timber.e("Couldn't find column \'$columnsName\' in ${Arrays.toString(cursor.columnNames)}")
-1
}
}
}
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package mapper
import android.database.Cursor
import model.MmsPart
interface CursorToPart : Mapper<Cursor, MmsPart> {
fun getPartsCursor(messageId: Long): Cursor?
}
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package mapper
import android.database.Cursor
import model.Recipient
interface CursorToRecipient : Mapper<Cursor, Recipient> {
fun getRecipientCursor(): Cursor
fun getRecipientCursor(id: Long): Cursor
}
+25
View File
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package mapper
interface Mapper<in From, out To> {
fun map(from: From): To
}
+30
View File
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package model
import io.realm.RealmList
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
open class Contact(
@PrimaryKey var lookupKey: String = "",
var numbers: RealmList<PhoneNumber> = RealmList(),
var name: String = "",
var lastUpdate: Long = 0
) : RealmObject()
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package model
import android.telephony.PhoneNumberUtils
import io.realm.RealmList
import io.realm.RealmObject
import io.realm.annotations.Index
import io.realm.annotations.PrimaryKey
import java.util.*
open class Conversation : RealmObject() {
@PrimaryKey var id: Long = 0
var recipients: RealmList<Recipient> = RealmList()
@Index var archived: Boolean = false
@Index var blocked: Boolean = false
var draft: String = ""
fun getTitle() = recipients.joinToString { recipient ->
recipient.contact?.name?.takeIf { it.isNotBlank() }
?: PhoneNumberUtils.formatNumber(recipient.address, Locale.getDefault().country)
?: recipient.address
}
}
+160
View File
@@ -0,0 +1,160 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package model
import android.content.ContentUris
import android.net.Uri
import android.provider.Telephony.*
import io.realm.RealmList
import io.realm.RealmObject
import io.realm.annotations.Index
import io.realm.annotations.PrimaryKey
open class Message : RealmObject() {
enum class AttachmentType { TEXT, IMAGE, VIDEO, AUDIO, SLIDESHOW, NOT_LOADED }
@PrimaryKey var id: Long = 0
// The MMS-SMS content provider returns messages where duplicate ids can exist. This is because
// SMS and MMS are stored in separate tables. We can't use these ids as our realm message id
// since it's our primary key for the single message object, so we'll store the original id in
// case we need to access the original message item in the content provider
var contentId: Long = 0
@Index var threadId: Long = 0
var address: String = ""
var boxId: Int = 0
var type: String = ""
var date: Long = 0
var dateSent: Long = 0
var seen: Boolean = false
var read: Boolean = false
var locked: Boolean = false
// SMS only
var body: String = ""
var errorCode: Int = 0
var deliveryStatus: Int = Sms.STATUS_NONE
// MMS only
var attachmentTypeString: String = AttachmentType.NOT_LOADED.toString()
var attachmentType: AttachmentType
get() = AttachmentType.valueOf(attachmentTypeString)
set(value) {
attachmentTypeString = value.toString()
}
var mmsDeliveryStatusString: String = ""
var readReportString: String = ""
var errorType: Int = 0
var messageSize: Int = 0
var messageType: Int = 0
var mmsStatus: Int = 0
var subject: String = ""
var textContentType: String = ""
var parts: RealmList<MmsPart> = RealmList()
fun getUri(): Uri {
val baseUri = if (isMms()) Mms.CONTENT_URI else Sms.CONTENT_URI
return ContentUris.withAppendedId(baseUri, contentId)
}
fun isMms(): Boolean = type == "mms"
fun isSms(): Boolean = type == "sms"
fun isMe(): Boolean {
val isIncomingMms = isMms() && (boxId == Mms.MESSAGE_BOX_INBOX || boxId == Mms.MESSAGE_BOX_ALL)
val isIncomingSms = isSms() && (boxId == Sms.MESSAGE_TYPE_INBOX || boxId == Sms.MESSAGE_TYPE_ALL)
return !(isIncomingMms || isIncomingSms)
}
fun isOutgoingMessage(): Boolean {
val isOutgoingMms = isMms() && boxId == Mms.MESSAGE_BOX_OUTBOX
val isOutgoingSms = isSms() && (boxId == Sms.MESSAGE_TYPE_FAILED
|| boxId == Sms.MESSAGE_TYPE_OUTBOX
|| boxId == Sms.MESSAGE_TYPE_QUEUED)
return isOutgoingMms || isOutgoingSms
}
/**
* Returns the text that should be displayed in the messagelist view
* The returned text may be an empty string
*/
fun getText(): String {
return when {
isSms() -> body
else -> parts
.mapNotNull { it.text }
.joinToString("\n") { text -> text }
}
}
/**
* Returns the text that should be displayed when a preview of the message
* needs to be displayed, such as in the conversation view or in a notification
*
* TODO: Don't return a hardcoded string
*/
fun getSummary(): String {
return when {
isSms() -> body
else -> parts
.mapNotNull { it.text }
.joinToString("\n") { text -> text }
.takeIf { it.isNotEmpty() }
?: getCleansedSubject()
.takeIf { it.isNotEmpty() }
?: "An MMS message"
}
}
/**
* Cleanses the subject in case it's useless, so that the UI doesn't have to show it
*/
fun getCleansedSubject(): String {
val uselessSubjects = listOf("no subject")
return if (uselessSubjects.contains(subject)) "" else subject
}
fun isSending(): Boolean {
return !isFailedMessage() && isOutgoingMessage()
}
fun isDelivered(): Boolean {
val isDeliveredMms = false // TODO
val isDeliveredSms = deliveryStatus == Sms.STATUS_COMPLETE
return isDeliveredMms || isDeliveredSms
}
fun isFailedMessage(): Boolean {
val isFailedMms = isMms() && (errorType >= MmsSms.ERR_TYPE_GENERIC_PERMANENT || boxId == Mms.MESSAGE_BOX_FAILED)
val isFailedSms = isSms() && boxId == Sms.MESSAGE_TYPE_FAILED
return isFailedMms || isFailedSms
}
fun compareSender(other: Message): Boolean {
return isMe() && other.isMe() || (!isMe() && !other.isMe() && address == other.address)
}
}
+33
View File
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package model
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
open class MmsPart : RealmObject() {
@PrimaryKey var id: Long = 0
var messageId: Long = 0
var type: String = ""
var text: String? = null
var image: String? = null
}
+26
View File
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package model
import io.realm.RealmObject
open class PhoneNumber(
var address: String = "",
var type: String = ""
) : RealmObject()
+31
View File
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package model
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
open class Recipient : RealmObject() {
@PrimaryKey var id: Long = 0
var address: String = ""
var contact: Contact? = null
var lastUpdate: Long = 0
}
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package model
import io.realm.RealmObject
open class SyncLog : RealmObject() {
var date: Long = System.currentTimeMillis()
}
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package repository
import android.net.Uri
import io.reactivex.Flowable
import io.reactivex.Single
import model.Contact
interface ContactRepository {
fun findContactUri(address: String): Single<Uri>
fun getUnmanagedContacts(): Flowable<List<Contact>>
}
@@ -0,0 +1,110 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package repository
import io.reactivex.Flowable
import io.reactivex.Maybe
import io.reactivex.Observable
import io.realm.RealmResults
import model.Conversation
import model.Message
import model.MmsPart
interface MessageRepository {
fun getConversations(archived: Boolean = false): Flowable<List<Pair<Conversation, Message>>>
fun getBlockedConversations(): Flowable<List<Conversation>>
fun getConversationAsync(threadId: Long): Conversation
fun getConversation(threadId: Long): Conversation?
fun getOrCreateConversation(threadId: Long): Conversation?
fun getOrCreateConversation(address: String): Maybe<Conversation>
fun getOrCreateConversation(addresses: List<String>): Maybe<Conversation>
fun saveDraft(threadId: Long, draft: String)
fun getMessages(threadId: Long): RealmResults<Message>
fun getMessage(id: Long): Message?
fun getMessageForPart(id: Long): Message?
fun getUnreadMessageCount(): Long
fun getPart(id: Long): MmsPart?
fun getPartsForConversation(threadId: Long): Observable<List<MmsPart>>
/**
* Retrieves the list of messages which should be shown in the notification
* for a given conversation
*/
fun getUnreadUnseenMessages(threadId: Long): RealmResults<Message>
fun markArchived(threadId: Long)
fun markUnarchived(threadId: Long)
fun markBlocked(threadId: Long)
fun markUnblocked(threadId: Long)
fun markAllSeen()
fun markSeen(threadId: Long)
fun markRead(threadId: Long)
/**
* Persists the SMS and attempts to send it
*/
fun sendSmsAndPersist(threadId: Long, address: String, body: String)
/**
* Attempts to send the SMS message. This can be called if the message has already been persisted
*/
fun sendSms(message: Message)
fun insertSentSms(threadId: Long, address: String, body: String): Message
fun insertReceivedSms(address: String, body: String, sentTime: Long): Message
/**
* Marks the message as sending, in case we need to retry sending it
*/
fun markSending(id: Long)
fun markSent(id: Long)
fun markFailed(id: Long, resultCode: Int)
fun markDelivered(id: Long)
fun markDeliveryFailed(id: Long, resultCode: Int)
fun deleteMessage(messageId: Long)
fun deleteConversation(threadId: Long)
}
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package repository
import android.net.Uri
import io.reactivex.Flowable
import model.Message
interface SyncRepository {
fun syncMessages(fullSync: Boolean = false)
fun syncMessage(uri: Uri): Flowable<Message>
fun syncContacts()
}