Skip to content

Commit

Permalink
add Timber
Browse files Browse the repository at this point in the history
  • Loading branch information
nilvng committed Aug 27, 2023
1 parent 9e28f13 commit 273ac7f
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ dependencies {
// optional - Paging 3 Integration
implementation "androidx.room:room-paging:$room_version"

// Timber
implementation 'com.jakewharton.timber:timber:5.0.1'

}
kapt {
correctErrorTypes true
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".MyApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -13,7 +15,6 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MovieNight"
android:name=".MyApplication"
tools:targetApi="31">
<activity
android:name=".ui.search.SearchActivity"
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/nillin/movienight/MyApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ package com.nillin.movienight

import android.app.Application
import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber

@HiltAndroidApp
class MyApplication: Application() {
override fun onCreate() {
super.onCreate()
Timber.plant(Timber.DebugTree())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import timber.log.Timber

@AndroidEntryPoint
class MainFragment : Fragment() {
Expand Down Expand Up @@ -45,13 +46,16 @@ class MainFragment : Fragment() {
viewModel.movieRepo.getAll()
.map { movieList -> movieList.map { movie -> movie.asState() } }
.collect {
it.forEach {movie ->
Timber.d("Repo: $movie")
}
(binding.rvMovies.adapter as MovieAdapter).update(it)
}
}
}

binding.btnAdd.setOnClickListener {
// onAddClicked()
onAddClicked()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.nillin.movienight.ui.main

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
Expand All @@ -15,21 +16,23 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

val dummy_data = listOf(dummy_normalpeople, dummy_silo)

@HiltViewModel
class MainViewModel @Inject constructor(
val movieRepo: MovieRepo
): ViewModel() {
) : ViewModel() {
var movies: LiveData<List<MovieUI>> = MutableLiveData(dummy_data)
var flowMovieUI : StateFlow<List<MovieUI>> = MutableStateFlow(dummy_data)
var flowMovieUI: StateFlow<List<MovieUI>> = MutableStateFlow(dummy_data)
private val _flowMovie = MutableStateFlow(dummy_data)

fun getMovies() {
viewModelScope.launch {
flowMovieUI = movieRepo.getAll().map { it.map { it.asState() }}.stateIn(viewModelScope)
flowMovieUI = movieRepo.getAll().map { it.map { it.asState() } }.stateIn(viewModelScope)
Timber.d(flowMovieUI.value.toString(), null)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ class MovieAdapter(private val movieUIS: ArrayList<MovieUI>) :
}

fun update(movieUIS: List<MovieUI>) {
if (movieUIS.isEmpty()) return
this.movieUIS.clear()
this.movieUIS.addAll(movieUIS)
notifyItemRangeChanged(0, movieUIS.count())
}


Expand Down

0 comments on commit 273ac7f

Please sign in to comment.