This commit is contained in:
Mariotaku Lee 2016-02-19 11:50:17 +08:00
parent 473b2fa7be
commit 01cfec55dd
4 changed files with 91 additions and 66 deletions

View File

@ -24,6 +24,7 @@ import android.content.SharedPreferences;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils; import android.text.TextUtils;
import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.Constants;
@ -49,7 +50,11 @@ public class AccountPreferences implements Constants {
public int getDefaultNotificationLightColor() { public int getDefaultNotificationLightColor() {
final ParcelableAccount a = DataStoreUtils.getAccount(mContext, mAccountId); final ParcelableAccount a = DataStoreUtils.getAccount(mContext, mAccountId);
return a != null ? a.color : mContext.getResources().getColor(R.color.branding_color); if (a != null) {
return a.color;
} else {
return ContextCompat.getColor(mContext, R.color.branding_color);
}
} }
public int getDirectMessagesNotificationType() { public int getDirectMessagesNotificationType() {
@ -69,9 +74,12 @@ public class AccountPreferences implements Constants {
} }
public Uri getNotificationRingtone() { public Uri getNotificationRingtone() {
final Uri def = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); final String ringtone = mPreferences.getString(KEY_NOTIFICATION_RINGTONE, null);
final String path = mPreferences.getString(KEY_NOTIFICATION_RINGTONE, null); if (TextUtils.isEmpty(ringtone)) {
return TextUtils.isEmpty(path) ? def : Uri.parse(path); return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
} else {
return Uri.parse(ringtone);
}
} }
public boolean isAutoRefreshDirectMessagesEnabled() { public boolean isAutoRefreshDirectMessagesEnabled() {

View File

@ -65,6 +65,7 @@ public class NotificationTypePreference extends DialogPreference implements Cons
} }
} }
persistInt(value); persistInt(value);
notifyChanged();
} }
@Override @Override
@ -94,9 +95,25 @@ public class NotificationTypePreference extends DialogPreference implements Cons
return entries; return entries;
} }
@Override
public CharSequence getSummary() {
final StringBuilder sb = new StringBuilder();
String[] entries = getEntries();
boolean[] states = getCheckedItems(getPersistedInt(mDefaultValue));
for (int i = 0, j = entries.length; i < j; i++) {
if (states[i]) {
if (sb.length() != 0) {
sb.append(", ");
}
sb.append(entries[i]);
}
}
return sb;
}
private int[] getFlags() { private int[] getFlags() {
return new int[] { VALUE_NOTIFICATION_FLAG_RINGTONE, VALUE_NOTIFICATION_FLAG_VIBRATION, return new int[]{VALUE_NOTIFICATION_FLAG_RINGTONE, VALUE_NOTIFICATION_FLAG_VIBRATION,
VALUE_NOTIFICATION_FLAG_LIGHT }; VALUE_NOTIFICATION_FLAG_LIGHT};
} }
} }

View File

@ -1318,7 +1318,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
if (count == 0) return; if (count == 0) return;
builder.setSmallIcon(R.drawable.ic_stat_notification); builder.setSmallIcon(R.drawable.ic_stat_notification);
builder.setCategory(NotificationCompat.CATEGORY_SOCIAL); builder.setCategory(NotificationCompat.CATEGORY_SOCIAL);
applyNotificationPreferences(builder, pref, pref.getHomeTimelineNotificationType()); applyNotificationPreferences(builder, pref, pref.getMentionsNotificationType());
final Resources resources = context.getResources(); final Resources resources = context.getResources();
final String accountName = DataStoreUtils.getAccountDisplayName(context, accountId, mNameFirst); final String accountName = DataStoreUtils.getAccountDisplayName(context, accountId, mNameFirst);
@ -1434,7 +1434,6 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
notificationDefaults &= ~NotificationCompat.DEFAULT_VIBRATE; notificationDefaults &= ~NotificationCompat.DEFAULT_VIBRATE;
} }
if (AccountPreferences.isNotificationHasRingtone(defaultFlags)) { if (AccountPreferences.isNotificationHasRingtone(defaultFlags)) {
notificationDefaults |= NotificationCompat.DEFAULT_SOUND;
builder.setSound(pref.getNotificationRingtone(), AudioManager.STREAM_NOTIFICATION); builder.setSound(pref.getNotificationRingtone(), AudioManager.STREAM_NOTIFICATION);
} }
} else { } else {

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/notifications"> android:title="@string/notifications">