Search in sources :

Example 6 with FirebaseJobDispatcher

use of com.firebase.jobdispatcher.FirebaseJobDispatcher in project FastHub by k0shk0sh.

the class NotificationSchedulerJobTask method scheduleJob.

public static void scheduleJob(@NonNull Context context, int duration, boolean cancel) {
    if (AppHelper.isGoogleAvailable(context)) {
        FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
        dispatcher.cancel(SINGLE_JOB_ID);
        if (cancel)
            dispatcher.cancel(JOB_ID);
        if (duration == -1) {
            dispatcher.cancel(JOB_ID);
            return;
        }
        duration = duration <= 0 ? THIRTY_MINUTES : duration;
        Job.Builder builder = dispatcher.newJobBuilder().setTag(JOB_ID).setRetryStrategy(RetryStrategy.DEFAULT_LINEAR).setLifetime(Lifetime.FOREVER).setRecurring(true).setConstraints(Constraint.ON_ANY_NETWORK).setTrigger(Trigger.executionWindow(duration / 2, duration)).setService(NotificationSchedulerJobTask.class);
        dispatcher.mustSchedule(builder.build());
    }
}
Also used : FirebaseJobDispatcher(com.firebase.jobdispatcher.FirebaseJobDispatcher) GooglePlayDriver(com.firebase.jobdispatcher.GooglePlayDriver) Job(com.firebase.jobdispatcher.Job)

Example 7 with FirebaseJobDispatcher

use of com.firebase.jobdispatcher.FirebaseJobDispatcher in project FastHub by k0shk0sh.

the class NotificationSchedulerJobTask method scheduleOneTimeJob.

public static void scheduleOneTimeJob(@NonNull Context context) {
    if (AppHelper.isGoogleAvailable(context)) {
        FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
        Job.Builder builder = dispatcher.newJobBuilder().setTag(SINGLE_JOB_ID).setReplaceCurrent(true).setRecurring(false).setTrigger(Trigger.executionWindow(30, 60)).setConstraints(Constraint.ON_ANY_NETWORK).setService(NotificationSchedulerJobTask.class);
        dispatcher.mustSchedule(builder.build());
    }
}
Also used : FirebaseJobDispatcher(com.firebase.jobdispatcher.FirebaseJobDispatcher) GooglePlayDriver(com.firebase.jobdispatcher.GooglePlayDriver) Job(com.firebase.jobdispatcher.Job)

Example 8 with FirebaseJobDispatcher

use of com.firebase.jobdispatcher.FirebaseJobDispatcher in project Passenger_Security by ujjwalagr.

the class JobClass method startJob.

public static void startJob(Context context) {
    FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
    Job job = dispatcher.newJobBuilder().setLifetime(Lifetime.FOREVER).setService(SmsJobSchedule.class).setTag("SMS_SENT_MESSAGE_TAG").setReplaceCurrent(false).setRecurring(true).setTrigger(Trigger.executionWindow(0, 60)).setRetryStrategy(RetryStrategy.DEFAULT_LINEAR).build();
    dispatcher.mustSchedule(job);
}
Also used : FirebaseJobDispatcher(com.firebase.jobdispatcher.FirebaseJobDispatcher) GooglePlayDriver(com.firebase.jobdispatcher.GooglePlayDriver) Job(com.firebase.jobdispatcher.Job)

Example 9 with FirebaseJobDispatcher

use of com.firebase.jobdispatcher.FirebaseJobDispatcher in project Passenger_Security by ujjwalagr.

the class JobClass method stopJob.

public static void stopJob(Context context) {
    FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
    // Cancel all the jobs for this package
    dispatcher.cancelAll();
    // Cancel the job for this tag
    dispatcher.cancel("SMS_SENT_MESSAGE_TAG");
}
Also used : FirebaseJobDispatcher(com.firebase.jobdispatcher.FirebaseJobDispatcher) GooglePlayDriver(com.firebase.jobdispatcher.GooglePlayDriver)

Example 10 with FirebaseJobDispatcher

use of com.firebase.jobdispatcher.FirebaseJobDispatcher in project anitrend-app by AniTrend.

the class JobSchedulerUtil method scheduleJob.

/**
 * Schedules a new job service or replaces the existing job if one
 * exists.
 * @param context any valid application context
 */
public static void scheduleJob(Context context) {
    ApplicationPref applicationPref = new ApplicationPref(context);
    if (applicationPref.isAuthenticated() && applicationPref.isNotificationEnabled()) {
        try {
            FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
            Job syncJob = dispatcher.newJobBuilder().setService(JobDispatcherService.class).setTag(JOB_DISPATCHER).setRecurring(true).setLifetime(Lifetime.UNTIL_NEXT_BOOT).setTrigger(Trigger.executionWindow(MINIMUM_SYNC_TIME, applicationPref.getSyncTime())).setReplaceCurrent(true).setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL).setConstraints(Constraint.ON_ANY_NETWORK).build();
            dispatcher.mustSchedule(syncJob);
            Log.d("JobSchedulerUtil", "JobDispatcher has been scheduled from context: " + context);
        } catch (FirebaseJobDispatcher.ScheduleFailedException ex) {
            Log.d("JobSchedulerUtil", ex.getLocalizedMessage());
            ex.printStackTrace();
        }
    } else
        cancelJob(context);
}
Also used : FirebaseJobDispatcher(com.firebase.jobdispatcher.FirebaseJobDispatcher) GooglePlayDriver(com.firebase.jobdispatcher.GooglePlayDriver) Job(com.firebase.jobdispatcher.Job)

Aggregations

FirebaseJobDispatcher (com.firebase.jobdispatcher.FirebaseJobDispatcher)10 GooglePlayDriver (com.firebase.jobdispatcher.GooglePlayDriver)10 Job (com.firebase.jobdispatcher.Job)9 Bundle (android.os.Bundle)3 SharedPreferences (android.content.SharedPreferences)2 View (android.view.View)2 TextView (android.widget.TextView)2 AdView (com.google.android.gms.ads.AdView)2 CurrencyEnum (it.angelic.mpw.model.enums.CurrencyEnum)2 PoolEnum (it.angelic.mpw.model.enums.PoolEnum)2 Intent (android.content.Intent)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 NavigationView (android.support.design.widget.NavigationView)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 EditTextPreference (android.support.v7.preference.EditTextPreference)1 ListPreference (android.support.v7.preference.ListPreference)1 Preference (android.support.v7.preference.Preference)1 SwitchPreferenceCompat (android.support.v7.preference.SwitchPreferenceCompat)1 Toolbar (android.support.v7.widget.Toolbar)1