Skip to content

Instantly share code, notes, and snippets.

View dracula151997's full-sized avatar

Hassan Mohammed dracula151997

View GitHub Profile
@dracula151997
dracula151997 / ChatRoute.kt
Created June 17, 2023 13:04
LazyColumn with different states
Column(
modifier = Modifier.fillMaxSize()
) {
StandardTopBar(title = stringResource(id = R.string.chats))
PullToRefreshBox(
state = pullToRefreshState,
refreshing = state.refreshing,
modifier = Modifier
.fillMaxSize()
.pullRefresh(state = pullToRefreshState)
public class LocationUtil {
public static int calculateDistanceInKm(double latitude1, double longitude1, double latitude2, double longitude2) {
Location location1 = new Location("location_1");
location1.setLatitude(latitude1);
location1.setLongitude(longitude1);
Location location2 = new Location("location_2");
location2.setLatitude(latitude2);
location2.setLongitude(longitude2);
return (int) Math.ceil(location1.distanceTo(location2) / 1000);
}
@dracula151997
dracula151997 / GradiantLinearProgressBar.kt
Created August 5, 2022 17:20
Create a graidnat linear progress bar
@Composable
fun GradiantLinearProgressBar(
gradientsColors: List<Color>,
percent: Double,
modifier: Modifier = Modifier,
preferredHeight: Dp = 9.dp,
shape: Shape = RoundedCornerShape(20.dp),
backgroundColor: Color = Color.Transparent,
) {
val context = LocalContext.current.resources
override fun getWordInfo(word: String): Flow<Resource<List<WordInfo>>> = flow {
emit(Resource.Loading())
val wordInfos = dao.getCachedWordInfos(word).map { it.toWordInfo() }
emit(Resource.Loading(wordInfos))
try {
val remoteWorkApi = api.getWorkInfo(word)
dao.deleteWordInfos(remoteWorkApi.map { it.word!! })
dao.insertWordInfo(remoteWorkApi.map { it.toWordInfoEntity() })
@dracula151997
dracula151997 / stopwatch_ClockTimestampProvider.kt
Created January 8, 2022 12:08
Gist for implementing a StopWatch in your app
package com.tutorial.runningapp.stopwatch
import javax.inject.Inject
class ClockTimestampProvider @Inject constructor() : TimestampProvider {
override fun getMilliseconds(): Long {
return System.currentTimeMillis()
}
}
@dracula151997
dracula151997 / ViewBindingDelegate.kt
Created September 16, 2021 07:41
Gist for Activity/Fragment databinding delegate
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import kotlin.properties.ReadOnlyProperty
@dracula151997
dracula151997 / ItemAdapter.java
Last active June 13, 2020 16:30
filter a recycler view data
package com.octopus.searchviewwithrecycler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;
import androidx.annotation.NonNull;
[
{"code":"ab","name":"Abkhaz","nativeName":"аҧсуа"},
{"code":"aa","name":"Afar","nativeName":"Afaraf"},
{"code":"af","name":"Afrikaans","nativeName":"Afrikaans"},
{"code":"ak","name":"Akan","nativeName":"Akan"},
{"code":"sq","name":"Albanian","nativeName":"Shqip"},
{"code":"am","name":"Amharic","nativeName":"አማርኛ"},
{"code":"ar","name":"Arabic","nativeName":"العربية"},
{"code":"an","name":"Aragonese","nativeName":"Aragonés"},
{"code":"hy","name":"Armenian","nativeName":"Հայերեն"},