Skip to content

Commit 7e85f7d

Browse files
authored
[DONE] clean meal & calendar code
[DONE] clean meal & calendar code
2 parents f7325dc + 0e8c6a6 commit 7e85f7d

File tree

227 files changed

+1495
-1261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+1495
-1261
lines changed

β€Ž.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,5 @@ app/google-services.json
8080
app/release/app-release 3.aab
8181

8282
app/release/app-release 2.aab
83+
84+
.idea/deploymentTargetDropDown.xml

β€Ž.idea/gradle.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žapp/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ plugins {
44
id 'kotlin-kapt'
55
id 'com.google.gms.google-services'
66
}
7-
87
android {
98
compileSdkVersion 30
109
buildToolsVersion "30.0.3"
1110

1211
defaultConfig {
1312
applicationId "com.dms.pmsandroid"
14-
minSdkVersion 23
13+
minSdkVersion 26
1514
targetSdkVersion 30
1615
versionCode 4 //μ—…λ°μ΄νŠΈ ν• λ•Œλ§ˆλ‹€ 1μ”© μ˜¬λ €μ£Όμ„Έμš”
1716
versionName "1.2"
@@ -117,6 +116,7 @@ dependencies {
117116
implementation "androidx.room:room-runtime:$room_version"
118117
implementation "androidx.room:room-rxjava3:$room_version"
119118
kapt("androidx.room:room-compiler:$room_version")
119+
kapt "org.xerial:sqlite-jdbc:3.34.0"
120120
androidTestImplementation "androidx.room:room-testing:2.3.0"
121121
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
122122

@@ -142,5 +142,8 @@ dependencies {
142142

143143
implementation 'com.facebook.shimmer:shimmer:0.5.0'
144144

145+
// mockito
146+
testImplementation 'org.mockito:mockito-core:2.28.2'
147+
145148

146149
}

β€Žapp/src/main/AndroidManifest.xml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
88

99
<application
10-
android:name=".di.PmsApplication"
10+
android:name="com.dms.pmsandroid.presentation.di.PmsApplication"
1111
android:allowBackup="true"
1212
android:icon="@mipmap/ic_launcher"
1313
android:label="@string/app_name"
@@ -16,7 +16,7 @@
1616
android:theme="@style/Theme.PmsAndroid"
1717
android:usesCleartextTraffic="true">
1818
<activity
19-
android:name=".ui.MainActivity"
19+
android:name="com.dms.pmsandroid.presentation.ui.MainActivity"
2020
android:screenOrientation="portrait"
2121
android:theme="@style/SplashTheme"
2222
android:windowSoftInputMode="adjustNothing"
@@ -28,56 +28,56 @@
2828
</intent-filter>
2929
</activity>
3030
<activity
31-
android:name=".feature.mypage.ui.activity.ChangePasswordActivity"
31+
android:name="com.dms.pmsandroid.presentation.feature.mypage.ui.activity.ChangePasswordActivity"
3232
android:exported="true" />
3333
<activity
34-
android:name=".feature.notify.ui.activity.NoticeDetailActivity"
34+
android:name="com.dms.pmsandroid.presentation.feature.notify.ui.activity.NoticeDetailActivity"
3535
android:screenOrientation="portrait"
3636
tools:ignore="LockedOrientationActivity" />
3737
<activity
38-
android:name=".feature.mypage.ui.activity.OutingContentActivity"
38+
android:name="com.dms.pmsandroid.presentation.feature.mypage.ui.activity.OutingContentActivity"
3939
android:screenOrientation="portrait"
40-
android:parentActivityName=".ui.MainActivity"
40+
android:parentActivityName="com.dms.pmsandroid.presentation.ui.MainActivity"
4141
tools:ignore="LockedOrientationActivity" >
4242
<intent-filter>
4343
<action android:name=".feature.mypage.ui.activity.OutingContentActivity"/>
4444
<category android:name="android.intent.category.DEFAULT"/>
4545
</intent-filter>
4646
</activity>
4747
<activity
48-
android:name=".feature.notify.ui.activity.GalleryDetailActivity"
48+
android:name="com.dms.pmsandroid.presentation.feature.notify.ui.activity.GalleryDetailActivity"
4949
android:screenOrientation="portrait"
5050
tools:ignore="LockedOrientationActivity" />
5151
<activity
52-
android:name=".feature.introduce.ui.activity.IntroduceCompanyActivity"
52+
android:name="com.dms.pmsandroid.presentation.feature.introduce.ui.activity.IntroduceCompanyActivity"
5353
android:screenOrientation="portrait"
5454
tools:ignore="LockedOrientationActivity" />
5555
<activity
56-
android:name=".feature.introduce.ui.activity.IntroduceDeveloperActivity"
56+
android:name="com.dms.pmsandroid.presentation.feature.introduce.ui.activity.IntroduceDeveloperActivity"
5757
android:screenOrientation="portrait"
5858
tools:ignore="LockedOrientationActivity" />
5959
<activity
60-
android:name=".feature.login.ui.activity.LoginActivity"
60+
android:name="com.dms.pmsandroid.presentation.feature.login.ui.activity.LoginActivity"
6161
android:screenOrientation="portrait"
6262
tools:ignore="LockedOrientationActivity" />
6363
<activity
64-
android:name=".feature.introduce.ui.activity.IntroduceCompanyDetailActivity"
64+
android:name="com.dms.pmsandroid.presentation.feature.introduce.ui.activity.IntroduceCompanyDetailActivity"
6565
android:screenOrientation="portrait"
6666
tools:ignore="LockedOrientationActivity" />
6767
<activity
68-
android:name=".feature.introduce.ui.activity.IntroduceClubDetailActivity"
68+
android:name="com.dms.pmsandroid.presentation.feature.introduce.ui.activity.IntroduceClubDetailActivity"
6969
android:screenOrientation="portrait"
7070
tools:ignore="LockedOrientationActivity" />
7171
<activity
72-
android:name=".feature.mypage.ui.activity.PointContentActivity"
72+
android:name="com.dms.pmsandroid.presentation.feature.mypage.ui.activity.PointContentActivity"
7373
android:screenOrientation="portrait"
7474
tools:ignore="LockedOrientationActivity" />
7575
<activity
76-
android:name=".feature.introduce.ui.activity.IntroduceClubActivity"
76+
android:name="com.dms.pmsandroid.presentation.feature.introduce.ui.activity.IntroduceClubActivity"
7777
android:screenOrientation="portrait"
7878
tools:ignore="LockedOrientationActivity" />
7979

80-
<service android:name=".feature.fcm.FCMService">
80+
<service android:name="com.dms.pmsandroid.presentation.feature.fcm.FCMService">
8181
<intent-filter>
8282
<action android:name="com.google.firebase.MESSAGING_EVENT" />
8383
</intent-filter>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.dms.pmsandroid.data.calendar
2+
3+
import com.dms.pmsandroid.data.calendar.dto.CalendarResponse
4+
import com.dms.pmsandroid.domain.calendar.entity.EventModel
5+
import com.dms.pmsandroid.domain.calendar.entity.EventTypes
6+
import io.reactivex.rxjava3.core.Single
7+
import java.time.LocalDate
8+
9+
fun CalendarResponse.toEventModel(): Single<MutableMap<LocalDate, EventModel>> = getEventsInResponse(this)
10+
11+
private fun getEventsInResponse(response: CalendarResponse): Single<MutableMap<LocalDate, EventModel>> =
12+
Single.just(HashMap<LocalDate, EventModel>().apply {
13+
putAll(response.janEvents.toEventModelMap())
14+
putAll(response.febEvents.toEventModelMap())
15+
putAll(response.marEvents.toEventModelMap())
16+
putAll(response.aprEvents.toEventModelMap())
17+
putAll(response.mayEvents.toEventModelMap())
18+
putAll(response.junEvents.toEventModelMap())
19+
putAll(response.julEvents.toEventModelMap())
20+
putAll(response.augEvents.toEventModelMap())
21+
putAll(response.sepEvents.toEventModelMap())
22+
putAll(response.octEvents.toEventModelMap())
23+
putAll(response.novEvents.toEventModelMap())
24+
putAll(response.decEvents.toEventModelMap())
25+
})
26+
27+
fun String.toLocalDate():LocalDate =
28+
LocalDate.of(this.substring(0,4).toInt(), this.substring(5,7).toInt(), this.substring(8,10).toInt())
29+
30+
fun List<String>.toEventModel(): EventModel {
31+
val eventTypes = ArrayList<EventTypes>()
32+
val resultEvents = ArrayList<String>()
33+
resultEvents.addAll(this)
34+
resultEvents.removeIf { it == "ν† μš”νœ΄μ—…μΌ" }
35+
for(event in resultEvents) {
36+
eventTypes.add(event.toEventType())
37+
}
38+
return EventModel(resultEvents, eventTypes)
39+
}
40+
41+
private fun Map<String, List<String>>.toEventModelMap() =
42+
this.mapKeys { it.key.toLocalDate() }.mapValues { it.value.toEventModel() }
43+
44+
fun String.toEventType(): EventTypes {
45+
return when (this) {
46+
"μ˜λ¬΄κ·€κ°€" -> {
47+
EventTypes.MUST_GO_HOME
48+
}
49+
50+
"쀑간고사", "기말고사" -> {
51+
EventTypes.EXAM
52+
}
53+
54+
"여름방학", "κ²¨μšΈλ°©ν•™", "여름방학식", "κ²¨μšΈλ°©ν•™μ‹" -> {
55+
EventTypes.VACATION
56+
}
57+
58+
"μ‹ μ •", "어린이날", "석가탄신일", "ν˜„μΆ©μΌ", "κ΄‘λ³΅μ ˆ", "λŒ€μ²΄κ³΅νœ΄μΌ", "μΆ”μ„μ—°νœ΄", "좔석", "개천절", "ν•œκΈ€λ‚ ", "기독탄신일(μ„±νƒ„μ ˆ)" -> {
59+
EventTypes.HOLIDAYS
60+
}
61+
62+
else -> {
63+
EventTypes.ETC
64+
}
65+
}
66+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.dms.pmsandroid.data.calendar.dto
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
data class CalendarResponse(
6+
@SerializedName("1")
7+
val janEvents: Map<String, List<String>>,
8+
9+
@SerializedName("2")
10+
val febEvents: Map<String, List<String>>,
11+
12+
@SerializedName("3")
13+
val marEvents: Map<String, List<String>>,
14+
15+
@SerializedName("4")
16+
val aprEvents: Map<String, List<String>>,
17+
18+
@SerializedName("5")
19+
val mayEvents: Map<String, List<String>>,
20+
21+
@SerializedName("6")
22+
val junEvents: Map<String, List<String>>,
23+
24+
@SerializedName("7")
25+
val julEvents: Map<String, List<String>>,
26+
27+
@SerializedName("8")
28+
val augEvents: Map<String, List<String>>,
29+
30+
@SerializedName("9")
31+
val sepEvents: Map<String, List<String>>,
32+
33+
@SerializedName("10")
34+
val octEvents: Map<String, List<String>>,
35+
36+
@SerializedName("11")
37+
val novEvents: Map<String, List<String>>,
38+
39+
@SerializedName("12")
40+
val decEvents: Map<String, List<String>>
41+
)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
package com.dms.pmsandroid.data.remote.calendar
1+
package com.dms.pmsandroid.data.calendar.remote
22

3+
import com.dms.pmsandroid.data.calendar.dto.CalendarResponse
34
import com.google.gson.JsonObject
45
import io.reactivex.rxjava3.core.Single
56
import retrofit2.Response
@@ -9,6 +10,6 @@ import retrofit2.http.Header
910
interface CalendarApi {
1011

1112
@GET("/calendar")
12-
fun schedules(@Header("Authorization") accessToken: String): Single<Response<JsonObject>>
13+
fun schedules(@Header("Authorization") accessToken: String): Single<Response<CalendarResponse>>
1314

1415
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
package com.dms.pmsandroid.data.remote.calendar
1+
package com.dms.pmsandroid.data.calendar.remote
22

3+
import com.dms.pmsandroid.data.calendar.dto.CalendarResponse
4+
import com.dms.pmsandroid.data.local.SharedPreferenceStorage
35
import com.dms.pmsandroid.data.remote.PotatoChipApi
46
import com.google.gson.JsonObject
57
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
@@ -8,11 +10,11 @@ import io.reactivex.rxjava3.core.Single
810
import io.reactivex.rxjava3.schedulers.Schedulers
911
import retrofit2.Response
1012

11-
class ProvideCalendarApi(api: PotatoChipApi) {
13+
class CalendarRemoteDatasource(api: PotatoChipApi, private val sharedPreferenceStorage: SharedPreferenceStorage) {
1214

1315
private val calendarApi = api.retrofit.create(CalendarApi::class.java)
1416

15-
fun scheduleApi(request: String): @NonNull Single<Response<JsonObject>> = calendarApi.schedules(request)
17+
fun getSchedules(): @NonNull Single<Response<CalendarResponse>> = calendarApi.schedules(sharedPreferenceStorage.getInfo("access_token"))
1618
.observeOn(AndroidSchedulers.mainThread())
1719
.subscribeOn(Schedulers.io())
1820
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.dms.pmsandroid.data.calendar.repository
2+
3+
import com.dms.pmsandroid.data.calendar.remote.CalendarRemoteDatasource
4+
import com.dms.pmsandroid.data.calendar.toEventModel
5+
import com.dms.pmsandroid.data.calendar.toLocalDate
6+
import com.dms.pmsandroid.data.local.room.EventDatabase
7+
import com.dms.pmsandroid.data.local.room.RoomEvents
8+
import com.dms.pmsandroid.domain.calendar.repository.CalendarRepository
9+
import com.dms.pmsandroid.domain.calendar.entity.EventModel
10+
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
11+
import io.reactivex.rxjava3.core.Single
12+
import io.reactivex.rxjava3.schedulers.Schedulers
13+
import kotlinx.coroutines.CoroutineScope
14+
import kotlinx.coroutines.Dispatchers
15+
import kotlinx.coroutines.launch
16+
import java.time.LocalDate
17+
import kotlin.collections.HashMap
18+
19+
class CalendarRepositoryImpl(
20+
private val calendarRemoteDatasource: CalendarRemoteDatasource,
21+
private val eventDatabase: EventDatabase
22+
) : CalendarRepository {
23+
override fun getEvents(): Single<Map<LocalDate, EventModel>> =
24+
getSchedulesAtServerOrLocal()
25+
26+
private fun getSchedulesAtServerOrLocal(): Single<Map<LocalDate, EventModel>> =
27+
calendarRemoteDatasource.getSchedules()
28+
.observeOn(AndroidSchedulers.mainThread())
29+
.subscribeOn(Schedulers.io())
30+
.flatMap { response ->
31+
if (response.isSuccessful && response.body() != null) {
32+
val result = response.body()!!.toEventModel()
33+
result.subscribe { event ->
34+
CoroutineScope(Dispatchers.IO).launch {
35+
eventDatabase.eventDao().run {
36+
deleteEvents()
37+
insertEvent(event.map {
38+
RoomEvents(
39+
it.key.toString(),
40+
it.value.eventNames
41+
)
42+
})
43+
}
44+
}
45+
}
46+
return@flatMap result
47+
} else {
48+
getSchedulesAtLocal()
49+
}
50+
}.onErrorResumeNext {
51+
getSchedulesAtLocal()
52+
}
53+
54+
private fun getSchedulesAtLocal(): Single<Map<LocalDate, EventModel>> =
55+
eventDatabase.eventDao().getLocalEvent()
56+
.observeOn(AndroidSchedulers.mainThread())
57+
.subscribeOn(Schedulers.io())
58+
.map {
59+
val filteredList = it.filter { it.events.isNotEmpty() }
60+
HashMap<LocalDate, EventModel>().apply {
61+
for (event in filteredList) {
62+
put(event.date.toLocalDate(), event.events.toEventModel())
63+
}
64+
}
65+
}
66+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.dms.pmsandroid.data.introduce.remote
2+
3+
import com.dms.pmsandroid.presentation.feature.introduce.model.ClubDetailModel
4+
import com.dms.pmsandroid.presentation.feature.introduce.model.ClubListModel
5+
import io.reactivex.rxjava3.core.Single
6+
import retrofit2.Response
7+
import retrofit2.http.*
8+
import retrofit2.http.GET
9+
import retrofit2.http.Header
10+
import retrofit2.http.Path
11+
12+
interface IntroduceClubApi {
13+
@GET("/introduce/clubs")
14+
fun club(
15+
@Header("Authorization") accessToken: String
16+
): Single<Response<ClubListModel>>
17+
18+
19+
@GET("/introduce/clubs/{clubname}")
20+
fun clubDetail(
21+
@Header("Authorization")accessToken: String,
22+
@Path("clubname")clubname:String
23+
): Single<Response<ClubDetailModel>>
24+
}

β€Žapp/src/main/java/com/dms/pmsandroid/data/remote/introduce/ProvideIntroduceClubApi.kt renamed to β€Žapp/src/main/java/com/dms/pmsandroid/data/introduce/remote/ProvideIntroduceClubApi.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package com.dms.pmsandroid.data.remote.introduce
1+
package com.dms.pmsandroid.data.introduce.remote
22

33
import com.dms.pmsandroid.data.remote.PotatoChipApi
4-
import com.dms.pmsandroid.feature.introduce.model.ClubDetailModel
5-
import com.dms.pmsandroid.feature.introduce.model.ClubListModel
4+
import com.dms.pmsandroid.presentation.feature.introduce.model.ClubDetailModel
5+
import com.dms.pmsandroid.presentation.feature.introduce.model.ClubListModel
66
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
77
import io.reactivex.rxjava3.annotations.NonNull
88
import io.reactivex.rxjava3.core.Single

0 commit comments

Comments
Β (0)