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
/** | |
* Used as a wrapper for data that is exposed via a LiveData that represents an event. | |
*/ | |
open class Event<out T>(private val content: T) { | |
@Suppress("MemberVisibilityCanBePrivate") | |
var hasBeenHandled = false | |
private set // Allow external read but not write |
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 UserRepository(private val responseHandler: ResponseHandler) { | |
suspend fun stimulateSocketTimeout() = flow { | |
//stimulate a network call | |
kotlinx.coroutines.delay(500) | |
emit( | |
//stimulate a failed network response | |
if (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
open class BaseViewModel : ViewModel() { | |
var responseMessage: MutableSharedFlow<Resource.CustomMessages> = MutableSharedFlow() | |
protected fun onResponseComplete(message : Resource.CustomMessages){ | |
viewModelScope.launch { | |
responseMessage.emit(message) | |
} |
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
sealed class Resource<T>( | |
val data: T? = null, | |
val error : String = ": | |
) { | |
class Success<T>(data: T?) : Resource<T>(data) | |
class Loading<T> : Resource<T>() | |
class Error<T>(messages: String):Resource<T>(error = messages) | |
} |
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
/** | |
* A generic class that holds a value with its loading status. | |
* @param <T> | |
</T> */ | |
sealed class Resource<T>( | |
val data: T? = null, | |
val error : CustomMessages= CustomMessages.SomethingWentWrong("Something Went Wrong") | |
) { | |
class Success<T>(data: T?) : Resource<T>(data) |
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
fun main() { | |
val str = "()))(()" | |
str.forEachIndexed { index, _ -> | |
val str1 = str.substring(0, index) | |
val str2 = str.substring(index, str.length) | |
println("str1s $str1") | |
println("str2 $str2") |
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
def final packageId = "com.app" | |
def versionPropFile = rootProject.file('version.properties') | |
def versionProps = new Properties() | |
versionProps.load(new FileInputStream(versionPropFile)) | |
android { | |
compileSdkVersion 31 | |
buildToolsVersion "30.0.3" | |
defaultConfig { |
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
/* | |
* Progress Updater | |
* */ | |
adapter.addLoadStateListener { loadState -> | |
if (loadState.refresh is LoadState.Loading || | |
loadState.append is LoadState.Loading) | |
// Show ProgressBar | |
else { | |
// Hide ProgressBar |
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
entityExtractor | |
.annotate(params) | |
.addOnSuccessListener { entityAnnotation -> | |
for (entitiy in entityAnnotation) { | |
val listOfEntities = entitiy.entities | |
for (entity in listOfEntities) { | |
when (entity.type) { | |
Entity.TYPE_ADDRESS -> { | |
binding.textView.append("address " + entitiy.annotatedText + "\n") |