Skip to content

Commit e0a5907

Browse files
committed
Fix : 알람 관련 버그 픽스
1 parent 877455e commit e0a5907

File tree

8 files changed

+63
-86
lines changed

8 files changed

+63
-86
lines changed

presentation/src/main/AndroidManifest.xml

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,17 @@
2020
android:dataExtractionRules="@xml/data_extraction_rules"
2121
android:fullBackupContent="@xml/backup_rules"
2222
android:icon="@mipmap/ic_bus"
23-
android:roundIcon="@mipmap/ic_bus_round"
2423
android:label="@string/app_name"
24+
android:roundIcon="@mipmap/ic_bus_round"
2525
android:supportsRtl="true"
26-
android:theme="@style/Theme.Splash"
2726
android:usesCleartextTraffic="true"
2827
tools:targetApi="31">
2928

30-
31-
<activity
32-
android:name=".TestActivity"
33-
android:excludeFromRecents="true"
34-
android:exported="true"
35-
android:launchMode="singleTop"
36-
android:showOnLockScreen="true">
37-
<intent-filter>
38-
<action android:name="android.intent.action.MAIN" />
39-
<category android:name="android.intent.category.DEFAULT" />
40-
</intent-filter>
41-
</activity>
42-
4329
<receiver
4430
android:name=".AlarmReceiver"
45-
android:enabled="true"/>
31+
android:enabled="true" />
4632

47-
<service
48-
android:name=".SoundService"/>
33+
<service android:name=".SoundService" />
4934

5035
<provider
5136
android:name="androidx.startup.InitializationProvider"
@@ -54,7 +39,10 @@
5439

5540
<activity
5641
android:name=".MainActivity"
57-
android:exported="true">
42+
android:excludeFromRecents="true"
43+
android:exported="true"
44+
android:showOnLockScreen="true"
45+
android:theme="@style/Theme.Splash">
5846

5947
<intent-filter>
6048
<action android:name="android.intent.action.MAIN" />

presentation/src/main/java/com/stop/AlarmFunctions.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.app.AlarmManager
44
import android.app.PendingIntent
55
import android.content.Context
66
import android.content.Intent
7-
import android.os.Build
87
import java.text.ParseException
98
import java.text.SimpleDateFormat
109
import java.util.*
@@ -20,11 +19,11 @@ class AlarmFunctions(
2019

2120
val receiverIntent = Intent(context, AlarmReceiver::class.java)
2221
receiverIntent.apply {
23-
putExtra("ALARM_REQUEST_CODE", alarmCode)
22+
putExtra("ALARM_CODE", alarmCode)
2423
putExtra("ALARM_CONTENT", alarmContent)
2524
}
2625

27-
val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
26+
val pendingIntent = if (isMoreThanSnow()) {
2827
PendingIntent.getBroadcast(context, alarmCode, receiverIntent, PendingIntent.FLAG_IMMUTABLE)
2928
} else {
3029
PendingIntent.getBroadcast(context, alarmCode, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT)
@@ -62,7 +61,7 @@ class AlarmFunctions(
6261
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
6362
val intent = Intent(context, AlarmReceiver::class.java)
6463

65-
pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
64+
pendingIntent = if (isMoreThanSnow()) {
6665
PendingIntent.getBroadcast(context, alarmCode, intent, PendingIntent.FLAG_IMMUTABLE)
6766
} else {
6867
PendingIntent.getBroadcast(context, alarmCode, intent, PendingIntent.FLAG_UPDATE_CURRENT)

presentation/src/main/java/com/stop/AlarmReceiver.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import androidx.core.app.NotificationCompat
1111
class AlarmReceiver : BroadcastReceiver() {
1212

1313
override fun onReceive(context: Context, intent: Intent) {
14-
val requestCode = intent.extras?.getInt("ALARM_REQUEST_CODE") ?: -1
14+
val alarmCode = intent.extras?.getInt("ALARM_CODE") ?: -1
1515
val alarmContent = intent.extras?.getString("ALARM_CONTENT") ?: ""
1616

1717
val soundServiceIntent = Intent(context, SoundService::class.java)
@@ -26,7 +26,8 @@ class AlarmReceiver : BroadcastReceiver() {
2626
}
2727
}
2828

29-
val pendingIntent = PendingIntent.getActivity(context, requestCode, Intent(context, TestActivity::class.java).apply {
29+
val pendingIntent = PendingIntent.getActivity(context, alarmCode, Intent(context, MainActivity::class.java).apply {
30+
putExtra("ALARM_CODE", alarmCode)
3031
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
3132
}, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
3233

@@ -47,7 +48,8 @@ class AlarmReceiver : BroadcastReceiver() {
4748
} else {
4849
context.startService(soundServiceIntent)
4950

50-
Intent(context, TestActivity::class.java).apply {
51+
Intent(context, MainActivity::class.java).apply {
52+
putExtra("ALARM_CODE", alarmCode)
5153
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
5254
context.startActivity(this)
5355
}

presentation/src/main/java/com/stop/MainActivity.kt

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package com.stop
22

3+
import android.app.KeyguardManager
34
import android.content.Context
5+
import android.content.Intent
46
import android.graphics.Rect
57
import android.os.Bundle
6-
import com.stop.databinding.ActivityMainBinding
78
import android.view.MotionEvent
89
import android.view.View
910
import android.view.WindowManager
1011
import android.view.inputmethod.InputMethodManager
1112
import android.widget.EditText
1213
import androidx.appcompat.app.AppCompatActivity
1314
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
15+
import androidx.navigation.fragment.NavHostFragment
16+
import com.stop.databinding.ActivityMainBinding
1417
import dagger.hilt.android.AndroidEntryPoint
1518

1619
@AndroidEntryPoint
@@ -19,11 +22,30 @@ class MainActivity : AppCompatActivity() {
1922

2023
override fun onCreate(savedInstanceState: Bundle?) {
2124
installSplashScreen()
25+
2226
super.onCreate(savedInstanceState)
2327

2428
binding = ActivityMainBinding.inflate(layoutInflater)
25-
hideStatusBar()
2629
setContentView(binding.root)
30+
31+
// TODO 버튼을 통해서 소리나 진동 끄기로 바꿔야함 !!
32+
val intent = Intent(this, SoundService::class.java)
33+
this.stopService(intent)
34+
35+
setStartDestination()
36+
hideStatusBar()
37+
showOverLockScreen()
38+
}
39+
40+
private fun setStartDestination() {
41+
intent.extras?.getInt("ALARM_CODE")?.let {
42+
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
43+
val inflater = navHostFragment.navController.navInflater
44+
val graph = inflater.inflate(R.navigation.nav_graph)
45+
graph.setStartDestination(R.id.alarmStartFragment)
46+
47+
navHostFragment.navController.graph = graph
48+
}
2749
}
2850

2951
private fun hideStatusBar() {
@@ -55,4 +77,20 @@ class MainActivity : AppCompatActivity() {
5577
this.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
5678
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
5779
}
80+
81+
private fun showOverLockScreen() {
82+
window.addFlags(
83+
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
84+
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
85+
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
86+
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
87+
)
88+
89+
if (isMoreThanOreoMr1()) {
90+
setShowWhenLocked(true)
91+
setTurnScreenOn(true)
92+
(getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).requestDismissKeyguard(this, null)
93+
}
94+
}
95+
5896
}

presentation/src/main/java/com/stop/SoundService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class SoundService : LifecycleService() {
7373

7474
private fun createNotification() {
7575
val notificationManager = this.getSystemService(NotificationManager::class.java)
76-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
76+
if (isMoreThanOreo()) {
7777
if (notificationManager.getNotificationChannel(DEFAULT_NOTIFICATION_CHANNEL_ID) == null) {
7878
NotificationChannel(DEFAULT_NOTIFICATION_CHANNEL_ID, DEFAULT_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT).apply {
7979
notificationManager.createNotificationChannel(this)
@@ -109,4 +109,4 @@ class SoundService : LifecycleService() {
109109
private const val DEFAULT_NOTIFICATION_ID = 124
110110
}
111111

112-
}
112+
}

presentation/src/main/java/com/stop/TestActivity.kt

Lines changed: 0 additions & 36 deletions
This file was deleted.

presentation/src/main/java/com/stop/ui/routedetail/RouteDetailFragment.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import android.view.LayoutInflater
66
import android.view.View
77
import android.view.ViewGroup
88
import androidx.fragment.app.activityViewModels
9+
import androidx.navigation.findNavController
10+
import com.stop.R
911
import com.stop.databinding.FragmentRouteDetailBinding
1012
import com.stop.ui.route.RouteViewModel
1113
import dagger.hilt.android.AndroidEntryPoint
@@ -40,7 +42,10 @@ class RouteDetailFragment : Fragment() {
4042
}
4143

4244
private fun initView() {
43-
45+
//TODO 임시 화면이동 로직
46+
binding.root.setOnClickListener {
47+
binding.root.findNavController().navigate(R.id.action_routeDetailFragment_to_alarmSetting)
48+
}
4449
}
4550

4651
override fun onDestroyView() {

presentation/src/main/res/layout/activity_test.xml

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)