mirror of
https://github.com/SimpleMobileTools/Simple-Voice-Recorder.git
synced 2025-06-05 21:59:31 +02:00
adding a setting for hiding the notification
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user