Merge branch 'vanita5-master'

This commit is contained in:
Mariotaku Lee 2015-04-08 00:40:22 +08:00
commit fbc347b3a2
8 changed files with 52 additions and 0 deletions

View File

@ -73,6 +73,8 @@ public interface IntentConstants {
public static final String INTENT_ACTION_DISCARD_DRAFT = INTENT_PACKAGE_PREFIX + "DISCARD_DRAFT";
public static final String INTENT_ACTION_PICK_ACTIVITY = "org.mariotaku.twidere.PICK_ACTIVITY";
public static final String INTENT_ACTION_PEBBLE_NOTIFICATION = "com.getpebble.action.SEND_NOTIFICATION";
public static final String BROADCAST_NOTIFICATION_DELETED = INTENT_PACKAGE_PREFIX + "NOTIFICATION_DELETED";
public static final String BROADCAST_USER_LIST_DETAILS_UPDATED = INTENT_PACKAGE_PREFIX
+ "USER_LIST_DETAILS_UPDATED";

View File

@ -267,6 +267,8 @@ public interface SharedPreferenceConstants {
String KEY_NOTIFICATION_TYPE_MENTIONS = "notification_type_mentions";
String KEY_NOTIFICATION_TYPE_DIRECT_MESSAGES = "notification_type_direct_messages";
String KEY_NOTIFICATION_FOLLOWING_ONLY = "notification_following_only";
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = false)
String KEY_PEBBLE_NOTIFICATIONS = "pebble_notifications";
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = false)
String KEY_COMPACT_CARDS = "compact_cards";

View File

@ -919,6 +919,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
builder.setColor(pref.getNotificationLightColor());
setNotificationPreferences(builder, pref, pref.getHomeTimelineNotificationType());
nm.notify("home_" + accountId, NOTIFICATION_ID_HOME_TIMELINE, builder.build());
Utils.sendPebbleNotification(context, notificationContent);
} finally {
statusCursor.close();
userCursor.close();
@ -1017,6 +1018,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
setNotificationPreferences(builder, pref, pref.getMentionsNotificationType());
nm.notify("mentions_" + accountId, NOTIFICATION_ID_MENTIONS_TIMELINE,
builder.build());
Utils.sendPebbleNotification(context, notificationContent);
} finally {
statusCursor.close();
userCursor.close();
@ -1201,6 +1203,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
builder.setColor(pref.getNotificationLightColor());
setNotificationPreferences(builder, pref, pref.getDirectMessagesNotificationType());
nm.notify("messages_" + accountId, NOTIFICATION_ID_DIRECT_MESSAGES, builder.build());
Utils.sendPebbleNotification(context, notificationContent);
} finally {
messageCursor.close();
userCursor.close();

View File

@ -112,7 +112,9 @@ import android.widget.Toast;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.http.protocol.HTTP;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.mariotaku.jsonserializer.JSONSerializer;
import org.mariotaku.querybuilder.AllColumns;
import org.mariotaku.querybuilder.Columns;
@ -4220,4 +4222,35 @@ public final class Utils implements Constants, TwitterConstants {
}
}
/**
* Send Notifications to Pebble smartwatches
*
* @param context Context
* @param message String
*/
public static void sendPebbleNotification(final Context context, final String message) {
if (context == null || TextUtils.isEmpty(message)) return;
final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
if (prefs.getBoolean(KEY_PEBBLE_NOTIFICATIONS, false)) {
final String app_name = context.getString(R.string.app_name);
final HashMap<String, String> data = new HashMap<>();
data.put("title", app_name);
data.put("body", message);
final JSONObject jsonData = new JSONObject(data);
final String notificationData = new JSONArray().put(jsonData).toString();
final Intent intent = new Intent(INTENT_ACTION_PEBBLE_NOTIFICATION);
intent.putExtra("messageType", "PEBBLE_ALERT");
intent.putExtra("sender", app_name);
intent.putExtra("notificationData", notificationData);
context.getApplicationContext().sendBroadcast(intent);
}
}
}

View File

@ -707,4 +707,5 @@
<string name="usage_statistics_header_summary">Twidere hat an einem Forschungsprojekt teilgenommen, an diesem Projekt mitzumachen wird Twidere und andere Anwendungen verbessern.</string>
<string name="no_tab">Kein Tab</string>
<string name="user_protected_summary">Du musst eine Follow-Anfrage an diesen geschützten Nutzer schicken um Tweets zu sehen</string>
<string name="pebble_notifications_summary">Notifications an Pebble senden</string>
</resources>

View File

@ -732,4 +732,6 @@
<string name="scale">Escalar</string>
<string name="user_type_verified">Verificado</string>
<string name="user_type_protected">Protegido</string>
<string name="pebble_notifications">Pebble</string>
<string name="pebble_notifications_summary">Enviar notificaciones a Pebble</string>
</resources>

View File

@ -734,6 +734,8 @@
<string name="user_type_protected">Protected</string>
<string name="tweet_hashtag">Tweet #<xliff:g id="text">%1$s</xliff:g></string>
<string name="share_status">Share tweet</string>
<string name="pebble_notifications">Pebble Notifications</string>
<string name="pebble_notifications_summary">Send Notifications to your Pebble</string>
<!-- 'Tweet' here is a verb -->
<string name="tweet_from_name">Tweet from <xliff:g id="text">%1$s</xliff:g></string>
<string name="permission_label_shorten_status">Shorten tweet</string>

View File

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