Search in sources :

Example 1 with ScheduledTweet

use of com.klinker.android.twitter.data.ScheduledTweet in project Talon-for-Twitter by klinker24.

the class QueuedDataSource method getScheduledTweets.

public ArrayList<ScheduledTweet> getScheduledTweets(int currentAccount) {
    ArrayList<ScheduledTweet> tweets = new ArrayList<ScheduledTweet>();
    Cursor cursor = getScheduledCursor(currentAccount);
    if (cursor.moveToFirst()) {
        do {
            String text = cursor.getString(cursor.getColumnIndex(QueuedSQLiteHelper.COLUMN_TEXT));
            long time = cursor.getLong(cursor.getColumnIndex(QueuedSQLiteHelper.COLUMN_TIME));
            int alarmId = cursor.getInt(cursor.getColumnIndex(QueuedSQLiteHelper.COLUMN_ALARM_ID));
            tweets.add(new ScheduledTweet(text, alarmId, time, currentAccount));
        } while (cursor.moveToNext());
    }
    cursor.close();
    return tweets;
}
Also used : ScheduledTweet(com.klinker.android.twitter.data.ScheduledTweet) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 2 with ScheduledTweet

use of com.klinker.android.twitter.data.ScheduledTweet in project Talon-for-Twitter by klinker24.

the class QueuedDataSource method getScheduledTweets.

public ArrayList<ScheduledTweet> getScheduledTweets() {
    ArrayList<ScheduledTweet> tweets = new ArrayList<ScheduledTweet>();
    Cursor cursor = getAllScheduledCursor();
    if (cursor.moveToFirst()) {
        do {
            String text = cursor.getString(cursor.getColumnIndex(QueuedSQLiteHelper.COLUMN_TEXT));
            long time = cursor.getLong(cursor.getColumnIndex(QueuedSQLiteHelper.COLUMN_TIME));
            int alarmId = cursor.getInt(cursor.getColumnIndex(QueuedSQLiteHelper.COLUMN_ALARM_ID));
            int account = cursor.getInt(cursor.getColumnIndex(QueuedSQLiteHelper.COLUMN_ACCOUNT));
            tweets.add(new ScheduledTweet(text, alarmId, time, account));
        } while (cursor.moveToNext());
    }
    cursor.close();
    return tweets;
}
Also used : ScheduledTweet(com.klinker.android.twitter.data.ScheduledTweet) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 3 with ScheduledTweet

use of com.klinker.android.twitter.data.ScheduledTweet in project Talon-for-Twitter by klinker24.

the class BootReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    this.context = context;
    AppSettings settings = AppSettings.getInstance(context);
    if (settings.timelineRefresh != 0) {
        // user only wants manual
        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        long now = new Date().getTime();
        long alarm = now + settings.timelineRefresh;
        Log.v("alarm_date", "timeline " + new Date(alarm).toString());
        PendingIntent pendingIntent = PendingIntent.getService(context, HomeFragment.HOME_REFRESH_ID, new Intent(context, TimelineRefreshService.class), 0);
        am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.timelineRefresh, pendingIntent);
    }
    if (settings.mentionsRefresh != 0) {
        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        long now = new Date().getTime();
        long alarm = now + settings.mentionsRefresh;
        Log.v("alarm_date", "mentions " + new Date(alarm).toString());
        PendingIntent pendingIntent = PendingIntent.getService(context, MentionsFragment.MENTIONS_REFRESH_ID, new Intent(context, MentionsRefreshService.class), 0);
        am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.mentionsRefresh, pendingIntent);
    }
    if (settings.dmRefresh != 0) {
        // user only wants manual
        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        long now = new Date().getTime();
        long alarm = now + settings.dmRefresh;
        Log.v("alarm_date", "dircet message " + new Date(alarm).toString());
        PendingIntent pendingIntent = PendingIntent.getService(context, DMFragment.DM_REFRESH_ID, new Intent(context, DirectMessageRefreshService.class), 0);
        am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.dmRefresh, pendingIntent);
    }
    if (settings.activityRefresh != 0) {
        // user only wants manual
        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        long now = new Date().getTime();
        long alarm = now + settings.activityRefresh;
        Log.v("alarm_date", "activity " + new Date(alarm).toString());
        PendingIntent pendingIntent = PendingIntent.getService(context, ActivityFragment.ACTIVITY_REFRESH_ID, new Intent(context, ActivityRefreshService.class), 0);
        am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.activityRefresh, pendingIntent);
    }
    if (settings.autoTrim) {
        // user only wants manual
        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        long now = new Date().getTime();
        long alarm = now + 1000 * 60;
        Log.v("alarm_date", "auto trim " + new Date(alarm).toString());
        PendingIntent pendingIntent = PendingIntent.getService(context, TRIM_ID, new Intent(context, TrimDataService.class), 0);
        am.set(AlarmManager.RTC_WAKEUP, alarm, pendingIntent);
    }
    if (settings.pushNotifications) {
        context.startService(new Intent(context, CatchupPull.class));
    }
    ArrayList<ScheduledTweet> tweets = QueuedDataSource.getInstance(context).getScheduledTweets();
    for (ScheduledTweet s : tweets) {
        Intent serviceIntent = new Intent(context.getApplicationContext(), SendScheduledTweet.class);
        Log.v("talon_scheduled_tweets", "in boot text: " + s.text);
        serviceIntent.putExtra(ViewScheduledTweets.EXTRA_TEXT, s.text);
        serviceIntent.putExtra("account", s.account);
        serviceIntent.putExtra("alarm_id", s.alarmId);
        PendingIntent pi = getDistinctPendingIntent(serviceIntent, s.alarmId);
        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        am.set(AlarmManager.RTC_WAKEUP, s.time, pi);
    }
}
Also used : AppSettings(com.klinker.android.twitter.settings.AppSettings) ScheduledTweet(com.klinker.android.twitter.data.ScheduledTweet) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Date(java.util.Date) AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent)

Example 4 with ScheduledTweet

use of com.klinker.android.twitter.data.ScheduledTweet in project Talon-for-Twitter by klinker24.

the class NewScheduledTweet method doneClick.

// this is where we will set everything up when the user has entered all the information
// including the alarm manager and writing the files to the database to save them
public boolean doneClick() {
    if (!mEditText.getText().toString().equals("") && timeDone) {
        ScheduledTweet tweet = new ScheduledTweet(getApplicationContext(), context, mEditText.getText().toString(), setDate.getTime(), settings.currentAccount);
        tweet.createScheduledTweet();
        finish();
    } else {
        Context context = getApplicationContext();
        CharSequence text = getString(R.string.complete_form);
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    }
    return true;
}
Also used : Context(android.content.Context) ScheduledTweet(com.klinker.android.twitter.data.ScheduledTweet) Toast(android.widget.Toast)

Aggregations

ScheduledTweet (com.klinker.android.twitter.data.ScheduledTweet)4 Cursor (android.database.Cursor)2 ArrayList (java.util.ArrayList)2 AlarmManager (android.app.AlarmManager)1 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Toast (android.widget.Toast)1 AppSettings (com.klinker.android.twitter.settings.AppSettings)1 Date (java.util.Date)1