From deb72e29ef884c789fa098da7d574b358873984e Mon Sep 17 00:00:00 2001 From: menghanli Date: Wed, 29 Jun 2022 08:27:12 +0800 Subject: [PATCH] Refactor CaptionMoreOptionsFragment to improve maintainability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause: There is a bunch of different logic of preferences in CaptionMoreOptionsFragment. It’s hard to implement new features and hard to maintain and hard to be testable. Solution: Move out different logic of CaptionMoreOptionsFragment into controllers to reduce the complexity of the relationship between preference and fragment. Bug: 197695932 Test: make RunSettingsRoboTests ROBOTEST_FILTER=CaptionMoreOptionsFragmentTest CaptionLocalePreferenceControllerTest Change-Id: Ifdf3e22b027328a9f8eb13d756730ca047ece047 --- res/xml/captioning_more_options.xml | 4 +- .../CaptionLocalePreferenceController.java | 66 +++++++++++++ .../CaptionMoreOptionsFragment.java | 49 +--------- ...CaptionLocalePreferenceControllerTest.java | 92 +++++++++++++++++++ .../CaptionMoreOptionsFragmentTest.java | 50 ++++++++++ 5 files changed, 211 insertions(+), 50 deletions(-) create mode 100644 src/com/android/settings/accessibility/CaptionLocalePreferenceController.java create mode 100644 tests/robotests/src/com/android/settings/accessibility/CaptionLocalePreferenceControllerTest.java create mode 100644 tests/robotests/src/com/android/settings/accessibility/CaptionMoreOptionsFragmentTest.java diff --git a/res/xml/captioning_more_options.xml b/res/xml/captioning_more_options.xml index b902c48a952..c4fc5297205 100644 --- a/res/xml/captioning_more_options.xml +++ b/res/xml/captioning_more_options.xml @@ -22,8 +22,8 @@ + android:title="@string/captioning_locale" + settings:controller="com.android.settings.accessibility.CaptionLocalePreferenceController"/> niks = CaptionMoreOptionsFragment.SEARCH_INDEX_DATA_PROVIDER + .getNonIndexableKeys(mContext); + final List keys = + XmlTestUtils.getKeysFromPreferenceXml(mContext, + R.xml.captioning_more_options); + + assertThat(keys).containsAtLeastElementsIn(niks); + } +}