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 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>) { | |
feedDao.insertAll(item) | |
} |
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
/** | |
* 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](https://developer.android.com/arch). | |
* | |
* @param <ResultType> | |
* @param <RequestType> | |
</RequestType></ResultType> */ |
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
/** | |
* 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]. | |
*/ |
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
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 |
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
Component | Test | Mock | |
---|---|---|---|
UI | Espresso | ViewModel | |
ViewModel | JUnit | Repository | |
Repository | JUnit | DAO and WebService | |
DAO | Instrumented | - | |
WebService | Instrumented | MockWebServer |
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
import android.support.annotation.NonNull; | |
import android.support.annotation.Nullable; | |
import android.support.v4.util.ArrayMap; | |
import java.io.IOException; | |
import java.util.Collections; | |
import java.util.Map; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; |
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
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}#end | |
import android.support.v7.widget.RecyclerView | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import java.util.* | |
#parse("File Header.java") | |
class ${NAME} : RecyclerView.Adapter<${ViewHolder_Class}>() { |
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
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(LocalDate.now()) | |
} | |
/** |
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 DateConverters { | |
@TypeConverter | |
fun fromTimestamp(value: Long?): Date? { | |
return if (value == null) null else Date(value) | |
} | |
@TypeConverter | |
fun dateToTimestamp(date: Date?): Long? { | |
return date?.time | |
} |
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
@Dao | |
abstract class UserDao { | |
@Insert | |
abstract fun insert(user: User) | |
@Update | |
abstract fun update(user: User) | |
@Transaction |
NewerOlder