Skip to content

Instantly share code, notes, and snippets.


Akshay Chordiya AkshayChordiya

View GitHub Profile
AkshayChordiya / FeedRepository.kt
Created Feb 25, 2018
Sample FeedRepository using NetworkBoundResouce class
View FeedRepository.kt
class FeedRepository @Inject constructor(
private val feedService: FeedService,
private val feedDao: FeedDao,
private val appExecutors: AppExecutors = AppExecutors()
) {
fun getFeeds(): LiveData<Resource<List<Feed>?>> = object : NetworkBoundResource<List<Feed>, List<Feed>>(appExecutors) {
override fun saveCallResult(item: List<Feed>) {
AkshayChordiya / NetworkBoundResource.kt
Created Feb 25, 2018
A generic class that can provide a resource backed by both the SQLite database and the network
View NetworkBoundResource.kt
* A generic class that can provide a resource backed by both the sqlite database and the network.
* You can read more about it in the [Architecture
* Guide](
* @param <ResultType>
* @param <RequestType>
</RequestType></ResultType> */
AkshayChordiya / Resource.kt
Created Feb 25, 2018
Generic class to hold data and state with LiveData
View Resource.kt
* A generic class that holds a value with its loading status.
* @param <T>
</T> */
data class Resource<ResultType>(var status: Status, var data: ResultType? = null, var message: String? = null) {
companion object {
* Creates [Resource] object with `SUCCESS` status and [data].
AkshayChordiya / components-action.csv
Created Feb 24, 2018
Android Architecture Guidelines Cheatsheet
View components-action.csv
Component Action
UI Controllers (Activity and Fragment) Only UI related logic
ViewModel Container for data required by UI
Repository Single source of truth for data
Room Local Database
Retrofit Web Service
AkshayChordiya / testing.csv
Created Feb 24, 2018
Android Architecture Guidelines Testing
View testing.csv
Component Test Mock
UI Espresso ViewModel
ViewModel JUnit Repository
Repository JUnit DAO and WebService
DAO Instrumented -
WebService Instrumented MockWebServer
AkshayChordiya /
Last active May 30, 2021
LiveData adapter for Retrofit
import java.util.Collections;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
AkshayChordiya / RecyclerViewAdapterTemplate.kt
Created Feb 1, 2018
File Template for Android Studio to instantly create RecyclerViewAdapter in Kotlin without boilerplate
View RecyclerViewAdapterTemplate.kt
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}#end
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import java.util.*
class ${NAME} : RecyclerView.Adapter<${ViewHolder_Class}>() {
AkshayChordiya / DateHeaderHelper.kt
Last active Apr 19, 2021
Use these date related top-level Kotlin functions to show sections like "Today", "Yesterday" and so on
View DateHeaderHelper.kt
import org.joda.time.LocalDate
* @return true if the supplied date is in the future else false
fun isUpcoming(millis: Long): Boolean {
return !isTomorrow(millis) && LocalDate(millis).isAfter(
View DateConverters.kt
class DateConverters {
fun fromTimestamp(value: Long?): Date? {
return if (value == null) null else Date(value)
fun dateToTimestamp(date: Date?): Long? {
return date?.time
AkshayChordiya / UserDao.kt
Created Dec 9, 2017
User DAO with transaction
View UserDao.kt
abstract class UserDao {
abstract fun insert(user: User)
abstract fun update(user: User)