Skip to content

Instantly share code, notes, and snippets.

View aruke's full-sized avatar
👨‍💻

Rajanikant Deshmukh aruke

👨‍💻
View GitHub Profile
{
"200":{
"icon":"thunderstorm",
"icon-day":"day-thunderstorm",
"icon-night":"night-alt-thunderstorm"
},
"201":{
"icon":"thunderstorm",
"icon-day":"day-thunderstorm",
"icon-night":"night-alt-thunderstorm"
@aruke
aruke / SimpleWorker_Observe.kt
Created March 10, 2019 14:30
Gists to embed in WorkManager blog. Full code is available at https://github.com/aruke/WorkManagerDemo.
val workerId = simpleWorkRequest.id
WorkManager.getInstance().getWorkInfoByIdLiveData(workerId)
.observe(this, Observer<WorkInfo> {
it?.let { workInfo ->
when (workInfo.state) {
WorkInfo.State.ENQUEUED ->
Log.d(TAG, "Worker ENQUEUED")
WorkInfo.State.RUNNING ->
Log.d(TAG, "Worker RUNNING")
@aruke
aruke / SimpleWorker_Enqueue.kt
Created March 10, 2019 14:30
Gists to embed in WorkManager blog. Full code is available at https://github.com/aruke/WorkManagerDemo.
val inputData: Data = Data.Builder().putInt(SimpleWorker.KEY_DELAY, 5).build()
val simpleWorkRequest = OneTimeWorkRequest.Builder(SimpleWorker::class.java)
.setInputData(inputData)
.build()
WorkManager.getInstance().enqueue(simpleWorkRequest)
@aruke
aruke / SimpleWorker.kt
Created March 10, 2019 14:30
Gists to embed in WorkManager blog. Full code is available at https://github.com/aruke/WorkManagerDemo.
class SimpleWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
private val delayInSeconds: Int = workerParams.inputData.getInt(KEY_DELAY, 0)
override fun doWork(): Result {
// Do intensive task here
// For now, our old friend Thread.sleep can replace intensive task here.
Thread.sleep(delayInSeconds * 1000L)
// Return with success
@aruke
aruke / NetworkWorker_PeriodicRequest.kt
Created March 10, 2019 14:30
Gists to embed in WorkManager blog. Full code is available at https://github.com/aruke/WorkManagerDemo.
fun buildPeriodicRequest(secretKey: String, userData: Array<String>): PeriodicWorkRequest {
val inputData = Data.Builder()
.putString(KEY_SECRET_KEY, secretKey)
.putStringArray(KEY_USER_DATA, userData)
.build()
val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.setRequiresCharging(true).build()
@aruke
aruke / NetworkWorker.kt
Last active March 10, 2019 14:30
Gists to embed in WorkManager blog. Full code is available at https://github.com/aruke/WorkManagerDemo.
class NetworkWorker(private val context: Context, private val params: WorkerParameters) : Worker(context, params) {
override fun doWork(): Result {
// Get the input data
val userData = params.inputData.getStringArray(KEY_USER_DATA)
val secretKey = params.inputData.getString(KEY_SECRET_KEY)
secretKey ?: run {
Log.e(TAG, "doWork: SecretKey not found in WorkParams")
@aruke
aruke / DummyData.java
Created August 27, 2018 13:06
A file collection showing use of dummy data class.
package com.example.data;
import java.util.ArrayList;
public class DummyData {
/**
* An {@link ArrayList} to store data.
*/
private static ArrayList<Model> mData;
// Call this method directly from java file
int secs = 2; // Delay in seconds
Utils.delay(secs, new Utils.DelayCallback() {
@Override
public void afterDelay() {
// Do something after delay
}