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
plugins { | |
id 'com.android.application' | |
id 'kotlin-android' | |
// id 'kotlin-kapt' not needed anymore | |
id "com.google.devtools.ksp" version "1.6.10-1.0.2" | |
} | |
dependencies { | |
... | |
implementation "androidx.room:room-runtime:$room_version" |
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 timber.log.Timber | |
inline fun logDebug(message: () -> String) { | |
Timber.d(message()) | |
} | |
inline fun logInfo(message: () -> String) { | |
Timber.i(message()) | |
} |
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 androidx.lifecycle.* | |
inline fun <T> Resource<T>.mapData(crossinline mapper: (T) -> T?): Resource<T> { | |
val data = this.toData() ?: return this | |
val processedData = mapper(data) | |
return when (this) { | |
is Resource.Progress -> Resource.loading(progression, processedData) | |
is Resource.Success -> Resource.success(processedData) | |
is Resource.Failure -> Resource.failure(this.throwable, processedData) |
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
@ExperimentalCoroutinesApi | |
@AndroidEntryPoint | |
class MainActivity : AppCompatActivity(), BlogAdapter.BlogItemListener { | |
private val viewModel: MainViewModel by viewModels() | |
private lateinit var adapter: BlogAdapter | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
setupRecyclerView() |
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 BlogAdapter(private val listener: BlogItemListener) : RecyclerView.Adapter<BlogViewHolder>() { | |
interface BlogItemListener { | |
fun onClickedBlog(blogTitle: CharSequence) | |
} | |
private val items = ArrayList<Blog>() | |
private lateinit var blog: Blog | |
fun setItems(items: ArrayList<Blog>) { |
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 MainRepository | |
constructor( | |
private val blogDao: BlogDao, | |
private val blogApi: BlogApi, | |
private val cacheMapper: CacheMapper, | |
private val blogMapper: BlogMapper | |
) { | |
suspend fun getBlog(): Flow<DataState<List<Blog>>> = flow { | |
emit(DataState.Loading) | |
try { |
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.content.Context | |
import android.graphics.Color | |
import android.graphics.PorterDuff | |
import android.graphics.PorterDuffColorFilter | |
import android.graphics.Typeface | |
import android.graphics.drawable.GradientDrawable | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import android.view.WindowManager |
NewerOlder