refactor
This commit is contained in:
parent
3c5283e32a
commit
4ee646687a
|
@ -15,7 +15,6 @@ import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.provider.Settings
|
|
||||||
import android.text.Editable
|
import android.text.Editable
|
||||||
import android.text.SpannableString
|
import android.text.SpannableString
|
||||||
import android.text.TextWatcher
|
import android.text.TextWatcher
|
||||||
|
@ -363,12 +362,12 @@ class ActAccountSetting
|
||||||
btnNotificationSoundReset = findViewById(R.id.btnNotificationSoundReset)
|
btnNotificationSoundReset = findViewById(R.id.btnNotificationSoundReset)
|
||||||
btnNotificationSoundEdit.setOnClickListener(this)
|
btnNotificationSoundEdit.setOnClickListener(this)
|
||||||
btnNotificationSoundReset.setOnClickListener(this)
|
btnNotificationSoundReset.setOnClickListener(this)
|
||||||
|
|
||||||
btnNotificationStyleEdit = findViewById(R.id.btnNotificationStyleEdit)
|
btnNotificationStyleEdit = findViewById(R.id.btnNotificationStyleEdit)
|
||||||
btnNotificationStyleEditReply = findViewById(R.id.btnNotificationStyleEditReply)
|
btnNotificationStyleEditReply = findViewById(R.id.btnNotificationStyleEditReply)
|
||||||
btnNotificationStyleEdit.setOnClickListener(this)
|
btnNotificationStyleEdit.setOnClickListener(this)
|
||||||
btnNotificationStyleEditReply.setOnClickListener(this)
|
btnNotificationStyleEditReply.setOnClickListener(this)
|
||||||
vg(btnNotificationStyleEditReply,Pref.bpSeparateReplyNotificationGroup(pref) )
|
vg(btnNotificationStyleEditReply, Pref.bpSeparateReplyNotificationGroup(pref))
|
||||||
|
|
||||||
name_invalidator = NetworkEmojiInvalidator(handler, etDisplayName)
|
name_invalidator = NetworkEmojiInvalidator(handler, etDisplayName)
|
||||||
note_invalidator = NetworkEmojiInvalidator(handler, etNote)
|
note_invalidator = NetworkEmojiInvalidator(handler, etNote)
|
||||||
|
@ -607,20 +606,19 @@ class ActAccountSetting
|
||||||
|
|
||||||
R.id.btnFields -> sendFields()
|
R.id.btnFields -> sendFields()
|
||||||
|
|
||||||
R.id.btnNotificationStyleEdit -> if(Build.VERSION.SDK_INT >= 26) {
|
R.id.btnNotificationStyleEdit ->
|
||||||
val channel = NotificationHelper.createNotificationChannel(this, account,NotificationHelper.TRACKING_NAME_DEFAULT)
|
NotificationHelper.openNotificationChannelSetting(
|
||||||
val intent = Intent("android.settings.CHANNEL_NOTIFICATION_SETTINGS")
|
this,
|
||||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, channel.id)
|
account,
|
||||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
|
NotificationHelper.TRACKING_NAME_DEFAULT
|
||||||
startActivity(intent)
|
)
|
||||||
}
|
|
||||||
R.id.btnNotificationStyleEditReply -> if(Build.VERSION.SDK_INT >= 26) {
|
R.id.btnNotificationStyleEditReply ->
|
||||||
val channel = NotificationHelper.createNotificationChannel(this, account,NotificationHelper.TRACKING_NAME_REPLY)
|
NotificationHelper.openNotificationChannelSetting(
|
||||||
val intent = Intent("android.settings.CHANNEL_NOTIFICATION_SETTINGS")
|
this,
|
||||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, channel.id)
|
account,
|
||||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
|
NotificationHelper.TRACKING_NAME_REPLY
|
||||||
startActivity(intent)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,9 @@ import android.annotation.TargetApi
|
||||||
import android.app.NotificationChannel
|
import android.app.NotificationChannel
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
|
import android.provider.Settings
|
||||||
|
|
||||||
import jp.juggler.subwaytooter.R
|
import jp.juggler.subwaytooter.R
|
||||||
import jp.juggler.subwaytooter.table.SavedAccount
|
import jp.juggler.subwaytooter.table.SavedAccount
|
||||||
|
@ -17,7 +20,11 @@ object NotificationHelper {
|
||||||
internal const val TRACKING_NAME_REPLY = "reply"
|
internal const val TRACKING_NAME_REPLY = "reply"
|
||||||
|
|
||||||
@TargetApi(26)
|
@TargetApi(26)
|
||||||
fun createNotificationChannel(context : Context, account : SavedAccount,trackingName:String) =when(trackingName) {
|
fun createNotificationChannel(
|
||||||
|
context : Context,
|
||||||
|
account : SavedAccount,
|
||||||
|
trackingName : String
|
||||||
|
) = when(trackingName) {
|
||||||
"" -> createNotificationChannel(
|
"" -> createNotificationChannel(
|
||||||
context,
|
context,
|
||||||
account.acct, // id
|
account.acct, // id
|
||||||
|
@ -26,7 +33,7 @@ object NotificationHelper {
|
||||||
NotificationManager.IMPORTANCE_DEFAULT // : NotificationManager.IMPORTANCE_LOW;
|
NotificationManager.IMPORTANCE_DEFAULT // : NotificationManager.IMPORTANCE_LOW;
|
||||||
)
|
)
|
||||||
|
|
||||||
else-> createNotificationChannel(
|
else -> createNotificationChannel(
|
||||||
context,
|
context,
|
||||||
"${account.acct}/$trackingName", // id
|
"${account.acct}/$trackingName", // id
|
||||||
"${account.acct}/$trackingName", // name
|
"${account.acct}/$trackingName", // name
|
||||||
|
@ -42,9 +49,10 @@ object NotificationHelper {
|
||||||
, description : String? // The user-visible description of the channel.
|
, description : String? // The user-visible description of the channel.
|
||||||
, importance : Int
|
, importance : Int
|
||||||
) : NotificationChannel {
|
) : NotificationChannel {
|
||||||
val notification_manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?
|
val notification_manager =
|
||||||
?: throw NotImplementedError("missing NotificationManager system service")
|
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?
|
||||||
|
?: throw NotImplementedError("missing NotificationManager system service")
|
||||||
|
|
||||||
var channel : NotificationChannel? = null
|
var channel : NotificationChannel? = null
|
||||||
try {
|
try {
|
||||||
channel = notification_manager.getNotificationChannel(channel_id)
|
channel = notification_manager.getNotificationChannel(channel_id)
|
||||||
|
@ -62,4 +70,18 @@ object NotificationHelper {
|
||||||
return channel
|
return channel
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun openNotificationChannelSetting(
|
||||||
|
context : Context,
|
||||||
|
account : SavedAccount,
|
||||||
|
trackingName : String
|
||||||
|
) {
|
||||||
|
if(Build.VERSION.SDK_INT >= 26) {
|
||||||
|
val channel = createNotificationChannel(context, account, trackingName)
|
||||||
|
val intent = Intent("android.settings.CHANNEL_NOTIFICATION_SETTINGS")
|
||||||
|
intent.putExtra(Settings.EXTRA_CHANNEL_ID, channel.id)
|
||||||
|
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
|
||||||
|
context.startActivity(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue