forked from yy0ung/nibobnebob
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#86 feat : 위치 권한 확인 로직, Extensions 함수로 분리
- Loading branch information
Showing
2 changed files
with
66 additions
and
39 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/UiExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,54 @@ | ||
package com.avengers.nibobnebob.presentation.ui | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.pm.PackageManager | ||
import android.location.LocationManager | ||
import android.provider.Settings | ||
import android.view.View | ||
import android.view.inputmethod.InputMethodManager | ||
import android.widget.Toast | ||
import androidx.core.content.ContextCompat | ||
|
||
internal fun Context.hideKeyboard(view: View) { | ||
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager | ||
imm.hideSoftInputFromWindow(view.windowToken, 0) | ||
} | ||
|
||
internal fun Context.requestLocationPermission( | ||
permissionList: Array<String>, | ||
onLauncherStart: () -> Unit, | ||
onTrackingChangeListener: (Boolean) -> Unit | ||
) { | ||
var permissionFlag = false | ||
permissionList.forEach { permission -> | ||
permissionFlag = ContextCompat.checkSelfPermission( | ||
this, | ||
permission | ||
) == PackageManager.PERMISSION_GRANTED | ||
} | ||
|
||
if (permissionFlag) { | ||
checkLocationIsOn(){ | ||
onTrackingChangeListener(it) | ||
} | ||
} else { | ||
onLauncherStart() | ||
Toast.makeText(this, "위치권한을 허용해주세요", Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
|
||
|
||
internal fun Context.checkLocationIsOn( | ||
onTrackingChangeListener: (Boolean) -> Unit | ||
) { | ||
val locationManager = | ||
getSystemService(Context.LOCATION_SERVICE) as LocationManager | ||
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { | ||
onTrackingChangeListener(true) | ||
} else { | ||
startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)) | ||
Toast.makeText(this, "휴대폰 GPS를 켜주세요", Toast.LENGTH_SHORT).show() | ||
onTrackingChangeListener(false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters