diff --git a/app/src/main/java/com/myongsik/myongsikandroid/MainActivity.kt b/app/src/main/java/com/myongsik/myongsikandroid/MainActivity.kt index 712bc1cb..d59da887 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/MainActivity.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/MainActivity.kt @@ -6,10 +6,8 @@ import android.content.Intent import android.os.Bundle import android.view.View import androidx.appcompat.app.AppCompatActivity -import androidx.fragment.app.Fragment import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.NavigationUI -import com.myongsik.myongsikandroid.alarm.AlarmBroadCastReceiver import com.myongsik.myongsikandroid.databinding.ActivityMainBinding import com.myongsik.myongsikandroid.util.MyongsikApplication import dagger.hilt.android.AndroidEntryPoint @@ -78,18 +76,5 @@ class MainActivity : AppCompatActivity() { binding.myongsikHomeFragmentView.setPadding(0,0,0,0) } } - - // Background - val alarmManager = getSystemService(ALARM_SERVICE) as AlarmManager - val triggerTime = Calendar.getInstance() - triggerTime.set(Calendar.HOUR_OF_DAY, 23) - triggerTime.set(Calendar.MINUTE, 59) - triggerTime.set(Calendar.SECOND, 0) - triggerTime.set(Calendar.MILLISECOND, 0) - - val intent = Intent(this@MainActivity, AlarmBroadCastReceiver::class.java) - val pIntent = PendingIntent.getBroadcast(this@MainActivity, 0, intent, PendingIntent.FLAG_IMMUTABLE) - alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, triggerTime.timeInMillis, AlarmManager.INTERVAL_DAY, pIntent) - } } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/alarm/AlarmBroadCastReceiver.kt b/app/src/main/java/com/myongsik/myongsikandroid/alarm/AlarmBroadCastReceiver.kt deleted file mode 100644 index 7df35e91..00000000 --- a/app/src/main/java/com/myongsik/myongsikandroid/alarm/AlarmBroadCastReceiver.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.myongsik.myongsikandroid.alarm - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import com.myongsik.myongsikandroid.util.MyongsikApplication - -class AlarmBroadCastReceiver : BroadcastReceiver() { - - override fun onReceive(p0: Context?, p1: Intent?) { - MyongsikApplication.prefs.setString("key", "gg") - } -} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt index 910a66b2..fbf7547e 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt @@ -23,28 +23,10 @@ interface FoodRepository { suspend fun getOneRestaurant(storeId : Int) : Response //DataStore - suspend fun saveLunchEvaluation(type: String, evaluation: String) - suspend fun saveSortType(key: Preferences.Key, value: String) suspend fun saveWidgetType(type : String) - suspend fun defaultDataStore() - - suspend fun getLunchEvaluation(): Flow - - suspend fun getLunchBEvaluation(): Flow - - suspend fun getDinnerEvaluation(): Flow - - suspend fun getLunchSEvaluation(): Flow - - suspend fun getDinnerSEvaluation(): Flow - - suspend fun getLunchHEvaluation(): Flow - - suspend fun getDinnerHEvaluation(): Flow - suspend fun getCurrentSortType(): Flow suspend fun getCurrentWidgetType(): Flow diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt index cea75b7a..d8696f81 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt @@ -5,7 +5,6 @@ import androidx.datastore.core.DataStore import androidx.datastore.preferences.core.Preferences import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.core.emptyPreferences -import androidx.datastore.preferences.core.stringPreferencesKey import com.myongsik.myongsikandroid.data.api.HomeFoodApi import com.myongsik.myongsikandroid.data.db.RestaurantDatabase import com.myongsik.myongsikandroid.data.model.food.* @@ -13,13 +12,6 @@ import com.myongsik.myongsikandroid.data.model.restaurant.RequestScrap import com.myongsik.myongsikandroid.data.model.restaurant.ResponseScrap import com.myongsik.myongsikandroid.data.model.review.RequestReviewData import com.myongsik.myongsikandroid.data.model.review.ResponseReviewData -import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl.PreferencesKeys.DINNER_EVALUATION -import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl.PreferencesKeys.DINNER_EVALUATION_H -import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl.PreferencesKeys.DINNER_EVALUATION_S -import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl.PreferencesKeys.LUNCH_A_EVALUATION_H -import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl.PreferencesKeys.LUNCH_A_EVALUATION_S -import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl.PreferencesKeys.LUNCH_B_EVALUATION -import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl.PreferencesKeys.LUNCH_EVALUATION import com.myongsik.myongsikandroid.util.DataStoreKey import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch @@ -56,57 +48,6 @@ class FoodRepositoryImpl @Inject constructor( } //DataStore - private object PreferencesKeys { - val LUNCH_EVALUATION = stringPreferencesKey("lunch_evaluation") - val LUNCH_B_EVALUATION = stringPreferencesKey("lunch_b_evaluation") - val DINNER_EVALUATION = stringPreferencesKey("dinner_evaluation") - val DINNER_EVALUATION_S = stringPreferencesKey("dinner_s_evaluation") - val LUNCH_A_EVALUATION_S = stringPreferencesKey("lunch_s_evaluation") - val DINNER_EVALUATION_H = stringPreferencesKey("dinner_h_evaluation") - val LUNCH_A_EVALUATION_H = stringPreferencesKey("lunch_h_evaluation") - } - - //중식 A, B 석식 평가 저장 - override suspend fun saveLunchEvaluation(type: String, evaluation: String) { - when (type) { - "A" -> { - dataStore.edit { prefs -> - prefs[LUNCH_EVALUATION] = evaluation - } - } - "B" -> { - dataStore.edit { prefs -> - prefs[LUNCH_B_EVALUATION] = evaluation - } - } - "D" -> { - dataStore.edit { prefs -> - prefs[DINNER_EVALUATION] = evaluation - } - } - "DS" -> { - dataStore.edit { prefs -> - prefs[DINNER_EVALUATION_S] = evaluation - } - } - "AS" -> { - dataStore.edit { prefs -> - prefs[LUNCH_A_EVALUATION_S] = evaluation - } - } - "AH" -> { - dataStore.edit { prefs -> - prefs[LUNCH_A_EVALUATION_H] = evaluation - } - } - "DH" -> { - dataStore.edit { prefs -> - prefs[DINNER_EVALUATION_H] = evaluation - } - } - } - } - override suspend fun saveSortType(key: Preferences.Key, value: String) { dataStore.edit { prefs -> prefs[key] = value @@ -119,142 +60,6 @@ class FoodRepositoryImpl @Inject constructor( } } - //DataStore 초기화 - override suspend fun defaultDataStore() { - dataStore.edit { prefs -> - prefs[LUNCH_EVALUATION] = "" - } - dataStore.edit { prefs -> - prefs[LUNCH_B_EVALUATION] = "" - } - dataStore.edit { prefs -> - prefs[DINNER_EVALUATION] = "" - } - dataStore.edit { prefs -> - prefs[LUNCH_A_EVALUATION_S] = "" - } - dataStore.edit { prefs -> - prefs[DINNER_EVALUATION_S] = "" - } - dataStore.edit { prefs -> - prefs[LUNCH_A_EVALUATION_H] = "" - } - dataStore.edit { prefs -> - prefs[DINNER_EVALUATION_H] = "" - } - } - - override suspend fun getLunchEvaluation(): Flow { - return dataStore.data - .catch { exception -> - if (exception is IOException) { - exception.printStackTrace() - emit(emptyPreferences()) - } else { - throw exception - } - } - .map { prefs -> - prefs[LUNCH_EVALUATION] ?: "" - } - } - - override suspend fun getLunchBEvaluation(): Flow { - return dataStore.data //data 메서드 - //실패 했을 대비에 예외처리 - .catch { exception -> - if (exception is IOException) { - exception.printStackTrace() - emit(emptyPreferences()) - } else { - throw exception - } - } - .map { prefs -> - prefs[LUNCH_B_EVALUATION] ?: "" - } - } - - override suspend fun getDinnerEvaluation(): Flow { - return dataStore.data //data 메서드 - //실패 했을 대비에 예외처리 - .catch { exception -> - if (exception is IOException) { - exception.printStackTrace() - emit(emptyPreferences()) - } else { - throw exception - } - } - .map { prefs -> - prefs[DINNER_EVALUATION] ?: "" - } - } - - override suspend fun getLunchSEvaluation(): Flow { - return dataStore.data //data 메서드 - //실패 했을 대비에 예외처리 - .catch { exception -> - if (exception is IOException) { - exception.printStackTrace() - emit(emptyPreferences()) - } else { - throw exception - } - } - .map { prefs -> - prefs[LUNCH_A_EVALUATION_S] ?: "" - } - } - - override suspend fun getDinnerSEvaluation(): Flow { - return dataStore.data //data 메서드 - //실패 했을 대비에 예외처리 - .catch { exception -> - if (exception is IOException) { - exception.printStackTrace() - emit(emptyPreferences()) - } else { - throw exception - } - } - .map { prefs -> - prefs[DINNER_EVALUATION_S] ?: "" - } - } - - override suspend fun getLunchHEvaluation(): Flow { - return dataStore.data //data 메서드 - //실패 했을 대비에 예외처리 - .catch { exception -> - if (exception is IOException) { - exception.printStackTrace() - emit(emptyPreferences()) - } else { - throw exception - } - } - .map { prefs -> - prefs[LUNCH_A_EVALUATION_H] ?: "" - } - } - - override suspend fun getDinnerHEvaluation(): Flow { - return dataStore.data //data 메서드 - //실패 했을 대비에 예외처리 - .catch { exception -> - if (exception is IOException) { - exception.printStackTrace() - emit(emptyPreferences()) - } else { - throw exception - } - } - .map { prefs -> - prefs[DINNER_EVALUATION_H] ?: "" - } - } - override suspend fun getCurrentSortType(): Flow { return dataStore.data //data 메서드 .catch { exception -> diff --git a/app/src/main/java/com/myongsik/myongsikandroid/presentation/adapter/food/MyPagerAdapter.kt b/app/src/main/java/com/myongsik/myongsikandroid/presentation/adapter/food/MyPagerAdapter.kt index 64842b80..4896396b 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/presentation/adapter/food/MyPagerAdapter.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/presentation/adapter/food/MyPagerAdapter.kt @@ -27,7 +27,6 @@ import java.util.* class MyPagerAdapter( private val itemList: List>>, - private val homeViewModel: HomeViewModel ) : RecyclerView.Adapter() { @@ -104,16 +103,6 @@ class MyPagerAdapter( binding.weekFoodLunchAV.text = "백반" binding.weekFoodLunchBTv.text = "샐러드" binding.weekFoodAfternoonTv.text = "볶음밥" - binding.todayGoodClLunchB.visibility = GONE - binding.todayGoodCl.visibility = GONE - binding.todayGoodClAfternoon.visibility = GONE - binding.todayHateClLunchB.visibility = GONE - binding.todayHateCl.visibility = GONE - binding.todayHateClLunchA.visibility = GONE - binding.todayLunchBLineIv.visibility = GONE - binding.todayLineIv.visibility = GONE - binding.todayLineIvAfternoon.visibility = GONE - } // text 설정, 자캠의 경우는 lunchB 지우기 binding.todayFood1.text = builderWeekFoodA @@ -126,12 +115,6 @@ class MyPagerAdapter( binding.homeLunchBV.visibility = GONE binding.todayDayLunchB.visibility = GONE - binding.todayLunchBLineIv.visibility = GONE - binding.todayGoodClLunchB.visibility = GONE - binding.todayLunchBGoodTv.visibility = GONE - binding.todayLunchBGoodIv.visibility = GONE - binding.todayLunchBHateIv.visibility = GONE - binding.todayLunchBHateTv.visibility = GONE binding.todayFoodLunchB.visibility = GONE } } @@ -147,485 +130,6 @@ class MyPagerAdapter( override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { val itemViewHolder = holder as ItemViewHolder itemViewHolder.bind(itemList[position]) - val today = Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - val isItemSelected = position == (today - 2) - val colorResId = if (isItemSelected) R.color.home_yes_color else R.color.home_not_color - val color = ContextCompat.getColor(holder.itemView.context, colorResId) - itemViewHolder.binding.todayAfternoonGoodTv.setTextColor(color) - itemViewHolder.binding.todayAfternoonHateTv.setTextColor(color) - itemViewHolder.binding.todayLunchAGoodTv.setTextColor(color) - itemViewHolder.binding.todayLunchBGoodTv.setTextColor(color) - itemViewHolder.binding.todayLunchAHateTv.setTextColor(color) - itemViewHolder.binding.todayLunchBHateTv.setTextColor(color) - itemViewHolder.binding.todayLunchAGoodIv.setColorFilter(color) - itemViewHolder.binding.todayLunchAHateIv.setColorFilter(color) - itemViewHolder.binding.todayLunchBGoodIv.setColorFilter(color) - itemViewHolder.binding.todayLunchBHateIv.setColorFilter(color) - itemViewHolder.binding.todayAfternoonGoodIv.setColorFilter(color) - itemViewHolder.binding.todayAfternoonHateIv.setColorFilter(color) - - fun getGoodChangeLunchA() { - itemViewHolder.binding.todayLunchAGoodTv.setTextColor(Color.parseColor("#274984")) - itemViewHolder.binding.todayLunchAHateTv.setTextColor(Color.parseColor("#CECECE")) - itemViewHolder.binding.todayLunchAGoodIv.setColorFilter(Color.parseColor("#274984")) - itemViewHolder.binding.todayLunchAHateIv.setColorFilter(Color.parseColor("#CECECE")) - } - - fun getGoodChangeLunchB() { - itemViewHolder.binding.todayLunchBGoodTv.setTextColor(Color.parseColor("#274984")) - itemViewHolder.binding.todayLunchBHateTv.setTextColor(Color.parseColor("#CECECE")) - itemViewHolder.binding.todayLunchBGoodIv.setColorFilter(Color.parseColor("#274984")) - itemViewHolder.binding.todayLunchBHateIv.setColorFilter(Color.parseColor("#CECECE")) - } - - fun getGoodChangeDinner() { - itemViewHolder.binding.todayAfternoonGoodTv.setTextColor(Color.parseColor("#274984")) - itemViewHolder.binding.todayAfternoonHateTv.setTextColor(Color.parseColor("#CECECE")) - itemViewHolder.binding.todayAfternoonGoodIv.setColorFilter(Color.parseColor("#274984")) - itemViewHolder.binding.todayAfternoonHateIv.setColorFilter(Color.parseColor("#CECECE")) - } - - fun getHateChangeLunchA() { - itemViewHolder.binding.todayLunchAHateTv.setTextColor(Color.parseColor("#274984")) - itemViewHolder.binding.todayLunchAGoodTv.setTextColor(Color.parseColor("#CECECE")) - itemViewHolder.binding.todayLunchAGoodIv.setColorFilter(Color.parseColor("#CECECE")) - itemViewHolder.binding.todayLunchAHateIv.setColorFilter(Color.parseColor("#274984")) - } - - fun getHateChangeLunchB() { - itemViewHolder.binding.todayLunchBHateTv.setTextColor(Color.parseColor("#274984")) - itemViewHolder.binding.todayLunchBGoodTv.setTextColor(Color.parseColor("#CECECE")) - itemViewHolder.binding.todayLunchBGoodIv.setColorFilter(Color.parseColor("#CECECE")) - itemViewHolder.binding.todayLunchBHateIv.setColorFilter(Color.parseColor("#274984")) - } - - fun getHateChangeDinner() { - itemViewHolder.binding.todayAfternoonHateTv.setTextColor(Color.parseColor("#274984")) - itemViewHolder.binding.todayAfternoonGoodTv.setTextColor(Color.parseColor("#CECECE")) - itemViewHolder.binding.todayAfternoonGoodIv.setColorFilter(Color.parseColor("#CECECE")) - itemViewHolder.binding.todayAfternoonHateIv.setColorFilter(Color.parseColor("#274984")) - } - - fun defaultChangeA() { - itemViewHolder.binding.todayLunchAHateTv.setTextColor(Color.parseColor("#717171")) - itemViewHolder.binding.todayLunchAGoodTv.setTextColor(Color.parseColor("#717171")) - itemViewHolder.binding.todayLunchAGoodIv.setColorFilter(Color.parseColor("#717171")) - itemViewHolder.binding.todayLunchAHateIv.setColorFilter(Color.parseColor("#717171")) - } - - fun defaultChangeB() { - itemViewHolder.binding.todayLunchBHateTv.setTextColor(Color.parseColor("#717171")) - itemViewHolder.binding.todayLunchBGoodTv.setTextColor(Color.parseColor("#717171")) - itemViewHolder.binding.todayLunchBGoodIv.setColorFilter(Color.parseColor("#717171")) - itemViewHolder.binding.todayLunchBHateIv.setColorFilter(Color.parseColor("#717171")) - } - - - fun defaultChange() { - itemViewHolder.binding.todayAfternoonHateTv.setTextColor(Color.parseColor("#717171")) - itemViewHolder.binding.todayAfternoonGoodTv.setTextColor(Color.parseColor("#717171")) - itemViewHolder.binding.todayAfternoonGoodIv.setColorFilter(Color.parseColor("#717171")) - itemViewHolder.binding.todayAfternoonHateIv.setColorFilter(Color.parseColor("#717171")) - } - - // 버튼 색 판단 - if (isItemSelected) { - if (itemList[0].size.toString() == "3" || MyongsikApplication.prefs.getUserArea() == "S"){ - if (LUNCH_A_GOOD == "good") getGoodChangeLunchA() - if (LUNCH_A_GOOD == "hate") getHateChangeLunchA() - if (LUNCH_B_GOOD == "good") getGoodChangeLunchB() - if (LUNCH_B_GOOD == "hate") getHateChangeLunchB() - if (DINNER == "good") getGoodChangeDinner() - if (DINNER == "hate") getHateChangeDinner() - } - if (MyongsikApplication.prefs.getUserArea() == "L"){ - if (LUNCH_A_GOOD_S == "good") getGoodChangeLunchA() - if (LUNCH_A_GOOD_S == "hate") getHateChangeLunchA() - if (DINNER_S == "good") getGoodChangeDinner() - if (DINNER_S == "hate") getHateChangeDinner() - } - if (MyongsikApplication.prefs.getUserArea() == "H"){ - if (LUNCH_A_GOOD_H == "good") getGoodChangeLunchA() - if (LUNCH_A_GOOD_H == "hate") getHateChangeLunchA() - if (DINNER_H == "good") getGoodChangeDinner() - if (DINNER_H == "hate") getHateChangeDinner() - } - } - - if (isItemSelected) { - itemViewHolder.binding.todayGoodClLunchB.setOnClickListener { - // lunch B - 자캠 불가능 - val dialogUtils = DialogUtils(holder.itemView.context) - if (LUNCH_B_GOOD == "good") { - if (itemViewHolder.binding.todayLunchBGoodTv.currentTextColor == Color.parseColor( - "#274984" - ) - ) { - defaultChangeB() - homeViewModel.saveLunchEvaluation("B", "") - return@setOnClickListener - } - } - - dialogUtils.showAlertDialog( - "‘맛있어요’로\n" + - "학식 평가를 하시겠어요?", - 6, - yesClickListener = { - // api - - // local - // 인캠의 경우 - LUNCH_B_GOOD = "good" - getGoodChangeLunchB() - homeViewModel.saveLunchEvaluation("B", "good") - - }, - noClickListener = { - - } - ) - } - - itemViewHolder.binding.todayHateClLunchB.setOnClickListener { - // lunch B - 자캠 불가능 - val dialogUtils = DialogUtils(holder.itemView.context) - if (LUNCH_B_GOOD == "hate") { - if (itemViewHolder.binding.todayLunchBHateTv.currentTextColor == Color.parseColor( - "#274984" - ) - ) { - defaultChangeB() - homeViewModel.saveLunchEvaluation("B", "") - return@setOnClickListener - } - } - - dialogUtils.showAlertDialog( - "‘맛없어요’로\n" + - "학식 평가를 하시겠어요?", - 6, - yesClickListener = { - // api - - // local - // 인캠의 경우 - LUNCH_B_GOOD = "hate" - getHateChangeLunchB() - homeViewModel.saveLunchEvaluation("B", "hate") - - }, - noClickListener = { - - } - ) - } - - itemViewHolder.binding.todayGoodCl.setOnClickListener { - val dialogUtils = DialogUtils(holder.itemView.context) - if (itemList[0].size.toString() == "3" || MyongsikApplication.prefs.getUserArea() == "S") { - if (LUNCH_A_GOOD == "good") { - if (itemViewHolder.binding.todayLunchAGoodTv.currentTextColor == Color.parseColor( - "#274984" - ) - ) { - defaultChangeA() - homeViewModel.saveLunchEvaluation("A", "") - return@setOnClickListener - } - } - } else { - if (MyongsikApplication.prefs.getUserArea() == "L") { - if (LUNCH_A_GOOD_S == "good") { - if (itemViewHolder.binding.todayLunchAGoodTv.currentTextColor == Color.parseColor( - "#274984" - ) - ) { - defaultChangeA() - homeViewModel.saveLunchEvaluation("AS", "") - return@setOnClickListener - } - } - } - if (MyongsikApplication.prefs.getUserArea() == "H") { - if (LUNCH_A_GOOD_H == "good") { - if (itemViewHolder.binding.todayLunchAGoodTv.currentTextColor == Color.parseColor( - "#274984" - ) - ) { - defaultChangeA() - homeViewModel.saveLunchEvaluation("AH", "") - return@setOnClickListener - } - } - } - } - - dialogUtils.showAlertDialog( - "‘맛있어요’로\n" + - "학식 평가를 하시겠어요?", - 6, - yesClickListener = { - // api - - // local - // 인캠의 경우 - if (itemList[0].size.toString() == "3" || MyongsikApplication.prefs.getUserArea() == "S") { - LUNCH_A_GOOD = "good" - getGoodChangeLunchA() - homeViewModel.saveLunchEvaluation("A", "good") - } - // 자캠의 경우 - else { - if (MyongsikApplication.prefs.getUserArea() == "L") { - LUNCH_A_GOOD_S = "good" - getGoodChangeLunchA() - homeViewModel.saveLunchEvaluation("AS", "good") - - } - if (MyongsikApplication.prefs.getUserArea() == "H") { - LUNCH_A_GOOD_H = "good" - getGoodChangeLunchA() - homeViewModel.saveLunchEvaluation("AH", "good") - - } - } - }, - noClickListener = { - - }) - } - - itemViewHolder.binding.todayHateClLunchA.setOnClickListener { - val dialogUtils = DialogUtils(holder.itemView.context) - if (itemList[0].size.toString() == "3" || MyongsikApplication.prefs.getUserArea() == "S") { - if (LUNCH_A_GOOD == "hate") { - if (itemViewHolder.binding.todayLunchAHateTv.currentTextColor == Color.parseColor( - "#274984" - ) - ) { - - defaultChangeA() - homeViewModel.saveLunchEvaluation("A", "") - return@setOnClickListener - } - } - } - if (MyongsikApplication.prefs.getUserArea() == "L") { - if (LUNCH_A_GOOD_S == "hate") { - if (itemViewHolder.binding.todayLunchAHateTv.currentTextColor == Color.parseColor( - "#274984" - ) - ) { - - defaultChangeA() - homeViewModel.saveLunchEvaluation("AS", "") - return@setOnClickListener - } - } - } - if (MyongsikApplication.prefs.getUserArea() == "H") { - if (LUNCH_A_GOOD_H == "hate") { - if (itemViewHolder.binding.todayLunchAHateTv.currentTextColor == Color.parseColor( - "#274984" - ) - ) { - defaultChangeA() - homeViewModel.saveLunchEvaluation("AH", "") - return@setOnClickListener - } - } - } - - dialogUtils.showAlertDialog( - "‘맛없어요’로\n" + - "학식 평가를 하시겠어요?", - 6, - yesClickListener = { - // 인캠의 경우 - if (itemList[0].size.toString() == "3" || MyongsikApplication.prefs.getUserArea() == "S") { - LUNCH_A_GOOD = "hate" - getHateChangeLunchA() - homeViewModel.saveLunchEvaluation("A", "hate") - } - // 자캠의 경우 - else { - if (MyongsikApplication.prefs.getUserArea() == "L") { - LUNCH_A_GOOD_S = "hate" - getHateChangeLunchA() - homeViewModel.saveLunchEvaluation("AS", "hate") - } - if (MyongsikApplication.prefs.getUserArea() == "H") { - LUNCH_A_GOOD_H = "hate" - getHateChangeLunchA() - homeViewModel.saveLunchEvaluation("AH", "hate") - } - } - }, - noClickListener = { - - } - ) - } - - itemViewHolder.binding.todayGoodClAfternoon.setOnClickListener { - val dialogUtils = DialogUtils(holder.itemView.context) - if (itemList[0].size.toString() == "3" || MyongsikApplication.prefs.getUserArea() == "S") { - if (DINNER == "good") { - if (itemViewHolder.binding.todayAfternoonGoodTv.currentTextColor == Color.parseColor( - "#274984" - ) - ) { - - defaultChange() - homeViewModel.saveLunchEvaluation("D", "") - return@setOnClickListener - } - } - } - if (MyongsikApplication.prefs.getUserArea() == "L") { - if (DINNER_S == "good") { - if (itemViewHolder.binding.todayAfternoonGoodTv.currentTextColor == Color.parseColor( - "#274984" - ) - ) { - - defaultChange() - homeViewModel.saveLunchEvaluation("DS", "") - return@setOnClickListener - } - } - } - if (MyongsikApplication.prefs.getUserArea() == "H") { - if (DINNER_H == "good") { - if (itemViewHolder.binding.todayAfternoonGoodTv.currentTextColor == Color.parseColor( - "#274984" - ) - ) { - - defaultChange() - homeViewModel.saveLunchEvaluation("DH", "") - return@setOnClickListener - } - } - } - - dialogUtils.showAlertDialog( - "‘맛있어요’로\n" + - "학식 평가를 하시겠어요?", - 6, - yesClickListener = { - // api - - // local - // 인캠의 경우 - if (itemList[0].size.toString() == "3" || MyongsikApplication.prefs.getUserArea() == "S") { - DINNER = "good" - getGoodChangeDinner() - homeViewModel.saveLunchEvaluation("D", "good") - } - // 자캠의 경우 - else { - if (MyongsikApplication.prefs.getUserArea() == "S") { - - DINNER_S = "good" - getGoodChangeDinner() - - homeViewModel.saveLunchEvaluation("DS", "good") - } - if (MyongsikApplication.prefs.getUserArea() == "H") { - - DINNER_H = "good" - getGoodChangeDinner() - - homeViewModel.saveLunchEvaluation("DH", "good") - } - } - }, - noClickListener = { - - } - ) - } - - - itemViewHolder.binding.todayHateCl.setOnClickListener { - if (itemList[0].size.toString() == "3" || MyongsikApplication.prefs.getUserArea() == "S") { - if (DINNER == "hate") { - if (itemViewHolder.binding.todayAfternoonHateTv.currentTextColor == Color.parseColor( - "#274984" - ) - ) { - defaultChange() - homeViewModel.saveLunchEvaluation("D", "") - return@setOnClickListener - } - } - } - if (MyongsikApplication.prefs.getUserArea() == "L") { - if (DINNER_S == "hate") { - if (itemViewHolder.binding.todayAfternoonHateTv.currentTextColor == Color.parseColor( - "#274984" - ) - ) { - defaultChange() - homeViewModel.saveLunchEvaluation("DS", "") - return@setOnClickListener - } - } - } - if (MyongsikApplication.prefs.getUserArea() == "H") { - if (DINNER_H == "hate") { - if (itemViewHolder.binding.todayAfternoonHateTv.currentTextColor == Color.parseColor( - "#274984" - ) - ) { - - defaultChange() - homeViewModel.saveLunchEvaluation("DH", "") - return@setOnClickListener - - } - } - } - - val dialogUtils = DialogUtils(holder.itemView.context) - dialogUtils.showAlertDialog( - "‘맛없어요’로\n" + - "학식 평가를 하시겠어요?", - 6, - yesClickListener = { - // 인캠의 경우 , 자캠 교직원 - if (itemList[0].size.toString() == "3" || MyongsikApplication.prefs.getUserArea() == "S") { - DINNER = "hate" - getHateChangeDinner() - - homeViewModel.saveLunchEvaluation("D", "hate") - } - // 자캠 생활관 - else { - if (MyongsikApplication.prefs.getUserArea() == "L") { - DINNER_S = "hate" - getHateChangeDinner() - homeViewModel.saveLunchEvaluation("DS", "hate") - } - if (MyongsikApplication.prefs.getUserArea() == "H") { - - DINNER_H = "hate" - getHateChangeDinner() - - homeViewModel.saveLunchEvaluation("DH", "hate") - } - } - }, - noClickListener = { - - } - ) - } - } else { - holder.itemView.setOnClickListener(null) - } } override fun getItemCount(): Int { diff --git a/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/food/HomeFragment.kt b/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/food/HomeFragment.kt index 260280e0..e9c31390 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/food/HomeFragment.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/food/HomeFragment.kt @@ -65,7 +65,6 @@ class HomeFragment : BaseFragment() { initData() initViewPager() initViews() - setEvaluationData() chekNetwork() checkWeekend() } @@ -113,7 +112,7 @@ class HomeFragment : BaseFragment() { } with(binding) { - viewPager2.adapter = MyPagerAdapter(chunkedList, homeViewModel) + viewPager2.adapter = MyPagerAdapter(chunkedList) viewPager2.orientation = ViewPager2.ORIENTATION_HORIZONTAL setCurrentPage(initDate) indicator.setViewPager(viewPager2) @@ -222,27 +221,6 @@ class HomeFragment : BaseFragment() { }) } - //하루가 지났을 때 AlarmManager 가 실행되면서 DataStore 가 초기화됐을 때 - private fun setEvaluationData() { - if (MyongsikApplication.prefs.getString("key", "null") == "gg") { //하루가 지나고 DataStore 초기화 후 prefs 값을 변경시켜줌으로써 다음에는 초기화 안되게 막아둠 - initEvaluation() - } else { - getEvaluation() - } - } - - private fun initEvaluation() { - LUNCH_A_GOOD = "" - LUNCH_B_GOOD = "" - DINNER = "" - LUNCH_A_GOOD_S = "" - DINNER_S = "" - LUNCH_A_GOOD_H = "" - DINNER_H = "" - defaultDataStore() - MyongsikApplication.prefs.setString("key", "todayStart") - } - //네트워크 연결 되어있는지 확인 private fun chekNetwork() { if (!NetworkUtils.getNetworkConnected(context)) { //실패했을 경우 @@ -323,26 +301,6 @@ class HomeFragment : BaseFragment() { binding.viewPager2.setCurrentItem(value - 1, false) } - //하루가 지났을 때 DataStore 를 초기화함 - private fun defaultDataStore() { - lifecycleScope.launch { - homeViewModel.defaultDataStore() - } - } - - //중식 평가 불러오기 - private fun getEvaluation() { - lifecycleScope.launch { //현재 불러온 값에 따라 값을 저장 - LUNCH_A_GOOD = homeViewModel.getLunchEvaluation() - LUNCH_B_GOOD = homeViewModel.getLunchBEvaluation() - DINNER = homeViewModel.getDinnerEvaluation() - DINNER_S = homeViewModel.getDinnerSEvaluation() - LUNCH_A_GOOD_S = homeViewModel.getLunchSEvaluation() - DINNER_H = homeViewModel.getDinnerHEvaluation() - LUNCH_A_GOOD_H = homeViewModel.getLunchHEvaluation() - } - } - private fun showBottomSheetDialog() { val binding = DialogBottomUpdateSheetBinding.inflate(layoutInflater) val bottomSheetDialog = BottomSheetDialog(requireContext()) diff --git a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/food/HomeViewModel.kt b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/food/HomeViewModel.kt index d5827268..5cc12c5b 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/food/HomeViewModel.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/food/HomeViewModel.kt @@ -53,48 +53,10 @@ class HomeViewModel @Inject constructor( } //DataStore - fun saveLunchEvaluation(type: String, value: String) = launch { - foodRepository.saveLunchEvaluation(type, value) - } - fun saveSortType(key: Preferences.Key, value: String) = launch { foodRepository.saveSortType(key, value) } - //DataStore 초기화 - suspend fun defaultDataStore() { - foodRepository.defaultDataStore() - } - - //중식 평가 불러오기 - suspend fun getLunchEvaluation() = withContext(Dispatchers.IO) { - foodRepository.getLunchEvaluation().first() - } - - suspend fun getLunchBEvaluation() = withContext(Dispatchers.IO) { - foodRepository.getLunchBEvaluation().first() - } - - suspend fun getDinnerEvaluation() = withContext(Dispatchers.IO) { - foodRepository.getDinnerEvaluation().first() - } - - suspend fun getLunchHEvaluation() = withContext(Dispatchers.IO) { - foodRepository.getLunchHEvaluation().first() - } - - suspend fun getDinnerHEvaluation() = withContext(Dispatchers.IO) { - foodRepository.getDinnerHEvaluation().first() - } - - suspend fun getLunchSEvaluation() = withContext(Dispatchers.IO) { - foodRepository.getLunchSEvaluation().first() - } - - suspend fun getDinnerSEvaluation() = withContext(Dispatchers.IO) { - foodRepository.getDinnerSEvaluation().first() - } - suspend fun getCurrentSortType() = withContext(Dispatchers.IO) { foodRepository.getCurrentSortType().first() } diff --git a/app/src/main/res/layout/item_home_today_food.xml b/app/src/main/res/layout/item_home_today_food.xml index a4f4916d..34f5a872 100644 --- a/app/src/main/res/layout/item_home_today_food.xml +++ b/app/src/main/res/layout/item_home_today_food.xml @@ -10,7 +10,7 @@ android:layout_width="match_parent" android:layout_height="0dp" android:background="@drawable/home_today_food_stroke" - app:layout_constraintBottom_toBottomOf="@+id/today_line_iv" + app:layout_constraintBottom_toBottomOf="@+id/today_food_1" app:layout_constraintStart_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -48,6 +48,7 @@ android:fontFamily="@font/notosans_regular" android:maxLines="3" android:paddingHorizontal="32dp" + android:paddingBottom="10dp" android:text="@string/food_list" android:textAlignment="center" android:textColor="#717171" @@ -56,92 +57,13 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/today_day_lunch_a" /> - - - - - - - - - - - - - - - - - - @@ -181,6 +103,7 @@ android:inputType="textMultiLine" android:maxLines="3" android:paddingHorizontal="32dp" + android:paddingBottom="10dp" android:text="@string/food_list" android:textAlignment="center" android:textColor="#717171" @@ -189,92 +112,13 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/today_day_lunch_b" /> - - - - - - - - - - - - - - - - - - @@ -315,6 +159,7 @@ android:fontFamily="@font/notosans_regular" android:maxLines="3" android:paddingHorizontal="32dp" + android:paddingBottom="10dp" android:text="@string/food_list" android:textAlignment="center" android:textColor="#717171" @@ -323,85 +168,6 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/today_day_afternoon" /> - - - - - - - - - - - - - - - - - - diff --git a/pull_request_template.md b/pull_request_template.md new file mode 100644 index 00000000..7389ad38 --- /dev/null +++ b/pull_request_template.md @@ -0,0 +1,11 @@ +## 주요 작업 내용 +- 이슈번호 : +- + +## 작업 내용 정리 +- + +## 변경점 +- + +## Notice