v1.1.1 - 전체 알람 온오프 스위치 및 해제 시 경고 팝업 적용, 앱 정보 화면 바운스 수정, 데이터 초기화 4단계 세분화
This commit is contained in:
@@ -29,9 +29,10 @@ object AlarmPermissionUtil {
|
||||
fun monitorAndAutoReturn(activity: Activity, isGrantedCheck: () -> Boolean) {
|
||||
monitorJob?.cancel()
|
||||
monitorJob = CoroutineScope(Dispatchers.Main).launch {
|
||||
delay(1000) // 설정 화면 전환 시간 대기
|
||||
var count = 0
|
||||
while (count < 150 && isActive) { // 최대 60초간 400ms 주기로 체크
|
||||
delay(400)
|
||||
while (count < 150 && isActive) { // 최대 60초간 500ms 주기로 체크
|
||||
delay(500)
|
||||
count++
|
||||
if (isGrantedCheck()) {
|
||||
try {
|
||||
|
||||
@@ -187,21 +187,19 @@ class FragmentSettingsAdditional : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
// 1. 개별 근무/알람 설정 전체 삭제
|
||||
binding.btnResetOverrides.setOnClickListener {
|
||||
androidx.appcompat.app.AlertDialog.Builder(requireContext())
|
||||
.setTitle("데이터 초기화")
|
||||
.setMessage("달력에서 개별적으로 바꾼 모든 근무와 알람 설정이 삭제됩니다. 계속하시겠습니까?")
|
||||
.setPositiveButton("초기화") { _, _ ->
|
||||
.setTitle("개별 근무/알람 설정 전체 삭제")
|
||||
.setMessage("달력에서 개별 변경한 모든 근무와 알람 일정이 삭제되고 기본값으로 복원됩니다. 계속하시겠습니까?")
|
||||
.setPositiveButton("삭제") { _, _ ->
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
val db = AppDatabase.getDatabase(requireContext())
|
||||
val dao = db.shiftDao()
|
||||
dao.clearOverrides()
|
||||
|
||||
// Immediately re-sync all alarms
|
||||
syncAllAlarms(requireContext())
|
||||
|
||||
Toast.makeText(requireContext(), "모든 개별 설정이 삭제되고 알람이 재설정되었습니다.", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(requireContext(), "개별 근무 및 알람 설정이 초기화되었습니다.", Toast.LENGTH_SHORT).show()
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(requireContext(), "초기화 실패: ${e.message}", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
@@ -210,6 +208,75 @@ class FragmentSettingsAdditional : Fragment() {
|
||||
.setNegativeButton("취소", null)
|
||||
.show()
|
||||
}
|
||||
|
||||
// 2. 개별 근무 삭제
|
||||
binding.btnResetShifts.setOnClickListener {
|
||||
androidx.appcompat.app.AlertDialog.Builder(requireContext())
|
||||
.setTitle("개별 근무 삭제")
|
||||
.setMessage("달력에서 개별 변경한 교대근무 일정만 삭제되고 기본 근무표로 복원됩니다. 계속하시겠습니까?")
|
||||
.setPositiveButton("삭제") { _, _ ->
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
val db = AppDatabase.getDatabase(requireContext())
|
||||
val dao = db.shiftDao()
|
||||
dao.clearOverrides()
|
||||
syncAllAlarms(requireContext())
|
||||
Toast.makeText(requireContext(), "개별 근무 변경 내역이 초기화되었습니다.", Toast.LENGTH_SHORT).show()
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(requireContext(), "초기화 실패: ${e.message}", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
.setNegativeButton("취소", null)
|
||||
.show()
|
||||
}
|
||||
|
||||
// 3. 알람 삭제
|
||||
binding.btnResetAlarms.setOnClickListener {
|
||||
androidx.appcompat.app.AlertDialog.Builder(requireContext())
|
||||
.setTitle("알람 삭제")
|
||||
.setMessage("등록된 모든 사용자 지정 알람이 삭제되고 기본 알람으로 초기화됩니다. 계속하시겠습니까?")
|
||||
.setPositiveButton("삭제") { _, _ ->
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
val db = AppDatabase.getDatabase(requireContext())
|
||||
val dao = db.shiftDao()
|
||||
dao.clearCustomAlarms()
|
||||
syncAllAlarms(requireContext())
|
||||
Toast.makeText(requireContext(), "등록된 알람이 모두 삭제되었습니다.", Toast.LENGTH_SHORT).show()
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(requireContext(), "삭제 실패: ${e.message}", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
.setNegativeButton("취소", null)
|
||||
.show()
|
||||
}
|
||||
|
||||
// 4. 전체 삭제 (완전 초기화)
|
||||
binding.btnResetAll.setOnClickListener {
|
||||
androidx.appcompat.app.AlertDialog.Builder(requireContext())
|
||||
.setTitle("전체 데이터 초기화")
|
||||
.setMessage("⚠️ 주의: 메모, 연차, 개별 근무, 알람을 포함한 모든 앱 데이터가 완전히 초기화됩니다.\n\n정말 전체 데이터를 초기화하시겠습니까?")
|
||||
.setPositiveButton("전체 초기화") { _, _ ->
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
val db = AppDatabase.getDatabase(requireContext())
|
||||
val dao = db.shiftDao()
|
||||
dao.clearOverrides()
|
||||
dao.clearMemos()
|
||||
dao.clearCustomAlarms()
|
||||
dao.clearAnnualLeave()
|
||||
syncAllAlarms(requireContext())
|
||||
Toast.makeText(requireContext(), "모든 데이터가 완전히 초기화되었습니다.", Toast.LENGTH_LONG).show()
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(requireContext(), "전체 초기화 실패: ${e.message}", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
.setNegativeButton("취소", null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -134,32 +134,72 @@ class FragmentSettingsAlarm : Fragment(), SharedPreferences.OnSharedPreferenceCh
|
||||
}
|
||||
|
||||
private val soundTitleCache = mutableMapOf<String?, String>()
|
||||
private var isUpdatingMasterSwitch = false
|
||||
|
||||
private fun updateMasterToggleUI(isEnabled: Boolean) {
|
||||
if (_binding == null) return
|
||||
isUpdatingMasterSwitch = true
|
||||
binding.masterSwitch.isChecked = isEnabled
|
||||
isUpdatingMasterSwitch = false
|
||||
|
||||
if (isEnabled) {
|
||||
binding.tvMasterStatus.text = "전체 알람 켜짐"
|
||||
binding.tvMasterStatus.setTextColor(ContextCompat.getColor(requireContext(), R.color.primary))
|
||||
binding.tvMasterStatus.backgroundTintList = android.content.res.ColorStateList.valueOf(Color.parseColor("#E3F2FD"))
|
||||
binding.tvMasterStatus.setTextColor(ContextCompat.getColor(requireContext(), R.color.text_primary))
|
||||
binding.ivMasterBell.imageTintList = android.content.res.ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.primary))
|
||||
} else {
|
||||
binding.tvMasterStatus.text = "전체 알람 꺼짐"
|
||||
binding.tvMasterStatus.setTextColor(ContextCompat.getColor(requireContext(), R.color.shift_red))
|
||||
binding.tvMasterStatus.backgroundTintList = android.content.res.ColorStateList.valueOf(Color.parseColor("#FFEBEE"))
|
||||
binding.tvMasterStatus.setTextColor(ContextCompat.getColor(requireContext(), R.color.text_secondary))
|
||||
binding.ivMasterBell.imageTintList = android.content.res.ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.text_secondary))
|
||||
}
|
||||
}
|
||||
|
||||
private fun showMasterAlarmOffConfirmationDialog() {
|
||||
val prefs = requireContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||
androidx.appcompat.app.AlertDialog.Builder(requireContext())
|
||||
.setTitle("전체 알람 끄기")
|
||||
.setMessage("전체 알람을 끄시겠습니까?\n모든 교대근무 알람 및 개별 알람이 정시에 울리지 않게 됩니다.")
|
||||
.setPositiveButton("끄기") { _, _ ->
|
||||
prefs.edit().putBoolean("master_alarm_enabled", false).apply()
|
||||
updateMasterToggleUI(false)
|
||||
Toast.makeText(requireContext(), "전체 알람이 꺼졌습니다.", Toast.LENGTH_SHORT).show()
|
||||
lifecycleScope.launch { syncAllAlarms(requireContext()) }
|
||||
}
|
||||
.setNegativeButton("취소") { dialog, _ ->
|
||||
// 스위치 원래대로 ON 복귀
|
||||
isUpdatingMasterSwitch = true
|
||||
binding.masterSwitch.isChecked = true
|
||||
isUpdatingMasterSwitch = false
|
||||
dialog.dismiss()
|
||||
}
|
||||
.setOnCancelListener {
|
||||
// 바깥 터치 시에도 원래대로 ON 복귀
|
||||
isUpdatingMasterSwitch = true
|
||||
binding.masterSwitch.isChecked = true
|
||||
isUpdatingMasterSwitch = false
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun setupListeners() {
|
||||
val prefs = requireContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||
|
||||
binding.tvMasterStatus.setOnClickListener {
|
||||
val isEnabled = !ShiftAlarmDefaults.isMasterAlarmEnabled(prefs)
|
||||
prefs.edit().putBoolean("master_alarm_enabled", isEnabled).apply()
|
||||
updateMasterToggleUI(isEnabled)
|
||||
|
||||
val message = if (isEnabled) "전체 알람이 켜졌습니다." else "전체 알람이 꺼졌습니다."
|
||||
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
|
||||
|
||||
// Resync immediately
|
||||
lifecycleScope.launch { syncAllAlarms(requireContext()) }
|
||||
binding.masterAlarmCard.setOnClickListener {
|
||||
binding.masterSwitch.performClick()
|
||||
}
|
||||
|
||||
binding.masterSwitch.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isUpdatingMasterSwitch) return@setOnCheckedChangeListener
|
||||
|
||||
if (isChecked) {
|
||||
// 바로 켜기
|
||||
prefs.edit().putBoolean("master_alarm_enabled", true).apply()
|
||||
updateMasterToggleUI(true)
|
||||
Toast.makeText(requireContext(), "전체 알람이 켜졌습니다.", Toast.LENGTH_SHORT).show()
|
||||
lifecycleScope.launch { syncAllAlarms(requireContext()) }
|
||||
} else {
|
||||
// 끌 때는 모달 확인 팝업
|
||||
showMasterAlarmOffConfirmationDialog()
|
||||
}
|
||||
}
|
||||
|
||||
binding.btnAddCustomAlarm.setOnClickListener {
|
||||
|
||||
@@ -233,46 +233,56 @@ class FragmentSettingsBasic : Fragment() {
|
||||
val prefs = requireContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||
|
||||
binding.btnBatteryOptimize.setOnClickListener {
|
||||
val isAlreadyGranted = AlarmPermissionUtil.getBatteryOptimizationStatus(requireContext())
|
||||
AlarmPermissionUtil.requestBatteryOptimization(requireActivity())
|
||||
AlarmPermissionUtil.monitorAndAutoReturn(requireActivity()) {
|
||||
AlarmPermissionUtil.getBatteryOptimizationStatus(requireContext())
|
||||
if (!isAlreadyGranted) {
|
||||
AlarmPermissionUtil.monitorAndAutoReturn(requireActivity()) {
|
||||
AlarmPermissionUtil.getBatteryOptimizationStatus(requireContext())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
binding.btnExactAlarm.setOnClickListener {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val isAlreadyGranted = AlarmPermissionUtil.getExactAlarmStatus(requireContext())
|
||||
val intent = Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM).apply {
|
||||
data = Uri.parse("package:${requireContext().packageName}")
|
||||
}
|
||||
requireActivity().startActivity(intent)
|
||||
AlarmPermissionUtil.monitorAndAutoReturn(requireActivity()) {
|
||||
AlarmPermissionUtil.getExactAlarmStatus(requireContext())
|
||||
if (!isAlreadyGranted) {
|
||||
AlarmPermissionUtil.monitorAndAutoReturn(requireActivity()) {
|
||||
AlarmPermissionUtil.getExactAlarmStatus(requireContext())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
binding.btnOverlayPermission.setOnClickListener {
|
||||
val isAlreadyGranted = AlarmPermissionUtil.getOverlayStatus(requireContext())
|
||||
AlarmPermissionUtil.requestOverlayPermission(requireActivity())
|
||||
AlarmPermissionUtil.monitorAndAutoReturn(requireActivity()) {
|
||||
AlarmPermissionUtil.getOverlayStatus(requireContext())
|
||||
if (!isAlreadyGranted) {
|
||||
AlarmPermissionUtil.monitorAndAutoReturn(requireActivity()) {
|
||||
AlarmPermissionUtil.getOverlayStatus(requireContext())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
binding.btnFullScreenIntent.setOnClickListener {
|
||||
val isAlreadyGranted = AlarmPermissionUtil.getFullScreenIntentStatus(requireContext())
|
||||
AlarmPermissionUtil.requestFullScreenIntentPermission(requireActivity())
|
||||
AlarmPermissionUtil.monitorAndAutoReturn(requireActivity()) {
|
||||
AlarmPermissionUtil.getFullScreenIntentStatus(requireContext())
|
||||
if (!isAlreadyGranted) {
|
||||
AlarmPermissionUtil.monitorAndAutoReturn(requireActivity()) {
|
||||
AlarmPermissionUtil.getFullScreenIntentStatus(requireContext())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
binding.btnPermissionSettings.setOnClickListener {
|
||||
// 앱 정보 상세 설정 화면은 일반 열람용이므로 자동 복귀를 걸지 않음
|
||||
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
|
||||
data = Uri.parse("package:${requireContext().packageName}")
|
||||
}
|
||||
requireActivity().startActivity(intent)
|
||||
AlarmPermissionUtil.monitorAndAutoReturn(requireActivity()) {
|
||||
AlarmPermissionUtil.isAllPermissionsGranted(requireContext())
|
||||
}
|
||||
}
|
||||
|
||||
binding.btnCheckUpdate.setOnClickListener {
|
||||
|
||||
Reference in New Issue
Block a user