Skip to content

Commit

Permalink
fix alarm slide not working properly
Browse files Browse the repository at this point in the history
update images and texts
  • Loading branch information
newhinton committed Oct 18, 2023
1 parent 3cff414 commit 69c7a7b
Show file tree
Hide file tree
Showing 5 changed files with 278 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class OnboardingActivity : AppIntro2() {
} else {
false
}
} else if(permission == Manifest.permission.WRITE_EXTERNAL_STORAGE) {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Environment.isExternalStorageManager()
} else {
ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
}
} else {
return context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED
}
Expand All @@ -65,6 +71,7 @@ class OnboardingActivity : AppIntro2() {
private var storageRequested = false
private var storageGranted = false
private var alarmRequested = false
private var alarmGranted = false

private var color = R.color.intro_color1

Expand Down Expand Up @@ -122,7 +129,7 @@ class OnboardingActivity : AppIntro2() {
AppIntroFragment.newInstance(
title = getString(R.string.intro_permission_changed_title),
description = getString(R.string.intro_permission_changed_description),
imageDrawable = R.drawable.undraw_the_world_is_mine,
imageDrawable = R.drawable.undraw_completion,
backgroundColor = resources.getColor(color)
))
switchColor()
Expand All @@ -131,7 +138,7 @@ class OnboardingActivity : AppIntro2() {
}


if(!checkExternalStorageManagerPermission()) {
if(!checkGenericPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
addSlide(
AppIntroFragment.newInstance(
title = getString(R.string.intro_storage_title),
Expand Down Expand Up @@ -169,7 +176,7 @@ class OnboardingActivity : AppIntro2() {
AppIntroFragment.newInstance(
title = getString(R.string.intro_alarms_title),
description = getString(R.string.intro_alarms_description),
imageDrawable = R.drawable.undraw_post_online,
imageDrawable = R.drawable.undraw_time_management,
backgroundColor = resources.getColor(color),
))
switchColor()
Expand Down Expand Up @@ -209,21 +216,21 @@ class OnboardingActivity : AppIntro2() {
return true
}

if (isAlarmSlide && alarmRequested) {
if (isAlarmSlide && alarmGranted) {
return true
}

if(isStorageSlide) {
if(checkExternalStorageManagerPermission()){
if(checkGenericPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)){
storageGranted = true
return true
}
tryGrantingAllStorageAccess()
requestStoragePermission()
}

if(isAlarmSlide) {
if(checkGenericPermission(this, Manifest.permission.SCHEDULE_EXACT_ALARM)){
alarmRequested = true
alarmGranted = true
return true
}
requestAlarmPermission()
Expand All @@ -244,13 +251,12 @@ class OnboardingActivity : AppIntro2() {
finish()
}

private fun tryGrantingAllStorageAccess() {
private fun requestStoragePermission() {
if(storageRequested) {
return
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {

val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
intent.data = Uri.fromParts(
"package",
Expand All @@ -267,38 +273,58 @@ class OnboardingActivity : AppIntro2() {
storageRequested = true
}

private fun checkExternalStorageManagerPermission(): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Environment.isExternalStorageManager()
} else {
ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
private fun requestAlarmPermission(){
if (alarmRequested) {
return
}
startActivity(Intent(ACTION_REQUEST_SCHEDULE_EXACT_ALARM))
alarmRequested = true
}

override fun onResume() {
super.onResume()

if(isStorageSlide) {
if(checkExternalStorageManagerPermission()){
Toasty.success(this, getString(R.string.intro_manage_external_storage_granted), Toast.LENGTH_SHORT, true).show()
if(checkGenericPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)){
storageGranted = true
goToNextSlide()
} else {
Toasty.info(this, getString(R.string.intro_manage_external_storage_failed), Toast.LENGTH_LONG, true).show()
denied(Manifest.permission.WRITE_EXTERNAL_STORAGE)
storageRequested = false
}
}

if(isAlarmSlide) {

if(checkGenericPermission(this, Manifest.permission.SCHEDULE_EXACT_ALARM)){
alarmGranted = true
goToNextSlide()
} else {
denied(Manifest.permission.SCHEDULE_EXACT_ALARM)
alarmRequested = false
}
}
}

private fun requestAlarmPermission(){
if (alarmRequested) {
return
override fun onUserDeniedPermission(permissionName: String) {
super.onUserDeniedPermission(permissionName)
denied(permissionName)

}

override fun onUserDisabledPermission(permissionName: String) {
super.onUserDisabledPermission(permissionName)
denied(permissionName)
}
private fun denied(permissionName: String){
if(permissionName == Manifest.permission.POST_NOTIFICATIONS) {
Toasty.info(this, getString(R.string.intro_notifications_denied), Toast.LENGTH_SHORT, true).show()
}
startActivity(Intent(ACTION_REQUEST_SCHEDULE_EXACT_ALARM))
if(permissionName == Manifest.permission.WRITE_EXTERNAL_STORAGE) {
Toasty.info(this, getString(R.string.intro_write_external_storage_denied), Toast.LENGTH_LONG, true).show()
}
//if(permissionName == Manifest.permission.SCHEDULE_EXACT_ALARM) {
// Toasty.info(this, getString(R.string.intro_alarms_denied), Toast.LENGTH_SHORT, true).show()
//}
}

private fun switchColor() {
Expand Down
86 changes: 86 additions & 0 deletions app/src/main/res/drawable/undraw_completion.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="668.6dp"
android:height="607.38dp"
android:viewportWidth="668.6"
android:viewportHeight="607.38">
<path
android:pathData="m385.32,606.19h-193.12c-28.09,0 -50.94,-22.85 -50.94,-50.94V50.94c0,-28.09 22.85,-50.94 50.94,-50.94h193.12c28.09,0 50.94,22.85 50.94,50.94v504.31c0,28.09 -22.85,50.94 -50.94,50.94Z"
android:strokeWidth="0"
android:fillColor="#d7d7d8"/>
<path
android:pathData="m385.46,592.4h-193.4c-20.79,0 -37.71,-16.92 -37.71,-37.71V50.51c0,-20.79 16.92,-37.71 37.71,-37.71h193.4c20.79,0 37.71,16.92 37.71,37.71v504.18c0,20.79 -16.92,37.71 -37.71,37.71Z"
android:strokeWidth="0"
android:fillColor="#fff"/>
<path
android:pathData="m316.1,46.36h-54.69c-7.22,0 -13.09,-5.87 -13.09,-13.09s5.87,-13.09 13.09,-13.09h54.69c7.22,0 13.09,5.87 13.09,13.09s-5.87,13.09 -13.09,13.09Z"
android:strokeWidth="0"
android:fillColor="#d7d7d8"/>
<path
android:pathData="m301.5,279.12v35.95h-103.83c-9.91,0 -17.98,-8.06 -17.98,-17.98s8.07,-17.97 17.98,-17.97h103.83Z"
android:strokeWidth="0"
android:fillColor="#fbca1e"/>
<path
android:pathData="m379.85,279.12h-182.18c-9.91,0 -17.98,8.06 -17.98,17.97s8.07,17.98 17.98,17.98h182.18c9.92,0 17.98,-8.06 17.98,-17.98s-8.06,-17.97 -17.98,-17.97ZM379.85,309.07h-182.18c-6.6,0 -11.98,-5.37 -11.98,-11.98s5.38,-11.97 11.98,-11.97h182.18c6.61,0 11.98,5.37 11.98,11.97s-5.37,11.98 -11.98,11.98Z"
android:strokeWidth="0"
android:fillColor="#d7d7d8"/>
<path
android:pathData="m668.6,606.19c0,0.66 -0.53,1.19 -1.19,1.19H1.19c-0.66,0 -1.19,-0.53 -1.19,-1.19s0.53,-1.19 1.19,-1.19h666.22c0.66,0 1.19,0.53 1.19,1.19Z"
android:strokeWidth="0"
android:fillColor="#2e2e43"/>
<path
android:pathData="M507.92,550.16l17.15,-10.97l15.56,24.33l-17.15,10.97z"
android:strokeWidth="0"
android:fillColor="#f3a3a6"/>
<path
android:pathData="M470.67,212.1l-21.67,7.4l-0.34,-31.29l19.72,-0.22l2.29,24.11z"
android:strokeWidth="0"
android:fillColor="#f3a3a6"/>
<path
android:pathData="M451.19,175.18m-21.67,0a21.67,21.67 0,1 1,43.34 0a21.67,21.67 0,1 1,-43.34 0"
android:strokeWidth="0"
android:fillColor="#f3a3a6"/>
<path
android:pathData="m457.12,172.97c-3.62,-0.07 -6.05,-3.7 -7.5,-7.04 -1.45,-3.32 -2.94,-7.16 -6.31,-8.51 -2.76,-1.1 -7.52,6.58 -9.72,4.58 -2.29,-2.09 -0.2,-13.01 2.19,-14.98s5.67,-2.39 8.75,-2.58c7.55,-0.43 15.14,0.09 22.56,1.56 4.58,0.9 9.32,2.29 12.65,5.56 4.23,4.15 5.37,10.47 5.73,16.38 0.38,6.05 0.09,12.39 -2.79,17.73 -2.89,5.33 -9,9.3 -14.93,8.02 -0.63,-3.21 -0.07,-6.5 0.13,-9.78 0.2,-3.26 -0.09,-6.78 -2.11,-9.36s-6.28,-3.56 -8.57,-1.23"
android:strokeWidth="0"
android:fillColor="#2f2e43"/>
<path
android:pathData="m483.86,180.18c2.15,-1.61 4.72,-2.97 7.39,-2.67 2.89,0.31 5.35,2.67 6.12,5.47s-0.03,5.9 -1.78,8.22 -4.38,3.86 -7.18,4.65c-1.62,0.46 -3.39,0.65 -4.95,0 -2.29,-0.96 -3.55,-3.85 -2.68,-6.18"
android:strokeWidth="0"
android:fillColor="#2f2e43"/>
<path
android:pathData="m403.22,384.9c-1.36,7.13 1.35,13.61 6.07,14.46 4.71,0.85 9.64,-4.25 11.01,-11.38 0.59,-2.84 0.46,-5.78 -0.38,-8.57l16.67,-111.76 -22.46,-3.96 -7.39,113.36c-1.81,2.32 -3.02,5.01 -3.52,7.88h0v-0.03Z"
android:strokeWidth="0"
android:fillColor="#f3a3a6"/>
<path
android:pathData="m448.6,205.14l-15.3,0.17c-10.8,1.75 -13.67,7.56 -16,18.24 -3.57,16.29 -8.13,38 -7.17,38.3 1.53,0.5 27.7,12.46 40.95,9.5l-2.47,-66.21h-0.01Z"
android:strokeWidth="0"
android:fillColor="#fbca1e"/>
<path
android:pathData="M447.03,560.58l20.36,-0.23l0.32,28.88l-20.36,0.23z"
android:strokeWidth="0"
android:fillColor="#f3a3a6"/>
<path
android:pathData="m427.67,607.17c-2.15,0.03 -4.04,0 -5.48,-0.12 -5.42,-0.43 -10.61,-4.37 -13.24,-6.67 -1.18,-1.03 -1.57,-2.71 -0.98,-4.15h0c0.42,-1.03 1.28,-1.82 2.36,-2.15l14.25,-4.24 22.97,-15.87 0.26,0.46c0.1,0.17 2.42,4.24 3.21,7 0.3,1.05 0.24,1.92 -0.2,2.6 -0.3,0.47 -0.72,0.75 -1.06,0.92 0.42,0.43 1.74,1.31 5.8,1.91 5.9,0.88 7.09,-5.26 7.13,-5.52l0.04,-0.21 0.17,-0.12c2.79,-1.85 4.5,-2.68 5.1,-2.51 0.38,0.1 0.99,0.29 2.85,16.93 0.17,0.52 1.39,4.34 0.63,8.02 -0.82,4 -18.27,2.81 -21.75,2.54 -0.1,0.01 -13.14,1.09 -22.08,1.18h0.03,-0.01Z"
android:strokeWidth="0"
android:fillColor="#2f2e43"/>
<path
android:pathData="m502.84,602.37c-2.39,0.03 -4.59,-0.24 -6.16,-0.5 -1.54,-0.26 -2.76,-1.47 -3.02,-3.01h0c-0.2,-1.11 0.13,-2.22 0.86,-3.06l9.84,-11.14 11.08,-25.62 0.47,0.25c0.17,0.09 4.29,2.32 6.43,4.24 0.81,0.73 1.22,1.5 1.22,2.32 0,0.56 -0.21,1.02 -0.42,1.33 0.59,0.14 2.17,0.18 5.93,-1.45 5.47,-2.38 3.23,-8.22 3.13,-8.45l-0.08,-0.2 0.09,-0.18c1.39,-3.04 2.41,-4.66 3,-4.84 0.38,-0.1 0.99,-0.29 11.38,12.85 0.42,0.35 3.48,2.94 4.78,6.46 1.41,3.83 -14,12.05 -17.12,13.66 -0.09,0.08 -16.2,12.05 -22.82,15.48 -2.63,1.36 -5.76,1.81 -8.61,1.83l0.03,0.03h-0.01Z"
android:strokeWidth="0"
android:fillColor="#2f2e43"/>
<path
android:pathData="m479.66,318.62l-57,0.63 -4.58,53.08 24.81,195.68 29.1,-0.33 -12.89,-113.03 48.34,101.65 25.66,-18.4 -37.92,-94.98s12.25,-83.24 1.67,-103.82c-10.57,-20.58 -17.18,-20.51 -17.18,-20.51v0.03h-0.01Z"
android:strokeWidth="0"
android:fillColor="#2f2e43"/>
<path
android:pathData="M508.04,321.54l-90.53,1.01l25.86,-117.34l39.45,-0.45l25.22,116.78z"
android:strokeWidth="0"
android:fillColor="#fbca1e"/>
<path
android:pathData="m516.88,383.64c1.52,7.11 -1.05,13.64 -5.74,14.59 -4.7,0.96 -9.74,-4.03 -11.25,-11.14 -0.65,-2.83 -0.59,-5.77 0.18,-8.58l-19.16,-111.37 22.36,-4.46 9.91,113.18c1.86,2.28 3.13,4.95 3.7,7.8h0v-0.02Z"
android:strokeWidth="0"
android:fillColor="#f3a3a6"/>
<path
android:pathData="m467.53,204.93l15.3,-0.17c10.83,1.52 13.83,7.26 16.41,17.89 3.93,16.21 8.96,37.8 8.02,38.13 -1.53,0.52 -27.41,13.06 -40.72,10.4l1.01,-66.25h-0.02Z"
android:strokeWidth="0"
android:fillColor="#fbca1e"/>
</vector>
Loading

0 comments on commit 69c7a7b

Please sign in to comment.