Skip to content

Instantly share code, notes, and snippets.

View esabook's full-sized avatar
🛰️
Seeking planet

esabook

🛰️
Seeking planet
View GitHub Profile
1. Open bash
2. goto root project
3. git config --global alias.change-commits '!'"f() { VAR=\$1; OLD=\$2; NEW=\$3; shift 3; git filter-branch --env-filter \"if [[ \\\"\$\`echo \$VAR\`\\\" = '\$OLD' ]]; then export \$VAR='\$NEW'; fi\" \$@; }; f"
4. git change-commits GIT_AUTHOR_EMAIL "[email protected]" "[email protected]" HEAD~50..HEAD
/*
* Copyright (c) 2022 esabook.
* Author: egit
*/
package com.esabook.app.services
import android.app.Activity
import android.content.BroadcastReceiver
import android.content.Context
@esabook
esabook / ImageViewUtil.kt
Created December 21, 2021 09:37
Imageloader for glide, auto stop/dispose when View.onDetach()
fun ImageView.loadImageWithGlide(
imgObj: Any?,
cacheMode: DiskCacheStrategy = DiskCacheStrategy.AUTOMATIC,
onFail: (() -> Unit?)? = null,
onSuccess: (() -> Unit?)? = null,
) {
try {
Glide.with(this)
.load(imgObj)
.placeholder(this.drawable)
@esabook
esabook / ViewUtil.kt
Created December 21, 2021 09:33
Connect tabLayout to recycleView as ItemIndicator
fun TabLayout.asItemIndicator(recyclerView: RecyclerView) {
//setup tab as dot indicator
removeAllTabs()
recyclerView.adapter?.itemCount?.downTo(1)?.forEach { _ ->
addTab(newTab())
}
//make tabActiveIndex as/jump rvAdapterIndex
addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) {
@esabook
esabook / installFromAAB.sh
Last active October 7, 2021 12:13 — forked from riyaz/installFromAAB.sh
Install the app in device from aab, add "pass=pass:*"
#!/bin/sh
# One step wrapper to install aab to connected device, it downloads bundletool if its missing and signs the app with android debug certifiate.
#
# Usage: installFromAAB apk.aab <local-aab-path/apk.aab>
#
BASENAME="${1##*/}"
KEYSTORE=~/.android/debug.keystore
KS_ALIAS="androiddebugkey"
PASS="pass:android"
@esabook
esabook / ImagePickerDialog.java
Created March 16, 2021 15:31
[Android] Pick image from gallery or camera
package *;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@esabook
esabook / DateFormatUtils.kt
Created March 16, 2021 15:23
[Kotlin-JVM] Custom monthNames, relativeDate, stringToDate, DateToString
package *
import android.text.format.DateUtils
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.TimeUnit.MILLISECONDS
import kotlin.math.abs
object DateFormatUtils {
val DEFAULT_FROM_DATE_PATTERN = "yyyy-MM-dd"
@esabook
esabook / AspectFrameLayout.java
Last active May 19, 2022 07:00
[Android] CameraActivity: FrontCam/MainCam, GreenScreen base for MaskingIndicator/Crop
package *;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import timber.log.Timber;
/**
@esabook
esabook / LayoutFragment.kt
Last active March 16, 2021 14:31
[Android] Single Fragment for multiple layout/*.xml in <navigation>
package *
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
class LayoutFragment : Fragment() {
@esabook
esabook / Ignore.java
Last active January 24, 2022 18:01
Execute code with silent crash mode;Ignore throwable runtime code;Can be used for Getter or Setter
/**
* Execute code with silent crash mode<br>
* usage:<br>
* <pre>
* Ignore.of(()-> {
* String bankName = o.infoPayment.namaBank.toUpperCase().replace("BANK", "");
* binding.tvBankName.setText(bankName);
* });
* </pre>