Merge pull request #125 from tanvir-ahmod/fix_108
Fix #108, Add setting to hide message content in notification
This commit is contained in:
commit
21044bdeee
|
@ -13,6 +13,10 @@ import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.commons.models.RadioItem
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import com.simplemobiletools.smsmessenger.R
|
import com.simplemobiletools.smsmessenger.R
|
||||||
import com.simplemobiletools.smsmessenger.extensions.config
|
import com.simplemobiletools.smsmessenger.extensions.config
|
||||||
|
import com.simplemobiletools.smsmessenger.extensions.getLockScreenVisibilityText
|
||||||
|
import com.simplemobiletools.smsmessenger.helpers.LOCK_SCREEN_NOTHING
|
||||||
|
import com.simplemobiletools.smsmessenger.helpers.LOCK_SCREEN_SENDER
|
||||||
|
import com.simplemobiletools.smsmessenger.helpers.LOCK_SCREEN_SENDER_MESSAGE
|
||||||
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
||||||
import kotlinx.android.synthetic.main.activity_settings.*
|
import kotlinx.android.synthetic.main.activity_settings.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -36,6 +40,7 @@ class SettingsActivity : SimpleActivity() {
|
||||||
setupChangeDateTimeFormat()
|
setupChangeDateTimeFormat()
|
||||||
setupFontSize()
|
setupFontSize()
|
||||||
setupShowCharacterCounter()
|
setupShowCharacterCounter()
|
||||||
|
setupLockScreenVisibility()
|
||||||
updateTextColors(settings_scrollview)
|
updateTextColors(settings_scrollview)
|
||||||
|
|
||||||
if (blockedNumbersAtPause != -1 && blockedNumbersAtPause != getBlockedNumbers().hashCode()) {
|
if (blockedNumbersAtPause != -1 && blockedNumbersAtPause != getBlockedNumbers().hashCode()) {
|
||||||
|
@ -108,7 +113,8 @@ class SettingsActivity : SimpleActivity() {
|
||||||
RadioItem(FONT_SIZE_SMALL, getString(R.string.small)),
|
RadioItem(FONT_SIZE_SMALL, getString(R.string.small)),
|
||||||
RadioItem(FONT_SIZE_MEDIUM, getString(R.string.medium)),
|
RadioItem(FONT_SIZE_MEDIUM, getString(R.string.medium)),
|
||||||
RadioItem(FONT_SIZE_LARGE, getString(R.string.large)),
|
RadioItem(FONT_SIZE_LARGE, getString(R.string.large)),
|
||||||
RadioItem(FONT_SIZE_EXTRA_LARGE, getString(R.string.extra_large)))
|
RadioItem(FONT_SIZE_EXTRA_LARGE, getString(R.string.extra_large))
|
||||||
|
)
|
||||||
|
|
||||||
RadioGroupDialog(this@SettingsActivity, items, config.fontSize) {
|
RadioGroupDialog(this@SettingsActivity, items, config.fontSize) {
|
||||||
config.fontSize = it as Int
|
config.fontSize = it as Int
|
||||||
|
@ -124,4 +130,20 @@ class SettingsActivity : SimpleActivity() {
|
||||||
config.showCharacterCounter = settings_show_character_counter.isChecked
|
config.showCharacterCounter = settings_show_character_counter.isChecked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupLockScreenVisibility() {
|
||||||
|
settings_lock_screen_visibility.text = getLockScreenVisibilityText(config.lockScreenVisibilitySetting)
|
||||||
|
settings_lock_screen_visibility_holder.setOnClickListener {
|
||||||
|
val items = arrayListOf(
|
||||||
|
RadioItem(LOCK_SCREEN_SENDER_MESSAGE, getString(R.string.sender_and_message)),
|
||||||
|
RadioItem(LOCK_SCREEN_SENDER, getString(R.string.sender_only)),
|
||||||
|
RadioItem(LOCK_SCREEN_NOTHING, getString(R.string.nothing)),
|
||||||
|
)
|
||||||
|
|
||||||
|
RadioGroupDialog(this@SettingsActivity, items, config.lockScreenVisibilitySetting) {
|
||||||
|
config.lockScreenVisibilitySetting = it as Int
|
||||||
|
settings_lock_screen_visibility.text = getLockScreenVisibilityText(config.lockScreenVisibilitySetting)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -709,24 +709,44 @@ fun Context.showMessageNotification(address: String, body: String, threadId: Lon
|
||||||
}
|
}
|
||||||
|
|
||||||
val largeIcon = bitmap ?: SimpleContactsHelper(this).getContactLetterIcon(sender)
|
val largeIcon = bitmap ?: SimpleContactsHelper(this).getContactLetterIcon(sender)
|
||||||
val builder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL)
|
val builder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL).apply {
|
||||||
.setContentTitle(sender)
|
when (config.lockScreenVisibilitySetting) {
|
||||||
.setContentText(body)
|
LOCK_SCREEN_SENDER_MESSAGE -> {
|
||||||
.setColor(getAdjustedPrimaryColor())
|
setContentTitle(sender)
|
||||||
.setSmallIcon(R.drawable.ic_messenger)
|
setLargeIcon(largeIcon)
|
||||||
.setLargeIcon(largeIcon)
|
setContentText(body)
|
||||||
.setStyle(NotificationCompat.BigTextStyle().setSummaryText(summaryText).bigText(body))
|
}
|
||||||
.setContentIntent(pendingIntent)
|
LOCK_SCREEN_SENDER -> {
|
||||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
setContentTitle(sender)
|
||||||
.setDefaults(Notification.DEFAULT_LIGHTS)
|
setLargeIcon(largeIcon)
|
||||||
.setCategory(Notification.CATEGORY_MESSAGE)
|
}
|
||||||
.setAutoCancel(true)
|
}
|
||||||
.setSound(soundUri, AudioManager.STREAM_NOTIFICATION)
|
|
||||||
if (replyAction != null) {
|
color = getAdjustedPrimaryColor()
|
||||||
|
setSmallIcon(R.drawable.ic_messenger)
|
||||||
|
setStyle(NotificationCompat.BigTextStyle().setSummaryText(summaryText).bigText(body))
|
||||||
|
setContentIntent(pendingIntent)
|
||||||
|
priority = NotificationCompat.PRIORITY_MAX
|
||||||
|
setDefaults(Notification.DEFAULT_LIGHTS)
|
||||||
|
setCategory(Notification.CATEGORY_MESSAGE)
|
||||||
|
setAutoCancel(true)
|
||||||
|
setSound(soundUri, AudioManager.STREAM_NOTIFICATION)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (replyAction != null && config.lockScreenVisibilitySetting == LOCK_SCREEN_SENDER_MESSAGE) {
|
||||||
builder.addAction(replyAction)
|
builder.addAction(replyAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.addAction(R.drawable.ic_check_vector, getString(R.string.mark_as_read), markAsReadPendingIntent)
|
builder.addAction(R.drawable.ic_check_vector, getString(R.string.mark_as_read), markAsReadPendingIntent)
|
||||||
.setChannelId(NOTIFICATION_CHANNEL)
|
.setChannelId(NOTIFICATION_CHANNEL)
|
||||||
|
|
||||||
notificationManager.notify(threadId.hashCode(), builder.build())
|
notificationManager.notify(threadId.hashCode(), builder.build())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.getLockScreenVisibilityText(type: Int) = getString(
|
||||||
|
when (type) {
|
||||||
|
LOCK_SCREEN_SENDER_MESSAGE -> R.string.sender_and_message
|
||||||
|
LOCK_SCREEN_SENDER -> R.string.sender_only
|
||||||
|
else -> R.string.nothing
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
|
@ -17,4 +17,8 @@ class Config(context: Context) : BaseConfig(context) {
|
||||||
var showCharacterCounter: Boolean
|
var showCharacterCounter: Boolean
|
||||||
get() = prefs.getBoolean(SHOW_CHARACTER_COUNTER, false)
|
get() = prefs.getBoolean(SHOW_CHARACTER_COUNTER, false)
|
||||||
set(showCharacterCounter) = prefs.edit().putBoolean(SHOW_CHARACTER_COUNTER, showCharacterCounter).apply()
|
set(showCharacterCounter) = prefs.edit().putBoolean(SHOW_CHARACTER_COUNTER, showCharacterCounter).apply()
|
||||||
|
|
||||||
|
var lockScreenVisibilitySetting: Int
|
||||||
|
get() = prefs.getInt(LOCK_SCREEN_VISIBILITY, LOCK_SCREEN_SENDER_MESSAGE)
|
||||||
|
set(lockScreenVisibilitySetting) = prefs.edit().putInt(LOCK_SCREEN_VISIBILITY, lockScreenVisibilitySetting).apply()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ const val SEARCHED_MESSAGE_ID = "searched_message_id"
|
||||||
const val USE_SIM_ID_PREFIX = "use_sim_id_"
|
const val USE_SIM_ID_PREFIX = "use_sim_id_"
|
||||||
const val NOTIFICATION_CHANNEL = "simple_sms_messenger"
|
const val NOTIFICATION_CHANNEL = "simple_sms_messenger"
|
||||||
const val SHOW_CHARACTER_COUNTER = "show_character_counter"
|
const val SHOW_CHARACTER_COUNTER = "show_character_counter"
|
||||||
|
const val LOCK_SCREEN_VISIBILITY = "lock_screen_visibility"
|
||||||
|
|
||||||
private const val PATH = "com.simplemobiletools.smsmessenger.action."
|
private const val PATH = "com.simplemobiletools.smsmessenger.action."
|
||||||
const val MARK_AS_READ = PATH + "mark_as_read"
|
const val MARK_AS_READ = PATH + "mark_as_read"
|
||||||
|
@ -26,6 +27,11 @@ const val THREAD_SENT_MESSAGE_ERROR = 4
|
||||||
const val THREAD_SENT_MESSAGE_SUCCESS = 5
|
const val THREAD_SENT_MESSAGE_SUCCESS = 5
|
||||||
const val THREAD_SENT_MESSAGE_SENDING = 6
|
const val THREAD_SENT_MESSAGE_SENDING = 6
|
||||||
|
|
||||||
|
// lock screen visibility constants
|
||||||
|
const val LOCK_SCREEN_SENDER_MESSAGE = 1
|
||||||
|
const val LOCK_SCREEN_SENDER = 2
|
||||||
|
const val LOCK_SCREEN_NOTHING = 3
|
||||||
|
|
||||||
fun refreshMessages() {
|
fun refreshMessages() {
|
||||||
EventBus.getDefault().post(Events.RefreshMessages())
|
EventBus.getDefault().post(Events.RefreshMessages())
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,5 +193,35 @@
|
||||||
app:switchPadding="@dimen/medium_margin" />
|
app:switchPadding="@dimen/medium_margin" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/settings_lock_screen_visibility_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.MyTextView
|
||||||
|
android:id="@+id/settings_lock_screen_visibility_label"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:paddingStart="@dimen/medium_margin"
|
||||||
|
android:text="@string/lock_screen_visibility" />
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/settings_lock_screen_visibility"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_marginEnd="@dimen/medium_margin"
|
||||||
|
android:background="@null"
|
||||||
|
android:clickable="false" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
|
@ -44,6 +44,11 @@
|
||||||
<item quantity="other">%d messages</item>
|
<item quantity="other">%d messages</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
|
||||||
|
<!-- Settings -->
|
||||||
|
<string name="lock_screen_visibility">Lock screen notification visibility</string>
|
||||||
|
<string name="sender_and_message">Sender and message</string>
|
||||||
|
<string name="sender_only">Sender only</string>
|
||||||
|
|
||||||
<!-- FAQ -->
|
<!-- FAQ -->
|
||||||
<string name="faq_1_title">Why does the app require access to the internet?</string>
|
<string name="faq_1_title">Why does the app require access to the internet?</string>
|
||||||
<string name="faq_1_text">Sadly it is needed for sending MMS attachments. Not being able to send MMS would be a really huge disadvantage compared to other apps, so we decided to go this way.
|
<string name="faq_1_text">Sadly it is needed for sending MMS attachments. Not being able to send MMS would be a really huge disadvantage compared to other apps, so we decided to go this way.
|
||||||
|
|
Loading…
Reference in New Issue