Skip to content

Instantly share code, notes, and snippets.

View oakkub's full-sized avatar
:octocat:
:)

Metas Kerdwat oakkub

:octocat:
:)
  • Bangkok, Thailand
View GitHub Profile
<?xml version="1.0" encoding="utf-8"?>
<shape
android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="8dp"
android:height="8dp" />
<solid android:color="@android:color/transparent" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
import android.content.Context
import android.content.SharedPreferences
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
/**
* Created by oakkub on 10/18/2017 AD.
*/
object PreferenceHelper {
interface BarcodeManager {
fun startDetecting()
fun stopDetecting()
fun release()
}
sealed class ScannedResult {
data class Success(val barcode: String) : ScannedResult()
object PermissionDenied : ScannedResult()
object NotOperational : ScannedResult()
@oakkub
oakkub / FieldInjected.kt
Created August 10, 2018 03:58
Set value to private field
fun FooViewModel.setMockRepository(mockRepository: FooRepository) {
val repository = FooViewModel::class.java.getDeclaredField("fooRepository")
repository.isAccessible = true
repository.set(this, mockRepository)
}
@oakkub
oakkub / FieldInjected.kt
Last active August 10, 2018 03:58
Set value to private field, in case we want to inject the mock repository or something.
fun FooViewModel.setMockRepository(mockRepository: FooRepository) {
val repository = FooViewModel::class.java.getDeclaredField("fooRepository")
repository.isAccessible = true
repository.set(this, mockRepository)
}
@oakkub
oakkub / CoroutineLifecycleObserver.kt
Created September 9, 2018 17:04 — forked from chrisbanes/CoroutineLifecycleObserver.kt
LifecycleObserver which allows easy cancelling of coroutines
/*
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
class LocationRequestHelper(private val context: Context,
private val locationRequest: LocationRequest,
lifecycle: Lifecycle,
private val onResult: (LocationResult) -> Unit) : LifecycleObserver {
private val locationClient by lazy { FusedLocationProviderClient(context) }
private val settingsClient by lazy { LocationServices.getSettingsClient(context) }
private val locationSettingRequest by lazy {
LocationSettingsRequest.Builder()
object GoogleApiAvailabilityHelper {
private const val REQUEST_CODE_GOOGLE_AVAILABILITY = 999
fun checkAvailability(activity: Activity): Boolean {
val googleApiAvailability = GoogleApiAvailability.getInstance()
val statusCode = googleApiAvailability.isGooglePlayServicesAvailable(activity)
val isResultSuccess = statusCode == ConnectionResult.SUCCESS
package com.redplanet.tune.ui.decorations
import android.graphics.Rect
import android.support.annotation.Px
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
class GridOffsetItemDecoration(@param:Px private val spacing: Int,
private val shouldIncludeEdge: Boolean) : RecyclerView.ItemDecoration() {