Skip to content

Commit

Permalink
Merge pull request #5 from skydoves/reafactor
Browse files Browse the repository at this point in the history
Update dependencies version to the recent and migrate codes
  • Loading branch information
skydoves authored Jan 8, 2022
2 parents dcb21ab + 3e15ee4 commit db14b25
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 127 deletions.
22 changes: 15 additions & 7 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ on:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: set up JDK 1.8

- name: set up JDK
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 11

- name: Cache Gradle and wrapper
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Make Gradle executable
run: chmod +x ./gradlew

- name: Build with Gradle
run: ./gradlew build
- name: Build Debug APK
run: ./gradlew assembleDebug
run: ./gradlew build
13 changes: 3 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '11'
}
buildFeatures {
dataBinding true
Expand Down Expand Up @@ -83,12 +83,9 @@ android {
dependencies {
// android supports
implementation "com.google.android.material:material:$versions.materialVersion"
implementation "androidx.constraintlayout:constraintlayout:$versions.constraintVersion"

// architecture components
implementation "androidx.fragment:fragment-ktx:$versions.fragmentVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$versions.lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$versions.lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$versions.lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$versions.lifecycleVersion"
implementation "androidx.room:room-runtime:$versions.roomVersion"
Expand Down Expand Up @@ -128,10 +125,6 @@ dependencies {
// glide
implementation "com.github.bumptech.glide:glide:$versions.glideVersion"
implementation "com.github.florent37:glidepalette:$versions.glidePaletteVersion"
kapt "com.github.bumptech.glide:compiler:$versions.glideVersion"

// recyclerView
implementation "androidx.recyclerview:recyclerview:$versions.recyclerView"

// whatIf
implementation "com.github.skydoves:whatif:$versions.whatIfVersion"
Expand Down
21 changes: 11 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.skydoves.pokedexar">

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

<uses-feature
android:glEsVersion="0x00030000"
android:required="true" />
<uses-feature
android:name="android.hardware.camera.ar"
android:required="true" />

<application
android:name=".PokedexARApp"
android:allowBackup="false"
Expand All @@ -39,6 +29,7 @@

<activity
android:name=".ui.main.MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait">
<intent-filter>
Expand Down Expand Up @@ -72,5 +63,15 @@
android:value="androidx.startup" />
</provider>
</application>
<uses-feature
android:name="android.hardware.camera.ar"
android:required="true" />

<uses-feature
android:glEsVersion="0x00030000"
android:required="true" />
<uses-permission android:name="android.permission.CAMERA" />

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

</manifest>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ object ViewBinding {
.into(image)
val name = getContentView().findViewById<TextView>(R.id.name)
name.text = it.name
show(view.rootView)
showAtCenter(view.rootView)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import androidx.databinding.Bindable
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.skydoves.bindables.BindingViewModel
import com.skydoves.bindables.asBindingProperty
import com.skydoves.bindables.bindingProperty
import com.skydoves.pokedexar.base.LiveCoroutinesViewModel
import com.skydoves.pokedexar.model.PokemonInfo
import com.skydoves.pokedexar.repository.DetailRepository
import dagger.assisted.Assisted
Expand All @@ -32,7 +32,7 @@ import timber.log.Timber
class DetailViewModel @AssistedInject constructor(
detailRepository: DetailRepository,
@Assisted private val pokemonName: String
) : LiveCoroutinesViewModel() {
) : BindingViewModel() {

private val pokemonInfoFlow = detailRepository.fetchPokemonInfo(
name = pokemonName,
Expand Down Expand Up @@ -66,7 +66,7 @@ class DetailViewModel @AssistedInject constructor(
pokemonName: String
): ViewModelProvider.Factory = object : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return assistedFactory.create(pokemonName) as T
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package com.skydoves.pokedexar.ui.main

import androidx.databinding.Bindable
import androidx.lifecycle.viewModelScope
import com.skydoves.bindables.BindingViewModel
import com.skydoves.bindables.asBindingProperty
import com.skydoves.bindables.bindingProperty
import com.skydoves.pokedexar.base.LiveCoroutinesViewModel
import com.skydoves.pokedexar.model.Pokemon
import com.skydoves.pokedexar.repository.MainRepository
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -30,7 +30,7 @@ import javax.inject.Inject
@HiltViewModel
class MainViewModel @Inject constructor(
mainRepository: MainRepository
) : LiveCoroutinesViewModel() {
) : BindingViewModel() {

@get:Bindable
var errorMessage: String? by bindingProperty(null)
Expand Down
41 changes: 20 additions & 21 deletions app/src/main/java/com/skydoves/pokedexar/ui/scene/SceneViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,36 @@ package com.skydoves.pokedexar.ui.scene

import androidx.annotation.MainThread
import androidx.databinding.Bindable
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.asLiveData
import androidx.lifecycle.switchMap
import androidx.lifecycle.viewModelScope
import com.skydoves.bindables.BindingViewModel
import com.skydoves.bindables.asBindingProperty
import com.skydoves.bindables.bindingProperty
import com.skydoves.pokedexar.base.LiveCoroutinesViewModel
import com.skydoves.pokedexar.model.Pokemon
import com.skydoves.pokedexar.repository.SceneRepository
import com.skydoves.pokedexar_core.RenderingModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.flatMapLatest
import timber.log.Timber
import javax.inject.Inject

@HiltViewModel
class SceneViewModel @Inject constructor(
private val sceneRepository: SceneRepository
) : LiveCoroutinesViewModel() {
) : BindingViewModel() {

private val pokemonFetchingModel: MutableLiveData<RenderingModel> = MutableLiveData()
val pokemonListLiveData: LiveData<Pokemon>
private val pokemonFetchingModel: MutableStateFlow<RenderingModel?> = MutableStateFlow(null)

private val pokemonListFlow = pokemonFetchingModel.filterNotNull().flatMapLatest { model ->
sceneRepository.insertPokemon(
pokemonModel = model,
onError = { errorMessage = it }
)
}

@get:Bindable
val pokemon: Pokemon? by pokemonListFlow.asBindingProperty(viewModelScope, null)

@get:Bindable
var errorMessage: String? by bindingProperty(null)
Expand All @@ -48,20 +58,9 @@ class SceneViewModel @Inject constructor(

init {
Timber.d("init SceneViewModel")

pokemonListLiveData = pokemonFetchingModel.switchMap {
isCaught = true
launchOnViewModelScope {
this.sceneRepository.insertPokemon(
pokemonModel = it,
onError = { errorMessage = it }
).asLiveData()
}
}
}

@MainThread
fun insertPokemonModel(renderingModel: RenderingModel) {
pokemonFetchingModel.value = renderingModel
}
fun insertPokemonModel(renderingModel: RenderingModel) =
pokemonFetchingModel.tryEmit(renderingModel)
}
32 changes: 16 additions & 16 deletions app/src/main/res/layout/activity_scene.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="vm"
type="com.skydoves.pokedexar.ui.scene.SceneViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.main.MainActivity">

<View
android:id="@+id/bindingView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:bindShowingBalloon="@{vm.pokemon}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:toast="@{vm.errorMessage}" />

<fragment
android:id="@+id/arFragment"
android:name="com.google.ar.sceneform.ux.ArFragment"
Expand All @@ -40,15 +42,13 @@
app:layout_constraintTop_toTopOf="parent"
tools:ignore="FragmentTagUsage" />

<View
android:id="@+id/bindingView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:bindShowingBalloon="@{vm.pokemonListLiveData}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:toast="@{vm.errorMessage}" />

</androidx.constraintlayout.widget.ConstraintLayout>

<data>

<variable
name="vm"
type="com.skydoves.pokedexar.ui.scene.SceneViewModel" />
</data>

</layout>
Loading

0 comments on commit db14b25

Please sign in to comment.