Skip to content

Commit

Permalink
Fix Issue #26
Browse files Browse the repository at this point in the history
Fix Issue #26
  • Loading branch information
KanuKim97 committed Jun 7, 2023
1 parent dee4ed8 commit 0ea1a44
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.example.koin_apps.common
object Constants {
const val BITHUMB_PUBLIC_API_URL: String = "https://api.bithumb.com/public/"
const val DELAY_TIME_MILLIS: Long = 1000L
const val RETRY_MAX_ATTEMPT: Int = 3
const val LOG_TAG: String = "로그"
const val LOG_ERROR_TAG: String = "에러"
const val RETRY_MAX_ATTEMPT = 3
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.example.koin_apps.presenter
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.koin_apps.common.Constants
import com.example.koin_apps.module.coroutineDispatcher.MainDispatcher
import com.example.koin_apps.presenter.adapter.recyclerViewAdapter.SelectRecyclerAdapter
import com.example.koin_apps.databinding.ActivitySelectKoinBinding
Expand All @@ -29,6 +31,7 @@ class SelectKoinActivity : AppCompatActivity() {

selectKoinBinding.compSelectBtn.setOnClickListener {
storeTicker()
Log.d(Constants.LOG_TAG, "${getSelectedItems()}")
startActivity(Intent(this, MainActivity::class.java))
}

Expand All @@ -42,9 +45,11 @@ class SelectKoinActivity : AppCompatActivity() {

private fun updateTickerList() = selectViewModel.tickerList.observe(this) { result ->
selectRecyclerAdapter = SelectRecyclerAdapter(result)
selectKoinBinding.CoinRecyclerView.adapter = SelectRecyclerAdapter(result)
selectKoinBinding.CoinRecyclerView.adapter = selectRecyclerAdapter
}

private fun getSelectedItems() = selectRecyclerAdapter.getSelectedItems()

private fun storeTicker(): Job =
selectViewModel.storeTickerTitle(selectRecyclerAdapter.getSelectedItems())

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.example.koin_apps.presenter.adapter.recyclerViewAdapter

import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.koin_apps.common.Constants
import com.example.koin_apps.databinding.SelectCoinviewItemBinding
import javax.inject.Inject

class SelectRecyclerAdapter @Inject constructor(
private var tickerList: List<String?>?,
private val tickerList: List<String?>?,
): RecyclerView.Adapter<SelectRecyclerAdapter.CoinsViewHolder>() {
private val selectedTickerList: MutableList<String> = mutableListOf()

Expand All @@ -17,13 +19,20 @@ class SelectRecyclerAdapter @Inject constructor(
fun bind(ticker: String) {
binding.titleCoin.text = ticker
binding.checkCoin.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) { selectedTickerList.add(ticker) }
else { selectedTickerList.remove(ticker) }
if (isChecked) {
selectedTickerList.add(ticker)
Log.d(Constants.LOG_TAG, "$selectedTickerList")
} else {
selectedTickerList.remove(ticker)
Log.d(Constants.LOG_TAG, "$selectedTickerList")
}
}
}
}

fun getSelectedItems(): List<String> = selectedTickerList
fun getSelectedItems(): List<String> {
return selectedTickerList.toList()
}

override fun onCreateViewHolder(
parent: ViewGroup,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.example.koin_apps.presenter.viewModel

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.domain.entity.TickerEntity
import com.example.domain.usecase.apiUseCase.GetTickerAllUseCase
import com.example.domain.usecase.databaseUseCase.InsertTickerUseCase
import com.example.koin_apps.common.Constants
import com.example.koin_apps.module.coroutineDispatcher.IoDispatcher
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineDispatcher
Expand All @@ -27,13 +29,11 @@ class SelectViewModel @Inject constructor(
init { loadTickerTitle() }

private fun loadTickerTitle(): Job = viewModelScope.launch(ioDispatcher) {
getTickerAllUseCase().collect { _tickerList.postValue(it) }
getTickerAllUseCase().collect { _tickerList.postValue(it.toList()) }
}

fun storeTickerTitle(tickerList: List<String>): Job = viewModelScope.launch(ioDispatcher) {
for (ticker in tickerList) {
insertTickerUseCase(TickerEntity(ticker)).collect { }
}
tickerList.forEach { insertTickerUseCase(TickerEntity(it)) }
}

override fun onCleared() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class GetTickerAllUseCase @Inject constructor(
private val bithumbApiRepo: BithumbApiRepository
) {
operator fun invoke(): Flow<MutableList<String?>> =
bithumbApiRepo.getTickerInfoAll().filter { it.remove("data") }
bithumbApiRepo.getTickerInfoAll().filter { it.remove("date") }
}

0 comments on commit 0ea1a44

Please sign in to comment.