Search in sources :

Example 1 with AppSettings

use of com.klinker.android.twitter.settings.AppSettings in project Talon-for-Twitter by klinker24.

the class HomeFragment method getTweet.

public boolean getTweet() {
    TweetMarkerHelper helper = new TweetMarkerHelper(currentAccount, sharedPrefs.getString("twitter_screen_name_" + currentAccount, ""), Utils.getTwitter(context, new AppSettings(context)), sharedPrefs);
    boolean updated = helper.getLastStatus("timeline", context);
    // update settings just in case it was invalidated
    settings = AppSettings.getInstance(getActivity());
    Log.v("talon_tweetmarker", "tweetmarker status: " + updated);
    if (updated) {
        //HomeContentProvider.updateCurrent(currentAccount, context, sharedPrefs.getLong("current_position_" + currentAccount, 0l));
        trueLive = true;
        return true;
    } else {
        return false;
    }
}
Also used : AppSettings(com.klinker.android.twitter.settings.AppSettings) TweetMarkerHelper(com.klinker.android.twitter.utils.api_helper.TweetMarkerHelper)

Example 2 with AppSettings

use of com.klinker.android.twitter.settings.AppSettings in project Talon-for-Twitter by klinker24.

the class HomeFragment method onStop.

@Override
public void onStop() {
    context.sendBroadcast(new Intent("com.klinker.android.twitter.CLEAR_PULL_UNREAD"));
    if (settings.tweetmarker && !isLauncher()) {
        new Thread(new Runnable() {

            @Override
            public void run() {
                TweetMarkerHelper helper = new TweetMarkerHelper(currentAccount, sharedPrefs.getString("twitter_screen_name_" + currentAccount, ""), Utils.getTwitter(context, new AppSettings(context)), sharedPrefs);
                long currentId = sharedPrefs.getLong("current_position_" + currentAccount, 0);
                helper.sendCurrentId("timeline", currentId);
            }
        }).start();
    }
    context.sendBroadcast(new Intent("com.klinker.android.talon.UPDATE_WIDGET"));
    //context.getContentResolver().notifyChange(HomeContentProvider.CONTENT_URI, null);
    super.onStop();
}
Also used : AppSettings(com.klinker.android.twitter.settings.AppSettings) TweetMarkerHelper(com.klinker.android.twitter.utils.api_helper.TweetMarkerHelper) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 3 with AppSettings

use of com.klinker.android.twitter.settings.AppSettings in project Talon-for-Twitter by klinker24.

the class NotificationUtils method notifySecondDMs.

public static void notifySecondDMs(Context context, int secondAccount) {
    DMDataSource data = DMDataSource.getInstance(context);
    SharedPreferences sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    int numberNew = sharedPrefs.getInt("dm_unread_" + secondAccount, 0);
    int smallIcon = R.drawable.ic_stat_icon;
    Bitmap largeIcon;
    Intent resultIntent = new Intent(context, SwitchAccountsRedirect.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
    NotificationCompat.Builder mBuilder;
    String title = context.getResources().getString(R.string.app_name) + " - " + context.getResources().getString(R.string.sec_acc);
    String name;
    String message;
    String messageLong;
    NotificationCompat.InboxStyle inbox = null;
    if (numberNew == 1) {
        name = data.getNewestName(secondAccount);
        // then just quit
        if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) {
            return;
        }
        message = context.getResources().getString(R.string.mentioned_by) + " @" + name;
        messageLong = "<b>@" + name + "</b>: " + data.getNewestMessage(secondAccount);
        largeIcon = getImage(context, name);
    } else {
        // more than one dm
        message = numberNew + " " + context.getResources().getString(R.string.new_mentions);
        messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " " + context.getResources().getString(R.string.new_mentions);
        largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark);
        inbox = getDMInboxStyle(numberNew, secondAccount, context, message);
    }
    Intent markRead = new Intent(context, MarkReadSecondAccService.class);
    PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);
    AppSettings settings = AppSettings.getInstance(context);
    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class);
    mBuilder = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon).setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setAutoCancel(true).setPriority(NotificationCompat.PRIORITY_HIGH);
    if (inbox == null) {
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong)));
    } else {
        mBuilder.setStyle(inbox);
    }
    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }
    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }
    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);
    if (settings.notifications) {
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
        notificationManager.notify(9, mBuilder.build());
        // if we want to wake the screen on a new message
        if (settings.wakeScreen) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
            wakeLock.acquire(5000);
        }
        // Pebble notification
        if (sharedPrefs.getBoolean("pebble_notification", false)) {
            sendAlertToPebble(context, title, messageLong);
        }
        // Light Flow notification
        sendToLightFlow(context, title, messageLong);
    }
}
Also used : AppSettings(com.klinker.android.twitter.settings.AppSettings) SharedPreferences(android.content.SharedPreferences) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PowerManager(android.os.PowerManager) Bitmap(android.graphics.Bitmap) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 4 with AppSettings

use of com.klinker.android.twitter.settings.AppSettings in project Talon-for-Twitter by klinker24.

the class NotificationUtils method newInteractions.

// type is either " retweeted your status", " favorited your status", or " followed you"
public static void newInteractions(User interactor, Context context, SharedPreferences sharedPrefs, String type) {
    String title = "";
    String text = "";
    String smallText = "";
    Bitmap icon = null;
    AppSettings settings = AppSettings.getInstance(context);
    Intent resultIntent = new Intent(context, RedirectToDrawer.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
    int newFollowers = sharedPrefs.getInt("new_followers", 0);
    int newRetweets = sharedPrefs.getInt("new_retweets", 0);
    int newFavorites = sharedPrefs.getInt("new_favorites", 0);
    int newQuotes = sharedPrefs.getInt("new_quotes", 0);
    // set title
    if (newFavorites + newRetweets + newFollowers > 1) {
        title = context.getResources().getString(R.string.new_interactions);
    } else {
        title = context.getResources().getString(R.string.new_interaction_upper);
    }
    // set text
    String currText = sharedPrefs.getString("old_interaction_text", "");
    if (!currText.equals("")) {
        currText += "<br>";
    }
    if (settings.displayScreenName) {
        text = currText + "<b>" + interactor.getScreenName() + "</b> " + type;
    } else {
        text = currText + "<b>" + interactor.getName() + "</b> " + type;
    }
    sharedPrefs.edit().putString("old_interaction_text", text).commit();
    // set icon
    int types = 0;
    if (newFavorites > 0) {
        types++;
    }
    if (newFollowers > 0) {
        types++;
    }
    if (newRetweets > 0) {
        types++;
    }
    if (newQuotes > 0) {
        types++;
    }
    if (types > 1) {
        icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_icon);
    } else {
        if (newFavorites > 0) {
            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_heart_dark);
        } else if (newRetweets > 0) {
            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_repeat_dark);
        } else {
            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark);
        }
    }
    // set shorter text
    int total = newFavorites + newFollowers + newRetweets + newQuotes;
    if (total > 1) {
        smallText = total + " " + context.getResources().getString(R.string.new_interactions_lower);
    } else {
        smallText = text;
    }
    Intent markRead = new Intent(context, ReadInteractionsService.class);
    PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);
    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(Html.fromHtml(settings.addonTheme ? smallText.replaceAll("FF8800", settings.accentColor) : smallText)).setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(icon).setContentIntent(resultPendingIntent).setTicker(title).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true);
    if (context.getResources().getBoolean(R.bool.expNotifications)) {
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(settings.addonTheme ? text.replaceAll("FF8800", settings.accentColor) : text)));
    }
    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }
    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }
    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);
    if (settings.notifications) {
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
        notificationManager.notify(4, mBuilder.build());
        // if we want to wake the screen on a new message
        if (settings.wakeScreen) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
            wakeLock.acquire(5000);
        }
        // Pebble notification
        if (sharedPrefs.getBoolean("pebble_notification", false)) {
            sendAlertToPebble(context, title, text);
        }
        // Light Flow notification
        sendToLightFlow(context, title, text);
    }
}
Also used : AppSettings(com.klinker.android.twitter.settings.AppSettings) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PowerManager(android.os.PowerManager) Bitmap(android.graphics.Bitmap) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 5 with AppSettings

use of com.klinker.android.twitter.settings.AppSettings in project Talon-for-Twitter by klinker24.

the class NotificationUtils method getDMInboxStyle.

private static NotificationCompat.InboxStyle getDMInboxStyle(int numberNew, int accountNumber, Context context, String title) {
    NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
    Cursor cursor = DMDataSource.getInstance(context).getCursor(accountNumber);
    if (!cursor.moveToLast()) {
        return style;
    }
    AppSettings settings = AppSettings.getInstance(context);
    if (numberNew > 5) {
        if (numberNew - 5 == 1) {
            style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_direct_message));
        } else {
            style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_direct_messages));
        }
        for (int i = 0; i < 5; i++) {
            String handle = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_SCREEN_NAME));
            String text = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_TEXT));
            String longText = "<b>@" + handle + "</b>: " + text;
            style.addLine(Html.fromHtml(settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText));
            cursor.moveToPrevious();
        }
    } else {
        for (int i = 0; i < numberNew; i++) {
            String handle = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_SCREEN_NAME));
            String text = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_TEXT));
            String longText = "<b>@" + handle + "</b>: " + text;
            style.addLine(Html.fromHtml(settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText));
            cursor.moveToPrevious();
        }
    }
    style.setBigContentTitle(title);
    return style;
}
Also used : AppSettings(com.klinker.android.twitter.settings.AppSettings) NotificationCompat(android.support.v4.app.NotificationCompat) Cursor(android.database.Cursor)

Aggregations

AppSettings (com.klinker.android.twitter.settings.AppSettings)33 Intent (android.content.Intent)18 PendingIntent (android.app.PendingIntent)10 Context (android.content.Context)10 NotificationCompat (android.support.v4.app.NotificationCompat)9 SharedPreferences (android.content.SharedPreferences)6 Cursor (android.database.Cursor)6 Bitmap (android.graphics.Bitmap)6 PowerManager (android.os.PowerManager)6 NotificationManagerCompat (android.support.v4.app.NotificationManagerCompat)6 Paging (twitter4j.Paging)6 ArrayList (java.util.ArrayList)5 Twitter (twitter4j.Twitter)5 HomeDataSource (com.klinker.android.twitter.data.sq_lite.HomeDataSource)4 MentionsDataSource (com.klinker.android.twitter.data.sq_lite.MentionsDataSource)4 Status (twitter4j.Status)4 AlarmManager (android.app.AlarmManager)3 Handler (android.os.Handler)3 RemoteInput (android.support.v4.app.RemoteInput)3 DMDataSource (com.klinker.android.twitter.data.sq_lite.DMDataSource)3