Updated Hide screen with new arch

This commit is contained in:
Viktor De Pasquale
2019-04-19 16:32:01 +02:00
parent cda14af208
commit e81f00ef1a
20 changed files with 639 additions and 114 deletions

View File

@@ -8,6 +8,8 @@ import androidx.appcompat.widget.Toolbar
import androidx.databinding.BindingAdapter
import androidx.drawerlayout.widget.DrawerLayout
import com.google.android.material.navigation.NavigationView
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.model.entity.state.IndeterminateState
@BindingAdapter("onNavigationClick")
@@ -35,3 +37,23 @@ fun setImageResource(view: AppCompatImageView, @DrawableRes resId: Int) {
fun setTint(view: AppCompatImageView, @ColorInt tint: Int) {
view.setColorFilter(tint)
}
@BindingAdapter("isChecked")
fun setChecked(view: AppCompatImageView, isChecked: Boolean) {
val state = when (isChecked) {
true -> IndeterminateState.CHECKED
else -> IndeterminateState.UNCHECKED
}
setChecked(view, state)
}
@BindingAdapter("isChecked")
fun setChecked(view: AppCompatImageView, isChecked: IndeterminateState) {
view.setImageResource(
when (isChecked) {
IndeterminateState.INDETERMINATE -> R.drawable.ic_indeterminate
IndeterminateState.CHECKED -> R.drawable.ic_checked
IndeterminateState.UNCHECKED -> R.drawable.ic_unchecked
}
)
}

View File

@@ -0,0 +1,50 @@
package com.topjohnwu.magisk.utils
import android.content.pm.ApplicationInfo
import android.content.pm.ComponentInfo
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.pm.PackageManager.*
val PackageInfo.processes
get() = activities?.processNames.orEmpty() +
services?.processNames.orEmpty() +
receivers?.processNames.orEmpty() +
providers?.processNames.orEmpty()
val Array<out ComponentInfo>.processNames get() = mapNotNull { it.processName }
val ApplicationInfo.packageInfo: PackageInfo?
get() {
val pm: PackageManager by inject()
return try {
val request = GET_ACTIVITIES or
GET_SERVICES or
GET_RECEIVERS or
GET_PROVIDERS
pm.getPackageInfo(packageName, request)
} catch (e1: Exception) {
try {
pm.activities(packageName).apply {
services = pm.services(packageName)
receivers = pm.receivers(packageName)
providers = pm.providers(packageName)
}
} catch (e2: Exception) {
null
}
}
}
fun PackageManager.activities(packageName: String) =
getPackageInfo(packageName, GET_ACTIVITIES)
fun PackageManager.services(packageName: String) =
getPackageInfo(packageName, GET_SERVICES).services
fun PackageManager.receivers(packageName: String) =
getPackageInfo(packageName, GET_RECEIVERS).receivers
fun PackageManager.providers(packageName: String) =
getPackageInfo(packageName, GET_PROVIDERS).providers

View File

@@ -0,0 +1,20 @@
package com.topjohnwu.magisk.utils
import org.koin.core.context.GlobalContext
import org.koin.core.parameter.ParametersDefinition
import org.koin.core.qualifier.Qualifier
import org.koin.core.scope.Scope
fun getKoin() = GlobalContext.get().koin
inline fun <reified T : Any> inject(
qualifier: Qualifier? = null,
scope: Scope? = null,
noinline parameters: ParametersDefinition? = null
) = lazy { get<T>(qualifier, scope, parameters) }
inline fun <reified T : Any> get(
qualifier: Qualifier? = null,
scope: Scope? = null,
noinline parameters: ParametersDefinition? = null
): T = getKoin().get(qualifier, scope, parameters)

View File

@@ -0,0 +1,5 @@
package com.topjohnwu.magisk.utils
import io.reactivex.Single
fun <T : Any> T.toSingle() = Single.just(this)