@@ -4,6 +4,8 @@ import android.Manifest
44import android.content.Intent
55import android.content.pm.PackageManager
66import android.os.Bundle
7+ import android.os.Handler
8+ import android.os.Looper
79import android.view.animation.DecelerateInterpolator
810import android.widget.Toast
911import androidx.core.app.ActivityCompat
@@ -32,13 +34,14 @@ import app.simple.positional.util.LocationExtension.getLocationStatus
3234import app.simple.positional.util.LocationPrompt.displayLocationSettingsRequest
3335
3436class MainActivity : BaseActivity (),
35- PermissionCallbacks ,
36- BottomSheetSlide ,
37- android.content.SharedPreferences .OnSharedPreferenceChangeListener {
37+ PermissionCallbacks ,
38+ BottomSheetSlide ,
39+ android.content.SharedPreferences .OnSharedPreferenceChangeListener {
3840
3941 private val defaultPermissionRequestCode = 123
4042 private lateinit var bottomBar: DynamicCornerRecyclerView
4143 private lateinit var bottomBarAdapter: BottomBarAdapter
44+ private val handler = Handler (Looper .getMainLooper())
4245
4346 override fun onCreate (savedInstanceState : Bundle ? ) {
4447 super .onCreate(savedInstanceState)
@@ -66,7 +69,7 @@ class MainActivity : BaseActivity(),
6669
6770 if (savedInstanceState.isNull()) {
6871 openFragment(FragmentPreferences .getCurrentTag(),
69- FragmentPreferences .getCurrentPage())
72+ FragmentPreferences .getCurrentPage())
7073 }
7174 }
7275
@@ -76,7 +79,10 @@ class MainActivity : BaseActivity(),
7679 return
7780 } else {
7881 if (MainPreferences .getShowRatingDialog()) {
79- Rate ().show(supportFragmentManager, " rate" )
82+ handler.postDelayed({
83+ Rate .newInstance()
84+ .show(supportFragmentManager, " rate" )
85+ }, 1500L )
8086 }
8187 }
8288 }
@@ -93,9 +99,14 @@ class MainActivity : BaseActivity(),
9399 stopService()
94100 }
95101
102+ override fun onDestroy () {
103+ super .onDestroy()
104+ handler.removeCallbacksAndMessages(null )
105+ }
106+
96107 private fun checkRunTimePermission () {
97108 if (ActivityCompat .checkSelfPermission(applicationContext, Manifest .permission.ACCESS_COARSE_LOCATION ) != PackageManager .PERMISSION_GRANTED &&
98- ActivityCompat .checkSelfPermission(applicationContext, Manifest .permission.ACCESS_FINE_LOCATION ) != PackageManager .PERMISSION_GRANTED ) {
109+ ActivityCompat .checkSelfPermission(applicationContext, Manifest .permission.ACCESS_FINE_LOCATION ) != PackageManager .PERMISSION_GRANTED ) {
99110 if (MainPreferences .getShowPermissionDialog()) {
100111 val permissionDialog = Permission .newInstance()
101112 permissionDialog.show(supportFragmentManager, " permission_info" )
@@ -115,7 +126,7 @@ class MainActivity : BaseActivity(),
115126 runService()
116127 } else {
117128 if (! ActivityCompat .shouldShowRequestPermissionRationale(this , Manifest .permission.ACCESS_FINE_LOCATION ) &&
118- ActivityCompat .shouldShowRequestPermissionRationale(this , Manifest .permission.ACCESS_COARSE_LOCATION )) {
129+ ActivityCompat .shouldShowRequestPermissionRationale(this , Manifest .permission.ACCESS_COARSE_LOCATION )) {
119130 Toast .makeText(this , R .string.no_location_permission_alert, Toast .LENGTH_LONG ).show()
120131 }
121132 }
@@ -159,41 +170,41 @@ class MainActivity : BaseActivity(),
159170 bottomBar.smoothScrollToPosition(position)
160171 getFragment(tag).let {
161172 supportFragmentManager.beginTransaction()
162- .setCustomAnimations(R .anim.dialog_in, R .anim.dialog_out)
163- .replace(R .id.containers, it, tag)
164- .commit()
173+ .setCustomAnimations(R .anim.dialog_in, R .anim.dialog_out)
174+ .replace(R .id.containers, it, tag)
175+ .commit()
165176 }
166177 }
167178
168179 private fun getFragment (name : String ): Fragment {
169180 when (name) {
170181 " clock" -> {
171182 return supportFragmentManager.findFragmentByTag(" clock" ) as Clock ?
172- ? : Clock .newInstance()
183+ ? : Clock .newInstance()
173184 }
174185 " compass" -> {
175186 return supportFragmentManager.findFragmentByTag(" compass" ) as Compass ?
176- ? : Compass .newInstance()
187+ ? : Compass .newInstance()
177188 }
178189 " location" -> {
179190 return supportFragmentManager.findFragmentByTag(" location" ) as GPS ?
180- ? : GPS .newInstance()
191+ ? : GPS .newInstance()
181192 }
182193 " trail" -> {
183194 return supportFragmentManager.findFragmentByTag(" trail" ) as Trail ?
184- ? : Trail .newInstance()
195+ ? : Trail .newInstance()
185196 }
186197 " level" -> {
187198 return supportFragmentManager.findFragmentByTag(" level" ) as Level ?
188- ? : Level .newInstance()
199+ ? : Level .newInstance()
189200 }
190201 " settings" -> {
191202 return supportFragmentManager.findFragmentByTag(" settings" ) as AppSettings ?
192- ? : AppSettings .newInstance()
203+ ? : AppSettings .newInstance()
193204 }
194205 else -> {
195206 return supportFragmentManager.findFragmentByTag(" location" ) as GPS ?
196- ? : GPS .newInstance()
207+ ? : GPS .newInstance()
197208 }
198209 }
199210 }
0 commit comments