mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Merge branch 'master' of https://github.com/moezbhatti/qksms3
This commit is contained in:
@@ -30,6 +30,8 @@ class NotificationManager @Inject constructor(
|
||||
) {
|
||||
|
||||
companion object {
|
||||
val DEFAULT_CHANNEL_ID = "channel_1"
|
||||
|
||||
val VIBRATE_PATTERN = longArrayOf(0, 200, 0, 200)
|
||||
}
|
||||
|
||||
@@ -40,16 +42,15 @@ class NotificationManager @Inject constructor(
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
|
||||
val id = "channel_1"
|
||||
val name = "Message notifications"
|
||||
val importance = NotificationManager.IMPORTANCE_HIGH
|
||||
val channel = NotificationChannel(id, name, importance)
|
||||
|
||||
channel.description = "Message notifications description"
|
||||
channel.enableLights(true)
|
||||
channel.lightColor = Color.WHITE
|
||||
channel.enableVibration(true)
|
||||
channel.vibrationPattern = VIBRATE_PATTERN
|
||||
val channel = NotificationChannel(DEFAULT_CHANNEL_ID, name, importance).apply {
|
||||
description = "Message notifications description"
|
||||
enableLights(true)
|
||||
lightColor = Color.WHITE
|
||||
enableVibration(true)
|
||||
vibrationPattern = VIBRATE_PATTERN
|
||||
}
|
||||
|
||||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
|
||||
@@ -13,12 +13,14 @@ import com.moez.QKSMS.common.util.extensions.asMaybe
|
||||
import com.moez.QKSMS.common.util.extensions.insertOrUpdate
|
||||
import com.moez.QKSMS.data.mapper.CursorToConversation
|
||||
import com.moez.QKSMS.data.mapper.CursorToMessage
|
||||
import com.moez.QKSMS.data.mapper.CursorToRecipient
|
||||
import com.moez.QKSMS.data.model.Conversation
|
||||
import com.moez.QKSMS.data.model.InboxItem
|
||||
import com.moez.QKSMS.data.model.Message
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.Maybe
|
||||
import io.reactivex.functions.BiFunction
|
||||
import io.reactivex.rxkotlin.toFlowable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmResults
|
||||
@@ -31,7 +33,8 @@ import javax.inject.Singleton
|
||||
class MessageRepository @Inject constructor(
|
||||
private val context: Context,
|
||||
private val cursorToMessage: CursorToMessage,
|
||||
private val cursorToConversation: CursorToConversation) {
|
||||
private val cursorToConversation: CursorToConversation,
|
||||
private val cursorToRecipient: CursorToRecipient) {
|
||||
|
||||
fun getConversations(archived: Boolean = false): Flowable<List<InboxItem>> {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
@@ -72,11 +75,6 @@ class MessageRepository @Inject constructor(
|
||||
.findFirst()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an unmanaged conversation by the address
|
||||
*/
|
||||
fun getOrCreateConversation(address: String) = getOrCreateConversation(listOf(address))
|
||||
|
||||
fun getOrCreateConversation(addresses: List<String>): Maybe<Conversation> {
|
||||
return Maybe.just(addresses)
|
||||
.map { recipients ->
|
||||
@@ -257,7 +255,7 @@ class MessageRepository @Inject constructor(
|
||||
context.contentResolver.delete(uri, null, null)
|
||||
}
|
||||
|
||||
fun getConversationFromCp(threadId: Long): Conversation? {
|
||||
private fun getConversationFromCp(threadId: Long): Conversation? {
|
||||
var conversation: Conversation? = null
|
||||
|
||||
val cursor = context.contentResolver.query(
|
||||
@@ -270,6 +268,13 @@ class MessageRepository @Inject constructor(
|
||||
if (cursor.moveToFirst()) {
|
||||
conversation = cursorToConversation.map(cursor)
|
||||
conversation.insertOrUpdate()
|
||||
|
||||
conversation.recipients.toFlowable()
|
||||
.map { recipient -> recipient.id.toString() }
|
||||
.map { id -> context.contentResolver.query(CursorToRecipient.URI, null, "_id = ?", arrayOf(id), null) }
|
||||
.flatMap { recipientCursor -> recipientCursor.asFlowable().map { cursor -> cursorToRecipient.map(cursor) } }
|
||||
.doOnNext { recipient -> recipient.insertOrUpdate() }
|
||||
.blockingSubscribe()
|
||||
}
|
||||
|
||||
cursor.close()
|
||||
@@ -290,7 +295,12 @@ class MessageRepository @Inject constructor(
|
||||
val columnsMap = CursorToMessage.MessageColumns(cursor)
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
cursorToMessage.map(Pair(cursor, columnsMap)).insertOrUpdate()
|
||||
val message = cursorToMessage.map(Pair(cursor, columnsMap))
|
||||
|
||||
// If the conversation isn't in Realm, add it
|
||||
getConversation(message.threadId) ?: getConversationFromCp(message.threadId)
|
||||
|
||||
message.insertOrUpdate()
|
||||
}
|
||||
|
||||
cursor.close()
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package com.moez.QKSMS.presentation
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.arch.lifecycle.ViewModel
|
||||
import android.arch.lifecycle.ViewModelProvider
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import com.moez.QKSMS.common.util.NotificationManager
|
||||
import com.moez.QKSMS.presentation.compose.ComposeActivity
|
||||
import com.moez.QKSMS.presentation.compose.ComposeViewModel
|
||||
import com.moez.QKSMS.presentation.main.MainViewModel
|
||||
@@ -44,6 +48,14 @@ class Navigator @Inject constructor(val context: Context) {
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.O)
|
||||
fun showNotificationSettings() {
|
||||
val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, NotificationManager.DEFAULT_CHANNEL_ID)
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
class ViewModelFactory(private val intent: Intent) : ViewModelProvider.Factory {
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
||||
@@ -26,6 +26,7 @@ class PreferenceView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
init {
|
||||
View.inflate(context, R.layout.preference_view, this)
|
||||
setBackgroundResource(R.drawable.ripple)
|
||||
orientation = VERTICAL
|
||||
|
||||
context.obtainStyledAttributes(attrs, R.styleable.PreferenceView)?.run {
|
||||
title = getString(R.styleable.PreferenceView_title)
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.moez.QKSMS.domain.interactor.*
|
||||
import com.moez.QKSMS.presentation.Navigator
|
||||
import com.moez.QKSMS.presentation.common.base.QkViewModel
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
@@ -108,6 +107,8 @@ class ComposeViewModel(threadId: Long, body: String)
|
||||
.combineLatest(view.queryChangedIntent, selectedContacts, { query, selectedContacts ->
|
||||
selectedContacts.isEmpty() || query.isNotEmpty()
|
||||
})
|
||||
.skipUntil(state.filter { state -> state.editingMode == true })
|
||||
.takeUntil(state.filter { state -> state.editingMode == false })
|
||||
.distinctUntilChanged()
|
||||
.subscribe { contactsVisible -> newState { it.copy(contactsVisible = contactsVisible && it.editingMode) } }
|
||||
|
||||
@@ -119,8 +120,9 @@ class ComposeViewModel(threadId: Long, body: String)
|
||||
.filterNot { contact -> selectedContacts.contains(contact) }
|
||||
.filter { contact -> contactFilter.filter(contact, query) }
|
||||
})
|
||||
.skipUntil(state.filter { state -> state.editingMode == true })
|
||||
.takeUntil(state.filter { state -> state.editingMode == false })
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { contacts -> newState { it.copy(contacts = contacts) } }
|
||||
|
||||
// Update the list of selected contacts when a new contact is selected or an existing one is deselected
|
||||
@@ -131,6 +133,8 @@ class ComposeViewModel(threadId: Long, body: String)
|
||||
view.chipSelectedIntent.doOnNext { contact ->
|
||||
contactsReducer.onNext { contacts -> contacts.toMutableList().apply { add(contact) } }
|
||||
})
|
||||
.skipUntil(state.filter { state -> state.editingMode == true })
|
||||
.takeUntil(state.filter { state -> state.editingMode == false })
|
||||
.subscribe()
|
||||
|
||||
// When the menu is loaded, trigger a new state so that the menu options can be rendered correctly
|
||||
|
||||
@@ -72,6 +72,8 @@ class SettingsActivity : QkActivity<SettingsViewModel>(), SettingsView {
|
||||
viewModel.bindView(this)
|
||||
|
||||
val supportsNotificationChannels = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||
notificationsO.setVisible(supportsNotificationChannels)
|
||||
notifications.setVisible(!supportsNotificationChannels)
|
||||
vibration.setVisible(!supportsNotificationChannels)
|
||||
ringtone.setVisible(!supportsNotificationChannels)
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.di.appComponent
|
||||
import com.moez.QKSMS.common.util.Preferences
|
||||
import com.moez.QKSMS.domain.interactor.FullSync
|
||||
import com.moez.QKSMS.presentation.Navigator
|
||||
import com.moez.QKSMS.presentation.common.base.QkViewModel
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import timber.log.Timber
|
||||
@@ -15,6 +16,7 @@ import javax.inject.Inject
|
||||
class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState()) {
|
||||
|
||||
@Inject lateinit var context: Context
|
||||
@Inject lateinit var navigator: Navigator
|
||||
@Inject lateinit var prefs: Preferences
|
||||
@Inject lateinit var fullSync: FullSync
|
||||
|
||||
@@ -90,6 +92,8 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
||||
|
||||
R.id.autoEmoji -> prefs.autoEmoji.set(!prefs.autoEmoji.get())
|
||||
|
||||
R.id.notificationsO -> navigator.showNotificationSettings()
|
||||
|
||||
R.id.notifications -> prefs.notifications.set(!prefs.notifications.get())
|
||||
|
||||
R.id.vibration -> prefs.vibration.set(!prefs.vibration.get())
|
||||
|
||||
Reference in New Issue
Block a user