Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
deba92a
commit 34a3ef7
Showing
23 changed files
with
148 additions
and
161 deletions.
There are no files selected for viewing
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
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
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
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
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
3 changes: 1 addition & 2 deletions
3
app/src/main/kotlin/net/rafaeltoledo/social/data/auth/AuthManager.kt
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
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
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
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
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
6 changes: 3 additions & 3 deletions
6
app/src/main/kotlin/net/rafaeltoledo/social/di/FirstModule.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package net.rafaeltoledo.social.di | ||
|
||
import org.koin.dsl.module.applicationContext | ||
import org.koin.dsl.module.module | ||
|
||
val firstModule = applicationContext { | ||
bean { "Social App" } | ||
val firstModule = module { | ||
single { "Social App" } | ||
} |
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
32 changes: 30 additions & 2 deletions
32
app/src/main/kotlin/net/rafaeltoledo/social/ui/BaseViewModel.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,42 @@ | ||
package net.rafaeltoledo.social.ui | ||
|
||
import android.arch.lifecycle.MutableLiveData | ||
import android.arch.lifecycle.ViewModel | ||
import android.util.Log | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
import net.rafaeltoledo.social.R | ||
|
||
abstract class BaseViewModel : ViewModel() { | ||
|
||
val loading = MutableLiveData<Boolean>() | ||
val error = MutableLiveData<Int>() | ||
|
||
private val viewModelJob = Job() | ||
private val uiScope = CoroutineScope(Dispatchers.Main + viewModelJob) | ||
|
||
init { | ||
loading.postValue(false) | ||
} | ||
|
||
protected fun launchDataLoad(block: suspend CoroutineScope.() -> Unit): Job { | ||
return uiScope.launch { | ||
try { | ||
loading.postValue(true) | ||
block() | ||
} catch (error: Exception) { | ||
errorHandler(error) | ||
} finally { | ||
loading.postValue(false) | ||
} | ||
} | ||
} | ||
|
||
private val errorHandler = { e: Throwable -> | ||
Log.e("BaseViewModel", "Failed to execute", e) | ||
loading.postValue(false) | ||
error.postValue(R.string.error_default_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
Oops, something went wrong.