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_신혜서 6주차 과제 step2 (수정) #89

Open
wants to merge 12 commits into
base: tlsgptj
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
8 changes: 7 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ android {
)
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand All @@ -42,11 +43,13 @@ android {
buildFeatures {
dataBinding = true
buildConfig = true
viewBinding = true
}
}

dependencies {

implementation ("com.google.firebase:firebase-messaging:24.0.0")
implementation ("com.google.firebase:firebase-config:24.0.0")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("com.google.android.material:material:1.12.0")
Expand All @@ -59,6 +62,9 @@ dependencies {
implementation("androidx.test:core-ktx:1.6.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.3")
implementation("androidx.room:room-runtime:2.6.1")
implementation("androidx.activity:activity:1.9.1")
implementation("com.google.firebase:firebase-config:22.0.0")
implementation("com.google.firebase:firebase-messaging:24.0.0")
kapt("androidx.room:room-compiler:2.6.1")
implementation("com.google.dagger:hilt-android:2.48.1")
kapt("com.google.dagger:hilt-compiler:2.48.1")
Expand Down
22 changes: 20 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,25 @@
android:theme="@style/Theme.Map"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name=".baseline_refresh_24"
android:exported="false" />
<activity
android:name=".view_error"
android:exported="false" />
<activity
android:name=".list_keyword"
android:exported="false" />
<activity
android:name=".list_item"
android:exported="false" />
<activity
android:name=".layout_map_bottom_sheet"
android:exported="false" />
<activity
android:name=".view.map.Map_Activity"
android:exported="false" />
<activity
android:name=".view.search.SearchActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -27,4 +45,4 @@
</activity>
</application>

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

import android.app.Application
import com.kakao.vectormap.KakaoMapSdk
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class MapApplication : Application() {
override fun onCreate() {
super.onCreate()
val key = getString(R.string.kakao_api_key)
KakaoMapSdk.init(this, key)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package campus.tech.kakao.map.adapter.keyword

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import campus.tech.kakao.map.databinding.ListKeywordBinding
import campus.tech.kakao.map.viewmodel.OnKeywordItemClickListener

class KeywordAdapter(private val onKeywordItemClickListener: OnKeywordItemClickListener) :
ListAdapter<String, KeywordAdapter.KeywordViewHolder>(
KeywordDiffCallback()
) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): KeywordViewHolder {
val inflater = LayoutInflater.from(parent.context)
val binding = ListKeywordBinding.inflate(inflater, parent, false)
return KeywordViewHolder(
binding
)
}

override fun onBindViewHolder(holder: KeywordViewHolder, position: Int) {
holder.bindViewHolder(getItem(position), onKeywordItemClickListener)
}

class KeywordViewHolder(private val binding: ListKeywordBinding) :
RecyclerView.ViewHolder(binding.root) {

fun bindViewHolder(
keyword: String,
onKeywordItemClickListener: OnKeywordItemClickListener
) {
binding.keyword = keyword
binding.listener = onKeywordItemClickListener
binding.executePendingBindings()
}
}
}

class KeywordDiffCallback : DiffUtil.ItemCallback<String>() {
override fun areItemsTheSame(oldItem: String, newItem: String) = oldItem == newItem
override fun areContentsTheSame(oldItem: String, newItem: String) = oldItem == newItem
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package campus.tech.kakao.map.adapter.search

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import campus.tech.kakao.map.databinding.ListItemBinding
import campus.tech.kakao.map.viewmodel.OnSearchItemClickListener
import campus.tech.kakao.map.model.kakaolocal.LocalUiModel

class SearchAdapter(
private val onSearchItemClickListener: OnSearchItemClickListener
) :
ListAdapter<LocalUiModel, SearchAdapter.SearchViewHolder>(SearchDiffCallback()) {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): SearchViewHolder {
val inflater = LayoutInflater.from(parent.context)
val binding = ListItemBinding.inflate(inflater, parent, false)
return SearchViewHolder(binding)
}

override fun onBindViewHolder(holder: SearchViewHolder, position: Int) {
val item = getItem(position)
holder.bindViewHolder(item, onSearchItemClickListener)
}

class SearchViewHolder(private val binding: ListItemBinding) :
RecyclerView.ViewHolder(binding.root) {

fun bindViewHolder(
localUiModel: LocalUiModel,
onSearchItemClickListener: OnSearchItemClickListener
) {
binding.localUiModel = localUiModel
binding.listener = onSearchItemClickListener
binding.executePendingBindings()
}
}
}

class SearchDiffCallback : DiffUtil.ItemCallback<LocalUiModel>() {
override fun areItemsTheSame(oldItem: LocalUiModel, newItem: LocalUiModel) =
oldItem.place == newItem.place

override fun areContentsTheSame(oldItem: LocalUiModel, newItem: LocalUiModel) =
oldItem == newItem
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package campus.tech.kakao.map.di.database

import android.content.Context
import androidx.room.Room
import campus.tech.kakao.map.repository.keyword.KeywordDao
import campus.tech.kakao.map.repository.keyword.KeywordDatabase
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

private const val DATABASE_NAME = "keyword"

@InstallIn(SingletonComponent::class)
@Module
class KeywordDatabaseModule {
@Singleton
@Provides
fun provideKeywordDatabase(@ApplicationContext appContext: Context): KeywordDatabase {
return Room.databaseBuilder(
appContext,
KeywordDatabase::class.java,
DATABASE_NAME
).build()
}

@Singleton
@Provides
fun provideKeywordDao(database: KeywordDatabase): KeywordDao {
return database.keywordDao()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package campus.tech.kakao.map.di.keyword

import campus.tech.kakao.map.repository.keyword.KeywordDatabase
import campus.tech.kakao.map.repository.keyword.KeywordRepository
import campus.tech.kakao.map.repository.keyword.KeywordRepositoryImpl
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
@Module
class KeywordRepositoryModule {
@Singleton
@Provides
fun provideKeywordRepository(keywordDatabase: KeywordDatabase): KeywordRepository {
return KeywordRepositoryImpl(keywordDatabase)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package campus.tech.kakao.map.di.location

import campus.tech.kakao.map.network.KakaoLocalService
import campus.tech.kakao.map.repository.location.KakaoLocationImpl
import campus.tech.kakao.map.repository.location.LocationRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
@Module
class LocationRepositoryModule {
@Singleton
@Provides
fun provideLocationRepository(kakaoLocalService: KakaoLocalService): LocationRepository {
return KakaoLocationImpl(kakaoLocalService)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package campus.tech.kakao.map.di.map

import android.content.SharedPreferences
import campus.tech.kakao.map.repository.map.datasource.MapDataSource
import campus.tech.kakao.map.repository.map.datasource.MapDataSourceImpl
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
@Module
class MapDataSourceModule {
@Singleton
@Provides
fun provideMapDataSource(preference: SharedPreferences): MapDataSource {
return MapDataSourceImpl(preference)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package campus.tech.kakao.map.di.map

import campus.tech.kakao.map.repository.map.MapRepository
import campus.tech.kakao.map.repository.map.MapRepositoryImpl
import campus.tech.kakao.map.repository.map.datasource.MapDataSource
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
@Module
class MapRepositoryModule {
@Singleton
@Provides
fun provideMapRepository(dataSource: MapDataSource): MapRepository {
return MapRepositoryImpl(dataSource)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package campus.tech.kakao.map.di.map

import android.app.Application
import android.content.Context
import android.content.SharedPreferences
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
@Module
class SharedPreferenceModule {
@Singleton
@Provides
fun provideSharedPreferences(context: Context): SharedPreferences {
return context.getSharedPreferences("LAST_POSITION", Context.MODE_PRIVATE)
}

@Singleton
@Provides
fun provideContext(application: Application): Context = application.applicationContext
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package campus.tech.kakao.map.di.network

import campus.tech.kakao.map.network.KakaoLocalService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
@Module
class KakaoLocalServiceModule {
@Singleton
@Provides
fun provideRetorfit(): Retrofit {
return Retrofit.Builder()
.baseUrl("https://dapi.kakao.com")
.addConverterFactory(GsonConverterFactory.create())
.build()
}

@Singleton
@Provides
fun provideKakaoLocalService(retrofit: Retrofit): KakaoLocalService =
retrofit.create(KakaoLocalService::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package campus.tech.kakao.map.model.kakaolocal

import com.google.gson.annotations.SerializedName

data class Document(
@SerializedName("address_name") val addressName: String,
@SerializedName("category_group_code") val categoryGroupCode: String,
@SerializedName("category_group_name") val categoryGroupName: String,
@SerializedName("category_name") val categoryName: String,
@SerializedName("distance") val distance: String,
@SerializedName("id") val id: String,
@SerializedName("phone") val phone: String,
@SerializedName("place_name") val placeName: String,
@SerializedName("place_url") val placeUrl: String,
@SerializedName("road_address_name") val roadAddressName: String,
@SerializedName("x") val x: String,
@SerializedName("y") val y: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package campus.tech.kakao.map.model.kakaolocal

data class KakaoLocalResponse(
val documents: List<Document>,
val meta: Meta
)
Loading