forked from upstream-mirrors/quik
Merge branch 'master' of https://github.com/moezbhatti/qksms3
This commit is contained in:
@@ -30,6 +30,8 @@ class NotificationManager @Inject constructor(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
val DEFAULT_CHANNEL_ID = "channel_1"
|
||||||
|
|
||||||
val VIBRATE_PATTERN = longArrayOf(0, 200, 0, 200)
|
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) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
|
||||||
val id = "channel_1"
|
|
||||||
val name = "Message notifications"
|
val name = "Message notifications"
|
||||||
val importance = NotificationManager.IMPORTANCE_HIGH
|
val importance = NotificationManager.IMPORTANCE_HIGH
|
||||||
val channel = NotificationChannel(id, name, importance)
|
val channel = NotificationChannel(DEFAULT_CHANNEL_ID, name, importance).apply {
|
||||||
|
description = "Message notifications description"
|
||||||
channel.description = "Message notifications description"
|
enableLights(true)
|
||||||
channel.enableLights(true)
|
lightColor = Color.WHITE
|
||||||
channel.lightColor = Color.WHITE
|
enableVibration(true)
|
||||||
channel.enableVibration(true)
|
vibrationPattern = VIBRATE_PATTERN
|
||||||
channel.vibrationPattern = VIBRATE_PATTERN
|
}
|
||||||
|
|
||||||
notificationManager.createNotificationChannel(channel)
|
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.common.util.extensions.insertOrUpdate
|
||||||
import com.moez.QKSMS.data.mapper.CursorToConversation
|
import com.moez.QKSMS.data.mapper.CursorToConversation
|
||||||
import com.moez.QKSMS.data.mapper.CursorToMessage
|
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.Conversation
|
||||||
import com.moez.QKSMS.data.model.InboxItem
|
import com.moez.QKSMS.data.model.InboxItem
|
||||||
import com.moez.QKSMS.data.model.Message
|
import com.moez.QKSMS.data.model.Message
|
||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import io.reactivex.Maybe
|
import io.reactivex.Maybe
|
||||||
import io.reactivex.functions.BiFunction
|
import io.reactivex.functions.BiFunction
|
||||||
|
import io.reactivex.rxkotlin.toFlowable
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import io.realm.RealmResults
|
import io.realm.RealmResults
|
||||||
@@ -31,7 +33,8 @@ import javax.inject.Singleton
|
|||||||
class MessageRepository @Inject constructor(
|
class MessageRepository @Inject constructor(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val cursorToMessage: CursorToMessage,
|
private val cursorToMessage: CursorToMessage,
|
||||||
private val cursorToConversation: CursorToConversation) {
|
private val cursorToConversation: CursorToConversation,
|
||||||
|
private val cursorToRecipient: CursorToRecipient) {
|
||||||
|
|
||||||
fun getConversations(archived: Boolean = false): Flowable<List<InboxItem>> {
|
fun getConversations(archived: Boolean = false): Flowable<List<InboxItem>> {
|
||||||
val realm = Realm.getDefaultInstance()
|
val realm = Realm.getDefaultInstance()
|
||||||
@@ -72,11 +75,6 @@ class MessageRepository @Inject constructor(
|
|||||||
.findFirst()
|
.findFirst()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets an unmanaged conversation by the address
|
|
||||||
*/
|
|
||||||
fun getOrCreateConversation(address: String) = getOrCreateConversation(listOf(address))
|
|
||||||
|
|
||||||
fun getOrCreateConversation(addresses: List<String>): Maybe<Conversation> {
|
fun getOrCreateConversation(addresses: List<String>): Maybe<Conversation> {
|
||||||
return Maybe.just(addresses)
|
return Maybe.just(addresses)
|
||||||
.map { recipients ->
|
.map { recipients ->
|
||||||
@@ -257,7 +255,7 @@ class MessageRepository @Inject constructor(
|
|||||||
context.contentResolver.delete(uri, null, null)
|
context.contentResolver.delete(uri, null, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getConversationFromCp(threadId: Long): Conversation? {
|
private fun getConversationFromCp(threadId: Long): Conversation? {
|
||||||
var conversation: Conversation? = null
|
var conversation: Conversation? = null
|
||||||
|
|
||||||
val cursor = context.contentResolver.query(
|
val cursor = context.contentResolver.query(
|
||||||
@@ -270,6 +268,13 @@ class MessageRepository @Inject constructor(
|
|||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
conversation = cursorToConversation.map(cursor)
|
conversation = cursorToConversation.map(cursor)
|
||||||
conversation.insertOrUpdate()
|
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()
|
cursor.close()
|
||||||
@@ -290,7 +295,12 @@ class MessageRepository @Inject constructor(
|
|||||||
val columnsMap = CursorToMessage.MessageColumns(cursor)
|
val columnsMap = CursorToMessage.MessageColumns(cursor)
|
||||||
|
|
||||||
if (cursor.moveToFirst()) {
|
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()
|
cursor.close()
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package com.moez.QKSMS.presentation
|
package com.moez.QKSMS.presentation
|
||||||
|
|
||||||
|
import android.annotation.TargetApi
|
||||||
import android.arch.lifecycle.ViewModel
|
import android.arch.lifecycle.ViewModel
|
||||||
import android.arch.lifecycle.ViewModelProvider
|
import android.arch.lifecycle.ViewModelProvider
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
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.ComposeActivity
|
||||||
import com.moez.QKSMS.presentation.compose.ComposeViewModel
|
import com.moez.QKSMS.presentation.compose.ComposeViewModel
|
||||||
import com.moez.QKSMS.presentation.main.MainViewModel
|
import com.moez.QKSMS.presentation.main.MainViewModel
|
||||||
@@ -44,6 +48,14 @@ class Navigator @Inject constructor(val context: Context) {
|
|||||||
startActivity(intent)
|
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 {
|
class ViewModelFactory(private val intent: Intent) : ViewModelProvider.Factory {
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class PreferenceView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
init {
|
init {
|
||||||
View.inflate(context, R.layout.preference_view, this)
|
View.inflate(context, R.layout.preference_view, this)
|
||||||
setBackgroundResource(R.drawable.ripple)
|
setBackgroundResource(R.drawable.ripple)
|
||||||
|
orientation = VERTICAL
|
||||||
|
|
||||||
context.obtainStyledAttributes(attrs, R.styleable.PreferenceView)?.run {
|
context.obtainStyledAttributes(attrs, R.styleable.PreferenceView)?.run {
|
||||||
title = getString(R.styleable.PreferenceView_title)
|
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.Navigator
|
||||||
import com.moez.QKSMS.presentation.common.base.QkViewModel
|
import com.moez.QKSMS.presentation.common.base.QkViewModel
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
||||||
import io.reactivex.rxkotlin.Observables
|
import io.reactivex.rxkotlin.Observables
|
||||||
import io.reactivex.rxkotlin.plusAssign
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import io.reactivex.rxkotlin.withLatestFrom
|
import io.reactivex.rxkotlin.withLatestFrom
|
||||||
@@ -108,6 +107,8 @@ class ComposeViewModel(threadId: Long, body: String)
|
|||||||
.combineLatest(view.queryChangedIntent, selectedContacts, { query, selectedContacts ->
|
.combineLatest(view.queryChangedIntent, selectedContacts, { query, selectedContacts ->
|
||||||
selectedContacts.isEmpty() || query.isNotEmpty()
|
selectedContacts.isEmpty() || query.isNotEmpty()
|
||||||
})
|
})
|
||||||
|
.skipUntil(state.filter { state -> state.editingMode == true })
|
||||||
|
.takeUntil(state.filter { state -> state.editingMode == false })
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.subscribe { contactsVisible -> newState { it.copy(contactsVisible = contactsVisible && it.editingMode) } }
|
.subscribe { contactsVisible -> newState { it.copy(contactsVisible = contactsVisible && it.editingMode) } }
|
||||||
|
|
||||||
@@ -119,8 +120,9 @@ class ComposeViewModel(threadId: Long, body: String)
|
|||||||
.filterNot { contact -> selectedContacts.contains(contact) }
|
.filterNot { contact -> selectedContacts.contains(contact) }
|
||||||
.filter { contact -> contactFilter.filter(contact, query) }
|
.filter { contact -> contactFilter.filter(contact, query) }
|
||||||
})
|
})
|
||||||
|
.skipUntil(state.filter { state -> state.editingMode == true })
|
||||||
|
.takeUntil(state.filter { state -> state.editingMode == false })
|
||||||
.subscribeOn(Schedulers.computation())
|
.subscribeOn(Schedulers.computation())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe { contacts -> newState { it.copy(contacts = contacts) } }
|
.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
|
// 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 ->
|
view.chipSelectedIntent.doOnNext { contact ->
|
||||||
contactsReducer.onNext { contacts -> contacts.toMutableList().apply { add(contact) } }
|
contactsReducer.onNext { contacts -> contacts.toMutableList().apply { add(contact) } }
|
||||||
})
|
})
|
||||||
|
.skipUntil(state.filter { state -> state.editingMode == true })
|
||||||
|
.takeUntil(state.filter { state -> state.editingMode == false })
|
||||||
.subscribe()
|
.subscribe()
|
||||||
|
|
||||||
// When the menu is loaded, trigger a new state so that the menu options can be rendered correctly
|
// 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)
|
viewModel.bindView(this)
|
||||||
|
|
||||||
val supportsNotificationChannels = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
val supportsNotificationChannels = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||||
|
notificationsO.setVisible(supportsNotificationChannels)
|
||||||
|
notifications.setVisible(!supportsNotificationChannels)
|
||||||
vibration.setVisible(!supportsNotificationChannels)
|
vibration.setVisible(!supportsNotificationChannels)
|
||||||
ringtone.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.di.appComponent
|
||||||
import com.moez.QKSMS.common.util.Preferences
|
import com.moez.QKSMS.common.util.Preferences
|
||||||
import com.moez.QKSMS.domain.interactor.FullSync
|
import com.moez.QKSMS.domain.interactor.FullSync
|
||||||
|
import com.moez.QKSMS.presentation.Navigator
|
||||||
import com.moez.QKSMS.presentation.common.base.QkViewModel
|
import com.moez.QKSMS.presentation.common.base.QkViewModel
|
||||||
import io.reactivex.rxkotlin.plusAssign
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@@ -15,6 +16,7 @@ import javax.inject.Inject
|
|||||||
class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState()) {
|
class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState()) {
|
||||||
|
|
||||||
@Inject lateinit var context: Context
|
@Inject lateinit var context: Context
|
||||||
|
@Inject lateinit var navigator: Navigator
|
||||||
@Inject lateinit var prefs: Preferences
|
@Inject lateinit var prefs: Preferences
|
||||||
@Inject lateinit var fullSync: FullSync
|
@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.autoEmoji -> prefs.autoEmoji.set(!prefs.autoEmoji.get())
|
||||||
|
|
||||||
|
R.id.notificationsO -> navigator.showNotificationSettings()
|
||||||
|
|
||||||
R.id.notifications -> prefs.notifications.set(!prefs.notifications.get())
|
R.id.notifications -> prefs.notifications.set(!prefs.notifications.get())
|
||||||
|
|
||||||
R.id.vibration -> prefs.vibration.set(!prefs.vibration.get())
|
R.id.vibration -> prefs.vibration.set(!prefs.vibration.get())
|
||||||
|
|||||||
@@ -3,36 +3,49 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center_vertical"
|
android:orientation="vertical"
|
||||||
tools:parentTag="com.moez.QKSMS.presentation.common.widget.PreferenceView">
|
tools:parentTag="com.moez.QKSMS.presentation.common.widget.PreferenceView">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:baselineAligned="false"
|
||||||
android:orientation="vertical"
|
android:gravity="center_vertical"
|
||||||
android:padding="16dp">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<com.moez.QKSMS.presentation.common.widget.QkTextView
|
<LinearLayout
|
||||||
android:id="@+id/titleView"
|
android:layout_width="0dp"
|
||||||
style="@style/TextPrimary"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:text="Default SMS App" />
|
android:layout_weight="1"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
<com.moez.QKSMS.presentation.common.widget.QkTextView
|
<com.moez.QKSMS.presentation.common.widget.QkTextView
|
||||||
android:id="@+id/summaryView"
|
android:id="@+id/titleView"
|
||||||
style="@style/TextSecondary"
|
style="@style/TextPrimary"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:text="QKSMS is your default SMS app" />
|
tools:text="Default SMS App" />
|
||||||
|
|
||||||
|
<com.moez.QKSMS.presentation.common.widget.QkTextView
|
||||||
|
android:id="@+id/summaryView"
|
||||||
|
style="@style/TextSecondary"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:text="QKSMS is your default SMS app" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/widgetFrame"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginRight="16dp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<FrameLayout
|
<com.moez.QKSMS.presentation.common.widget.Separator
|
||||||
android:id="@+id/widgetFrame"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="1dp" />
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_marginRight="16dp" />
|
|
||||||
|
|
||||||
</merge>
|
</merge>
|
||||||
@@ -50,6 +50,12 @@
|
|||||||
app:title="@string/settings_auto_emoji_title"
|
app:title="@string/settings_auto_emoji_title"
|
||||||
app:widget="@layout/settings_switch_widget" />
|
app:widget="@layout/settings_switch_widget" />
|
||||||
|
|
||||||
|
<com.moez.QKSMS.presentation.common.widget.PreferenceView
|
||||||
|
android:id="@+id/notificationsO"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:title="@string/settings_notifications_title" />
|
||||||
|
|
||||||
<com.moez.QKSMS.presentation.common.widget.PreferenceView
|
<com.moez.QKSMS.presentation.common.widget.PreferenceView
|
||||||
android:id="@+id/notifications"
|
android:id="@+id/notifications"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
Reference in New Issue
Block a user