Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

전남대 Android_이민서_5주차 과제_Step 2 #73

Open
wants to merge 33 commits into
base: leeminseo00
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0e3e647
docs: README.md
LEEMINSEO00 Jul 25, 2024
6f595e4
feat: Room_define Entity
LEEMINSEO00 Jul 25, 2024
5515689
feat: Room_define DAO
LEEMINSEO00 Jul 25, 2024
d60dcd0
feat: Room_define, create, use Database
LEEMINSEO00 Jul 25, 2024
f0e9072
feat: Room_modify MainViewModel
LEEMINSEO00 Jul 25, 2024
35155af
feat: Room_modify MainActivity
LEEMINSEO00 Jul 25, 2024
55dc90c
feat: Room_modify SearchAdapter
LEEMINSEO00 Jul 25, 2024
9f69d1b
feat: Room_modify SavedSearchAdapter
LEEMINSEO00 Jul 25, 2024
6881aea
feat: fix error
LEEMINSEO00 Jul 25, 2024
241aedb
feat: delete DbHelper
LEEMINSEO00 Jul 25, 2024
092a7fe
feat: Hilt_application-level dependency container settings
LEEMINSEO00 Jul 25, 2024
8733fd0
feat: Hilt_create Module
LEEMINSEO00 Jul 25, 2024
0c59fd5
feat: Hilt_modify PlaceRepository
LEEMINSEO00 Jul 25, 2024
328505b
feat: Hilt_modify MainViewModel
LEEMINSEO00 Jul 25, 2024
f74f493
feat: Hilt_modify MainActivity
LEEMINSEO00 Jul 25, 2024
980c3a9
feat: Hilt_modify MapActivity
LEEMINSEO00 Jul 25, 2024
43a98b2
feat: delete comments and useless import
LEEMINSEO00 Jul 25, 2024
d66c50f
docs: README.md
LEEMINSEO00 Jul 26, 2024
2db6354
refactor: DataBinding_activity_main.xml
LEEMINSEO00 Jul 26, 2024
f42a9d9
refactor: DataBinding_MainAcitivity.kt
LEEMINSEO00 Jul 26, 2024
e55060b
refactor: DataBinding And LiveData_MainViewModel.kt
LEEMINSEO00 Jul 26, 2024
98b401b
feat: solve error
LEEMINSEO00 Jul 26, 2024
b99ff71
feat: delete comment
LEEMINSEO00 Jul 26, 2024
c01ebe2
refactor: DataBinding_activity_map.xml
LEEMINSEO00 Jul 26, 2024
d698459
refactor: DataBinding_MapActivity.kt
LEEMINSEO00 Jul 26, 2024
ec14834
refactor: DataBinding and LiveData_MapViewModel.kt
LEEMINSEO00 Jul 26, 2024
abae786
feat: solve error
LEEMINSEO00 Jul 26, 2024
fcfb501
feat: delete comment, typo and useless import
LEEMINSEO00 Jul 26, 2024
8683450
refactor: change package structure
LEEMINSEO00 Jul 29, 2024
6731b26
feat: apply feedback_use ViewModel
LEEMINSEO00 Jul 30, 2024
5f93f66
feat: apply feedback_View Data Class
LEEMINSEO00 Jul 30, 2024
e15f6b8
feat: delete comments
LEEMINSEO00 Jul 30, 2024
1d1a0d0
refactor: change package structure_UIState.kt
LEEMINSEO00 Jul 30, 2024
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# android-map-refactoring
## Step 2. 아키텍처 패턴
### 구현 기능 목록

1. MVVM 아키텍처 패턴 적용
- DataBinding, LiveData 사용
2. 비동기 처리 -> Coroutine 변경
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dependencies {
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.3")
implementation("androidx.room:room-runtime:2.6.1")
implementation("androidx.test.espresso:espresso-contrib:3.6.1")
implementation("androidx.coordinatorlayout:coordinatorlayout:1.2.0")
kapt("androidx.room:room-compiler:2.6.1")
implementation("com.google.dagger:hilt-android:2.48.1")
kapt("com.google.dagger:hilt-compiler:2.48.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@ package campus.tech.kakao.map
import androidx.test.espresso.intent.Intents
import android.os.SystemClock
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso
import androidx.test.espresso.Espresso.onIdle
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.action.ViewActions.typeText
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.withContext
import campus.tech.kakao.map.view.MainActivity
import campus.tech.kakao.map.view.MapActivity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import campus.tech.kakao.map.view.MainActivity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".MyApplication"
android:name=".application.MyApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -16,15 +16,15 @@
android:theme="@style/Theme.Map"
tools:targetApi="31">
<activity
android:name=".MapActivity"
android:name=".view.MapActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
<activity android:name=".view.MainActivity"/>
</application>

</manifest>
61 changes: 0 additions & 61 deletions app/src/main/java/campus/tech/kakao/map/MainViewModel.kt

This file was deleted.

17 changes: 0 additions & 17 deletions app/src/main/java/campus/tech/kakao/map/PlaceRepository.kt

This file was deleted.

7 changes: 0 additions & 7 deletions app/src/main/java/campus/tech/kakao/map/SearchResult.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import campus.tech.kakao.map.databinding.ItemSavedSearchBinding
import campus.tech.kakao.map.model.Place

class SavedSearchAdapter(private val onSearchClicked: (String) -> Unit, private val onDeleteClicked: (String) -> Unit) : RecyclerView.Adapter<SavedSearchAdapter.ViewHolder>() {
private val searches = mutableListOf<String>()
class SavedSearchAdapter(private val onSearchClicked: (Place) -> Unit, private val onDeleteClicked: (Place) -> Unit) : RecyclerView.Adapter<SavedSearchAdapter.ViewHolder>() {
private val searches = mutableListOf<Place>()

class ViewHolder(val binding: ItemSavedSearchBinding) : RecyclerView.ViewHolder(binding.root)

Expand All @@ -17,7 +18,7 @@ class SavedSearchAdapter(private val onSearchClicked: (String) -> Unit, private

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val search = searches[position]
holder.binding.savedTextView.text = search
holder.binding.savedTextView.text = search.name
holder.binding.savedTextView.setOnClickListener {
onSearchClicked(search)
}
Expand All @@ -30,7 +31,7 @@ class SavedSearchAdapter(private val onSearchClicked: (String) -> Unit, private
return searches.size
}

fun updateSearches(newSearches: List<String>) {
fun updateSearches(newSearches: List<Place>) {
searches.clear()
searches.addAll(newSearches)
notifyDataSetChanged()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.adapter

import androidx.recyclerview.widget.RecyclerView
import android.view.ViewGroup
import android.view.LayoutInflater
import campus.tech.kakao.map.databinding.ItemResultBinding
import android.util.Log
import campus.tech.kakao.map.model.Place

class SearchAdapter(private val onItemClicked: (Document) -> Unit) : RecyclerView.Adapter<SearchAdapter.ViewHolder>() {
class SearchAdapter(private val onItemClicked: (Place) -> Unit) : RecyclerView.Adapter<SearchAdapter.ViewHolder>() {

private val results = mutableListOf<Document>()
private val results = mutableListOf<Place>()

class ViewHolder(val binding: ItemResultBinding) : RecyclerView.ViewHolder(binding.root)

Expand All @@ -21,9 +22,9 @@ class SearchAdapter(private val onItemClicked: (Document) -> Unit) : RecyclerVie
val result = results[position]
Log.d("SearchAdapter", "Binding result at position $position: $result")

holder.binding.resultTextView.text = result.place_name
holder.binding.resultAddressTextView.text = result.address_name
holder.binding.resultCategoryTextView.text = result.category_group_name
holder.binding.resultTextView.text = result.name
holder.binding.resultAddressTextView.text = result.address
holder.binding.resultCategoryTextView.text = result.category
Log.e("SearchAdapter", "Unexpected result format: $result")

holder.binding.root.setOnClickListener {
Expand All @@ -33,7 +34,7 @@ class SearchAdapter(private val onItemClicked: (Document) -> Unit) : RecyclerVie

override fun getItemCount() = results.size

fun updateResults(newResults: List<Document>) {
fun updateResults(newResults: List<Place>) {
Log.d("SearchAdapter", "Updating results: $newResults")
results.clear()
results.addAll(newResults)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.application

import android.app.Application
import campus.tech.kakao.map.R
import com.kakao.vectormap.KakaoMapSdk
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
Expand Down
65 changes: 65 additions & 0 deletions app/src/main/java/campus/tech/kakao/map/di/AppModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package campus.tech.kakao.map.di

import android.app.Application
import androidx.room.Room
import campus.tech.kakao.map.network.AuthInterceptor
import campus.tech.kakao.map.BuildConfig
import campus.tech.kakao.map.network.KakaoAPIRetrofitService
import campus.tech.kakao.map.model.AppDatabase
import campus.tech.kakao.map.model.PlaceDao
import campus.tech.kakao.map.repository.PlaceRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object AppModule {

@Provides
@Singleton
fun provideDatabase(app: Application): AppDatabase {
return Room.databaseBuilder(app, AppDatabase::class.java, "place_database")
.fallbackToDestructiveMigration()
.build()
}

@Provides
fun providePlaceDao(database: AppDatabase): PlaceDao {
return database.placeDao()
}

@Provides
@Singleton
fun provideOkHttpClient(): OkHttpClient {
return OkHttpClient.Builder()
.addInterceptor(AuthInterceptor(BuildConfig.KAKAO_REST_API_KEY))
.build()
}

@Provides
@Singleton
fun provideRetrofit(client: OkHttpClient): Retrofit {
return Retrofit.Builder()
.baseUrl("https://dapi.kakao.com/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
}

@Provides
fun provideKakaoApiService(retrofit: Retrofit): KakaoAPIRetrofitService {
return retrofit.create(KakaoAPIRetrofitService::class.java)
}

@Provides
@Singleton
fun providePlaceRepository(apiService: KakaoAPIRetrofitService, placeDao: PlaceDao): PlaceRepository {
return PlaceRepository(apiService, placeDao)
}
}
28 changes: 28 additions & 0 deletions app/src/main/java/campus/tech/kakao/map/model/AppDatabase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package campus.tech.kakao.map.model

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

@Database(entities = [Place::class], version = 1)
abstract class AppDatabase : RoomDatabase() {
abstract fun placeDao(): PlaceDao

companion object {
@Volatile
private var INSTANCE: AppDatabase? = null

fun getDatabase(context: Context): AppDatabase {
return INSTANCE ?: synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java,
"place_database"
).build()
INSTANCE = instance
instance
}
}
}
}
14 changes: 14 additions & 0 deletions app/src/main/java/campus/tech/kakao/map/model/Place.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package campus.tech.kakao.map.model

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "places")
data class Place(
@PrimaryKey(autoGenerate = true) val id: Int = 0,
val name: String,
val address: String,
val category: String,
val x: String,
val y: String
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.model

object PlaceContract {
const val TABLE_NAME = "places"
Expand Down
Loading