Skip to content

Instantly share code, notes, and snippets.

View es0329's full-sized avatar

Eric es0329

View GitHub Profile
@RkNaing
RkNaing / OkHttpFileLoggingInterceptor.java
Last active February 28, 2024 03:36
OkHttp File Logging Interceptor that internally uses HttpLoggingInterceptor with a custom logger instance to write logs to file.
import android.text.TextUtils;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParser;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
name: EZRep Build
on:
push:
tags: releases/[1-9]+.[0-9]+.[0-9]+
branches: master
jobs:
build:
runs-on: windows-latest
@nostra13
nostra13 / CrashlyticsLogger.kt
Last active March 22, 2022 09:57
Android Logger (concise wrapper of Timber) + CrashlyticsLogger
package com.nostra13.log
import android.util.Log
import com.google.firebase.crashlytics.FirebaseCrashlytics
class CrashlyticsLogger(private val isDebug: Boolean) : Logger() {
private val priorityStr = mapOf(
Log.VERBOSE to "V",
Log.DEBUG to "D",
@marcouberti
marcouberti / CoroutineTestRule.kt
Last active June 1, 2021 01:51
Android Local Unit Test using Kotlin Coroutines and MockK. A CoroutineTestRule is needed if your tested classes use the Main dispatcher, otherwise an "IllegalStateException" is thrown. Also a InstantTaskExecutorRule is needed to avoid a "NullPointerException". Use runBlockingTest to skip all suspending delays. Use coEvery/coVerify to mock/verify…
import org.junit.rules.TestWatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.*
import org.junit.runner.Description
@ExperimentalCoroutinesApi
class CoroutineTestRule(val dispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()) : TestWatcher() {
override fun starting(description: Description?) {
image: seanghay/android-ci
before_script:
- chmod +x ./gradlew
stages:
- build
cache:
paths:
- .gradle/wrapper
- .gradle/caches
assembleDebug:

How to use this code

  1. Add the build_pull_request.sh to the root of your git repository;
  2. Add the android.yml file to .github/workflows/;
  3. Make build_pull_request.sh executable using: chmod +x build_pull_request.sh;
  4. Commit your code and push the changes

LICENSE

# MIT License
@GokhanArik
GokhanArik / NetworkStateManager.kt
Created March 12, 2020 03:11
Check Internet Connection in Android 21+
package manager
import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import android.os.Build
import android.util.Log
import com.jakewharton.rxrelay2.BehaviorRelay
@Zhuinden
Zhuinden / FragmentViewBindingDelegate.kt
Last active October 27, 2025 16:26
Fragment view binding delegate
// https://github.com/Zhuinden/fragmentviewbindingdelegate-kt
import android.view.View
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import androidx.viewbinding.ViewBinding
import kotlin.properties.ReadOnlyProperty
@davidliu
davidliu / FragmentViewModelFactory.kt
Created February 16, 2020 20:49
View model factory extensions
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.lifecycle.AbstractSavedStateViewModelFactory
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.savedstate.SavedStateRegistryOwner
@Frank1234
Frank1234 / ViewBindingHolder.kt
Last active December 14, 2020 11:36
Holds and manages ViewBinding inside a Fragment.
/**
* Holds and manages ViewBinding inside a Fragment.
*/
interface ViewBindingHolder<T : ViewBinding> {
val binding: T?
/**
* Saves the binding for cleanup on onDestroy, calls the specified function [onBound] with `this` value
* as its receiver and returns the bound view root.