Skip to content

Commit

Permalink
Apply suggestions from code reviewer
Browse files Browse the repository at this point in the history
  • Loading branch information
ILoveOpenSourceApplications committed Oct 30, 2024
1 parent c1060b1 commit e597374
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ object SettingsContract {
const val SECURITY_TOKEN = "securityToken"
const val VERSION_INFO = "versionInfo"
const val DEVICE_DATA_VERSION_INFO = "deviceDataVersionInfo"
const val HIDE_APP_ICON = "hideAppIcon"

val PROJECTION = arrayOf(
ENABLED,
Expand All @@ -44,7 +43,6 @@ object SettingsContract {
SECURITY_TOKEN,
VERSION_INFO,
DEVICE_DATA_VERSION_INFO,
HIDE_APP_ICON,
)
const val PREFERENCES_NAME = "checkin"
const val INITIAL_DIGEST = "1-929a0dca0eee55513280171a8585da7dcd3700f8"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class SettingsProvider : ContentProvider() {
CheckIn.SECURITY_TOKEN -> checkInPrefs.getLong(key, 0)
CheckIn.VERSION_INFO -> checkInPrefs.getString(key, "") ?: ""
CheckIn.DEVICE_DATA_VERSION_INFO -> checkInPrefs.getString(key, "") ?: ""
CheckIn.HIDE_APP_ICON -> getSettingsBoolean(key, false)
else -> throw IllegalArgumentException()
}
}
Expand All @@ -135,10 +134,6 @@ class SettingsProvider : ContentProvider() {
// special case: not saved in checkInPrefs
updateCheckInEnabled(value as Boolean)
}
if (key == CheckIn.HIDE_APP_ICON) {
// special case: not saved in checkInPrefs
updateHideAppIcon(value as Boolean)
}
when (key) {
CheckIn.ANDROID_ID -> editor.putLong(key, value as Long)
CheckIn.DIGEST -> editor.putString(key, value as String?)
Expand All @@ -157,12 +152,6 @@ class SettingsProvider : ContentProvider() {
.apply()
}

private fun updateHideAppIcon(hide: Boolean) {
preferences.edit()
.putBoolean(CheckIn.HIDE_APP_ICON, hide)
.apply()
}

private fun queryGcm(p: Array<out String>): Cursor = MatrixCursor(p).addRow(p) { key ->
when (key) {
Gcm.ENABLE_GCM -> getSettingsBoolean(key, false)
Expand Down
17 changes: 17 additions & 0 deletions play-services-base/core/src/main/res/drawable/ic_miscellaneous.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: 2019, The Android Open Source Project
~ SPDX-FileCopyrightText: 2020, microG Project Team
~ SPDX-License-Identifier: Apache-2.0
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#FF000000"
android:pathData="M5 21H3C2.4 21 2 20.6 2 20S2.4 19 3 19H5V21ZM21 21H13V19H21C21.6 19 22 19.4 22 20S21.6 21 21 21ZM10 16H8C7.4 16 7 16.4 7 17V23C7 23.6 7.4 24 8 24H10C10.6 24 11 23.6 11 23V17C11 16.4 10.6 16 10 16ZM16 26H14C13.4 26 13 26.4 13 27V33C13 33.6 13.4 34 14 34H16C16.6 34 17 33.6 17 33V27C17 26.4 16.6 26 16 26ZM21 31H19V29H21C21.6 29 22 29.4 22 30S21.6 31 21 31ZM11 31H3C2.4 31 2 30.6 2 30S2.4 29 3 29H11V31Z"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import org.microg.gms.people.PeopleManager;
import org.microg.gms.profile.Build;
import org.microg.gms.profile.ProfileManager;
import org.microg.gms.ui.UtilsKt;

import java.io.IOException;
import java.security.MessageDigest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package org.microg.gms.ui

import android.content.ComponentName
import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.lifecycleScope
Expand All @@ -17,7 +19,6 @@ import org.microg.gms.checkin.CheckinPreferences
import org.microg.gms.gcm.GcmDatabase
import org.microg.gms.gcm.GcmPrefs
import org.microg.gms.safetynet.SafetyNetPreferences
import org.microg.gms.settings.SettingsContract
import org.microg.gms.ui.settings.SettingsProvider
import org.microg.gms.ui.settings.getAllSettingsProviders
import org.microg.gms.vending.VendingPreferences
Expand Down Expand Up @@ -62,12 +63,23 @@ class SettingsFragment : ResourceSettingsFragment() {
summary = getString(org.microg.tools.ui.R.string.about_version_str, AboutFragment.getSelfVersion(context))
}

findPreference<SwitchPreferenceCompat>(SettingsContract.CheckIn.HIDE_APP_ICON)!!.apply {
setOnPreferenceChangeListener { _, newValue ->
requireActivity().hideAppIcon(newValue as Boolean)
true
}
val hideAppIconPref = findPreference<SwitchPreferenceCompat>("pref_hide_app_icon")
val isHuaweiBuild = isHuaweiDevice()

hideAppIconPref?.let {
if (isHuaweiBuild) {
it.isVisible = false
} else {
val componentName = ComponentName("org.microg.gms.ui", "org.microg.gms.ui.SettingsActivity")
val state = requireContext().packageManager.getComponentEnabledSetting(componentName)
it.isChecked = (state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED)

it.setOnPreferenceChangeListener { _, newValue ->
val enabled = newValue as Boolean
requireActivity().hideAppIcon(enabled)
true
}
}
}

for (entry in getAllSettingsProviders(requireContext()).flatMap { it.getEntriesStatic(requireContext()) }) {
Expand Down Expand Up @@ -136,6 +148,9 @@ class SettingsFragment : ResourceSettingsFragment() {
}
}
}
private fun isHuaweiDevice(): Boolean {
return android.os.Build.MANUFACTURER.equals("Huawei", ignoreCase = true)
}

companion object {
const val PREF_ABOUT = "pref_about"
Expand Down
1 change: 1 addition & 0 deletions play-services-core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ This can take a couple of minutes."</string>
<string name="pref_gcm_confirm_new_apps_summary">Ask before registering a new app to receive push notifications</string>
<string name="pref_gcm_ping_interval">Ping interval: <xliff:g example="10 minutes">%1$s</xliff:g></string>

<string name="pref_miscellaneous_title">Miscellaneous</string>
<string name="pref_hide_app_icon_title">Hide app icon</string>
<string name="pref_hide_app_icon_summary">Hides app icon from the launcher</string>
<string name="pref_about_title">About microG Services</string>
Expand Down
28 changes: 28 additions & 0 deletions play-services-core/src/main/res/xml/preferences_hide_app_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2013-2017 microG Project Team
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory android:layout="@layout/preference_category_no_label" android:key="prefcat_other_services">
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_hide_app_icon"
android:key="pref_hide_app_icon"
android:persistent="false"
android:summary="@string/pref_hide_app_icon_summary"
android:title="@string/pref_hide_app_icon_title" />
</PreferenceCategory>
</PreferenceScreen>
14 changes: 6 additions & 8 deletions play-services-core/src/main/res/xml/preferences_start.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@
<Preference
android:icon="@drawable/ic_map_marker"
android:key="pref_location"
android:title="@string/service_name_location"/>
android:title="@string/service_name_location" />
</PreferenceCategory>
<PreferenceCategory android:layout="@layout/preference_category_no_label" android:key="prefcat_footer">
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_hide_app_icon"
android:key="pref_hide_app_icon"
android:summary="@string/pref_hide_app_icon_summary"
android:title="@string/pref_hide_app_icon_title" />
<PreferenceCategory android:layout="@layout/preference_category_no_label" android:key="prefcat_other_services">
<Preference
android:icon="@drawable/ic_miscellaneous"
android:key="pref_miscellaneous"
android:title="@string/pref_miscellaneous_title" />
<Preference
android:icon="@drawable/ic_info_outline"
android:key="pref_about"
Expand Down

0 comments on commit e597374

Please sign in to comment.