Skip to content

Commit

Permalink
Merge branch 'main' into refactor/clean
Browse files Browse the repository at this point in the history
  • Loading branch information
SsongSik committed May 10, 2023
2 parents 62488c3 + fcaccfa commit 62b09fe
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 1,058 deletions.
15 changes: 0 additions & 15 deletions app/src/main/java/com/myongsik/myongsikandroid/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,10 @@ interface FoodRepository {
suspend fun getOneRestaurant(storeId : Int) : Response<ResponseOneRestaurant>

//DataStore
suspend fun saveLunchEvaluation(type: String, evaluation: String)

suspend fun saveSortType(key: Preferences.Key<String>, value: String)

suspend fun saveWidgetType(type : String)

suspend fun defaultDataStore()

suspend fun getLunchEvaluation(): Flow<String>

suspend fun getLunchBEvaluation(): Flow<String>

suspend fun getDinnerEvaluation(): Flow<String>

suspend fun getLunchSEvaluation(): Flow<String>

suspend fun getDinnerSEvaluation(): Flow<String>

suspend fun getLunchHEvaluation(): Flow<String>

suspend fun getDinnerHEvaluation(): Flow<String>

suspend fun getCurrentSortType(): Flow<String>

suspend fun getCurrentWidgetType(): Flow<String?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@ 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.*
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
Expand Down Expand Up @@ -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<String>, value: String) {
dataStore.edit { prefs ->
prefs[key] = value
Expand All @@ -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<String> {
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<String> {
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<String> {
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<String> {
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<String> {
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<String> {
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<String> {
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<String> {
return dataStore.data //data 메서드
.catch { exception ->
Expand Down
Loading

0 comments on commit 62b09fe

Please sign in to comment.