Skip to content

Commit

Permalink
1. fix Gradle Version
Browse files Browse the repository at this point in the history
 - JAVA VERSION 1.8 -> VERSION 17
2. fix #27 Issue
3. fix domain, data AndroidManifest.xml
 - delete <application> tag
4. add annotation on DispatcherModule.kt, DispatcherQualifier.kt, AlertDialogModule.kt
5. rename TickerRemoteModule.kt -> BithumbApiModule.kt
6. delete MainDispatcher Each Views
  • Loading branch information
KanuKim97 committed Jun 9, 2023
1 parent 0ea1a44 commit c1025ca
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 188 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
freeCompilerArgs += [ "-Xjvm-default=all"]
jvmTarget = '1.8'
jvmTarget = '17'
}

buildFeatures { viewBinding = true }
Expand All @@ -50,8 +50,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'

implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.navigation:navigation-fragment-ktx:2.5.3"
implementation "androidx.navigation:navigation-ui-ktx:2.5.3"
implementation "androidx.navigation:navigation-fragment-ktx:2.6.0"
implementation "androidx.navigation:navigation-ui-ktx:2.6.0"

// Android material
implementation 'com.google.android.material:material:1.9.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

/** AlertDialog Module **/
/** AlertDialogBuilder Module **/
@Module
@InstallIn(SingletonComponent::class)
object AlertDialogModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import javax.inject.Singleton
/** Bithumb Public Api Module **/
@Module
@InstallIn(SingletonComponent::class)
object TickerRemoteModule {
object BithumbApiModule {
@Provides
fun providesBaseUrl(): String = Constants.BITHUMB_PUBLIC_API_URL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers

/** Coroutine Dispatcher Module **/
/** Coroutine Dispatcher Module (IO, Main, Default) **/
@Module
@InstallIn(SingletonComponent::class)
object DispatcherModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

/** Room Database Module **/
/** Room ORM (Local Database) Module **/
@Module
@InstallIn(SingletonComponent::class)
object TickerDBModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ package com.example.koin_apps.module.coroutineDispatcher

import javax.inject.Qualifier

/** Coroutine Dispatcher Qualifier **/
/** Coroutine IoDispatcher Qualifier **/
@Retention(AnnotationRetention.RUNTIME)
@Qualifier
annotation class IoDispatcher

/** Coroutine DefaultDispatcher Qualifier **/
@Retention(AnnotationRetention.RUNTIME)
@Qualifier
annotation class DefaultDispatcher

/** Coroutine MainDispatcher Qualifier **/
@Retention(AnnotationRetention.RUNTIME)
@Qualifier
annotation class MainDispatcher
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@ package com.example.koin_apps.presenter
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import com.example.koin_apps.R
import com.example.koin_apps.module.coroutineDispatcher.MainDispatcher
import com.example.koin_apps.databinding.ActivityLiveTimeBinding
import com.example.koin_apps.presenter.viewModel.LiveTimeViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.launch
import javax.inject.Inject

@AndroidEntryPoint
class LiveTimeActivity : AppCompatActivity() {
@MainDispatcher @Inject lateinit var mainDispatcher: CoroutineDispatcher

private val liveTimeBinding by lazy { ActivityLiveTimeBinding.inflate(layoutInflater) }
private val liveTimeViewModel: LiveTimeViewModel by viewModels()

private val orderBookFragment = OrderBookFragment()
private val fragmentBundle = Bundle()
private val orderBookFragment: OrderBookFragment = OrderBookFragment()
private val fragmentBundle: Bundle = Bundle()
private val ticker: String by lazy { setTicker() }

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -34,7 +27,6 @@ class LiveTimeActivity : AppCompatActivity() {

supportFragmentManager.beginTransaction()
.replace(R.id.FragmentLayout, orderBookFragment)
.addToBackStack(null)
.commit()

setContentView(liveTimeBinding.root)
Expand All @@ -50,14 +42,9 @@ class LiveTimeActivity : AppCompatActivity() {
private fun updateTickerTitle() { liveTimeBinding.coinTitle.text = ticker }

private fun updateTickerInfo() = liveTimeViewModel.tickerLiveViewData.observe(this) {
lifecycleScope.launch(mainDispatcher) {
liveTimeBinding.tickerWon.text =
getString(R.string.tickerWon, it.closingPrice.toString())
liveTimeBinding.Flucatate24H.text =
getString(R.string.ticker_Flucatate_won24H, it.fluctate_24H.toString())
liveTimeBinding.FlucatateRate24H.text =
getString(R.string.ticker_Flucatate_rate24H, it.fluctate_Rate.toString())
}
liveTimeBinding.tickerWon.text = getString(R.string.tickerWon, it.closingPrice.toString())
liveTimeBinding.Flucatate24H.text = getString(R.string.ticker_Flucatate_won24H, it.fluctate_24H.toString())
liveTimeBinding.FlucatateRate24H.text = getString(R.string.ticker_Flucatate_rate24H, it.fluctate_Rate.toString())
}

}
Expand Down
31 changes: 8 additions & 23 deletions app/src/main/java/com/example/koin_apps/presenter/LogoActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,29 @@ import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import com.example.koin_apps.common.Constants
import com.example.koin_apps.module.coroutineDispatcher.MainDispatcher
import com.example.koin_apps.databinding.ActivityLogoBinding
import com.example.koin_apps.presenter.viewModel.LogoViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.*
import javax.inject.Inject

@AndroidEntryPoint
class LogoActivity : AppCompatActivity() {
@MainDispatcher @Inject lateinit var mainDispatcher: CoroutineDispatcher

private val logoBinding by lazy { ActivityLogoBinding.inflate(layoutInflater) }
private val logoViewModel: LogoViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
updateUI()
setContentView(logoBinding.root)
}

private fun updateUI() {
logoViewModel.readAllTicker.observe(this) { ticker ->
if (ticker != null) {
lifecycleScope.launch(mainDispatcher) {
delay(Constants.DELAY_TIME_MILLIS)
startActivity(Intent(this@LogoActivity, MainActivity::class.java))
finish()
}
logoViewModel.readAllTicker.observe(this) { tickerList ->
if (tickerList != null) {
startActivity(Intent(this, MainActivity::class.java))
finish()
} else {
lifecycleScope.launch(mainDispatcher) {
delay(Constants.DELAY_TIME_MILLIS)
startActivity(Intent(this@LogoActivity, SelectKoinActivity::class.java))
finish()
}
startActivity(Intent(this, SelectKoinActivity::class.java))
finish()
}
}

setContentView(logoBinding.root)
}

}
47 changes: 22 additions & 25 deletions app/src/main/java/com/example/koin_apps/presenter/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,36 @@ import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.koin_apps.R
import com.example.koin_apps.module.coroutineDispatcher.MainDispatcher
import com.example.koin_apps.presenter.adapter.recyclerViewAdapter.MainRecyclerAdapter
import com.example.koin_apps.presenter.viewModel.MainViewModel
import com.example.koin_apps.databinding.ActivityMainBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
@MainDispatcher @Inject lateinit var mainDispatcher: CoroutineDispatcher
@Inject lateinit var alertDialog: AlertDialog.Builder

private val mainActivityBinding by lazy { ActivityMainBinding.inflate(layoutInflater) }
private val mainRecyclerView by lazy { mainActivityBinding.mainRecyclerView }
private val mainViewModel: MainViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

mainActivityBinding.mainRecyclerView.layoutManager = LinearLayoutManager(this)

fetchTickerDB()
updateUI()
initRecyclerView()

mainViewModel.tickerAllData.observe(this) { tickerList ->
if (tickerList != null) {
mainRecyclerView.adapter = MainRecyclerAdapter(this, tickerList)
} else {
showDataNullDialog()
}
}

mainActivityBinding.addCoinBtn.setOnClickListener {
startActivity(Intent(this, SelectKoinActivity::class.java))
Expand All @@ -41,23 +43,18 @@ class MainActivity : AppCompatActivity() {
setContentView(mainActivityBinding.root)
}

private fun updateUI() = mainViewModel.tickerAllData.observe(this) { ticker ->
if(ticker != null) {
lifecycleScope.launch(mainDispatcher) {
mainActivityBinding.mainRecyclerView.adapter =
MainRecyclerAdapter(this@MainActivity, ticker)
}
} else { lifecycleScope.launch(mainDispatcher) { showDataNullDialog() } }
}
private fun fetchTickerDB(): Job = mainViewModel.fetchAllTickerData()

private fun showDataNullDialog(): AlertDialog =
alertDialog
.setIcon(R.drawable.ic_dangerous)
.setTitle(R.string.NullDialog_Title)
.setMessage(R.string.NullDialog_Content)
.setPositiveButton(R.string.NullDialog_okBtn, null)
.show()
private fun initRecyclerView(): RecyclerView = mainActivityBinding.mainRecyclerView.apply {
layoutManager = LinearLayoutManager(this@MainActivity)
setHasFixedSize(true)
}

private fun fetchTickerDB(): Job = mainViewModel.fetchAllTickerData()
private fun showDataNullDialog(): AlertDialog = alertDialog
.setIcon(R.drawable.ic_dangerous)
.setTitle(R.string.NullDialog_Title)
.setMessage(R.string.NullDialog_Content)
.setPositiveButton(R.string.NullDialog_okBtn, null)
.show()

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,16 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import com.example.koin_apps.R
import com.example.koin_apps.module.coroutineDispatcher.MainDispatcher
import com.example.koin_apps.presenter.adapter.listViewAdapter.OrderBookAskListAdapter
import com.example.koin_apps.presenter.adapter.listViewAdapter.OrderBookBidListAdapter
import com.example.koin_apps.presenter.adapter.listViewAdapter.TransactionListAdapter
import com.example.koin_apps.databinding.FragmentOrderBookBinding
import com.example.koin_apps.presenter.viewModel.OrderBookViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.launch
import javax.inject.Inject

@AndroidEntryPoint
class OrderBookFragment : Fragment() {
@MainDispatcher @Inject lateinit var mainDispatcher: CoroutineDispatcher

private var _orderBookBinding: FragmentOrderBookBinding? = null
private val orderBookBinding get() = _orderBookBinding!!
private val orderBookViewModel: OrderBookViewModel by viewModels()
Expand All @@ -44,9 +37,26 @@ class OrderBookFragment : Fragment() {
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
updateTickerTextView()
updateTransactionList()
updateOrderBookList()
orderBookViewModel.tickerData.observe(viewLifecycleOwner) { result ->
orderBookBinding.orderBookTickerInfo.text = getString(
R.string.orderBook_Ticker_Info,
result.closingPrice.toString(),
result.prevClosingPrice.toString(),
result.maxPrice.toString(),
result.minPrice.toString(),
result.unitsTraded_24H.toString()
)
}

orderBookViewModel.transactionData.observe(viewLifecycleOwner) { result ->
orderBookBinding.transactionList.adapter = TransactionListAdapter(result)
}

orderBookViewModel.orderBookData.observe(viewLifecycleOwner) { result ->
orderBookBinding.orderBookAskList.adapter = OrderBookAskListAdapter(result.asks!!)
orderBookBinding.orderBookBidList.adapter = OrderBookBidListAdapter(result.bids!!)
}

}

override fun onDestroyView() {
Expand All @@ -56,34 +66,4 @@ class OrderBookFragment : Fragment() {

private fun setTicker(): String = arguments?.getString("coinTitle").toString()

private fun updateTickerTextView() = orderBookViewModel.tickerData
.observe(viewLifecycleOwner) { result ->
lifecycleScope.launch(mainDispatcher) {
orderBookBinding.orderBookTickerInfo.text =
getString(
R.string.orderBook_Ticker_Info,
result.closingPrice.toString(),
result.prevClosingPrice.toString(),
result.maxPrice.toString(),
result.minPrice.toString(),
result.unitsTraded_24H.toString()
)
}
}

private fun updateTransactionList() = orderBookViewModel.transactionData
.observe(viewLifecycleOwner) { result ->
lifecycleScope.launch(mainDispatcher) {
orderBookBinding.transactionList.adapter = TransactionListAdapter(result)
}
}

private fun updateOrderBookList() = orderBookViewModel.orderBookData
.observe(viewLifecycleOwner) { result ->
lifecycleScope.launch(mainDispatcher) {
orderBookBinding.orderBookAskList.adapter = OrderBookAskListAdapter(result.asks!!)
orderBookBinding.orderBookBidList.adapter = OrderBookBidListAdapter(result.bids!!)
}
}

}
Loading

0 comments on commit c1025ca

Please sign in to comment.