mirror of
https://github.com/SimpleMobileTools/Simple-Voice-Recorder.git
synced 2025-01-25 13:38:48 +01:00
adding a setting for hiding the notification
This commit is contained in:
parent
2ec7e6be14
commit
01120a9255
@ -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()
|
||||
}
|
||||
|
||||
|
BIN
app/src/main/res/drawable/ic_empty.png
Normal file
BIN
app/src/main/res/drawable/ic_empty.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 91 B |
@ -75,5 +75,28 @@
|
||||
app:switchPadding="@dimen/medium_margin" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_hide_notification_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingLeft="@dimen/normal_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/normal_margin"
|
||||
android:paddingBottom="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MySwitchCompat
|
||||
android:id="@+id/settings_hide_notification"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/try_hiding_notification"
|
||||
app:switchPadding="@dimen/medium_margin" />
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
Loading…
x
Reference in New Issue
Block a user