Show app icons for blocking manager preference

This commit is contained in:
Moez Bhatti
2021-02-23 23:04:19 -05:00
parent 6b9469757e
commit 1e69a6a000
12 changed files with 233 additions and 23 deletions
@@ -2,11 +2,14 @@ package com.moez.QKSMS.feature.blocking.manager
import android.app.Activity
import android.app.AlertDialog
import android.content.res.ColorStateList
import android.view.View
import androidx.core.view.isVisible
import androidx.core.view.isInvisible
import com.jakewharton.rxbinding2.view.clicks
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkController
import com.moez.QKSMS.common.util.Colors
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
import com.moez.QKSMS.injection.appComponent
import com.moez.QKSMS.util.Preferences
import io.reactivex.Observable
@@ -14,12 +17,12 @@ import io.reactivex.Single
import io.reactivex.subjects.PublishSubject
import kotlinx.android.synthetic.main.blocking_manager_controller.*
import kotlinx.android.synthetic.main.blocking_manager_list_option.view.*
import kotlinx.android.synthetic.main.radio_preference_view.view.*
import javax.inject.Inject
class BlockingManagerController : QkController<BlockingManagerView, BlockingManagerState, BlockingManagerPresenter>(),
BlockingManagerView {
@Inject lateinit var colors: Colors
@Inject override lateinit var presenter: BlockingManagerPresenter
private val activityResumedSubject: PublishSubject<Unit> = PublishSubject.create()
@@ -35,6 +38,18 @@ class BlockingManagerController : QkController<BlockingManagerView, BlockingMana
presenter.bindIntents(this)
setTitle(R.string.blocking_manager_title)
showBackButton(true)
val states = arrayOf(
intArrayOf(android.R.attr.state_activated),
intArrayOf(-android.R.attr.state_activated))
val textTertiary = view.context.resolveThemeColor(android.R.attr.textColorTertiary)
val imageTintList = ColorStateList(states, intArrayOf(colors.theme().theme, textTertiary))
qksms.action.imageTintList = imageTintList
callBlocker.action.imageTintList = imageTintList
callControl.action.imageTintList = imageTintList
shouldIAnswer.action.imageTintList = imageTintList
}
override fun onActivityResumed(activity: Activity) {
@@ -42,16 +57,29 @@ class BlockingManagerController : QkController<BlockingManagerView, BlockingMana
}
override fun render(state: BlockingManagerState) {
qksms.radioButton.isChecked = state.blockingManager == Preferences.BLOCKING_MANAGER_QKSMS
qksms.action.setImageResource(getActionIcon(true))
qksms.action.isActivated = true
qksms.action.isInvisible = state.blockingManager != Preferences.BLOCKING_MANAGER_QKSMS
callBlocker.radioButton.isChecked = state.blockingManager == Preferences.BLOCKING_MANAGER_CB
callBlocker.install.isVisible = !state.callBlockerInstalled
callBlocker.action.setImageResource(getActionIcon(state.callBlockerInstalled))
callBlocker.action.isActivated = state.callBlockerInstalled
callBlocker.action.isInvisible = state.blockingManager != Preferences.BLOCKING_MANAGER_CB
&& state.callBlockerInstalled
callControl.radioButton.isChecked = state.blockingManager == Preferences.BLOCKING_MANAGER_CC
callControl.install.isVisible = !state.callControlInstalled
callControl.action.setImageResource(getActionIcon(state.callControlInstalled))
callControl.action.isActivated = state.callControlInstalled
callControl.action.isInvisible = state.blockingManager != Preferences.BLOCKING_MANAGER_CC
&& state.callControlInstalled
shouldIAnswer.radioButton.isChecked = state.blockingManager == Preferences.BLOCKING_MANAGER_SIA
shouldIAnswer.install.isVisible = !state.siaInstalled
shouldIAnswer.action.setImageResource(getActionIcon(state.siaInstalled))
shouldIAnswer.action.isActivated = state.siaInstalled
shouldIAnswer.action.isInvisible = state.blockingManager != Preferences.BLOCKING_MANAGER_SIA
&& state.siaInstalled
}
private fun getActionIcon(installed: Boolean): Int = when {
!installed -> R.drawable.ic_chevron_right_black_24dp
else -> R.drawable.ic_check_white_24dp
}
override fun activityResumed(): Observable<*> = activityResumedSubject
@@ -0,0 +1,93 @@
/*
* Copyright (C) 2020 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.blocking.manager
import android.content.Context
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.moez.QKSMS.R
import com.moez.QKSMS.common.util.extensions.animateLayoutChanges
import com.moez.QKSMS.common.util.extensions.resolveThemeAttribute
import com.moez.QKSMS.common.util.extensions.setVisible
import kotlinx.android.synthetic.main.blocking_manager_preference_view.view.*
class BlockingManagerPreferenceView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
) : ConstraintLayout(context, attrs) {
var icon: Drawable? = null
set(value) {
field = value
if (isInEditMode) {
findViewById<ImageView>(R.id.iconView).setImageDrawable(value)
} else {
iconView.setImageDrawable(value)
}
}
var title: String? = null
set(value) {
field = value
if (isInEditMode) {
findViewById<TextView>(R.id.titleView).text = value
} else {
titleView.text = value
}
}
var summary: String? = null
set(value) {
field = value
if (isInEditMode) {
findViewById<TextView>(R.id.summaryView).run {
text = value
setVisible(value?.isNotEmpty() == true)
}
} else {
summaryView.text = value
summaryView.setVisible(value?.isNotEmpty() == true)
}
}
init {
View.inflate(context, R.layout.blocking_manager_preference_view, this)
setBackgroundResource(context.resolveThemeAttribute(R.attr.selectableItemBackground))
context.obtainStyledAttributes(attrs, R.styleable.BlockingManagerPreferenceView).run {
icon = getDrawable(R.styleable.BlockingManagerPreferenceView_icon)
title = getString(R.styleable.BlockingManagerPreferenceView_title)
summary = getString(R.styleable.BlockingManagerPreferenceView_summary)
// If there's a custom view used for the preference's widget, inflate it
getResourceId(R.styleable.BlockingManagerPreferenceView_widget, -1).takeIf { it != -1 }?.let { id ->
View.inflate(context, id, widgetFrame)
}
recycle()
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

@@ -30,33 +30,38 @@
android:paddingTop="8dp"
android:paddingBottom="8dp">
<com.moez.QKSMS.common.widget.RadioPreferenceView
<com.moez.QKSMS.feature.blocking.manager.BlockingManagerPreferenceView
android:id="@+id/qksms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_blocking_manager_qksms"
app:summary="@string/blocking_manager_qksms_summary"
app:title="@string/blocking_manager_qksms_title" />
app:title="@string/blocking_manager_qksms_title"
app:widget="@layout/blocking_manager_list_option" />
<com.moez.QKSMS.common.widget.RadioPreferenceView
<com.moez.QKSMS.feature.blocking.manager.BlockingManagerPreferenceView
android:id="@+id/callBlocker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_blocking_manager_call_blocker"
app:summary="@string/blocking_manager_call_blocker_summary"
app:title="@string/blocking_manager_call_blocker_title"
app:widget="@layout/blocking_manager_list_option" />
<com.moez.QKSMS.common.widget.RadioPreferenceView
<com.moez.QKSMS.feature.blocking.manager.BlockingManagerPreferenceView
android:id="@+id/callControl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_blocking_manager_call_control"
app:summary="@string/blocking_manager_call_control_summary"
app:title="@string/blocking_manager_call_control_title"
app:widget="@layout/blocking_manager_list_option" />
<com.moez.QKSMS.common.widget.RadioPreferenceView
<com.moez.QKSMS.feature.blocking.manager.BlockingManagerPreferenceView
android:id="@+id/shouldIAnswer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_blocking_manager_sia"
app:summary="@string/blocking_manager_sia_summary"
app:title="@string/blocking_manager_sia_title"
app:widget="@layout/blocking_manager_list_option" />
@@ -18,11 +18,11 @@
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
-->
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/install"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/action"
android:layout_width="56dp"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:orientation="vertical"
android:padding="16dp"
android:src="@drawable/ic_info_black_24dp"
android:tint="?android:attr/textColorTertiary" />
tools:src="@drawable/ic_chevron_right_black_24dp"
tools:tint="?android:attr/textColorTertiary" />
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2020 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/>.
-->
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:parentTag="com.moez.QKSMS.feature.blocking.manager.BlockingManagerPreferenceView">
<ImageView
android:id="@+id/iconView"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_marginStart="16dp"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/titleView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@mipmap/ic_launcher" />
<com.moez.QKSMS.common.widget.QkTextView
android:id="@+id/titleView"
style="@style/TextPrimary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toStartOf="@id/widgetFrame"
app:layout_constraintStart_toEndOf="@id/iconView"
app:layout_constraintTop_toTopOf="parent"
tools:text="Default SMS App" />
<com.moez.QKSMS.common.widget.QkTextView
android:id="@+id/summaryView"
style="@style/TextSecondary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/titleView"
app:layout_constraintStart_toStartOf="@id/titleView"
app:layout_constraintTop_toBottomOf="@id/titleView"
tools:text="QKSMS is your default SMS app" />
<FrameLayout
android:id="@+id/widgetFrame"
android:layout_width="wrap_content"
android:animateLayoutChanges="true"
android:layout_height="match_parent"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_goneMarginEnd="24dp" />
</merge>
@@ -22,7 +22,7 @@
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.appcompat.widget.Toolbar
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/toolbar"
style="@style/Toolbar"
+10 -2
View File
@@ -22,6 +22,7 @@
<attr name="title" format="string" />
<attr name="summary" format="string" />
<attr name="widget" format="reference" />
<attr name="icon" format="reference" />
<attr name="textColor" format="enum">
<enum name="theme" value="0" />
@@ -53,7 +54,7 @@
<attr name="title" />
<attr name="summary" />
<attr name="widget" />
<attr name="icon" format="reference" />
<attr name="icon" />
</declare-styleable>
<declare-styleable name="RadioPreferenceView">
@@ -62,4 +63,11 @@
<attr name="widget" />
</declare-styleable>
</resources>
<declare-styleable name="BlockingManagerPreferenceView">
<attr name="icon" />
<attr name="title" />
<attr name="summary" />
<attr name="widget" />
</declare-styleable>
</resources>
+2 -2
View File
@@ -289,8 +289,8 @@
<string name="blocking_manager_title">Blocking Manager</string>
<string name="blocking_manager_qksms_title">QKSMS</string>
<string name="blocking_manager_qksms_summary">Built-in blocking functionality in QKSMS</string>
<string name="blocking_manager_call_blocker_title" translatable="false">Call Blocker</string>
<string name="blocking_manager_call_blocker_summary">Call Blocker is a program that blocks unwanted calls, call centers, spam, robocalls, telemarketing, private calls, hidden calls, anonymous calls, strangers, etc.</string>
<string name="blocking_manager_call_blocker_title" translatable="false">Call Blocker - Incoming/Outgoing</string>
<string name="blocking_manager_call_blocker_summary">Block spam messages, numbers &amp; unknown calls with blacklist &amp; Schedule</string>
<string name="blocking_manager_call_control_title" translatable="false">Call Control</string>
<string name="blocking_manager_call_control_summary">Automatically filter your calls and messages in one convenient place! Community IQ™ allows you to prevent unwanted messages from community known spammers</string>
<string name="blocking_manager_sia_title" translatable="false">Should I Answer?</string>