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
fun from(responseModels: List<ResponseModel>): List<NormalUiModel> { | |
return responseModels.map { from(it) } | |
} | |
fun from(responseModel: ResponseModel): NormalUiModel { | |
return responseModel.run { | |
when (type) { | |
ResponseType.MONITOR -> NormalUiModel.Monitor(id, price, inch ?: 0f) | |
ResponseType.MOUSE -> NormalUiModel.Mouse(id, price, buttonCount ?: 0) | |
ResponseType.PHONE -> NormalUiModel.Phone(id, price, os ?: "") |
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 CommonViewModel(private val api: MockApi = MockService()) : ViewModel() // 생성자 구조 | |
private val _uiModels = MutableLiveData<List<NormalUiModel>>(emptyList()) | |
val uiModels: LiveData<List<NormalUiModel>> = _uiModels | |
val uiModelsValue get() = uiModels.value ?: emptyList() | |
fun loadMoreUiModels() { | |
if (requestLock.getAndSet(true)) return | |
isShowProgress.value = true | |
api.loadMore() |
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
binding.recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() { | |
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { | |
super.onScrolled(recyclerView, dx, dy) | |
if (dy > 0 && | |
layoutManager.findLastVisibleItemPosition() > | |
viewModel.uiModelsValue.size - INTERVAL_LOAD_MORE | |
) { | |
viewModel.loadMoreUiModels() | |
} | |
} |
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
interface MockApi { | |
fun loadMore(): Single<List<ResponseModel>> | |
} |
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.test.ext.junit.runners.AndroidJUnit4 | |
import androidx.test.platform.app.InstrumentationRegistry | |
import io.reactivex.internal.functions.Functions | |
import io.reactivex.rxkotlin.subscribeBy | |
import org.junit.Assert | |
import org.junit.Rule | |
import org.junit.Test | |
import org.junit.runner.RunWith | |
import org.koin.test.KoinTest | |
import org.koin.test.inject |
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 io.reactivex.android.plugins.RxAndroidPlugins | |
import io.reactivex.plugins.RxJavaPlugins | |
import io.reactivex.schedulers.Schedulers | |
import org.junit.rules.TestRule | |
import org.junit.runner.Description | |
import org.junit.runners.model.Statement | |
class RxSchedulerRule : TestRule { | |
override fun apply(base: Statement?, description: Description?): Statement { | |
return object : Statement() { |
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 App : Application() { | |
// 중략 | |
override fun onCreate() { | |
super.onCreate() | |
startKoin { | |
androidLogger(Level.ERROR) | |
androidContext(applicationContext) | |
modules(resultModule) |
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
val resultModule = listOf( | |
viewModelModule, | |
networkModule, | |
repositoryModule, | |
localModule, | |
etcModule | |
) |
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 SettingRepository(private val settingLocalDataSource: SettingLocalDataSource) { | |
// 중략 | |
fun getLatelySearchKeyword(): Single<List<String>> { | |
return Single.just(settingLocalDataSource.getLatelySearchKeyword()) | |
} | |
fun addLatelySearchKeyword(keyword: String): Completable { | |
settingLocalDataSource.addLatelySearchKeyword(keyword) |
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
processRemoteConfig4.createRxSingleRemoteConfig() | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe({ | |
it.run { | |
when (this) { | |
is RemoteConfigResult.Run -> { | |
Log.d(TAG, "onRun $message $etc") | |
startActivity(Intent(baseContext, MainActivity::class.java)) | |
finish() |