View AppCompatBottomAppBar.kt
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 |
View ParamsStoredViaRoom.kt
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 { |
View FailWorkNextAttempt.kt
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 |
View ObserveWorkManagerInternal.kt
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 | |
} |
View ObserveWorkManager.kt
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! | |
} | |
}) | |
} |
View WorkManagerSchedulers.kt
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 { |
View WorkStopper.kt
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) | |
} |
View Work.kt
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) |
View KitsuUIParts.kt
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() |
View KitsuAPI.kt
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