This file contains hidden or 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 MapFragment : Fragment(), OnMapReadyCallback { | |
| companion object { | |
| private const val MAP_VIEW_BUNDLE_KEY = "mapview_bundle_key" | |
| } | |
| private var _binding: FragmentMapsBinding? = null | |
| private val binding: FragmentMapsBinding get() = _binding!! | |
| private var hasMapConfigured: Boolean = false |
This file contains hidden or 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
| import os | |
| def listFileName(directoryName): | |
| scandir_iterator = os.scandir(directoryName) | |
| for item in scandir_iterator: | |
| if os.path.isfile(item.path): | |
| print(item.name) | |
| if __name__ == "__main__": |
This file contains hidden or 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
| /** | |
| * With Given LiveData, produce a new LiveData, which will filter given one's emitted item with | |
| * supplied predicate. | |
| */ | |
| fun <T> LiveData<T>.filter(predicate: (T) -> Boolean): LiveData<T> { | |
| val filtered = MediatorLiveData<T>() | |
| filtered.addSource(this) { | |
| if (predicate(it)) { | |
| filtered.value = it | |
| } |
This file contains hidden or 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
| /** | |
| * With Given LiveData, produce a new LiveData, which will filter given one's emitted item with | |
| * supplied predicate. | |
| */ | |
| fun <T> LiveData<T>.filter(predicate: (T) -> Boolean): LiveData<T> { | |
| val filtered = MediatorLiveData<T>() | |
| filtered.addSource(this) { | |
| if (predicate(it)) { | |
| filtered.value = it | |
| } |
This file contains hidden or 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
| /** | |
| * Monitor the LiveData and when an emitted item satisfies predicate. Trigger an action, execute | |
| * the statements supplied. Then stop monitoring the LiveData. | |
| */ | |
| fun <T> LiveData<T>.doOnce(predicate: (T) -> Boolean, action: () -> Unit): LiveData<T> { | |
| val liveData: LiveData<T> = this | |
| val observer = object : Observer<T> { | |
| override fun onChanged(t: T) { | |
| if (predicate(t)) { | |
| action() |
This file contains hidden or 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
| /** | |
| * Monitor the LiveData and when an emitted item satisfies predicate. Trigger an action, | |
| * execute the statements supplied. | |
| */ | |
| fun <T> LiveData<T>.doWhen(predicate: (T) -> Boolean, action: () -> Unit): LiveData<T> { | |
| this.observeForever { | |
| if (predicate(it)) { | |
| action() | |
| } | |
| } |
This file contains hidden or 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
| /** | |
| * When an item is emitted by either of two LiveData, combine the latest item emitted by each | |
| * LiveData via a specified function and emit items based on the result of this function. | |
| */ | |
| @Suppress("UNCHECKED_CAST") | |
| fun <Y, T1, T2> LiveData<T1>.combineLatest(another: LiveData<T2>, | |
| combiner: (T1, T2) -> Y): LiveData<Y> { | |
| val mediatorLiveData = MediatorLiveData<Y>() | |
| var latestT1: T1? = null |
This file contains hidden or 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
| private val mediatorData = MediatorLiveData<List<Item>>().apply { | |
| this.addSource(itemListLiveData) { itemList -> | |
| val apiResponse = apiLiveData.value | |
| if (apiResponse != null) { | |
| this.value = combineItemListAndApi(itemList, apiResponse) | |
| } | |
| } | |
| this.addSource(apiLiveData) { apiResponse -> | |
| val itemList = itemListLiveData.value | |
| if (itemList != null) { |
This file contains hidden or 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 BigInteger private constructor(private val valueArray: CharArray, | |
| private val isPositive: Boolean) { | |
| constructor(strValue: String) : this(strValue.toProperCharArray(), | |
| strValue.isPositive()) | |
| fun getValueArray(): CharArray { | |
| return this.valueArray.copyOf() | |
| } |
This file contains hidden or 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
| /** | |
| * Counting Sort assumes every element of input array was inside [0,k] | |
| */ | |
| object CountingSort { | |
| fun sort(input: Array<Int>, upperLimit: Int): Array<Int> { | |
| val C = IntArray(upperLimit + 1) { 0 } | |
| val output = Array<Int>(input.size) { 0 } | |
| input.forEach { element -> | |
| C[element]++ |
NewerOlder