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주차 과제_Step2 #84

Open
wants to merge 21 commits into
base: fivejinw
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# android-map-refactoring
## step1 구현할 기능 목록

- [ ] ROOM을 활용하여 장소데이터를 저장하는 기능 구현
- [ ] ROOM을 활용하여 저장된 장소데이터를 불러오는 기능 구현
- [ ] ROOM을 활용하여 저장된 장소데이터를 삭제하는 기능 구현
- [ ] Hilt를 사용하여 의존성 주입하기

-----------------------------------

## step2 구현할 기능 목록
- [ ] 데이터 바인딩을 적용하기
30 changes: 23 additions & 7 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jlleitschuh.gradle.ktlint")
id("kotlin-kapt")
id("com.google.dagger.hilt.android")
id("kotlin-parcelize")
}

Expand Down Expand Up @@ -45,25 +48,32 @@ android {
}

buildFeatures {
dataBinding = true
viewBinding = true
buildConfig = true
}

}

dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.recyclerview:recyclerview:1.3.2")
implementation("com.squareup.retrofit2:retrofit:2.11.0")
implementation("com.squareup.retrofit2:converter-gson:2.11.0")
implementation("com.kakao.maps.open:android:2.9.5")
implementation("androidx.activity:activity:1.8.0")
implementation("androidx.test:core-ktx:1.5.0")
implementation("androidx.activity:activity-ktx:1.9.1")
implementation("androidx.test:core-ktx:1.6.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.3")
implementation("androidx.room:room-runtime:2.6.1")
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")
implementation("androidx.room:room-ktx:2.6.1")
testImplementation("androidx.room:room-testing:2.6.1")
implementation("androidx.datastore:datastore-preferences:1.1.1")
implementation ("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.3")
testImplementation("junit:junit:4.13.2")
testImplementation("io.mockk:mockk-android:1.13.11")
testImplementation("io.mockk:mockk-agent:1.13.11")
Expand All @@ -75,5 +85,11 @@ dependencies {
androidTestImplementation("androidx.test:rules:1.5.0")
androidTestImplementation("androidx.test.espresso:espresso-intents:3.5.1")
androidTestImplementation("androidx.test.espresso:espresso-contrib:3.5.1")

androidTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
androidTestImplementation("androidx.test:rules:1.6.1")
androidTestImplementation("androidx.test.espresso:espresso-intents:3.6.1")
androidTestImplementation("com.google.dagger:hilt-android-testing:2.48.1")
kaptAndroidTest("com.google.dagger:hilt-android-compiler:2.48.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.app.Instrumentation
import android.content.Intent
import android.view.View
import android.widget.EditText
import androidx.lifecycle.Lifecycle
import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.*
Expand All @@ -21,19 +20,14 @@ import androidx.test.espresso.intent.matcher.IntentMatchers.*
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import campus.tech.kakao.map.R
import campus.tech.kakao.map.adapter.PlaceViewAdapter
import campus.tech.kakao.map.adapter.PlaceViewHolder
import campus.tech.kakao.map.adapter.SavedPlaceViewAdapter
import campus.tech.kakao.map.model.Constants
import campus.tech.kakao.map.model.Place
import campus.tech.kakao.map.model.SavedPlace
import org.hamcrest.core.AllOf.*
import campus.tech.kakao.map.utilities.Constants
import campus.tech.kakao.map.data.Place
import campus.tech.kakao.map.data.SavedPlace
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.util.regex.Matcher


class SearchActivityTest {
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/java/campus/tech/kakao/map/MainActivity.kt

This file was deleted.

2 changes: 2 additions & 0 deletions app/src/main/java/campus/tech/kakao/map/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package campus.tech.kakao.map

import android.app.Application
import com.kakao.vectormap.KakaoMapSdk
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package campus.tech.kakao.map.repository
package campus.tech.kakao.map.api

import android.util.Log
import campus.tech.kakao.map.BuildConfig
import campus.tech.kakao.map.model.Place
import campus.tech.kakao.map.data.Place
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import retrofit2.Retrofit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package campus.tech.kakao.map.repository
package campus.tech.kakao.map.api

import campus.tech.kakao.map.model.ResultSearch
import retrofit2.Call
import retrofit2.Response
import campus.tech.kakao.map.data.ResultSearch
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Query

interface KakaoLocalApi {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map.model
package campus.tech.kakao.map.data

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/campus/tech/kakao/map/data/PlaceRepository.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package campus.tech.kakao.map.data

import campus.tech.kakao.map.api.KakaoApiDataSource
import campus.tech.kakao.map.data.Place
import javax.inject.Inject

class PlaceRepository @Inject constructor(private val kakaoApiDataSource : KakaoApiDataSource){
suspend fun getKakaoLocalPlaceData(text : String) : List<Place>{
val placeList = kakaoApiDataSource.getPlaceData(text)
return placeList
}
}
10 changes: 10 additions & 0 deletions app/src/main/java/campus/tech/kakao/map/data/SavedPlace.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package campus.tech.kakao.map.data

import androidx.room.Entity
import androidx.room.PrimaryKey
import campus.tech.kakao.map.utilities.PlaceContract

@Entity(tableName = PlaceContract.SavedPlaceEntry.TABLE_NAME)
data class SavedPlace(
@PrimaryKey val name: String
)
21 changes: 21 additions & 0 deletions app/src/main/java/campus/tech/kakao/map/data/SavedPlaceDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package campus.tech.kakao.map.data

import androidx.room.Dao
import androidx.room.Query
import campus.tech.kakao.map.utilities.PlaceContract

@Dao
interface SavedPlaceDao {

@Query("SELECT * FROM ${PlaceContract.SavedPlaceEntry.TABLE_NAME}")
fun readSavedPlaceData(): List<SavedPlace>

@Query("SELECT * FROM ${PlaceContract.SavedPlaceEntry.TABLE_NAME} WHERE ${PlaceContract.SavedPlaceEntry.COLUMN_NAME} = :name")
fun readSavedPlaceDataWithSamedName(name: String): List<SavedPlace>

@Query("DELETE FROM ${PlaceContract.SavedPlaceEntry.TABLE_NAME} WHERE ${PlaceContract.SavedPlaceEntry.COLUMN_NAME} = :name")
fun deleteSavedPlace(name: String)

@Query("INSERT INTO ${PlaceContract.SavedPlaceEntry.TABLE_NAME} (${PlaceContract.SavedPlaceEntry.COLUMN_NAME}) VALUES (:name)")
fun insertSavedPlaceData(name:String)
}
28 changes: 28 additions & 0 deletions app/src/main/java/campus/tech/kakao/map/data/SavedPlaceDatabase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package campus.tech.kakao.map.data

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import campus.tech.kakao.map.utilities.PlaceContract
import kotlin.concurrent.Volatile

@Database(entities = [SavedPlace::class], version = PlaceContract.VERSION, exportSchema = false)
abstract class SavedPlaceDatabase : RoomDatabase() {

abstract fun savedPlaceDao(): SavedPlaceDao

companion object {
@Volatile
private var instance: SavedPlaceDatabase? = null

fun getInstance(context: Context): SavedPlaceDatabase {
return instance ?: synchronized(this) {
Room.databaseBuilder(
context, SavedPlaceDatabase::class.java, PlaceContract.DATABASE_NAME
).build().also { instance = it }
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package campus.tech.kakao.map.data

import android.util.Log
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class SavedPlaceRepository @Inject constructor(private val savedPlaceDao : SavedPlaceDao){
suspend fun getAllSavedPlace() : List<SavedPlace> = savedPlaceDao.readSavedPlaceData()


suspend fun writePlace(place: Place){
val savedList = savedPlaceDao.readSavedPlaceDataWithSamedName(place.name)
if (savedList.isNotEmpty()) {
Log.d("testt", "데이터 중복")
// 입력의 시간순대로 정렬되기 떄문에 레코드 삭제후 다시 집어넣기
savedPlaceDao.deleteSavedPlace(place.name)
savedPlaceDao.insertSavedPlaceData(place.name)
} else {
savedPlaceDao.insertSavedPlaceData(place.name)
}
}

suspend fun deleteSavedPlace(savedPlace: SavedPlace){
savedPlaceDao.deleteSavedPlace(savedPlace.name)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map.repository
package campus.tech.kakao.map.data

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
Expand All @@ -7,8 +7,11 @@ import androidx.datastore.preferences.core.edit
import campus.tech.kakao.map.view.MapActivity
import com.kakao.vectormap.LatLng
import kotlinx.coroutines.flow.map
import javax.inject.Inject
import javax.inject.Singleton

class SharedPreferenceRepository(private val dataStore: DataStore<Preferences>) {
@Singleton
class SharedPreferenceRepository @Inject constructor(private val dataStore: DataStore<Preferences>) {

companion object {
val KEY_LATITUDE = doublePreferencesKey("latitude")
Expand Down
20 changes: 0 additions & 20 deletions app/src/main/java/campus/tech/kakao/map/db/PlaceContract.kt

This file was deleted.

Loading