Skip to content

Instantly share code, notes, and snippets.

did:3:kjzl6cwe1jw14a71oav2l5h7igau98c0sb3djyvlrmzbmlh9fcfawv3a4gtbgqi
@Drjacky
Drjacky / build.gradle.kts
Last active June 8, 2020 12:46
multiplatform shared module build.gradle.kts file
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
val buildToolsVersion: String by project
val kotlinVersion: String by extra
plugins {
id("com.android.library")
kotlin("multiplatform")
}
@Drjacky
Drjacky / WrapResult.kt
Created November 7, 2018 16:23
Wrapping and Composing data
protected fun <D> wrapResult(): SingleTransformer<D, ResultState<D>> = SingleTransformer {
it.map { d -> ResultState.Success(d) as ResultState<D> }
.onErrorReturn { e -> ResultState.Error(e, null) }
}
@Drjacky
Drjacky / ResultState.kt
Created November 7, 2018 16:16
A wrapper for data sources states
/**
* A wrapper for database and network states.
*/
sealed class ResultState<T> {
/**
* A state of [data] which shows that we know there is still an update to come.
*/
data class Loading<T>(val data: T) : ResultState<T>()
@Drjacky
Drjacky / OperationLiveData.kt
Created November 7, 2018 15:14
Custom MutableLiveData that operate just once.
class OperationLiveData<T>(private val operation: OperationLiveData<T>.() -> Unit) : MutableLiveData<T>() {
private var operated = AtomicBoolean(false)
override fun observe(owner: LifecycleOwner, observer: Observer<in T>) {
super.observe(owner, observer)
operate()
}
@Drjacky
Drjacky / RxSchedulerExtension.kt
Created November 7, 2018 14:46
An extension class for Rx schedulers
//Observable
fun <T> Observable<T>.applyIoScheduler() = applyScheduler(Schedulers.io())
fun <T> Observable<T>.applyComputationScheduler() = applyScheduler(Schedulers.computation())
private fun <T> Observable<T>.applyScheduler(scheduler: Scheduler) =
subscribeOn(scheduler).observeOn(AndroidSchedulers.mainThread())
//Flowable
@Drjacky
Drjacky / dependencies.gradle
Last active July 30, 2020 06:42
Dependencies in a separated file - Useful for Clean Architecture and Modular Android Applications
ext {
// Android
minSdkVersion = 14
targetSdkVersion = 28
versionCode = 1
versionName = "1.0"
androidCompileSdkVersion = 28
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
// Libraries
ankoVersion = '0.10.4'
@Drjacky
Drjacky / build_android_ARmv7a-ARMEABI.sh
Created October 25, 2018 16:40
How to compile FFMPEG for ARM
#!/bin/bash
if [ "$NDK" = "" ]; then
echo NDK variable not set, assuming ${HOME}/android-ndk
export NDK=${HOME}/android-ndk
fi
SYSROOT=$NDK/platforms/android-14/arch-arm
WORKING_DIR=`pwd`
# Expand the prebuilt/* path into the correct one
@Drjacky
Drjacky / PackageManagerService.java
Created October 25, 2018 15:48
grantSignaturePermission method in PackageManagerService java file
private boolean grantSignaturePermission(String perm, PackageParser.Package pkg,
BasePermission bp, HashSet<String> origPermissions) {
boolean allowed;
allowed = (compareSignatures(
bp.packageSetting.signatures.mSignatures, pkg.mSignatures)
== PackageManager.SIGNATURE_MATCH)
|| (compareSignatures(mPlatformPackage.mSignatures, pkg.mSignatures)
== PackageManager.SIGNATURE_MATCH);
if (!allowed && (bp.protectionLevel
& PermissionInfo.PROTECTION_FLAG_SYSTEM) != 0) {