Skip to content

Commit

Permalink
Move menu option to preference fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
WSTxda committed Jul 17, 2024
1 parent cfc7b6b commit 22507a3
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 52 deletions.
2 changes: 1 addition & 1 deletion play-services-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@

<activity
android:name="org.microg.gms.ui.LegacyAccountSettingsActivity"
android:label="@string/privacy_title"
android:label="@string/pref_privacy_title"
android:process=":ui"
android:taskAffinity="org.microg.gms.settings" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ import android.net.Uri
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
Expand Down Expand Up @@ -154,6 +150,15 @@ class AccountsFragment : PreferenceFragmentCompat() {
true
}

findPreference<Preference>("pref_privacy")?.setOnPreferenceClickListener {
try {
startActivity(Intent(requireContext(), LegacyAccountSettingsActivity::class.java))
} catch (activityNotFoundException: ActivityNotFoundException) {
Log.e(tag, "Failed to launch privacy activity", activityNotFoundException)
}
true
}

findPreference<Preference>("pref_manage_history")?.setOnPreferenceClickListener {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://myactivity.google.com/product/youtube")))
true
Expand All @@ -165,26 +170,6 @@ class AccountsFragment : PreferenceFragmentCompat() {
}
}

init {
setHasOptionsMenu(true)
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.accounts_menu_item, menu)
super.onCreateOptionsMenu(menu, inflater)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.privacy_settings -> {
findNavController().navigate(R.id.privacyFragment)
true
}

else -> super.onOptionsItemSelected(item)
}
}

private fun getDisplayName(account: Account): String? {
val databaseHelper = DatabaseHelper(requireContext())
val cursor = databaseHelper.getOwner(account.name)
Expand Down Expand Up @@ -216,9 +201,5 @@ class AccountsFragment : PreferenceFragmentCompat() {
super.onCreate(savedInstanceState)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.fragment.app.Fragment;
import androidx.preference.Preference;

Expand All @@ -38,14 +39,24 @@

public class LegacyAccountSettingsActivity extends AbstractSettingsActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
}

@Override
protected Fragment getFragment() {
return new AccountSettingsFragment();
}

public static class AccountSettingsFragment extends ResourceSettingsFragment {
public AccountSettingsFragment() {
preferencesResource = R.xml.preferences_account;
preferencesResource = R.xml.preferences_account;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion play-services-core/src/main/res/layout/ask_permission.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="10dp"
android:text="@string/privacy_title"
android:text="@string/pref_privacy_title"
android:textColor="?attr/colorPrimary" />

<View
Expand Down
9 changes: 0 additions & 9 deletions play-services-core/src/main/res/menu/accounts_menu_item.xml

This file was deleted.

5 changes: 0 additions & 5 deletions play-services-core/src/main/res/navigation/nav_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@
android:name="org.microg.gms.ui.PushNotificationAdvancedFragment"
android:label="@string/menu_settings" />

<fragment
android:id="@+id/privacyFragment"
android:name="org.microg.gms.ui.LegacyAccountSettingsActivity$AccountSettingsFragment"
android:label="@string/privacy_title" />

<!-- About -->

<fragment
Expand Down
3 changes: 2 additions & 1 deletion play-services-core/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<string name="ask_scope_permission_title"><xliff:g example="F-Droid">%1$s</xliff:g> gostaria de:</string>
<string name="ask_service_permission_title"><xliff:g example="F-Droid">%1$s</xliff:g> gostaria de usar:</string>

<string name="privacy_title">Privacidade</string>
<string name="pref_privacy_title">Privacidade</string>
<string name="pref_privacy_summary">Configurações de privacidade para autenticação e apps</string>
<string name="prefcat_applications">Aplicativos</string>
<string name="prefcat_authentication">Autenticação</string>

Expand Down
3 changes: 2 additions & 1 deletion play-services-core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<string name="ask_scope_permission_title"><xliff:g example="F-Droid">%1$s</xliff:g> would like to:</string>
<string name="ask_service_permission_title"><xliff:g example="F-Droid">%1$s</xliff:g> would like to use:</string>

<string name="privacy_title">Privacy</string>
<string name="pref_privacy_title">Privacy</string>
<string name="pref_privacy_summary">Privacy settings for authentication and apps</string>
<string name="prefcat_applications">Applications</string>
<string name="prefcat_authentication">Authentication</string>

Expand Down
17 changes: 12 additions & 5 deletions play-services-core/src/main/res/xml/preferences_accounts.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<PreferenceCategory
android:key="prefcat_current_accounts"
android:title="@string/prefcat_accounts_login_accounts_title"
android:visibility="gone" />

<Preference
android:icon="@drawable/ic_add_new_account"
android:key="pref_add_account"
app:allowDividerBelow="true"
android:title="@string/pref_accounts_add_account_title" />

<PreferenceCategory
android:key="prefcat_account_settings"
android:title="@string/prefcat_accounts_options_title">

<Preference
android:icon="@drawable/ic_add_new_account"
android:key="pref_add_account"
android:summary="@string/pref_account_summary"
android:title="@string/pref_accounts_add_account_title" />
android:icon="@drawable/ic_privacy"
android:key="pref_privacy"
android:summary="@string/pref_privacy_summary"
android:title="@string/pref_privacy_title" />

<Preference
android:icon="@drawable/ic_manage_account"
Expand Down

0 comments on commit 22507a3

Please sign in to comment.