mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-31 23:03:54 +01:00
init
This commit is contained in:
parent
bd436422dc
commit
bdda18223e
7 changed files with 57 additions and 12 deletions
|
|
@ -223,7 +223,9 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
||||||
final String twoFactorCode = Objects.requireNonNull(binding.loginTwoFactor.getText()).toString();
|
final String twoFactorCode = Objects.requireNonNull(binding.loginTwoFactor.getText()).toString();
|
||||||
|
|
||||||
showLoggingProgressBar();
|
showLoggingProgressBar();
|
||||||
loginClient.doLogin(username, password, twoFactorCode, Locale.getDefault().getLanguage(),
|
String fullCode = Locale.getDefault().getLanguage();
|
||||||
|
String mainCode = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode;
|
||||||
|
loginClient.doLogin(username, password, twoFactorCode, mainCode,
|
||||||
new LoginCallback() {
|
new LoginCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void success(@NonNull LoginResult loginResult) {
|
public void success(@NonNull LoginResult loginResult) {
|
||||||
|
|
|
||||||
|
|
@ -490,7 +490,7 @@ public class MainActivity extends BaseActivity
|
||||||
Activity.MODE_PRIVATE);
|
Activity.MODE_PRIVATE);
|
||||||
final String language = preferences.getString("language", "");
|
final String language = preferences.getString("language", "");
|
||||||
final SettingsFragment settingsFragment = new SettingsFragment();
|
final SettingsFragment settingsFragment = new SettingsFragment();
|
||||||
settingsFragment.setLocale(this, language);
|
settingsFragment.setLocale(this, language, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NavTabLayout.OnNavigationItemSelectedListener getNavListener() {
|
public NavTabLayout.OnNavigationItemSelectedListener getNavListener() {
|
||||||
|
|
|
||||||
|
|
@ -345,6 +345,8 @@ public class NetworkingModule {
|
||||||
@Singleton
|
@Singleton
|
||||||
@Named(NAMED_LANGUAGE_WIKI_PEDIA_WIKI_SITE)
|
@Named(NAMED_LANGUAGE_WIKI_PEDIA_WIKI_SITE)
|
||||||
public WikiSite provideLanguageWikipediaSite() {
|
public WikiSite provideLanguageWikipediaSite() {
|
||||||
return WikiSite.forLanguageCode(Locale.getDefault().getLanguage());
|
String fullCode = Locale.getDefault().getLanguage();
|
||||||
|
String mainCode = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode;
|
||||||
|
return WikiSite.forLanguageCode(mainCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -707,7 +707,8 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
||||||
*/
|
*/
|
||||||
private void buildDepictionList(List<IdAndCaptions> idAndCaptions) {
|
private void buildDepictionList(List<IdAndCaptions> idAndCaptions) {
|
||||||
binding.mediaDetailDepictionContainer.removeAllViews();
|
binding.mediaDetailDepictionContainer.removeAllViews();
|
||||||
String locale = Locale.getDefault().getLanguage();
|
String fullCode = Locale.getDefault().getLanguage();
|
||||||
|
String locale = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode;
|
||||||
for (IdAndCaptions idAndCaption : idAndCaptions) {
|
for (IdAndCaptions idAndCaption : idAndCaptions) {
|
||||||
binding.mediaDetailDepictionContainer.addView(buildDepictLabel(
|
binding.mediaDetailDepictionContainer.addView(buildDepictLabel(
|
||||||
getDepictionCaption(idAndCaption, locale),
|
getDepictionCaption(idAndCaption, locale),
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,8 @@ public class NearbyController extends MapController {
|
||||||
Timber.d("Loading attractions nearby, but currentLatLng is null");
|
Timber.d("Loading attractions nearby, but currentLatLng is null");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
String fullCode = Locale.getDefault().getLanguage();
|
||||||
|
String mainCode = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode;
|
||||||
List<Place> places = nearbyPlaces
|
List<Place> places = nearbyPlaces
|
||||||
.radiusExpander(searchLatLng, Locale.getDefault().getLanguage(), returnClosestResult,
|
.radiusExpander(searchLatLng, Locale.getDefault().getLanguage(), returnClosestResult,
|
||||||
customQuery);
|
customQuery);
|
||||||
|
|
|
||||||
|
|
@ -373,9 +373,11 @@ public class UploadRepository {
|
||||||
@Nullable
|
@Nullable
|
||||||
public Place checkNearbyPlaces(final double decLatitude, final double decLongitude) {
|
public Place checkNearbyPlaces(final double decLatitude, final double decLongitude) {
|
||||||
try {
|
try {
|
||||||
|
String fullCode = Locale.getDefault().getLanguage();
|
||||||
|
String mainCode = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode;
|
||||||
final List<Place> fromWikidataQuery = nearbyPlaces.getFromWikidataQuery(new LatLng(
|
final List<Place> fromWikidataQuery = nearbyPlaces.getFromWikidataQuery(new LatLng(
|
||||||
decLatitude, decLongitude, 0.0f),
|
decLatitude, decLongitude, 0.0f),
|
||||||
Locale.getDefault().getLanguage(),
|
mainCode,
|
||||||
NEARBY_RADIUS_IN_KILO_METERS, null);
|
NEARBY_RADIUS_IN_KILO_METERS, null);
|
||||||
return (fromWikidataQuery != null && fromWikidataQuery.size() > 0) ? fromWikidataQuery
|
return (fromWikidataQuery != null && fromWikidataQuery.size() > 0) ? fromWikidataQuery
|
||||||
.get(0) : null;
|
.get(0) : null;
|
||||||
|
|
|
||||||
|
|
@ -327,7 +327,9 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||||
System.out.println(languageCode);
|
System.out.println(languageCode);
|
||||||
HashMap<Integer, String> selectedLanguages = new HashMap<>();
|
HashMap<Integer, String> selectedLanguages = new HashMap<>();
|
||||||
assert languageCode != null;
|
assert languageCode != null;
|
||||||
selectedLanguages.put(0, Locale.getDefault().getLanguage());
|
String fullCode = Locale.getDefault().getLanguage();
|
||||||
|
String mainCode = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode;
|
||||||
|
selectedLanguages.put(0, mainCode);
|
||||||
|
|
||||||
// Deserializing saved language codes to Language objects
|
// Deserializing saved language codes to Language objects
|
||||||
ArrayList<Language> Saved_Languages = new ArrayList<>();
|
ArrayList<Language> Saved_Languages = new ArrayList<>();
|
||||||
|
|
@ -422,6 +424,10 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||||
}
|
}
|
||||||
descriptionSecondaryLanguageListPreference.setSummary(getCurrentLanguageCode("descriptionSecondaryLanguagePref"));
|
descriptionSecondaryLanguageListPreference.setSummary(getCurrentLanguageCode("descriptionSecondaryLanguagePref"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dialog.setOnDismissListener(dialogInterface -> {
|
||||||
|
setLocale(requireActivity(), languageCode, false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -448,7 +454,9 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||||
|
|
||||||
assert languageCode != null;
|
assert languageCode != null;
|
||||||
if (languageCode.equals("")) {
|
if (languageCode.equals("")) {
|
||||||
selectedLanguages.put(0, Locale.getDefault().getLanguage());
|
String fullCode = Locale.getDefault().getLanguage();
|
||||||
|
String mainCode = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode;
|
||||||
|
selectedLanguages.put(0, mainCode);
|
||||||
} else {
|
} else {
|
||||||
selectedLanguages.put(0, languageCode);
|
selectedLanguages.put(0, languageCode);
|
||||||
}
|
}
|
||||||
|
|
@ -456,7 +464,9 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||||
|
|
||||||
assert languageCode != null;
|
assert languageCode != null;
|
||||||
if (languageCode.equals("")) {
|
if (languageCode.equals("")) {
|
||||||
selectedLanguages.put(0, Locale.getDefault().getLanguage());
|
String fullCode = Locale.getDefault().getLanguage();
|
||||||
|
String mainCode = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode;
|
||||||
|
selectedLanguages.put(0, mainCode);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
selectedLanguages.put(0, languageCode);
|
selectedLanguages.put(0, languageCode);
|
||||||
|
|
@ -465,7 +475,9 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||||
|
|
||||||
assert languageCode != null;
|
assert languageCode != null;
|
||||||
if (languageCode.equals("")) {
|
if (languageCode.equals("")) {
|
||||||
selectedLanguages.put(0, Locale.getDefault().getLanguage());
|
String fullCode = Locale.getDefault().getLanguage();
|
||||||
|
String mainCode = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode;
|
||||||
|
selectedLanguages.put(0, mainCode);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
selectedLanguages.put(0, languageCode);
|
selectedLanguages.put(0, languageCode);
|
||||||
|
|
@ -535,7 +547,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||||
Locale defLocale = createLocale(languageCode);
|
Locale defLocale = createLocale(languageCode);
|
||||||
if(keyListPreference.equals("appUiDefaultLanguagePref")) {
|
if(keyListPreference.equals("appUiDefaultLanguagePref")) {
|
||||||
appUiLanguageListPreference.setSummary(defLocale.getDisplayLanguage(defLocale));
|
appUiLanguageListPreference.setSummary(defLocale.getDisplayLanguage(defLocale));
|
||||||
setLocale(requireActivity(), languageCode);
|
setLocale(requireActivity(), languageCode, true);
|
||||||
getActivity().recreate();
|
getActivity().recreate();
|
||||||
final Intent intent = new Intent(getActivity(), MainActivity.class);
|
final Intent intent = new Intent(getActivity(), MainActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
|
@ -603,7 +615,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||||
final Locale defLocale = createLocale(recentLanguageCode);
|
final Locale defLocale = createLocale(recentLanguageCode);
|
||||||
if (keyListPreference.equals("appUiDefaultLanguagePref")) {
|
if (keyListPreference.equals("appUiDefaultLanguagePref")) {
|
||||||
appUiLanguageListPreference.setSummary(defLocale.getDisplayLanguage(defLocale));
|
appUiLanguageListPreference.setSummary(defLocale.getDisplayLanguage(defLocale));
|
||||||
setLocale(requireActivity(), recentLanguageCode);
|
setLocale(requireActivity(), recentLanguageCode, true);
|
||||||
getActivity().recreate();
|
getActivity().recreate();
|
||||||
final Intent intent = new Intent(getActivity(), MainActivity.class);
|
final Intent intent = new Intent(getActivity(), MainActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
|
@ -622,13 +634,37 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||||
separator.setVisibility(View.GONE);
|
separator.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String reSerialise(ArrayList<String> languageCodes) {
|
||||||
|
// Join the elements of the list into a single string, separated by a comma and a space
|
||||||
|
return String.join(", ", languageCodes);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changing the default app language with selected one and save it to SharedPreferences
|
* Changing the default app language with selected one and save it to SharedPreferences
|
||||||
*/
|
*/
|
||||||
public void setLocale(final Activity activity, String userSelectedValue) {
|
public void setLocale(final Activity activity, String userSelectedValue, boolean appUI) {
|
||||||
|
|
||||||
if (userSelectedValue.equals("")) {
|
if (userSelectedValue.equals("")) {
|
||||||
userSelectedValue = Locale.getDefault().getLanguage();
|
userSelectedValue = Locale.getDefault().getLanguage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String current = Locale.getDefault().getLanguage();
|
||||||
|
ArrayList<String> languageCodes = deSerialise(current);
|
||||||
|
if(appUI) {
|
||||||
|
languageCodes.set(0, userSelectedValue);
|
||||||
|
userSelectedValue = reSerialise(languageCodes);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
ArrayList<String> newLanguageCodes = new ArrayList<>();
|
||||||
|
ArrayList<String> userSelctedCode = deSerialise(userSelectedValue);
|
||||||
|
|
||||||
|
newLanguageCodes.add(languageCodes.get(0));
|
||||||
|
for(String code : userSelctedCode){
|
||||||
|
newLanguageCodes.add(code);
|
||||||
|
}
|
||||||
|
userSelectedValue = reSerialise(newLanguageCodes);
|
||||||
|
}
|
||||||
|
|
||||||
final Locale locale = createLocale(userSelectedValue);
|
final Locale locale = createLocale(userSelectedValue);
|
||||||
Locale.setDefault(locale);
|
Locale.setDefault(locale);
|
||||||
final Configuration configuration = new Configuration();
|
final Configuration configuration = new Configuration();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue