mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Add list list preference for #148
This commit is contained in:
@@ -41,8 +41,8 @@ public class ConversationPrefsHelper {
|
||||
return getBoolean(SettingsFragment.NOTIFICATION_TICKER, true);
|
||||
}
|
||||
|
||||
public boolean getPrivateNotificationsEnabled() {
|
||||
return getBoolean(SettingsFragment.NOTIFICATION_PRIVATE, false);
|
||||
public Integer getPrivateNotificationsSetting(){
|
||||
return Integer.parseInt(mPrefs.getString(SettingsFragment.PRIVATE_NOTIFICATION, "0"));
|
||||
}
|
||||
|
||||
public boolean getVibrateEnabled() {
|
||||
|
||||
@@ -185,11 +185,17 @@ public class NotificationManager {
|
||||
builder.setLights(getLedColour(conversationPrefs), 1000, 1000);
|
||||
}
|
||||
|
||||
boolean privateNotifications = conversationPrefs.getPrivateNotificationsEnabled();
|
||||
Integer privateNotifications = conversationPrefs.getPrivateNotificationsSetting();
|
||||
|
||||
if (conversationPrefs.getTickerEnabled()) {
|
||||
String messageBody = privateNotifications ? sRes.getString(R.string.new_message) : lastMessage.mBody;
|
||||
builder.setTicker(String.format("%s: %s", lastMessage.mContact, messageBody));
|
||||
switch (privateNotifications) {
|
||||
case 0:
|
||||
builder.setTicker(String.format("%s: %s", lastMessage.mContact, lastMessage.mBody));
|
||||
case 1:
|
||||
builder.setTicker(String.format("%s: %s", lastMessage.mContact, sRes.getString(R.string.new_message)));
|
||||
case 2:
|
||||
builder.setTicker(String.format("%s: %s", "QKSMS", sRes.getString(R.string.new_message)));
|
||||
}
|
||||
}
|
||||
|
||||
if (conversationPrefs.getWakePhoneEnabled()) {
|
||||
@@ -266,7 +272,7 @@ public class NotificationManager {
|
||||
builder.setLights(getLedColour(conversationPrefs), 1000, 1000);
|
||||
}
|
||||
|
||||
boolean privateNotifications = conversationPrefs.getPrivateNotificationsEnabled();
|
||||
Integer privateNotifications = conversationPrefs.getPrivateNotificationsSetting();
|
||||
|
||||
if (conversations.size() == 1 && lastConversation.size() == 1) {
|
||||
singleMessage(context, lastConversation, threadId, builder, conversationPrefs, privateNotifications);
|
||||
@@ -312,11 +318,18 @@ public class NotificationManager {
|
||||
PI = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
|
||||
boolean privateNotifications = sPrefs.getBoolean(SettingsFragment.NOTIFICATION_PRIVATE, false);
|
||||
|
||||
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
|
||||
|
||||
for (Message message : SmsHelper.getFailedMessages(context)) {
|
||||
String body = privateNotifications ? sRes.getString(R.string.new_message) : message.getBody();
|
||||
inboxStyle.addLine(Html.fromHtml("<strong>" + message.getName() + "</strong> " + body));
|
||||
switch (Integer.parseInt(sPrefs.getString(SettingsFragment.PRIVATE_NOTIFICATION, "0"))) {
|
||||
case 0:
|
||||
inboxStyle.addLine(Html.fromHtml("<strong>" + message.getName() + "</strong> " + message.getBody()));
|
||||
case 1:
|
||||
inboxStyle.addLine(Html.fromHtml("<strong>" + message.getName() + "</strong> " + sRes.getString(R.string.new_message)));
|
||||
case 2:
|
||||
inboxStyle.addLine(Html.fromHtml("<strong>" + "QKSMS" + "</strong> " + sRes.getString(R.string.new_message)));
|
||||
}
|
||||
}
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
|
||||
@@ -411,7 +424,7 @@ public class NotificationManager {
|
||||
*/
|
||||
private static void singleMessage(final Context context, final ArrayList<MessageItem> messages, final long threadId,
|
||||
final NotificationCompat.Builder builder, final ConversationPrefsHelper conversationPrefs,
|
||||
final boolean privateNotifications) {
|
||||
final Integer privateNotifications) {
|
||||
|
||||
MessageItem message = messages.get(0);
|
||||
|
||||
@@ -442,7 +455,7 @@ public class NotificationManager {
|
||||
*/
|
||||
private static void buildSingleMessageNotification(final Context context, ArrayList<MessageItem> messages, long threadId,
|
||||
final NotificationCompat.Builder builder, ConversationPrefsHelper conversationPrefs,
|
||||
final boolean privateNotifications) {
|
||||
final Integer privateNotifications) {
|
||||
|
||||
MessageItem message = messages.get(0);
|
||||
|
||||
@@ -464,12 +477,35 @@ public class NotificationManager {
|
||||
final PendingIntent seenPI = PendingIntent.getBroadcast(context, buildRequestCode(threadId, 4), seenIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
int unreadMessageCount = SmsHelper.getUnreadMessageCount(context);
|
||||
builder.setContentTitle(message.mContact)
|
||||
.setContentText(privateNotifications ? sRes.getString(R.string.new_message) : message.mBody)
|
||||
.setLargeIcon(getLargeIcon(context, Contact.get(message.mAddress, false)))
|
||||
String body;
|
||||
String title;
|
||||
NotificationCompat.Style nstyle = null;
|
||||
switch (privateNotifications){
|
||||
case 0: //Hide nothing
|
||||
body = message.mBody;
|
||||
title = message.mContact;
|
||||
nstyle = new NotificationCompat.BigTextStyle().bigText(message.mBody);
|
||||
break;
|
||||
case 1: //Hide message
|
||||
body = sRes.getString(R.string.new_message);
|
||||
title = message.mContact;
|
||||
break;
|
||||
case 2: //Hide sender & message
|
||||
body = sRes.getString(R.string.new_message);
|
||||
title = "QKSMS";
|
||||
break;
|
||||
default:
|
||||
body = message.mBody;
|
||||
title = message.mContact;
|
||||
nstyle = null;
|
||||
}
|
||||
|
||||
builder.setContentTitle(title)
|
||||
.setContentText(body)
|
||||
.setLargeIcon(getLargeIcon(context, Contact.get(message.mAddress, false), privateNotifications))
|
||||
.setContentIntent(threadPI)
|
||||
.setNumber(unreadMessageCount)
|
||||
.setStyle(privateNotifications ? null : new NotificationCompat.BigTextStyle().bigText(message.mBody))
|
||||
.setStyle(nstyle)
|
||||
.addAction(R.drawable.ic_reply, sRes.getString(R.string.reply), replyPI)
|
||||
.addAction(R.drawable.ic_accept, sRes.getString(R.string.read), readPI)
|
||||
.extend(WearableIntentReceiver.getSingleConversationExtender(context, message.mContact, message.mAddress, threadId))
|
||||
@@ -494,16 +530,15 @@ public class NotificationManager {
|
||||
NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle()
|
||||
.setBigContentTitle(message.mContact)
|
||||
.setSummaryText(message.mBody)
|
||||
.bigLargeIcon(getLargeIcon(context, Contact.get(message.mAddress, false)))
|
||||
.bigLargeIcon(getLargeIcon(context, Contact.get(message.mAddress, false), privateNotifications))
|
||||
.bigPicture(image);
|
||||
if (privateNotifications == 0) builder.setStyle(style);
|
||||
else builder.setStyle(null);
|
||||
|
||||
builder.setStyle(privateNotifications ? null : style);
|
||||
} else {
|
||||
Log.d(TAG, "MMS Type: not an image lol");
|
||||
NotificationCompat.BigTextStyle style = privateNotifications ?
|
||||
null : new NotificationCompat.BigTextStyle().bigText(message.mBody);
|
||||
|
||||
builder.setStyle(style);
|
||||
if (privateNotifications == 0) builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message.mBody));
|
||||
else builder.setStyle(null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -516,7 +551,7 @@ public class NotificationManager {
|
||||
*/
|
||||
private static void singleSender(final Context context, ArrayList<MessageItem> messages, long threadId,
|
||||
final NotificationCompat.Builder builder, ConversationPrefsHelper conversationPrefs,
|
||||
final boolean privateNotifications) {
|
||||
final Integer privateNotifications) {
|
||||
|
||||
MessageItem message = messages.get(0);
|
||||
|
||||
@@ -542,13 +577,17 @@ public class NotificationManager {
|
||||
inboxStyle.addLine(message1.mBody);
|
||||
}
|
||||
|
||||
NotificationCompat.Style stylen;
|
||||
if (privateNotifications == 0) stylen = inboxStyle;
|
||||
else stylen = null;
|
||||
|
||||
int unreadMessageCount = SmsHelper.getUnreadMessageCount(context);
|
||||
builder.setContentTitle(message.mContact)
|
||||
.setContentText(SmsHelper.getUnseenSMSCount(context, threadId) + " " + sRes.getString(R.string.new_messages))
|
||||
.setLargeIcon(getLargeIcon(context, Contact.get(message.mAddress, false)))
|
||||
.setLargeIcon(getLargeIcon(context, Contact.get(message.mAddress, false), privateNotifications))
|
||||
.setContentIntent(threadPI)
|
||||
.setNumber(unreadMessageCount)
|
||||
.setStyle(privateNotifications ? null : inboxStyle)
|
||||
.setStyle(stylen)
|
||||
.addAction(R.drawable.ic_reply, sRes.getString(R.string.reply), replyPI)
|
||||
.addAction(R.drawable.ic_accept, sRes.getString(R.string.read), readPI)
|
||||
.extend(WearableIntentReceiver.getSingleConversationExtender(context, message.mContact, message.mAddress, threadId))
|
||||
@@ -580,9 +619,9 @@ public class NotificationManager {
|
||||
if (!oldThreads.contains(threadId)) {
|
||||
ConversationPrefsHelper conversationPrefs = new ConversationPrefsHelper(context, threadId);
|
||||
if (conversations.get(threadId).size() == 1) {
|
||||
singleMessage(context, conversations.get(threadId), threadId, copyBuilder(builder), conversationPrefs, false);
|
||||
singleMessage(context, conversations.get(threadId), threadId, copyBuilder(builder), conversationPrefs, 0);
|
||||
} else {
|
||||
singleSender(context, conversations.get(threadId), threadId, copyBuilder(builder), conversationPrefs, false);
|
||||
singleSender(context, conversations.get(threadId), threadId, copyBuilder(builder), conversationPrefs, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -655,17 +694,21 @@ public class NotificationManager {
|
||||
* Retreives the avatar to be used for the notification's large icon. If the user is running Lollipop, then let's
|
||||
* crop their avatar to a circle
|
||||
*/
|
||||
private static Bitmap getLargeIcon(Context context, Contact contact) {
|
||||
private static Bitmap getLargeIcon(Context context, Contact contact, Integer privateNotification) {
|
||||
Drawable avatarDrawable = contact.getAvatar(context, new BitmapDrawable(sRes, ContactHelper.blankContact(context, contact.getName())));
|
||||
int idealIconWidth = sRes.getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
|
||||
int idealIconHeight = sRes.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
|
||||
|
||||
Bitmap bitmap = Bitmap.createScaledBitmap(((BitmapDrawable) avatarDrawable).getBitmap(), idealIconWidth, idealIconHeight, true);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
return ImageUtils.getCircleBitmap(bitmap, idealIconWidth);
|
||||
} else {
|
||||
return bitmap;
|
||||
if (privateNotification == 2) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
return ImageUtils.getCircleBitmap(bitmap, idealIconWidth);
|
||||
}
|
||||
else return bitmap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-3
@@ -99,9 +99,6 @@ public class ConversationNotificationSettingsDialog extends QKDialog implements
|
||||
list.addView(new QKCheckBoxPreference(getActivity(), this, SettingsFragment.NOTIFICATION_TICKER,
|
||||
mConversationPrefs.getConversationPrefs(), mConversationPrefs.getTickerEnabled(), R.string.pref_ticker, R.string.pref_ticker_summary).getView());
|
||||
|
||||
list.addView(new QKCheckBoxPreference(getActivity(), this, SettingsFragment.NOTIFICATION_PRIVATE,
|
||||
mConversationPrefs.getConversationPrefs(), mConversationPrefs.getPrivateNotificationsEnabled(), R.string.pref_notifications_private, R.string.pref_notifications_private_summary).getView());
|
||||
|
||||
list.addView(new QKCheckBoxPreference(getActivity(), this, SettingsFragment.NOTIFICATION_VIBRATE,
|
||||
mConversationPrefs.getConversationPrefs(), mConversationPrefs.getVibrateEnabled(), R.string.pref_vibration, R.string.pref_vibration_summary).getView());
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ public class SettingsFragment extends PreferenceFragment implements
|
||||
public static final String NOTIFICATION_LED_COLOR = "pref_key_theme_led";
|
||||
public static final String WAKE = "pref_key_wake";
|
||||
public static final String NOTIFICATION_TICKER = "pref_key_ticker";
|
||||
public static final String NOTIFICATION_PRIVATE = "pref_key_notifications_private";
|
||||
public static final String PRIVATE_NOTIFICATION = "pref_key_notification_private";
|
||||
public static final String NOTIFICATION_VIBRATE = "pref_key_vibration";
|
||||
public static final String NOTIFICATION_TONE = "pref_key_ringtone";
|
||||
public static final String NOTIFICATION_CALL_BUTTON = "pref_key_notification_call";
|
||||
|
||||
@@ -196,7 +196,7 @@
|
||||
<string name="pref_wake">Wake phone</string>
|
||||
<string name="pref_wake_summary">Turn your screen on when you receive a new message</string>
|
||||
<string name="pref_notifications_private">Private notifications</string>
|
||||
<string name="pref_notifications_private_summary">Hide message text in notifications</string>
|
||||
<string name="pref_notifications_private_summary">Tap to change what should be hidden in notfication</string>
|
||||
<string name="pref_ringtone">Notification sound</string>
|
||||
<string name="pref_ringtone_summary">Select a notification sound</string>
|
||||
<string name="pref_ticker">Show ticker</string>
|
||||
@@ -778,6 +778,12 @@
|
||||
<item>Send message</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="notification_private_options">
|
||||
<item>Show all</item>
|
||||
<item>Hide message</item>
|
||||
<item>Hide message and sender</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Max MMS attachment sizes. I.e. will compress pictures that are larger than 300 KB down to
|
||||
under 300KB. -->
|
||||
<string-array name="max_mms_attachment_sizes">
|
||||
|
||||
@@ -106,8 +106,8 @@
|
||||
android:defaultValue="true"
|
||||
android:key="pref_key_ticker" />
|
||||
<Preference
|
||||
android:defaultValue="false"
|
||||
android:key="pref_key_notifications_private" />
|
||||
android:defaultValue="0"
|
||||
android:key="pref_key_notification_private" />
|
||||
<Preference
|
||||
android:defaultValue="true"
|
||||
android:key="pref_key_vibration" />
|
||||
|
||||
@@ -39,14 +39,14 @@
|
||||
android:summary="@string/pref_ticker_summary"
|
||||
android:title="@string/pref_ticker"
|
||||
android:widgetLayout="@layout/view_checkbox" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:dependency="pref_key_notifications"
|
||||
android:key="pref_key_notifications_private"
|
||||
<ListPreference
|
||||
android:defaultValue="0"
|
||||
android:entries="@array/notification_private_options"
|
||||
android:entryValues="@array/enter_button_values"
|
||||
android:key="pref_key_notification_private"
|
||||
android:layout="@layout/list_item_preference"
|
||||
android:summary="@string/pref_notifications_private_summary"
|
||||
android:title="@string/pref_notifications_private"
|
||||
android:widgetLayout="@layout/view_checkbox" />
|
||||
android:title="@string/pref_notifications_private" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:dependency="pref_key_notifications"
|
||||
|
||||
Reference in New Issue
Block a user