diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..60453d1 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 595907a..9055ffe 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -6,15 +6,15 @@ plugins { } android { - namespace = "com.example.cloudcompute" + namespace = "com.fiveoneone.cloudcompute" compileSdk = 34 defaultConfig { - applicationId = "com.example.cloudcompute" + applicationId = "com.fiveoneone.cloudcompute" minSdk = 26 targetSdk = 33 versionCode = 1 - versionName = "1.0" + versionName = "1.00" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { @@ -51,8 +51,10 @@ android { dependencies { + //네비게이션 implementation("androidx.core:core-ktx:1.9.0") implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2") + implementation("androidx.appcompat:appcompat:1.7.0") implementation("androidx.databinding:databinding-runtime:8.4.1") implementation("androidx.datastore:datastore-core-android:1.1.1") @@ -68,4 +70,14 @@ dependencies { kapt("com.google.dagger:hilt-android-compiler:2.48") implementation("com.google.android.material:material:1.7.0") kapt("androidx.hilt:hilt-compiler:1.0.0") + + //retrofit2 + implementation ("com.squareup.retrofit2:retrofit:2.9.0") + implementation ("com.squareup.retrofit2:converter-gson:2.9.0") + + //Http 통신 로그 + implementation ("com.squareup.okhttp3:logging-interceptor:4.9.0") + + //리사이클러뷰 + implementation("androidx.recyclerview:recyclerview:1.3.2") } \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/cloudcompute/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/fiveoneone/cloudcompute/ExampleInstrumentedTest.kt similarity index 94% rename from app/src/androidTest/java/com/example/cloudcompute/ExampleInstrumentedTest.kt rename to app/src/androidTest/java/com/fiveoneone/cloudcompute/ExampleInstrumentedTest.kt index 8b78166..39839a5 100644 --- a/app/src/androidTest/java/com/example/cloudcompute/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/com/fiveoneone/cloudcompute/ExampleInstrumentedTest.kt @@ -1,4 +1,4 @@ -package com.example.cloudcompute +package com.fiveoneone.cloudcompute import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a551be6..b3aa099 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,16 +2,21 @@ + + - - + @@ -19,12 +24,9 @@ - - - + android:exported="false" /> \ No newline at end of file diff --git a/app/src/main/java/com/example/cloudcompute/ui/main/home/HomeFragment.kt b/app/src/main/java/com/example/cloudcompute/ui/main/home/HomeFragment.kt deleted file mode 100644 index 291e8ff..0000000 --- a/app/src/main/java/com/example/cloudcompute/ui/main/home/HomeFragment.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.example.cloudcompute.ui.main.home - -import android.os.Bundle -import android.view.View -import androidx.fragment.app.viewModels -import com.example.cloudcompute.R -import com.example.cloudcompute.base.BaseFragment -import com.example.cloudcompute.databinding.FragmentHomeBinding - -class HomeFragment: BaseFragment(R.layout.fragment_home) { - - private val viewModel: HomeViewModel by viewModels() - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - binding.vm = viewModel - binding.lifecycleOwner = viewLifecycleOwner - - viewModel.setDummy() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/cloudcompute/ui/main/home/HomeViewModel.kt b/app/src/main/java/com/example/cloudcompute/ui/main/home/HomeViewModel.kt deleted file mode 100644 index 1e8bff5..0000000 --- a/app/src/main/java/com/example/cloudcompute/ui/main/home/HomeViewModel.kt +++ /dev/null @@ -1,58 +0,0 @@ -package com.example.cloudcompute.ui.main.home - - -import androidx.lifecycle.ViewModel -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.flow.update -import java.text.SimpleDateFormat -import java.util.Date -import java.util.Locale -import javax.inject.Inject - - -data class HomeUiState( - val currentDateTime: String = "", - val status: Status = Status.LEISURELY, - val expectedWaitTime: Int = 0, - val expectedPeopleCount: Int = 0 -) - -enum class Status { - LEISURELY, NORMAL, CROWDED -} - -@HiltViewModel -class HomeViewModel @Inject constructor() : ViewModel() { - - private val _uiState = MutableStateFlow(HomeUiState()) - val uiState: StateFlow = _uiState.asStateFlow() - - fun setDummy() { - _uiState.update { state -> - state.copy( - currentDateTime = getCurrentDateTime(), - status = Status.CROWDED, - expectedPeopleCount = 15, - expectedWaitTime = 10 - ) - } - - } - - fun getStatusText(status: Status): String { - return when (status) { - Status.LEISURELY -> "여유" - Status.NORMAL -> "보통" - Status.CROWDED -> "혼잡" - } - } -} - -private fun getCurrentDateTime(): String { - val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm a", Locale.getDefault()) - return dateFormat.format(Date()) -} - diff --git a/app/src/main/java/com/example/cloudcompute/App.kt b/app/src/main/java/com/fiveoneone/cloudcompute/App.kt similarity index 77% rename from app/src/main/java/com/example/cloudcompute/App.kt rename to app/src/main/java/com/fiveoneone/cloudcompute/App.kt index d85e01a..8ac5d68 100644 --- a/app/src/main/java/com/example/cloudcompute/App.kt +++ b/app/src/main/java/com/fiveoneone/cloudcompute/App.kt @@ -1,4 +1,4 @@ -package com.example.cloudcompute +package com.fiveoneone.cloudcompute import android.app.Application import dagger.hilt.android.HiltAndroidApp diff --git a/app/src/main/java/com/example/cloudcompute/base/BaseActivity.kt b/app/src/main/java/com/fiveoneone/cloudcompute/base/BaseActivity.kt similarity index 96% rename from app/src/main/java/com/example/cloudcompute/base/BaseActivity.kt rename to app/src/main/java/com/fiveoneone/cloudcompute/base/BaseActivity.kt index 6c23d10..5c07af8 100644 --- a/app/src/main/java/com/example/cloudcompute/base/BaseActivity.kt +++ b/app/src/main/java/com/fiveoneone/cloudcompute/base/BaseActivity.kt @@ -1,4 +1,4 @@ -package com.example.cloudcompute.base +package com.fiveoneone.cloudcompute.base import android.os.Bundle import android.view.LayoutInflater diff --git a/app/src/main/java/com/example/cloudcompute/base/BaseFragment.kt b/app/src/main/java/com/fiveoneone/cloudcompute/base/BaseFragment.kt similarity index 98% rename from app/src/main/java/com/example/cloudcompute/base/BaseFragment.kt rename to app/src/main/java/com/fiveoneone/cloudcompute/base/BaseFragment.kt index 997c0a7..d6ffddc 100644 --- a/app/src/main/java/com/example/cloudcompute/base/BaseFragment.kt +++ b/app/src/main/java/com/fiveoneone/cloudcompute/base/BaseFragment.kt @@ -1,4 +1,4 @@ -package com.example.cloudcompute.base +package com.fiveoneone.cloudcompute.base import android.content.Context import android.os.Bundle diff --git a/app/src/main/java/com/example/cloudcompute/bindingAdapters/HomeBindingAdapters.kt b/app/src/main/java/com/fiveoneone/cloudcompute/bindingAdapters/HomeBindingAdapters.kt similarity index 72% rename from app/src/main/java/com/example/cloudcompute/bindingAdapters/HomeBindingAdapters.kt rename to app/src/main/java/com/fiveoneone/cloudcompute/bindingAdapters/HomeBindingAdapters.kt index a4eb70d..2867bcd 100644 --- a/app/src/main/java/com/example/cloudcompute/bindingAdapters/HomeBindingAdapters.kt +++ b/app/src/main/java/com/fiveoneone/cloudcompute/bindingAdapters/HomeBindingAdapters.kt @@ -1,11 +1,11 @@ -package com.example.cloudcompute.bindingAdapters +package com.fiveoneone.cloudcompute.bindingAdapters import android.view.View import android.widget.Button import android.widget.ImageView import androidx.databinding.BindingAdapter -import com.example.cloudcompute.R -import com.example.cloudcompute.ui.main.home.Status +import com.fiveoneone.cloudcompute.R +import com.fiveoneone.cloudcompute.ui.main.home.Status @BindingAdapter("statusBackground") fun setStatusBackground(view: View, status: Status?) { @@ -14,6 +14,8 @@ fun setStatusBackground(view: View, status: Status?) { Status.LEISURELY -> R.color.leisurely_main Status.NORMAL -> R.color.normal_main Status.CROWDED -> R.color.crowded_main + Status.SENSOR_ERROR -> R.color.error_main + Status.SENSOR_INACTIVE -> R.color.inactive_main } view.setBackgroundColor(view.context.getColor(color)) } @@ -26,6 +28,8 @@ fun setStatusBackgroundResource(button: Button, status: Status?) { Status.LEISURELY -> R.drawable.rect_leisure Status.NORMAL -> R.drawable.rect_common Status.CROWDED -> R.drawable.rect_crowded + Status.SENSOR_ERROR -> R.drawable.rect_error + Status.SENSOR_INACTIVE -> R.drawable.rect_inactive } button.setBackgroundResource(backgroundResource) } @@ -38,6 +42,8 @@ fun setStatusImage(imageView: ImageView, status: Status?) { Status.LEISURELY -> R.drawable.ic_leisure Status.NORMAL -> R.drawable.ic_normal Status.CROWDED -> R.drawable.ic_crowded + Status.SENSOR_ERROR -> R.drawable.ic_error + Status.SENSOR_INACTIVE -> R.drawable.ic_inactive } imageView.setImageResource(imageResource) } diff --git a/app/src/main/java/com/example/cloudcompute/customview/LoadingDialog.kt b/app/src/main/java/com/fiveoneone/cloudcompute/customview/LoadingDialog.kt similarity index 92% rename from app/src/main/java/com/example/cloudcompute/customview/LoadingDialog.kt rename to app/src/main/java/com/fiveoneone/cloudcompute/customview/LoadingDialog.kt index 438639b..ddba50a 100644 --- a/app/src/main/java/com/example/cloudcompute/customview/LoadingDialog.kt +++ b/app/src/main/java/com/fiveoneone/cloudcompute/customview/LoadingDialog.kt @@ -5,7 +5,7 @@ import android.content.Context import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.view.Window -import com.example.cloudcompute.databinding.DialogLoadingBinding +import com.fiveoneone.cloudcompute.databinding.DialogLoadingBinding class LoadingDialog(context : Context) : Dialog(context) { diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/repository/RetrofitClient.kt b/app/src/main/java/com/fiveoneone/cloudcompute/repository/RetrofitClient.kt new file mode 100644 index 0000000..16fc3da --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/repository/RetrofitClient.kt @@ -0,0 +1,38 @@ +package com.fiveoneone.cloudcompute.repository + +import com.fiveoneone.cloudcompute.service.CongestionApiService +import com.fiveoneone.cloudcompute.service.RecommendApiService +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory + +object RetrofitClient { + private const val BASE_URL = "https://ohanahana.kro.kr/" + + private val loggingInterceptor = HttpLoggingInterceptor().apply { + level = HttpLoggingInterceptor.Level.BODY + } + + private val okHttpClient = OkHttpClient.Builder() + .addInterceptor(loggingInterceptor) + .build() + + val congestionService: CongestionApiService by lazy { + Retrofit.Builder() + .baseUrl(BASE_URL) + .addConverterFactory(GsonConverterFactory.create()) + .client(okHttpClient) + .build() + .create(CongestionApiService::class.java) + } + + val recommendService: RecommendApiService by lazy { + Retrofit.Builder() + .baseUrl(BASE_URL) + .addConverterFactory(GsonConverterFactory.create()) + .client(okHttpClient) + .build() + .create(RecommendApiService::class.java) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/service/CongestionApiService.kt b/app/src/main/java/com/fiveoneone/cloudcompute/service/CongestionApiService.kt new file mode 100644 index 0000000..81a2533 --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/service/CongestionApiService.kt @@ -0,0 +1,14 @@ +package com.fiveoneone.cloudcompute.service + +import com.fiveoneone.cloudcompute.service.dto.CongestionData +import retrofit2.Call +import retrofit2.http.GET + +interface CongestionApiService { + + /** + * [GET] 혼잡도 조회하기 + */ + @GET("/congestion/") + fun getCongestion(): Call +} \ No newline at end of file diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/service/RecommendApiService.kt b/app/src/main/java/com/fiveoneone/cloudcompute/service/RecommendApiService.kt new file mode 100644 index 0000000..0da40f5 --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/service/RecommendApiService.kt @@ -0,0 +1,14 @@ +package com.fiveoneone.cloudcompute.service + +import com.fiveoneone.cloudcompute.service.dto.RecommendData +import retrofit2.Call +import retrofit2.http.GET + +interface RecommendApiService { + + /** + * [GET] 추천 버스 조회하기 + */ + @GET("/bus") + fun getRecommend(): Call +} \ No newline at end of file diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/service/ShuttleApiService.kt b/app/src/main/java/com/fiveoneone/cloudcompute/service/ShuttleApiService.kt new file mode 100644 index 0000000..9e83300 --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/service/ShuttleApiService.kt @@ -0,0 +1,14 @@ +package com.fiveoneone.cloudcompute.service + +import com.fiveoneone.cloudcompute.service.dto.ShuttleData +import retrofit2.Call +import retrofit2.http.GET + +interface ShuttleApiService { + + /** + * [GET] 셔틀 버스 조회하기 + */ + @GET("/bus/shuttle") + fun getShuttle(): Call +} \ No newline at end of file diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/service/dto/CongestionData.kt b/app/src/main/java/com/fiveoneone/cloudcompute/service/dto/CongestionData.kt new file mode 100644 index 0000000..bde7c2f --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/service/dto/CongestionData.kt @@ -0,0 +1,9 @@ +package com.fiveoneone.cloudcompute.service.dto + +data class CongestionData( + val currentLocation : String, + val currentDateTime : String, + val congestion: String, + val expectedWaitingTime: String, + val expectedWaitingPeople: String + ) \ No newline at end of file diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/service/dto/ErrorResponse.kt b/app/src/main/java/com/fiveoneone/cloudcompute/service/dto/ErrorResponse.kt new file mode 100644 index 0000000..d7694c0 --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/service/dto/ErrorResponse.kt @@ -0,0 +1,5 @@ +package com.fiveoneone.cloudcompute.service.dto + +data class ErrorResponse( + val errorMessage: String +) \ No newline at end of file diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/service/dto/RecommendData.kt b/app/src/main/java/com/fiveoneone/cloudcompute/service/dto/RecommendData.kt new file mode 100644 index 0000000..2255b5e --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/service/dto/RecommendData.kt @@ -0,0 +1,19 @@ +package com.fiveoneone.cloudcompute.service.dto + +data class RecommendData( + val shuttle: BusInfo, + val ddg: BusInfo, + val yg: BusInfo, + val inhaFrontGate: BusInfo) { + data class BusInfo( + val busStopName: String, + val busStopNumber: String?, + val busNumber: String, + val remainTime: Int, + val remainBusStop: Int, + val congestion: Int, + val des: String, + val estimatedTime: Int, + val isTransfer: Boolean + ) +} diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/service/dto/ShuttleData.kt b/app/src/main/java/com/fiveoneone/cloudcompute/service/dto/ShuttleData.kt new file mode 100644 index 0000000..1b549c4 --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/service/dto/ShuttleData.kt @@ -0,0 +1,8 @@ +package com.fiveoneone.cloudcompute.service.dto + +data class ShuttleData( + val remainTime: Int, + val departureTime: String, + val src: String, + val des: String +) \ No newline at end of file diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/service/dto/Todo.kt b/app/src/main/java/com/fiveoneone/cloudcompute/service/dto/Todo.kt new file mode 100644 index 0000000..692128a --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/service/dto/Todo.kt @@ -0,0 +1,6 @@ +package com.fiveoneone.cloudcompute.service.dto + +data class Todo( + val title: String, + var completed: Boolean +) \ No newline at end of file diff --git a/app/src/main/java/com/example/cloudcompute/ui/main/MainActivity.kt b/app/src/main/java/com/fiveoneone/cloudcompute/ui/main/MainActivity.kt similarity index 84% rename from app/src/main/java/com/example/cloudcompute/ui/main/MainActivity.kt rename to app/src/main/java/com/fiveoneone/cloudcompute/ui/main/MainActivity.kt index 61d0766..0eb6a2d 100644 --- a/app/src/main/java/com/example/cloudcompute/ui/main/MainActivity.kt +++ b/app/src/main/java/com/fiveoneone/cloudcompute/ui/main/MainActivity.kt @@ -1,15 +1,14 @@ -package com.example.cloudcompute.ui.main +package com.fiveoneone.cloudcompute.ui.main import android.graphics.Color -import android.os.Build import android.os.Bundle import android.view.View import android.view.WindowManager import androidx.navigation.NavController import androidx.navigation.fragment.NavHostFragment -import com.example.cloudcompute.R -import com.example.cloudcompute.base.BaseActivity -import com.example.cloudcompute.databinding.ActivityMainBinding +import com.fiveoneone.cloudcompute.R +import com.fiveoneone.cloudcompute.base.BaseActivity +import com.fiveoneone.cloudcompute.databinding.ActivityMainBinding import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/ui/main/home/HomeFragment.kt b/app/src/main/java/com/fiveoneone/cloudcompute/ui/main/home/HomeFragment.kt new file mode 100644 index 0000000..c653ce6 --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/ui/main/home/HomeFragment.kt @@ -0,0 +1,72 @@ +package com.fiveoneone.cloudcompute.ui.main.home + +import android.content.Intent +import android.os.Bundle +import android.view.View +import androidx.fragment.app.viewModels +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.repeatOnLifecycle +import com.fiveoneone.cloudcompute.R +import com.fiveoneone.cloudcompute.base.BaseFragment +import com.fiveoneone.cloudcompute.databinding.FragmentHomeBinding +import com.fiveoneone.cloudcompute.ui.recommendation.RecommendActivity +import com.motax.modutaxi.presentation.customview.LoadingDialog +import kotlinx.coroutines.launch + +class HomeFragment : BaseFragment(R.layout.fragment_home) { + + private val viewModel: HomeViewModel by viewModels() + private lateinit var loadingDialog: LoadingDialog + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + loadingDialog = LoadingDialog(requireContext()) + + binding.vm = viewModel + binding.lifecycleOwner = viewLifecycleOwner + + binding.ivRefresh.setOnClickListener { + viewModel.fetchCongestion() + binding.ivRefresh.isEnabled = false + binding.progressBar.visibility = View.VISIBLE + } + + binding.btnFindAlternative.setOnClickListener { + val intent = Intent(requireContext(), RecommendActivity::class.java) + startActivity(intent) + } + + binding.layoutHome.visibility = View.GONE + +// viewLifecycleOwner.lifecycleScope.launch { +// viewLifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { +// viewModel.uiState.collect { state -> +// if (!state.isLoading) { +// binding.layoutHome.visibility = View.VISIBLE +// } +// } +// } +// } + + viewLifecycleOwner.lifecycleScope.launchWhenStarted { + viewModel.uiState.collect { state -> + if (state.isLoading) { + binding.progressBar.visibility = View.VISIBLE + binding.ivRefresh.isEnabled = false + } else { + binding.layoutHome.visibility = View.VISIBLE + binding.progressBar.visibility = View.GONE + binding.ivRefresh.isEnabled = true + } + } + } + + viewModel.fetchCongestion() + + } + + + +} \ No newline at end of file diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/ui/main/home/HomeViewModel.kt b/app/src/main/java/com/fiveoneone/cloudcompute/ui/main/home/HomeViewModel.kt new file mode 100644 index 0000000..bbb20c3 --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/ui/main/home/HomeViewModel.kt @@ -0,0 +1,91 @@ +package com.fiveoneone.cloudcompute.ui.main.home + + +import android.util.Log +import androidx.lifecycle.ViewModel +import com.fiveoneone.cloudcompute.repository.RetrofitClient +import com.fiveoneone.cloudcompute.service.dto.CongestionData +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.update +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response +import javax.inject.Inject + + +data class HomeUiState( + val currentDateTime: String = "", + val status: Status? = Status.SENSOR_INACTIVE, + val expectedWaitTime: String = "-", + val expectedPeopleCount: String = "-", + val isLoading: Boolean = true +) + +enum class Status { + LEISURELY, NORMAL, CROWDED, SENSOR_ERROR, SENSOR_INACTIVE +} + +@HiltViewModel +class HomeViewModel @Inject constructor() : ViewModel() { + + private val _uiState = MutableStateFlow(HomeUiState()) + val uiState: StateFlow = _uiState.asStateFlow() + + fun getStatusText(status: Status): String { + return when (status) { + Status.LEISURELY -> "여유" + Status.NORMAL -> "보통" + Status.CROWDED -> "혼잡" + Status.SENSOR_ERROR -> "센서 이상" + Status.SENSOR_INACTIVE -> "센서 미작동 시간" + } + } + + fun getStatusFromText(text: String): Status { + return when (text) { + "SPARE" -> Status.LEISURELY + "NORMAL" -> Status.NORMAL + "CONGESTION" -> Status.CROWDED + "SENSOR_ERROR" -> Status.SENSOR_ERROR + "SENSOR_INACTIVE" -> Status.SENSOR_INACTIVE + else -> throw IllegalArgumentException("Unknown status text: $text") + } + } + + fun fetchCongestion() { + + _uiState.update { it.copy(isLoading = true) } + + RetrofitClient.congestionService.getCongestion() + .enqueue(object : Callback { + override fun onResponse(call: Call, response: Response) { + if (response.isSuccessful) { + response.body()?.let { + Log.d("debugging", "$it") + _uiState.update {state -> + state.copy( + currentDateTime = it.currentDateTime, + //status = getStatusFromText(it.congestion), + status = Status.SENSOR_INACTIVE, + expectedWaitTime = it.expectedWaitingTime, + expectedPeopleCount = it.expectedWaitingPeople, + isLoading = false + ) + + } + } + } + } + + override fun onFailure(call: Call, t: Throwable) { + Log.e("debugging", "API 요청 중 오류 발생: ${t.message}") + } + }) + } + + + +} \ No newline at end of file diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/ui/recommendation/DividerItemDecoration.kt b/app/src/main/java/com/fiveoneone/cloudcompute/ui/recommendation/DividerItemDecoration.kt new file mode 100644 index 0000000..6ced2b1 --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/ui/recommendation/DividerItemDecoration.kt @@ -0,0 +1,43 @@ +package com.fiveoneone.cloudcompute.ui.recommendation + +import android.content.Context +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.Path +import android.graphics.Rect +import android.graphics.DashPathEffect +import android.view.View +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.RecyclerView +import com.fiveoneone.cloudcompute.R + +class DividerItemDecoration(context: Context) : RecyclerView.ItemDecoration() { + + private val paint = Paint().apply { + color = ContextCompat.getColor(context, R.color.divider_color) + style = Paint.Style.STROKE + strokeWidth = context.resources.getDimension(R.dimen.divider_height) + pathEffect = DashPathEffect(floatArrayOf(10f, 10f), 0f) + } + + override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) { + val left = parent.paddingLeft + val right = parent.width - parent.paddingRight + + for (i in 0 until parent.childCount) { + val child = parent.getChildAt(i) + val params = child.layoutParams as RecyclerView.LayoutParams + val top = child.bottom + params.bottomMargin + val bottom = top + paint.strokeWidth.toInt() + val path = Path().apply { + moveTo(left.toFloat(), top.toFloat()) + lineTo(right.toFloat(), top.toFloat()) + } + c.drawPath(path, paint) + } + } + + override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) { + outRect.bottom = paint.strokeWidth.toInt() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/ui/recommendation/RecommendActivity.kt b/app/src/main/java/com/fiveoneone/cloudcompute/ui/recommendation/RecommendActivity.kt new file mode 100644 index 0000000..fb47eb0 --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/ui/recommendation/RecommendActivity.kt @@ -0,0 +1,52 @@ +package com.fiveoneone.cloudcompute.ui.recommendation + +import android.os.Bundle +import android.view.View +import androidx.activity.viewModels +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import com.fiveoneone.cloudcompute.base.BaseActivity +import com.fiveoneone.cloudcompute.databinding.ActivityRecommendBinding + +class RecommendActivity : BaseActivity(ActivityRecommendBinding::inflate) { + + private val viewModel: RecommendViewModel by viewModels() + private val recyclerViewAdapter = RecommendAdapter(mutableListOf()) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + binding.rvRecommendContent.apply { + layoutManager = LinearLayoutManager(this@RecommendActivity) + adapter = recyclerViewAdapter + addItemDecoration(DividerItemDecoration(context)) // ItemDecoration 추가 + } + + // LiveData 옵저빙 + viewModel.busData.observe(this, Observer { data -> + recyclerViewAdapter.updateData(data) + }) + + viewModel.isLoading.observe(this, Observer { isLoading -> + showLoading(isLoading) + }) + + // 뒤로가기 버튼 클릭 이벤트 + binding.btnBack.setOnClickListener { + finish() // 액티비티 종료 + } + + binding.btnRefresh.setOnClickListener { + viewModel.fetchRecommend() // 새로고침 시 API 다시 호출 + } + } + + private fun showLoading(show: Boolean) { + if(show) { + binding.progressBar.visibility = View.VISIBLE + } + if(!show) { + binding.progressBar.visibility = View.GONE + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/ui/recommendation/RecommendAdapter.kt b/app/src/main/java/com/fiveoneone/cloudcompute/ui/recommendation/RecommendAdapter.kt new file mode 100644 index 0000000..91773cb --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/ui/recommendation/RecommendAdapter.kt @@ -0,0 +1,83 @@ +package com.fiveoneone.cloudcompute.ui.recommendation + +import android.graphics.Typeface +import android.os.CountDownTimer +import android.text.SpannableString +import android.text.Spanned +import android.text.style.RelativeSizeSpan +import android.text.style.StyleSpan +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.fiveoneone.cloudcompute.R +import java.util.concurrent.TimeUnit + +class RecommendAdapter(private var itemList: MutableList) : RecyclerView.Adapter() { + + class RecommendViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val busStopNameTextView: TextView = itemView.findViewById(R.id.tv_bus_stop_name) + val subwayNameTextView: TextView = itemView.findViewById(R.id.tv_subway_name) + val busNameTextView: TextView = itemView.findViewById(R.id.tv_bus_name) + val remainTimeTextView: TextView = itemView.findViewById(R.id.tv_remain_time) + val estimatedTimeTextView: TextView = itemView.findViewById(R.id.tv_estimated_time) + var countDownTimer: CountDownTimer? = null // 타이머를 보관하기 위한 변수 + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecommendViewHolder { + val itemView = LayoutInflater.from(parent.context) + .inflate(R.layout.item_recommend, parent, false) + return RecommendViewHolder(itemView) + } + + override fun onBindViewHolder(holder: RecommendViewHolder, position: Int) { + val currentItem = itemList[position] + holder.busStopNameTextView.text = currentItem.busStopName + holder.subwayNameTextView.text = currentItem.subwayName + holder.busNameTextView.text = currentItem.busName + + // 이전 타이머가 있다면 취소 + holder.countDownTimer?.cancel() + + // 남은 시간 텍스트 설정 + holder.countDownTimer = object : CountDownTimer(currentItem.remainTime, 1000) { + override fun onTick(millisUntilFinished: Long) { + currentItem.remainTime = millisUntilFinished + val minutes = TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) + val seconds = TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) % 60 + + holder.remainTimeTextView.text = if (minutes > 0) { + String.format("%d분 %d초 전", minutes, seconds) + } else { + String.format("%d초 전", seconds) + } + } + + override fun onFinish() { + holder.remainTimeTextView.text = "없음" + } + }.start() + + // 예상 소요 시간 텍스트 설정 + val estimatedTimeText = currentItem.estimatedTime + val spannableString = SpannableString(estimatedTimeText) + val start = estimatedTimeText.indexOfFirst { it.isDigit() } + val end = estimatedTimeText.indexOfFirst { it == '분' } + + if (start >= 0 && end > start) { + spannableString.setSpan(StyleSpan(Typeface.BOLD), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) + spannableString.setSpan(RelativeSizeSpan(1.2f), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) + } + + holder.estimatedTimeTextView.text = spannableString + } + + override fun getItemCount() = itemList.size + + fun updateData(newItemList: List) { + itemList.clear() + itemList.addAll(newItemList) + notifyDataSetChanged() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/ui/recommendation/RecommendItem.kt b/app/src/main/java/com/fiveoneone/cloudcompute/ui/recommendation/RecommendItem.kt new file mode 100644 index 0000000..7d3599f --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/ui/recommendation/RecommendItem.kt @@ -0,0 +1,9 @@ +package com.fiveoneone.cloudcompute.ui.recommendation + +data class RecommendItem( + val busStopName: String, + val subwayName: String, + val busName: String, + var remainTime: Long, + val estimatedTime: String, +) diff --git a/app/src/main/java/com/fiveoneone/cloudcompute/ui/recommendation/RecommendViewModel.kt b/app/src/main/java/com/fiveoneone/cloudcompute/ui/recommendation/RecommendViewModel.kt new file mode 100644 index 0000000..174c07e --- /dev/null +++ b/app/src/main/java/com/fiveoneone/cloudcompute/ui/recommendation/RecommendViewModel.kt @@ -0,0 +1,66 @@ +package com.fiveoneone.cloudcompute.ui.recommendation + +import android.util.Log +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.fiveoneone.cloudcompute.repository.RetrofitClient +import com.fiveoneone.cloudcompute.service.dto.RecommendData +import dagger.hilt.android.lifecycle.HiltViewModel +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response +import javax.inject.Inject + +@HiltViewModel +class RecommendViewModel @Inject constructor() : ViewModel() { + + private val _busData = MutableLiveData>() + val busData: LiveData> get() = _busData + + private val _isLoading = MutableLiveData() + val isLoading: LiveData get() = _isLoading + + init { + fetchRecommend() + } + + fun fetchRecommend() { + _isLoading.value = true + RetrofitClient.recommendService.getRecommend() + .enqueue(object : Callback { + override fun onResponse(call: Call, response: Response) { + if (response.isSuccessful) { + response.body()?.let { + val dataList = listOf( + it.shuttle.toRecommendItem(), + it.ddg.toRecommendItem(), + it.yg.toRecommendItem(), + it.inhaFrontGate.toRecommendItem() + ) + _busData.value = dataList + _isLoading.value = false + } + } else { + Log.e("RecommendViewModel", "Response was not successful") + _isLoading.value = false + } + } + + override fun onFailure(call: Call, t: Throwable) { + Log.e("RecommendViewModel", "API 요청 중 오류 발생: ${t.message}") + _isLoading.value = false + } + }) + } + + private fun RecommendData.BusInfo.toRecommendItem(): RecommendItem { + return RecommendItem( + busStopName = busStopName + if (!busStopNumber.isNullOrEmpty()) "($busStopNumber)" else "", + subwayName = des, + busName = busNumber, + remainTime = remainTime * 1000L, + estimatedTime = "예상 소요 ${estimatedTime}분" + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/cloudcompute/ui/splash/SplashActivity.kt b/app/src/main/java/com/fiveoneone/cloudcompute/ui/splash/SplashActivity.kt similarity index 65% rename from app/src/main/java/com/example/cloudcompute/ui/splash/SplashActivity.kt rename to app/src/main/java/com/fiveoneone/cloudcompute/ui/splash/SplashActivity.kt index 409a3f3..3206e7d 100644 --- a/app/src/main/java/com/example/cloudcompute/ui/splash/SplashActivity.kt +++ b/app/src/main/java/com/fiveoneone/cloudcompute/ui/splash/SplashActivity.kt @@ -1,17 +1,12 @@ -package com.example.cloudcompute.ui.splash +package com.fiveoneone.cloudcompute.ui.splash import android.content.Intent import android.os.Bundle import android.os.Handler import android.os.Looper -import com.example.cloudcompute.base.BaseActivity -import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity -import com.example.cloudcompute.R -import com.example.cloudcompute.databinding.ActivitySplashBinding -import com.example.cloudcompute.ui.main.MainActivity -import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.delay +import com.fiveoneone.cloudcompute.R +import com.fiveoneone.cloudcompute.ui.main.MainActivity class SplashActivity : AppCompatActivity() { @@ -29,7 +24,7 @@ class SplashActivity : AppCompatActivity() { // 이동한 다음 사용안함으로 finish 처리 finish() - }, 4000) // 시간 2초 이후 실행 + }, 1000) // 시간 2초 이후 실행 } } \ No newline at end of file diff --git a/app/src/main/java/com/example/cloudcompute/ui/splash/SplashViewModel.kt b/app/src/main/java/com/fiveoneone/cloudcompute/ui/splash/SplashViewModel.kt similarity index 73% rename from app/src/main/java/com/example/cloudcompute/ui/splash/SplashViewModel.kt rename to app/src/main/java/com/fiveoneone/cloudcompute/ui/splash/SplashViewModel.kt index 7f663d1..351237a 100644 --- a/app/src/main/java/com/example/cloudcompute/ui/splash/SplashViewModel.kt +++ b/app/src/main/java/com/fiveoneone/cloudcompute/ui/splash/SplashViewModel.kt @@ -1,4 +1,4 @@ -package com.example.cloudcompute.ui.splash +package com.fiveoneone.cloudcompute.ui.splash import androidx.lifecycle.ViewModel import javax.inject.Inject diff --git a/app/src/main/res/drawable/ic_back_black.xml b/app/src/main/res/drawable/ic_back_black.xml new file mode 100644 index 0000000..3f35298 --- /dev/null +++ b/app/src/main/res/drawable/ic_back_black.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_bus.xml b/app/src/main/res/drawable/ic_bus.xml new file mode 100644 index 0000000..aaae3b6 --- /dev/null +++ b/app/src/main/res/drawable/ic_bus.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/app/src/main/res/drawable/ic_error.xml b/app/src/main/res/drawable/ic_error.xml new file mode 100644 index 0000000..c6e39ad --- /dev/null +++ b/app/src/main/res/drawable/ic_error.xml @@ -0,0 +1,55 @@ + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_inactive.xml b/app/src/main/res/drawable/ic_inactive.xml new file mode 100644 index 0000000..7680bf9 --- /dev/null +++ b/app/src/main/res/drawable/ic_inactive.xml @@ -0,0 +1,47 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/ic_refresh.xml b/app/src/main/res/drawable/ic_refresh.xml new file mode 100644 index 0000000..0de3f11 --- /dev/null +++ b/app/src/main/res/drawable/ic_refresh.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_refresh_black.xml b/app/src/main/res/drawable/ic_refresh_black.xml new file mode 100644 index 0000000..b94e671 --- /dev/null +++ b/app/src/main/res/drawable/ic_refresh_black.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_subway.xml b/app/src/main/res/drawable/ic_subway.xml new file mode 100644 index 0000000..3d2ea8a --- /dev/null +++ b/app/src/main/res/drawable/ic_subway.xml @@ -0,0 +1,30 @@ + + + + + + + + + + diff --git a/app/src/main/res/drawable/rect_bus.xml b/app/src/main/res/drawable/rect_bus.xml new file mode 100644 index 0000000..26acd69 --- /dev/null +++ b/app/src/main/res/drawable/rect_bus.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/rect_error.xml b/app/src/main/res/drawable/rect_error.xml new file mode 100644 index 0000000..ebacc33 --- /dev/null +++ b/app/src/main/res/drawable/rect_error.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/rect_inactive.xml b/app/src/main/res/drawable/rect_inactive.xml new file mode 100644 index 0000000..f9153eb --- /dev/null +++ b/app/src/main/res/drawable/rect_inactive.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_recommend.xml b/app/src/main/res/layout/activity_recommend.xml new file mode 100644 index 0000000..8e445bb --- /dev/null +++ b/app/src/main/res/layout/activity_recommend.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 3bb38c0..78e5667 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -7,259 +7,277 @@ - + + + + type="com.fiveoneone.cloudcompute.ui.main.home.HomeViewModel" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - + app:layout_constraintTop_toTopOf="parent" + app:statusBackground="@{vm.uiState.status}" + tools:background="@color/leisurely_main"> + - + - + android:orientation="horizontal" + app:layout_constraintGuide_percent="0.60" /> - + android:orientation="horizontal" + app:layout_constraintGuide_percent="0.62" /> + + + + + + + + + app:layout_constraintBottom_toTopOf="@id/guideline_16_horizontal" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" /> - + - + + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/guideline_16_horizontal" + tools:text="인하대학교 후문" /> + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/current_location" + tools:text="2024-05-31 16:30 PM" /> + + + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/guideline_62_horizontal" + tools:text="여유" /> - - - - + + + + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/app/src/main/res/layout/item_recommend.xml b/app/src/main/res/layout/item_recommend.xml new file mode 100644 index 0000000..013ea35 --- /dev/null +++ b/app/src/main/res/layout/item_recommend.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/navigation/main_nav.xml b/app/src/main/res/navigation/main_nav.xml index 28d0d74..fa5aa67 100644 --- a/app/src/main/res/navigation/main_nav.xml +++ b/app/src/main/res/navigation/main_nav.xml @@ -6,7 +6,7 @@ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index a5f1fd8..c6b9947 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -12,4 +12,16 @@ #ef6c02 #FB8B01 + #515151 + #A9A9A9 + + #212020 + #484848 + + #EBEBEB + #294082 + #00CA37 + #FF4720 + #747775 + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..e6d1263 --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,4 @@ + + + 1dp + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index a399bf6..527fa3f 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -3,7 +3,7 @@ diff --git a/app/src/test/java/com/example/cloudcompute/ExampleUnitTest.kt b/app/src/test/java/com/fiveoneone/cloudcompute/ExampleUnitTest.kt similarity index 89% rename from app/src/test/java/com/example/cloudcompute/ExampleUnitTest.kt rename to app/src/test/java/com/fiveoneone/cloudcompute/ExampleUnitTest.kt index fa8a703..360a75c 100644 --- a/app/src/test/java/com/example/cloudcompute/ExampleUnitTest.kt +++ b/app/src/test/java/com/fiveoneone/cloudcompute/ExampleUnitTest.kt @@ -1,4 +1,4 @@ -package com.example.cloudcompute +package com.fiveoneone.cloudcompute import org.junit.Test