From 87c4d304c9d1b843f36a2082a9b8b64c72495883 Mon Sep 17 00:00:00 2001 From: LeeHaiLim Date: Tue, 12 Dec 2023 01:59:19 +0900 Subject: [PATCH 1/8] =?UTF-8?q?enhancement:=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=ED=81=B4=EB=A6=AD=20=EC=8B=9C=20=EC=8B=9C?= =?UTF-8?q?=EC=8A=A4=ED=85=9C=20=EC=95=B1=20=EC=95=8C=EB=A6=BC=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=ED=99=94=EB=A9=B4=EC=9C=BC=EB=A1=9C=20=EC=A0=84?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/local/datastore/DataStoreHelper.kt | 21 +----- .../data/repository/SettingRepository.kt | 17 ----- .../data/repository/UserRepository.kt | 1 - .../data/repository/di/RepositoryModule.kt | 7 -- .../setting/alarm/SettingAlarmFragment.kt | 30 --------- .../setting/alarm/SettingAlarmViewModel.kt | 40 ----------- .../setting/home/SettingHomeFragment.kt | 18 ++++- .../res/layout/fragment_setting_alarm.xml | 66 ------------------- .../main/res/navigation/nav_graph_setting.xml | 8 --- android/app/src/main/res/values/strings.xml | 1 + 10 files changed, 17 insertions(+), 192 deletions(-) delete mode 100644 android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/SettingRepository.kt delete mode 100644 android/app/src/main/java/com/teameetmeet/meetmeet/presentation/setting/alarm/SettingAlarmFragment.kt delete mode 100644 android/app/src/main/java/com/teameetmeet/meetmeet/presentation/setting/alarm/SettingAlarmViewModel.kt delete mode 100644 android/app/src/main/res/layout/fragment_setting_alarm.xml diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/data/local/datastore/DataStoreHelper.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/data/local/datastore/DataStoreHelper.kt index fe50dc4..606aebd 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/data/local/datastore/DataStoreHelper.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/data/local/datastore/DataStoreHelper.kt @@ -2,7 +2,6 @@ package com.teameetmeet.meetmeet.data.local.datastore import androidx.datastore.core.DataStore import androidx.datastore.preferences.core.Preferences -import androidx.datastore.preferences.core.booleanPreferencesKey import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.core.stringPreferencesKey import com.teameetmeet.meetmeet.data.NoDataException @@ -25,7 +24,7 @@ class DataStoreHelper @Inject constructor( fun getAppToken(): Flow = dataStore.data.map { it[ACCESS_TOKEN] } - fun getRefreshToken(): Flow = dataStore.data.map {it[REFRESH_TOKEN]} + fun getRefreshToken(): Flow = dataStore.data.map { it[REFRESH_TOKEN] } suspend fun fetchUserProfile(userProfile: UserProfile) { dataStore.edit { @@ -50,23 +49,6 @@ class DataStoreHelper @Inject constructor( } } - fun getAlarmState(): Flow { - return dataStore.data - .map { it[IS_PUSH_ALARM_ON] ?: true } - } - - suspend fun storeAlarmState(isOn: Boolean) { - dataStore.edit { - it[IS_PUSH_ALARM_ON] = isOn - } - } - - suspend fun resetAlarmState() { - dataStore.edit { - it[IS_PUSH_ALARM_ON] = true - } - } - suspend fun deleteAppToken() { dataStore.edit { it[ACCESS_TOKEN] = "" @@ -88,6 +70,5 @@ class DataStoreHelper @Inject constructor( val USER_PROFILE_IMAGE = stringPreferencesKey("userProfileImage") val USER_NICKNAME = stringPreferencesKey("userNickName") val USER_EMAIL = stringPreferencesKey("userEmail") - val IS_PUSH_ALARM_ON = booleanPreferencesKey("isPushAlarmOn") } } \ No newline at end of file diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/SettingRepository.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/SettingRepository.kt deleted file mode 100644 index 86c3889..0000000 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/SettingRepository.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.teameetmeet.meetmeet.data.repository - -import com.teameetmeet.meetmeet.data.local.datastore.DataStoreHelper -import kotlinx.coroutines.flow.Flow -import javax.inject.Inject - -class SettingRepository @Inject constructor( - private val dataStore: DataStoreHelper -) { - fun getAlarmState(): Flow { - return dataStore.getAlarmState() - } - - suspend fun storeAlarmState(isOn: Boolean) { - dataStore.storeAlarmState(isOn) - } -} \ No newline at end of file diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/UserRepository.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/UserRepository.kt index 2688d28..bb26640 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/UserRepository.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/UserRepository.kt @@ -89,7 +89,6 @@ class UserRepository @Inject constructor( fun resetDataStore(): Flow { return flowOf(true) .map { - dataStore.resetAlarmState() dataStore.deleteUserProfile() dataStore.deleteAppToken() }.catch { diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/di/RepositoryModule.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/di/RepositoryModule.kt index 31cf23d..4200cae 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/di/RepositoryModule.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/di/RepositoryModule.kt @@ -12,7 +12,6 @@ import com.teameetmeet.meetmeet.data.repository.CalendarRepository import com.teameetmeet.meetmeet.data.repository.EventStoryRepository import com.teameetmeet.meetmeet.data.repository.FollowRepository import com.teameetmeet.meetmeet.data.repository.LoginRepository -import com.teameetmeet.meetmeet.data.repository.SettingRepository import com.teameetmeet.meetmeet.data.repository.TokenRepository import com.teameetmeet.meetmeet.data.repository.UserRepository import dagger.Module @@ -54,12 +53,6 @@ class RepositoryModule { dataStore: DataStoreHelper ) = EventStoryRepository(eventStoryApi, dataStore) - @Singleton - @Provides - fun provideSettingRepository( - dataStore: DataStoreHelper - ) = SettingRepository(dataStore) - @Singleton @Provides fun provideTokenRepository( diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/setting/alarm/SettingAlarmFragment.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/setting/alarm/SettingAlarmFragment.kt deleted file mode 100644 index a4bb524..0000000 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/setting/alarm/SettingAlarmFragment.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.teameetmeet.meetmeet.presentation.setting.alarm - -import android.os.Bundle -import android.view.View -import androidx.fragment.app.viewModels -import androidx.navigation.fragment.findNavController -import com.teameetmeet.meetmeet.R -import com.teameetmeet.meetmeet.databinding.FragmentSettingAlarmBinding -import com.teameetmeet.meetmeet.presentation.base.BaseFragment -import dagger.hilt.android.AndroidEntryPoint - -@AndroidEntryPoint -class SettingAlarmFragment : BaseFragment( - R.layout.fragment_setting_alarm -) { - private val viewModel: SettingAlarmViewModel by viewModels() - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - binding.vm = viewModel - setTopAppBar() - } - - private fun setTopAppBar() { - binding.topAppBar.setNavigationOnClickListener { - findNavController().popBackStack() - } - } -} \ No newline at end of file diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/setting/alarm/SettingAlarmViewModel.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/setting/alarm/SettingAlarmViewModel.kt deleted file mode 100644 index b3b5413..0000000 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/setting/alarm/SettingAlarmViewModel.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.teameetmeet.meetmeet.presentation.setting.alarm - -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import com.teameetmeet.meetmeet.data.repository.SettingRepository -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.collectLatest -import kotlinx.coroutines.launch -import javax.inject.Inject - -@HiltViewModel -class SettingAlarmViewModel @Inject constructor( - private val settingRepository: SettingRepository -) : ViewModel() { - private val _isPushAlarmOn = MutableStateFlow(true) - val isPushAlarmOn: StateFlow = _isPushAlarmOn - - init { - getStoredAlarmState() - } - - private fun getStoredAlarmState() { - viewModelScope.launch(Dispatchers.IO) { - settingRepository - .getAlarmState() - .collectLatest { - _isPushAlarmOn.emit(it) - } - } - } - - fun changeAlarmState(isOn: Boolean) { - viewModelScope.launch { - settingRepository.storeAlarmState(isOn) - } - } -} \ No newline at end of file diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/setting/home/SettingHomeFragment.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/setting/home/SettingHomeFragment.kt index 890b20b..3274291 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/setting/home/SettingHomeFragment.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/setting/home/SettingHomeFragment.kt @@ -1,6 +1,8 @@ package com.teameetmeet.meetmeet.presentation.setting.home +import android.content.Intent import android.os.Bundle +import android.provider.Settings import android.view.View import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle @@ -48,9 +50,19 @@ class SettingHomeFragment : ) } binding.settingHomeBtnAlarmSetting.setOnClickListener { - findNavController().navigate( - SettingHomeFragmentDirections.actionSettingHomeFragmentToSettingAlarmFragment() - ) + navigateToNotificationSetting() + } + } + + private fun navigateToNotificationSetting() { + val intent = Intent().apply { + action = Settings.ACTION_APP_NOTIFICATION_SETTINGS + putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName) + } + try { + startActivity(intent) + } catch (e: Exception) { + showMessage(R.string.setting_notification_navigate_fail, e.message.orEmpty()) } } diff --git a/android/app/src/main/res/layout/fragment_setting_alarm.xml b/android/app/src/main/res/layout/fragment_setting_alarm.xml deleted file mode 100644 index 0eba3f4..0000000 --- a/android/app/src/main/res/layout/fragment_setting_alarm.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/android/app/src/main/res/navigation/nav_graph_setting.xml b/android/app/src/main/res/navigation/nav_graph_setting.xml index 9bf8738..d27cb4d 100644 --- a/android/app/src/main/res/navigation/nav_graph_setting.xml +++ b/android/app/src/main/res/navigation/nav_graph_setting.xml @@ -16,9 +16,6 @@ - @@ -40,11 +37,6 @@ android:name="com.teameetmeet.meetmeet.presentation.setting.profile.SettingProfileFragment" android:label="setting_profile_fragment" tools:layout="@layout/fragment_setting_profile" /> - Hello blank fragment 로그아웃 실패 반복 주기와 종료일을 모두 선택해주세요. + 알림 설정에 접근할 수 없습니다. \ No newline at end of file From 8c660a7312e49b2b3b3a7f1e068d65db5fdee3a9 Mon Sep 17 00:00:00 2001 From: LeeHaiLim Date: Tue, 12 Dec 2023 02:05:10 +0900 Subject: [PATCH 2/8] =?UTF-8?q?enhancement:=20flow=20=EB=82=B4=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=ED=95=A0=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/repository/CalendarRepository.kt | 43 +++++++++++-------- .../data/repository/TokenRepository.kt | 2 +- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/CalendarRepository.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/CalendarRepository.kt index 3ca0410..60da1de 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/CalendarRepository.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/CalendarRepository.kt @@ -14,7 +14,10 @@ import com.teameetmeet.meetmeet.util.date.DateTimeFormat import com.teameetmeet.meetmeet.util.date.toDateString import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.onEach +import java.net.UnknownHostException import java.time.ZoneId import javax.inject.Inject @@ -22,12 +25,25 @@ class CalendarRepository @Inject constructor( private val localCalendarDataSource: LocalCalendarDataSource, private val remoteCalendarDataSource: RemoteCalendarDataSource ) { - suspend fun getEvents(startDate: Long, endDate: Long): Flow> { - try { - syncEvents(startDate, endDate) - } finally { - return localCalendarDataSource.getEvents(startDate, endDate) - } + fun getSyncedEvents(startDateTime: Long, endDateTime: Long): Flow> { + return remoteCalendarDataSource + .getEvents( + startDateTime.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC")), + endDateTime.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC")) + ).onEach { + localCalendarDataSource.deleteEvents(startDateTime, endDateTime) + localCalendarDataSource.insertEvents(it.map(EventResponse::toEvent)) + }.map { + localCalendarDataSource.getEvents(startDateTime, endDateTime).first() + }.catch { + when (it) { + is UnknownHostException -> { + emit(localCalendarDataSource.getEvents(startDateTime, endDateTime).first()) + } + + else -> throw it.toException() + } + } } fun getEventsByUserId(userId: Int, startDate: Long, endDate: Long): Flow> { @@ -82,19 +98,8 @@ class CalendarRepository @Inject constructor( endDate: String ): Flow> { return remoteCalendarDataSource.searchEvents(keyword, startDate, endDate) - } - - private suspend fun syncEvents(startDateTime: Long, endDateTime: Long) { - remoteCalendarDataSource - .getEvents( - startDateTime.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC")), - endDateTime.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC")) - ).catch { - //todo: 예외처리 - throw it - }.collect { - localCalendarDataSource.deleteEvents(startDateTime, endDateTime) - localCalendarDataSource.insertEvents(it.map(EventResponse::toEvent)) + .catch { + throw it.toException() } } } \ No newline at end of file diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/TokenRepository.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/TokenRepository.kt index 286a21e..719577a 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/TokenRepository.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/TokenRepository.kt @@ -38,7 +38,7 @@ class TokenRepository @Inject constructor( is HttpException -> { if(it.code() == 418) { val token = refreshAccessToken() - autoLoginApp(token) + emit(autoLoginApp(token).first()) } else { throw it } From 39142eb759b6005b737511d8750fb34acca542d0 Mon Sep 17 00:00:00 2001 From: LeeHaiLim Date: Tue, 12 Dec 2023 02:41:52 +0900 Subject: [PATCH 3/8] =?UTF-8?q?chore:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasource/LocalCalendarDataSource.kt | 17 ----------------- .../data/local/database/dao/EventDao.kt | 18 ------------------ 2 files changed, 35 deletions(-) diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/data/datasource/LocalCalendarDataSource.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/data/datasource/LocalCalendarDataSource.kt index 0118514..80ad49a 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/data/datasource/LocalCalendarDataSource.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/data/datasource/LocalCalendarDataSource.kt @@ -8,9 +8,6 @@ import kotlinx.coroutines.flow.map import javax.inject.Inject class LocalCalendarDataSource @Inject constructor(private val dao: EventDao) { - fun get(id: Int): Flow { - return dao.get(id) - } fun getEvents(startDateTime: Long, endDateTime: Long): Flow> { return flowOf(true).map { dao.getEvents(startDateTime, endDateTime) } @@ -40,18 +37,4 @@ class LocalCalendarDataSource @Inject constructor(private val dao: EventDao) { dao.deleteEvents(startDateTime, endDateTime) } - suspend fun updateEventAttr( - id: Int, - title: String? = null, - startDateTime: Long? = null, - endDateTime: Long? = null, - color: String? = null, - notification: String? = null - ) { - title?.let { title -> dao.updateTitle(id, title) } - startDateTime?.let { startDateLong -> dao.updateStartDateTime(id, startDateLong) } - endDateTime?.let { endDateLong -> dao.updateEndDateTime(id, endDateLong) } - color?.let { color -> dao.updateTitle(id, color) } - notification?.let { notification -> dao.updateTitle(id, notification) } - } } \ No newline at end of file diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/data/local/database/dao/EventDao.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/data/local/database/dao/EventDao.kt index a978abf..ee015f4 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/data/local/database/dao/EventDao.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/data/local/database/dao/EventDao.kt @@ -29,24 +29,6 @@ interface EventDao { @Query("DELETE FROM Event WHERE endDateTime >= :startDateTime AND startDateTime <= :endDateTime") suspend fun deleteEvents(startDateTime: Long, endDateTime: Long) - @Query("SELECT * FROM Event WHERE id = :id") - fun get(id: Int): Flow - @Query("SELECT * FROM Event WHERE endDateTime >= :startDateTime AND startDateTime <= :endDateTime") suspend fun getEvents(startDateTime: Long, endDateTime: Long): List - - @Query("UPDATE Event SET title = :title WHERE id = :id ") - suspend fun updateTitle(id: Int, title: String) - - @Query("UPDATE Event SET startDateTime = :startDateTime WHERE id = :id ") - suspend fun updateStartDateTime(id: Int, startDateTime: Long) - - @Query("UPDATE Event SET endDateTime = :endDateTime WHERE id = :id ") - suspend fun updateEndDateTime(id: Int, endDateTime: Long) - - @Query("UPDATE Event SET color = :color WHERE id = :id ") - suspend fun updateColor(id: Int, color: String) - - @Query("UPDATE Event SET notification = :notification WHERE id = :id ") - suspend fun updateNotification(id: Int, notification: String) } \ No newline at end of file From 5207666a5ac0c94b024a018ef4953b7b41141632 Mon Sep 17 00:00:00 2001 From: LeeHaiLim Date: Tue, 12 Dec 2023 02:44:29 +0900 Subject: [PATCH 4/8] =?UTF-8?q?feat:=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EB=A0=88=EC=9D=B4=EC=96=B4=20=EC=98=88=EC=99=B8=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datasource/RemoteCalendarDataSource.kt | 35 ++-------- .../data/repository/CalendarRepository.kt | 19 ++--- .../data/repository/EventStoryRepository.kt | 69 +++++++++---------- 3 files changed, 49 insertions(+), 74 deletions(-) diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/data/datasource/RemoteCalendarDataSource.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/data/datasource/RemoteCalendarDataSource.kt index 7cc21ec..eff6173 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/data/datasource/RemoteCalendarDataSource.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/data/datasource/RemoteCalendarDataSource.kt @@ -4,24 +4,14 @@ import com.teameetmeet.meetmeet.data.network.api.CalendarApi import com.teameetmeet.meetmeet.data.network.entity.AddEventRequest import com.teameetmeet.meetmeet.data.network.entity.EventResponse import com.teameetmeet.meetmeet.data.network.entity.UserEventResponse -import com.teameetmeet.meetmeet.data.toException import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import javax.inject.Inject class RemoteCalendarDataSource @Inject constructor(private val api: CalendarApi) { fun getEvents(startDate: String, endDate: String): Flow> { - return flowOf(true) - .map { - val result = api.getEvents(startDate, endDate).events - result - } - .catch { - throw it - //todo: 예외 처리 - } + return flowOf(true).map { api.getEvents(startDate, endDate).events } } fun getEventsByUserId( @@ -29,14 +19,7 @@ class RemoteCalendarDataSource @Inject constructor(private val api: CalendarApi) startDate: String, endDate: String ): Flow> { - return flowOf(true) - .map { - val result = api.getEventsByUserId(userId, startDate, endDate).events - result - } - .catch { - throw it.toException() - } + return flowOf(true).map { api.getEventsByUserId(userId, startDate, endDate).events } } fun searchEvents( @@ -44,20 +27,10 @@ class RemoteCalendarDataSource @Inject constructor(private val api: CalendarApi) startDate: String, endDate: String ): Flow> { - return flowOf(true) - .map { api.searchEvents(keyword, startDate, endDate).events } - .catch { - throw it - //todo: 예외 처리 - } + return flowOf(true).map { api.searchEvents(keyword, startDate, endDate).events } } fun addEvent(addEventRequest: AddEventRequest): Flow> { - return flowOf(true) - .map { - api.addEvent(addEventRequest).events - }.catch { - throw it - } + return flowOf(true).map { api.addEvent(addEventRequest).events } } } \ No newline at end of file diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/CalendarRepository.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/CalendarRepository.kt index 60da1de..7a11d55 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/CalendarRepository.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/CalendarRepository.kt @@ -46,14 +46,17 @@ class CalendarRepository @Inject constructor( } } - fun getEventsByUserId(userId: Int, startDate: Long, endDate: Long): Flow> { - return remoteCalendarDataSource.getEventsByUserId( - userId, - startDate.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC")), - endDate.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC")) - ).map { - it.map(UserEventResponse::toEvent) - } + fun getEventsByUserId(userId: Int, startDateTime: Long, endDateTime: Long): Flow> { + return remoteCalendarDataSource + .getEventsByUserId( + userId, + startDateTime.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC")), + endDateTime.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC")) + ).map { + it.map(UserEventResponse::toEvent) + }.catch { + throw it.toException() + } } suspend fun deleteEvents() { diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/EventStoryRepository.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/EventStoryRepository.kt index 5a583a9..7fafa77 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/EventStoryRepository.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/EventStoryRepository.kt @@ -115,7 +115,6 @@ class EventStoryRepository @Inject constructor( val contents = media?.map { uri -> val file = uri.toAbsolutePath()?.let { File(it) } ?: return@map null val type = uri.getMimeType() ?: return@map null - println(type.toMediaType().toString()) MultipartBody.Part.createFormData( "contents", file.name, file.asRequestBody(type.toMediaType()) ) @@ -126,7 +125,7 @@ class EventStoryRepository @Inject constructor( contents ) }.catch { - throw it + throw it.toException() } } @@ -139,49 +138,49 @@ class EventStoryRepository @Inject constructor( } fun getFeedDetail(feedId: Int): Flow { - return flowOf(true).map { - val userNickname = dataStore.getUserProfile().first().nickname - eventStoryApi.getFeedDetail(feedId).let { feed -> - feed.copy( - isMine = userNickname == feed.author.nickname, - comments = feed.comments.map { comment -> - comment.copy( - isMine = comment.author.nickname == userNickname - ) - } - ) + return flowOf(true) + .map { + val userNickname = dataStore.getUserProfile().first().nickname + eventStoryApi.getFeedDetail(feedId).let { feed -> + feed.copy( + isMine = userNickname == feed.author.nickname, + comments = feed.comments.map { comment -> + comment.copy(isMine = comment.author.nickname == userNickname) + } + ) + } + }.catch { + throw it.toException() } - }.catch { - //todo: 예외처리 - throw it - } } fun deleteFeed(feedId: Int): Flow { - return flowOf(true).map { - eventStoryApi.deleteFeed(feedId) - }.catch { - throw it.toException() - } + return flowOf(true) + .map { + eventStoryApi.deleteFeed(feedId) + }.catch { + throw it.toException() + } } fun addFeedComment(feedId: Int, memo: String): Flow { - return flowOf(true).map { - eventStoryApi.addFeedComment( - feedId, AddFeedCommentRequest(memo) - ) - }.catch { - //todo: 예외처리 - throw it - } + return flowOf(true) + .map { + eventStoryApi.addFeedComment( + feedId, AddFeedCommentRequest(memo) + ) + }.catch { + throw it.toException() + } } fun deleteFeedComment(feedId: Int, commentId: Int): Flow { - return flowOf(true).map { - eventStoryApi.deleteFeedComment(feedId, commentId) - }.catch { - throw it.toException() - } + return flowOf(true) + .map { + eventStoryApi.deleteFeedComment(feedId, commentId) + }.catch { + throw it.toException() + } } fun inviteEvent(eventId: Int, userId: Int): Flow { From f6b10a4c88217f86920e4cf03425d712fb341588 Mon Sep 17 00:00:00 2001 From: LeeHaiLim Date: Tue, 12 Dec 2023 03:03:35 +0900 Subject: [PATCH 5/8] =?UTF-8?q?chore:=20=ED=8C=A8=ED=82=A4=EC=A7=80=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/teameetmeet/meetmeet/data/network/api/LoginApi.kt | 1 - .../calendar/monthcalendar/vm/OwnerMonthCalendarViewModel.kt | 2 +- .../presentation/eventstory/eventstory/OnItemClickListener.kt | 2 -- .../eventstory/feeddetail/feedcontent/FeedContentFragment.kt | 2 +- .../feeddetail/{temp => feedcontentmedia}/FeedContentAdapter.kt | 2 +- .../{temp => feedcontentmedia}/FeedContentImageFragment.kt | 2 +- .../{temp => feedcontentmedia}/FeedContentVideoFragment.kt | 2 +- 7 files changed, 5 insertions(+), 8 deletions(-) rename android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/{temp => feedcontentmedia}/FeedContentAdapter.kt (98%) rename android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/{temp => feedcontentmedia}/FeedContentImageFragment.kt (98%) rename android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/{temp => feedcontentmedia}/FeedContentVideoFragment.kt (99%) diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/data/network/api/LoginApi.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/data/network/api/LoginApi.kt index 155cd95..2522e79 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/data/network/api/LoginApi.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/data/network/api/LoginApi.kt @@ -17,7 +17,6 @@ interface LoginApi { @POST("/auth/login") suspend fun loginSelf(@Body selfSignRequest: SelfSignRequest): LoginResponse - @GET("auth/check/email") suspend fun checkEmailDuplication(@Query("email") email: String): AvailableResponse diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/vm/OwnerMonthCalendarViewModel.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/vm/OwnerMonthCalendarViewModel.kt index 8bc5b52..f40c50b 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/vm/OwnerMonthCalendarViewModel.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/vm/OwnerMonthCalendarViewModel.kt @@ -21,7 +21,7 @@ class OwnerMonthCalendarViewModel( val startDateTime = date.withDayOfMonth(1).toStartLong() val endDateTime = date.withDayOfMonth(date.lengthOfMonth()).toEndLong() calendarRepository - .getEvents(startDateTime, endDateTime) + .getSyncedEvents(startDateTime, endDateTime) .collectLatest { setDaysInMonth(it.map(Event::toEventSimple)) } diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/eventstory/OnItemClickListener.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/eventstory/OnItemClickListener.kt index a8207e7..00d1f22 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/eventstory/OnItemClickListener.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/eventstory/OnItemClickListener.kt @@ -1,7 +1,5 @@ package com.teameetmeet.meetmeet.presentation.eventstory.eventstory -import androidx.recyclerview.widget.RecyclerView.ViewHolder - interface OnItemClickListener { fun onItemClick() diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/feedcontent/FeedContentFragment.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/feedcontent/FeedContentFragment.kt index d80b2b6..7e13784 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/feedcontent/FeedContentFragment.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/feedcontent/FeedContentFragment.kt @@ -18,7 +18,7 @@ import androidx.viewpager2.widget.ViewPager2 import com.teameetmeet.meetmeet.R import com.teameetmeet.meetmeet.databinding.FragmentFeedContentBinding import com.teameetmeet.meetmeet.presentation.base.BaseFragment -import com.teameetmeet.meetmeet.presentation.eventstory.feeddetail.temp.FeedContentAdapter +import com.teameetmeet.meetmeet.presentation.eventstory.feeddetail.feedcontentmedia.FeedContentAdapter import com.teameetmeet.meetmeet.service.downloading.ImageDownloadWorker import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.launch diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/temp/FeedContentAdapter.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/feedcontentmedia/FeedContentAdapter.kt similarity index 98% rename from android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/temp/FeedContentAdapter.kt rename to android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/feedcontentmedia/FeedContentAdapter.kt index 7bfaef7..a2677f6 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/temp/FeedContentAdapter.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/feedcontentmedia/FeedContentAdapter.kt @@ -1,4 +1,4 @@ -package com.teameetmeet.meetmeet.presentation.eventstory.feeddetail.temp +package com.teameetmeet.meetmeet.presentation.eventstory.feeddetail.feedcontentmedia import androidx.fragment.app.Fragment import androidx.recyclerview.widget.DiffUtil diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/temp/FeedContentImageFragment.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/feedcontentmedia/FeedContentImageFragment.kt similarity index 98% rename from android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/temp/FeedContentImageFragment.kt rename to android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/feedcontentmedia/FeedContentImageFragment.kt index 4e6a6bd..380db86 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/temp/FeedContentImageFragment.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/feedcontentmedia/FeedContentImageFragment.kt @@ -1,4 +1,4 @@ -package com.teameetmeet.meetmeet.presentation.eventstory.feeddetail.temp +package com.teameetmeet.meetmeet.presentation.eventstory.feeddetail.feedcontentmedia import android.os.Bundle import android.view.View diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/temp/FeedContentVideoFragment.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/feedcontentmedia/FeedContentVideoFragment.kt similarity index 99% rename from android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/temp/FeedContentVideoFragment.kt rename to android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/feedcontentmedia/FeedContentVideoFragment.kt index 47229b6..60dd8dc 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/temp/FeedContentVideoFragment.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/feedcontentmedia/FeedContentVideoFragment.kt @@ -1,4 +1,4 @@ -package com.teameetmeet.meetmeet.presentation.eventstory.feeddetail.temp +package com.teameetmeet.meetmeet.presentation.eventstory.feeddetail.feedcontentmedia import android.os.Bundle import android.view.View From b939a78b9a51f6f2f6d77894ec748602e1dba8da Mon Sep 17 00:00:00 2001 From: LeeHaiLim Date: Tue, 12 Dec 2023 03:09:00 +0900 Subject: [PATCH 6/8] =?UTF-8?q?refactor:=20=EB=B7=B0=ED=99=80=EB=8D=94=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bottomsheet/EventsPerDayAdapter.kt | 56 +---------------- .../bottomsheet/EventsPerDayViewHolder.kt | 61 +++++++++++++++++++ .../calendar/monthcalendar/EventBarAdapter.kt | 35 +---------- .../monthcalendar/EventBarViewHolder.kt | 36 +++++++++++ .../monthcalendar/MonthCalendarAdapter.kt | 37 ++--------- .../monthcalendar/MonthCalendarViewHolder.kt | 36 +++++++++++ .../eventstory/createfeed/MediaAdapter.kt | 9 +-- .../eventstory/createfeed/MediaViewHolder.kt | 12 ++++ .../feeddetail/FeedCommentAdapter.kt | 32 ++++++++++ .../feeddetail/FeedCommentViewHolder.kt | 40 ++++++++++++ .../feeddetail/FeedCommentsAdapter.kt | 59 ------------------ .../feeddetail/FeedDetailBindingAdapter.kt | 2 +- .../feeddetail/FeedDetailFragment.kt | 4 +- .../presentation/home/HomeViewModel.kt | 8 +-- 14 files changed, 235 insertions(+), 192 deletions(-) create mode 100644 android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/bottomsheet/EventsPerDayViewHolder.kt create mode 100644 android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/EventBarViewHolder.kt create mode 100644 android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/MonthCalendarViewHolder.kt create mode 100644 android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedCommentAdapter.kt create mode 100644 android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedCommentViewHolder.kt delete mode 100644 android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedCommentsAdapter.kt diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/bottomsheet/EventsPerDayAdapter.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/bottomsheet/EventsPerDayAdapter.kt index d26b58e..327fccd 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/bottomsheet/EventsPerDayAdapter.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/bottomsheet/EventsPerDayAdapter.kt @@ -1,73 +1,21 @@ package com.teameetmeet.meetmeet.presentation.calendar.bottomsheet -import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter -import androidx.recyclerview.widget.RecyclerView -import com.teameetmeet.meetmeet.databinding.ItemEventSimpleBinding import com.teameetmeet.meetmeet.presentation.model.EventSimple -import com.teameetmeet.meetmeet.util.date.DateTimeFormat -import com.teameetmeet.meetmeet.util.date.getLocalDate -import com.teameetmeet.meetmeet.util.date.toDateString -import com.teameetmeet.meetmeet.util.date.toLocalDate class EventsPerDayAdapter( private val listener: EventItemClickListener -) : ListAdapter(diffCallback) { +) : ListAdapter(diffCallback) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EventsPerDayViewHolder { - val binding = ItemEventSimpleBinding.inflate( - LayoutInflater.from(parent.context), - parent, - false - ) - return EventsPerDayViewHolder(binding, listener) + return EventsPerDayViewHolder.from(parent, listener) } override fun onBindViewHolder(holder: EventsPerDayViewHolder, position: Int) { holder.bind(getItem(position)) } - class EventsPerDayViewHolder( - private val binding: ItemEventSimpleBinding, - private val listener: EventItemClickListener, - ) : RecyclerView.ViewHolder(binding.root) { - fun bind(item: EventSimple) { - binding.item = item - setDateText(item) - itemView.setOnClickListener { - listener.onItemClick(item) - } - } - - private fun setDateText(item: EventSimple) { - val startDate = item.startDateTime.toLocalDate() - val endDate = item.endDateTime.toLocalDate() - val year = getLocalDate().year - - binding.itemEventBsTvDescription.text = - if (startDate == endDate) { - "${ - item.startDateTime.toDateString(DateTimeFormat.LOCAL_TIME) - } - ${ - item.endDateTime.toDateString(DateTimeFormat.LOCAL_TIME) - }" - } else { - "${ - item.startDateTime.toDateString( - if (startDate.year == year) DateTimeFormat.LOCAL_DATE_TIME_WO_YEAR - else DateTimeFormat.LOCAL_DATE_TIME - ) - } - ${ - item.endDateTime.toDateString( - if (endDate.year == year) DateTimeFormat.LOCAL_DATE_TIME_WO_YEAR - else DateTimeFormat.LOCAL_DATE_TIME - ) - }" - } - } - } - companion object { val diffCallback = object : DiffUtil.ItemCallback() { override fun areItemsTheSame(oldItem: EventSimple, newItem: EventSimple): Boolean { diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/bottomsheet/EventsPerDayViewHolder.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/bottomsheet/EventsPerDayViewHolder.kt new file mode 100644 index 0000000..8486741 --- /dev/null +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/bottomsheet/EventsPerDayViewHolder.kt @@ -0,0 +1,61 @@ +package com.teameetmeet.meetmeet.presentation.calendar.bottomsheet + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.teameetmeet.meetmeet.databinding.ItemEventSimpleBinding +import com.teameetmeet.meetmeet.presentation.model.EventSimple +import com.teameetmeet.meetmeet.util.date.DateTimeFormat +import com.teameetmeet.meetmeet.util.date.getLocalDate +import com.teameetmeet.meetmeet.util.date.toDateString +import com.teameetmeet.meetmeet.util.date.toLocalDate + +class EventsPerDayViewHolder( + private val binding: ItemEventSimpleBinding, + private val listener: EventItemClickListener, +) : RecyclerView.ViewHolder(binding.root) { + fun bind(item: EventSimple) { + binding.item = item + setDateText(item) + itemView.setOnClickListener { + listener.onItemClick(item) + } + } + + private fun setDateText(item: EventSimple) { + val startDate = item.startDateTime.toLocalDate() + val endDate = item.endDateTime.toLocalDate() + val year = getLocalDate().year + + binding.itemEventBsTvDescription.text = + if (startDate == endDate) { + "${ + item.startDateTime.toDateString(DateTimeFormat.LOCAL_TIME) + } - ${ + item.endDateTime.toDateString(DateTimeFormat.LOCAL_TIME) + }" + } else { + "${ + item.startDateTime.toDateString( + if (startDate.year == year) DateTimeFormat.LOCAL_DATE_TIME_WO_YEAR + else DateTimeFormat.LOCAL_DATE_TIME + ) + } - ${ + item.endDateTime.toDateString( + if (endDate.year == year) DateTimeFormat.LOCAL_DATE_TIME_WO_YEAR + else DateTimeFormat.LOCAL_DATE_TIME + ) + }" + } + } + + companion object { + fun from(parent: ViewGroup, listener: EventItemClickListener): EventsPerDayViewHolder { + val inflater = LayoutInflater.from(parent.context) + return EventsPerDayViewHolder( + ItemEventSimpleBinding.inflate(inflater, parent, false), + listener + ) + } + } +} \ No newline at end of file diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/EventBarAdapter.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/EventBarAdapter.kt index 7775338..442b70b 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/EventBarAdapter.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/EventBarAdapter.kt @@ -1,48 +1,19 @@ package com.teameetmeet.meetmeet.presentation.calendar.monthcalendar -import android.view.LayoutInflater import android.view.ViewGroup -import androidx.annotation.Dimension import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter -import androidx.recyclerview.widget.RecyclerView -import com.teameetmeet.meetmeet.databinding.ItemEventBarBinding import com.teameetmeet.meetmeet.presentation.model.EventBar -class EventBarAdapter : ListAdapter(diffCallback) { - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): EventBarViewHolder { - val binding = ItemEventBarBinding.inflate( - LayoutInflater.from(parent.context), - parent, - false - ) - binding.root.layoutParams.height = (parent.measuredHeight / 5) - binding.itemEventBarTvHidden.setTextSize( - Dimension.PX, parent.measuredHeight.toFloat() / 20 - ) - return EventBarViewHolder(binding) +class EventBarAdapter : ListAdapter(diffCallback) { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EventBarViewHolder { + return EventBarViewHolder.from(parent) } override fun onBindViewHolder(holder: EventBarViewHolder, position: Int) { holder.bind(getItem(position)) } - class EventBarViewHolder( - private val binding: ItemEventBarBinding, - ) : RecyclerView.ViewHolder(binding.root) { - fun bind(item: EventBar?) { - binding.item = item - binding.itemEventBarTvHidden.text = - with(item) { - if (this != null && hiddenCount > 0) "+$hiddenCount" - else "" - } - } - } - companion object { val diffCallback = object : DiffUtil.ItemCallback() { override fun areItemsTheSame(oldItem: EventBar, newItem: EventBar): Boolean { diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/EventBarViewHolder.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/EventBarViewHolder.kt new file mode 100644 index 0000000..8c964ef --- /dev/null +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/EventBarViewHolder.kt @@ -0,0 +1,36 @@ +package com.teameetmeet.meetmeet.presentation.calendar.monthcalendar + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.annotation.Dimension +import androidx.recyclerview.widget.RecyclerView +import com.teameetmeet.meetmeet.databinding.ItemEventBarBinding +import com.teameetmeet.meetmeet.presentation.model.EventBar + +class EventBarViewHolder( + private val binding: ItemEventBarBinding +) : RecyclerView.ViewHolder(binding.root) { + fun bind(item: EventBar?) { + binding.item = item + binding.itemEventBarTvHidden.text = + with(item) { + if (this != null && hiddenCount > 0) "+$hiddenCount" + else "" + } + } + + companion object { + fun from(parent: ViewGroup): EventBarViewHolder { + val inflater = LayoutInflater.from(parent.context) + return EventBarViewHolder( + ItemEventBarBinding.inflate(inflater, parent, false) + .apply { + root.layoutParams.height = (parent.measuredHeight / 5) + itemEventBarTvHidden.setTextSize( + Dimension.PX, parent.measuredHeight.toFloat() / 20 + ) + } + ) + } + } +} \ No newline at end of file diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/MonthCalendarAdapter.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/MonthCalendarAdapter.kt index 68ff17a..6faa3b6 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/MonthCalendarAdapter.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/MonthCalendarAdapter.kt @@ -1,49 +1,22 @@ package com.teameetmeet.meetmeet.presentation.calendar.monthcalendar -import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter -import androidx.recyclerview.widget.RecyclerView -import com.teameetmeet.meetmeet.databinding.ItemCalendarBinding import com.teameetmeet.meetmeet.presentation.model.CalendarItem class MonthCalendarAdapter( - private val calendarItemClickListener: CalendarItemClickListener -) : ListAdapter(diffCallback) { + private val listener: CalendarItemClickListener +) : ListAdapter(diffCallback) { - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CalendarViewHolder { - val binding = ItemCalendarBinding.inflate( - LayoutInflater.from(parent.context), - parent, - false - ) - binding.root.layoutParams.height = parent.measuredHeight / 6 - return CalendarViewHolder(binding, calendarItemClickListener) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MonthCalendarViewHolder { + return MonthCalendarViewHolder.from(parent, listener) } - override fun onBindViewHolder(holder: CalendarViewHolder, position: Int) { + override fun onBindViewHolder(holder: MonthCalendarViewHolder, position: Int) { holder.bind(getItem(position)) } - class CalendarViewHolder( - private val binding: ItemCalendarBinding, - private val calendarItemClickListener: CalendarItemClickListener - ) : RecyclerView.ViewHolder(binding.root) { - fun bind(item: CalendarItem) { - with(binding) { - this.item = item - itemCalendarViewTouch.setOnClickListener { - calendarItemClickListener.onItemClick(item) - } - if (itemCalendarRvEvents.adapter == null) { - itemCalendarRvEvents.adapter = EventBarAdapter() - } - itemCalendarRvEvents.itemAnimator = null - } - } - } - companion object { val diffCallback = object : DiffUtil.ItemCallback() { override fun areItemsTheSame(oldItem: CalendarItem, newItem: CalendarItem): Boolean { diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/MonthCalendarViewHolder.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/MonthCalendarViewHolder.kt new file mode 100644 index 0000000..217a895 --- /dev/null +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/MonthCalendarViewHolder.kt @@ -0,0 +1,36 @@ +package com.teameetmeet.meetmeet.presentation.calendar.monthcalendar + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.teameetmeet.meetmeet.databinding.ItemCalendarBinding +import com.teameetmeet.meetmeet.presentation.model.CalendarItem + +class MonthCalendarViewHolder( + private val binding: ItemCalendarBinding, + private val listener: CalendarItemClickListener +) : RecyclerView.ViewHolder(binding.root) { + fun bind(item: CalendarItem) { + with(binding) { + this.item = item + itemCalendarViewTouch.setOnClickListener { + listener.onItemClick(item) + } + if (itemCalendarRvEvents.adapter == null) { + itemCalendarRvEvents.adapter = EventBarAdapter() + } + itemCalendarRvEvents.itemAnimator = null + } + } + + companion object { + fun from(parent: ViewGroup, listener: CalendarItemClickListener): MonthCalendarViewHolder { + val inflater = LayoutInflater.from(parent.context) + return MonthCalendarViewHolder( + ItemCalendarBinding.inflate(inflater, parent, false) + .apply { root.layoutParams.height = parent.measuredHeight / 6 }, + listener + ) + } + } +} \ No newline at end of file diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/createfeed/MediaAdapter.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/createfeed/MediaAdapter.kt index 9782d6a..be33d5a 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/createfeed/MediaAdapter.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/createfeed/MediaAdapter.kt @@ -1,22 +1,15 @@ package com.teameetmeet.meetmeet.presentation.eventstory.createfeed -import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter -import com.teameetmeet.meetmeet.databinding.ItemCreateFeedMediaBinding import com.teameetmeet.meetmeet.presentation.model.FeedMedia class MediaAdapter( private val listener: MediaItemCancelClickListener ) : ListAdapter(diffCallback) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MediaViewHolder { - val binding = ItemCreateFeedMediaBinding.inflate( - LayoutInflater.from(parent.context), - parent, - false - ) - return MediaViewHolder(binding, listener) + return MediaViewHolder.from(parent, listener) } override fun onBindViewHolder(holder: MediaViewHolder, position: Int) { diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/createfeed/MediaViewHolder.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/createfeed/MediaViewHolder.kt index 5e93e53..ae7800e 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/createfeed/MediaViewHolder.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/createfeed/MediaViewHolder.kt @@ -1,5 +1,7 @@ package com.teameetmeet.meetmeet.presentation.eventstory.createfeed +import android.view.LayoutInflater +import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.teameetmeet.meetmeet.databinding.ItemCreateFeedMediaBinding import com.teameetmeet.meetmeet.presentation.model.FeedMedia @@ -14,4 +16,14 @@ class MediaViewHolder( listener.onItemClick(item) } } + + companion object { + fun from(parent: ViewGroup, listener: MediaItemCancelClickListener): MediaViewHolder { + val inflater = LayoutInflater.from(parent.context) + return MediaViewHolder( + ItemCreateFeedMediaBinding.inflate(inflater, parent, false), + listener + ) + } + } } \ No newline at end of file diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedCommentAdapter.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedCommentAdapter.kt new file mode 100644 index 0000000..b14a5ef --- /dev/null +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedCommentAdapter.kt @@ -0,0 +1,32 @@ +package com.teameetmeet.meetmeet.presentation.eventstory.feeddetail + +import android.view.ViewGroup +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.ListAdapter +import com.teameetmeet.meetmeet.data.model.Comment +import com.teameetmeet.meetmeet.presentation.model.EventAuthority + +class FeedCommentAdapter( + private val authority: EventAuthority, + private val listener: CommentDeleteClickListener +) : ListAdapter(diffCallback) { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FeedCommentViewHolder { + return FeedCommentViewHolder.from(parent, authority, listener) + } + + override fun onBindViewHolder(holder: FeedCommentViewHolder, position: Int) { + holder.bind(getItem(position)) + } + + companion object { + private val diffCallback = object : DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: Comment, newItem: Comment): Boolean { + return oldItem.id == newItem.id + } + + override fun areContentsTheSame(oldItem: Comment, newItem: Comment): Boolean { + return oldItem == newItem + } + } + } +} \ No newline at end of file diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedCommentViewHolder.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedCommentViewHolder.kt new file mode 100644 index 0000000..baefedc --- /dev/null +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedCommentViewHolder.kt @@ -0,0 +1,40 @@ +package com.teameetmeet.meetmeet.presentation.eventstory.feeddetail + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.core.view.isVisible +import androidx.recyclerview.widget.RecyclerView +import com.teameetmeet.meetmeet.data.model.Comment +import com.teameetmeet.meetmeet.databinding.ItemFeedCommentBinding +import com.teameetmeet.meetmeet.presentation.model.EventAuthority + +class FeedCommentViewHolder( + private val binding: ItemFeedCommentBinding, + private val authority: EventAuthority, + private val listener: CommentDeleteClickListener +) : + RecyclerView.ViewHolder(binding.root) { + fun bind(item: Comment) { + binding.item = item + binding.feedCommentBtnDelete.isVisible = + item.isMine || authority == EventAuthority.OWNER + binding.feedCommentBtnDelete.setOnClickListener { + listener.onClick(item) + } + } + + companion object { + fun from( + parent: ViewGroup, + authority: EventAuthority, + listener: CommentDeleteClickListener + ): FeedCommentViewHolder { + val inflater = LayoutInflater.from(parent.context) + return FeedCommentViewHolder( + ItemFeedCommentBinding.inflate(inflater, parent, false), + authority, + listener + ) + } + } +} \ No newline at end of file diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedCommentsAdapter.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedCommentsAdapter.kt deleted file mode 100644 index 8727964..0000000 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedCommentsAdapter.kt +++ /dev/null @@ -1,59 +0,0 @@ -package com.teameetmeet.meetmeet.presentation.eventstory.feeddetail - -import android.view.LayoutInflater -import android.view.ViewGroup -import androidx.core.view.isVisible -import androidx.recyclerview.widget.DiffUtil -import androidx.recyclerview.widget.ListAdapter -import androidx.recyclerview.widget.RecyclerView -import com.teameetmeet.meetmeet.data.model.Comment -import com.teameetmeet.meetmeet.databinding.ItemFeedCommentBinding -import com.teameetmeet.meetmeet.presentation.model.EventAuthority - -class FeedCommentsAdapter( - private val authority: EventAuthority, - private val commentDeleteClickListener: CommentDeleteClickListener -) : - ListAdapter(diffCallback) { - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FeedCommentsViewHolder { - val binding = ItemFeedCommentBinding.inflate( - LayoutInflater.from(parent.context), - parent, - false - ) - return FeedCommentsViewHolder(binding, authority, commentDeleteClickListener) - } - - override fun onBindViewHolder(holder: FeedCommentsViewHolder, position: Int) { - holder.bind(getItem(position)) - } - - class FeedCommentsViewHolder( - private val binding: ItemFeedCommentBinding, - private val authority: EventAuthority, - private val commentDeleteClickListener: CommentDeleteClickListener - ) : - RecyclerView.ViewHolder(binding.root) { - fun bind(item: Comment) { - binding.item = item - binding.feedCommentBtnDelete.isVisible = - item.isMine || authority == EventAuthority.OWNER - binding.feedCommentBtnDelete.setOnClickListener { - commentDeleteClickListener.onClick(item) - } - } - } - - companion object { - private val diffCallback = object : DiffUtil.ItemCallback() { - override fun areItemsTheSame(oldItem: Comment, newItem: Comment): Boolean { - return oldItem.id == newItem.id - } - - override fun areContentsTheSame(oldItem: Comment, newItem: Comment): Boolean { - return oldItem == newItem - } - - } - } -} \ No newline at end of file diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedDetailBindingAdapter.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedDetailBindingAdapter.kt index 114bbb2..3e7af3a 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedDetailBindingAdapter.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedDetailBindingAdapter.kt @@ -11,7 +11,7 @@ import androidx.viewpager2.widget.ViewPager2 import com.google.android.material.appbar.MaterialToolbar import com.teameetmeet.meetmeet.R import com.teameetmeet.meetmeet.data.model.Content -import com.teameetmeet.meetmeet.presentation.eventstory.feeddetail.temp.FeedContentAdapter +import com.teameetmeet.meetmeet.presentation.eventstory.feeddetail.feedcontentmedia.FeedContentAdapter import com.teameetmeet.meetmeet.presentation.model.EventAuthority @BindingAdapter("sub_list") diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedDetailFragment.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedDetailFragment.kt index c816992..b7a9c28 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedDetailFragment.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/eventstory/feeddetail/FeedDetailFragment.kt @@ -18,7 +18,7 @@ import com.teameetmeet.meetmeet.R import com.teameetmeet.meetmeet.data.model.Comment import com.teameetmeet.meetmeet.databinding.FragmentFeedDetailBinding import com.teameetmeet.meetmeet.presentation.base.BaseFragment -import com.teameetmeet.meetmeet.presentation.eventstory.feeddetail.temp.FeedContentAdapter +import com.teameetmeet.meetmeet.presentation.eventstory.feeddetail.feedcontentmedia.FeedContentAdapter import com.teameetmeet.meetmeet.presentation.model.EventAuthority import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.launch @@ -63,7 +63,7 @@ class FeedDetailFragment : with(binding) { vm = viewModel feedDetailRvComment.adapter = - FeedCommentsAdapter(navArgs.authority, this@FeedDetailFragment) + FeedCommentAdapter(navArgs.authority, this@FeedDetailFragment) feedDetailVpMedia.adapter = FeedContentAdapter(this@FeedDetailFragment) feedDetailClComment.isVisible = navArgs.authority != EventAuthority.GUEST } diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/home/HomeViewModel.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/home/HomeViewModel.kt index 2934cf3..31471ee 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/home/HomeViewModel.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/home/HomeViewModel.kt @@ -40,13 +40,13 @@ class HomeViewModel @Inject constructor( private fun setAlarm() { viewModelScope.launch { - calendarRepository.getEvents( + calendarRepository.getSyncedEvents( getLocalDateTime().toLong(), getLocalDateTime().plusDays(AlarmHelper.UPDATE_DAY_UNIT).toLong() - ).catch {} - .collect { events -> + ).catch { + }.collect { events -> events.filter { - getLocalDateTime().toLong() <= it.getTriggerTime() + getLocalDateTime().toLong() <= it.getTriggerTime() }.forEach { alarmHelper.registerEventAlarm( EventAlarm( From 7ff44a2398d32dc463e95d391b79e452a877a0d0 Mon Sep 17 00:00:00 2001 From: LeeHaiLim Date: Tue, 12 Dec 2023 05:57:29 +0900 Subject: [PATCH 7/8] =?UTF-8?q?refactor:=20comparator=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EA=B0=80=EB=8F=85=EC=84=B1=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/monthcalendar/vm/MonthCalendarViewModel.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/vm/MonthCalendarViewModel.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/vm/MonthCalendarViewModel.kt index a7ad8d6..8eb9b50 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/vm/MonthCalendarViewModel.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/presentation/calendar/monthcalendar/vm/MonthCalendarViewModel.kt @@ -55,10 +55,8 @@ abstract class MonthCalendarViewModel : ViewModel(), CalendarItemClickListener { val endToday1 = event1.endDateTime.toLocalDate() == today val endToday2 = event2.endDateTime.toLocalDate() == today - if (!endToday1 && endToday2) -1 - else if (endToday1 && !endToday2) 1 - else if (event1.startDateTime - event2.startDateTime <= 0) -1 - else 1 + if (endToday1 == endToday2) event1.startDateTime.compareTo(event2.startDateTime) + else endToday1.compareTo(endToday2) } } @@ -92,7 +90,7 @@ abstract class MonthCalendarViewModel : ViewModel(), CalendarItemClickListener { daysInMonth[i - 1].eventBars.any { it?.id == event.id } } - var eventBars: MutableList = (0..<5).map { null }.toMutableList() + val eventBars: MutableList = (0..<5).map { null }.toMutableList() continuity[true]?.map { event -> val index = daysInMonth[i - 1].eventBars.indexOfFirst { it?.id == event.id } From 8cae39659449a6155d1686350bf9e457bf2a28f8 Mon Sep 17 00:00:00 2001 From: LeeHaiLim Date: Tue, 12 Dec 2023 18:57:25 +0900 Subject: [PATCH 8/8] =?UTF-8?q?feat:=20=EC=84=9C=EB=B2=84=20=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=20=EC=8B=9C=20=EB=AC=B4=EC=A1=B0=EA=B1=B4=20=EB=A1=9C?= =?UTF-8?q?=EC=BB=AC=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EA=B0=80=EC=A0=B8?= =?UTF-8?q?=EC=98=A4=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meetmeet/data/repository/CalendarRepository.kt | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/CalendarRepository.kt b/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/CalendarRepository.kt index 7a11d55..82ca9c6 100644 --- a/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/CalendarRepository.kt +++ b/android/app/src/main/java/com/teameetmeet/meetmeet/data/repository/CalendarRepository.kt @@ -17,7 +17,6 @@ import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach -import java.net.UnknownHostException import java.time.ZoneId import javax.inject.Inject @@ -36,13 +35,7 @@ class CalendarRepository @Inject constructor( }.map { localCalendarDataSource.getEvents(startDateTime, endDateTime).first() }.catch { - when (it) { - is UnknownHostException -> { - emit(localCalendarDataSource.getEvents(startDateTime, endDateTime).first()) - } - - else -> throw it.toException() - } + emit(localCalendarDataSource.getEvents(startDateTime, endDateTime).first()) } }