Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce updated locale picker #16331

Merged
merged 35 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2e2139a
ADded backing models and view holders.
khaykov Jun 8, 2021
0365e99
Added adapter.
khaykov Jun 8, 2021
eab2be2
Updated locale manager to reurn triple with all the required values.
khaykov Jun 8, 2021
850093b
Added locale picker view model
khaykov Jun 8, 2021
b612dd9
Added bottom sheet with picker.
khaykov Jun 8, 2021
3da94ed
Reattaching locale picker callback.
khaykov Jun 10, 2021
0e96316
Minor visual tweaks.
khaykov Jun 10, 2021
603b453
Simplified logic.
khaykov Jun 10, 2021
3fbab83
Switched suggestion label to current language.
khaykov Jun 14, 2021
e48e415
Removed subheader.
khaykov Jun 14, 2021
c990562
Removed subheader from adapter.
khaykov Jun 14, 2021
d4d7965
Wrapping some language utils into LocaleProvider
khaykov Jun 14, 2021
0c61feb
Added tests.
khaykov Jun 14, 2021
ec5ebe6
Fixed checkstyle errors.
khaykov Jun 14, 2021
23fe646
Added localized locale name search test.
khaykov Jun 14, 2021
ade3644
Cleaning up.
khaykov Jun 14, 2021
94a7ccf
Merge branch 'develop' of github.com:wordpress-mobile/WordPress-Andro…
khaykov Jun 14, 2021
70d37e5
Removed unused view type.
khaykov Jun 14, 2021
0ce9eb5
Udpated release notes.
khaykov Jun 14, 2021
767f889
Removed layout manager from code.
khaykov Jun 17, 2021
c4fd366
Removed unused import.
khaykov Jun 17, 2021
2a1a3fd
Merge branch 'trunk' into feature/updated-locale-picker
Apr 13, 2022
2adc724
Fix out-of-date import
Apr 14, 2022
4a833a1
Update RELEASE-NOTES
Apr 14, 2022
a47d7a0
Merge branch 'trunk' into feature/updated-locale-picker
Apr 19, 2022
873234f
Bring @inject annotations inline for consistency
Apr 19, 2022
b3aafa5
Merge branch 'trunk' into feature/updated-locale-picker
Apr 19, 2022
a373e7a
Revert unintentional changes to formatting
Apr 19, 2022
49004d2
Merge branch 'feature/updated-locale-picker' of github.com:wordpress-…
Apr 19, 2022
7e9fd51
Revert unintentional changes to formatting
Apr 19, 2022
d186d4e
Merge branch 'trunk' into feature/updated-locale-picker
Apr 28, 2022
158d11e
Move parenthesis positioning for increased readability
Apr 28, 2022
84d3aab
Merge branch 'trunk' into feature/updated-locale-picker
Apr 28, 2022
f375f75
Add missing binding notation to method
Apr 28, 2022
ea45494
Update RELEASE-NOTES
Apr 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

19.8
-----
* [*] App Settings: updated look and functionality of Locale Picker [https://github.com/wordpress-mobile/WordPress-Android/pull/16331]
* [*] Fix issue that prevented Jetpack customers with standalone VideoPress subs uploading >5min videos [https://github.com/wordpress-mobile/WordPress-Android/pull/16322]
* [*] On self-hosted sites, allow previewing unsaved changes to draft posts [https://github.com/wordpress-mobile/WordPress-Android/pull/16296]
* [*] Editor: Fix issue that caused previews on atomic sites to sometimes be out-of-date. [https://github.com/wordpress-mobile/WordPress-Android/pull/16332]
* [*] Fixes Media Picker video selection Accessibility issue [https://github.com/wordpress-mobile/WordPress-Android/pull/16426]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
import org.wordpress.android.ui.prefs.categories.detail.CategoryDetailFragment;
import org.wordpress.android.ui.prefs.categories.list.CategoriesListFragment;
import org.wordpress.android.ui.prefs.homepage.HomepageSettingsDialog;
import org.wordpress.android.ui.prefs.language.LocalePickerBottomSheet;
import org.wordpress.android.ui.prefs.notifications.NotificationsSettingsFragment;
import org.wordpress.android.ui.prefs.timezone.SiteSettingsTimezoneBottomSheet;
import org.wordpress.android.ui.publicize.PublicizeAccountChooserListAdapter;
Expand Down Expand Up @@ -660,6 +661,8 @@ public interface AppComponent {
void inject(EditCancelDialogFragment object);

void inject(BloggingReminderBottomSheetFragment object);

void inject(LocalePickerBottomSheet object);

void inject(CategoriesListFragment object);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.wordpress.android.ui.prefs.categories.detail.CategoryDetailViewModel;
import org.wordpress.android.ui.prefs.categories.list.CategoriesListViewModel;
import org.wordpress.android.ui.prefs.homepage.HomepageSettingsViewModel;
import org.wordpress.android.ui.prefs.language.LocalePickerViewModel;
import org.wordpress.android.ui.prefs.timezone.SiteSettingsTimezoneViewModel;
import org.wordpress.android.ui.reader.ReaderCommentListViewModel;
import org.wordpress.android.ui.reader.discover.ReaderDiscoverViewModel;
Expand Down Expand Up @@ -582,6 +583,11 @@ abstract class ViewModelModule {
@ViewModelKey(CategoriesListViewModel.class)
abstract ViewModel categoriesViewModel(CategoriesListViewModel viewModel);

@Binds
@IntoMap
@ViewModelKey(LocalePickerViewModel.class)
abstract ViewModel localePickerViewModel(LocalePickerViewModel viewModel);

@Binds
@IntoMap
@ViewModelKey(CategoryDetailViewModel.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
import android.text.TextUtils;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -26,6 +25,7 @@

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jetbrains.annotations.NotNull;
import org.wordpress.android.BuildConfig;
import org.wordpress.android.R;
import org.wordpress.android.WordPress;
Expand All @@ -42,6 +42,8 @@
import org.wordpress.android.fluxc.store.WhatsNewStore.OnWhatsNewFetched;
import org.wordpress.android.fluxc.store.WhatsNewStore.WhatsNewAppId;
import org.wordpress.android.fluxc.store.WhatsNewStore.WhatsNewFetchPayload;
import org.wordpress.android.ui.prefs.language.LocalePickerBottomSheet;
import org.wordpress.android.ui.prefs.language.LocalePickerBottomSheet.LocalePickerCallback;
import org.wordpress.android.ui.about.UnifiedAboutActivity;
import org.wordpress.android.ui.debug.DebugSettingsActivity;
import org.wordpress.android.ui.mysite.tabs.MySiteDefaultTabExperiment;
Expand Down Expand Up @@ -72,10 +74,10 @@
import javax.inject.Inject;

public class AppSettingsFragment extends PreferenceFragment
implements OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
implements OnPreferenceClickListener, Preference.OnPreferenceChangeListener, LocalePickerCallback {
public static final int LANGUAGE_CHANGED = 1000;

private DetailListPreference mLanguagePreference;
private WPPreference mLanguagePreference;
private ListPreference mAppThemePreference;
private ListPreference mInitialScreenPreference;

Expand Down Expand Up @@ -136,8 +138,9 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
);
updateAnalyticsSyncUI();

mLanguagePreference = (DetailListPreference) findPreference(getString(R.string.pref_key_language));
mLanguagePreference = (WPPreference) findPreference(getString(R.string.pref_key_language));
mLanguagePreference.setOnPreferenceChangeListener(this);
mLanguagePreference.setOnPreferenceClickListener(this);

mAppThemePreference = (ListPreference) findPreference(getString(R.string.pref_key_app_theme));
mAppThemePreference.setOnPreferenceChangeListener(this);
Expand Down Expand Up @@ -302,8 +305,7 @@ public void onStop() {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

updateLanguagePreference(getResources().getConfiguration().locale.toString());
reattachLocalePickerCallback();
// flush gathered events (if any)
AnalyticsTracker.flush();
}
Expand Down Expand Up @@ -385,6 +387,8 @@ public boolean onPreferenceClick(Preference preference) {
return handlePrivacyClick();
} else if (preference == mWhatsNew) {
return handleFeatureAnnouncementClick();
} else if (preference == mLanguagePreference) {
return handleAppLocalePickerClick();
}

return false;
Expand Down Expand Up @@ -480,7 +484,6 @@ private void changeLanguage(String languageCode) {

LocaleManager.setNewLocale(WordPress.getContext(), languageCode);
WordPress.updateContextLocale();
updateLanguagePreference(languageCode);
mContextProvider.refreshContext();

// Track language change on Analytics because we have both the device language and app selected language
Expand All @@ -503,33 +506,6 @@ private void changeLanguage(String languageCode) {
ReaderUpdateServiceStarter.startService(WordPress.getContext(), EnumSet.of(ReaderUpdateLogic.UpdateTask.TAGS));
}

private void updateLanguagePreference(String languageCode) {
if (mLanguagePreference == null || TextUtils.isEmpty(languageCode)) {
return;
}

Locale languageLocale = LocaleManager.languageLocale(languageCode);
String[] availableLocales = getResources().getStringArray(R.array.available_languages);

Pair<String[], String[]> pair =
LocaleManager.createSortedLanguageDisplayStrings(availableLocales, languageLocale);
// check for a possible NPE
if (pair == null) {
return;
}

String[] sortedEntries = pair.first;
String[] sortedValues = pair.second;

mLanguagePreference.setEntries(sortedEntries);
mLanguagePreference.setEntryValues(sortedValues);
mLanguagePreference.setDetails(LocaleManager.createLanguageDetailDisplayStrings(sortedValues));

mLanguagePreference.setValue(languageCode);
mLanguagePreference.setSummary(LocaleManager.getLanguageString(languageCode, languageLocale));
mLanguagePreference.refreshAdapter();
}

private boolean handleAboutPreferenceClick() {
// Temporarily limiting this feature to the WordPress app
if (mUnifiedAboutFeatureConfig.isEnabled() && !BuildConfig.IS_JETPACK_APP) {
Expand Down Expand Up @@ -651,4 +627,33 @@ private boolean handleFeatureAnnouncementClick() {
+ "using support fragment manager from AppCompatActivity.");
}
}

private boolean handleAppLocalePickerClick() {
if (getActivity() instanceof AppCompatActivity) {
LocalePickerBottomSheet bottomSheet = LocalePickerBottomSheet.newInstance();
bottomSheet.setLocalePickerCallback(this);
bottomSheet.show(((AppCompatActivity) getActivity()).getSupportFragmentManager(),
LocalePickerBottomSheet.TAG);
return true;
} else {
throw new IllegalArgumentException(
"Parent activity is not AppCompatActivity. LocalePickerBottomSheet must be called "
+ "using support fragment manager from AppCompatActivity.");
}
}

private void reattachLocalePickerCallback() {
if (getActivity() instanceof AppCompatActivity) {
LocalePickerBottomSheet bottomSheet = (LocalePickerBottomSheet) (((AppCompatActivity) getActivity()))
.getSupportFragmentManager().findFragmentByTag(LocalePickerBottomSheet.TAG);
if (bottomSheet != null) {
bottomSheet.setLocalePickerCallback(this);
}
}
}

@Override
public void onLocaleSelected(@NotNull String languageCode) {
onPreferenceChange(mLanguagePreference, languageCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import android.preference.PreferenceScreen;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.util.Pair;
import android.util.SparseBooleanArray;
import android.view.ActionMode;
import android.view.HapticFeedbackConstants;
Expand Down Expand Up @@ -114,6 +113,8 @@

import static org.wordpress.android.ui.prefs.WPComSiteSettings.supportsJetpackSiteAcceleratorSettings;

import kotlin.Triple;

/**
* Allows interfacing with WordPress site settings. Works with WP.com and WP.org v4.5+ (pending).
* <p>
Expand Down Expand Up @@ -1654,15 +1655,16 @@ private void sortLanguages() {
return;
}

Pair<String[], String[]> pair = LocaleManager
Triple<String[], String[], String[]> supportedLocales = LocaleManager
.createSortedLanguageDisplayStrings(mLanguagePref.getEntryValues(), LocaleManager.languageLocale(null));
if (pair != null) {
String[] sortedEntries = pair.first;
String[] sortedValues = pair.second;
if (supportedLocales != null) {
String[] sortedEntries = supportedLocales.component1();
String[] sortedValues = supportedLocales.component2();
String[] localizedEntries = supportedLocales.component3();

mLanguagePref.setEntries(sortedEntries);
mLanguagePref.setEntryValues(sortedValues);
mLanguagePref.setDetails(LocaleManager.createLanguageDetailDisplayStrings(sortedValues));
mLanguagePref.setDetails(localizedEntries);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.wordpress.android.ui.prefs.language

import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import org.wordpress.android.ui.prefs.language.LocalePickerListItem.LocalePickerListViewType.LOCALE
import org.wordpress.android.ui.prefs.language.LocalePickerListItem.LocaleRow

class LocalePickerAdapter : ListAdapter<LocalePickerListItem, LocalePickerListViewHolder<*>>(DIFF_CALLBACK) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LocalePickerListViewHolder<*> {
return when (viewType) {
LOCALE.ordinal -> LocalePickerListItemViewHolder(parent)
else -> throw IllegalArgumentException("Unexpected view holder in LocalePickerAdapter")
}
}

override fun onBindViewHolder(holder: LocalePickerListViewHolder<*>, position: Int) {
val item = getItem(position)
when (holder) {
is LocalePickerListItemViewHolder -> holder.bind(item as LocaleRow)
}
}

override fun getItemViewType(position: Int): Int {
return getItem(position)!!.type.ordinal
}

companion object {
val DIFF_CALLBACK = object : DiffUtil.ItemCallback<LocalePickerListItem>() {
override fun areItemsTheSame(oldItem: LocalePickerListItem, newItem: LocalePickerListItem): Boolean {
return when {
oldItem is LocaleRow && newItem is LocaleRow -> oldItem.label == newItem.label
else -> false
}
}

override fun areContentsTheSame(oldItem: LocalePickerListItem, newItem: LocalePickerListItem) =
oldItem == newItem
}
}
}
Loading