Merge pull request #116 from X1nto/master

Fixed microg icon unhiding on huawei
This commit is contained in:
KevinX8 2021-03-16 11:14:09 +00:00 committed by GitHub
commit 8ad8ea42e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 11 deletions

View File

@ -58,6 +58,7 @@ import org.microg.gms.checkin.LastCheckinInfo;
import org.microg.gms.common.HttpFormClient;
import org.microg.gms.common.Utils;
import org.microg.gms.people.PeopleManager;
import org.microg.gms.ui.UtilsKt;
import java.io.IOException;
import java.util.Locale;
@ -147,8 +148,6 @@ public class LoginActivity extends AssistantActivity {
} else {
retrieveRtToken(getIntent().getStringExtra(EXTRA_TOKEN));
}
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
init();
} else {
setMessage(R.string.auth_before_connect);
setSpoofButtonText(R.string.brand_spoof_button);
@ -162,7 +161,10 @@ public class LoginActivity extends AssistantActivity {
super.onHuaweiButtonClicked();
state++;
if (state == 1) {
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean("pref_hide_launcher_icon", false).apply();
if (SDK_INT >= Build.VERSION_CODES.M) {
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean("pref_hide_launcher_icon", false).apply();
UtilsKt.hideIcon(this, false);
}
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(HuaweiButtonPreference, true).apply();
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(LoginButtonPreference, true)) {
LastCheckinInfo.ClearCheckinInfo(this);

View File

@ -55,14 +55,7 @@ class SettingsFragment : ResourceSettingsFragment() {
findPreference<SwitchPreferenceCompat>(PREF_CAST_HIDE_LAUNCHER_ICON)?.apply {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
setOnPreferenceChangeListener { _, newValue ->
pm.setComponentEnabledSetting(
ComponentName.createRelative(requireActivity(), "org.microg.gms.ui.SettingsActivityLauncher"),
when (newValue) {
true -> PackageManager.COMPONENT_ENABLED_STATE_DISABLED
else -> PackageManager.COMPONENT_ENABLED_STATE_ENABLED
},
PackageManager.DONT_KILL_APP
)
requireActivity().hideIcon(newValue as Boolean)
true
}
} else {

View File

@ -5,13 +5,16 @@
package org.microg.gms.ui
import android.content.ComponentName
import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import androidx.annotation.IdRes
import androidx.annotation.RequiresApi
import androidx.navigation.NavController
import androidx.navigation.navOptions
import androidx.navigation.ui.R
@ -36,6 +39,18 @@ fun NavController.navigate(context: Context, @IdRes resId: Int, args: Bundle? =
} else null)
}
@RequiresApi(Build.VERSION_CODES.M)
fun Context.hideIcon(hide: Boolean) {
packageManager.setComponentEnabledSetting(
ComponentName.createRelative(this, "org.microg.gms.ui.SettingsActivityLauncher"),
when (hide) {
true -> PackageManager.COMPONENT_ENABLED_STATE_DISABLED
false -> PackageManager.COMPONENT_ENABLED_STATE_ENABLED
},
PackageManager.DONT_KILL_APP
)
}
val Context.systemAnimationsEnabled: Boolean
get() {