Skip to content

Instantly share code, notes, and snippets.

Marcel Pintó Biescas skimarxall

Block or report user

Report or block skimarxall

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View BaseSlice.kt
abstract class BaseSlice(val context: Context, val sliceUri: Uri) {
/**
* @return the slice implementation to be used by SliceProvider
*/
abstract fun buildSlice(): Slice
/**
* Call refresh to notify the SliceProvider to load again.
*/
@skimarxall
skimarxall / MyViewModel.kt
Created Apr 2, 2019
Gist for ViewData best practice blog - Best way
View MyViewModel.kt
sealed class MyViewData {
abstract val distance: Int
data class Km(override val distance: Int): MyViewData()
data class Miles(override val distance: Int): MyViewData()
}
class MyViewModel: ViewModel() {
@skimarxall
skimarxall / MyViewModel.kt
Created Apr 2, 2019
Gist for ViewData best practice blog - Good way
View MyViewModel.kt
data class MyViewData(val value: Int, val textId: Int, val labelId: Int)
class MyViewModel: ViewModel() {
private val _myViewData = MutableLiveData<MyViewData>()
val myViewData: LiveData<MyViewData> = _myViewData
fun updateViewData() {
val value = getDistance()
@skimarxall
skimarxall / MyViewModel.kt
Created Apr 2, 2019
Gist for ViewData best practice blog
View MyViewModel.kt
data class MyViewData(val text: String)
class MyViewModel(application: Application): AndroidViewModel(application) {
private val _myViewData = MutableLiveData<MyViewData>()
val myViewData: LiveData<MyViewData> = _myViewData
fun updateViewData() {
val value = getDistance()
View HomePage.kt
data class HomePage(
val locationInfo: LocationInfo? = null,
val travelInfo: TravelInfo? = null,
val weddingLocation: WeddingLocation? = null,
val weddingInfo: WeddingInfo? = null,
val weddingDate: WeddingDate? = null,
val welcome: WelcomeItem? = null
)
View HomePageFragment.kt
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
homeRecycler.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
homeRecycler.adapter = adapter
homeViewModel.homePage.observe(this, Observer { resource ->
resource?.apply {
when (resource.status) {
SUCCESS -> {
@skimarxall
skimarxall / FirebaseLiveData.kt
Last active Oct 14, 2018
Example of Firebase LiveData mechanism
View FirebaseLiveData.kt
class FirebaseLiveData<T>(
private val reference: DatabaseReference,
private val resourceType: Class<T>
) : LiveData<Resource<T>>(), ValueEventListener {
override fun onActive() {
super.onActive()
if (value == null) {
value = Resource.loading()
}
View NetworkFactoryTest.kt
class NetworkFactoryTest {
private val baseUrl = "/"
private val testData = TestData("hello!")
private val testDataJson = "{\"name\":\"${testData.name}\"}"
private val mockWebServer = MockWebServer()
private val httpUrl = mockWebServer.url(baseUrl)
private val moshi = createMoshi()
@skimarxall
skimarxall / NetworkFactory.kt
Last active Jul 21, 2018
Testing your Network
View NetworkFactory.kt
class NetworkFactory(moshi: Moshi, authInterceptor: AuthenticationInterceptor, authenticator: Authenticator) {
private val okHttpClient: OkHttpClient
private val retrofitBuilder: Retrofit.Builder
init {
val level = if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE
val loggingInterceptor = HttpLoggingInterceptor().setLevel(level)
okHttpClient = OkHttpClient.Builder()
View new_map_xkcd.html
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="http://cmx.io/v/0.1/cmx.css">
<script src="http://cmx.io/v/0.1/cmx.js" charset="utf-8"></script>
<style>.cmx-user-scene4 .cmx-text-border .cmx-path {stroke: orange}</style>
<body>
<div style="max-width:900px; -webkit-transform:rotate(0deg)">
<scene id="scene1">
<label t="translate(0,346)">
You can’t perform that action at this time.