This file contains 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
class AppCompatBottomAppBar : BottomAppBar { | |
private val compatBehavior by lazyFast { CompatBehavior() } | |
constructor(context: Context) : super(context) | |
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) // respect internal style | |
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) | |
override fun getBehavior(): CoordinatorLayout.Behavior<BottomAppBar> { | |
return compatBehavior |
This file contains 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
class WorkSpec { | |
// ... | |
@ColumnInfo(name = "worker_class_name") | |
var workerClassName: String | |
// ... | |
} | |
fun doWork(): WorkerResult { |
This file contains 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
@Query("UPDATE workspec SET run_attempt_count=run_attempt_count+1 WHERE id=:id") | |
fun incrementWorkSpecRunAttemptCount(id: String): Int |
This file contains 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
override fun getStatusById(id: UUID): LiveData<WorkStatus> { | |
val dao = mWorkDatabase.workSpecDao() | |
val inputLiveData = dao.getWorkStatusPojoLiveDataForIds(listOf(id.toString())) | |
return LiveDataUtils.dedupedMappedLiveDataFor<List<WorkSpec.WorkStatusPojo>, WorkStatus>(inputLiveData) { input -> | |
var workStatus: WorkStatus? = null | |
if (null != input && input.isNotEmpty()) { | |
workStatus = input [0].toWorkStatus() | |
} | |
workStatus | |
} |
This file contains 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
fun observeMyWorkPlease() { | |
WorkManager.getInstance().getStatusById(hardWorkId).observe(lifecycleOwner, workStatus -> { | |
if (null != workStatus && workStatus.state.isFinished()) { | |
// let's rock! | |
} | |
}) | |
} |
This file contains 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
fun getSchedulers(): List<Scheduler> { | |
if (mSchedulers == null) { | |
mSchedulers = Arrays.asList( | |
Schedulers.createBestAvailableBackgroundScheduler(mContext), | |
GreedyScheduler(mContext, this)) | |
} | |
return mSchedulers | |
} | |
internal fun createBestAvailableBackgroundScheduler(context: Context): Scheduler { |
This file contains 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
fun hardWorkerRunner(): WorkRequest { | |
val hardWork = OneTimeWorkRequest.Builder(HardWorker::class.java).build() | |
WorkManager.getInstance().enqueue(hardWork) | |
return hardWork | |
} | |
fun hardWorkerStopper() { | |
val hardWorkId = hardWorkerRunner().id | |
WorkManager.getInstance().cancelWorkById(hardWorkId) | |
} |
This file contains 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
internal class HardWorker : Worker() { | |
override fun doWork(): Worker.WorkerResult { | |
reallyMassiveHeavyLongPLayingWork(); | |
return Worker.WorkerResult.SUCCESS // or FAILURE, or RETRY if you want to run again | |
} | |
} | |
fun hardWorkerRunner() { | |
val hardWork = OneTimeWorkRequest.Builder(HardWorker::class.java).build() | |
WorkManager.getInstance().enqueue(hardWork) |
This file contains 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
class KitsuViewHolder(parent :ViewGroup) : RecyclerView.ViewHolder( | |
LayoutInflater.from(parent.context).inflate(R.layout.kitsu_item, parent, false)) { | |
var item : KitsuItem? = null | |
fun bindTo(item : KitsuItem?) { | |
this.item = item | |
itemView.itemTypeView.text = item?.type?.capitalize() | |
?: "Ouhh..." | |
itemView.itemSubtypeView.text = item?.attributes?.subtype?.capitalize() |
This file contains 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
object KitsuRestApi { | |
private val kitsuApi: KitsuSpecApi | |
init { | |
val retrofit = Retrofit.Builder() | |
.baseUrl("https://kitsu.io/api/edge/") | |
.addConverterFactory(MoshiConverterFactory.create()) | |
.build() | |
kitsuApi = retrofit.create(KitsuSpecApi::class.java) |
NewerOlder