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 #74

Open
wants to merge 39 commits into
base: arieum
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
56c0f65
Resolved conflicts & Add google-services.json(.gitignore)
arieum Jul 29, 2024
f656ea1
Feat: Write README.md
arieum Jul 29, 2024
60687d8
Create: Add initial entry screen_WelcomeActivity
arieum Jul 29, 2024
21a284a
feat: Add Remote_Config function
arieum Jul 30, 2024
264327d
refactor: databinding 제거
arieum Jul 30, 2024
6d838e2
refactor: Resolve Issue!
arieum Jul 31, 2024
1c4dec6
refactor: Resolve issue(Add coroutine)
arieum Jul 31, 2024
a770a31
refactor: Add WelcomeViewModel_init_function
arieum Jul 31, 2024
74ea599
feat: Add Foreground_Custom_Notification
arieum Aug 1, 2024
813f910
feat: Add Function_firebase_MSG_Recieved
arieum Aug 2, 2024
6a4db28
refactor: remove unnecessary import & typo correction
arieum Aug 2, 2024
e14ebea
Delete MyPlaceContract.kt
arieum Aug 2, 2024
b611435
Delete PlaceDbHelper.kt
arieum Aug 2, 2024
9c8289d
Delete RetrofitClient.kt
arieum Aug 2, 2024
945bb92
refactor: Resolved conflict in .gitignore
arieum Aug 2, 2024
27a1288
refactor: Resolved conflicts in gradlew
arieum Aug 2, 2024
0fc30e8
refactor: Resolved conflicts in gradlew.bat
arieum Aug 2, 2024
7aa3d7d
refactor: Inject sharedPreference in MapRepository.kt
arieum Aug 2, 2024
64075b7
refactor: changed mapRepository parameter in RepositoryModule.kt
arieum Aug 2, 2024
53d0ec3
refactor: add const variable KakaoAK in PlaceRepository.kt
arieum Aug 2, 2024
1468dd3
refactor: Apply STEP1 Feedback
arieum Aug 2, 2024
3ff02b5
refactor: remove img entity in place
arieum Aug 2, 2024
a4ad50c
Merge branch 'arieum' into arieum_step2
arieum Aug 3, 2024
abc69b8
Merge remote-tracking branch 'arieum_remote/arieum_step1' into arieum…
arieum Aug 3, 2024
70419e2
feat: Add Foreground_Custom_Notification
arieum Aug 1, 2024
15cda87
feat: Add Function_firebase_MSG_Recieved
arieum Aug 2, 2024
a521fd2
refactor: remove unnecessary import & typo correction
arieum Aug 2, 2024
3abdb54
refactor: Apply STEP1 Feedback
arieum Aug 2, 2024
7748b14
refactor: remove img entity in place
arieum Aug 2, 2024
2cfcdee
refactor: Replace runBlocking with coroutineScope to prevent ANR
arieum Aug 3, 2024
63cb7ae
rebase
arieum Aug 3, 2024
e2a532c
Resolved conflicts
arieum Aug 3, 2024
381cfa9
refacotr: typo correction
arieum Aug 3, 2024
c673313
refactor: Use Dispatcher.IO for database operations in LogRepository
arieum Aug 3, 2024
5a5e991
refacotr: Restructure package
arieum Aug 3, 2024
1001f19
refactor: refactor db&repository implementation
arieum Aug 3, 2024
4a17bd6
refactor: Improve delayed UI update using coroutines in WelcomeAcitivity
arieum Aug 3, 2024
e96fff7
refactor: refactor FCMservice for proper initialization and foregroun…
arieum Aug 4, 2024
7904df8
refactor: Move hardcoded strings to string resources
arieum Aug 4, 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ google-services.json
/app/release

# Mac OS
.DS_Store
.DS_Store
12 changes: 3 additions & 9 deletions app/schemas/campus.tech.kakao.map.data.db.AppDatabase/1.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "e1dff925b4d05fac65f959d46ab6a9a7",
"identityHash": "de42a776ec13b03bff04a36fe6dc2ddb",
"entities": [
{
"tableName": "research",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `img` INTEGER NOT NULL, `name` TEXT NOT NULL, `location` TEXT NOT NULL, `category` TEXT NOT NULL, `x` TEXT NOT NULL, `y` TEXT NOT NULL)",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT NOT NULL, `location` TEXT NOT NULL, `category` TEXT NOT NULL, `x` TEXT NOT NULL, `y` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "img",
"columnName": "img",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
Expand Down Expand Up @@ -64,7 +58,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'e1dff925b4d05fac65f959d46ab6a9a7')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'de42a776ec13b03bff04a36fe6dc2ddb')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.espresso.assertion.ViewAssertions.matches
import campus.tech.kakao.map.view.MainActivity
import campus.tech.kakao.map.presentation.view.MainActivity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand Down
28 changes: 23 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" android:minSdkVersion="33"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:name=".base.MyApplication"
Expand All @@ -18,22 +21,37 @@
android:theme="@style/Theme.Map"
tools:targetApi="31">
<activity
android:name=".view.MapViewActivity"
android:name=".presentation.view.MapViewActivity"
android:exported="false" />
<activity
android:name=".view.ErrorActivity"
android:name=".presentation.view.ErrorActivity"
android:exported="false" />
<activity
android:name=".view.MainActivity"
android:name=".presentation.view.MainActivity"
android:exported="true" />
<activity
android:name=".view.WelcomeActivity"
android:name=".presentation.view.WelcomeActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".data.remote.service.FCMservice"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_channel_id" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_launcher_foreground" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
</application>

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

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import campus.tech.kakao.map.data.db.entity.Place

@Database(entities = [Place::class], version = 1)
abstract class AppDatabase: RoomDatabase() {
abstract fun placeDao(): PlaceDao

companion object {
@Volatile private var instance: AppDatabase? = null

fun getDatabase(context: Context): AppDatabase =
instance ?: synchronized(this) {
instance ?: buildDatabase(context).also { instance = it }
}

private fun buildDatabase(context: Context) =
Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java,
"MyPlace.db").build()

}
}
8 changes: 4 additions & 4 deletions app/src/main/java/campus/tech/kakao/map/data/db/PlaceDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import campus.tech.kakao.map.data.db.entity.Place
@Dao
interface PlaceDao {
@Insert(onConflict = OnConflictStrategy.IGNORE)
fun insertLog(place: Place)
suspend fun insertLog(place: Place)

@Delete
fun deleteLog(place: Place)
suspend fun deleteLog(place: Place)

@Query("SELECT * FROM research")
fun getAllLogs(): List<Place>
suspend fun getAllLogs(): List<Place>

@Query("SELECT COUNT(*) FROM research")
fun getPlaceCount(): Int
suspend fun getPlaceCount(): Int
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package campus.tech.kakao.map.data.db.entity

import androidx.annotation.DrawableRes
import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "research")
data class Place (
@PrimaryKey(autoGenerate = true) val id: Int? = null,
@DrawableRes val img: Int,
val name: String,
val location: String,
val category: String,
val x: String,
val y: String
)
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package campus.tech.kakao.map.data.di

import android.content.Context
import androidx.room.Room
import campus.tech.kakao.map.data.db.AppDatabase
import campus.tech.kakao.map.data.db.PlaceDao
import dagger.Module
Expand All @@ -13,10 +14,15 @@ import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {
private const val DATABASE_NAME = "MyPlace.db"
@Provides
@Singleton
fun provideDatabase(@ApplicationContext context: Context): AppDatabase {
return AppDatabase.getDatabase(context)
return Room.databaseBuilder(
context,
AppDatabase::class.java,
DATABASE_NAME
).build()
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object PreferencesModule {

@Provides
@Singleton
fun provideSharedPreferences(@ApplicationContext context: Context): SharedPreferences {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package campus.tech.kakao.map.data.di

import campus.tech.kakao.map.repository.RemoteConfigManager
import campus.tech.kakao.map.data.remote.config.RemoteConfigManager
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down
22 changes: 10 additions & 12 deletions app/src/main/java/campus/tech/kakao/map/data/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package campus.tech.kakao.map.data.di

import android.app.Application
import android.content.Context
import android.content.SharedPreferences
import campus.tech.kakao.map.base.MyApplication
import campus.tech.kakao.map.data.db.PlaceDao
import campus.tech.kakao.map.data.db.AppDatabase
import campus.tech.kakao.map.data.remote.api.KakaoApiService
import campus.tech.kakao.map.repository.LogRepository
import campus.tech.kakao.map.repository.LogRepositoryInterface
import campus.tech.kakao.map.repository.MapRepository
import campus.tech.kakao.map.repository.MapRepositoryInterface
import campus.tech.kakao.map.repository.PlaceRepository
import campus.tech.kakao.map.repository.PlaceRepositoryInterface
import campus.tech.kakao.map.repository.WelcomeRepository
import campus.tech.kakao.map.data.repository.log.LogRepository
import campus.tech.kakao.map.data.repository.log.LogRepositoryInterface
import campus.tech.kakao.map.data.repository.map.MapRepository
import campus.tech.kakao.map.data.repository.map.MapRepositoryInterface
import campus.tech.kakao.map.data.repository.place.PlaceRepository
import campus.tech.kakao.map.data.repository.place.PlaceRepositoryInterface
import campus.tech.kakao.map.data.repository.WelcomeRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -39,8 +37,8 @@ object RepositoryModule {

@Provides
@Singleton
fun provideLogRepository(context: Context, placeDao: PlaceDao): LogRepositoryInterface {
return LogRepository(context.applicationContext as MyApplication, placeDao)
fun provideLogRepository(placeDatabase: AppDatabase): LogRepositoryInterface {
return LogRepository(placeDatabase)
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map.repository
package campus.tech.kakao.map.data.remote.config

import android.util.Log
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package campus.tech.kakao.map.data.remote.service

import android.util.Log
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage

class FCMservice : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
super.onMessageReceived(remoteMessage)
Log.d("TEST_FcmService", "Received Message")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package campus.tech.kakao.map.data.repository

import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import androidx.core.app.NotificationCompat
import campus.tech.kakao.map.R
import campus.tech.kakao.map.presentation.view.WelcomeActivity

class WelcomeRepository {
fun sendForegroundNotification(context: Context) {
val intent = Intent(context, WelcomeActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
val pendingIntent: PendingIntent = PendingIntent.getActivity(context, REQUEST_CODE, intent, PendingIntent.FLAG_IMMUTABLE)

val notification = NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.icon)
.setContentTitle("[알림]KAKAO MAP")
.setContentText("In Foreground, This app is RUNNING...!")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.build()

val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(NOTIFICATION_ID, notification)
}
fun createNotificationChannel(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channelId = CHANNEL_ID
val channelName = CHANNEL_NAME
val channelDescription = CHANNEL_DESCRIPTION
val importance = NotificationManager.IMPORTANCE_DEFAULT

val channel = NotificationChannel(channelId, channelName, importance).apply {
description = channelDescription
}

val notificationManager: NotificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}
}

companion object {
private const val NOTIFICATION_ID = 222222
private const val REQUEST_CODE = 0
private const val CHANNEL_ID = "Mychannel"
private const val CHANNEL_NAME = "Mychannel"
private const val CHANNEL_DESCRIPTION = "This is Mychannel"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package campus.tech.kakao.map.data.repository.log

import campus.tech.kakao.map.data.db.AppDatabase
import campus.tech.kakao.map.data.db.entity.Place
import javax.inject.Inject

class LogRepository @Inject constructor (private val placeDatabase: AppDatabase): LogRepositoryInterface {
override suspend fun getAllLogs(): List<Place> {
return placeDatabase.placeDao().getAllLogs()
}

override suspend fun haveAnyLog(): Boolean {
return placeDatabase.placeDao().getPlaceCount() > 0
}

override suspend fun insertLog(place: Place) {
placeDatabase.placeDao().insertLog(place)
}

override suspend fun deleteLog(place: Place) {
placeDatabase.placeDao().deleteLog(place)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package campus.tech.kakao.map.data.repository.log

import campus.tech.kakao.map.data.db.entity.Place

interface LogRepositoryInterface {
suspend fun getAllLogs(): List<Place>
suspend fun haveAnyLog(): Boolean
suspend fun insertLog(place: Place)
suspend fun deleteLog(place: Place)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map.repository
package campus.tech.kakao.map.data.repository.map

import android.content.SharedPreferences
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map.repository
package campus.tech.kakao.map.data.repository.map

interface MapRepositoryInterface {
fun getLastLocation(): Pair<Double, Double>?
Expand Down
Loading