From 01120a925589b7875373ce92de6926f1e9c3312b Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 30 Mar 2020 23:25:51 +0200 Subject: [PATCH] adding a setting for hiding the notification --- .../activities/SettingsActivity.kt | 13 ++++++-- .../voicerecorder/helpers/Config.kt | 4 +++ .../voicerecorder/helpers/Constants.kt | 3 ++ .../voicerecorder/services/RecorderService.kt | 28 ++++++++++++++---- app/src/main/res/drawable/ic_empty.png | Bin 0 -> 91 bytes app/src/main/res/layout/activity_settings.xml | 23 ++++++++++++++ 6 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 app/src/main/res/drawable/ic_empty.png diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/SettingsActivity.kt index 3c3b9c6..0f23a48 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/SettingsActivity.kt @@ -1,14 +1,12 @@ package com.simplemobiletools.voicerecorder.activities -import android.content.Intent import android.os.Bundle -import com.simplemobiletools.voicerecorder.extensions.config import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.isThankYouInstalled import com.simplemobiletools.commons.extensions.launchPurchaseThankYouIntent import com.simplemobiletools.commons.extensions.updateTextColors -import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS import com.simplemobiletools.voicerecorder.R +import com.simplemobiletools.voicerecorder.extensions.config import kotlinx.android.synthetic.main.activity_settings.* import java.util.* @@ -25,6 +23,7 @@ class SettingsActivity : SimpleActivity() { setupPurchaseThankYou() setupCustomizeColors() setupUseEnglish() + setupHideNotification() updateTextColors(settings_scrollview) } @@ -50,4 +49,12 @@ class SettingsActivity : SimpleActivity() { System.exit(0) } } + + private fun setupHideNotification() { + settings_hide_notification.isChecked = config.hideNotification + settings_hide_notification_holder.setOnClickListener { + settings_hide_notification.toggle() + config.hideNotification = settings_hide_notification.isChecked + } + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/helpers/Config.kt index 695ff75..51f9023 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/helpers/Config.kt @@ -7,4 +7,8 @@ class Config(context: Context) : BaseConfig(context) { companion object { fun newInstance(context: Context) = Config(context) } + + var hideNotification: Boolean + get() = prefs.getBoolean(HIDE_NOTIFICATION, false) + set(hideNotification) = prefs.edit().putBoolean(HIDE_NOTIFICATION, hideNotification).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/helpers/Constants.kt index ac2d595..27390ee 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/helpers/Constants.kt @@ -5,3 +5,6 @@ const val RECORDER_RUNNING_NOTIF_ID = 10000 private const val PATH = "com.simplemobiletools.voicerecorder.action." const val GET_RECORDER_INFO = PATH + "GET_RECORDER_INFO" const val STOP_AMPLITUDE_UPDATE = PATH + "STOP_AMPLITUDE_UPDATE" + +// shared preferences +const val HIDE_NOTIFICATION = "hide_notification" diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/services/RecorderService.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/services/RecorderService.kt index 3dcd909..3bc0823 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/services/RecorderService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/services/RecorderService.kt @@ -19,6 +19,7 @@ import com.simplemobiletools.commons.helpers.isOreoPlus import com.simplemobiletools.commons.helpers.isQPlus import com.simplemobiletools.voicerecorder.R import com.simplemobiletools.voicerecorder.activities.SplashActivity +import com.simplemobiletools.voicerecorder.extensions.config import com.simplemobiletools.voicerecorder.helpers.GET_RECORDER_INFO import com.simplemobiletools.voicerecorder.helpers.RECORDER_RUNNING_NOTIF_ID import com.simplemobiletools.voicerecorder.helpers.STOP_AMPLITUDE_UPDATE @@ -184,29 +185,44 @@ class RecorderService : Service() { @TargetApi(Build.VERSION_CODES.O) private fun showNotification(): Notification { + val hideNotification = config.hideNotification val channelId = "simple_recorder" val label = getString(R.string.app_name) val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager if (isOreoPlus()) { - val importance = NotificationManager.IMPORTANCE_DEFAULT + val importance = if (hideNotification) NotificationManager.IMPORTANCE_MIN else NotificationManager.IMPORTANCE_DEFAULT NotificationChannel(channelId, label, importance).apply { setSound(null, null) notificationManager.createNotificationChannel(this) } } + var priority = Notification.PRIORITY_DEFAULT + var icon = R.drawable.ic_microphone_small + var title = label + var text = getString(R.string.recording) + var visibility = NotificationCompat.VISIBILITY_PUBLIC + + if (hideNotification) { + priority = Notification.PRIORITY_MIN + icon = R.drawable.ic_empty + title = "" + text = "" + visibility = NotificationCompat.VISIBILITY_SECRET + } + val builder = NotificationCompat.Builder(this) - .setContentTitle(label) - .setContentText(getString(R.string.recording)) - .setSmallIcon(R.drawable.ic_microphone_small) + .setContentTitle(title) + .setContentText(text) + .setSmallIcon(icon) .setContentIntent(getOpenAppIntent()) - .setPriority(Notification.PRIORITY_DEFAULT) + .setPriority(priority) + .setVisibility(visibility) .setSound(null) .setOngoing(true) .setAutoCancel(true) .setChannelId(channelId) - builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) return builder.build() } diff --git a/app/src/main/res/drawable/ic_empty.png b/app/src/main/res/drawable/ic_empty.png new file mode 100644 index 0000000000000000000000000000000000000000..bd396de62e493c894552d9ca112992b72158b96a GIT binary patch literal 91 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k8}bl&H|6fVg?4jBOuH;Rhv&5D9G#S g;uyj)GdTeWfLvAv#`cANSAZ-APgg&ebxsLQ0Hf>?e*gdg literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index fcd26a5..dfb6a5e 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -75,5 +75,28 @@ app:switchPadding="@dimen/medium_margin" /> + + + + + +