Skip to content

Instantly share code, notes, and snippets.

View wangerekaharun's full-sized avatar

Harun Wangereka wangerekaharun

View GitHub Profile
@wangerekaharun
wangerekaharun / HomeActivity.kt
Created April 3, 2020 10:45
Inflating toolnbar as a fragement
private fun showToolbarContent(isAuthenticated: Boolean, destinationId: Int) {
val content = when (destinationId) {
R.id.homeFragment -> if (isAuthenticated) FeedbackFragment() else CountdownFragment()
R.id.feedFragment -> TitleFragment().also {
val args = Bundle()
args.putString("title", getString(R.string.feed))
it.arguments = args
}
R.id.sessionsFragment -> TitleFragment().also {
public class PreviousRideRepo {
// define a new executor of type single thread
private Executor executor= Executors.newSingleThreadExecutor();
private void insert(){
executor.execute(()->{
// do your insert here inside this block
//omitted class definations for brevity
private val sessionDataStateMediatorLiveData = MediatorLiveData<SessionsModel>()
private val error = MediatorLiveData<String>()
fun getSessionDetails(dayNumber: String, sessionId: Int) {
viewModelScope.launch {
when (val value = sessionDataRepo.getSessionData(dayNumber, sessionId)) {
is FirebaseResult.Success -> sessionDataStateMediatorLiveData.postValue(value.data)
is FirebaseResult.Error -> error.postValue(value.exception)
val retrofit = module(override = true) {
single {
val interceptor = HttpLoggingInterceptor()
if (BuildConfig.DEBUG) {
interceptor.apply { interceptor.level = HttpLoggingInterceptor.Level.BODY }
} else {
interceptor.apply { interceptor.level = HttpLoggingInterceptor.Level.NONE }
}
@wangerekaharun
wangerekaharun / targetEntity.kt
Created October 27, 2019 12:37
Example showing how to use target Entity
@Dao
interface SongsDao {
@Insert(targetEntity = Song::class)
fun inserNameamdId(nameAndId : NameAndId)
}
@wangerekaharun
wangerekaharun / projections
Created October 27, 2019 12:25
How to use room expand projections
@Dao
interface SongsDao {
@Query("SELECT * FROM song")
suspend fun getAllSongs(): List<NameAndId>
}
// data class with only name and id
data class NameAndId(val id: Long, val songName: String)
@wangerekaharun
wangerekaharun / song
Created October 27, 2019 12:17
Song Data Class
@Entity
data class Song(
@PrimaryKey
val id: Long,
val url: String,
val songName: String,
val artistName: String,
val albumName: String
)
@wangerekaharun
wangerekaharun / build1.gradle
Created October 27, 2019 12:04
Adding expanding projections in room
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = [
"room.expandProjection":"true"
]
}
@wangerekaharun
wangerekaharun / build.gradle
Created October 27, 2019 11:41
Adding room incremental processing support
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = [
"room.incremental":"true"
]
}
@wangerekaharun
wangerekaharun / RoomFlow.kt
Last active October 27, 2019 11:55
Room Flow<T> support
@Dao
interface FavoritesDao {
@Query("SELECT * FROM Work")
fun getAll(): Flow<Work>
}
suspend fun getAll(){