Verified Commit d2b2ee53 authored by Marvin W.'s avatar Marvin W. 🐿
Browse files

Even more UI improovements

parent 509ccdf2
Subproject commit 43a18f90c13c1e7198c23295bb9beb5869030a3b
Subproject commit 632ab7790355f58033b3296d811b88831bea8a07
......@@ -411,13 +411,18 @@
android:label="@string/pref_about_title"
android:theme="@style/Theme.AppCompat.Settings"/>
<activity
android:name="org.microg.gms.ui.CheckinFragment$AsActivity"
android:label="@string/service_name_checkin"
android:theme="@style/Theme.AppCompat.Settings"/>
<activity
android:name="org.microg.gms.ui.GcmFragment$AsActivity"
android:label="@string/service_name_mcs"
android:theme="@style/Theme.AppCompat.Settings"/>
<activity
android:name="org.microg.gms.ui.GcmFragment$AdvancedAsActivity"
android:name="org.microg.gms.ui.GcmAdvancedFragment$AsActivity"
android:label="@string/service_name_mcs"
android:theme="@style/Theme.AppCompat.Settings"/>
......@@ -426,11 +431,21 @@
android:label="@string/service_name_mcs"
android:theme="@style/Theme.AppCompat.Settings"/>
<activity
android:name="org.microg.gms.ui.GoogleMoreFragment$AsActivity"
android:label="@string/gms_settings_name"
android:theme="@style/Theme.AppCompat.Settings"/>
<activity
android:name="org.microg.gms.ui.SafetyNetFragment$AsActivity"
android:label="@string/service_name_snet"
android:theme="@style/Theme.AppCompat.Settings"/>
<activity
android:name="org.microg.gms.ui.SafetyNetAdvancedFragment$AsActivity"
android:label="@string/service_name_snet"
android:theme="@style/Theme.AppCompat.Settings"/>
<activity
android:name="org.microg.gms.ui.SelfCheckFragment$AsActivity"
android:label="@string/self_check_title"
......
......@@ -27,6 +27,7 @@ public class SafetyNetPrefs implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_SNET_OFFICIAL = "snet_official";
public static final String PREF_SNET_THIRD_PARTY = "snet_third_party";
public static final String PREF_SNET_CUSTOM_URL = "snet_custom_url";
public static final String PREF_SNET_SELF_SIGNED = "snet_self_signed";
private static SafetyNetPrefs INSTANCE;
......@@ -40,6 +41,7 @@ public class SafetyNetPrefs implements SharedPreferences.OnSharedPreferenceChang
private boolean disabled;
private boolean official;
private boolean selfSigned;
private boolean thirdParty;
private String customUrl;
......@@ -55,7 +57,8 @@ public class SafetyNetPrefs implements SharedPreferences.OnSharedPreferenceChang
public void update() {
disabled = defaultPreferences.getBoolean(PREF_SNET_DISABLED, true);
official = defaultPreferences.getBoolean(PREF_SNET_OFFICIAL, false);
official = defaultPreferences.getBoolean(PREF_SNET_OFFICIAL, true);
selfSigned = defaultPreferences.getBoolean(PREF_SNET_SELF_SIGNED, false);
thirdParty = defaultPreferences.getBoolean(PREF_SNET_THIRD_PARTY, false);
customUrl = defaultPreferences.getString(PREF_SNET_CUSTOM_URL, null);
}
......@@ -66,7 +69,19 @@ public class SafetyNetPrefs implements SharedPreferences.OnSharedPreferenceChang
}
public boolean isEnabled() {
return !disabled && (official || thirdParty);
return !disabled && (official || selfSigned || thirdParty);
}
public void setEnabled(boolean enabled) {
defaultPreferences.edit().putBoolean(PREF_SNET_DISABLED, !enabled).apply();
if (enabled && !isEnabled()) {
official = true;
defaultPreferences.edit().putBoolean(PREF_SNET_OFFICIAL, true).apply();
}
}
public boolean isSelfSigned() {
return selfSigned;
}
public boolean isOfficial() {
......
/*
* Copyright (C) 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.
*/
package org.microg.gms.ui;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import com.google.android.gms.R;
import org.microg.tools.ui.AbstractSettingsActivity;
import org.microg.tools.ui.SwitchBarResourceSettingsFragment;
import static org.microg.gms.checkin.TriggerReceiver.PREF_ENABLE_CHECKIN;
public class CheckinFragment extends SwitchBarResourceSettingsFragment {
public CheckinFragment() {
preferencesResource = R.xml.preferences_checkin;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
switchBar.setChecked(PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean(PREF_ENABLE_CHECKIN, false));
}
@Override
public void onSwitchBarChanged(boolean isChecked) {
PreferenceManager.getDefaultSharedPreferences(getContext()).edit().putBoolean(PREF_ENABLE_CHECKIN, isChecked).apply();
}
public static class AsActivity extends AbstractSettingsActivity {
public AsActivity() {
showHomeAsUp = true;
}
@Override
protected Fragment getFragment() {
return new CheckinFragment();
}
}
}
/*
* Copyright (C) 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.
*/
package org.microg.gms.ui;
import android.support.v4.app.Fragment;
import com.google.android.gms.R;
import org.microg.tools.ui.AbstractSettingsActivity;
import org.microg.tools.ui.ResourceSettingsFragment;
public class GcmAdvancedFragment extends ResourceSettingsFragment {
public GcmAdvancedFragment() {
preferencesResource = R.xml.preferences_gcm_advanced;
}
public static class AsActivity extends AbstractSettingsActivity {
public AsActivity() {
showHomeAsUp = true;
}
@Override
protected Fragment getFragment() {
return new GcmAdvancedFragment();
}
}
}
......@@ -28,7 +28,6 @@ import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.PreferenceViewHolder;
import android.support.v7.widget.SwitchCompat;
import android.text.format.DateUtils;
import android.view.Menu;
import android.view.MenuInflater;
......@@ -42,8 +41,7 @@ import org.microg.gms.gcm.McsConstants;
import org.microg.gms.gcm.McsService;
import org.microg.tools.ui.AbstractSettingsActivity;
import org.microg.tools.ui.DimmableIconPreference;
import org.microg.tools.ui.ResourceSettingsFragment;
import org.microg.tools.ui.SwitchBar;
import org.microg.tools.ui.SwitchBarResourceSettingsFragment;
import java.util.ArrayList;
import java.util.Collections;
......@@ -54,17 +52,13 @@ import static android.text.format.DateUtils.FORMAT_SHOW_TIME;
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
import static android.text.format.DateUtils.WEEK_IN_MILLIS;
public class GcmFragment extends ResourceSettingsFragment implements SwitchBar.OnSwitchChangeListener {
public class GcmFragment extends SwitchBarResourceSettingsFragment {
public static final String PREF_GCM_STATUS = "pref_gcm_status";
public static final String PREF_GCM_APPS = "gcm_apps";
private GcmDatabase database;
private SwitchBar switchBar;
private SwitchCompat switchCompat;
private boolean listenerSetup = false;
private final int MENU_ADVANCED = Menu.FIRST;
public GcmFragment() {
......@@ -75,12 +69,7 @@ public class GcmFragment extends ResourceSettingsFragment implements SwitchBar.O
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
AbstractSettingsActivity activity = (AbstractSettingsActivity) getActivity();
setHasOptionsMenu(true);
switchBar = activity.getSwitchBar();
switchBar.show();
switchCompat = switchBar.getSwitch();
switchBar.setChecked(GcmPrefs.get(getContext()).isGcmEnabled());
}
......@@ -93,28 +82,14 @@ public class GcmFragment extends ResourceSettingsFragment implements SwitchBar.O
updateContent();
}
@Override
public void onDestroyView() {
super.onDestroyView();
switchBar.hide();
}
@Override
public void onResume() {
super.onResume();
if (!listenerSetup) {
switchBar.addOnSwitchChangeListener(this);
listenerSetup = true;
}
updateContent();
}
@Override
public void onPause() {
if (listenerSetup) {
switchBar.removeOnSwitchChangeListener(this);
listenerSetup = false;
}
super.onPause();
database.close();
}
......@@ -129,7 +104,7 @@ public class GcmFragment extends ResourceSettingsFragment implements SwitchBar.O
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_ADVANCED:
Intent intent = new Intent(getContext(), AdvancedAsActivity.class);
Intent intent = new Intent(getContext(), GcmAdvancedFragment.AsActivity .class);
startActivity(intent);
return true;
default:
......@@ -138,16 +113,14 @@ public class GcmFragment extends ResourceSettingsFragment implements SwitchBar.O
}
@Override
public void onSwitchChanged(SwitchCompat switchView, boolean isChecked) {
if (switchView == switchCompat) {
getPreferenceManager().getSharedPreferences().edit().putBoolean(GcmPrefs.PREF_ENABLE_GCM, isChecked).apply();
if (!isChecked) {
McsService.stop(getContext());
} else {
getContext().startService(new Intent(McsConstants.ACTION_CONNECT, null, getContext(), McsService.class));
}
updateContent();
public void onSwitchBarChanged(boolean isChecked) {
getPreferenceManager().getSharedPreferences().edit().putBoolean(GcmPrefs.PREF_ENABLE_GCM, isChecked).apply();
if (!isChecked) {
McsService.stop(getContext());
} else {
getContext().startService(new Intent(McsConstants.ACTION_CONNECT, null, getContext(), McsService.class));
}
updateContent();
}
private static void addPreferencesSorted(List<Preference> prefs, PreferenceGroup container) {
......@@ -155,7 +128,7 @@ public class GcmFragment extends ResourceSettingsFragment implements SwitchBar.O
Collections.sort(prefs, new Comparator<Preference>() {
@Override
public int compare(Preference lhs, Preference rhs) {
return lhs.getTitle().toString().compareTo(rhs.getTitle().toString());
return lhs.getTitle().toString().toLowerCase().compareTo(rhs.getTitle().toString().toLowerCase());
}
});
for (Preference entry : prefs) {
......@@ -262,11 +235,4 @@ public class GcmFragment extends ResourceSettingsFragment implements SwitchBar.O
return new GcmFragment();
}
}
public static class AdvancedAsActivity extends AbstractSettingsActivity {
public AdvancedAsActivity() {
showHomeAsUp = true;
preferencesResource = R.xml.preferences_gcm_advanced;
}
}
}
\ No newline at end of file
/*
* Copyright (C) 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.
*/
package org.microg.gms.ui;
import com.google.android.gms.R;
import org.microg.tools.ui.AbstractSettingsActivity;
public class GoogleMoreFragment {
public static class AsActivity extends AbstractSettingsActivity {
public AsActivity() {
showHomeAsUp = true;
preferencesResource = R.xml.preferences_google_more;
}
}
}
/*
* Copyright (C) 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.
*/
package org.microg.gms.ui;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.preference.Preference;
import com.google.android.gms.R;
import org.microg.tools.ui.AbstractSettingsActivity;
import org.microg.tools.ui.RadioButtonPreference;
import org.microg.tools.ui.ResourceSettingsFragment;
import static org.microg.gms.snet.SafetyNetPrefs.PREF_SNET_OFFICIAL;
import static org.microg.gms.snet.SafetyNetPrefs.PREF_SNET_SELF_SIGNED;
import static org.microg.gms.snet.SafetyNetPrefs.PREF_SNET_THIRD_PARTY;
public class SafetyNetAdvancedFragment extends ResourceSettingsFragment {
public SafetyNetAdvancedFragment() {
preferencesResource = R.xml.preferences_snet_advanced;
}
private RadioButtonPreference radioOfficial;
private RadioButtonPreference radioSelfSigned;
private RadioButtonPreference radioThirdParty;
@Override
public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
super.onCreatePreferencesFix(savedInstanceState, rootKey);
radioOfficial = (RadioButtonPreference) findPreference(PREF_SNET_OFFICIAL);
radioSelfSigned = (RadioButtonPreference) findPreference(PREF_SNET_SELF_SIGNED);
radioThirdParty = (RadioButtonPreference) findPreference(PREF_SNET_THIRD_PARTY);
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (preference == radioOfficial) {
radioOfficial.setChecked(true);
radioSelfSigned.setChecked(false);
radioThirdParty.setChecked(false);
return true;
} else if (preference == radioSelfSigned) {
radioOfficial.setChecked(false);
radioSelfSigned.setChecked(true);
radioThirdParty.setChecked(false);
return true;
} else if (preference == radioThirdParty) {
radioOfficial.setChecked(false);
radioSelfSigned.setChecked(false);
radioThirdParty.setChecked(true);
return true;
}
return super.onPreferenceTreeClick(preference);
}
public static class AsActivity extends AbstractSettingsActivity {
public AsActivity() {
showHomeAsUp = true;
}
@Override
protected Fragment getFragment() {
return new SafetyNetAdvancedFragment();
}
}
}
......@@ -16,59 +16,56 @@
package org.microg.gms.ui;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.preference.Preference;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import com.google.android.gms.R;
import org.microg.gms.snet.SafetyNetPrefs;
import org.microg.tools.ui.AbstractSettingsActivity;
import org.microg.tools.ui.RadioButtonPreference;
import org.microg.tools.ui.ResourceSettingsFragment;
import org.microg.tools.ui.SwitchBarResourceSettingsFragment;
import static org.microg.gms.snet.SafetyNetPrefs.PREF_SNET_DISABLED;
import static org.microg.gms.snet.SafetyNetPrefs.PREF_SNET_OFFICIAL;
import static org.microg.gms.snet.SafetyNetPrefs.PREF_SNET_THIRD_PARTY;
public class SafetyNetFragment extends ResourceSettingsFragment {
public class SafetyNetFragment extends SwitchBarResourceSettingsFragment {
private final int MENU_ADVANCED = Menu.FIRST;
public SafetyNetFragment() {
preferencesResource = R.xml.preferences_snet;
}
private RadioButtonPreference radioDisabled;
private RadioButtonPreference radioOfficial;
private RadioButtonPreference radioThirdParty;
@Override
public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
super.onCreatePreferencesFix(savedInstanceState, rootKey);
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
switchBar.setChecked(SafetyNetPrefs.get(getContext()).isEnabled());
}
radioDisabled = (RadioButtonPreference) findPreference(PREF_SNET_DISABLED);
radioOfficial = (RadioButtonPreference) findPreference(PREF_SNET_OFFICIAL);
radioThirdParty = (RadioButtonPreference) findPreference(PREF_SNET_THIRD_PARTY);
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.add(0, MENU_ADVANCED, 0, R.string.menu_advanced);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (preference == radioDisabled) {
radioDisabled.setChecked(true);
radioOfficial.setChecked(false);
radioThirdParty.setChecked(false);
return true;
} else if (preference == radioOfficial) {
radioDisabled.setChecked(false);
radioOfficial.setChecked(true);
radioThirdParty.setChecked(false);
return true;
} else if (preference == radioThirdParty) {
radioDisabled.setChecked(false);
radioOfficial.setChecked(false);
radioThirdParty.setChecked(true);
return true;
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_ADVANCED:
Intent intent = new Intent(getContext(), SafetyNetAdvancedFragment.AsActivity.class);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
return super.onPreferenceTreeClick(preference);
}
@Override
public void onSwitchBarChanged(boolean isChecked) {
SafetyNetPrefs.get(getContext()).setEnabled(isChecked);
}
public static class AsActivity extends AbstractSettingsActivity {
......
......@@ -17,6 +17,7 @@
package org.microg.gms.ui;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
......@@ -25,9 +26,12 @@ import com.google.android.gms.R;
import org.microg.gms.gcm.GcmDatabase;
import org.microg.gms.gcm.GcmPrefs;
import org.microg.gms.snet.SafetyNetPrefs;
import org.microg.nlp.Preferences;
import org.microg.tools.ui.AbstractDashboardActivity;
import org.microg.tools.ui.ResourceSettingsFragment;
import static org.microg.gms.checkin.TriggerReceiver.PREF_ENABLE_CHECKIN;
public class SettingsActivity extends AbstractDashboardActivity {
public SettingsActivity() {
......@@ -46,6 +50,8 @@ public class SettingsActivity extends AbstractDashboardActivity {
public static final String PREF_ABOUT = "pref_about";
public static final String PREF_GCM = "pref_gcm";
public static final String PREF_SNET = "pref_snet";
public static final String PREF_UNIFIEDNLP = "pref_unifiednlp";
public static final String PREF_CHECKIN = "pref_checkin";
public FragmentImpl() {
preferencesResource = R.xml.preferences_start;
......@@ -69,11 +75,19 @@ public class SettingsActivity extends AbstractDashboardActivity {
GcmDatabase database = new GcmDatabase(getContext());
int regCount = database.getRegistrationList().size();
database.close();
findPreference(PREF_GCM).setSummary(getString(R.string.v7_preference_on) + " / " + getContext().getString(R.string.gcm_registered_apps_counter, regCount));
findPreference(PREF_GCM).setSummary(getString(R.string.v7_preference_on) + " / " + getResources().getQuantityString(R.plurals.gcm_registered_apps_counter, regCount, regCount));
} else {
findPreference(PREF_GCM).setSummary(R.string.v7_preference_off);
}
findPreference(PREF_SNET).setSummary(SafetyNetPrefs.get(getContext()).isEnabled() ? R.string.service_status_enabled : R.string.service_status_disabled);
Preferences unifiedNlPrefs = new Preferences(getContext());
int backendCount = Preferences.splitBackendString(unifiedNlPrefs.getLocationBackends()).length;
backendCount += Preferences.splitBackendString(unifiedNlPrefs.getGeocoderBackends()).length;
findPreference(PREF_UNIFIEDNLP).setSummary(getResources().getQuantityString(R.plurals.pref_unifiednlp_summary, backendCount, backendCount));
boolean checkinEnabled = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean(PREF_ENABLE_CHECKIN, false);
findPreference(PREF_CHECKIN).setSummary(checkinEnabled ? R.string.service_status_enabled : R.string.service_status_disabled);
}
}
}