#1064 - Show radio button for appropriate dialogs

This commit is contained in:
Moez Bhatti
2018-04-19 03:05:02 -04:00
parent 13bcf27b51
commit 77bfab19f2
11 changed files with 70 additions and 21 deletions
@@ -19,6 +19,7 @@
package common
import android.content.Context
import android.content.res.ColorStateList
import android.support.annotation.ArrayRes
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
@@ -28,9 +29,9 @@ import com.moez.QKSMS.R
import common.base.QkAdapter
import common.base.QkViewHolder
import common.util.Colors
import common.util.extensions.setTint
import common.util.extensions.setVisible
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.Observables
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
@@ -66,8 +67,15 @@ class MenuItemAdapter @Inject constructor(private val context: Context, private
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.menu_list_item, parent, false)
disposables += colors.theme
.subscribe { view.check.setTint(it) }
val states = arrayOf(
intArrayOf(android.R.attr.state_selected),
intArrayOf(-android.R.attr.state_selected))
disposables += Observables
.combineLatest(colors.theme, colors.textTertiary, { theme, textSecondary ->
ColorStateList(states, intArrayOf(theme, textSecondary))
})
.subscribe { view.check.imageTintList = it }
return QkViewHolder(view)
}
@@ -79,7 +87,8 @@ class MenuItemAdapter @Inject constructor(private val context: Context, private
view.clicks().subscribe { menuItemClicks.onNext(menuItem.actionId) }
view.title.text = menuItem.title
view.check.setVisible(menuItem.actionId == selectedItem)
view.check.isSelected = (menuItem.actionId == selectedItem)
view.check.setVisible(selectedItem != null)
}
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
@@ -90,7 +90,8 @@ class NotificationPrefsActivity : QkThemedActivity<NotificationPrefsViewModel>()
}
notifications.checkbox.isChecked = state.notificationsEnabled
notificationPreviews.summary = state.notificationPreviewSummary
notificationPreviews.summary = state.previewSummary
previewModeDialog.adapter.selectedItem = state.previewId
vibration.checkbox.isChecked = state.vibrationEnabled
ringtone.summary = state.ringtoneName
qkreply.checkbox.isChecked = state.qkReplyEnabled
@@ -19,11 +19,13 @@
package feature.notificationprefs
import android.os.Build
import util.Preferences
data class NotificationPrefsState(
val conversationTitle: String = "",
val notificationsEnabled: Boolean = true,
val notificationPreviewSummary: String = "",
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,
@@ -48,6 +48,7 @@ class NotificationPrefsViewModel(intent: Intent) : QkViewModel<NotificationPrefs
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>
@@ -55,6 +56,7 @@ class NotificationPrefsViewModel(intent: Intent) : QkViewModel<NotificationPrefs
appComponent.inject(this)
notifications = prefs.notifications(threadId)
previews = prefs.notificationPreviews(threadId)
vibration = prefs.vibration(threadId)
ringtone = prefs.ringtone(threadId)
@@ -67,9 +69,11 @@ class NotificationPrefsViewModel(intent: Intent) : QkViewModel<NotificationPrefs
disposables += notifications.asObservable()
.subscribe { enabled -> newState { it.copy(notificationsEnabled = enabled) } }
val notificationPreviewLabels = context.resources.getStringArray(R.array.notification_preview_options)
disposables += prefs.notificationPreviews().asObservable()
.subscribe { nightMode -> newState { it.copy(notificationPreviewSummary = notificationPreviewLabels[nightMode]) } }
val previewLabels = context.resources.getStringArray(R.array.notification_preview_options)
disposables += previews.asObservable()
.subscribe { previewId ->
newState { it.copy(previewSummary = previewLabels[previewId], previewId = previewId) }
}
disposables += vibration.asObservable()
.subscribe { enabled -> newState { it.copy(vibrationEnabled = enabled) } }
@@ -111,7 +115,7 @@ class NotificationPrefsViewModel(intent: Intent) : QkViewModel<NotificationPrefs
view.previewModeSelectedIntent
.autoDisposable(view.scope())
.subscribe { prefs.notificationPreviews().set(it) }
.subscribe { previews.set(it) }
view.ringtoneSelectedIntent
.autoDisposable(view.scope())
@@ -108,6 +108,7 @@ class SettingsActivity : QkThemedActivity<SettingsViewModel>(), SettingsView {
themePreview.setBackgroundTint(state.theme)
night.summary = state.nightModeSummary
nightModeDialog.adapter.selectedItem = state.nightModeId
nightStart.setVisible(state.nightModeId == Preferences.NIGHT_MODE_AUTO)
nightStart.summary = state.nightStart
nightEnd.setVisible(state.nightModeId == Preferences.NIGHT_MODE_AUTO)
@@ -120,6 +121,7 @@ class SettingsActivity : QkThemedActivity<SettingsViewModel>(), SettingsView {
delivery.checkbox.isChecked = state.deliveryEnabled
textSize.summary = state.textSizeSummary
textSizeDialog.adapter.selectedItem = state.textSizeId
systemFont.checkbox.isChecked = state.systemFontEnabled
unicode.checkbox.isChecked = state.stripUnicodeEnabled
@@ -33,6 +33,7 @@ data class SettingsState(
val notificationsEnabled: Boolean = true,
val deliveryEnabled: Boolean = false,
val textSizeSummary: String = "",
val textSizeId: Int = Preferences.TEXT_SIZE_NORMAL,
val systemFontEnabled: Boolean = false,
val splitSmsEnabled: Boolean = false,
val stripUnicodeEnabled: Boolean = false,
@@ -86,7 +86,9 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
val textSizeLabels = context.resources.getStringArray(R.array.text_sizes)
disposables += prefs.textSize.asObservable()
.subscribe { textSize -> newState { it.copy(textSizeSummary = textSizeLabels[textSize]) } }
.subscribe { textSize ->
newState { it.copy(textSizeSummary = textSizeLabels[textSize], textSizeId = textSize) }
}
disposables += prefs.systemFont.asObservable()
.subscribe { enabled -> newState { it.copy(systemFontEnabled = enabled) } }
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,7c-2.76,0 -5,2.24 -5,5s2.24,5 5,5 5,-2.24 5,-5 -2.24,-5 -5,-5zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
</vector>
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
</vector>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_radio_button_checked_black_24dp" android:state_selected="true" />
<item android:drawable="@drawable/ic_radio_button_unchecked_black_24dp" />
</selector>
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
~
~ This file is part of QKSMS.
@@ -18,12 +17,21 @@
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/check"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="24dp"
android:src="@drawable/radio_button"
tools:tint="@color/textTertiary" />
<common.widget.QkTextView
android:id="@+id/title"
style="@style/TextPrimary"
@@ -33,13 +41,7 @@
android:paddingBottom="12dp"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:paddingTop="12dp" />
<ImageView
android:id="@+id/check"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginRight="24dp"
android:src="@drawable/ic_check_white_24dp" />
android:paddingTop="12dp"
tools:text="Testing" />
</LinearLayout>