Skip to content

Commit

Permalink
[DONE] clean meal & calendar code
Browse files Browse the repository at this point in the history
[DONE] clean meal & calendar code
  • Loading branch information
JaewonKim04 authored Mar 10, 2022
2 parents f7325dc + 0e8c6a6 commit 7e85f7d
Show file tree
Hide file tree
Showing 227 changed files with 1,495 additions and 1,261 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ app/google-services.json
app/release/app-release 3.aab

app/release/app-release 2.aab

.idea/deploymentTargetDropDown.xml
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ plugins {
id 'kotlin-kapt'
id 'com.google.gms.google-services'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

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

Expand All @@ -142,5 +142,8 @@ dependencies {

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

// mockito
testImplementation 'org.mockito:mockito-core:2.28.2'


}
30 changes: 15 additions & 15 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:name=".di.PmsApplication"
android:name="com.dms.pmsandroid.presentation.di.PmsApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand All @@ -16,7 +16,7 @@
android:theme="@style/Theme.PmsAndroid"
android:usesCleartextTraffic="true">
<activity
android:name=".ui.MainActivity"
android:name="com.dms.pmsandroid.presentation.ui.MainActivity"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme"
android:windowSoftInputMode="adjustNothing"
Expand All @@ -28,56 +28,56 @@
</intent-filter>
</activity>
<activity
android:name=".feature.mypage.ui.activity.ChangePasswordActivity"
android:name="com.dms.pmsandroid.presentation.feature.mypage.ui.activity.ChangePasswordActivity"
android:exported="true" />
<activity
android:name=".feature.notify.ui.activity.NoticeDetailActivity"
android:name="com.dms.pmsandroid.presentation.feature.notify.ui.activity.NoticeDetailActivity"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".feature.mypage.ui.activity.OutingContentActivity"
android:name="com.dms.pmsandroid.presentation.feature.mypage.ui.activity.OutingContentActivity"
android:screenOrientation="portrait"
android:parentActivityName=".ui.MainActivity"
android:parentActivityName="com.dms.pmsandroid.presentation.ui.MainActivity"
tools:ignore="LockedOrientationActivity" >
<intent-filter>
<action android:name=".feature.mypage.ui.activity.OutingContentActivity"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".feature.notify.ui.activity.GalleryDetailActivity"
android:name="com.dms.pmsandroid.presentation.feature.notify.ui.activity.GalleryDetailActivity"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".feature.introduce.ui.activity.IntroduceCompanyActivity"
android:name="com.dms.pmsandroid.presentation.feature.introduce.ui.activity.IntroduceCompanyActivity"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".feature.introduce.ui.activity.IntroduceDeveloperActivity"
android:name="com.dms.pmsandroid.presentation.feature.introduce.ui.activity.IntroduceDeveloperActivity"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".feature.login.ui.activity.LoginActivity"
android:name="com.dms.pmsandroid.presentation.feature.login.ui.activity.LoginActivity"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".feature.introduce.ui.activity.IntroduceCompanyDetailActivity"
android:name="com.dms.pmsandroid.presentation.feature.introduce.ui.activity.IntroduceCompanyDetailActivity"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".feature.introduce.ui.activity.IntroduceClubDetailActivity"
android:name="com.dms.pmsandroid.presentation.feature.introduce.ui.activity.IntroduceClubDetailActivity"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".feature.mypage.ui.activity.PointContentActivity"
android:name="com.dms.pmsandroid.presentation.feature.mypage.ui.activity.PointContentActivity"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".feature.introduce.ui.activity.IntroduceClubActivity"
android:name="com.dms.pmsandroid.presentation.feature.introduce.ui.activity.IntroduceClubActivity"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />

<service android:name=".feature.fcm.FCMService">
<service android:name="com.dms.pmsandroid.presentation.feature.fcm.FCMService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.dms.pmsandroid.data.calendar

import com.dms.pmsandroid.data.calendar.dto.CalendarResponse
import com.dms.pmsandroid.domain.calendar.entity.EventModel
import com.dms.pmsandroid.domain.calendar.entity.EventTypes
import io.reactivex.rxjava3.core.Single
import java.time.LocalDate

fun CalendarResponse.toEventModel(): Single<MutableMap<LocalDate, EventModel>> = getEventsInResponse(this)

private fun getEventsInResponse(response: CalendarResponse): Single<MutableMap<LocalDate, EventModel>> =
Single.just(HashMap<LocalDate, EventModel>().apply {
putAll(response.janEvents.toEventModelMap())
putAll(response.febEvents.toEventModelMap())
putAll(response.marEvents.toEventModelMap())
putAll(response.aprEvents.toEventModelMap())
putAll(response.mayEvents.toEventModelMap())
putAll(response.junEvents.toEventModelMap())
putAll(response.julEvents.toEventModelMap())
putAll(response.augEvents.toEventModelMap())
putAll(response.sepEvents.toEventModelMap())
putAll(response.octEvents.toEventModelMap())
putAll(response.novEvents.toEventModelMap())
putAll(response.decEvents.toEventModelMap())
})

fun String.toLocalDate():LocalDate =
LocalDate.of(this.substring(0,4).toInt(), this.substring(5,7).toInt(), this.substring(8,10).toInt())

fun List<String>.toEventModel(): EventModel {
val eventTypes = ArrayList<EventTypes>()
val resultEvents = ArrayList<String>()
resultEvents.addAll(this)
resultEvents.removeIf { it == "ν† μš”νœ΄μ—…μΌ" }
for(event in resultEvents) {
eventTypes.add(event.toEventType())
}
return EventModel(resultEvents, eventTypes)
}

private fun Map<String, List<String>>.toEventModelMap() =
this.mapKeys { it.key.toLocalDate() }.mapValues { it.value.toEventModel() }

fun String.toEventType(): EventTypes {
return when (this) {
"μ˜λ¬΄κ·€κ°€" -> {
EventTypes.MUST_GO_HOME
}

"쀑간고사", "기말고사" -> {
EventTypes.EXAM
}

"여름방학", "κ²¨μšΈλ°©ν•™", "여름방학식", "κ²¨μšΈλ°©ν•™μ‹" -> {
EventTypes.VACATION
}

"μ‹ μ •", "어린이날", "석가탄신일", "ν˜„μΆ©μΌ", "κ΄‘λ³΅μ ˆ", "λŒ€μ²΄κ³΅νœ΄μΌ", "μΆ”μ„μ—°νœ΄", "좔석", "개천절", "ν•œκΈ€λ‚ ", "기독탄신일(μ„±νƒ„μ ˆ)" -> {
EventTypes.HOLIDAYS
}

else -> {
EventTypes.ETC
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.dms.pmsandroid.data.calendar.dto

import com.google.gson.annotations.SerializedName

data class CalendarResponse(
@SerializedName("1")
val janEvents: Map<String, List<String>>,

@SerializedName("2")
val febEvents: Map<String, List<String>>,

@SerializedName("3")
val marEvents: Map<String, List<String>>,

@SerializedName("4")
val aprEvents: Map<String, List<String>>,

@SerializedName("5")
val mayEvents: Map<String, List<String>>,

@SerializedName("6")
val junEvents: Map<String, List<String>>,

@SerializedName("7")
val julEvents: Map<String, List<String>>,

@SerializedName("8")
val augEvents: Map<String, List<String>>,

@SerializedName("9")
val sepEvents: Map<String, List<String>>,

@SerializedName("10")
val octEvents: Map<String, List<String>>,

@SerializedName("11")
val novEvents: Map<String, List<String>>,

@SerializedName("12")
val decEvents: Map<String, List<String>>
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dms.pmsandroid.data.remote.calendar
package com.dms.pmsandroid.data.calendar.remote

import com.dms.pmsandroid.data.calendar.dto.CalendarResponse
import com.google.gson.JsonObject
import io.reactivex.rxjava3.core.Single
import retrofit2.Response
Expand All @@ -9,6 +10,6 @@ import retrofit2.http.Header
interface CalendarApi {

@GET("/calendar")
fun schedules(@Header("Authorization") accessToken: String): Single<Response<JsonObject>>
fun schedules(@Header("Authorization") accessToken: String): Single<Response<CalendarResponse>>

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

import com.dms.pmsandroid.data.calendar.dto.CalendarResponse
import com.dms.pmsandroid.data.local.SharedPreferenceStorage
import com.dms.pmsandroid.data.remote.PotatoChipApi
import com.google.gson.JsonObject
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
Expand All @@ -8,11 +10,11 @@ import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.schedulers.Schedulers
import retrofit2.Response

class ProvideCalendarApi(api: PotatoChipApi) {
class CalendarRemoteDatasource(api: PotatoChipApi, private val sharedPreferenceStorage: SharedPreferenceStorage) {

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

fun scheduleApi(request: String): @NonNull Single<Response<JsonObject>> = calendarApi.schedules(request)
fun getSchedules(): @NonNull Single<Response<CalendarResponse>> = calendarApi.schedules(sharedPreferenceStorage.getInfo("access_token"))
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.dms.pmsandroid.data.calendar.repository

import com.dms.pmsandroid.data.calendar.remote.CalendarRemoteDatasource
import com.dms.pmsandroid.data.calendar.toEventModel
import com.dms.pmsandroid.data.calendar.toLocalDate
import com.dms.pmsandroid.data.local.room.EventDatabase
import com.dms.pmsandroid.data.local.room.RoomEvents
import com.dms.pmsandroid.domain.calendar.repository.CalendarRepository
import com.dms.pmsandroid.domain.calendar.entity.EventModel
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.schedulers.Schedulers
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.time.LocalDate
import kotlin.collections.HashMap

class CalendarRepositoryImpl(
private val calendarRemoteDatasource: CalendarRemoteDatasource,
private val eventDatabase: EventDatabase
) : CalendarRepository {
override fun getEvents(): Single<Map<LocalDate, EventModel>> =
getSchedulesAtServerOrLocal()

private fun getSchedulesAtServerOrLocal(): Single<Map<LocalDate, EventModel>> =
calendarRemoteDatasource.getSchedules()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.flatMap { response ->
if (response.isSuccessful && response.body() != null) {
val result = response.body()!!.toEventModel()
result.subscribe { event ->
CoroutineScope(Dispatchers.IO).launch {
eventDatabase.eventDao().run {
deleteEvents()
insertEvent(event.map {
RoomEvents(
it.key.toString(),
it.value.eventNames
)
})
}
}
}
return@flatMap result
} else {
getSchedulesAtLocal()
}
}.onErrorResumeNext {
getSchedulesAtLocal()
}

private fun getSchedulesAtLocal(): Single<Map<LocalDate, EventModel>> =
eventDatabase.eventDao().getLocalEvent()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.map {
val filteredList = it.filter { it.events.isNotEmpty() }
HashMap<LocalDate, EventModel>().apply {
for (event in filteredList) {
put(event.date.toLocalDate(), event.events.toEventModel())
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.dms.pmsandroid.data.introduce.remote

import com.dms.pmsandroid.presentation.feature.introduce.model.ClubDetailModel
import com.dms.pmsandroid.presentation.feature.introduce.model.ClubListModel
import io.reactivex.rxjava3.core.Single
import retrofit2.Response
import retrofit2.http.*
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Path

interface IntroduceClubApi {
@GET("/introduce/clubs")
fun club(
@Header("Authorization") accessToken: String
): Single<Response<ClubListModel>>


@GET("/introduce/clubs/{clubname}")
fun clubDetail(
@Header("Authorization")accessToken: String,
@Path("clubname")clubname:String
): Single<Response<ClubDetailModel>>
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.dms.pmsandroid.data.remote.introduce
package com.dms.pmsandroid.data.introduce.remote

import com.dms.pmsandroid.data.remote.PotatoChipApi
import com.dms.pmsandroid.feature.introduce.model.ClubDetailModel
import com.dms.pmsandroid.feature.introduce.model.ClubListModel
import com.dms.pmsandroid.presentation.feature.introduce.model.ClubDetailModel
import com.dms.pmsandroid.presentation.feature.introduce.model.ClubListModel
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.annotations.NonNull
import io.reactivex.rxjava3.core.Single
Expand Down
Loading

0 comments on commit 7e85f7d

Please sign in to comment.