-
Notifications
You must be signed in to change notification settings - Fork 32
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 이혜원 step2 코드 #95
Open
heonniy
wants to merge
7
commits into
kakao-tech-campus-2nd-step2:main
Choose a base branch
from
heonniy:step2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e90986a
3주차 코드입니다
heonniy 00a6bbd
docs: step1 readme
heonniy bc52f6c
feat: 주소위치를 받기위한, 그 전 파일들 수정
heonniy c8ed879
feat: Map 에서 라벨 표시 및 위치 변동 기능 구현
heonniy ca2c6a3
feat: 추가 수정사항
heonniy afd6bfd
feat: 카카오지도 onMapError() 호출 시 에러 화면을 보여주기 구현
heonniy 7d34178
feat: step2 테스트 코드 작성
heonniy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
# android-map-location | ||
## 카카오맵 API 심화 | ||
## step1 | ||
|
||
## 과제 진행 요구 사항 | ||
|
||
-[ ] 저장된 검색어를 선택하면 해당 검색어의 검색 결과가 표시된다. | ||
-[ ] 검색 결과 목록 중 하나의 항목을 선택하면 해당 항목의 위치를 지도에 표시한다. | ||
-[ ] 앱 종료 시 마지막 위치를 저장하여 다시 앱 실행 시 해당 위치로 포커스 한다. | ||
-[ ] 카카오지도 onMapError() 호출 시 에러 화면을 보여준다. | ||
|
||
## 프로그래밍 요구 사항 | ||
-[ ] BottomSheet를 사용한다. | ||
-[ ] 카카오 API 사용을 위한 앱 키를 외부에 노출하지 않는다. | ||
-[ ] 가능한 MVVM 아키텍처 패턴을 적용하도록 한다. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/src/androidTest/java/campus/tech/kakao/map/MainActivityUITest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package campus.tech.kakao.map | ||
|
||
import androidx.test.ext.junit.rules.ActivityScenarioRule | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.action.ViewActions.typeText | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.espresso.matcher.ViewMatchers.withText | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.action.ViewActions.closeSoftKeyboard | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class MainActivityUITest { | ||
|
||
@get:Rule | ||
val activityRule = ActivityScenarioRule(MainActivity::class.java) | ||
|
||
@Test | ||
fun testSearchTextCleared() { | ||
onView(withId(R.id.SearchText)).perform(typeText("Test"), closeSoftKeyboard()) | ||
|
||
onView(withId(R.id.Delete)).perform(click()) | ||
|
||
onView(withId(R.id.SearchText)).check(matches(withText(""))) | ||
} | ||
|
||
@Test | ||
fun testRecyclerViewVisibility() { | ||
onView(withId(R.id.SearchText)).perform(typeText(""), closeSoftKeyboard()) | ||
onView(withId(R.id.NoSearchText)).check(matches(withText("검색 결과가 없습니다."))) | ||
onView(withId(R.id.RecyclerView)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.INVISIBLE))) | ||
|
||
onView(withId(R.id.SearchText)).perform(typeText("Test"), closeSoftKeyboard()) | ||
onView(withId(R.id.NoSearchText)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.INVISIBLE))) | ||
onView(withId(R.id.RecyclerView)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) | ||
} | ||
|
||
@Test | ||
fun testInsertHistory() { | ||
|
||
onView(withId(R.id.SearchText)).perform(typeText("Seoul"), closeSoftKeyboard()) | ||
onView(withId(R.id.SearchText)).perform(click()) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package campus.tech.kakao.map | ||
|
||
import android.content.Context | ||
import android.database.sqlite.SQLiteDatabase | ||
import android.database.sqlite.SQLiteOpenHelper | ||
|
||
class DBHelper( | ||
context: Context?, | ||
name: String?, | ||
factory: SQLiteDatabase.CursorFactory?, | ||
version: Int | ||
) : SQLiteOpenHelper(context, name, factory, version) { | ||
|
||
|
||
override fun onCreate(db: SQLiteDatabase?) { | ||
val CREATE_TABLE = "CREATE TABLE ${PlaceEntry.TABLE_NAME} (" + | ||
"${PlaceEntry.COLUMN_NAME} TEXT, " + | ||
"${PlaceEntry.COLUMN_ADDRESS} TEXT, " + | ||
"${PlaceEntry.COLUMN_CATEGORY} TEXT)" | ||
db?.execSQL(CREATE_TABLE) | ||
} | ||
|
||
override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) { | ||
db?.execSQL("DROP TABLE IF EXISTS ${PlaceEntry.TABLE_NAME}") | ||
onCreate(db) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package campus.tech.kakao.map | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.widget.ImageButton | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.view.WindowCompat | ||
import androidx.core.view.WindowInsetsCompat | ||
|
||
class ErrorActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_error) | ||
|
||
// Edge-to-Edge 화면 지원 설정 | ||
WindowCompat.setDecorFitsSystemWindows(window, false) | ||
|
||
val retryButton: ImageButton = findViewById(R.id.robot) | ||
|
||
retryButton.setOnClickListener { | ||
// 다시 MapActivity로 이동 | ||
val intent = Intent(this, MapActivity::class.java) | ||
startActivity(intent) | ||
finish() // 현재 액티비티 종료 | ||
} | ||
|
||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/campus/tech/kakao/map/HistoryDBHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package campus.tech.kakao.map | ||
|
||
import android.content.Context | ||
import android.database.sqlite.SQLiteDatabase | ||
import android.database.sqlite.SQLiteOpenHelper | ||
|
||
class HistoryDBHelper( | ||
context: Context?, | ||
name: String?, | ||
factory: SQLiteDatabase.CursorFactory?, | ||
version: Int | ||
) : SQLiteOpenHelper(context, name, factory, version) { | ||
|
||
|
||
override fun onCreate(db: SQLiteDatabase?) { | ||
val CREATE_TABLE = "CREATE TABLE ${HistoryEntry.TABLE_NAME} (" + | ||
"${HistoryEntry.COLUMN_NAME} TEXT," + | ||
"${HistoryEntry.COLUMN_X} TEXT," + | ||
"${HistoryEntry.COLUMN_Y} TEXT," + | ||
"${HistoryEntry.COLUMN_ADDRESS} TEXT" + | ||
")" | ||
db?.execSQL(CREATE_TABLE) | ||
} | ||
|
||
override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) { | ||
db?.execSQL("DROP TABLE IF EXISTS ${PlaceEntry.TABLE_NAME}") | ||
onCreate(db) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package campus.tech.kakao.map | ||
|
||
object HistoryEntry { | ||
const val TABLE_NAME = "History" | ||
const val COLUMN_NAME = "name" | ||
const val COLUMN_X = "x" | ||
const val COLUMN_Y = "y" | ||
const val COLUMN_ADDRESS = "address" | ||
} |
62 changes: 62 additions & 0 deletions
62
app/src/main/java/campus/tech/kakao/map/HorRecycleAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package campus.tech.kakao.map | ||
|
||
import android.database.Cursor | ||
import android.provider.Settings.Global.getString | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import campus.tech.kakao.map.databinding.HoritemRecyclerviewBinding | ||
|
||
|
||
class HorRecycleAdapter(private val onClick : (String, String, String, String) -> Unit, private val onDeleteClick: (String) -> Unit ) : RecyclerView.Adapter<HorRecycleAdapter.Holder>() { | ||
|
||
|
||
private var cursor:Cursor? = null | ||
|
||
inner class Holder(private val binding: HoritemRecyclerviewBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
|
||
fun bind(name: String, x: String, y: String, address: String) { | ||
binding.Name.text = name | ||
|
||
// 전체 항목(root)을 클릭했을 때의 동작 | ||
binding.root.setOnClickListener { | ||
onClick(name, x, y,address) | ||
} | ||
|
||
// Delete 버튼을 클릭했을 때의 동작 | ||
binding.Delete.setOnClickListener { | ||
onDeleteClick(name) | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HorRecycleAdapter.Holder { | ||
val binding = HoritemRecyclerviewBinding.inflate(LayoutInflater.from(parent.context)) | ||
return Holder(binding) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return cursor?.count ?: 0 | ||
} | ||
|
||
override fun onBindViewHolder(holder: HorRecycleAdapter.Holder, position: Int) { | ||
cursor?.apply { | ||
moveToPosition(position) | ||
val name = getString(getColumnIndexOrThrow(HistoryEntry.COLUMN_NAME)) | ||
val x = getString(getColumnIndexOrThrow(HistoryEntry.COLUMN_X)) | ||
val y = getString(getColumnIndexOrThrow(HistoryEntry.COLUMN_Y)) | ||
val address = getString(getColumnIndexOrThrow(HistoryEntry.COLUMN_ADDRESS)) | ||
holder.bind(name, x, y,address) | ||
} | ||
} | ||
|
||
fun SubmitCursor(Cursor : Cursor?){ | ||
cursor = Cursor | ||
notifyDataSetChanged() | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package campus.tech.kakao.map | ||
|
||
import retrofit2.Call | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
import retrofit2.http.Query | ||
|
||
interface KakaoAPI { | ||
@GET("v2/local/search/keyword.json") | ||
fun getSearchKeyword( | ||
@Header("Authorization") key: String, | ||
@Query ("query") query: String | ||
): Call<ResultSearch> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package campus.tech.kakao.map | ||
|
||
class ListLayout( | ||
val name: String, | ||
val address: String, | ||
val category: String, | ||
val x : String, | ||
val y : String | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adapter에 DB의 데이터를 쿼리해오는 Cursor가 직접 들어오는건 좋은구조가 아니라고 생각해요.