From 2d7a6b80eb2f37b28466bdedd3ee8dbb681300e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Fri, 28 Jul 2023 22:47:39 +0100 Subject: [PATCH] Migrate Loyalty Cards preferences to AbstractSettingsActivityV2 --- .../AbstractSettingsActivityV2.java | 3 +- .../LoyaltyCardsSettingsActivity.java | 55 ++++--------------- .../LoyaltyCardsSettingsFragment.java | 13 +---- .../res/layout/activity_loyalty_cards.xml | 12 ---- 4 files changed, 16 insertions(+), 67 deletions(-) delete mode 100644 app/src/main/res/layout/activity_loyalty_cards.xml diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractSettingsActivityV2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractSettingsActivityV2.java index df746129e..3fb6976e5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractSettingsActivityV2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractSettingsActivityV2.java @@ -19,6 +19,7 @@ package nodomain.freeyourgadget.gadgetbridge.activities; import android.os.Bundle; import android.view.MenuItem; +import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.fragment.app.Fragment; import androidx.preference.PreferenceFragmentCompat; @@ -70,7 +71,7 @@ public abstract class AbstractSettingsActivityV2 extends AbstractGBActivity impl } @Override - public boolean onOptionsItemSelected(final MenuItem item) { + public boolean onOptionsItemSelected(@NonNull final MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // Simulate a back press, so that we don't actually exit the activity when diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/loyaltycards/LoyaltyCardsSettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/loyaltycards/LoyaltyCardsSettingsActivity.java index 1a9bf9686..da7c5efb9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/loyaltycards/LoyaltyCardsSettingsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/loyaltycards/LoyaltyCardsSettingsActivity.java @@ -29,10 +29,11 @@ import androidx.preference.PreferenceScreen; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity; +import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivityV2; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; -public class LoyaltyCardsSettingsActivity extends AbstractGBActivity implements +public class LoyaltyCardsSettingsActivity extends AbstractSettingsActivityV2 implements PreferenceFragmentCompat.OnPreferenceStartScreenCallback, ActivityCompat.OnRequestPermissionsResultCallback { @@ -40,53 +41,21 @@ public class LoyaltyCardsSettingsActivity extends AbstractGBActivity implements private GBDevice device; + @Override + protected String fragmentTag() { + return LoyaltyCardsSettingsFragment.FRAGMENT_TAG; + } + + @Override + protected PreferenceFragmentCompat newFragment() { + return LoyaltyCardsSettingsFragment.newInstance(device); + } + @Override protected void onCreate(final Bundle savedInstanceState) { device = getIntent().getParcelableExtra(GBDevice.EXTRA_DEVICE); super.onCreate(savedInstanceState); - setContentView(R.layout.activity_loyalty_cards); - if (savedInstanceState == null) { - Fragment fragment = getSupportFragmentManager().findFragmentByTag(LoyaltyCardsSettingsFragment.FRAGMENT_TAG); - if (fragment == null) { - fragment = LoyaltyCardsSettingsFragment.newInstance(device); - } - getSupportFragmentManager() - .beginTransaction() - .replace(R.id.settings_container, fragment, LoyaltyCardsSettingsFragment.FRAGMENT_TAG) - .commit(); - } - } - - @Override - public boolean onPreferenceStartScreen(final PreferenceFragmentCompat caller, final PreferenceScreen preferenceScreen) { - final PreferenceFragmentCompat fragment = LoyaltyCardsSettingsFragment.newInstance(device); - final Bundle args = fragment.getArguments(); - if (args != null) { - args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.getKey()); - fragment.setArguments(args); - } - - getSupportFragmentManager() - .beginTransaction() - .replace(R.id.settings_container, fragment, preferenceScreen.getKey()) - .addToBackStack(preferenceScreen.getKey()) - .commit(); - - return true; - } - - @Override - public boolean onOptionsItemSelected(@NonNull final MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - // Simulate a back press, so that we don't actually exit the activity when - // in a nested PreferenceScreen - this.onBackPressed(); - return true; - } - - return super.onOptionsItemSelected(item); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/loyaltycards/LoyaltyCardsSettingsFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/loyaltycards/LoyaltyCardsSettingsFragment.java index cdc7c1b19..a0f7d6e10 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/loyaltycards/LoyaltyCardsSettingsFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/loyaltycards/LoyaltyCardsSettingsFragment.java @@ -23,10 +23,7 @@ import static nodomain.freeyourgadget.gadgetbridge.activities.loyaltycards.Loyal import static nodomain.freeyourgadget.gadgetbridge.activities.loyaltycards.LoyaltyCardsSettingsConst.LOYALTY_CARDS_INSTALL_CATIMA; import static nodomain.freeyourgadget.gadgetbridge.activities.loyaltycards.LoyaltyCardsSettingsConst.LOYALTY_CARDS_OPEN_CATIMA; import static nodomain.freeyourgadget.gadgetbridge.activities.loyaltycards.LoyaltyCardsSettingsConst.LOYALTY_CARDS_SYNC; -import static nodomain.freeyourgadget.gadgetbridge.activities.loyaltycards.LoyaltyCardsSettingsConst.LOYALTY_CARDS_SYNC_ARCHIVED; import static nodomain.freeyourgadget.gadgetbridge.activities.loyaltycards.LoyaltyCardsSettingsConst.LOYALTY_CARDS_SYNC_GROUPS; -import static nodomain.freeyourgadget.gadgetbridge.activities.loyaltycards.LoyaltyCardsSettingsConst.LOYALTY_CARDS_SYNC_GROUPS_ONLY; -import static nodomain.freeyourgadget.gadgetbridge.activities.loyaltycards.LoyaltyCardsSettingsConst.LOYALTY_CARDS_SYNC_STARRED; import static nodomain.freeyourgadget.gadgetbridge.activities.loyaltycards.LoyaltyCardsSettingsConst.PREF_KEY_HEADER_LOYALTY_CARDS_CATIMA; import static nodomain.freeyourgadget.gadgetbridge.activities.loyaltycards.LoyaltyCardsSettingsConst.PREF_KEY_HEADER_LOYALTY_CARDS_SYNC; import static nodomain.freeyourgadget.gadgetbridge.activities.loyaltycards.LoyaltyCardsSettingsConst.PREF_KEY_HEADER_LOYALTY_CARDS_SYNC_OPTIONS; @@ -44,29 +41,23 @@ import androidx.preference.ListPreference; import androidx.preference.MultiSelectListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; -import androidx.preference.PreferenceFragmentCompat; -import androidx.preference.SwitchPreference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; -import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.AbstractPreferenceFragment; import nodomain.freeyourgadget.gadgetbridge.capabilities.loyaltycards.CatimaContentProvider; import nodomain.freeyourgadget.gadgetbridge.capabilities.loyaltycards.CatimaManager; -import nodomain.freeyourgadget.gadgetbridge.capabilities.loyaltycards.LoyaltyCard; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; -public class LoyaltyCardsSettingsFragment extends PreferenceFragmentCompat { +public class LoyaltyCardsSettingsFragment extends AbstractPreferenceFragment { private static final Logger LOG = LoggerFactory.getLogger(LoyaltyCardsSettingsFragment.class); static final String FRAGMENT_TAG = "LOYALTY_CARDS_SETTINGS_FRAGMENT"; diff --git a/app/src/main/res/layout/activity_loyalty_cards.xml b/app/src/main/res/layout/activity_loyalty_cards.xml deleted file mode 100644 index c99658e68..000000000 --- a/app/src/main/res/layout/activity_loyalty_cards.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - -