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
|
package com.simplemobiletools.voicerecorder.activities
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import com.simplemobiletools.voicerecorder.extensions.config
|
|
||||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||||
import com.simplemobiletools.commons.extensions.isThankYouInstalled
|
import com.simplemobiletools.commons.extensions.isThankYouInstalled
|
||||||
import com.simplemobiletools.commons.extensions.launchPurchaseThankYouIntent
|
import com.simplemobiletools.commons.extensions.launchPurchaseThankYouIntent
|
||||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||||
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
|
|
||||||
import com.simplemobiletools.voicerecorder.R
|
import com.simplemobiletools.voicerecorder.R
|
||||||
|
import com.simplemobiletools.voicerecorder.extensions.config
|
||||||
import kotlinx.android.synthetic.main.activity_settings.*
|
import kotlinx.android.synthetic.main.activity_settings.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@ -25,6 +23,7 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
setupPurchaseThankYou()
|
setupPurchaseThankYou()
|
||||||
setupCustomizeColors()
|
setupCustomizeColors()
|
||||||
setupUseEnglish()
|
setupUseEnglish()
|
||||||
|
setupHideNotification()
|
||||||
updateTextColors(settings_scrollview)
|
updateTextColors(settings_scrollview)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,4 +49,12 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
System.exit(0)
|
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 {
|
companion object {
|
||||||
fun newInstance(context: Context) = Config(context)
|
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."
|
private const val PATH = "com.simplemobiletools.voicerecorder.action."
|
||||||
const val GET_RECORDER_INFO = PATH + "GET_RECORDER_INFO"
|
const val GET_RECORDER_INFO = PATH + "GET_RECORDER_INFO"
|
||||||
const val STOP_AMPLITUDE_UPDATE = PATH + "STOP_AMPLITUDE_UPDATE"
|
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.commons.helpers.isQPlus
|
||||||
import com.simplemobiletools.voicerecorder.R
|
import com.simplemobiletools.voicerecorder.R
|
||||||
import com.simplemobiletools.voicerecorder.activities.SplashActivity
|
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.GET_RECORDER_INFO
|
||||||
import com.simplemobiletools.voicerecorder.helpers.RECORDER_RUNNING_NOTIF_ID
|
import com.simplemobiletools.voicerecorder.helpers.RECORDER_RUNNING_NOTIF_ID
|
||||||
import com.simplemobiletools.voicerecorder.helpers.STOP_AMPLITUDE_UPDATE
|
import com.simplemobiletools.voicerecorder.helpers.STOP_AMPLITUDE_UPDATE
|
||||||
@ -184,29 +185,44 @@ class RecorderService : Service() {
|
|||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.O)
|
@TargetApi(Build.VERSION_CODES.O)
|
||||||
private fun showNotification(): Notification {
|
private fun showNotification(): Notification {
|
||||||
|
val hideNotification = config.hideNotification
|
||||||
val channelId = "simple_recorder"
|
val channelId = "simple_recorder"
|
||||||
val label = getString(R.string.app_name)
|
val label = getString(R.string.app_name)
|
||||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
if (isOreoPlus()) {
|
if (isOreoPlus()) {
|
||||||
val importance = NotificationManager.IMPORTANCE_DEFAULT
|
val importance = if (hideNotification) NotificationManager.IMPORTANCE_MIN else NotificationManager.IMPORTANCE_DEFAULT
|
||||||
NotificationChannel(channelId, label, importance).apply {
|
NotificationChannel(channelId, label, importance).apply {
|
||||||
setSound(null, null)
|
setSound(null, null)
|
||||||
notificationManager.createNotificationChannel(this)
|
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)
|
val builder = NotificationCompat.Builder(this)
|
||||||
.setContentTitle(label)
|
.setContentTitle(title)
|
||||||
.setContentText(getString(R.string.recording))
|
.setContentText(text)
|
||||||
.setSmallIcon(R.drawable.ic_microphone_small)
|
.setSmallIcon(icon)
|
||||||
.setContentIntent(getOpenAppIntent())
|
.setContentIntent(getOpenAppIntent())
|
||||||
.setPriority(Notification.PRIORITY_DEFAULT)
|
.setPriority(priority)
|
||||||
|
.setVisibility(visibility)
|
||||||
.setSound(null)
|
.setSound(null)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setChannelId(channelId)
|
.setChannelId(channelId)
|
||||||
|
|
||||||
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
||||||
return builder.build()
|
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" />
|
app:switchPadding="@dimen/medium_margin" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</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>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
Reference in New Issue
Block a user