Skip to content

Instantly share code, notes, and snippets.

View Shivamdhuria's full-sized avatar

Shivam Dhuria Shivamdhuria

View GitHub Profile
adb shell settings put global window_animation_scale 1
adb shell settings put global transition_animation_scale 1
adb shell settings put global animator_duration_scale 1
adb shell settings put global window_animation_scale 10
adb shell settings put global transition_animation_scale 10
adb shell settings put global animator_duration_scale 10
private fun subscribeObservers() {
viewModel.liveDateFetch.observe(this, Observer {
when (it) {
is ResultWrapper.Loading -> showLoading(it.isLoading)
is ResultWrapper.NetworkError -> showError()
is ResultWrapper.Success<*> -> {
animation_loading.visibility = View.INVISIBLE
scroll_root.fullScroll(View.FOCUS_DOWN)
}
}
<androidx.core.widget.NestedScrollView
android:id="@+id/scroll_root"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/loadMore"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/search">
<LinearLayout
android:layout_width="match_parent"
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="@raw/splash_animation"
@Query("SELECT * FROM dog WHERE breed LIKE '%' || :search || '%'")
fun getSearchedDogs(search: String?): Flow<List<Dog>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun save(dog: Dog)
fun getSearchedDogs(search: String): Flow<List<Dog>> {
return dogDao.getSearchedDogs(search) //Get searched dogs from Room Database
//Combine the result with another flow
.combine(topBreedsFlow) { dogs, topDogs ->
dogs.applyToDog(topDogs)
}
.flowOn(Dispatchers.Default)
//Return the latest values
.conflate()
}
private val searchChanel = ConflatedBroadcastChannel<String>()
//We will use a ConflatedBroadcastChannel as this will only broadcast
//the most recent sent element to all the subscribers
fun setSearchQuery(search: String) {
//We use .offer() to send the element to all the subscribers.
searchChanel.offer(search)
}
//Observe this live Data from view and submit the list in adapter.
search.setOnQueryTextListener(object : SearchView.OnQueryTextListener, androidx.appcompat.widget.SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
return true
}
override fun onQueryTextChange(newText: String?): Boolean {
newText?.let {
//Pass Search Query to this function in viewmodel
viewModel.setSearchQuery(it)
}
livedata {
while(true){
emit(service.getLikes())
delay(10000)
}
}