Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsKotlinAndroid)
alias(libs.plugins.kotlin.kapt)
alias(libs.plugins.kotlin.ksp)
alias(libs.plugins.dagger.hilt)
}

android {
Expand Down Expand Up @@ -69,7 +72,19 @@ dependencies {

// navigation
implementation(libs.navigation.compose)
implementation(libs.hilt.navigation.compose)

// pager
implementation(libs.pager)

// hilt
implementation(libs.hilt)
kapt(libs.hilt.compiler)

// network
implementation(libs.bundles.network)
ksp(libs.moshi.code.gen)

// coroutine
implementation(libs.bundles.coroutine)
}
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

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

<application
android:name=".BitApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.seoj17.android_14th_compose_zzik

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class BitApplication : Application()
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package io.seoj17.android_14th_compose_zzik
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import dagger.hilt.android.AndroidEntryPoint
import io.seoj17.android_14th_compose_zzik.ui.theme.Android14thComposeZzikTheme

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.seoj17.android_14th_compose_zzik.data

import io.seoj17.android_14th_compose_zzik.data.dto.MarketCodeResponse
import kotlinx.coroutines.flow.Flow

interface BitRepository {
suspend fun getMarketCodeList(): Flow<List<MarketCodeResponse>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.seoj17.android_14th_compose_zzik.data

import io.seoj17.android_14th_compose_zzik.data.dto.MarketCodeResponse
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class BitRepositoryImpl @Inject constructor(
private val bitService: BitService
) : BitRepository {
override suspend fun getMarketCodeList(): Flow<List<MarketCodeResponse>> = flow {
val marketCodeList = bitService.getMarketCodeList()
emit(marketCodeList)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.seoj17.android_14th_compose_zzik.data

import io.seoj17.android_14th_compose_zzik.data.dto.MarketCodeResponse
import retrofit2.http.GET
import retrofit2.http.Query

interface BitService {

@GET("/market/all")
suspend fun getMarketCodeList(
@Query("isDetails") isDetails: Boolean = false
): List<MarketCodeResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.seoj17.android_14th_compose_zzik.data

import okhttp3.Response
import okhttp3.WebSocket
import okhttp3.WebSocketListener
import okio.ByteString

class BitWebSocketListener : WebSocketListener() {
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
super.onClosed(webSocket, code, reason)
}

override fun onClosing(webSocket: WebSocket, code: Int, reason: String) {
super.onClosing(webSocket, code, reason)
webSocket.close(NORMAL_CLOSURE_STATUS, null)
webSocket.cancel()
}

override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
super.onFailure(webSocket, t, response)
}

override fun onMessage(webSocket: WebSocket, text: String) {
super.onMessage(webSocket, text)
}

override fun onMessage(webSocket: WebSocket, bytes: ByteString) {
super.onMessage(webSocket, bytes)
}

override fun onOpen(webSocket: WebSocket, response: Response) {
super.onOpen(webSocket, response)
webSocket.send("{\"type\":\"ticker\", \"symbols\": [\"BTC_KRW\"], \"tickTypes\": [\"30M\"]}")
webSocket.close(NORMAL_CLOSURE_STATUS, null) //없을 경우 끊임없이 서버와 통신함
}

companion object {
private const val NORMAL_CLOSURE_STATUS = 1000
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.seoj17.android_14th_compose_zzik.data.dto

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class MarketCodeResponse(
@Json(name = "market")
val market: String,
@Json(name = "korean_name")
val korName: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.seoj17.android_14th_compose_zzik.di

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import io.seoj17.android_14th_compose_zzik.data.BitService
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
class NetworkModule {

@Provides
@Singleton
fun providesOkHttpClient(): OkHttpClient {
val httpLoggingInterceptor = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}
return OkHttpClient.Builder()
.addInterceptor(httpLoggingInterceptor)
.build()
}

@Provides
@Singleton
fun providesRetrofit(okHttpClient: OkHttpClient): Retrofit =
Retrofit.Builder()
.baseUrl(BASE_URL)
.client(okHttpClient)
.addConverterFactory(MoshiConverterFactory.create())
.build()

@Provides
@Singleton
fun providesBitService(retrofit: Retrofit): BitService = retrofit.create(BitService::class.java)

@Provides
@Singleton
fun providesRequest(): Request =
Request.Builder()
.url(WEBSOCKET_URL)
.build()

companion object {
private const val BASE_URL = "https://api.upbit.com/v1"
private const val WEBSOCKET_URL = "wss://api.upbit.com/websocket/v1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.seoj17.android_14th_compose_zzik.di

import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import io.seoj17.android_14th_compose_zzik.data.BitRepository
import io.seoj17.android_14th_compose_zzik.data.BitRepositoryImpl
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface RepositoryModule {

@Binds
@Singleton
fun bindsBitRepository(bitRepository: BitRepositoryImpl): BitRepository
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import io.seoj17.android_14th_compose_zzik.ui.excepthome.compose.CoinInfoRoute
import io.seoj17.android_14th_compose_zzik.ui.excepthome.compose.DepositWithdrawalRoute
import io.seoj17.android_14th_compose_zzik.ui.excepthome.compose.InvestmentDetailsRoute
import io.seoj17.android_14th_compose_zzik.ui.excepthome.compose.MoreDetailsRoute
import io.seoj17.android_14th_compose_zzik.ui.home.compose.DetailRoute
import io.seoj17.android_14th_compose_zzik.ui.home.compose.HomeRoute
import io.seoj17.android_14th_compose_zzik.ui.home.navigation.homeGraph

@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.seoj17.android_14th_compose_zzik.ui.excepthome.compose
package io.seoj17.android_14th_compose_zzik.ui.excepthome

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.seoj17.android_14th_compose_zzik.ui.excepthome.compose
package io.seoj17.android_14th_compose_zzik.ui.excepthome

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.seoj17.android_14th_compose_zzik.ui.excepthome.compose
package io.seoj17.android_14th_compose_zzik.ui.excepthome

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.seoj17.android_14th_compose_zzik.ui.excepthome.compose
package io.seoj17.android_14th_compose_zzik.ui.excepthome

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.seoj17.android_14th_compose_zzik.ui.home.compose
package io.seoj17.android_14th_compose_zzik.ui.home

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.seoj17.android_14th_compose_zzik.ui.home.compose
package io.seoj17.android_14th_compose_zzik.ui.home

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -13,6 +13,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import io.seoj17.android_14th_compose_zzik.ui.common.BitTextField
import io.seoj17.android_14th_compose_zzik.ui.common.BitTopBar
import io.seoj17.android_14th_compose_zzik.ui.common.BitUnitTabPager
Expand All @@ -21,8 +22,9 @@ import io.seoj17.android_14th_compose_zzik.ui.theme.BitWhiteColor

@Composable
fun HomeRoute(
modifier: Modifier = Modifier,
onCoinInfoClicked: (String) -> Unit,
modifier: Modifier = Modifier
viewModel: HomeViewModel = hiltViewModel(),
) {
HomeScreen(
modifier = modifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.seoj17.android_14th_compose_zzik.ui.home

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import io.seoj17.android_14th_compose_zzik.data.BitRepository
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class HomeViewModel @Inject constructor(
private val bitRepository: BitRepository
) : ViewModel() {

init {
getMarketCodeList()
}

private fun getMarketCodeList() {
viewModelScope.launch {
bitRepository.getMarketCodeList().collect { marketCodeList ->
marketCodeList.forEach {
Log.d("psj", it.market + ": " + it.korName)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.navigation
import io.seoj17.android_14th_compose_zzik.navigation.BitNavigationRoute
import io.seoj17.android_14th_compose_zzik.ui.home.compose.DetailRoute
import io.seoj17.android_14th_compose_zzik.ui.home.compose.HomeRoute
import io.seoj17.android_14th_compose_zzik.ui.home.DetailRoute
import io.seoj17.android_14th_compose_zzik.ui.home.HomeRoute

fun NavGraphBuilder.homeGraph(
navController: NavController
Expand Down
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
alias(libs.plugins.kotlin.kapt) apply false
alias(libs.plugins.kotlin.ksp) apply false
alias(libs.plugins.dagger.hilt) apply false
}
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
agp = "8.3.0"
agp = "8.3.1"
kotlin = "1.9.0"
coreKtx = "1.12.0"
ksp = "1.9.10-1.0.13"
Expand All @@ -12,7 +12,7 @@ lifecycleRuntimeKtx = "2.7.0"
activityCompose = "1.8.2"
composeBom = "2023.08.00"

hilt = "2.48.1"
hilt = "2.49"

okhttp = "4.11.0"
retrofit = "2.9.0"
Expand Down