forked from upstream-mirrors/quik
@@ -260,27 +260,33 @@ class Navigator @Inject constructor(
|
||||
startActivityExternal(intent)
|
||||
}
|
||||
|
||||
fun viewFile(file: File) {
|
||||
val data = FileProvider.getUriForFile(context, "${context.packageName}.fileprovider", file)
|
||||
val type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(file.name.split(".").last())
|
||||
fun viewFile(uri: Uri, mimeType: String) {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
.setDataAndType(data, type)
|
||||
.setDataAndType(uri, mimeType.lowercase())
|
||||
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
.let { Intent.createChooser(it, null) }
|
||||
|
||||
startActivityExternal(intent)
|
||||
}
|
||||
|
||||
fun shareFile(file: File) {
|
||||
val data = FileProvider.getUriForFile(context, "${context.packageName}.fileprovider", file)
|
||||
val type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(file.name.split(".").last())
|
||||
fun shareFile(uri: Uri, mimeType: String) {
|
||||
val intent = Intent(Intent.ACTION_SEND)
|
||||
.setType(type)
|
||||
.putExtra(Intent.EXTRA_STREAM, data)
|
||||
.setType(mimeType.lowercase())
|
||||
.putExtra(Intent.EXTRA_STREAM, uri)
|
||||
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
.let { Intent.createChooser(it, null) }
|
||||
|
||||
startActivityExternal(intent)
|
||||
}
|
||||
|
||||
fun showPermissions() {
|
||||
val intent = Intent()
|
||||
intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
|
||||
intent.data = Uri.fromParts("package", context.packageName, null)
|
||||
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
fun showNotificationSettings(threadId: Long = 0) {
|
||||
val intent = Intent(context, NotificationPrefsActivity::class.java)
|
||||
intent.putExtra("threadId", threadId)
|
||||
@@ -301,4 +307,12 @@ class Navigator @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun showExactAlarmsSettings() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val intent = Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM)
|
||||
.setData(Uri.parse("package:${context.packageName}"))
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ import com.moez.QKSMS.util.GlideApp
|
||||
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import com.moez.QKSMS.util.tryOrNull
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@@ -94,6 +95,11 @@ class NotificationManagerImpl @Inject constructor(
|
||||
return
|
||||
}
|
||||
|
||||
if (!permissions.hasNotifications()) {
|
||||
Timber.w("Cannot update notification because we don't have the notification permission")
|
||||
return
|
||||
}
|
||||
|
||||
val messages = messageRepo.getUnreadUnseenMessages(threadId)
|
||||
|
||||
// If there are no messages to be displayed, make sure that the notification is dismissed
|
||||
@@ -114,11 +120,11 @@ class NotificationManagerImpl @Inject constructor(
|
||||
val taskStackBuilder = TaskStackBuilder.create(context)
|
||||
.addParentStack(ComposeActivity::class.java)
|
||||
.addNextIntent(contentIntent)
|
||||
val contentPI = taskStackBuilder.getPendingIntent(threadId.toInt(), PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val contentPI = taskStackBuilder.getPendingIntent(threadId.toInt(), PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
|
||||
val seenIntent = Intent(context, MarkSeenReceiver::class.java).putExtra("threadId", threadId)
|
||||
val seenPI = PendingIntent.getBroadcast(context, threadId.toInt(), seenIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
|
||||
// We can't store a null preference, so map it to a null Uri if the pref string is empty
|
||||
val ringtone = prefs.ringtone(threadId).get()
|
||||
@@ -233,7 +239,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
Preferences.NOTIFICATION_ACTION_ARCHIVE -> {
|
||||
val intent = Intent(context, MarkArchivedReceiver::class.java).putExtra("threadId", threadId)
|
||||
val pi = PendingIntent.getBroadcast(context, threadId.toInt(), intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
NotificationCompat.Action.Builder(R.drawable.ic_archive_white_24dp, actionLabels[action], pi)
|
||||
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_ARCHIVE).build()
|
||||
}
|
||||
@@ -244,7 +250,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
.putExtra("threadId", threadId)
|
||||
.putExtra("messageIds", messageIds)
|
||||
val pi = PendingIntent.getBroadcast(context, threadId.toInt(), intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
NotificationCompat.Action.Builder(R.drawable.ic_delete_white_24dp, actionLabels[action], pi)
|
||||
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_DELETE).build()
|
||||
}
|
||||
@@ -252,7 +258,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
Preferences.NOTIFICATION_ACTION_BLOCK -> {
|
||||
val intent = Intent(context, BlockThreadReceiver::class.java).putExtra("threadId", threadId)
|
||||
val pi = PendingIntent.getBroadcast(context, threadId.toInt(), intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
NotificationCompat.Action.Builder(R.drawable.ic_block_white_24dp, actionLabels[action], pi)
|
||||
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_MUTE).build()
|
||||
}
|
||||
@@ -260,7 +266,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
Preferences.NOTIFICATION_ACTION_READ -> {
|
||||
val intent = Intent(context, MarkReadReceiver::class.java).putExtra("threadId", threadId)
|
||||
val pi = PendingIntent.getBroadcast(context, threadId.toInt(), intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
NotificationCompat.Action.Builder(R.drawable.ic_check_white_24dp, actionLabels[action], pi)
|
||||
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_MARK_AS_READ).build()
|
||||
}
|
||||
@@ -271,7 +277,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
} else {
|
||||
val intent = Intent(context, QkReplyActivity::class.java).putExtra("threadId", threadId)
|
||||
val pi = PendingIntent.getActivity(context, threadId.toInt(), intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
NotificationCompat.Action
|
||||
.Builder(R.drawable.ic_reply_white_24dp, actionLabels[action], pi)
|
||||
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_REPLY).build()
|
||||
@@ -283,7 +289,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
val intentAction = if (permissions.hasCalling()) Intent.ACTION_CALL else Intent.ACTION_DIAL
|
||||
val intent = Intent(intentAction, Uri.parse("tel:$address"))
|
||||
val pi = PendingIntent.getActivity(context, threadId.toInt(), intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
NotificationCompat.Action.Builder(R.drawable.ic_call_white_24dp, actionLabels[action], pi)
|
||||
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_CALL).build()
|
||||
}
|
||||
@@ -337,7 +343,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
val taskStackBuilder = TaskStackBuilder.create(context)
|
||||
.addParentStack(ComposeActivity::class.java)
|
||||
.addNextIntent(contentIntent)
|
||||
val contentPI = taskStackBuilder.getPendingIntent(threadId.toInt(), PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val contentPI = taskStackBuilder.getPendingIntent(threadId.toInt(), PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
|
||||
val notification = NotificationCompat.Builder(context, getChannelIdForNotification(threadId))
|
||||
.setContentTitle(context.getString(R.string.notification_message_failed_title))
|
||||
@@ -357,7 +363,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
private fun getReplyAction(threadId: Long): NotificationCompat.Action {
|
||||
val replyIntent = Intent(context, RemoteMessagingReceiver::class.java).putExtra("threadId", threadId)
|
||||
val replyPI = PendingIntent.getBroadcast(context, threadId.toInt(), replyIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)
|
||||
|
||||
val title = context.resources.getStringArray(R.array.notification_actions)[
|
||||
Preferences.NOTIFICATION_ACTION_REPLY]
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.moez.QKSMS.common.util
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.DocumentsContract
|
||||
import androidx.activity.result.contract.ActivityResultContract
|
||||
|
||||
class QkActivityResultContracts {
|
||||
|
||||
data class OpenDocumentParams(
|
||||
val mimeTypes: List<String>,
|
||||
val initialUri: Uri? = null
|
||||
)
|
||||
|
||||
class OpenDocument : ActivityResultContract<OpenDocumentParams, Uri>() {
|
||||
override fun createIntent(context: Context, input: OpenDocumentParams): Intent {
|
||||
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
|
||||
.putExtra(Intent.EXTRA_MIME_TYPES, input.mimeTypes.toTypedArray())
|
||||
.setType("*/*")
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, input.initialUri)
|
||||
}
|
||||
|
||||
return intent
|
||||
}
|
||||
|
||||
override fun parseResult(resultCode: Int, intent: Intent?): Uri? {
|
||||
if (intent == null || resultCode != Activity.RESULT_OK) {
|
||||
return null
|
||||
}
|
||||
|
||||
return intent.data
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,7 +35,6 @@ import com.moez.QKSMS.util.GlideApp
|
||||
import com.moez.QKSMS.util.tryOrNull
|
||||
import javax.inject.Inject
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
class QkChooserTargetService : ChooserTargetService() {
|
||||
|
||||
@Inject lateinit var conversationRepo: ConversationRepository
|
||||
|
||||
+9
-1
@@ -32,4 +32,12 @@ fun AlertDialog.Builder.setNegativeButton(@StringRes textId: Int, subject: Subje
|
||||
|
||||
fun AlertDialog.Builder.setNeutralButton(@StringRes textId: Int, subject: Subject<Unit>): AlertDialog.Builder {
|
||||
return setNeutralButton(textId) { _, _ -> subject.onNext(Unit) }
|
||||
}
|
||||
}
|
||||
|
||||
fun AlertDialog.setShowing(show: Boolean) {
|
||||
if (isShowing && !show) {
|
||||
dismiss()
|
||||
} else if (!isShowing && show) {
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,9 +63,6 @@ fun ProgressBar.setTint(color: Int) {
|
||||
fun View.setBackgroundTint(color: Int) {
|
||||
|
||||
// API 21 doesn't support this
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
background?.setColorFilter(color, PorterDuff.Mode.SRC_IN)
|
||||
}
|
||||
|
||||
backgroundTintList = ColorStateList.valueOf(color)
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* 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 com.moez.QKSMS.feature.backup
|
||||
|
||||
import android.content.Context
|
||||
import android.text.format.Formatter
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.FlowableAdapter
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.DateFormatter
|
||||
import com.moez.QKSMS.model.BackupFile
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.backup_list_item.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class BackupAdapter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val dateFormatter: DateFormatter
|
||||
) : FlowableAdapter<BackupFile>() {
|
||||
|
||||
val backupSelected: Subject<BackupFile> = PublishSubject.create()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
val view = layoutInflater.inflate(R.layout.backup_list_item, parent, false)
|
||||
|
||||
return QkViewHolder(view).apply {
|
||||
view.setOnClickListener { backupSelected.onNext(getItem(adapterPosition)) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val backup = getItem(position)
|
||||
|
||||
val count = backup.messages
|
||||
|
||||
holder.title.text = dateFormatter.getDetailedTimestamp(backup.date)
|
||||
holder.messages.text = context.resources.getQuantityString(R.plurals.backup_message_count, count, count)
|
||||
holder.size.text = Formatter.formatFileSize(context, backup.size)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,78 +18,113 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.backup
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Typeface
|
||||
import android.net.Uri
|
||||
import android.view.View
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.view.children
|
||||
import androidx.core.view.isVisible
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkController
|
||||
import com.moez.QKSMS.common.util.DateFormatter
|
||||
import com.moez.QKSMS.common.util.QkActivityResultContracts
|
||||
import com.moez.QKSMS.common.util.extensions.getLabel
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setNegativeButton
|
||||
import com.moez.QKSMS.common.util.extensions.setPositiveButton
|
||||
import com.moez.QKSMS.common.util.extensions.setShowing
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.common.widget.PreferenceView
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.model.BackupFile
|
||||
import com.moez.QKSMS.repository.BackupRepository
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.backup_controller.*
|
||||
import kotlinx.android.synthetic.main.backup_list_dialog.view.*
|
||||
import kotlinx.android.synthetic.main.preference_view.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class BackupController : QkController<BackupView, BackupState, BackupPresenter>(), BackupView {
|
||||
|
||||
@Inject lateinit var adapter: BackupAdapter
|
||||
@Inject lateinit var dateFormatter: DateFormatter
|
||||
@Inject override lateinit var presenter: BackupPresenter
|
||||
|
||||
private val activityVisibleSubject: Subject<Unit> = PublishSubject.create()
|
||||
private val confirmRestoreSubject: Subject<Unit> = PublishSubject.create()
|
||||
private val stopRestoreSubject: Subject<Unit> = PublishSubject.create()
|
||||
private val selectFolderCancelSubject: Subject<Unit> = PublishSubject.create()
|
||||
private val selectFolderConfirmSubject: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
private val backupFilesDialog by lazy {
|
||||
val view = View.inflate(activity, R.layout.backup_list_dialog, null)
|
||||
.apply { files.adapter = adapter.apply { emptyView = empty } }
|
||||
private val restoreErrorConfirmSubject: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
AlertDialog.Builder(activity!!)
|
||||
.setView(view)
|
||||
.setCancelable(true)
|
||||
.create()
|
||||
}
|
||||
private val confirmRestoreCancelSubject: Subject<Unit> = PublishSubject.create()
|
||||
private val confirmRestoreConfirmSubject: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
private val confirmRestoreDialog by lazy {
|
||||
AlertDialog.Builder(activity!!)
|
||||
.setTitle(R.string.backup_restore_confirm_title)
|
||||
.setMessage(R.string.backup_restore_confirm_message)
|
||||
.setPositiveButton(R.string.backup_restore_title, confirmRestoreSubject)
|
||||
.setNegativeButton(R.string.button_cancel, null)
|
||||
.create()
|
||||
}
|
||||
private val stopRestoreConfirmSubject: Subject<Unit> = PublishSubject.create()
|
||||
private val stopRestoreCancelSubject: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
private val documentTreeSelectedSubject: Subject<Uri> = PublishSubject.create()
|
||||
private val documentSelectedSubject: Subject<Uri> = PublishSubject.create()
|
||||
|
||||
private val stopRestoreDialog by lazy {
|
||||
AlertDialog.Builder(activity!!)
|
||||
.setTitle(R.string.backup_restore_stop_title)
|
||||
.setMessage(R.string.backup_restore_stop_message)
|
||||
.setPositiveButton(R.string.button_stop, stopRestoreSubject)
|
||||
.setNegativeButton(R.string.button_cancel, null)
|
||||
.setPositiveButton(R.string.button_stop, stopRestoreConfirmSubject)
|
||||
.setNegativeButton(R.string.button_cancel, stopRestoreCancelSubject)
|
||||
.setCancelable(false)
|
||||
.create()
|
||||
}
|
||||
|
||||
private val selectLocationRationaleDialog by lazy {
|
||||
AlertDialog.Builder(activity!!)
|
||||
.setTitle(R.string.backup_select_location_rationale_title)
|
||||
.setMessage(R.string.backup_select_location_rationale_message)
|
||||
.setPositiveButton(R.string.button_continue, selectFolderConfirmSubject)
|
||||
.setNegativeButton(R.string.button_cancel, selectFolderCancelSubject)
|
||||
.setCancelable(false)
|
||||
.create()
|
||||
}
|
||||
|
||||
private val selectedBackupErrorDialog by lazy {
|
||||
AlertDialog.Builder(activity!!)
|
||||
.setTitle(R.string.backup_selected_backup_error_title)
|
||||
.setMessage(R.string.backup_selected_backup_error_message)
|
||||
.setPositiveButton(R.string.button_continue, restoreErrorConfirmSubject)
|
||||
.setCancelable(false)
|
||||
.create()
|
||||
}
|
||||
|
||||
private val selectedBackupDetailsDialog by lazy {
|
||||
AlertDialog.Builder(activity!!)
|
||||
.setTitle(R.string.backup_selected_backup_details_title)
|
||||
.setPositiveButton(R.string.backup_restore_title, confirmRestoreConfirmSubject)
|
||||
.setNegativeButton(R.string.button_cancel, confirmRestoreCancelSubject)
|
||||
.setCancelable(false)
|
||||
.create()
|
||||
}
|
||||
|
||||
private lateinit var openDirectory: ActivityResultLauncher<Uri>
|
||||
private lateinit var openDocument: ActivityResultLauncher<QkActivityResultContracts.OpenDocumentParams>
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
layoutRes = R.layout.backup_controller
|
||||
}
|
||||
|
||||
override fun onContextAvailable(context: Context) {
|
||||
// Init activity result contracts
|
||||
openDirectory = themedActivity!!
|
||||
.registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri ->
|
||||
uri?.let(documentTreeSelectedSubject::onNext)
|
||||
}
|
||||
|
||||
openDocument = themedActivity!!
|
||||
.registerForActivityResult(QkActivityResultContracts.OpenDocument()) { uri ->
|
||||
uri?.let(documentSelectedSubject::onNext)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttach(view: View) {
|
||||
super.onAttach(view)
|
||||
presenter.bindIntents(this)
|
||||
@@ -115,11 +150,6 @@ class BackupController : QkController<BackupView, BackupState, BackupPresenter>(
|
||||
.forEach { it.setTypeface(it.typeface, Typeface.BOLD) }
|
||||
}
|
||||
|
||||
override fun onActivityResumed(activity: Activity) {
|
||||
super.onActivityResumed(activity)
|
||||
activityVisibleSubject.onNext(Unit)
|
||||
}
|
||||
|
||||
override fun render(state: BackupState) {
|
||||
when {
|
||||
state.backupProgress.running -> {
|
||||
@@ -158,9 +188,14 @@ class BackupController : QkController<BackupView, BackupState, BackupPresenter>(
|
||||
}
|
||||
}
|
||||
|
||||
backup.summary = state.lastBackup
|
||||
selectLocationRationaleDialog.setShowing(state.showLocationRationale)
|
||||
|
||||
adapter.data = state.backups
|
||||
selectedBackupErrorDialog.setShowing(state.showSelectedBackupError)
|
||||
|
||||
selectedBackupDetailsDialog.setMessage(state.selectedBackupDetails)
|
||||
selectedBackupDetailsDialog.setShowing(state.selectedBackupDetails != null)
|
||||
|
||||
stopRestoreDialog.setShowing(state.showStopRestoreDialog)
|
||||
|
||||
fabIcon.setImageResource(when (state.upgraded) {
|
||||
true -> R.drawable.ic_file_upload_black_24dp
|
||||
@@ -173,29 +208,40 @@ class BackupController : QkController<BackupView, BackupState, BackupPresenter>(
|
||||
})
|
||||
}
|
||||
|
||||
override fun activityVisible(): Observable<*> = activityVisibleSubject
|
||||
override fun setBackupLocationClicks(): Observable<*> = location.clicks()
|
||||
|
||||
override fun restoreClicks(): Observable<*> = restore.clicks()
|
||||
|
||||
override fun restoreFileSelected(): Observable<BackupFile> = adapter.backupSelected
|
||||
.doOnNext { backupFilesDialog.dismiss() }
|
||||
override fun locationRationaleConfirmClicks(): Observable<*> = selectFolderConfirmSubject
|
||||
|
||||
override fun restoreConfirmed(): Observable<*> = confirmRestoreSubject
|
||||
override fun locationRationaleCancelClicks(): Observable<*> = selectFolderCancelSubject
|
||||
|
||||
override fun selectedBackupErrorClicks(): Observable<*> = restoreErrorConfirmSubject
|
||||
|
||||
override fun confirmRestoreBackupConfirmClicks(): Observable<*> = confirmRestoreConfirmSubject
|
||||
|
||||
override fun confirmRestoreBackupCancelClicks(): Observable<*> = confirmRestoreCancelSubject
|
||||
|
||||
override fun stopRestoreClicks(): Observable<*> = progressCancel.clicks()
|
||||
|
||||
override fun stopRestoreConfirmed(): Observable<*> = stopRestoreSubject
|
||||
override fun stopRestoreConfirmed(): Observable<*> = stopRestoreConfirmSubject
|
||||
|
||||
override fun fabClicks(): Observable<*> = fab.clicks()
|
||||
override fun stopRestoreCancel(): Observable<*> = stopRestoreCancelSubject
|
||||
|
||||
override fun requestStoragePermission() {
|
||||
ActivityCompat.requestPermissions(activity!!, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 0)
|
||||
override fun backupClicks(): Observable<*> = fab.clicks()
|
||||
|
||||
override fun documentTreeSelected(): Observable<Uri> = documentTreeSelectedSubject
|
||||
|
||||
override fun documentSelected(): Observable<Uri> = documentSelectedSubject
|
||||
|
||||
override fun selectFolder(initialUri: Uri) {
|
||||
openDirectory.launch(initialUri)
|
||||
}
|
||||
|
||||
override fun selectFile() = backupFilesDialog.show()
|
||||
override fun selectFile(initialUri: Uri) {
|
||||
openDocument.launch(QkActivityResultContracts.OpenDocumentParams(
|
||||
mimeTypes = listOf("application/json", "application/octet-stream"),
|
||||
initialUri = initialUri))
|
||||
}
|
||||
|
||||
override fun confirmRestore() = confirmRestoreDialog.show()
|
||||
|
||||
override fun stopRestore() = stopRestoreDialog.show()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package com.moez.QKSMS.feature.backup
|
||||
|
||||
import android.content.Context
|
||||
import androidx.core.net.toUri
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.base.QkPresenter
|
||||
@@ -26,14 +27,14 @@ import com.moez.QKSMS.common.util.DateFormatter
|
||||
import com.moez.QKSMS.common.util.extensions.makeToast
|
||||
import com.moez.QKSMS.interactor.PerformBackup
|
||||
import com.moez.QKSMS.manager.BillingManager
|
||||
import com.moez.QKSMS.manager.PermissionManager
|
||||
import com.moez.QKSMS.repository.BackupRepository
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import timber.log.Timber
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -43,12 +44,9 @@ class BackupPresenter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val dateFormatter: DateFormatter,
|
||||
private val navigator: Navigator,
|
||||
private val performBackup: PerformBackup,
|
||||
private val permissionManager: PermissionManager
|
||||
private val performBackup: PerformBackup
|
||||
) : QkPresenter<BackupView, BackupState>(BackupState()) {
|
||||
|
||||
private val storagePermissionSubject: Subject<Boolean> = BehaviorSubject.createDefault(permissionManager.hasStorage())
|
||||
|
||||
init {
|
||||
disposables += backupRepo.getBackupProgress()
|
||||
.sample(16, TimeUnit.MILLISECONDS)
|
||||
@@ -60,20 +58,6 @@ class BackupPresenter @Inject constructor(
|
||||
.distinctUntilChanged()
|
||||
.subscribe { progress -> newState { copy(restoreProgress = progress) } }
|
||||
|
||||
disposables += storagePermissionSubject
|
||||
.distinctUntilChanged()
|
||||
.switchMap { backupRepo.getBackups() }
|
||||
.doOnNext { backups -> newState { copy(backups = backups) } }
|
||||
.map { backups -> backups.map { it.date }.max() ?: 0L }
|
||||
.map { lastBackup ->
|
||||
when (lastBackup) {
|
||||
0L -> context.getString(R.string.backup_never)
|
||||
else -> dateFormatter.getDetailedTimestamp(lastBackup)
|
||||
}
|
||||
}
|
||||
.startWith(context.getString(R.string.backup_loading))
|
||||
.subscribe { lastBackup -> newState { copy(lastBackup = lastBackup) } }
|
||||
|
||||
disposables += billingManager.upgradeStatus
|
||||
.subscribe { upgraded -> newState { copy(upgraded = upgraded) } }
|
||||
}
|
||||
@@ -81,10 +65,10 @@ class BackupPresenter @Inject constructor(
|
||||
override fun bindIntents(view: BackupView) {
|
||||
super.bindIntents(view)
|
||||
|
||||
view.activityVisible()
|
||||
.map { permissionManager.hasStorage() }
|
||||
view.setBackupLocationClicks()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe(storagePermissionSubject)
|
||||
.subscribe { view.selectFolder(backupRepo.getBackupPathUriForPicker()) }
|
||||
|
||||
view.restoreClicks()
|
||||
.withLatestFrom(
|
||||
@@ -96,40 +80,80 @@ class BackupPresenter @Inject constructor(
|
||||
!upgraded -> context.makeToast(R.string.backup_restore_error_plus)
|
||||
backupProgress.running -> context.makeToast(R.string.backup_restore_error_backup)
|
||||
restoreProgress.running -> context.makeToast(R.string.backup_restore_error_restore)
|
||||
!permissionManager.hasStorage() -> view.requestStoragePermission()
|
||||
else -> view.selectFile()
|
||||
else -> view.selectFile(backupRepo.getBackupPathUriForPicker())
|
||||
}
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.restoreFileSelected()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.confirmRestore() }
|
||||
|
||||
view.restoreConfirmed()
|
||||
.withLatestFrom(view.restoreFileSelected()) { _, backup -> backup }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { backup -> RestoreBackupService.start(context, backup.path) }
|
||||
|
||||
view.stopRestoreClicks()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.stopRestore() }
|
||||
|
||||
view.stopRestoreConfirmed()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { backupRepo.stopRestore() }
|
||||
|
||||
view.fabClicks()
|
||||
view.backupClicks()
|
||||
.withLatestFrom(billingManager.upgradeStatus) { _, upgraded -> upgraded }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { upgraded ->
|
||||
when {
|
||||
backupRepo.getBackupDocumentTree() == null -> {
|
||||
newState { copy(showLocationRationale = true) }
|
||||
}
|
||||
!upgraded -> navigator.showQksmsPlusActivity("backup_fab")
|
||||
!permissionManager.hasStorage() -> view.requestStoragePermission()
|
||||
upgraded -> performBackup.execute(Unit)
|
||||
}
|
||||
}
|
||||
|
||||
view.locationRationaleConfirmClicks()
|
||||
.doOnNext { newState { copy(showLocationRationale = false) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.selectFolder(backupRepo.getBackupPathUriForPicker()) }
|
||||
|
||||
view.locationRationaleCancelClicks()
|
||||
.doOnNext { newState { copy(showLocationRationale = false) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.selectedBackupErrorClicks()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { copy(showSelectedBackupError = false) } }
|
||||
|
||||
view.confirmRestoreBackupConfirmClicks()
|
||||
.doOnNext { newState { copy(selectedBackupDetails = null) } }
|
||||
.withLatestFrom(view.documentSelected()) { _, backup -> backup }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { backup -> RestoreBackupService.start(context, backup) }
|
||||
|
||||
view.confirmRestoreBackupCancelClicks()
|
||||
.doOnNext { newState { copy(selectedBackupDetails = null) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.stopRestoreClicks()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { copy(showStopRestoreDialog = true) } }
|
||||
|
||||
view.stopRestoreConfirmed()
|
||||
.doOnNext { newState { copy(showStopRestoreDialog = false) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { backupRepo.stopRestore() }
|
||||
|
||||
view.stopRestoreCancel()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { copy(showStopRestoreDialog = false) } }
|
||||
|
||||
view.documentTreeSelected()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { uri -> backupRepo.persistBackupDirectory(uri) }
|
||||
|
||||
view.documentSelected()
|
||||
.observeOn(Schedulers.io())
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { uri ->
|
||||
try {
|
||||
val backupFile = backupRepo.parseBackup(uri)
|
||||
val date = dateFormatter.getDetailedTimestamp(backupFile.date)
|
||||
val details = context.getString(R.string.backup_details, date, backupFile.messages)
|
||||
newState { copy(selectedBackupDetails = details) }
|
||||
} catch (e: Exception) {
|
||||
newState { copy(showSelectedBackupError = true) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,13 +18,16 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.backup
|
||||
|
||||
import com.moez.QKSMS.model.BackupFile
|
||||
import com.moez.QKSMS.repository.BackupRepository
|
||||
|
||||
data class BackupState(
|
||||
val backupProgress: BackupRepository.Progress = BackupRepository.Progress.Idle(),
|
||||
val restoreProgress: BackupRepository.Progress = BackupRepository.Progress.Idle(),
|
||||
val lastBackup: String = "",
|
||||
val backups: List<BackupFile> = listOf(),
|
||||
|
||||
val showLocationRationale: Boolean = false,
|
||||
val showSelectedBackupError: Boolean = false,
|
||||
val selectedBackupDetails: String? = null,
|
||||
val showStopRestoreDialog: Boolean = false,
|
||||
|
||||
val upgraded: Boolean = false
|
||||
)
|
||||
)
|
||||
|
||||
@@ -18,23 +18,31 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.backup
|
||||
|
||||
import android.net.Uri
|
||||
import com.moez.QKSMS.common.base.QkViewContract
|
||||
import com.moez.QKSMS.model.BackupFile
|
||||
import io.reactivex.Observable
|
||||
|
||||
interface BackupView : QkViewContract<BackupState> {
|
||||
|
||||
fun activityVisible(): Observable<*>
|
||||
fun setBackupLocationClicks(): Observable<*>
|
||||
fun restoreClicks(): Observable<*>
|
||||
fun restoreFileSelected(): Observable<BackupFile>
|
||||
fun restoreConfirmed(): Observable<*>
|
||||
|
||||
fun backupClicks(): Observable<*>
|
||||
|
||||
fun locationRationaleConfirmClicks(): Observable<*>
|
||||
fun locationRationaleCancelClicks(): Observable<*>
|
||||
|
||||
fun selectedBackupErrorClicks(): Observable<*>
|
||||
|
||||
fun confirmRestoreBackupConfirmClicks(): Observable<*>
|
||||
fun confirmRestoreBackupCancelClicks(): Observable<*>
|
||||
|
||||
fun stopRestoreClicks(): Observable<*>
|
||||
fun stopRestoreConfirmed(): Observable<*>
|
||||
fun fabClicks(): Observable<*>
|
||||
fun stopRestoreCancel(): Observable<*>
|
||||
|
||||
fun requestStoragePermission()
|
||||
fun selectFile()
|
||||
fun confirmRestore()
|
||||
fun stopRestore()
|
||||
fun documentTreeSelected(): Observable<Uri>
|
||||
fun documentSelected(): Observable<Uri>
|
||||
|
||||
}
|
||||
fun selectFolder(initialUri: Uri)
|
||||
fun selectFile(initialUri: Uri)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.annotation.SuppressLint
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.IBinder
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
@@ -43,12 +44,12 @@ class RestoreBackupService : Service() {
|
||||
|
||||
private const val ACTION_START = "com.moez.QKSMS.ACTION_START"
|
||||
private const val ACTION_STOP = "com.moez.QKSMS.ACTION_STOP"
|
||||
private const val EXTRA_FILE_PATH = "com.moez.QKSMS.EXTRA_FILE_PATH"
|
||||
private const val EXTRA_FILE_URI = "com.moez.QKSMS.EXTRA_FILE_URI"
|
||||
|
||||
fun start(context: Context, filePath: String) {
|
||||
fun start(context: Context, backupFile: Uri) {
|
||||
val intent = Intent(context, RestoreBackupService::class.java)
|
||||
.setAction(ACTION_START)
|
||||
.putExtra(EXTRA_FILE_PATH, filePath)
|
||||
.putExtra(EXTRA_FILE_URI, backupFile.toString())
|
||||
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
@@ -100,7 +101,7 @@ class RestoreBackupService : Service() {
|
||||
|
||||
// Start the restore
|
||||
Observable.just(intent)
|
||||
.map { it.getStringExtra(EXTRA_FILE_PATH) }
|
||||
.map { Uri.parse(it.getStringExtra(EXTRA_FILE_URI)) }
|
||||
.map(backupRepo::performRestore)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe({}, Timber::w)
|
||||
|
||||
@@ -156,11 +156,6 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
.subscribe()
|
||||
|
||||
window.callback = ComposeWindowCallback(window.callback, this)
|
||||
|
||||
// These theme attributes don't apply themselves on API 21
|
||||
if (Build.VERSION.SDK_INT <= 22) {
|
||||
messageBackground.setBackgroundTint(resolveThemeColor(R.attr.bubbleColor))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
@@ -403,8 +398,8 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
super.onSaveInstanceState(outState)
|
||||
}
|
||||
|
||||
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
|
||||
cameraDestination = savedInstanceState?.getParcelable(CameraDestinationKey)
|
||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||
cameraDestination = savedInstanceState.getParcelable(CameraDestinationKey)
|
||||
super.onRestoreInstanceState(savedInstanceState)
|
||||
}
|
||||
|
||||
|
||||
@@ -433,7 +433,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { part ->
|
||||
if (permissionManager.hasStorage()) {
|
||||
messageRepo.savePart(part.id)?.let(navigator::viewFile)
|
||||
messageRepo.savePart(part.id)?.let { navigator.viewFile(it, part.type) }
|
||||
} else {
|
||||
view.requestStoragePermission()
|
||||
}
|
||||
@@ -634,23 +634,36 @@ class ComposeViewModel @Inject constructor(
|
||||
|
||||
// Send a message when the send button is clicked, and disable editing mode if it's enabled
|
||||
view.sendIntent
|
||||
.filter { permissionManager.isDefaultSms().also { if (!it) view.requestDefaultSms() } }
|
||||
.filter { permissionManager.hasSendSms().also { if (!it) view.requestSmsPermission() } }
|
||||
.withLatestFrom(view.textChangedIntent) { _, body -> body }
|
||||
.map { body -> body.toString() }
|
||||
.withLatestFrom(view.textChangedIntent) { _, body -> body.toString() }
|
||||
.withLatestFrom(state, attachments, conversation, selectedChips) { body, state, attachments,
|
||||
conversation, chips ->
|
||||
val subId = state.subscription?.subscriptionId ?: -1
|
||||
val addresses = when (conversation.recipients.isNotEmpty()) {
|
||||
true -> conversation.recipients.map { it.address }
|
||||
false -> chips.map { chip -> chip.address }
|
||||
if (!permissionManager.isDefaultSms()) {
|
||||
view.requestDefaultSms()
|
||||
return@withLatestFrom
|
||||
}
|
||||
|
||||
if (!permissionManager.hasSendSms()) {
|
||||
view.requestSmsPermission()
|
||||
return@withLatestFrom
|
||||
}
|
||||
|
||||
val delay = when (prefs.sendDelay.get()) {
|
||||
Preferences.SEND_DELAY_SHORT -> 3000
|
||||
Preferences.SEND_DELAY_MEDIUM -> 5000
|
||||
Preferences.SEND_DELAY_LONG -> 10000
|
||||
else -> 0
|
||||
}
|
||||
|
||||
if ((delay != 0 || state.scheduled != 0L) && !permissionManager.hasExactAlarms()) {
|
||||
navigator.showExactAlarmsSettings()
|
||||
return@withLatestFrom
|
||||
}
|
||||
|
||||
val subId = state.subscription?.subscriptionId ?: -1
|
||||
val addresses = when (conversation.recipients.isNotEmpty()) {
|
||||
true -> conversation.recipients.map { it.address }
|
||||
false -> chips.map { chip -> chip.address }
|
||||
}
|
||||
val sendAsGroup = !state.editingMode || state.sendAsGroup
|
||||
|
||||
when {
|
||||
|
||||
@@ -83,7 +83,7 @@ class ComposeWindowCallback(
|
||||
return localCallback.onCreatePanelMenu(i, menu)
|
||||
}
|
||||
|
||||
override fun onPreparePanel(i: Int, view: View, menu: Menu): Boolean {
|
||||
override fun onPreparePanel(i: Int, view: View?, menu: Menu): Boolean {
|
||||
return localCallback.onPreparePanel(i, view, menu)
|
||||
}
|
||||
|
||||
@@ -123,7 +123,6 @@ class ComposeWindowCallback(
|
||||
return localCallback.onSearchRequested()
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
override fun onSearchRequested(searchEvent: SearchEvent): Boolean {
|
||||
return localCallback.onSearchRequested(searchEvent)
|
||||
}
|
||||
@@ -132,7 +131,6 @@ class ComposeWindowCallback(
|
||||
return localCallback.onWindowStartingActionMode(callback)
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
override fun onWindowStartingActionMode(callback: ActionMode.Callback, i: Int): ActionMode? {
|
||||
return localCallback.onWindowStartingActionMode(callback, i)
|
||||
}
|
||||
|
||||
@@ -152,9 +152,7 @@ class MessagesAdapter @Inject constructor(
|
||||
view = layoutInflater.inflate(R.layout.message_list_item_in, parent, false)
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
view.body.hyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE
|
||||
}
|
||||
view.body.hyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE
|
||||
|
||||
val partsAdapter = partsAdapterProvider.get()
|
||||
partsAdapter.clicks.subscribe(partClicks)
|
||||
|
||||
@@ -44,11 +44,6 @@ class ChipsAdapter @Inject constructor() : QkAdapter<Recipient>() {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val view = inflater.inflate(R.layout.contact_chip, parent, false)
|
||||
return QkViewHolder(view).apply {
|
||||
// These theme attributes don't apply themselves on API 21
|
||||
if (Build.VERSION.SDK_INT <= 22) {
|
||||
content.setBackgroundTint(view.context.resolveThemeColor(R.attr.bubbleColor))
|
||||
}
|
||||
|
||||
view.setOnClickListener {
|
||||
val chip = getItem(adapterPosition)
|
||||
showDetailedChip(view.context, chip)
|
||||
|
||||
@@ -88,11 +88,6 @@ class ContactsActivity : QkThemedActivity(), ContactsContract {
|
||||
viewModel.bindView(this)
|
||||
|
||||
contacts.adapter = contactsAdapter
|
||||
|
||||
// These theme attributes don't apply themselves on API 21
|
||||
if (Build.VERSION.SDK_INT <= 22) {
|
||||
search.setBackgroundTint(resolveThemeColor(R.attr.bubbleColor))
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(state: ContactsState) {
|
||||
|
||||
@@ -81,9 +81,11 @@ class GalleryViewModel @Inject constructor(
|
||||
view.optionsItemSelected()
|
||||
.filter { itemId -> itemId == R.id.share }
|
||||
.filter { permissions.hasStorage().also { if (!it) view.requestStoragePermission() } }
|
||||
.withLatestFrom(view.pageChanged()) { _, part -> part.id }
|
||||
.withLatestFrom(view.pageChanged()) { _, part -> part }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { partId -> messageRepo.savePart(partId)?.let(navigator::shareFile) }
|
||||
.subscribe { part ->
|
||||
messageRepo.savePart(part.id)?.let { navigator.shareFile(it, part.type) }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -185,11 +185,6 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
// Set the FAB compose icon color
|
||||
compose.setTint(theme.textPrimary)
|
||||
}
|
||||
|
||||
// These theme attributes don't apply themselves on API 21
|
||||
if (Build.VERSION.SDK_INT <= 22) {
|
||||
toolbarSearch.setBackgroundTint(resolveThemeColor(R.attr.bubbleColor))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
@@ -294,7 +289,7 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
when (state.syncing) {
|
||||
is SyncRepository.SyncProgress.Idle -> {
|
||||
syncing.isVisible = false
|
||||
snackbar.isVisible = !state.defaultSms || !state.smsPermission || !state.contactPermission
|
||||
snackbar.isVisible = !state.defaultSms || !state.smsPermission || !state.contactPermission || !state.notificationPermission
|
||||
}
|
||||
|
||||
is SyncRepository.SyncProgress.Running -> {
|
||||
@@ -324,6 +319,12 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
snackbarMessage?.setText(R.string.main_permission_contacts)
|
||||
snackbarButton?.setText(R.string.main_permission_allow)
|
||||
}
|
||||
|
||||
!state.notificationPermission -> {
|
||||
snackbarTitle?.setText(R.string.main_permission_required)
|
||||
snackbarMessage?.setText(R.string.main_permission_notifications)
|
||||
snackbarButton?.setText(R.string.main_permission_allow)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,10 +356,17 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
}
|
||||
|
||||
override fun requestPermissions() {
|
||||
ActivityCompat.requestPermissions(this, arrayOf(
|
||||
Manifest.permission.READ_SMS,
|
||||
Manifest.permission.SEND_SMS,
|
||||
Manifest.permission.READ_CONTACTS), 0)
|
||||
val permissions = mutableListOf(
|
||||
Manifest.permission.READ_SMS,
|
||||
Manifest.permission.SEND_SMS,
|
||||
Manifest.permission.READ_CONTACTS
|
||||
)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
permissions += Manifest.permission.POST_NOTIFICATIONS
|
||||
}
|
||||
|
||||
ActivityCompat.requestPermissions(this, permissions.toTypedArray(), 0)
|
||||
}
|
||||
|
||||
override fun clearSearch() {
|
||||
|
||||
@@ -32,7 +32,8 @@ data class MainState(
|
||||
val syncing: SyncRepository.SyncProgress = SyncRepository.SyncProgress.Idle,
|
||||
val defaultSms: Boolean = true,
|
||||
val smsPermission: Boolean = true,
|
||||
val contactPermission: Boolean = true
|
||||
val contactPermission: Boolean = true,
|
||||
val notificationPermission: Boolean = true,
|
||||
)
|
||||
|
||||
sealed class MainPage
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.main
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.provider.Settings
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
@@ -135,28 +138,56 @@ class MainViewModel @Inject constructor(
|
||||
!permissionManager.hasReadSms() || !permissionManager.hasContacts() -> view.requestPermissions()
|
||||
}
|
||||
|
||||
val permissions = view.activityResumedIntent
|
||||
.filter { resumed -> resumed }
|
||||
.observeOn(Schedulers.io())
|
||||
.map { Triple(permissionManager.isDefaultSms(), permissionManager.hasReadSms(), permissionManager.hasContacts()) }
|
||||
.distinctUntilChanged()
|
||||
.share()
|
||||
// If the default SMS state changes, reflect it in the State
|
||||
view.activityResumedIntent
|
||||
.filter { resumed -> resumed }
|
||||
.observeOn(Schedulers.io())
|
||||
.map { permissionManager.isDefaultSms() }
|
||||
.distinctUntilChanged()
|
||||
.doOnNext { defaultSms -> newState { copy(defaultSms = defaultSms) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// If the default SMS state or permission states change, update the ViewState
|
||||
permissions
|
||||
.doOnNext { (defaultSms, smsPermission, contactPermission) ->
|
||||
newState { copy(defaultSms = defaultSms, smsPermission = smsPermission, contactPermission = contactPermission) }
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
// If the SMS Permission state changes, reflect it in the State
|
||||
view.activityResumedIntent
|
||||
.filter { resumed -> resumed }
|
||||
.observeOn(Schedulers.io())
|
||||
.map { permissionManager.hasReadSms() }
|
||||
.distinctUntilChanged()
|
||||
.doOnNext { smsPermission -> newState { copy(smsPermission = smsPermission) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// If we go from not having all permissions to having them, sync messages
|
||||
permissions
|
||||
.skip(1)
|
||||
.filter { it.first && it.second && it.third }
|
||||
.take(1)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { syncMessages.execute(Unit) }
|
||||
// If the Contacts Permission state changes, reflect it in the State
|
||||
view.activityResumedIntent
|
||||
.filter { resumed -> resumed }
|
||||
.observeOn(Schedulers.io())
|
||||
.map { permissionManager.hasContacts() }
|
||||
.distinctUntilChanged()
|
||||
.doOnNext { contactPermission -> newState { copy(contactPermission = contactPermission) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// If the Notifications Permission state changes, reflect it in the State
|
||||
view.activityResumedIntent
|
||||
.filter { resumed -> resumed }
|
||||
.observeOn(Schedulers.io())
|
||||
.map { permissionManager.hasNotifications() }
|
||||
.distinctUntilChanged()
|
||||
.doOnNext { notificationPermission -> newState { copy(notificationPermission = notificationPermission) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// If we go from not having all SMS permissions to having them, sync messages
|
||||
view.activityResumedIntent
|
||||
.filter { resumed -> resumed }
|
||||
.observeOn(Schedulers.io())
|
||||
.map { permissionManager.isDefaultSms() && permissionManager.hasReadSms() && permissionManager.hasContacts() }
|
||||
.distinctUntilChanged()
|
||||
.skip(1)
|
||||
.filter { hasAllPermissions -> hasAllPermissions }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { syncMessages.execute(Unit) }
|
||||
|
||||
// Launch screen from intent
|
||||
view.onNewIntentIntent
|
||||
@@ -408,6 +439,8 @@ class MainViewModel @Inject constructor(
|
||||
val page = state.page.copy(addContact = add, markPinned = pin, markRead = read, selected = selected)
|
||||
newState { copy(page = page) }
|
||||
}
|
||||
|
||||
is Searching -> {} // Ignore
|
||||
}
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
@@ -446,6 +479,14 @@ class MainViewModel @Inject constructor(
|
||||
!state.defaultSms -> view.requestDefaultSms()
|
||||
!state.smsPermission -> view.requestPermissions()
|
||||
!state.contactPermission -> view.requestPermissions()
|
||||
!state.notificationPermission -> {
|
||||
if (prefs.hasAskedForNotificationPermission.get()) {
|
||||
navigator.showPermissions()
|
||||
} else {
|
||||
prefs.hasAskedForNotificationPermission.set(true)
|
||||
view.requestPermissions()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ import javax.inject.Inject
|
||||
class UpgradeButtonExperiment @Inject constructor(
|
||||
context: Context,
|
||||
analytics: AnalyticsManager
|
||||
) : Experiment<@StringRes Int>(context, analytics) {
|
||||
) : Experiment<Int>(context, analytics) {
|
||||
|
||||
override val key: String = "Upgrade Button"
|
||||
|
||||
|
||||
@@ -74,15 +74,6 @@ class QkReplyActivity : QkThemedActivity(), QkReplyView {
|
||||
messages.adapter?.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||
override fun onChanged() = messages.scrollToPosition(adapter.itemCount - 1)
|
||||
})
|
||||
|
||||
// These theme attributes don't apply themselves on API 21
|
||||
if (Build.VERSION.SDK_INT <= 22) {
|
||||
toolbar.setBackgroundTint(resolveThemeColor(R.attr.colorPrimary))
|
||||
background.setBackgroundTint(resolveThemeColor(android.R.attr.windowBackground))
|
||||
messageBackground.setBackgroundTint(resolveThemeColor(R.attr.bubbleColor))
|
||||
composeBackgroundGradient.setBackgroundTint(resolveThemeColor(android.R.attr.windowBackground))
|
||||
composeBackgroundSolid.setBackgroundTint(resolveThemeColor(android.R.attr.windowBackground))
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(state: QkReplyState) {
|
||||
|
||||
@@ -140,17 +140,17 @@ class WidgetProvider : AppWidgetProvider() {
|
||||
|
||||
// Main intent
|
||||
val mainIntent = Intent(context, MainActivity::class.java)
|
||||
val mainPI = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val mainPI = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
remoteViews.setOnClickPendingIntent(R.id.title, mainPI)
|
||||
|
||||
// Compose intent
|
||||
val composeIntent = Intent(context, ComposeActivity::class.java)
|
||||
val composePI = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val composePI = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
remoteViews.setOnClickPendingIntent(R.id.compose, composePI)
|
||||
|
||||
// Conversation intent
|
||||
val startActivityIntent = Intent(context, MainActivity::class.java)
|
||||
val startActivityPendingIntent = PendingIntent.getActivity(context, 0, startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val startActivityPendingIntent = PendingIntent.getActivity(context, 0, startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
remoteViews.setPendingIntentTemplate(R.id.conversations, startActivityPendingIntent)
|
||||
|
||||
AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews)
|
||||
|
||||
Reference in New Issue
Block a user