Extract UserShortcutType functions from ToggleFeaturePreferenceFragment

* Simplify StringJoiner to '+' since it only have one case
* Simplify Collections usage to use removeIf() and findFirst() directly
* Change class name SharedPreferenceUtils to PreferredShortcuts

Bug: 158540780
Test: atest ToggleFeaturePreferenceFragmentTest
Test: atest PreferredShortcutsTest
Change-Id: I02f03ccba09b6d7edaa5c0c8223ab3561a5e976b
This commit is contained in:
jasonwshsu
2020-07-19 23:46:54 +08:00
committed by Jason Hsu
parent 26f1b5f65c
commit 48b546eccf
9 changed files with 225 additions and 164 deletions

View File

@@ -54,10 +54,6 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.androidx.fragment.FragmentController;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/** Tests for {@link ToggleFeaturePreferenceFragment} */
@RunWith(RobolectricTestRunner.class)
public class ToggleFeaturePreferenceFragmentTest {
@@ -159,9 +155,7 @@ public class ToggleFeaturePreferenceFragmentTest {
private void putUserShortcutTypeIntoSharedPreference(Context context,
PreferredShortcut shortcut) {
Set<String> value = new HashSet<>(Collections.singletonList(shortcut.toString()));
SharedPreferenceUtils.setUserShortcutType(context, value);
PreferredShortcuts.saveUserShortcutType(context, shortcut);
}
private void callEmptyOnClicked(DialogInterface dialog, int which) {}