Skip to content

Instantly share code, notes, and snippets.

View Kashif-E's full-sized avatar
:octocat:

Kashif Mehmood Kashif-E

:octocat:
View GitHub Profile
/**
* 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
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) {
open class BaseViewModel : ViewModel() {
var responseMessage: MutableSharedFlow<Resource.CustomMessages> = MutableSharedFlow()
protected fun onResponseComplete(message : Resource.CustomMessages){
viewModelScope.launch {
responseMessage.emit(message)
}
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)
}
/**
* 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)
@Kashif-E
Kashif-E / FindTheIndexWhereRightAndLeftBracketsAreEqual.kt
Last active August 15, 2024 11:40
Kotlin programe to find the index in a string where right and left Paranthesis are equal
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")
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 {
fun shareImages(
contextActibity: Activity,
listOfImages: List<String>,
description: String? = null,
price: String? = null,
name: String? = "",
details: String = "",
catalogName: String = ""
) {
Log.e("list", listOfImages.toString())
@Kashif-E
Kashif-E / loadstatelistener.kt
Created September 21, 2021 06:56
load state listener for paging
/*
* Progress Updater
* */
adapter.addLoadStateListener { loadState ->
if (loadState.refresh is LoadState.Loading ||
loadState.append is LoadState.Loading)
// Show ProgressBar
else {
// Hide ProgressBar
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")