Skip to content

Instantly share code, notes, and snippets.

View kzotin's full-sized avatar

Kirill Zotin kzotin

  • Monobank / Koto card
View GitHub Profile
class NewGuide {
@PrimaryKey lateinit var remote_id: String
@ColumnInfo(name = "created_at") lateinit var createdAt: String
@ColumnInfo(name = "updated_at") var updatedAt: String? = null
@ColumnInfo lateinit var title: String
@ColumnInfo lateinit var description: String
@ColumnInfo var imageUrl: String? = null
@kzotin
kzotin / Guide.kt
Created March 5, 2018 18:31
Guide.kt
@Entity(tableName = Sql.TABLE_GUIDES)
data class Guide(
@PrimaryKey lateinit var remote_id: String,
@ColumnInfo lateinit var created_at: String,
@ColumnInfo var updated_at: String? = null,
@ColumnInfo val title: String,
@ColumnInfo val description: String
...
)
@kzotin
kzotin / VaultSpy.kt
Created March 5, 2018 18:31
VaultSpy.kt
package com.contentful.vault
import android.annotation.SuppressLint
import android.arch.persistence.room.RoomMasterTable
import android.database.sqlite.SQLiteDatabase
object VaultSpy {
@SuppressLint("RestrictedApi")
fun Vault.updateRoomIdentityHash(hash: String) {
@kzotin
kzotin / GuidesRepository.kt
Created March 5, 2018 18:31
GuidesRepository.kt
// old way
return vault.observe(Guide::class.java)
.all()
.filter({ guide -> guide.remoteId() == guideId })
.buffer(RESULT_SET_DEFAULT)
.first(listOf())
.toFlowable().toLiveData()
// new way
return dao.getGuidesByAuthorId(authorId)
@kzotin
kzotin / GuideDao.kt
Last active March 5, 2018 18:31
GuideDao.kt
@Dao
interface GuideDao {
@Query(SELECT_GUIDE_JOIN_DETAILS + " where creatorId = :arg0")
fun getGuidesByAuthorId(arg0: String): Flowable<List<NewGuide>>
@Query(SELECT_GUIDE_JOIN_DETAILS + " order by guides.created_at DESC limit :arg0")
fun getLastUpdated(arg0: Int): Flowable<List<NewGuide>>
...
@kzotin
kzotin / LiveDataUtils.kt
Created November 29, 2017 19:57 — forked from magneticflux-/LiveDataUtils.kt
Helpful Android-Kotlin LiveData utilities
/*
* Copyright (C) 2017 Mitchell Skaggs, Keturah Gadson, Ethan Holtgrieve, Nathan Skelton, Pattonville School District
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
public class RequestQueueProvider {
private static RequestQueue mRequestQueue;
public static RequestQueue getRequestQueue(Context context) {
if (mRequestQueue == null) {
mRequestQueue = newSitecoreRequestQueue(context.getContentResolver());
}
return mRequestQueue;
}