-
-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to remove all custom notification channels (#3549)
Closes #3531 Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>
- Loading branch information
1 parent
0a6451c
commit 24b5894
Showing
6 changed files
with
75 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...src/main/java/org/openhab/habdroid/ui/preference/widgets/NotificationChannelPreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
package org.openhab.habdroid.ui.preference.widgets | ||
|
||
import android.app.NotificationManager | ||
import android.content.Context | ||
import android.os.Build | ||
import android.util.AttributeSet | ||
import android.widget.ImageView | ||
import androidx.appcompat.widget.TooltipCompat | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceViewHolder | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
import org.openhab.habdroid.R | ||
|
||
class NotificationChannelPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs) { | ||
private var helpIcon: ImageView? = null | ||
|
||
init { | ||
widgetLayoutResource = R.layout.help_icon_pref | ||
} | ||
|
||
override fun onBindViewHolder(holder: PreferenceViewHolder) { | ||
super.onBindViewHolder(holder) | ||
|
||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { | ||
return | ||
} | ||
|
||
helpIcon = holder.itemView.findViewById(R.id.help_icon) | ||
helpIcon?.apply { | ||
val contentDescription = context.getString(R.string.click_here_for_more_information) | ||
this.contentDescription = contentDescription | ||
TooltipCompat.setTooltipText(this, contentDescription) | ||
|
||
setOnClickListener { | ||
MaterialAlertDialogBuilder(context) | ||
.setMessage(R.string.settings_notification_hint) | ||
.setPositiveButton(android.R.string.ok, null) | ||
.setNegativeButton(R.string.settings_notification_reset_settings) { _, _ -> | ||
MaterialAlertDialogBuilder(context) | ||
.setMessage(R.string.settings_notification_reset_settings_confirm) | ||
.setPositiveButton(android.R.string.ok) { _, _ -> | ||
val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||
nm.notificationChannels | ||
.filter { it.id.startsWith("severity-") } | ||
.forEach { | ||
nm.deleteNotificationChannel(it.id) | ||
} | ||
} | ||
.setNegativeButton(android.R.string.cancel, null) | ||
.show() | ||
} | ||
.show() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters