Skip to content

Instantly share code, notes, and snippets.

View enginebai's full-sized avatar
📈
Focusing, Learning, Improving, Evolving

Engine Bai enginebai

📈
Focusing, Learning, Improving, Evolving
View GitHub Profile
@enginebai
enginebai / build.gradle.kts
Created October 16, 2019 13:31
Module-level gradle kts file in kotlin
plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-android-extensions")
}
android {
compileSdkVersion(Versions.Android.sdk)
defaultConfig {
applicationId = Versions.App.id
@enginebai
enginebai / Dependencies.kt
Last active October 18, 2019 11:51
The versions and dependencies in kotlin that can be used in gradle kts file.
object Versions {
const val kotlin = "1.3.50"
const val androidX = "1.1.0"
const val junit = "4.12"
const val espresso = "3.2.0"
object Android {
const val sdk = 29
const val minSdk = 23
}
@enginebai
enginebai / build.gradle.kts.diff
Last active October 16, 2019 10:52
Project-level build.gradle migration
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
- ext.kotlin_version = "1.3.50"
repositories {
google()
jcenter()
}
dependencies {
@enginebai
enginebai / build.gradle.kts.diff
Last active December 10, 2019 09:08
Module-level build.gradle migration
-apply plugin: "com.android.application"
-apply plugin: "kotlin-android"
-apply plugin: "kotlin-android-extensions"
+plugins {
+ id("com.android.application")
+ id("kotlin-android")
+ id("kotlin-android-extensions")
+}
android {
class GalleryViewModel : ViewModel(), KoinComponent {
var setting: AlbumSetting? = null
val multipleSelectMedia = BehaviorSubject.createDefault<MutableList<Media>>(mutableListOf())
val singleSelectMedia = PublishSubject.create<Media>()
val currentAlbumItem = BehaviorSubject.create<AlbumItem>()
private val albumRepo: AlbumRepo by inject()
fun loadAlbums(): Completable {
return albumRepo.fetchAlbums(setting)
class AlbumRepoImpl(private val context: Context) : AlbumRepo {
private val albumSubject = BehaviorSubject.create<List<AlbumItem>>()
private val albumItemMapping = mutableMapOf<String, AlbumItem>()
override fun fetchAlbums(setting: AlbumSetting?): Completable {
return Completable.fromAction {
fetchAlbumSync(setting)
}
}
interface AlbumRepo {
fun fetchAlbums(setting: AlbumSetting? = null): Completable
fun getAlbums(setting: AlbumSetting? = null): BehaviorSubject<List<AlbumItem>>
fun getAlbumItem(name: String, setting: AlbumSetting? = null): Observable<AlbumItem>
fun getAlbumItemSync(name: String, settings: AlbumSetting? = null): AlbumItem?
}
@enginebai
enginebai / Model.kt
Created October 6, 2019 01:54
Gallery model class
const val ALL_MEDIA_ALBUM_NAME = "ALL_MEDIA_ALBUM_NAME"
const val KEY_MEDIA_LIST = "mediaList"
data class AlbumItem(
val name: String,
val folder: String,
val coverImagePath: String
) {
val mediaList = mutableListOf<Media>()
}
@enginebai
enginebai / AndroidManifest.xml
Last active October 6, 2019 01:52
Gallery add permissions to AndroidManifest.xml
<manifest package="com.enginebai.gallery"
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Remember to add this line -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
...
interface PostRepository {
fun getFeeds(): Observable<PagedList<Post>>
}
class PostRepositoryImpl : PostRepository {
private val remoteDataSource: PostApiService by inject()
private val localDataSource: PostDao by inject()
private val postBoundaryCallback: postBoundaryCallback by inject()