now delete notification can also mark read.

fixed crashes in notification settings due to non exists key "stream_notification"
This commit is contained in:
Mariotaku Lee 2015-04-08 18:39:25 +08:00
parent 8f645d3112
commit 31171ad05e
6 changed files with 21 additions and 57 deletions

View File

@ -88,6 +88,7 @@ dependencies {
compile 'com.github.uucky:ColorPicker-Android:0.9.1' compile 'com.github.uucky:ColorPicker-Android:0.9.1'
compile 'com.sprylab.android.texturevideoview:texturevideoview:1.0.0' compile 'com.sprylab.android.texturevideoview:texturevideoview:1.0.0'
compile 'com.squareup:pollexor:2.0.2' compile 'com.squareup:pollexor:2.0.2'
compile 'org.apache.commons:commons-lang3:3.4'
googleCompile 'com.google.android.gms:play-services-maps:7.0.0' googleCompile 'com.google.android.gms:play-services-maps:7.0.0'
googleCompile 'com.google.maps.android:android-maps-utils:0.3.4' googleCompile 'com.google.maps.android:android-maps-utils:0.3.4'
fdroidCompile 'org.osmdroid:osmdroid-android:4.3' fdroidCompile 'org.osmdroid:osmdroid-android:4.3'

View File

@ -216,13 +216,13 @@ public final class MediaViewerActivity extends ThemedActionBarActivity implement
@Override @Override
public void onPrepared(MediaPlayer mp) { public void onPrepared(MediaPlayer mp) {
if (getUserVisibleHint()) { if (getUserVisibleHint()) {
mp.start();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC); mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
if (mPlayAudio) { if (mPlayAudio) {
mp.setVolume(1, 1); mp.setVolume(1, 1);
} else { } else {
mp.setVolume(0, 0); mp.setVolume(0, 0);
} }
mp.start();
} }
} }

View File

@ -19,7 +19,6 @@
package org.mariotaku.twidere.provider; package org.mariotaku.twidere.provider;
import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@ -522,46 +521,6 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
} }
} }
private void buildNotification(final NotificationCompat.Builder builder, final AccountPreferences accountPrefs,
final int notificationType, final String ticker, final String title, final String message, final long when,
final int icon, final Bitmap largeIcon, final Intent contentIntent, final Intent deleteIntent) {
final Context context = getContext();
builder.setTicker(ticker);
builder.setContentTitle(title);
builder.setContentText(message);
builder.setAutoCancel(true);
builder.setWhen(System.currentTimeMillis());
builder.setSmallIcon(icon);
if (largeIcon != null) {
builder.setLargeIcon(largeIcon);
}
if (deleteIntent != null) {
builder.setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent,
PendingIntent.FLAG_UPDATE_CURRENT));
}
if (contentIntent != null) {
builder.setContentIntent(PendingIntent.getActivity(context, 0, contentIntent,
PendingIntent.FLAG_UPDATE_CURRENT));
}
int defaults = 0;
if (isNotificationAudible()) {
if (AccountPreferences.isNotificationHasRingtone(notificationType)) {
final Uri ringtone = accountPrefs.getNotificationRingtone();
builder.setSound(ringtone, Notification.STREAM_DEFAULT);
}
if (AccountPreferences.isNotificationHasVibration(notificationType)) {
defaults |= Notification.DEFAULT_VIBRATE;
} else {
defaults &= ~Notification.DEFAULT_VIBRATE;
}
}
if (AccountPreferences.isNotificationHasLight(notificationType)) {
final int color = accountPrefs.getNotificationLightColor();
builder.setLights(color, 1000, 2000);
}
builder.setDefaults(defaults);
}
private boolean checkPermission(final String... permissions) { private boolean checkPermission(final String... permissions) {
return mPermissionsManager.checkCallingPermission(permissions); return mPermissionsManager.checkCallingPermission(permissions);
} }
@ -1039,6 +998,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
private static PendingIntent getDeleteIntent(Context context, String type, long accountId, long position) { private static PendingIntent getDeleteIntent(Context context, String type, long accountId, long position) {
// Setup delete intent // Setup delete intent
final Intent recvIntent = new Intent(context, NotificationReceiver.class); final Intent recvIntent = new Intent(context, NotificationReceiver.class);
recvIntent.setAction(BROADCAST_NOTIFICATION_DELETED);
final Uri.Builder recvLinkBuilder = new Uri.Builder(); final Uri.Builder recvLinkBuilder = new Uri.Builder();
recvLinkBuilder.scheme(SCHEME_TWIDERE); recvLinkBuilder.scheme(SCHEME_TWIDERE);
recvLinkBuilder.authority(AUTHORITY_NOTIFICATIONS); recvLinkBuilder.authority(AUTHORITY_NOTIFICATIONS);
@ -1067,13 +1027,19 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
if (AccountPreferences.isNotificationHasLight(defaultFlags)) { if (AccountPreferences.isNotificationHasLight(defaultFlags)) {
notificationDefaults |= NotificationCompat.DEFAULT_LIGHTS; notificationDefaults |= NotificationCompat.DEFAULT_LIGHTS;
} }
if (isNotificationAudible()) {
if (AccountPreferences.isNotificationHasVibration(defaultFlags)) { if (AccountPreferences.isNotificationHasVibration(defaultFlags)) {
notificationDefaults |= NotificationCompat.DEFAULT_VIBRATE; notificationDefaults |= NotificationCompat.DEFAULT_VIBRATE;
} else {
notificationDefaults &= ~NotificationCompat.DEFAULT_VIBRATE;
} }
if (AccountPreferences.isNotificationHasRingtone(defaultFlags)) { if (AccountPreferences.isNotificationHasRingtone(defaultFlags)) {
notificationDefaults |= NotificationCompat.DEFAULT_SOUND; notificationDefaults |= NotificationCompat.DEFAULT_SOUND;
builder.setSound(pref.getNotificationRingtone(), AudioManager.STREAM_NOTIFICATION); builder.setSound(pref.getNotificationRingtone(), AudioManager.STREAM_NOTIFICATION);
} }
} else {
notificationDefaults &= ~(NotificationCompat.DEFAULT_VIBRATE | NotificationCompat.DEFAULT_SOUND);
}
builder.setDefaults(notificationDefaults); builder.setDefaults(notificationDefaults);
} }
@ -1281,10 +1247,6 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
return count; return count;
} }
private static <T> T safeGet(final List<T> list, final int index) {
return index >= 0 && index < list.size() ? list.get(index) : null;
}
private static boolean shouldReplaceOnConflict(final int table_id) { private static boolean shouldReplaceOnConflict(final int table_id) {
switch (table_id) { switch (table_id) {
case TABLE_ID_CACHED_HASHTAGS: case TABLE_ID_CACHED_HASHTAGS:

View File

@ -39,7 +39,9 @@ import org.mariotaku.twidere.util.Utils;
public class NotificationReceiver extends BroadcastReceiver implements Constants { public class NotificationReceiver extends BroadcastReceiver implements Constants {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) { final String action = intent.getAction();
if (action == null) return;
switch (action) {
case BROADCAST_NOTIFICATION_DELETED: { case BROADCAST_NOTIFICATION_DELETED: {
final Uri uri = intent.getData(); final Uri uri = intent.getData();
final String tag = getPositionTag(uri.getLastPathSegment()); final String tag = getPositionTag(uri.getLastPathSegment());

View File

@ -217,7 +217,7 @@ public class BackgroundOperationService extends IntentService implements Constan
} }
private Notification buildNotification(final String title, final String message, final int icon, private Notification buildNotification(final String title, final String message, final int icon,
final Intent content_intent, final Intent delete_intent) { final Intent content_intent, final Intent deleteIntent) {
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setTicker(message); builder.setTicker(message);
builder.setContentTitle(title); builder.setContentTitle(title);
@ -225,8 +225,8 @@ public class BackgroundOperationService extends IntentService implements Constan
builder.setAutoCancel(true); builder.setAutoCancel(true);
builder.setWhen(System.currentTimeMillis()); builder.setWhen(System.currentTimeMillis());
builder.setSmallIcon(icon); builder.setSmallIcon(icon);
if (delete_intent != null) { if (deleteIntent != null) {
builder.setDeleteIntent(PendingIntent.getBroadcast(this, 0, delete_intent, builder.setDeleteIntent(PendingIntent.getBroadcast(this, 0, deleteIntent,
PendingIntent.FLAG_UPDATE_CURRENT)); PendingIntent.FLAG_UPDATE_CURRENT));
} }
if (content_intent != null) { if (content_intent != null) {

View File

@ -27,7 +27,6 @@
<org.mariotaku.twidere.preference.AutoFixCheckBoxPreference <org.mariotaku.twidere.preference.AutoFixCheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="pebble_notifications" android:key="pebble_notifications"
android:dependency="stream_notifications"
android:summary="@string/pebble_notifications_summary" android:summary="@string/pebble_notifications_summary"
android:title="@string/pebble_notifications"/> android:title="@string/pebble_notifications"/>
</PreferenceCategory> </PreferenceCategory>