Skip to content

Instantly share code, notes, and snippets.

Avatar
:electron:

Hossein Abbasi Drjacky

:electron:
View GitHub Profile
View self.id
did:3:kjzl6cwe1jw14a71oav2l5h7igau98c0sb3djyvlrmzbmlh9fcfawv3a4gtbgqi
@Drjacky
Drjacky / build.gradle.kts
Last active Jun 8, 2020
multiplatform shared module build.gradle.kts file
View build.gradle.kts
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 Nov 7, 2018
Wrapping and Composing data
View WrapResult.kt
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 Nov 7, 2018
A wrapper for data sources states
View ResultState.kt
/**
* 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 Nov 7, 2018
Custom MutableLiveData that operate just once.
View OperationLiveData.kt
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 Nov 7, 2018
An extension class for Rx schedulers
View RxSchedulerExtension.kt
//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 Jul 30, 2020
Dependencies in a separated file - Useful for Clean Architecture and Modular Android Applications
View dependencies.gradle
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 Oct 25, 2018
How to compile FFMPEG for ARM
View build_android_ARmv7a-ARMEABI.sh
#!/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 Oct 25, 2018
grantSignaturePermission method in PackageManagerService java file
View PackageManagerService.java
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) {