This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.annotation.TargetApi; | |
import android.app.Notification; | |
import android.app.NotificationManager; | |
import android.content.Context; | |
import android.graphics.Bitmap; | |
import android.net.Uri; | |
import android.os.Build; | |
import android.support.annotation.AttrRes; | |
import android.support.annotation.ColorInt; | |
import android.support.annotation.ColorRes; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SampleWorker extends RxWorker { | |
public SampleWorker( | |
@NonNull Context context, | |
@NonNull WorkerParameters parameters) { | |
super(context, parameters); | |
} | |
public Single<Result> createWork() { | |
// Create a single observer which will hit a url and nothing else. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final Constraints NETWORK_CONSTRAINT = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build(); | |
// Create a OneTimeWorkRequest using our worker; SampleWorker.class | |
OneTimeWorkRequest sampleWorkRequest = new OneTimeWorkRequest | |
.Builder(SampleWorker.class) | |
.setConstraints(NETWORK_CONSTRAINT) | |
.setBackoffCriteria(BackoffPolicy.LINEAR, OneTimeWorkRequest.DEFAULT_BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) | |
.build(); | |
// Enqueue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Target(ElementType.METHOD) | |
@Retention(RetentionPolicy.RUNTIME) | |
@MapKey | |
public @interface WorkerKey { | |
Class<? extends RxWorker> value(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
public abstract class WorkerBindingModule { | |
@Binds | |
@IntoMap | |
@WorkerKey(SampleWorker.class) | |
abstract RxWorker bindPushContentWorker(SampleWorker sampleWorkerInstance); | |
@Binds | |
@IntoMap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SampleWorker extends RxWorker { | |
// Our custom parameter | |
private final Retrofit retrofit; | |
@Inject | |
public SampleWorker( | |
@NonNull Context context, | |
@NonNull WorkerParameters parameters, | |
Retrofit retrofit) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component(modules = { | |
WorkerBindingModule.class, // To bind our worker classes to the factory | |
AppModule.class, //. Which provides context | |
ActivityBinderModule.class, // TO bind our activities | |
FragmentBinderModule.class, // To bind our fragments | |
AndroidInjectionModule.class | |
}) | |
@Singleton | |
public interface AppComponent extends AndroidInjector<WonderquilApplication> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Subcomponent(modules = WorkerBindingModule.class) | |
public interface WorkManagerFactorySubComponent { | |
Map<Class<? extends RxWorker>, Provider<RxWorker>> getWorkerMap(); | |
@Subcomponent.Builder | |
interface Builder { | |
@BindsInstance | |
Builder parameters(WorkerParameters parameters); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WorkManagerWorkFactory extends WorkerFactory { | |
private final WorkManagerFactorySubComponent.Builder subComponentBuilder; | |
@Inject | |
public WorkManagerWorkFactory(WorkManagerFactorySubComponent.Builder workerFactorySubComponent) { | |
this.subComponentBuilder = workerFactorySubComponent; | |
} | |
@Nullable | |
@Override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<application | |
. | |
. | |
. <!-- Activities and various other things --> | |
. | |
. | |
. | |
<provider | |
android:authorities="${applicationId}.workmanager-init" | |
android:name="androidx.work.impl.WorkManagerInitializer" |
OlderNewer