Skip to content

Instantly share code, notes, and snippets.

@vargasgabriel
vargasgabriel / ActivityRestart.kt
Created January 25, 2022 17:50 — forked from easterapps/ActivityRestart.kt
restart android application programmatically
fun triggerRestart(context: Activity) {
val intent = Intent(context, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
if (context is Activity) {
(context as Activity).finish()
}
Runtime.getRuntime().exit(0)
}
@vargasgabriel
vargasgabriel / LiveDataValidator.kt
Last active May 20, 2021 02:02 — forked from carlosezam/LiveDataValidator.kt
Form validation with LiveData
// https://oozou.com/blog/modern-android-form-validations-with-data-binding-147
typealias Predicate<T> = (value: T?) -> Boolean
class LiveDataValidator<T>(private val liveData: LiveData<T>){
private val validationRules = mutableListOf<Predicate<T>>()
private val errorMessages = mutableListOf<String>()
var error = MutableLiveData<Message?>()
@vargasgabriel
vargasgabriel / AppHelper.java
Created May 7, 2021 11:49 — forked from anggadarkprince/AppHelper.java
Upload file with Multipart Request Volley Android
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import java.io.ByteArrayOutputStream;
/**
* Sketch Project Studio
* Created by Angga on 12/04/2016 14.27.
*/
public class AppHelper {
@vargasgabriel
vargasgabriel / script.sh
Created August 26, 2019 17:37 — forked from dlew/script.sh
Simple AndroidX Migration Script
#!/usr/bin/env bash
# I've found that the "Migrate to AndroidX" converter in Android Studio doesn't work very
# well, so I wrote my own script to do the simple job of converting package names.
#
# You can download a CSV of package names here: https://developer.android.com/topic/libraries/support-library/downloads/androidx-class-mapping.csv
#
# It'll run faster on a clean build because then there are fewer files to scan over.
#
# Uses `gsed` because I'm on a Mac. Can easily replace with `sed` if you don't have `gsed`.
@vargasgabriel
vargasgabriel / git-tag-delete-local-and-remote.sh
Created February 25, 2018 04:04 — forked from mobilemind/git-tag-delete-local-and-remote.sh
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName