Move packages to com.moez.QKSMS

This commit is contained in:
Moez Bhatti
2018-06-20 14:29:07 -04:00
parent d8141737b3
commit a5f518042e
268 changed files with 1101 additions and 1116 deletions
@@ -0,0 +1,119 @@
/*
* 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.notificationprefs
import android.app.Activity
import android.arch.lifecycle.ViewModelProvider
import android.arch.lifecycle.ViewModelProviders
import android.content.Intent
import android.media.RingtoneManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import com.jakewharton.rxbinding2.view.clicks
import com.moez.QKSMS.R
import com.moez.QKSMS.common.QkDialog
import com.moez.QKSMS.common.base.QkThemedActivity
import com.moez.QKSMS.common.util.extensions.animateLayoutChanges
import com.moez.QKSMS.common.util.extensions.setVisible
import com.moez.QKSMS.common.widget.PreferenceView
import dagger.android.AndroidInjection
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.notification_prefs_activity.*
import kotlinx.android.synthetic.main.settings_switch_widget.view.*
import javax.inject.Inject
class NotificationPrefsActivity : QkThemedActivity(), NotificationPrefsView {
@Inject lateinit var previewModeDialog: QkDialog
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
override val preferenceClickIntent: Subject<PreferenceView> = PublishSubject.create()
override val previewModeSelectedIntent by lazy { previewModeDialog.adapter.menuItemClicks }
override val ringtoneSelectedIntent: Subject<String> = PublishSubject.create()
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[NotificationPrefsViewModel::class.java] }
override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.notification_prefs_activity)
setTitle(R.string.title_notification_prefs)
showBackButton(true)
viewModel.bindView(this)
preferences.postDelayed({ preferences.animateLayoutChanges = true }, 100)
val hasOreo = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
notificationsO.setVisible(hasOreo)
notifications.setVisible(!hasOreo)
vibration.setVisible(!hasOreo)
ringtone.setVisible(!hasOreo)
previewModeDialog.setTitle(R.string.settings_notification_previews_title)
previewModeDialog.adapter.setData(R.array.notification_preview_options)
// Listen to clicks for all of the preferences
(0 until preferences.childCount)
.map { index -> preferences.getChildAt(index) }
.filter { view -> view is PreferenceView }
.forEach { preference ->
preference.clicks().subscribe {
preferenceClickIntent.onNext(preference as PreferenceView)
}
}
}
override fun render(state: NotificationPrefsState) {
if (state.conversationTitle.isNotEmpty()) {
title = state.conversationTitle
}
notifications.checkbox.isChecked = state.notificationsEnabled
notificationPreviews.summary = state.previewSummary
previewModeDialog.adapter.selectedItem = state.previewId
vibration.checkbox.isChecked = state.vibrationEnabled
ringtone.summary = state.ringtoneName
qkreply.checkbox.isChecked = state.qkReplyEnabled
qkreplyTapDismiss.setVisible(state.qkReplyEnabled)
qkreplyTapDismiss.checkbox.isChecked = state.qkReplyTapDismiss
}
override fun showPreviewModeDialog() = previewModeDialog.show(this)
override fun showRingtonePicker(default: Uri?) {
val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER)
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true)
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true)
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, default)
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION)
startActivityForResult(intent, 123)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == 123 && resultCode == Activity.RESULT_OK) {
val uri: Uri? = data?.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)
ringtoneSelectedIntent.onNext(uri?.toString() ?: "")
}
}
}
@@ -0,0 +1,21 @@
package com.moez.QKSMS.feature.notificationprefs
import android.arch.lifecycle.ViewModel
import android.content.Intent
import com.moez.QKSMS.injection.ViewModelKey
import dagger.Module
import dagger.Provides
import dagger.multibindings.IntoMap
@Module
class NotificationPrefsActivityModule {
@Provides
fun provideIntent(activity: NotificationPrefsActivity): Intent = activity.intent
@Provides
@IntoMap
@ViewModelKey(NotificationPrefsViewModel::class)
fun provideNotificationPrefsViewModel(viewModel: NotificationPrefsViewModel): ViewModel = viewModel
}
@@ -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 com.moez.QKSMS.feature.notificationprefs
import android.os.Build
import com.moez.QKSMS.util.Preferences
data class NotificationPrefsState(
val conversationTitle: String = "",
val notificationsEnabled: Boolean = true,
val previewSummary: String = "",
val previewId: Int = Preferences.NOTIFICATION_PREVIEWS_ALL,
val vibrationEnabled: Boolean = true,
val ringtoneName: String = "",
val qkReplyEnabled: Boolean = Build.VERSION.SDK_INT < Build.VERSION_CODES.N,
val qkReplyTapDismiss: Boolean = true)
@@ -0,0 +1,35 @@
/*
* 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.notificationprefs
import android.net.Uri
import com.moez.QKSMS.common.base.QkView
import com.moez.QKSMS.common.widget.PreferenceView
import io.reactivex.Observable
import io.reactivex.subjects.Subject
interface NotificationPrefsView : QkView<NotificationPrefsState> {
val preferenceClickIntent: Subject<PreferenceView>
val previewModeSelectedIntent: Subject<Int>
val ringtoneSelectedIntent: Observable<String>
fun showPreviewModeDialog()
fun showRingtonePicker(default: Uri?)
}
@@ -0,0 +1,125 @@
/*
* 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.notificationprefs
import android.content.Context
import android.content.Intent
import android.media.RingtoneManager
import android.net.Uri
import com.f2prateek.rx.preferences2.Preference
import com.moez.QKSMS.R
import com.moez.QKSMS.common.Navigator
import com.moez.QKSMS.common.base.QkViewModel
import com.moez.QKSMS.extensions.mapNotNull
import com.moez.QKSMS.repository.ConversationRepository
import com.moez.QKSMS.util.Preferences
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.kotlin.autoDisposable
import io.reactivex.Flowable
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
class NotificationPrefsViewModel @Inject constructor(
private val intent: Intent,
private val context: Context,
private val conversationRepo: ConversationRepository,
private val navigator: Navigator,
private val prefs: Preferences
) : QkViewModel<NotificationPrefsView, NotificationPrefsState>(NotificationPrefsState()) {
private val threadId = intent.extras?.getLong("threadId") ?: 0L
private val notifications: Preference<Boolean>
private val previews: Preference<Int>
private val vibration: Preference<Boolean>
private val ringtone: Preference<String>
init {
notifications = prefs.notifications(threadId)
previews = prefs.notificationPreviews(threadId)
vibration = prefs.vibration(threadId)
ringtone = prefs.ringtone(threadId)
disposables += Flowable.just(threadId)
.mapNotNull { threadId -> conversationRepo.getConversation(threadId) }
.map { conversation -> conversation.getTitle() }
.subscribeOn(Schedulers.io())
.subscribe { title -> newState { copy(conversationTitle = title) } }
disposables += notifications.asObservable()
.subscribe { enabled -> newState { copy(notificationsEnabled = enabled) } }
val previewLabels = context.resources.getStringArray(R.array.notification_preview_options)
disposables += previews.asObservable()
.subscribe { previewId ->
newState { copy(previewSummary = previewLabels[previewId], previewId = previewId) }
}
disposables += vibration.asObservable()
.subscribe { enabled -> newState { copy(vibrationEnabled = enabled) } }
disposables += ringtone.asObservable()
.map { uriString ->
uriString.takeIf { it.isNotEmpty() }
?.let(Uri::parse)
?.let { uri -> RingtoneManager.getRingtone(context, uri) }?.getTitle(context)
?: context.getString(R.string.settings_ringtone_none)
}
.subscribe { title -> newState { copy(ringtoneName = title) } }
disposables += prefs.qkreply.asObservable()
.subscribe { enabled -> newState { copy(qkReplyEnabled = enabled) } }
disposables += prefs.qkreplyTapDismiss.asObservable()
.subscribe { enabled -> newState { copy(qkReplyTapDismiss = enabled) } }
}
override fun bindView(view: NotificationPrefsView) {
super.bindView(view)
view.preferenceClickIntent
.autoDisposable(view.scope())
.subscribe {
when (it.id) {
R.id.notificationsO -> navigator.showNotificationChannel(threadId)
R.id.notifications -> notifications.set(!notifications.get())
R.id.notificationPreviews -> view.showPreviewModeDialog()
R.id.vibration -> vibration.set(!vibration.get())
R.id.ringtone -> view.showRingtonePicker(ringtone.get().takeIf { it.isNotEmpty() }?.let(Uri::parse))
R.id.qkreply -> prefs.qkreply.set(!prefs.qkreply.get())
R.id.qkreplyTapDismiss -> prefs.qkreplyTapDismiss.set(!prefs.qkreplyTapDismiss.get())
}
}
view.previewModeSelectedIntent
.autoDisposable(view.scope())
.subscribe { previews.set(it) }
view.ringtoneSelectedIntent
.autoDisposable(view.scope())
.subscribe { ringtone -> this.ringtone.set(ringtone) }
}
}