From e14e91a2a40653356a6a1461657494ab74d5b33d Mon Sep 17 00:00:00 2001 From: Kr328 <39107975+Kr328@users.noreply.github.com> Date: Mon, 25 Nov 2019 00:52:13 +0800 Subject: [PATCH] notification --- .../kr328/clash/service/ClashNotification.kt | 35 ++++++++++++++++ .../kr328/clash/service/ClashService.kt | 5 --- .../main/res/layout/clash_notification.xml | 41 +++++++++++++++++++ service/src/main/res/values/strings.xml | 4 ++ 4 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 service/src/main/java/com/github/kr328/clash/service/ClashNotification.kt create mode 100644 service/src/main/res/layout/clash_notification.xml diff --git a/service/src/main/java/com/github/kr328/clash/service/ClashNotification.kt b/service/src/main/java/com/github/kr328/clash/service/ClashNotification.kt new file mode 100644 index 0000000..5a433d1 --- /dev/null +++ b/service/src/main/java/com/github/kr328/clash/service/ClashNotification.kt @@ -0,0 +1,35 @@ +package com.github.kr328.clash.service + +import android.app.NotificationChannel +import android.app.NotificationManager +import android.content.Context +import android.os.Build +import androidx.core.app.NotificationManagerCompat + +class ClashNotification(private val context: Context) { + companion object { + private const val CLASH_STATUS_NOTIFICATION_CHANNEL = "clash_status_channel" + private const val CLASH_STATUS_NOTIFICATION_ID = 413 + + private const val MAIN_ACTIVITY_NAME = ".MainActivity" + } + + init { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationManagerCompat.from(context) + .createNotificationChannel( + NotificationChannel(CLASH_STATUS_NOTIFICATION_CHANNEL, + context.getString(R.string.clash_service_status_channel), + NotificationManager.IMPORTANCE_MIN) + ) + } + } + + fun show() { + + } + + fun cancel() { + + } +} \ No newline at end of file diff --git a/service/src/main/java/com/github/kr328/clash/service/ClashService.kt b/service/src/main/java/com/github/kr328/clash/service/ClashService.kt index 265f111..a43a02b 100644 --- a/service/src/main/java/com/github/kr328/clash/service/ClashService.kt +++ b/service/src/main/java/com/github/kr328/clash/service/ClashService.kt @@ -25,11 +25,6 @@ import java.util.concurrent.Executors class ClashService : Service() { companion object { private const val TAG = "ClashForAndroid" - - private const val CLASH_STATUS_NOTIFICATION_CHANNEL = "clash_status_channel" - private const val CLASH_STATUS_NOTIFICATION_ID = 413 - - private const val MAIN_ACTIVITY_NAME = ".MainActivity" } private val handler = Handler() diff --git a/service/src/main/res/layout/clash_notification.xml b/service/src/main/res/layout/clash_notification.xml new file mode 100644 index 0000000..18526c4 --- /dev/null +++ b/service/src/main/res/layout/clash_notification.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + diff --git a/service/src/main/res/values/strings.xml b/service/src/main/res/values/strings.xml index 4ad8fad..b5a164a 100644 --- a/service/src/main/res/values/strings.xml +++ b/service/src/main/res/values/strings.xml @@ -5,4 +5,8 @@ Running Profile %s loaded VPN + + UP + Down + 0 KiB/s