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
/** | |
* A static factory method to request permission from activity. | |
* | |
* @param activity an instance of [AppCompatActivity] | |
* @param requestId Request ID for permission request | |
* @param permissions Permission(s) to request | |
* | |
* @return [PermissionResult] | |
* | |
* Suspends the coroutines until result is available. |
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
/** | |
* A static method to request permission from activity. | |
* Your activity must implement [PermissionObserver] | |
* | |
* @param activity an instance of [AppCompatActivity] which is also [PermissionObserver] | |
* @param requestId Request ID for permission request | |
* @param permissions Permission(s) to request | |
* | |
* @throws [IllegalArgumentException] if your activity doesn't implement [PermissionObserver] | |
*/ |
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
/** | |
* Interface definition for a callback to get [LiveData] of [PermissionResult] | |
* | |
* Implement this interface to get [LiveData] for observing permission request result. | |
*/ | |
interface PermissionObserver { | |
fun setupObserver(permissionResultLiveData: LiveData<PermissionResult>) | |
} |
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
override fun setupObserver(permissionResultLiveData: LiveData<PermissionResult>) { | |
permissionResultLiveData.observe(this, Observer<PermissionResult> { | |
when (it) { | |
is PermissionResult.PermissionGranted -> { | |
if (it.requestId == REQUEST_ID) { | |
//Add your logic here after user grants permission(s) | |
} | |
} | |
is PermissionResult.PermissionDenied -> { | |
if (it.requestId == REQUEST_ID) { |
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
PermissionManager.requestPermissions( | |
this, | |
REQUEST_ID, | |
Manifest.permission.ACCESS_FINE_LOCATION, | |
Manifest.permission.READ_CONTACTS | |
) |
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
sealed class PermissionResult(val requestCode: Int) { | |
class PermissionGranted(requestCode: Int) : PermissionResult(requestCode) | |
class PermissionDenied( | |
requestCode: Int, | |
val deniedPermissions: List<String> | |
) : PermissionResult(requestCode) | |
class ShowRational(requestCode: Int) : PermissionResult(requestCode) | |
class PermissionDeniedPermanently( | |
requestCode: Int, |
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
. | |
. | |
. | |
launch { | |
//CoroutineScope | |
val permissionResult = PermissionManager.requestPermissions( //Suspends the coroutine | |
this@Fragment, | |
REQUEST_ID, | |
Manifest.permission.ACCESS_FINE_LOCATION, |
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
class Trie { | |
data class Node(var word: String? = null, val childNodes: MutableMap<Char, Node> = mutableMapOf()) | |
private val root = Node() | |
fun insert(word: String) { | |
var currentNode = root | |
for (char in word) { | |
if (currentNode.childNodes[char] == null) { |
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
fun demo { | |
print("Hi there") | |
} |
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
val springAnimation = view.springAnimationOf(DynamicAnimation.TRANSLATION_X) { | |
stiffness = STIFFNESS_MEDIUM | |
dampingRatio = DAMPING_RATIO_MEDIUM_BOUNCY | |
} |