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_노신 4주차 Step2 #59

Open
wants to merge 25 commits into
base: normenghub
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
# android-map-location

## 기능 요구 사항

저장된 검색어를 선택하면 해당 검색어의 검색 결과가 표시된다.

검색 결과 목록 중 하나의 항목을 선택하면 해당 항목의 위치를 지도에 표시한다.

앱 종료 시 마지막 위치를 저장하여 다시 앱 실행 시 해당 위치로 포커스 한다.

카카오지도 onMapError() 호출 시 에러 화면을 보여준다.

## 프로그래밍 요구 사항

BottomSheet를 사용한다.

카카오 API 사용을 위한 앱 키를 외부에 노출하지 않는다.

가능한 MVVM 아키텍처 패턴을 적용하도록 한다.

## 기능 요구 사항

테스트 코드를 작성한다.
44 changes: 36 additions & 8 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import java.io.FileNotFoundException
import java.util.Properties

plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
Expand All @@ -13,6 +16,8 @@ android {
targetSdk = 34
versionCode = 1
versionName = "1.0"
buildConfigField("String", "KAKAO_REST_API_KEY", "\"${getApiKey("KAKAO_REST_API_KEY")}\"")
resValue("string", "kakao_api_key", getApiKey("kakao_api_key"))

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -37,27 +42,50 @@ android {
buildFeatures {
viewBinding = true
}
testOptions {
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}
}

dependencies {

testImplementation("io.mockk:mockk-android:1.13.11")
testImplementation("io.mockk:mockk-agent:1.13.11")
androidTestImplementation("androidx.test:core:1.5.0")
androidTestImplementation("androidx.test:core-ktx:1.5.0")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.ext:junit-ktx:1.1.5")
androidTestImplementation("androidx.test.ext:truth:1.5.0")
androidTestImplementation("androidx.test:runner:1.5.2")
androidTestUtil("androidx.test:orchestrator:1.4.2")
implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1")
implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1")
implementation ("androidx.lifecycle:lifecycle-runtime-ktx:2.4.0")
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.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.recyclerview:recyclerview:1.3.2")
implementation("androidx.datastore:datastore-preferences:1.0.0")
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("com.kakao.sdk:v2-all:2.20.3")
implementation("androidx.activity:activity:1.8.0")
implementation("androidx.test:core-ktx:1.5.0")
debugImplementation("androidx.fragment:fragment-testing:1.8.1")
testImplementation("junit:junit:4.13.2")
testImplementation("io.mockk:mockk-android:1.13.11")
testImplementation("io.mockk:mockk-agent:1.13.11")
testImplementation("androidx.arch.core:core-testing:2.2.0")
testImplementation("org.robolectric:robolectric:4.11.1")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation("androidx.test:rules:1.5.0")
androidTestImplementation("androidx.test.espresso:espresso-intents:3.5.1")
testImplementation ("org.robolectric:robolectric:4.9")
}
fun getApiKey(key: String): String {
val properties = Properties()
val localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
properties.load(localPropertiesFile.inputStream())
return properties.getProperty(key) ?: throw IllegalArgumentException("API key '$key' not found in local.properties")
} else {
throw FileNotFoundException("local.properties files not found")
}
}


43 changes: 43 additions & 0 deletions app/src/androidTest/java/MapFragmentUiTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import androidx.fragment.app.testing.FragmentScenario
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.runners.AndroidJUnit4
import campus.tech.kakao.View.MapFragment
import campus.tech.kakao.map.R
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class MapFragmentUITest {
private lateinit var fragmentScenario: FragmentScenario<MapFragment>

@Before
fun setUp() {
fragmentScenario = FragmentScenario.launchInContainer(MapFragment::class.java)
}
@After
fun tearDown() {
fragmentScenario.close()
}
@Test
fun testMapViewIsDisplayed() {
onView(withId(R.id.KakaoMapView)).check(matches(isDisplayed()))
}
@Test
fun testSearchViewIsDisplayed() {
onView(withId(R.id.searchView1)).check(matches(isDisplayed()))
}
@Test
fun testSearchViewFunctionality() {
onView(withId(R.id.searchView1)).perform(click())
onView(withId(R.id.searchView1)).perform(typeText("검색어"), closeSoftKeyboard())
onView(withId(R.id.searchView1)).check(matches(withText("검색어")))
}



}
50 changes: 50 additions & 0 deletions app/src/androidTest/java/SearchFragmentUiTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import androidx.fragment.app.testing.FragmentScenario
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.typeText
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import campus.tech.kakao.View.SearchFragment
import campus.tech.kakao.map.R
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)

class SearchFragmentUiTest {
private lateinit var fragmentScenario: FragmentScenario<SearchFragment>
@Before
fun setUp() {
fragmentScenario = FragmentScenario.launchInContainer(SearchFragment::class.java)
}
@After
fun tearDown() {
fragmentScenario.close()
}
@Test
fun testSearchViewIsDisplayed() {
onView(withId(R.id.searchView2)).check(matches(isDisplayed()))
}
@Test
fun testRecyclerViewIsDisplayed() {

onView(withId(R.id.recyclerView)).check(matches(isDisplayed()))
}
@Test
fun testHistoryRecyclerViewIsDisplayed() {
onView(withId(R.id.historyRecyclerView)).check(matches(isDisplayed()))
}
@Test
fun testSearchViewFunctionality() {
onView(withId(R.id.searchView2)).perform(click())
onView(withId(R.id.searchView2)).perform(typeText("검색어"))


onView(withId(R.id.recyclerView)).check(matches(isDisplayed()))
}


}
10 changes: 9 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,33 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name = ".initializing"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:usesCleartextTraffic="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Map"
tools:targetApi="31">
<activity
android:name=".MainActivity"

android:name="campus.tech.kakao.View.MainActivity"
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="campus.tech.kakao.View.OnMapErrorActivity"></activity>
</application>

</manifest>
50 changes: 50 additions & 0 deletions app/src/main/java/campus/tech/kakao/BottomSheetDialogFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package campus.tech.kakao.View

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import campus.tech.kakao.map.R

class PlaceInfoBottomSheet : BottomSheetDialogFragment() {

private var placeName: String? = null
private var roadAddressName: String? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
placeName = it.getString("placeName")
roadAddressName = it.getString("roadAddressName")
}
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.bottomsheet, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val placeNameTextView: TextView = view.findViewById(R.id.placeNameTextView)
val roadAddressTextView: TextView = view.findViewById(R.id.roadAddressTextView)

placeNameTextView.text = placeName
roadAddressTextView.text = roadAddressName
}

companion object {
@JvmStatic
fun newInstance(placeName: String, roadAddressName: String) =
PlaceInfoBottomSheet().apply {
arguments = Bundle().apply {
putString("placeName", placeName)
putString("roadAddressName", roadAddressName)
}
}
}
}
Loading