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주차 과제 (수정) #53

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8b097b3
Initial commit
MyStoryG Jun 15, 2024
654c207
init commit
tlsgptj Jul 16, 2024
340373e
git commit
tlsgptj Jul 16, 2024
119def2
제대로 merge안된 부분 가져옴
tlsgptj Jul 16, 2024
0e26be6
MapView 수정
tlsgptj Jul 16, 2024
c8f079b
MapView 수정
tlsgptj Jul 16, 2024
e5860c2
build.gradle 수정
tlsgptj Jul 16, 2024
e2f2430
build.gradle 수정
tlsgptj Jul 16, 2024
0f88075
google로 지도 띄우기 성공
tlsgptj Jul 17, 2024
5c329c4
실패로직 띄우기
tlsgptj Jul 17, 2024
cd260e7
PlaceViewModel에서 왜 에러가 날까용
tlsgptj Jul 17, 2024
4618a39
에러해결
tlsgptj Jul 17, 2024
1f260fb
마커 표시 및 클릭 시 위치 정보 표기 구현
tlsgptj Jul 17, 2024
d0b05cf
마커 표시 및 클릭 시 위치 정보 표기 구현
tlsgptj Jul 17, 2024
8c45e0b
NullPointException
tlsgptj Jul 18, 2024
ed2e115
STEP1 제출
tlsgptj Jul 18, 2024
c309aaa
STEP1 제출
tlsgptj Jul 18, 2024
50bcaf9
MVVM 아키텍쳐로 분리
tlsgptj Jul 18, 2024
c214fee
Test코드 작성중
tlsgptj Jul 19, 2024
41be8d0
ReadME.md 파일 수정
tlsgptj Jul 19, 2024
763127a
SearchActivityTest.kt파일 작성
tlsgptj Jul 19, 2024
cbe602a
ext가 인식이 안됨
tlsgptj Jul 19, 2024
f7d9ea4
ext가 인식이 안됨
tlsgptj Jul 19, 2024
f591419
ext가 인식이 안됨
tlsgptj Jul 19, 2024
d2e2d15
앱 401에러 보완
tlsgptj Jul 19, 2024
b2995fc
actionOnItemAtPosition함수 구현 중
tlsgptj Jul 19, 2024
68ff63e
Resolve merge conflicts between origin/step0 and current branch
tlsgptj Jul 22, 2024
1d7f940
초기 빌드
tlsgptj Jul 23, 2024
d7ffe45
초기 빌드
tlsgptj Jul 23, 2024
fe4dd1f
필요없는 파일 삭제
tlsgptj Jul 23, 2024
bf72410
필요없는 파일 삭제
tlsgptj Jul 23, 2024
02c04b7
필요없는 파일 삭제
tlsgptj Jul 23, 2024
4a5e755
필요없는 파일 삭제
tlsgptj Jul 23, 2024
0855bdb
내가 검색한 데이터를 저장하는 부분을 Room으로 변경
tlsgptj Jul 24, 2024
b23b0e9
오류 수정
tlsgptj Jul 24, 2024
9c6d802
Hilt 의존성 추가
tlsgptj Jul 24, 2024
9c5a39b
4주차 수정
tlsgptj Jul 25, 2024
647d748
4주차 수정
tlsgptj Jul 25, 2024
ff858d8
4주차 수정
tlsgptj Jul 25, 2024
686de08
4주차 수정
tlsgptj Jul 26, 2024
547d377
Hilt 의존성 추가
tlsgptj Jul 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<<<<<<< HEAD
=======
.DS_Store
### Android template
>>>>>>> origin/step0
# Gradle files
.gradle/
build/
Expand Down Expand Up @@ -33,5 +36,11 @@ google-services.json

# Android Profiling
*.hprof
<<<<<<< HEAD

# Mac OS
.DS_Store
=======
/keyStore
/app/release
>>>>>>> origin/step0
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# android-map-refactoring
# 기능 요구 사항
1. 데이터베이스를 Room으로 변경한다.
2. 가능한 모든 부분에 대해서 의존성 주입을 적용한다.
# 프로그래밍 요구 사항
1. 의존성 주입을 위해서 Hilt를 사용한다.
2. 코드 컨벤션을 준수하며 프로그래밍한다.
73 changes: 49 additions & 24 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ plugins {
}

android {
namespace = "campus.tech.kakao.map"
compileSdk = 34
namespace = "campus.tech.kakao.map"

defaultConfig {
applicationId = "campus.tech.kakao.map"
minSdk = 26
targetSdk = 34
versionCode = 1
versionName = "1.0"
ndk {
abiFilters.add("arm64-v8a")
abiFilters.add("armeabi-v7a")
abiFilters.add("x86")
abiFilters.add("x86_64")
}
dataBinding {
enable = true
}

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -26,55 +35,71 @@ android {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
"proguard-rules.pro"
)
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = "17"
}

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

dependencies {

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-ktx:1.9.0")
implementation("androidx.test:core-ktx:1.6.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.3")
implementation("androidx.test.espresso:espresso-core:3.6.1")
testImplementation ("org.junit.jupiter:junit-jupiter-api:5.8.2")
testRuntimeOnly ("org.junit.jupiter:junit-jupiter-engine:5.8.2")
implementation("androidx.test.ext:junit-ktx:1.2.1")
implementation("androidx.test.espresso:espresso-intents:3.6.1")
testImplementation("io.mockk:mockk:1.13.11")
testImplementation("io.mockk:mockk-android:1.13.11")
testImplementation("io.mockk:mockk-agent:1.13.11")
testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0")
testImplementation("junit:junit:4.13.2")
testImplementation("org.mockito:mockito-core:4.8.1")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
androidTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
implementation("androidx.room:room-runtime:2.6.1")
kapt("androidx.room:room-compiler:2.6.1")
testImplementation("androidx.room:room-testing:2.6.1")
implementation("com.google.dagger:hilt-android:2.48.1")
kapt("com.google.dagger:hilt-compiler:2.48.1")
implementation("androidx.activity:activity-ktx:1.9.0")
androidTestImplementation("com.google.dagger:hilt-android-testing:2.48.1")
kaptAndroidTest("com.google.dagger:hilt-android-compiler:2.48.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4")
implementation("androidx.room:room-ktx:2.6.1")
testImplementation("androidx.room:room-testing:2.6.1")
testImplementation("junit:junit:4.13.2")
implementation("com.google.android.gms:play-services-maps:19.0.0")
implementation("com.google.android.libraries.places:places:3.5.0")
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")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
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")
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("androidx.datastore:datastore-preferences:1.1.1")
implementation("androidx.activity:activity:1.9.1")
implementation("com.squareup.retrofit2:retrofit:2.11.0")
implementation("com.squareup.retrofit2:converter-gson:2.11.0")
implementation("com.google.ar.sceneform:core:1.17.1")
implementation("com.google.android.gms:play-services-location:21.3.0")
implementation("androidx.multidex:multidex:2.0.1")
implementation("com.kakao.maps.open:android:2.9.5")
implementation("com.kakao.sdk:v2-all:2.20.3")
implementation("com.squareup.okhttp3:okhttp:4.11.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.9.2")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package campus.tech.kakao.map

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.runner.AndroidJUnit4
import campus.tech.kakao.map.View.ErrorActivity
import campus.tech.kakao.map.View.Map_Activity
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class ErrorActivityTest {

private lateinit var scenario: ActivityScenario<ErrorActivity>

@Before
fun setup() {
scenario = ActivityScenario.launch(ErrorActivity::class.java)
}

@After
fun tearDown() {
scenario.close()
}

@Test
fun testErrorActivityIsDisplayed() {
onView(withId(R.id.error_message)).check(matches(isDisplayed()))
onView(withId(R.id.retry_button)).check(matches(isDisplayed()))
}

@Test
fun testRetryButton() {
onView(withId(R.id.retry_button)).perform(click())

val intendedIntent = Intent(getInstrumentation().targetContext, Map_Activity::class.java)
intendedIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
assertEquals(intendedIntent.component, (getInstrumentation().context as AppCompatActivity))
}
}
84 changes: 84 additions & 0 deletions app/src/androidTest/java/campus/tech/kakao/map/MapActivityTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package campus.tech.kakao.map

import android.content.SharedPreferences
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import campus.tech.kakao.map.View.Map_Activity
import com.google.android.gms.maps.model.LatLng
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class MapActivityTest {

private lateinit var scenario: ActivityScenario<Map_Activity>
private lateinit var sharedPreferences: SharedPreferences
private lateinit var editor: SharedPreferences.Editor

@Before
fun setup() {
editor = sharedPreferences.edit()

scenario = ActivityScenario.launch(Map_Activity::class.java)
}

@After
fun tearDown() {
scenario.close()
}

@Test
fun mapSuccess() {
scenario.onActivity { activity ->
val googleMap = scenario
assertNotNull(googleMap)
}
}

@Test
fun lastLocationRequest() {
val testLatLng = LatLng(37.5665, 126.9780)

scenario.onActivity { activity ->
val method = Map_Activity::class.java.getDeclaredMethod("saveLastLocation", Double::class.java, Double::class.java)
method.isAccessible = true
method.invoke(activity, testLatLng.latitude, testLatLng.longitude)

val lastLatitude = sharedPreferences.getFloat("lastLatitude", 0f)
val lastLongitude = sharedPreferences.getFloat("lastLongitude", 0f)

assertEquals(testLatLng.latitude.toFloat(), lastLatitude)
assertEquals(testLatLng.longitude.toFloat(), lastLongitude)

val field = Map_Activity::class.java.getDeclaredField("lastKnownLocation")
field.isAccessible = true
val lastKnownLocation = field.get(activity) as LatLng

assertEquals(testLatLng, lastKnownLocation)
}
}

@Test
fun showError401() {
scenario.onActivity { activity ->
activity.onMapError(401)
onView(withId(R.id.error_message)).check(matches(isDisplayed()))
onView(withId(R.id.error_message)).check(matches(withText("401 Unauthorized Error")))
}
}
}






Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@file:Suppress("DEPRECATION")

package campus.tech.kakao.map

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.rules.ActivityScenarioRule
import androidx.test.runner.AndroidJUnit4
import campus.tech.kakao.map.View.Search_Activity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class SearchActivityTest {

@get:Rule
val activityRule = ActivityScenarioRule(Search_Activity::class.java)

@Test
fun testSearchView_isDisplayed() {
onView(withId(R.id.search_text)).check(matches(isDisplayed()))
}

@Test
fun testSearchRecyclerView_isDisplayed() {
onView(withId(R.id.RecyclerVer)).check(matches(isDisplayed()))
}

@Test
fun testSavedSearchRecyclerView_isDisplayed() {
onView(withId(R.id.recyclerHor)).check(matches(isDisplayed()))
}

@Test
fun testSearchView_textEntry() {
onView(withId(R.id.search_text))
.perform(typeText("카페"), pressImeActionButton())

onView(withId(R.id.RecyclerVer)).check(matches(hasDescendant(withText("Cafe Name"))))
}

@Test
fun testSearchResult_click() {
onView(withId(R.id.search_text))
.perform(typeText("도서관"), pressImeActionButton())

Thread.sleep(2000)
}

}
18 changes: 16 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!-- 권한 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -12,15 +18,23 @@
android:supportsRtl="true"
android:theme="@style/Theme.Map"
tools:targetApi="31">

<activity
android:name=".View.Map_Activity"
android:exported="true" />

<activity
android:name=".MainActivity"
android:name=".View.Search_Activity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCUncz7v8nwT3m5OHasVJTep1e1549yAKM" />
</application>

</manifest>
Loading