mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-04 10:19:18 +02:00
Add UI to manage notification filter
This commit is contained in:
parent
7ae4c30e3e
commit
d7fd43685b
6 changed files with 166 additions and 0 deletions
|
@ -0,0 +1,53 @@
|
|||
package io.timelimit.android.ui.manage.category.settings
|
||||
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import io.timelimit.android.data.model.Category
|
||||
import io.timelimit.android.databinding.CategoryNotificationFilterBinding
|
||||
import io.timelimit.android.livedata.mergeLiveData
|
||||
import io.timelimit.android.sync.actions.UpdateCategoryBlockAllNotificationsAction
|
||||
import io.timelimit.android.ui.main.ActivityViewModel
|
||||
import io.timelimit.android.ui.payment.RequiresPurchaseDialogFragment
|
||||
|
||||
object CategoryNotificationFilter {
|
||||
fun bind(
|
||||
view: CategoryNotificationFilterBinding,
|
||||
auth: ActivityViewModel,
|
||||
categoryLive: LiveData<Category?>,
|
||||
lifecycleOwner: LifecycleOwner,
|
||||
fragmentManager: FragmentManager
|
||||
) {
|
||||
val premium = auth.logic.fullVersion.shouldProvideFullVersionFunctions
|
||||
|
||||
mergeLiveData(categoryLive, premium).observe(lifecycleOwner, Observer { (category, hasPremium) ->
|
||||
val shouldBeChecked = category?.blockAllNotifications ?: false
|
||||
|
||||
view.checkbox.setOnCheckedChangeListener { _, _ -> }
|
||||
view.checkbox.isChecked = shouldBeChecked
|
||||
view.checkbox.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked != shouldBeChecked) {
|
||||
if (isChecked && (hasPremium != true)) {
|
||||
RequiresPurchaseDialogFragment().show(fragmentManager)
|
||||
view.checkbox.isChecked = shouldBeChecked
|
||||
} else {
|
||||
if (
|
||||
category != null &&
|
||||
auth.tryDispatchParentAction(
|
||||
UpdateCategoryBlockAllNotificationsAction(
|
||||
categoryId = category.id,
|
||||
blocked = isChecked
|
||||
)
|
||||
)
|
||||
) {
|
||||
// ok
|
||||
} else {
|
||||
view.checkbox.isChecked = shouldBeChecked
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -69,6 +69,14 @@ class CategorySettingsFragment : Fragment() {
|
|||
auth = auth
|
||||
)
|
||||
|
||||
CategoryNotificationFilter.bind(
|
||||
view = binding.notificationFilter,
|
||||
lifecycleOwner = this,
|
||||
fragmentManager = fragmentManager!!,
|
||||
auth = auth,
|
||||
categoryLive = categoryEntry
|
||||
)
|
||||
|
||||
binding.btnDeleteCategory.setOnClickListener { deleteCategory() }
|
||||
binding.editCategoryTitleGo.setOnClickListener { renameCategory() }
|
||||
|
||||
|
|
54
app/src/main/res/layout/category_notification_filter.xml
Normal file
54
app/src/main/res/layout/category_notification_filter.xml
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
TimeLimit Copyright <C> 2019 Jonas Lochmann
|
||||
This program 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 version 3 of the License.
|
||||
|
||||
This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<androidx.cardview.widget.CardView
|
||||
app:cardUseCompatPadding="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:textAppearance="?android:textAppearanceLarge"
|
||||
android:text="@string/category_notification_filter_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:textAppearance="?android:textAppearanceMedium"
|
||||
android:text="@string/category_notification_filter_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/checkbox"
|
||||
android:text="@string/category_notifications_filter_checkbox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:textAppearance="?android:textAppearanceSmall"
|
||||
android:text="@string/purchase_required_info_local_mode_free"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
</layout>
|
|
@ -76,6 +76,9 @@
|
|||
<include android:id="@+id/parent_category"
|
||||
layout="@layout/manage_parent_category" />
|
||||
|
||||
<include android:id="@+id/notification_filter"
|
||||
layout="@layout/category_notification_filter" />
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
app:cardUseCompatPadding="true"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
TimeLimit Copyright <C> 2019 Jonas Lochmann
|
||||
This program 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 version 3 of the License.
|
||||
|
||||
This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<resources>
|
||||
<string name="category_notification_filter_title">Benachrichtigungsfilter</string>
|
||||
<string name="category_notification_filter_text">
|
||||
Wenn der Benachrichtigungszugriff in den Geräte-Einträgen aktiviert wurde,
|
||||
dann werden Benachrichtigungen bei Sperrzeiten und wenn die Zeit abgelaufen ist blockiert.
|
||||
Hiermit können die Benachrichtigungen von Apps einer Kategorie immer blockiert werden.
|
||||
</string>
|
||||
<string name="category_notifications_filter_checkbox">Alle Benachrichtigungen blockieren</string>
|
||||
</resources>
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
TimeLimit Copyright <C> 2019 Jonas Lochmann
|
||||
This program 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 version 3 of the License.
|
||||
|
||||
This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<resources>
|
||||
<string name="category_notification_filter_title">Notification filter</string>
|
||||
<string name="category_notification_filter_text">
|
||||
When enabling the notification access in the device entries,
|
||||
then notifications are blocked at blocked time areas and when the time is over.
|
||||
Here you can enable blocking all notifications from Apps of a category.
|
||||
</string>
|
||||
<string name="category_notifications_filter_checkbox">Block all notifications</string>
|
||||
</resources>
|
Loading…
Add table
Add a link
Reference in a new issue