Skip to content

Instantly share code, notes, and snippets.

View alvindizon's full-sized avatar
🎯
Focusing

Alvin Dizon alvindizon

🎯
Focusing
View GitHub Profile
@marcellogalhardo
marcellogalhardo / SavedStateHandle+StateFlow.kt
Last active July 23, 2023 23:46
A helper function to let you expose a MutableStateFlow from a SavedStateHandle.
/**
* Returns a [StateFlow] that access data associated with the given key.
*
* @param scope The scope used to synchronize the [StateFlow] and [SavedStateHandle]
* @param key The identifier for the value
* @param initialValue If no value exists with the given [key], a new one is created
* with the given [initialValue].
*
* @see SavedStateHandle.getLiveData
*/
@handstandsam
handstandsam / MyLifecycleOwner.kt
Last active May 23, 2025 08:53
Jetpack Compose OverlayService. You have to have all the correct permissions granted and in your manifest, but if you do, this this will show a green box with "Hello" in it!
import android.os.Bundle
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleRegistry
import androidx.savedstate.SavedStateRegistry
import androidx.savedstate.SavedStateRegistryController
import androidx.savedstate.SavedStateRegistryOwner
internal class MyLifecycleOwner : SavedStateRegistryOwner {
private var mLifecycleRegistry: LifecycleRegistry = LifecycleRegistry(this)
private var mSavedStateRegistryController: SavedStateRegistryController = SavedStateRegistryController.create(this)
@ShivamPokhriyal
ShivamPokhriyal / OTPEditText.java
Created November 27, 2020 15:03
A custom view to handle otp input in multiple edittexts. It will move focus to next edittext, if available, when user enters otp and it will move focus to the previous edittext, if available, when user deletes otp. It will also delegate the paste option, if user long presses and pastes a string into the otp input.
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
@volodia-chornenkyy
volodia-chornenkyy / detektGrabSubprojectsReports.groovy
Created January 17, 2020 16:27
Gradle task which gathers all Detekt reports from the subprojects and put it in the one folder "$rootDir/reports/detekt". It simplifies CI process a bit.
task detektGrabSubprojectsReports {
group = "Verification"
def detektSingleReportFolder = "$rootDir/reports/detekt"
def detektGeneralFolder = new File(detektSingleReportFolder)
detektGeneralFolder.mkdirs();
subprojects.findAll { subproject ->
def projectReportDir = "$subproject.buildDir/reports"
def detektReportFiles = [
"detekt.xml",
@G00fY2
G00fY2 / CustomRxJava2CallAdapterFactory.java
Last active October 2, 2024 04:13
CustomRxJava2CallAdapterFactory to transform HttpExceptions to custom error
import com.google.gson.Gson;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.reactivex.MaybeSource;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.Scheduler;
import io.reactivex.Single;
import java.lang.annotation.Annotation;
@clxy
clxy / AppDao.java
Last active February 25, 2024 03:26
Android Room Generic Dao
import android.arch.persistence.db.SimpleSQLiteQuery;
import android.arch.persistence.db.SupportSQLiteQuery;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.RawQuery;
import java.lang.reflect.ParameterizedType;
import java.util.List;
@JoseAlcerreca
JoseAlcerreca / Event.kt
Created April 26, 2018 10:25
An event wrapper for data that is exposed via a LiveData that represents an event.
/**
* 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) {
var hasBeenHandled = false
private set // Allow external read but not write
/**
* Returns the content and prevents its use again.
@Pulimet
Pulimet / AdbCommands
Last active June 7, 2025 16:10
Adb useful commands list
Hi All!
I've recently launched a tool that wraps many of the commands here with a user interface. This desktop application is currently available for macOS. There's a roadmap outlining planned features for the near future.
Feel free to request any features you'd like to see, and I'll prioritize them accordingly.
One of the most important aspects of this application is that every command executed behind the scenes is displayed in a special log section. This allows you to see exactly what’s happening and learn from it.
Here's the link to the repository: https://github.com/Pulimet/ADBugger
App Description:
ADBugger is a desktop tool designed for debugging and QA of Android devices and emulators. It simplifies testing, debugging, and performance analysis by offering device management, automated testing, log analysis, and remote control capabilities. This ensures smooth app performance across various setups.
@dseerapu
dseerapu / gist:b768728b3b4ccf282c7806a3745d0347
Last active October 25, 2022 15:04
Android app inactivity timeout | Android Logout timer
public class LogOutTimerUtil {
public interface LogOutListener {
void doLogout();
}
static Timer longTimer;
static final int LOGOUT_TIME = 600000; // delay in milliseconds i.e. 5 min = 300000 ms or use timeout argument
public static synchronized void startLogoutTimer(final Context context, final LogOutListener logOutListener) {
@davinctor
davinctor / RetryWithDelayTransformer.java
Last active February 3, 2020 23:39
Observable.Transformer to add retry feature to source observable if it fails. Every retry can be delayed.
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.petcube.android.helpers.Log;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.Subscriber;