From 381b1eecaa7766a7d46b89944009cbf64191130c Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Mon, 1 Jul 2024 20:28:23 +0900 Subject: [PATCH 01/24] docs: Add Program Description & Step1 Feature --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index df2a6477..35d43c72 100644 --- a/README.md +++ b/README.md @@ -1 +1,21 @@ # android-map-keyword + +## ๐Ÿ“„ ํ”„๋กœ๊ทธ๋žจ ์„ค๋ช… + +์นด์นด์˜ค๋งต์˜ ํด๋ก  ์ฝ”๋”ฉ์„ ์œ„ํ•ด, ๊ฒ€์ƒ‰ ๋ ˆ์ด์•„์›ƒ์„ ์ œ์ž‘ํ•˜์˜€์Šต๋‹ˆ๋‹ค. + +์ด๋•Œ ๋‚ด๋ถ€ ์ €์žฅ์†Œ์ธ SQLite๋ฅผ ํ†ตํ•ด์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๊ณ , ๊ธฐ๋ก์„ ์ €์žฅํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค. + +## ๐ŸŽฏ 1๋‹จ๊ณ„(๋กœ์ปฌ ๋ฐ์ดํ„ฐ) ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ + +- [ ] ๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅ ๋ฐ›๊ณ  ๋ณด์—ฌ์ฃผ๋Š” ๋ ˆ์ด์•„์›ƒ ์ œ์ž‘ + + - [ ] ๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅ ๋ฐ›๋Š” EditText ์ œ์ž‘ + + - [ ] X ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ๊ฒ€์ƒ‰์–ด๋ฅผ ์ดˆ๊ธฐํ™”ํ•  ์ˆ˜ ์žˆ๋„๋ก ImageButton ์ œ์ž‘ + + - [ ] ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ๋ ˆ์ด์•„์›ƒ ์ œ์ž‘ + + - [ ] ์ด์ „์˜ ๊ฒ€์ƒ‰ ๊ธฐ๋ก์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” ๋ ˆ์ด์•„์›ƒ ์ œ์ž‘ + +- [ ] ๊ฒ€์ƒ‰์— ์‚ฌ์šฉ๋  ๋ฐ์ดํ„ฐ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ SQLite์— ์ €์žฅ \ No newline at end of file From e53a1bea82951edad851773f4a72692601daa9f7 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Tue, 2 Jul 2024 14:15:11 +0900 Subject: [PATCH 02/24] feat: Add Location Search Layout --- README.md | 10 +-- app/build.gradle.kts | 3 +- app/src/main/AndroidManifest.xml | 7 ++- .../tech/kakao/map/SearchLocationActivity.kt | 15 +++++ app/src/main/res/drawable/round_close_24.xml | 5 ++ app/src/main/res/drawable/round_place_24.xml | 5 ++ .../res/layout/activity_search_location.xml | 61 +++++++++++++++++++ app/src/main/res/layout/item_location.xml | 59 ++++++++++++++++++ app/src/main/res/values/colors.xml | 2 + app/src/main/res/values/strings.xml | 2 + 10 files changed, 161 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/campus/tech/kakao/map/SearchLocationActivity.kt create mode 100644 app/src/main/res/drawable/round_close_24.xml create mode 100644 app/src/main/res/drawable/round_place_24.xml create mode 100644 app/src/main/res/layout/activity_search_location.xml create mode 100644 app/src/main/res/layout/item_location.xml diff --git a/README.md b/README.md index 35d43c72..67124daa 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,14 @@ ## ๐ŸŽฏ 1๋‹จ๊ณ„(๋กœ์ปฌ ๋ฐ์ดํ„ฐ) ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ -- [ ] ๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅ ๋ฐ›๊ณ  ๋ณด์—ฌ์ฃผ๋Š” ๋ ˆ์ด์•„์›ƒ ์ œ์ž‘ +- [X] ๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅ ๋ฐ›๊ณ  ๋ณด์—ฌ์ฃผ๋Š” ๋ ˆ์ด์•„์›ƒ ์ œ์ž‘ - - [ ] ๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅ ๋ฐ›๋Š” EditText ์ œ์ž‘ + - [X] ๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅ ๋ฐ›๋Š” EditText ์ œ์ž‘ - - [ ] X ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ๊ฒ€์ƒ‰์–ด๋ฅผ ์ดˆ๊ธฐํ™”ํ•  ์ˆ˜ ์žˆ๋„๋ก ImageButton ์ œ์ž‘ + - [X] X ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ๊ฒ€์ƒ‰์–ด๋ฅผ ์ดˆ๊ธฐํ™”ํ•  ์ˆ˜ ์žˆ๋„๋ก ImageButton ์ œ์ž‘ - - [ ] ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ๋ ˆ์ด์•„์›ƒ ์ œ์ž‘ + - [X] ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ๋ ˆ์ด์•„์›ƒ ์ œ์ž‘ - - [ ] ์ด์ „์˜ ๊ฒ€์ƒ‰ ๊ธฐ๋ก์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” ๋ ˆ์ด์•„์›ƒ ์ œ์ž‘ + - [X] ์ด์ „์˜ ๊ฒ€์ƒ‰ ๊ธฐ๋ก์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” ๋ ˆ์ด์•„์›ƒ ์ œ์ž‘ - [ ] ๊ฒ€์ƒ‰์— ์‚ฌ์šฉ๋  ๋ฐ์ดํ„ฐ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ SQLite์— ์ €์žฅ \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9932d6bb..296c8738 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -47,7 +47,8 @@ dependencies { implementation("androidx.constraintlayout:constraintlayout:2.1.4") implementation("androidx.recyclerview:recyclerview:1.3.2") implementation("androidx.datastore:datastore-preferences:1.0.0") - testImplementation("junit:junit:4.13.2") + implementation("androidx.activity:activity:1.8.0") + testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6bca2f54..2196da3c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,7 +13,7 @@ android:theme="@style/Theme.Map" tools:targetApi="31"> @@ -21,6 +21,9 @@ + - + \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/SearchLocationActivity.kt b/app/src/main/java/campus/tech/kakao/map/SearchLocationActivity.kt new file mode 100644 index 00000000..59fb6193 --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/SearchLocationActivity.kt @@ -0,0 +1,15 @@ +package campus.tech.kakao.map + +import android.os.Bundle +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat + +class SearchLocationActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_search_location) + + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/round_close_24.xml b/app/src/main/res/drawable/round_close_24.xml new file mode 100644 index 00000000..13608b6a --- /dev/null +++ b/app/src/main/res/drawable/round_close_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/round_place_24.xml b/app/src/main/res/drawable/round_place_24.xml new file mode 100644 index 00000000..eca274a7 --- /dev/null +++ b/app/src/main/res/drawable/round_place_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/layout/activity_search_location.xml b/app/src/main/res/layout/activity_search_location.xml new file mode 100644 index 00000000..0ffe4f7a --- /dev/null +++ b/app/src/main/res/layout/activity_search_location.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_location.xml b/app/src/main/res/layout/item_location.xml new file mode 100644 index 00000000..aa280dcb --- /dev/null +++ b/app/src/main/res/layout/item_location.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 768b058a..ab247e2f 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -2,4 +2,6 @@ #FF000000 #FFFFFFFF + #FF9E9E9E + #74C99F diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e5ba5b9c..688e5e1f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,5 @@ Map + ๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”. + ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. \ No newline at end of file From cde43214cb6c5ed90df3f7ddb399e6c98b916e03 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Tue, 2 Jul 2024 14:45:35 +0900 Subject: [PATCH 03/24] feat: Add Contract & DbHelper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SQLite๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด Contract์™€ DbHelper๋ฅผ ์ƒ์„ฑ --- .../tech/kakao/map/db/LocationContract.kt | 10 +++++++ .../tech/kakao/map/db/LocationDbHelper.kt | 26 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 app/src/main/java/campus/tech/kakao/map/db/LocationContract.kt create mode 100644 app/src/main/java/campus/tech/kakao/map/db/LocationDbHelper.kt diff --git a/app/src/main/java/campus/tech/kakao/map/db/LocationContract.kt b/app/src/main/java/campus/tech/kakao/map/db/LocationContract.kt new file mode 100644 index 00000000..e95d2cca --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/db/LocationContract.kt @@ -0,0 +1,10 @@ +package campus.tech.kakao.map.db + +import android.provider.BaseColumns + +object LocationContract : BaseColumns { + const val TABLE_NAME = "LOCATION" + const val COLUMN_NAME = "name" + const val COLUMN_ADDRESS = "address" + const val COLUMN_CATEGORY = "category" +} \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/db/LocationDbHelper.kt b/app/src/main/java/campus/tech/kakao/map/db/LocationDbHelper.kt new file mode 100644 index 00000000..9b04f263 --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/db/LocationDbHelper.kt @@ -0,0 +1,26 @@ +package campus.tech.kakao.map.db + +import android.content.Context +import android.database.sqlite.SQLiteDatabase +import android.database.sqlite.SQLiteOpenHelper + +class LocationDbHelper(context: Context) : + SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) { + override fun onCreate(db: SQLiteDatabase?) { + val query = "CREATE TABLE ${LocationContract.TABLE_NAME} (" + + "${LocationContract.COLUMN_NAME} VARCHAR(50)," + + "${LocationContract.COLUMN_ADDRESS} VARCHAR(50)," + + "${LocationContract.COLUMN_CATEGORY} VARCHAR(20))" + db?.execSQL(query) + } + + override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) { + db?.execSQL("DROP TABLE IF EXISTS ${LocationContract.TABLE_NAME}") + onCreate(db) + } + + companion object { + const val DATABASE_NAME = "location.db" + const val DATABASE_VERSION = 1 + } +} \ No newline at end of file From 5f158fb968756f38e24b5ea0cb482ad7548fc5e1 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Tue, 2 Jul 2024 15:09:16 +0900 Subject: [PATCH 04/24] feat: Create Dummy Data on Database --- .../tech/kakao/map/SearchLocationActivity.kt | 6 ++++ .../tech/kakao/map/db/LocationDbHelper.kt | 35 ++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/SearchLocationActivity.kt b/app/src/main/java/campus/tech/kakao/map/SearchLocationActivity.kt index 59fb6193..1432b9f2 100644 --- a/app/src/main/java/campus/tech/kakao/map/SearchLocationActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/SearchLocationActivity.kt @@ -1,15 +1,21 @@ package campus.tech.kakao.map +import android.database.sqlite.SQLiteDatabase import android.os.Bundle import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat +import campus.tech.kakao.map.db.LocationDbHelper class SearchLocationActivity : AppCompatActivity() { + private val dbHelper = LocationDbHelper(this) + private lateinit var db: SQLiteDatabase + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_search_location) + db = dbHelper.writableDatabase } } \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/db/LocationDbHelper.kt b/app/src/main/java/campus/tech/kakao/map/db/LocationDbHelper.kt index 9b04f263..1e7b21ef 100644 --- a/app/src/main/java/campus/tech/kakao/map/db/LocationDbHelper.kt +++ b/app/src/main/java/campus/tech/kakao/map/db/LocationDbHelper.kt @@ -1,5 +1,6 @@ package campus.tech.kakao.map.db +import android.content.ContentValues import android.content.Context import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteOpenHelper @@ -7,11 +8,15 @@ import android.database.sqlite.SQLiteOpenHelper class LocationDbHelper(context: Context) : SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) { override fun onCreate(db: SQLiteDatabase?) { - val query = "CREATE TABLE ${LocationContract.TABLE_NAME} (" + - "${LocationContract.COLUMN_NAME} VARCHAR(50)," + - "${LocationContract.COLUMN_ADDRESS} VARCHAR(50)," + - "${LocationContract.COLUMN_CATEGORY} VARCHAR(20))" - db?.execSQL(query) + db?.let { + val query = "CREATE TABLE ${LocationContract.TABLE_NAME} (" + + "${LocationContract.COLUMN_NAME} VARCHAR(50)," + + "${LocationContract.COLUMN_ADDRESS} VARCHAR(50)," + + "${LocationContract.COLUMN_CATEGORY} VARCHAR(20))" + it.execSQL(query) + + createLocationData(it) + } } override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) { @@ -19,6 +24,26 @@ class LocationDbHelper(context: Context) : onCreate(db) } + private fun createLocationData(db: SQLiteDatabase) { + // ์ž„์˜์˜ ์นดํŽ˜ ๋ฐ์ดํ„ฐ 15๊ฐœ ์ƒ์„ฑ + for (i in 1..15) { + val values = ContentValues() + values.put(LocationContract.COLUMN_NAME, "์นดํŽ˜$i") + values.put(LocationContract.COLUMN_ADDRESS, "์„œ์šธ ์„ฑ๋™๊ตฌ ์„ฑ์ˆ˜๋™ $i") + values.put(LocationContract.COLUMN_CATEGORY, "์นดํŽ˜") + db.insert(LocationContract.TABLE_NAME, null, values) + } + + // ์ž„์˜์˜ ์•ฝ๊ตญ ๋ฐ์ดํ„ฐ 15๊ฐœ ์ƒ์„ฑ + for (i in 1..15) { + val values = ContentValues() + values.put(LocationContract.COLUMN_NAME, "์•ฝ๊ตญ$i") + values.put(LocationContract.COLUMN_ADDRESS, "์„œ์šธ ๊ฐ•๋‚จ๊ตฌ ๋Œ€์น˜๋™ $i") + values.put(LocationContract.COLUMN_CATEGORY, "์•ฝ๊ตญ") + db.insert(LocationContract.TABLE_NAME, null, values) + } + } + companion object { const val DATABASE_NAME = "location.db" const val DATABASE_VERSION = 1 From e1238e367ca0c8840323dd812ce6b161ad9f9492 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Thu, 4 Jul 2024 14:41:44 +0900 Subject: [PATCH 05/24] docs: Update Step2 Feature --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 67124daa..40fda342 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,24 @@ - [X] ์ด์ „์˜ ๊ฒ€์ƒ‰ ๊ธฐ๋ก์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” ๋ ˆ์ด์•„์›ƒ ์ œ์ž‘ -- [ ] ๊ฒ€์ƒ‰์— ์‚ฌ์šฉ๋  ๋ฐ์ดํ„ฐ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ SQLite์— ์ €์žฅ \ No newline at end of file +- [X] ๊ฒ€์ƒ‰์— ์‚ฌ์šฉ๋  ๋ฐ์ดํ„ฐ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ SQLite์— ์ €์žฅ + +## ๐ŸŽฏ 2๋‹จ๊ณ„(๊ฒ€์ƒ‰) ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ + +- [ ] X๋ฒ„ํŠผ ํด๋ฆญ ์‹œ, ์ž…๋ ฅ๋œ ๊ฒ€์ƒ‰์–ด๋ฅผ ์ง€์šฐ๊ธฐ + +- [ ] ๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ๋„์›Œ ์ฃผ๊ธฐ + + - [ ] ์—…์ข…(`COLUMN_CATEGORY`)๊ณผ ์ผ์น˜ํ•œ ๊ฒฐ๊ณผ๋ฅผ DB์—์„œ ๋ฆฌ์ŠคํŠธ๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ + + - [ ] ๊ฐ€์ ธ์˜จ ๋ฆฌ์ŠคํŠธ๋ฅผ RecyclerView์— ์ ์šฉํ•˜์—ฌ ๋ณด์—ฌ์ฃผ๊ธฐ + +- [ ] ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ์ค‘ ํ•˜๋‚˜๋ฅผ ํด๋ฆญํ•˜๋Š” ๊ฒฝ์šฐ, ํ•ด๋‹น ์žฅ์†Œ๋ฅผ ๊ฒ€์ƒ‰ ๊ธฐ๋ก์— ์ถ”๊ฐ€ํ•˜๊ธฐ + + - [ ] ๊ฒ€์ƒ‰ ๊ธฐ๋ก์„ ๋ณด์—ฌ์ฃผ๋Š” item์˜ ๋ ˆ์ด์•„์›ƒ ์ œ์ž‘ํ•˜๊ธฐ + + - [ ] ์ด๋ฏธ DB์— ์กด์žฌํ•œ๋‹ค๋ฉด, ํ•ด๋‹น ๊ฐ’์„ ์ง€์šฐ๊ณ  ์ƒˆ๋กœ ์ €์žฅํ•ด์„œ ๋งจ ๋’ค๋กœ ๊ฐ€๋„๋ก ๊ตฌํ˜„ํ•˜๊ธฐ + + - [ ] DB์— ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, ์ƒˆ๋กญ๊ฒŒ ์ถ”๊ฐ€ํ•˜๊ณ  ๋งจ ๋’ค์—์„œ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + +- [ ] ๊ฒ€์ƒ‰ ๊ธฐ๋ก์˜ X๋ฒ„ํŠผ ํด๋ฆญ ์‹œ, ํ•ด๋‹น ๊ฒ€์ƒ‰ ๊ธฐ๋ก์„ ์‚ญ์ œํ•˜๊ธฐ \ No newline at end of file From d90c483980e4a2b7fafca1c8abcfcd34036c8abe Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Thu, 4 Jul 2024 14:46:05 +0900 Subject: [PATCH 06/24] feat: Add Search History Item Layout --- README.md | 2 +- .../main/res/drawable/background_round.xml | 10 ++++++ .../res/layout/activity_search_location.xml | 5 ++- app/src/main/res/layout/item_history.xml | 33 +++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable/background_round.xml create mode 100644 app/src/main/res/layout/item_history.xml diff --git a/README.md b/README.md index 40fda342..c4a850ab 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ - [ ] ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ์ค‘ ํ•˜๋‚˜๋ฅผ ํด๋ฆญํ•˜๋Š” ๊ฒฝ์šฐ, ํ•ด๋‹น ์žฅ์†Œ๋ฅผ ๊ฒ€์ƒ‰ ๊ธฐ๋ก์— ์ถ”๊ฐ€ํ•˜๊ธฐ - - [ ] ๊ฒ€์ƒ‰ ๊ธฐ๋ก์„ ๋ณด์—ฌ์ฃผ๋Š” item์˜ ๋ ˆ์ด์•„์›ƒ ์ œ์ž‘ํ•˜๊ธฐ + - [X] ๊ฒ€์ƒ‰ ๊ธฐ๋ก์„ ๋ณด์—ฌ์ฃผ๋Š” item์˜ ๋ ˆ์ด์•„์›ƒ ์ œ์ž‘ํ•˜๊ธฐ - [ ] ์ด๋ฏธ DB์— ์กด์žฌํ•œ๋‹ค๋ฉด, ํ•ด๋‹น ๊ฐ’์„ ์ง€์šฐ๊ณ  ์ƒˆ๋กœ ์ €์žฅํ•ด์„œ ๋งจ ๋’ค๋กœ ๊ฐ€๋„๋ก ๊ตฌํ˜„ํ•˜๊ธฐ diff --git a/app/src/main/res/drawable/background_round.xml b/app/src/main/res/drawable/background_round.xml new file mode 100644 index 00000000..bf633b04 --- /dev/null +++ b/app/src/main/res/drawable/background_round.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_search_location.xml b/app/src/main/res/layout/activity_search_location.xml index 0ffe4f7a..02977f0a 100644 --- a/app/src/main/res/layout/activity_search_location.xml +++ b/app/src/main/res/layout/activity_search_location.xml @@ -30,11 +30,14 @@ android:id="@+id/searchHistoryRecyclerView" android:layout_width="match_parent" android:layout_height="50dp" + android:orientation="horizontal" android:visibility="gone" + app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layout_constraintBottom_toTopOf="@+id/searchResultRecyclerView" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/searchInputEditText" /> + app:layout_constraintTop_toBottomOf="@+id/searchInputEditText" + tools:listitem="@layout/item_history" /> + + + + + + + \ No newline at end of file From 3c3b587145f4b97423354acb2d974e9d124dbd23 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Thu, 4 Jul 2024 20:32:47 +0900 Subject: [PATCH 07/24] refactor: Apply MVVM Pattern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Package๋ฅผ Model, View, ViewModel๋กœ ๋‚˜๋ˆ„์–ด์„œ ๋ณด๊ธฐ ํŽธํ•˜๊ฒŒ ํ•˜์˜€๋‹ค. --- app/src/main/AndroidManifest.xml | 5 +---- .../campus/tech/kakao/map/MainActivity.kt | 11 ----------- .../map/{db => model}/LocationContract.kt | 2 +- .../map/{db => model}/LocationDbHelper.kt | 2 +- .../map/model/SearchLocationRepository.kt | 5 +++++ .../map/{ => view}/SearchLocationActivity.kt | 8 +++----- .../map/viewmodel/SearchLocationViewModel.kt | 7 +++++++ app/src/main/res/layout/activity_main.xml | 19 ------------------- .../res/layout/activity_search_location.xml | 2 +- 9 files changed, 19 insertions(+), 42 deletions(-) delete mode 100644 app/src/main/java/campus/tech/kakao/map/MainActivity.kt rename app/src/main/java/campus/tech/kakao/map/{db => model}/LocationContract.kt (86%) rename app/src/main/java/campus/tech/kakao/map/{db => model}/LocationDbHelper.kt (97%) create mode 100644 app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt rename app/src/main/java/campus/tech/kakao/map/{ => view}/SearchLocationActivity.kt (68%) create mode 100644 app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt delete mode 100644 app/src/main/res/layout/activity_main.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2196da3c..37c62043 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,7 +13,7 @@ android:theme="@style/Theme.Map" tools:targetApi="31"> @@ -21,9 +21,6 @@ - \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/MainActivity.kt b/app/src/main/java/campus/tech/kakao/map/MainActivity.kt deleted file mode 100644 index 95b43803..00000000 --- a/app/src/main/java/campus/tech/kakao/map/MainActivity.kt +++ /dev/null @@ -1,11 +0,0 @@ -package campus.tech.kakao.map - -import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity - -class MainActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - } -} diff --git a/app/src/main/java/campus/tech/kakao/map/db/LocationContract.kt b/app/src/main/java/campus/tech/kakao/map/model/LocationContract.kt similarity index 86% rename from app/src/main/java/campus/tech/kakao/map/db/LocationContract.kt rename to app/src/main/java/campus/tech/kakao/map/model/LocationContract.kt index e95d2cca..12b27a59 100644 --- a/app/src/main/java/campus/tech/kakao/map/db/LocationContract.kt +++ b/app/src/main/java/campus/tech/kakao/map/model/LocationContract.kt @@ -1,4 +1,4 @@ -package campus.tech.kakao.map.db +package campus.tech.kakao.map.model import android.provider.BaseColumns diff --git a/app/src/main/java/campus/tech/kakao/map/db/LocationDbHelper.kt b/app/src/main/java/campus/tech/kakao/map/model/LocationDbHelper.kt similarity index 97% rename from app/src/main/java/campus/tech/kakao/map/db/LocationDbHelper.kt rename to app/src/main/java/campus/tech/kakao/map/model/LocationDbHelper.kt index 1e7b21ef..0d3cd4cd 100644 --- a/app/src/main/java/campus/tech/kakao/map/db/LocationDbHelper.kt +++ b/app/src/main/java/campus/tech/kakao/map/model/LocationDbHelper.kt @@ -1,4 +1,4 @@ -package campus.tech.kakao.map.db +package campus.tech.kakao.map.model import android.content.ContentValues import android.content.Context diff --git a/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt b/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt new file mode 100644 index 00000000..844482c5 --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt @@ -0,0 +1,5 @@ +package campus.tech.kakao.map.model + +class SearchLocationRepository { + +} \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/SearchLocationActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt similarity index 68% rename from app/src/main/java/campus/tech/kakao/map/SearchLocationActivity.kt rename to app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt index 1432b9f2..487ea0e5 100644 --- a/app/src/main/java/campus/tech/kakao/map/SearchLocationActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt @@ -1,12 +1,10 @@ -package campus.tech.kakao.map +package campus.tech.kakao.map.view import android.database.sqlite.SQLiteDatabase import android.os.Bundle -import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity -import androidx.core.view.ViewCompat -import androidx.core.view.WindowInsetsCompat -import campus.tech.kakao.map.db.LocationDbHelper +import campus.tech.kakao.map.R +import campus.tech.kakao.map.model.LocationDbHelper class SearchLocationActivity : AppCompatActivity() { private val dbHelper = LocationDbHelper(this) diff --git a/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt b/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt new file mode 100644 index 00000000..4da22bd2 --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt @@ -0,0 +1,7 @@ +package campus.tech.kakao.map.viewmodel + +import androidx.lifecycle.ViewModel + +class SearchLocationViewModel : ViewModel() { + +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index 24d17df2..00000000 --- a/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - diff --git a/app/src/main/res/layout/activity_search_location.xml b/app/src/main/res/layout/activity_search_location.xml index 02977f0a..2a4a86dd 100644 --- a/app/src/main/res/layout/activity_search_location.xml +++ b/app/src/main/res/layout/activity_search_location.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp" - tools:context=".SearchLocationActivity"> + tools:context=".view.SearchLocationActivity"> Date: Thu, 4 Jul 2024 21:12:43 +0900 Subject: [PATCH 08/24] feat: Data binding & connect ViewModel, Model --- .../tech/kakao/map/view/SearchLocationActivity.kt | 15 ++++++++------- .../map/viewmodel/SearchLocationViewModel.kt | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt index 487ea0e5..074168e6 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt @@ -1,19 +1,20 @@ package campus.tech.kakao.map.view -import android.database.sqlite.SQLiteDatabase import android.os.Bundle import androidx.appcompat.app.AppCompatActivity -import campus.tech.kakao.map.R -import campus.tech.kakao.map.model.LocationDbHelper +import androidx.lifecycle.ViewModelProvider +import campus.tech.kakao.map.databinding.ActivitySearchLocationBinding +import campus.tech.kakao.map.viewmodel.SearchLocationViewModel class SearchLocationActivity : AppCompatActivity() { - private val dbHelper = LocationDbHelper(this) - private lateinit var db: SQLiteDatabase + private lateinit var viewModel: SearchLocationViewModel + private lateinit var binding: ActivitySearchLocationBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_search_location) + viewModel = ViewModelProvider(this)[SearchLocationViewModel::class.java] + binding = ActivitySearchLocationBinding.inflate(layoutInflater) + setContentView(binding.root) - db = dbHelper.writableDatabase } } \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt b/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt index 4da22bd2..ba20abee 100644 --- a/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt +++ b/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt @@ -1,7 +1,9 @@ package campus.tech.kakao.map.viewmodel import androidx.lifecycle.ViewModel +import campus.tech.kakao.map.model.SearchLocationRepository class SearchLocationViewModel : ViewModel() { + private val repository = SearchLocationRepository() } \ No newline at end of file From 43533ef16780d4c5223cfdc0bbd941bfb2b8ec7c Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Thu, 4 Jul 2024 21:14:23 +0900 Subject: [PATCH 09/24] feat: When Click X Button, Clear EditText's text --- README.md | 2 +- .../java/campus/tech/kakao/map/view/SearchLocationActivity.kt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c4a850ab..26a0388a 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ ## ๐ŸŽฏ 2๋‹จ๊ณ„(๊ฒ€์ƒ‰) ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ -- [ ] X๋ฒ„ํŠผ ํด๋ฆญ ์‹œ, ์ž…๋ ฅ๋œ ๊ฒ€์ƒ‰์–ด๋ฅผ ์ง€์šฐ๊ธฐ +- [X] X๋ฒ„ํŠผ ํด๋ฆญ ์‹œ, ์ž…๋ ฅ๋œ ๊ฒ€์ƒ‰์–ด๋ฅผ ์ง€์šฐ๊ธฐ - [ ] ๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ๋„์›Œ ์ฃผ๊ธฐ diff --git a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt index 074168e6..9522cc69 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt @@ -16,5 +16,8 @@ class SearchLocationActivity : AppCompatActivity() { binding = ActivitySearchLocationBinding.inflate(layoutInflater) setContentView(binding.root) + binding.removeSearchInputButton.setOnClickListener { + binding.searchInputEditText.text.clear() + } } } \ No newline at end of file From 0c2bd067c85ca5e023a363d294460c0943112a89 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Thu, 4 Jul 2024 22:26:29 +0900 Subject: [PATCH 10/24] feat: Get Data Matching Category from SQLite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - EditText์— ์ž…๋ ฅ๋œ String๊ณผ category๊ฐ€ ์ผ์น˜ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ด --- README.md | 2 +- .../campus/tech/kakao/map/model/Location.kt | 7 +++++ .../map/model/SearchLocationRepository.kt | 26 ++++++++++++++++++- .../kakao/map/view/SearchLocationActivity.kt | 12 +++++++++ .../map/viewmodel/SearchLocationViewModel.kt | 14 +++++++++- 5 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/campus/tech/kakao/map/model/Location.kt diff --git a/README.md b/README.md index 26a0388a..c71163fe 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ - [ ] ๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ๋„์›Œ ์ฃผ๊ธฐ - - [ ] ์—…์ข…(`COLUMN_CATEGORY`)๊ณผ ์ผ์น˜ํ•œ ๊ฒฐ๊ณผ๋ฅผ DB์—์„œ ๋ฆฌ์ŠคํŠธ๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ + - [X] ์—…์ข…(`COLUMN_CATEGORY`)๊ณผ ์ผ์น˜ํ•œ ๊ฒฐ๊ณผ๋ฅผ DB์—์„œ ๋ฆฌ์ŠคํŠธ๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ - [ ] ๊ฐ€์ ธ์˜จ ๋ฆฌ์ŠคํŠธ๋ฅผ RecyclerView์— ์ ์šฉํ•˜์—ฌ ๋ณด์—ฌ์ฃผ๊ธฐ diff --git a/app/src/main/java/campus/tech/kakao/map/model/Location.kt b/app/src/main/java/campus/tech/kakao/map/model/Location.kt new file mode 100644 index 00000000..21529b85 --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/model/Location.kt @@ -0,0 +1,7 @@ +package campus.tech.kakao.map.model + +data class Location( + val name: String, + val address: String, + val category: String +) \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt b/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt index 844482c5..e4fe4a88 100644 --- a/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt +++ b/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt @@ -1,5 +1,29 @@ package campus.tech.kakao.map.model -class SearchLocationRepository { +import android.content.Context +class SearchLocationRepository(context: Context) { + private val dbHelper: LocationDbHelper = LocationDbHelper(context) + + fun searchLocation(category: String): List { + val db = dbHelper.readableDatabase + val searchQuery = "SELECT * FROM ${LocationContract.TABLE_NAME} " + + "WHERE ${LocationContract.COLUMN_CATEGORY} = '$category'" + val cursor = db.rawQuery(searchQuery, null) + + val result = mutableListOf() + while (cursor.moveToNext()) { + result.add( + Location( + name = cursor.getString(cursor.getColumnIndexOrThrow(LocationContract.COLUMN_NAME)), + address = cursor.getString(cursor.getColumnIndexOrThrow(LocationContract.COLUMN_ADDRESS)), + category = cursor.getString(cursor.getColumnIndexOrThrow(LocationContract.COLUMN_CATEGORY)) + ) + ) + } + cursor.close() + db.close() + + return result.toList() + } } \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt index 9522cc69..fbdafbd2 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt @@ -1,9 +1,12 @@ package campus.tech.kakao.map.view import android.os.Bundle +import android.text.Editable +import android.text.TextWatcher import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.ViewModelProvider import campus.tech.kakao.map.databinding.ActivitySearchLocationBinding +import campus.tech.kakao.map.model.SearchLocationRepository import campus.tech.kakao.map.viewmodel.SearchLocationViewModel class SearchLocationActivity : AppCompatActivity() { @@ -13,11 +16,20 @@ class SearchLocationActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) viewModel = ViewModelProvider(this)[SearchLocationViewModel::class.java] + viewModel.setRepository(SearchLocationRepository(this)) binding = ActivitySearchLocationBinding.inflate(layoutInflater) setContentView(binding.root) binding.removeSearchInputButton.setOnClickListener { binding.searchInputEditText.text.clear() } + + binding.searchInputEditText.addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {} + override fun afterTextChanged(s: Editable?) { + viewModel.searchLocation(s.toString()) + } + }) } } \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt b/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt index ba20abee..0a299ad2 100644 --- a/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt +++ b/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt @@ -1,9 +1,21 @@ package campus.tech.kakao.map.viewmodel +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import campus.tech.kakao.map.model.Location import campus.tech.kakao.map.model.SearchLocationRepository class SearchLocationViewModel : ViewModel() { - private val repository = SearchLocationRepository() + private lateinit var repository: SearchLocationRepository + fun setRepository(repository: SearchLocationRepository) { + this.repository = repository + } + private val _location = MutableLiveData>() + val location: LiveData> = _location + + fun searchLocation(category: String) { + _location.value = repository.searchLocation(category) + } } \ No newline at end of file From 788e35739f6ae6a359c359332a18b924c33e9cce Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Thu, 4 Jul 2024 22:50:56 +0900 Subject: [PATCH 11/24] feat: Add RecyclerView Adapter for searchResultRecyclerView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Data Binding์„ ์ด์šฉํ•˜์—ฌ Adapter๋ฅผ ์„ค๊ณ„ํ•˜์˜€๋‹ค. --- .../kakao/map/view/SearchLocationAdapter.kt | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 app/src/main/java/campus/tech/kakao/map/view/SearchLocationAdapter.kt diff --git a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationAdapter.kt b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationAdapter.kt new file mode 100644 index 00000000..54702cda --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationAdapter.kt @@ -0,0 +1,39 @@ +package campus.tech.kakao.map.view + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import campus.tech.kakao.map.databinding.ItemLocationBinding +import campus.tech.kakao.map.model.Location + +class SearchLocationAdapter( + private val dataList: List, + private val context: Context +) : RecyclerView.Adapter() { + + inner class MyViewHolder(private val binding: ItemLocationBinding) : + RecyclerView.ViewHolder(binding.root) { + fun bind(locationData: Location) { + binding.locationNameTextView.text = locationData.name + binding.locationAddressTextView.text = locationData.address + binding.locationTypeTextView.text = locationData.category + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { + return MyViewHolder( + ItemLocationBinding.inflate( + LayoutInflater.from(context), + parent, + false + ) + ) + } + + override fun onBindViewHolder(holder: MyViewHolder, position: Int) { + holder.bind(dataList[position]) + } + + override fun getItemCount(): Int = dataList.size +} \ No newline at end of file From 77958d0247113d3a316a06ccf4d104b494eaee62 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Thu, 4 Jul 2024 23:22:20 +0900 Subject: [PATCH 12/24] feat: Show the Searched Information to RecyclerView --- README.md | 4 ++-- .../tech/kakao/map/view/SearchLocationActivity.kt | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c71163fe..a8db934e 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,11 @@ - [X] X๋ฒ„ํŠผ ํด๋ฆญ ์‹œ, ์ž…๋ ฅ๋œ ๊ฒ€์ƒ‰์–ด๋ฅผ ์ง€์šฐ๊ธฐ -- [ ] ๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ๋„์›Œ ์ฃผ๊ธฐ +- [X] ๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ๋„์›Œ ์ฃผ๊ธฐ - [X] ์—…์ข…(`COLUMN_CATEGORY`)๊ณผ ์ผ์น˜ํ•œ ๊ฒฐ๊ณผ๋ฅผ DB์—์„œ ๋ฆฌ์ŠคํŠธ๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ - - [ ] ๊ฐ€์ ธ์˜จ ๋ฆฌ์ŠคํŠธ๋ฅผ RecyclerView์— ์ ์šฉํ•˜์—ฌ ๋ณด์—ฌ์ฃผ๊ธฐ + - [X] ๊ฐ€์ ธ์˜จ ๋ฆฌ์ŠคํŠธ๋ฅผ RecyclerView์— ์ ์šฉํ•˜์—ฌ ๋ณด์—ฌ์ฃผ๊ธฐ - [ ] ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ์ค‘ ํ•˜๋‚˜๋ฅผ ํด๋ฆญํ•˜๋Š” ๊ฒฝ์šฐ, ํ•ด๋‹น ์žฅ์†Œ๋ฅผ ๊ฒ€์ƒ‰ ๊ธฐ๋ก์— ์ถ”๊ฐ€ํ•˜๊ธฐ diff --git a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt index fbdafbd2..f784c283 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt @@ -4,7 +4,9 @@ import android.os.Bundle import android.text.Editable import android.text.TextWatcher import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.isVisible import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import campus.tech.kakao.map.databinding.ActivitySearchLocationBinding import campus.tech.kakao.map.model.SearchLocationRepository import campus.tech.kakao.map.viewmodel.SearchLocationViewModel @@ -31,5 +33,13 @@ class SearchLocationActivity : AppCompatActivity() { viewModel.searchLocation(s.toString()) } }) + + viewModel.location.observe(this) { + it?.let { locationData -> + binding.searchResultRecyclerView.adapter = SearchLocationAdapter(locationData, this) + binding.searchResultRecyclerView.layoutManager = LinearLayoutManager(this) + binding.emptyResultTextView.isVisible = locationData.isEmpty() + } + } } } \ No newline at end of file From 14ca3179a647440bd5c0a1ee6af267d040f3185b Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Thu, 4 Jul 2024 23:54:39 +0900 Subject: [PATCH 13/24] feat: Add Contract & DbHelper for History --- .../tech/kakao/map/model/HistoryContract.kt | 8 ++++++ .../tech/kakao/map/model/HistoryDbHelper.kt | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 app/src/main/java/campus/tech/kakao/map/model/HistoryContract.kt create mode 100644 app/src/main/java/campus/tech/kakao/map/model/HistoryDbHelper.kt diff --git a/app/src/main/java/campus/tech/kakao/map/model/HistoryContract.kt b/app/src/main/java/campus/tech/kakao/map/model/HistoryContract.kt new file mode 100644 index 00000000..1b309d26 --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/model/HistoryContract.kt @@ -0,0 +1,8 @@ +package campus.tech.kakao.map.model + +import android.provider.BaseColumns + +object HistoryContract : BaseColumns { + const val TABLE_NAME = "HISTORY" + const val COLUMN_NAME = "name" +} \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/model/HistoryDbHelper.kt b/app/src/main/java/campus/tech/kakao/map/model/HistoryDbHelper.kt new file mode 100644 index 00000000..c36f7f0e --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/model/HistoryDbHelper.kt @@ -0,0 +1,27 @@ +package campus.tech.kakao.map.model + +import android.content.Context +import android.database.sqlite.SQLiteDatabase +import android.database.sqlite.SQLiteOpenHelper + +class HistoryDbHelper(context: Context) : + SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) { + + override fun onCreate(db: SQLiteDatabase?) { + db?.let { + val query = "CREATE TABLE ${HistoryContract.TABLE_NAME} (" + + "${HistoryContract.COLUMN_NAME} VARCHAR(50))" + it.execSQL(query) + } + } + + override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) { + db?.execSQL("DROP TABLE IF EXISTS ${HistoryContract.TABLE_NAME}") + onCreate(db) + } + + companion object { + const val DATABASE_NAME = "history.db" + const val DATABASE_VERSION = 1 + } +} \ No newline at end of file From c1e84b5bb6ae80b59206cdb7fbf1b03f5ac0a021 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Fri, 5 Jul 2024 00:01:08 +0900 Subject: [PATCH 14/24] feat: Add a Method to Check if History exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - isExistHistory(locationName)๋ฅผ ํ†ตํ•ด SQLite์— ํ•ด๋‹น ๊ฐ’์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๋‚ด๋ถ€ํ•จ์ˆ˜ --- .../map/model/SearchLocationRepository.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt b/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt index e4fe4a88..f8cddee3 100644 --- a/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt +++ b/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt @@ -3,10 +3,11 @@ package campus.tech.kakao.map.model import android.content.Context class SearchLocationRepository(context: Context) { - private val dbHelper: LocationDbHelper = LocationDbHelper(context) + private val locationDbHelper: LocationDbHelper = LocationDbHelper(context) + private val historyDbHelper: HistoryDbHelper = HistoryDbHelper(context) fun searchLocation(category: String): List { - val db = dbHelper.readableDatabase + val db = locationDbHelper.readableDatabase val searchQuery = "SELECT * FROM ${LocationContract.TABLE_NAME} " + "WHERE ${LocationContract.COLUMN_CATEGORY} = '$category'" val cursor = db.rawQuery(searchQuery, null) @@ -26,4 +27,17 @@ class SearchLocationRepository(context: Context) { return result.toList() } + + private fun isExistHistory(locationName: String): Boolean { + val db = historyDbHelper.readableDatabase + val searchQuery = "SELECT * FROM ${HistoryContract.TABLE_NAME} " + + "WHERE ${HistoryContract.COLUMN_NAME} = '$locationName'" + val cursor = db.rawQuery(searchQuery, null) + + val result = cursor.count > 0 + cursor.close() + db.close() + + return result + } } \ No newline at end of file From 00a9cb341d243c6da14cc620a4af3242a8774f33 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Fri, 5 Jul 2024 00:04:39 +0900 Subject: [PATCH 15/24] feat: Add a Method to Remove Row in DB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - removeHistory(locationName)๋ฅผ ํ†ตํ•ด SQLite์— ํ•ด๋‹น ๊ฐ’์ด ์žˆ๋Š” ์—ด์„ ์‚ญ์ œํ•จ --- .../tech/kakao/map/model/SearchLocationRepository.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt b/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt index f8cddee3..54993aa7 100644 --- a/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt +++ b/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt @@ -40,4 +40,12 @@ class SearchLocationRepository(context: Context) { return result } + + private fun removeHistory(locationName: String) { + val db = historyDbHelper.writableDatabase + val deleteQuery = "DELETE FROM ${HistoryContract.TABLE_NAME} " + + "WHERE ${HistoryContract.COLUMN_NAME} = '$locationName'" + db.execSQL(deleteQuery) + db.close() + } } \ No newline at end of file From 457e5b74d99ce2bcbde63fea14ce558b64ba19d2 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Fri, 5 Jul 2024 00:46:30 +0900 Subject: [PATCH 16/24] feat: Add History When Click Location Item MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - App Inspection์œผ๋กœ ํ™•์ธํ•œ ๊ฒฐ๊ณผ, item์„ ํด๋ฆญํ•œ ๊ฒฝ์šฐ HISTORY table์— ์ •์ƒ์ ์œผ๋กœ ์•„์ดํ…œ์ด ๋“ค์–ด๊ฐ€๋Š” ๊ฒƒ์„ ํ™•์ธํ•จ --- README.md | 4 ++-- .../kakao/map/model/SearchLocationRepository.kt | 14 ++++++++++++++ .../tech/kakao/map/view/SearchLocationActivity.kt | 2 +- .../tech/kakao/map/view/SearchLocationAdapter.kt | 10 +++++++++- .../kakao/map/viewmodel/SearchLocationViewModel.kt | 4 ++++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a8db934e..0d8a364d 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ - [X] ๊ฒ€์ƒ‰ ๊ธฐ๋ก์„ ๋ณด์—ฌ์ฃผ๋Š” item์˜ ๋ ˆ์ด์•„์›ƒ ์ œ์ž‘ํ•˜๊ธฐ - - [ ] ์ด๋ฏธ DB์— ์กด์žฌํ•œ๋‹ค๋ฉด, ํ•ด๋‹น ๊ฐ’์„ ์ง€์šฐ๊ณ  ์ƒˆ๋กœ ์ €์žฅํ•ด์„œ ๋งจ ๋’ค๋กœ ๊ฐ€๋„๋ก ๊ตฌํ˜„ํ•˜๊ธฐ + - [X] ์ด๋ฏธ DB์— ์กด์žฌํ•œ๋‹ค๋ฉด, ํ•ด๋‹น ๊ฐ’์„ ์ง€์šฐ๊ณ  ์ƒˆ๋กœ ์ €์žฅํ•ด์„œ ๋งจ ๋’ค๋กœ ๊ฐ€๋„๋ก ๊ตฌํ˜„ํ•˜๊ธฐ - - [ ] DB์— ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, ์ƒˆ๋กญ๊ฒŒ ์ถ”๊ฐ€ํ•˜๊ณ  ๋งจ ๋’ค์—์„œ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + - [X] DB์— ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, ์ƒˆ๋กญ๊ฒŒ ์ถ”๊ฐ€ํ•˜๊ณ  ๋งจ ๋’ค์—์„œ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ - [ ] ๊ฒ€์ƒ‰ ๊ธฐ๋ก์˜ X๋ฒ„ํŠผ ํด๋ฆญ ์‹œ, ํ•ด๋‹น ๊ฒ€์ƒ‰ ๊ธฐ๋ก์„ ์‚ญ์ œํ•˜๊ธฐ \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt b/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt index 54993aa7..7561822e 100644 --- a/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt +++ b/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt @@ -1,5 +1,6 @@ package campus.tech.kakao.map.model +import android.content.ContentValues import android.content.Context class SearchLocationRepository(context: Context) { @@ -28,6 +29,19 @@ class SearchLocationRepository(context: Context) { return result.toList() } + fun addHistory(locationName: String) { + if (isExistHistory(locationName)) { + removeHistory(locationName) + } + + val db = historyDbHelper.writableDatabase + val historyValues = ContentValues() + historyValues.put(HistoryContract.COLUMN_NAME, locationName) + db.insert(HistoryContract.TABLE_NAME, null, historyValues) + + db.close() + } + private fun isExistHistory(locationName: String): Boolean { val db = historyDbHelper.readableDatabase val searchQuery = "SELECT * FROM ${HistoryContract.TABLE_NAME} " + diff --git a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt index f784c283..917b2f4c 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt @@ -36,7 +36,7 @@ class SearchLocationActivity : AppCompatActivity() { viewModel.location.observe(this) { it?.let { locationData -> - binding.searchResultRecyclerView.adapter = SearchLocationAdapter(locationData, this) + binding.searchResultRecyclerView.adapter = SearchLocationAdapter(locationData, this, viewModel) binding.searchResultRecyclerView.layoutManager = LinearLayoutManager(this) binding.emptyResultTextView.isVisible = locationData.isEmpty() } diff --git a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationAdapter.kt b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationAdapter.kt index 54702cda..14c2928c 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationAdapter.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationAdapter.kt @@ -6,14 +6,22 @@ import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import campus.tech.kakao.map.databinding.ItemLocationBinding import campus.tech.kakao.map.model.Location +import campus.tech.kakao.map.viewmodel.SearchLocationViewModel class SearchLocationAdapter( private val dataList: List, - private val context: Context + private val context: Context, + private val viewModel: SearchLocationViewModel ) : RecyclerView.Adapter() { inner class MyViewHolder(private val binding: ItemLocationBinding) : RecyclerView.ViewHolder(binding.root) { + init { + binding.root.setOnClickListener { + viewModel.addHistory(dataList[bindingAdapterPosition].name) + } + } + fun bind(locationData: Location) { binding.locationNameTextView.text = locationData.name binding.locationAddressTextView.text = locationData.address diff --git a/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt b/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt index 0a299ad2..8cc56a0c 100644 --- a/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt +++ b/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt @@ -18,4 +18,8 @@ class SearchLocationViewModel : ViewModel() { fun searchLocation(category: String) { _location.value = repository.searchLocation(category) } + + fun addHistory(locationName: String) { + repository.addHistory(locationName) + } } \ No newline at end of file From 48e9578e7c8801e82a3b31f0be3119f7fc895694 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Fri, 5 Jul 2024 13:48:15 +0900 Subject: [PATCH 17/24] feat: Add a Method to Get History from SQLite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - getHistory(): SQLite์— ์ €์žฅ๋œ history๋“ค์„ ๋ถˆ๋Ÿฌ์™€, List์œผ๋กœ ์ „๋‹ฌํ•˜๋Š” ๋ฉ”์†Œ๋“œ ์ œ์ž‘ --- .../kakao/map/model/SearchLocationRepository.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt b/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt index 7561822e..31666b7f 100644 --- a/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt +++ b/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt @@ -42,6 +42,21 @@ class SearchLocationRepository(context: Context) { db.close() } + fun getHistory(): List { + val db = historyDbHelper.readableDatabase + val searchQuery = "SELECT * FROM ${HistoryContract.TABLE_NAME}" + val cursor = db.rawQuery(searchQuery, null) + + val result = mutableListOf() + while (cursor.moveToNext()) { + result.add(cursor.getString(cursor.getColumnIndexOrThrow(HistoryContract.COLUMN_NAME))) + } + + cursor.close() + db.close() + return result.toList() + } + private fun isExistHistory(locationName: String): Boolean { val db = historyDbHelper.readableDatabase val searchQuery = "SELECT * FROM ${HistoryContract.TABLE_NAME} " + From f097dce72681fff637cf1d1064d31062cb0827a2 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Fri, 5 Jul 2024 13:51:11 +0900 Subject: [PATCH 18/24] feat: Update History List When Start & Add Item --- .../tech/kakao/map/viewmodel/SearchLocationViewModel.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt b/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt index 8cc56a0c..c0636aea 100644 --- a/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt +++ b/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt @@ -10,16 +10,21 @@ class SearchLocationViewModel : ViewModel() { private lateinit var repository: SearchLocationRepository fun setRepository(repository: SearchLocationRepository) { this.repository = repository + _history.value = repository.getHistory() } private val _location = MutableLiveData>() val location: LiveData> = _location + private val _history = MutableLiveData>() + val history: LiveData> = _history + fun searchLocation(category: String) { _location.value = repository.searchLocation(category) } fun addHistory(locationName: String) { repository.addHistory(locationName) + _history.value = repository.getHistory() } } \ No newline at end of file From 94f989b2b6119f40894cd30420be4f4e8f40a7bd Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Fri, 5 Jul 2024 14:00:37 +0900 Subject: [PATCH 19/24] feat: Add RecyclerView Adapter for searchHistoryRecyclerView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ Data Binding์„ ์ด์šฉํ•˜์—ฌ Adapter๋ฅผ ์„ค๊ณ„ํ•˜์˜€๋‹ค. --- .../tech/kakao/map/view/HistoryAdapter.kt | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 app/src/main/java/campus/tech/kakao/map/view/HistoryAdapter.kt diff --git a/app/src/main/java/campus/tech/kakao/map/view/HistoryAdapter.kt b/app/src/main/java/campus/tech/kakao/map/view/HistoryAdapter.kt new file mode 100644 index 00000000..819051ad --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/view/HistoryAdapter.kt @@ -0,0 +1,37 @@ +package campus.tech.kakao.map.view + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import campus.tech.kakao.map.databinding.ItemHistoryBinding + +class HistoryAdapter( + private val dataList: List, + private val context: Context +) : RecyclerView.Adapter() { + + inner class MyViewHolder(private val binding: ItemHistoryBinding) : + RecyclerView.ViewHolder(binding.root) { + + fun binding(historyData: String) { + binding.locationHistoryNameTextView.text = historyData + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { + return MyViewHolder( + ItemHistoryBinding.inflate( + LayoutInflater.from(context), + parent, + false + ) + ) + } + + override fun onBindViewHolder(holder: MyViewHolder, position: Int) { + holder.binding(dataList[position]) + } + + override fun getItemCount(): Int = dataList.size +} \ No newline at end of file From 7e5040b92254d30dbc5a87e2816e8dcb22d8e2f4 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Fri, 5 Jul 2024 14:07:11 +0900 Subject: [PATCH 20/24] feat: Show History to searchHistoryRecyclerView --- .../campus/tech/kakao/map/view/SearchLocationActivity.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt index 917b2f4c..4d2350fe 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt @@ -41,5 +41,12 @@ class SearchLocationActivity : AppCompatActivity() { binding.emptyResultTextView.isVisible = locationData.isEmpty() } } + + viewModel.history.observe(this) { + it?.let { historyData -> + binding.searchHistoryRecyclerView.adapter = HistoryAdapter(historyData, this) + binding.searchHistoryRecyclerView.isVisible = historyData.isNotEmpty() + } + } } } \ No newline at end of file From 007b136c5a48fb29fadf421c2e2294b6b6874423 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Fri, 5 Jul 2024 14:18:52 +0900 Subject: [PATCH 21/24] feat: Change private to public at removeHistory() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - History ์‚ญ์ œ๋Š” ViewModel์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ด์•ผ ํ•˜๋ฏ€๋กœ, private๋กœ ์ง€์ •๋˜์–ด ์žˆ๋˜ ๊ฐ’์„ public์œผ๋กœ ์—ด์–ด์คŒ --- README.md | 2 +- .../campus/tech/kakao/map/model/SearchLocationRepository.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0d8a364d..223ddacb 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ - [X] ๊ฐ€์ ธ์˜จ ๋ฆฌ์ŠคํŠธ๋ฅผ RecyclerView์— ์ ์šฉํ•˜์—ฌ ๋ณด์—ฌ์ฃผ๊ธฐ -- [ ] ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ์ค‘ ํ•˜๋‚˜๋ฅผ ํด๋ฆญํ•˜๋Š” ๊ฒฝ์šฐ, ํ•ด๋‹น ์žฅ์†Œ๋ฅผ ๊ฒ€์ƒ‰ ๊ธฐ๋ก์— ์ถ”๊ฐ€ํ•˜๊ธฐ +- [X] ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ์ค‘ ํ•˜๋‚˜๋ฅผ ํด๋ฆญํ•˜๋Š” ๊ฒฝ์šฐ, ํ•ด๋‹น ์žฅ์†Œ๋ฅผ ๊ฒ€์ƒ‰ ๊ธฐ๋ก์— ์ถ”๊ฐ€ํ•˜๊ธฐ - [X] ๊ฒ€์ƒ‰ ๊ธฐ๋ก์„ ๋ณด์—ฌ์ฃผ๋Š” item์˜ ๋ ˆ์ด์•„์›ƒ ์ œ์ž‘ํ•˜๊ธฐ diff --git a/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt b/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt index 31666b7f..f9dc1b69 100644 --- a/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt +++ b/app/src/main/java/campus/tech/kakao/map/model/SearchLocationRepository.kt @@ -70,7 +70,7 @@ class SearchLocationRepository(context: Context) { return result } - private fun removeHistory(locationName: String) { + fun removeHistory(locationName: String) { val db = historyDbHelper.writableDatabase val deleteQuery = "DELETE FROM ${HistoryContract.TABLE_NAME} " + "WHERE ${HistoryContract.COLUMN_NAME} = '$locationName'" From 76ca1eb2f029e8e59fe7861102a1c40fad128058 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Fri, 5 Jul 2024 14:21:36 +0900 Subject: [PATCH 22/24] feat: Remove History When Click History Item --- README.md | 2 +- .../java/campus/tech/kakao/map/view/HistoryAdapter.kt | 10 ++++++++-- .../tech/kakao/map/view/SearchLocationActivity.kt | 2 +- .../kakao/map/viewmodel/SearchLocationViewModel.kt | 5 +++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 223ddacb..82294c05 100644 --- a/README.md +++ b/README.md @@ -38,4 +38,4 @@ - [X] DB์— ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, ์ƒˆ๋กญ๊ฒŒ ์ถ”๊ฐ€ํ•˜๊ณ  ๋งจ ๋’ค์—์„œ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ -- [ ] ๊ฒ€์ƒ‰ ๊ธฐ๋ก์˜ X๋ฒ„ํŠผ ํด๋ฆญ ์‹œ, ํ•ด๋‹น ๊ฒ€์ƒ‰ ๊ธฐ๋ก์„ ์‚ญ์ œํ•˜๊ธฐ \ No newline at end of file +- [X] ๊ฒ€์ƒ‰ ๊ธฐ๋ก์˜ X๋ฒ„ํŠผ ํด๋ฆญ ์‹œ, ํ•ด๋‹น ๊ฒ€์ƒ‰ ๊ธฐ๋ก์„ ์‚ญ์ œํ•˜๊ธฐ \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/view/HistoryAdapter.kt b/app/src/main/java/campus/tech/kakao/map/view/HistoryAdapter.kt index 819051ad..24ce6fba 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/HistoryAdapter.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/HistoryAdapter.kt @@ -5,15 +5,21 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import campus.tech.kakao.map.databinding.ItemHistoryBinding +import campus.tech.kakao.map.viewmodel.SearchLocationViewModel class HistoryAdapter( private val dataList: List, - private val context: Context + private val context: Context, + private val viewModel: SearchLocationViewModel ) : RecyclerView.Adapter() { inner class MyViewHolder(private val binding: ItemHistoryBinding) : RecyclerView.ViewHolder(binding.root) { - + init { + binding.removeLocationHistoryButton.setOnClickListener { + viewModel.removeHistory(dataList[bindingAdapterPosition]) + } + } fun binding(historyData: String) { binding.locationHistoryNameTextView.text = historyData } diff --git a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt index 4d2350fe..fc08579d 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt @@ -44,7 +44,7 @@ class SearchLocationActivity : AppCompatActivity() { viewModel.history.observe(this) { it?.let { historyData -> - binding.searchHistoryRecyclerView.adapter = HistoryAdapter(historyData, this) + binding.searchHistoryRecyclerView.adapter = HistoryAdapter(historyData, this, viewModel) binding.searchHistoryRecyclerView.isVisible = historyData.isNotEmpty() } } diff --git a/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt b/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt index c0636aea..a3080a5e 100644 --- a/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt +++ b/app/src/main/java/campus/tech/kakao/map/viewmodel/SearchLocationViewModel.kt @@ -27,4 +27,9 @@ class SearchLocationViewModel : ViewModel() { repository.addHistory(locationName) _history.value = repository.getHistory() } + + fun removeHistory(locationName: String) { + repository.removeHistory(locationName) + _history.value = repository.getHistory() + } } \ No newline at end of file From 426fcb6d9431a43bcaa298cdb5b76ffb27ca2515 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Fri, 5 Jul 2024 15:41:23 +0900 Subject: [PATCH 23/24] feat: Use DiffUtil to Notify Changed Item in HistoryAdapter --- .../tech/kakao/map/view/HistoryAdapter.kt | 11 ++++++++++- .../kakao/map/view/HistoryDiffUtilCallback.kt | 18 ++++++++++++++++++ .../kakao/map/view/SearchLocationActivity.kt | 9 ++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/campus/tech/kakao/map/view/HistoryDiffUtilCallback.kt diff --git a/app/src/main/java/campus/tech/kakao/map/view/HistoryAdapter.kt b/app/src/main/java/campus/tech/kakao/map/view/HistoryAdapter.kt index 24ce6fba..721a08f5 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/HistoryAdapter.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/HistoryAdapter.kt @@ -3,12 +3,13 @@ package campus.tech.kakao.map.view import android.content.Context import android.view.LayoutInflater import android.view.ViewGroup +import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import campus.tech.kakao.map.databinding.ItemHistoryBinding import campus.tech.kakao.map.viewmodel.SearchLocationViewModel class HistoryAdapter( - private val dataList: List, + private var dataList: List, private val context: Context, private val viewModel: SearchLocationViewModel ) : RecyclerView.Adapter() { @@ -25,6 +26,14 @@ class HistoryAdapter( } } + fun updateDataList(newDataList: List) { + val diffUtil = HistoryDiffUtilCallback(dataList, newDataList) + val diffResult = DiffUtil.calculateDiff(diffUtil) + + dataList = newDataList + diffResult.dispatchUpdatesTo(this) + } + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { return MyViewHolder( ItemHistoryBinding.inflate( diff --git a/app/src/main/java/campus/tech/kakao/map/view/HistoryDiffUtilCallback.kt b/app/src/main/java/campus/tech/kakao/map/view/HistoryDiffUtilCallback.kt new file mode 100644 index 00000000..d70fd405 --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/view/HistoryDiffUtilCallback.kt @@ -0,0 +1,18 @@ +package campus.tech.kakao.map.view + +import androidx.recyclerview.widget.DiffUtil + +class HistoryDiffUtilCallback( + private val oldList: List, + private val newList: List +) : DiffUtil.Callback() { + override fun getOldListSize(): Int = oldList.size + + override fun getNewListSize(): Int = newList.size + + override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean = + oldList[oldItemPosition] == newList[newItemPosition] + + override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean = + oldList[oldItemPosition] == newList[newItemPosition] +} \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt index fc08579d..630b9956 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/SearchLocationActivity.kt @@ -44,7 +44,14 @@ class SearchLocationActivity : AppCompatActivity() { viewModel.history.observe(this) { it?.let { historyData -> - binding.searchHistoryRecyclerView.adapter = HistoryAdapter(historyData, this, viewModel) + val adapter = binding.searchHistoryRecyclerView.adapter as? HistoryAdapter + + if (adapter == null) { + binding.searchHistoryRecyclerView.adapter = HistoryAdapter(historyData, this, viewModel) + } else { + adapter.updateDataList(historyData) + } + binding.searchHistoryRecyclerView.isVisible = historyData.isNotEmpty() } } From 866fcfa73d064a04ab041bbcecf9691d5122e603 Mon Sep 17 00:00:00 2001 From: Jeong Suhyeon Date: Fri, 5 Jul 2024 15:51:09 +0900 Subject: [PATCH 24/24] style: Reformat code --- app/build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 296c8738..06f1b539 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -47,8 +47,8 @@ dependencies { implementation("androidx.constraintlayout:constraintlayout:2.1.4") implementation("androidx.recyclerview:recyclerview:1.3.2") implementation("androidx.datastore:datastore-preferences:1.0.0") - implementation("androidx.activity:activity:1.8.0") - testImplementation("junit:junit:4.13.2") + implementation("androidx.activity:activity:1.8.0") + testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") }