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수정 #104

Open
wants to merge 5 commits into
base: anyooin
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.test.espresso.Espresso
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.rules.ActivityScenarioRule
import campus.tech.kakao.map.Activity.MapActivity
import org.junit.Rule
import org.junit.Test

Expand Down
11 changes: 2 additions & 9 deletions app/src/androidTest/java/campus/tech/kakao/map/SearchUITet.kt
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
package campus.tech.kakao.map

import android.app.Application
import android.view.LayoutInflater

import androidx.recyclerview.widget.RecyclerView
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.contrib.RecyclerViewActions
import androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.hasChildCount
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.hasMinimumChildCount
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import junit.framework.TestCase.assertEquals
import org.junit.AfterClass
import campus.tech.kakao.map.Activity.SearchActivity
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Rule
import org.junit.Test

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".MyApplication"
android:name=".Activity.MyApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -17,13 +17,13 @@
android:theme="@style/Theme.Map"
tools:targetApi="31">
<activity
android:name=".MapErrorActivity"
android:name=".Activity.MapErrorActivity"
android:exported="false" />
<activity
android:name=".SearchActivity"
android:name=".Activity.SearchActivity"
android:exported="false" />
<activity
android:name=".MapActivity"
android:name=".Activity.MapActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.Activity

import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.LinearLayoutCompat
import campus.tech.kakao.map.R
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.kakao.vectormap.KakaoMap
import com.kakao.vectormap.KakaoMapReadyCallback
Expand All @@ -20,7 +19,6 @@ import com.kakao.vectormap.label.LabelLayer
import com.kakao.vectormap.label.LabelOptions
import com.kakao.vectormap.label.LabelStyle
import com.kakao.vectormap.label.LabelStyles
import org.w3c.dom.Text


class MapActivity : AppCompatActivity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.Activity

import android.os.Bundle
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import campus.tech.kakao.map.R

class MapErrorActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.Activity

import android.app.Application
import campus.tech.kakao.map.R
import com.kakao.vectormap.KakaoMapSdk

class MyApplication : Application() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.Activity

import android.app.Application
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.Editable
Expand All @@ -12,16 +14,34 @@ import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ApplicationProvider
import campus.tech.kakao.map.adapter.ItemClickListener
import campus.tech.kakao.map.database.KakaoMapItem
import campus.tech.kakao.map.database.MapItemViewModel
import campus.tech.kakao.map.adapter.MapListAdapter
import campus.tech.kakao.map.R
import campus.tech.kakao.map.adapter.SelectItemClickListener
import campus.tech.kakao.map.adapter.SelectListAdapter
import campus.tech.kakao.map.database.KakaoMapItemDbHelper
import campus.tech.kakao.map.database.SelectMapItem
import campus.tech.kakao.map.kakaoAPI.NetworkService
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class SearchActivity : AppCompatActivity() {
private lateinit var mapItemDB : KakaoMapItemDbHelper
private lateinit var networkService : NetworkService
private lateinit var mapItemViewModel : MapItemViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_search)

val mapItemViewModel = MapItemViewModel(this)
//val mapItemViewModel = MapItemViewModel(this)
mapItemDB = KakaoMapItemDbHelper(applicationContext)
networkService = NetworkService()
val mapItemViewModel = MapItemViewModel(mapItemDB, networkService)
mapItemViewModel.makeAllSelectItemList()

val mapList = findViewById<RecyclerView>(R.id.mapList)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.adapter

import android.view.View
import campus.tech.kakao.map.database.KakaoMapItem
import campus.tech.kakao.map.database.SelectMapItem

interface ItemClickListener {
fun onClick(v: View, selectItem: KakaoMapItem)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import campus.tech.kakao.map.database.KakaoMapItem
import campus.tech.kakao.map.R

class MapListAdapter(
var mapItemList: List<KakaoMapItem>, val layoutInflater: LayoutInflater
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import campus.tech.kakao.map.R
import campus.tech.kakao.map.database.SelectMapItem

class SelectListAdapter(
var selectItemList: List<SelectMapItem>, val layoutInflater: LayoutInflater
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.database

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.provider.BaseColumns
import android.util.Log
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

data class KakaoMapItem(
val id: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.database

import android.content.Context
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class MapItemViewModel(context: Context) : ViewModel() {
private val mapItemDB = KakaoMapItemDbHelper(context)
val networkService = NetworkService()
import campus.tech.kakao.map.kakaoAPI.NetworkService

class MapItemViewModel(
private val mapItemDB : KakaoMapItemDbHelper,
private val networkService : NetworkService
) : ViewModel() {
//private val mapItemDB = KakaoMapItemDbHelper(context)
//val networkService = NetworkService()

private val _kakaoMapItemList: MutableLiveData<List<KakaoMapItem>> = MutableLiveData()
val kakaoMapItemList : LiveData<List<KakaoMapItem>> get() = _kakaoMapItemList
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.database

import android.content.ContentValues
import android.database.sqlite.SQLiteDatabase
import campus.tech.kakao.map.database.SelectItemDB
import campus.tech.kakao.map.database.SelectMapItem

class SelectItemDao(private val wDb: SQLiteDatabase, private val rDb: SQLiteDatabase) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.kakaoAPI

data class KakaoMapResponse (
val meta: Meta,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.kakaoAPI

import android.util.Log
import campus.tech.kakao.map.database.KakaoMapItem
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.kakaoAPI

import campus.tech.kakao.map.BuildConfig
import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_map.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapActivity">
tools:context=".Activity.MapActivity">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_map_error.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:orientation="vertical"
android:paddingStart="30dp"
android:paddingEnd="30dp"
tools:context=".MapErrorActivity">
tools:context=".Activity.MapErrorActivity">

<TextView
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SearchActivity">
tools:context=".Activity.SearchActivity">

<EditText
android:id="@+id/inputSpace"
Expand Down
31 changes: 31 additions & 0 deletions app/src/test/java/campus/tech/kakao/map/NetworkServiceTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package campus.tech.kakao.map

import android.content.Context
import androidx.test.core.app.ApplicationProvider
import campus.tech.kakao.map.database.KakaoMapItemDbHelper
import campus.tech.kakao.map.database.SelectItemDao
import campus.tech.kakao.map.kakaoAPI.NetworkService
import junit.framework.TestCase
import junit.framework.TestCase.assertTrue
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.junit.Before
import org.junit.Test

class NetworkServiceTest {
private lateinit var networkService : NetworkService

@Before
fun init() {
networkService = NetworkService()
}

@Test
fun checkInsertSelectItem() {
CoroutineScope(Dispatchers.IO).launch {
val kakaoMapItems = networkService.searchKakaoMapItem("카페")
assertTrue(kakaoMapItems.size >= 15)
}
}
}
Loading