Search in sources :

Example 1 with ActivityUtils

use of com.klinker.android.twitter.utils.ActivityUtils in project Talon-for-Twitter by klinker24.

the class ActivityFragment method onRefreshStarted.

@Override
public void onRefreshStarted() {
    new AsyncTask<Void, Void, Cursor>() {

        private boolean update = false;

        @Override
        protected void onPreExecute() {
            DrawerActivity.canSwitch = false;
        }

        @Override
        protected Cursor doInBackground(Void... params) {
            ActivityUtils utils = new ActivityUtils(getActivity());
            update = utils.refreshActivity();
            AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            long now = new Date().getTime();
            long alarm = now + DrawerActivity.settings.activityRefresh;
            PendingIntent pendingIntent = PendingIntent.getService(context, ACTIVITY_REFRESH_ID, new Intent(context, ActivityRefreshService.class), 0);
            if (DrawerActivity.settings.activityRefresh != 0)
                am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, DrawerActivity.settings.activityRefresh, pendingIntent);
            else
                am.cancel(pendingIntent);
            if (settings.syncSecondMentions) {
                context.startService(new Intent(context, SecondActivityRefreshService.class));
            }
            return ActivityDataSource.getInstance(context).getCursor(currentAccount);
        }

        @Override
        protected void onPostExecute(Cursor cursor) {
            Cursor c = null;
            try {
                c = cursorAdapter.getCursor();
            } catch (Exception e) {
            }
            cursorAdapter = setAdapter(cursor);
            try {
                listView.setAdapter(cursorAdapter);
            } catch (Exception e) {
            }
            if (cursor.getCount() == 0) {
                spinner.setVisibility(View.VISIBLE);
            } else {
                spinner.setVisibility(View.GONE);
            }
            try {
                if (update) {
                    showToastBar(getString(R.string.new_activity), getString(R.string.ok), 400, true, toTopListener);
                }
            } catch (Exception e) {
            // user closed the app before it was done
            }
            refreshLayout.setRefreshing(false);
            DrawerActivity.canSwitch = true;
            try {
                c.close();
            } catch (Exception e) {
            }
        }
    }.execute();
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Cursor(android.database.Cursor) ActivityUtils(com.klinker.android.twitter.utils.ActivityUtils) Date(java.util.Date)

Example 2 with ActivityUtils

use of com.klinker.android.twitter.utils.ActivityUtils in project Talon-for-Twitter by klinker24.

the class ActivityRefreshService method onHandleIntent.

@Override
public void onHandleIntent(Intent intent) {
    AppSettings settings = AppSettings.getInstance(this);
    ActivityUtils utils = new ActivityUtils(this, false);
    if (Utils.getConnectionStatus(this) && !settings.syncMobile) {
        return;
    }
    boolean newActivity = utils.refreshActivity();
    if (settings.notifications && settings.activityNot && newActivity) {
        utils.postNotification();
    }
    if (settings.syncSecondMentions) {
        Intent second = new Intent(this, SecondActivityRefreshService.class);
        startService(second);
    }
}
Also used : AppSettings(com.klinker.android.twitter.settings.AppSettings) Intent(android.content.Intent) ActivityUtils(com.klinker.android.twitter.utils.ActivityUtils)

Example 3 with ActivityUtils

use of com.klinker.android.twitter.utils.ActivityUtils in project Talon-for-Twitter by klinker24.

the class SecondActivityRefreshService method onHandleIntent.

@Override
public void onHandleIntent(Intent intent) {
    AppSettings settings = AppSettings.getInstance(this);
    ActivityUtils utils = new ActivityUtils(this, true);
    if (Utils.getConnectionStatus(this) && !settings.syncMobile) {
        return;
    }
    boolean newActivity = utils.refreshActivity();
    if (settings.notifications && settings.activityNot && newActivity) {
        utils.postNotification(ActivityUtils.SECOND_NOTIFICATION_ID);
    }
}
Also used : AppSettings(com.klinker.android.twitter.settings.AppSettings) ActivityUtils(com.klinker.android.twitter.utils.ActivityUtils)

Aggregations

ActivityUtils (com.klinker.android.twitter.utils.ActivityUtils)3 Intent (android.content.Intent)2 AppSettings (com.klinker.android.twitter.settings.AppSettings)2 AlarmManager (android.app.AlarmManager)1 PendingIntent (android.app.PendingIntent)1 Cursor (android.database.Cursor)1 Date (java.util.Date)1