mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	Finished Issue 1
This commit is contained in:
		
							parent
							
								
									7f537f2ccd
								
							
						
					
					
						commit
						1dd633d9b9
					
				
					 10 changed files with 142 additions and 103 deletions
				
			
		|  | @ -223,9 +223,7 @@ 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(); | ||||||
|         String fullCode = Locale.getDefault().getLanguage(); |         loginClient.doLogin(username, password, twoFactorCode, 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, true); |         settingsFragment.setLocale(this, language); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public NavTabLayout.OnNavigationItemSelectedListener getNavListener() { |     public NavTabLayout.OnNavigationItemSelectedListener getNavListener() { | ||||||
|  |  | ||||||
|  | @ -345,8 +345,6 @@ 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() { | ||||||
|         String fullCode = Locale.getDefault().getLanguage(); |         return WikiSite.forLanguageCode(Locale.getDefault().getLanguage()); | ||||||
|         String mainCode = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode; |  | ||||||
|         return WikiSite.forLanguageCode(mainCode); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1367,10 +1367,8 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private String chooseDescription(Media media) { |     private String chooseDescription(Media media) { | ||||||
|         String fullCode = Locale.getDefault().getLanguage(); |  | ||||||
|         String mainCode = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode; |  | ||||||
|         final Map<String, String> descriptions = media.getDescriptions(); |         final Map<String, String> descriptions = media.getDescriptions(); | ||||||
|         final String multilingualDesc = descriptions.get(mainCode); |         final String multilingualDesc = descriptions.get(Locale.getDefault().getLanguage()); | ||||||
|         if (multilingualDesc != null) { |         if (multilingualDesc != null) { | ||||||
|             return multilingualDesc; |             return multilingualDesc; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -409,15 +409,55 @@ public class OkHttpJsonApiClient { | ||||||
|      */ |      */ | ||||||
|     @Nullable |     @Nullable | ||||||
|     public List<Place> getPlaces( |     public List<Place> getPlaces( | ||||||
|         final List<Place> placeList, final String language) throws IOException { |         final List<Place> placeList, final String language, final String secondaryLanguages) throws IOException { | ||||||
|         final String wikidataQuery = FileUtils.readFromResource("/queries/query_for_item.rq"); |         final String wikidataQuery = FileUtils.readFromResource("/queries/query_for_item.rq"); | ||||||
|  |         final String[] secondaryLanguageArray = secondaryLanguages.split(",\\s*"); // could be used to generate backup SparQL Queries | ||||||
|  | 
 | ||||||
|         String qids = ""; |         String qids = ""; | ||||||
|         for (final Place place : placeList) { |         for (final Place place : placeList) { | ||||||
|             qids += "\n" + ("wd:" + place.getWikiDataEntityId()); |             qids += "\n" + ("wd:" + place.getWikiDataEntityId()); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         StringBuilder fallBackDescription = new StringBuilder(); | ||||||
|  |         for (int i = 0; i < secondaryLanguageArray.length; i++) { | ||||||
|  |             fallBackDescription.append("OPTIONAL {?item schema:description ?itemDescriptionPreferredLanguage_") | ||||||
|  |                 .append(i + 1) | ||||||
|  |                 .append(". FILTER (lang(?itemDescriptionPreferredLanguage_") | ||||||
|  |                 .append(i + 1) | ||||||
|  |                 .append(") = \"") | ||||||
|  |                 .append(secondaryLanguageArray[i]) | ||||||
|  |                 .append("\")}\n"); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         StringBuilder fallbackLabel = new StringBuilder(); | ||||||
|  |         for (int i = 0; i < secondaryLanguageArray.length; i++) { | ||||||
|  |             fallbackLabel.append("OPTIONAL {?item rdfs:label ?itemLabelPreferredLanguage_") | ||||||
|  |                 .append(i + 1) | ||||||
|  |                 .append(". FILTER (lang(?itemLabelPreferredLanguage_") | ||||||
|  |                 .append(i + 1) | ||||||
|  |                 .append(") = \"") | ||||||
|  |                 .append(secondaryLanguageArray[i]) | ||||||
|  |                 .append("\")}\n"); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         StringBuilder fallbackClassLabel = new StringBuilder(); | ||||||
|  |         for (int i = 0; i < secondaryLanguageArray.length; i++) { | ||||||
|  |             fallbackClassLabel.append("OPTIONAL {?class rdfs:label ?classLabelPreferredLanguage_") | ||||||
|  |                 .append(i + 1) | ||||||
|  |                 .append(". FILTER (lang(?classLabelPreferredLanguage_") | ||||||
|  |                 .append(i + 1) | ||||||
|  |                 .append(") = \"") | ||||||
|  |                 .append(secondaryLanguageArray[i]) | ||||||
|  |                 .append("\")}\n"); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         final String query = wikidataQuery |         final String query = wikidataQuery | ||||||
|             .replace("${ENTITY}", qids) |             .replace("${ENTITY}", qids) | ||||||
|             .replace("${LANG}", language); |             .replace("${LANG}", language) | ||||||
|  |             .replace("${SECONDARYDESCRIPTION}", fallBackDescription.toString()) | ||||||
|  |             .replace("${SECONDARYLABEL}", fallbackLabel.toString()) | ||||||
|  |             .replace("${SECONDARYCLASSLABEL}", fallbackClassLabel.toString()); | ||||||
|  | 
 | ||||||
|         final HttpUrl.Builder urlBuilder = HttpUrl |         final HttpUrl.Builder urlBuilder = HttpUrl | ||||||
|             .parse(sparqlQueryUrl) |             .parse(sparqlQueryUrl) | ||||||
|             .newBuilder() |             .newBuilder() | ||||||
|  | @ -640,17 +680,13 @@ public class OkHttpJsonApiClient { | ||||||
|             } |             } | ||||||
|         }).doOnError(Timber::e)); |         }).doOnError(Timber::e)); | ||||||
|     } |     } | ||||||
|     String fullCode = Locale.getDefault().getLanguage(); |  | ||||||
|     String mainCode = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode; |  | ||||||
| 
 | 
 | ||||||
|     @NotNull |     @NotNull | ||||||
|     private Request sparqlQuery(String qid, int startPosition, int limit, String fileName) |     private Request sparqlQuery(String qid, int startPosition, int limit, String fileName) | ||||||
|         throws IOException { |         throws IOException { | ||||||
|         String fullCode = Locale.getDefault().getLanguage(); |  | ||||||
|         String mainCode = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode; |  | ||||||
|         String query = FileUtils.readFromResource(fileName) |         String query = FileUtils.readFromResource(fileName) | ||||||
|             .replace("${QID}", qid) |             .replace("${QID}", qid) | ||||||
|             .replace("${LANG}", "\"" + mainCode + "\"") |             .replace("${LANG}", "\"" + Locale.getDefault().getLanguage() + "\"") | ||||||
|             .replace("${LIMIT}", "" + limit) |             .replace("${LIMIT}", "" + limit) | ||||||
|             .replace("${OFFSET}", "" + startPosition); |             .replace("${OFFSET}", "" + startPosition); | ||||||
|         HttpUrl.Builder urlBuilder = HttpUrl |         HttpUrl.Builder urlBuilder = HttpUrl | ||||||
|  |  | ||||||
|  | @ -8,6 +8,8 @@ import androidx.annotation.Nullable; | ||||||
| import fr.free.nrw.commons.BaseMarker; | import fr.free.nrw.commons.BaseMarker; | ||||||
| import fr.free.nrw.commons.MapController; | import fr.free.nrw.commons.MapController; | ||||||
| import fr.free.nrw.commons.location.LatLng; | import fr.free.nrw.commons.location.LatLng; | ||||||
|  | import fr.free.nrw.commons.kvstore.JsonKvStore; | ||||||
|  | import fr.free.nrw.commons.settings.Prefs; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.Collections; | import java.util.Collections; | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
|  | @ -16,6 +18,7 @@ import java.util.ListIterator; | ||||||
| import java.util.Locale; | import java.util.Locale; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import javax.inject.Inject; | import javax.inject.Inject; | ||||||
|  | import javax.inject.Named; | ||||||
| import timber.log.Timber; | import timber.log.Timber; | ||||||
| 
 | 
 | ||||||
| public class NearbyController extends MapController { | public class NearbyController extends MapController { | ||||||
|  | @ -34,6 +37,9 @@ public class NearbyController extends MapController { | ||||||
|         this.nearbyPlaces = nearbyPlaces; |         this.nearbyPlaces = nearbyPlaces; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     @Inject | ||||||
|  |     @Named("default_preferences") | ||||||
|  |     JsonKvStore defaultKvStore; | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Prepares Place list to make their distance information update later. |      * Prepares Place list to make their distance information update later. | ||||||
|  | @ -56,10 +62,9 @@ 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, mainCode, returnClosestResult, |             .radiusExpander(searchLatLng, Locale.getDefault().getLanguage(), returnClosestResult, | ||||||
|                 customQuery); |                 customQuery); | ||||||
| 
 | 
 | ||||||
|         if (null != places && places.size() > 0) { |         if (null != places && places.size() > 0) { | ||||||
|  | @ -141,9 +146,10 @@ public class NearbyController extends MapController { | ||||||
|      * @throws Exception If an error occurs during the retrieval process. |      * @throws Exception If an error occurs during the retrieval process. | ||||||
|      */ |      */ | ||||||
|     public List<Place> getPlaces(List<Place> placeList) throws Exception { |     public List<Place> getPlaces(List<Place> placeList) throws Exception { | ||||||
|         String fullCode = Locale.getDefault().getLanguage(); | 
 | ||||||
|         String mainCode = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode; |         String secondaryLanguages = defaultKvStore.getString(Prefs.SECONDARY_LANGUAGE, ""); | ||||||
|         return nearbyPlaces.getPlaces(placeList, mainCode); | 
 | ||||||
|  |         return nearbyPlaces.getPlaces(placeList, Locale.getDefault().getLanguage(), secondaryLanguages); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static LatLng calculateNorthEast(double latitude, double longitude, double distance) { |     public static LatLng calculateNorthEast(double latitude, double longitude, double distance) { | ||||||
|  | @ -200,11 +206,8 @@ public class NearbyController extends MapController { | ||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         String fullCode = Locale.getDefault().getLanguage(); |  | ||||||
|         String mainCode = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode; |  | ||||||
| 
 |  | ||||||
|         List<Place> places = nearbyPlaces.getFromWikidataQuery(screenTopRight, screenBottomLeft, |         List<Place> places = nearbyPlaces.getFromWikidataQuery(screenTopRight, screenBottomLeft, | ||||||
|             mainCode, shouldQueryForMonuments, customQuery); |             Locale.getDefault().getLanguage(), shouldQueryForMonuments, customQuery); | ||||||
| 
 | 
 | ||||||
|         if (null != places && places.size() > 0) { |         if (null != places && places.size() > 0) { | ||||||
|             LatLng[] boundaryCoordinates = { |             LatLng[] boundaryCoordinates = { | ||||||
|  |  | ||||||
|  | @ -131,9 +131,9 @@ public class NearbyPlaces { | ||||||
|      * @throws Exception If an error occurs during the retrieval process. |      * @throws Exception If an error occurs during the retrieval process. | ||||||
|      */ |      */ | ||||||
|     public List<Place> getPlaces(final List<Place> placeList, |     public List<Place> getPlaces(final List<Place> placeList, | ||||||
|         final String lang) throws Exception { |         final String lang, final String lang2) throws Exception { | ||||||
|         return okHttpJsonApiClient |         return okHttpJsonApiClient | ||||||
|             .getPlaces(placeList, lang); |             .getPlaces(placeList, lang, lang2); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  |  | ||||||
|  | @ -373,11 +373,9 @@ 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), | ||||||
|                 mainCode, |                 Locale.getDefault().getLanguage(), | ||||||
|                 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; | ||||||
|  |  | ||||||
|  | @ -190,18 +190,11 @@ public class SettingsFragment extends PreferenceFragmentCompat { | ||||||
|         keyLanguageListPreference = descriptionSecondaryLanguageListPreference.getKey(); |         keyLanguageListPreference = descriptionSecondaryLanguageListPreference.getKey(); | ||||||
|         languageCode = getCurrentLanguageCode(keyLanguageListPreference); |         languageCode = getCurrentLanguageCode(keyLanguageListPreference); | ||||||
|         assert languageCode != null; |         assert languageCode != null; | ||||||
|         if (languageCode.equals("")) { |         descriptionSecondaryLanguageListPreference.setSummary("List additional languages."); | ||||||
|             // If current language code is empty, means none selected by user yet so use phone local | 
 | ||||||
|             descriptionSecondaryLanguageListPreference.setSummary(Locale.getDefault().getDisplayLanguage()); |  | ||||||
|         } else { |  | ||||||
|             // If any language is selected by user previously, use it |  | ||||||
|             Locale defLocale = createLocale(languageCode); |  | ||||||
|             descriptionSecondaryLanguageListPreference.setSummary(defLocale.getDisplayLanguage(defLocale)); |  | ||||||
|         } |  | ||||||
|         descriptionSecondaryLanguageListPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { |         descriptionSecondaryLanguageListPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { | ||||||
|             @Override |             @Override | ||||||
|             public boolean onPreferenceClick(Preference preference) { |             public boolean onPreferenceClick(Preference preference) { | ||||||
|                 System.out.println("click recieved"); |  | ||||||
|                 prepareSecondaryLanguageDialog(); |                 prepareSecondaryLanguageDialog(); | ||||||
|                 return true; |                 return true; | ||||||
|             } |             } | ||||||
|  | @ -323,19 +316,22 @@ public class SettingsFragment extends PreferenceFragmentCompat { | ||||||
| 
 | 
 | ||||||
|     private void prepareSecondaryLanguageDialog() { |     private void prepareSecondaryLanguageDialog() { | ||||||
|         final String languageCode = getCurrentLanguageCode("descriptionSecondaryLanguagePref"); |         final String languageCode = getCurrentLanguageCode("descriptionSecondaryLanguagePref"); | ||||||
|         System.out.println("before"); |  | ||||||
|         System.out.println(languageCode); |  | ||||||
|         HashMap<Integer, String> selectedLanguages = new HashMap<>(); |         HashMap<Integer, String> selectedLanguages = new HashMap<>(); | ||||||
|         assert languageCode != null; |         assert languageCode != null; | ||||||
|         String fullCode = Locale.getDefault().getLanguage(); |         selectedLanguages.put(0, Locale.getDefault().getLanguage()); | ||||||
|         String mainCode = fullCode.contains(",") ? fullCode.substring(0, fullCode.indexOf(',')).trim() : fullCode; |         System.out.println(Locale.getDefault().getLanguage()); | ||||||
|         selectedLanguages.put(0, mainCode); |         System.out.println(languageCode); | ||||||
| 
 | 
 | ||||||
|         // Deserializing saved language codes to Language objects |         // Deserializing saved language codes to Language objects | ||||||
|         ArrayList<Language> Saved_Languages = new ArrayList<>(); |         ArrayList<Language> savedLanguages = new ArrayList<>(); | ||||||
|         for (String code : deSerialise(languageCode)) { |         for (String code : deSerialise(languageCode)) { | ||||||
|  |             System.out.println(code); | ||||||
|  |             if(code.equals(Locale.getDefault().getLanguage())){ | ||||||
|  |                 System.out.println("match"); | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|             Locale locale = new Locale(code); |             Locale locale = new Locale(code); | ||||||
|             Saved_Languages.add(new Language(locale.getDisplayLanguage(locale), code)); |             savedLanguages.add(new Language(locale.getDisplayLanguage(locale), code)); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // Create the new dialog for secondary language |         // Create the new dialog for secondary language | ||||||
|  | @ -355,29 +351,27 @@ public class SettingsFragment extends PreferenceFragmentCompat { | ||||||
|         View separator = dialog.findViewById(R.id.separator); |         View separator = dialog.findViewById(R.id.separator); | ||||||
| 
 | 
 | ||||||
|         // Setup saved languages with the new SavedLanguagesAdapter |         // Setup saved languages with the new SavedLanguagesAdapter | ||||||
|         updateSavedLanguages(savedLanguageListView, Saved_Languages, selectedLanguages); |         updateSavedLanguages(savedLanguageListView, savedLanguages, selectedLanguages); | ||||||
| 
 | 
 | ||||||
|         // Set an onItemClickListener to remove a language when clicked |         // Set an onItemClickListener to remove a language when clicked | ||||||
|         savedLanguageListView.setOnItemClickListener((adapterView, view, position, id) -> { |         savedLanguageListView.setOnItemClickListener((adapterView, view, position, id) -> { | ||||||
|             // Remove the clicked language from Saved_Languages |             // Remove the clicked language from Saved_Languages | ||||||
|             Saved_Languages.remove(position); |             savedLanguages.remove(position); | ||||||
| 
 | 
 | ||||||
|             // Update the saved language list view after removing the language |             // Update the saved language list view after removing the language | ||||||
|             updateSavedLanguages(savedLanguageListView, Saved_Languages, selectedLanguages); |             updateSavedLanguages(savedLanguageListView, savedLanguages, selectedLanguages); | ||||||
| 
 | 
 | ||||||
|             // Update the shared preferences to reflect the removal |             // Update the shared preferences to reflect the removal | ||||||
|             String updatedLanguageCodes = ""; |             String updatedLanguageCodes = ""; | ||||||
|             for (Language language : Saved_Languages) { |             for (Language language : savedLanguages) { | ||||||
|                 updatedLanguageCodes += language.getLanguageCode() + ", "; |                 updatedLanguageCodes += language.getLanguageCode() + ", "; | ||||||
|             } |             } | ||||||
|             // Remove the trailing comma and space if present |             // Remove the trailing comma and space if present | ||||||
|             if (!updatedLanguageCodes.isEmpty()) { |             if (!updatedLanguageCodes.isEmpty()) { | ||||||
|                 updatedLanguageCodes = updatedLanguageCodes.substring(0, updatedLanguageCodes.length() - 2); |                 updatedLanguageCodes = updatedLanguageCodes.substring(0, updatedLanguageCodes.length() - 2); | ||||||
|             } |             } | ||||||
| 
 |  | ||||||
|             saveLanguageValue(updatedLanguageCodes, "descriptionSecondaryLanguagePref"); |             saveLanguageValue(updatedLanguageCodes, "descriptionSecondaryLanguagePref"); | ||||||
|             System.out.println("after removal"); | //            descriptionSecondaryLanguageListPreference.setSummary(getCurrentLanguageCode("descriptionSecondaryLanguagePref")); | ||||||
|             System.out.println(getCurrentLanguageCode("descriptionSecondaryLanguagePref")); |  | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         // Set up the adapter for new languages using the selectedLanguages map |         // Set up the adapter for new languages using the selectedLanguages map | ||||||
|  | @ -411,22 +405,36 @@ public class SettingsFragment extends PreferenceFragmentCompat { | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             Saved_Languages.add(new Language(selectedLanguageName, selectedLanguageCode)); |             savedLanguages.add(new Language(selectedLanguageName, selectedLanguageCode)); | ||||||
|             updateSavedLanguages(savedLanguageListView, Saved_Languages, selectedLanguages); |             updateSavedLanguages(savedLanguageListView, savedLanguages, selectedLanguages); | ||||||
| 
 | 
 | ||||||
| 
 |             // Update the shared preferences to reflect the addition | ||||||
|             // Save the language |             String updatedLanguageCodes = ""; | ||||||
|             if (getCurrentLanguageCode("descriptionSecondaryLanguagePref").isEmpty()) { |             for (Language language : savedLanguages) { | ||||||
|                 saveLanguageValue(selectedLanguageCode, "descriptionSecondaryLanguagePref"); |                 updatedLanguageCodes += language.getLanguageCode() + ", "; | ||||||
|             } else { |  | ||||||
|                 saveLanguageValue(getCurrentLanguageCode("descriptionSecondaryLanguagePref") + ", " |  | ||||||
|                     + selectedLanguageCode, "descriptionSecondaryLanguagePref"); |  | ||||||
|             } |             } | ||||||
|             descriptionSecondaryLanguageListPreference.setSummary(getCurrentLanguageCode("descriptionSecondaryLanguagePref")); |             // Remove the trailing comma and space if present | ||||||
|  |             if (!updatedLanguageCodes.isEmpty()) { | ||||||
|  |                 updatedLanguageCodes = updatedLanguageCodes.substring(0, updatedLanguageCodes.length() - 2); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             saveLanguageValue(updatedLanguageCodes, "descriptionSecondaryLanguagePref"); | ||||||
|  | 
 | ||||||
|  | //            descriptionSecondaryLanguageListPreference.setSummary(getCurrentLanguageCode("descriptionSecondaryLanguagePref")); | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         dialog.setOnDismissListener(dialogInterface -> { |         dialog.setOnDismissListener(dialogInterface -> { | ||||||
|             setLocale(requireActivity(), languageCode, false); |             // Update the shared preferences to reflect changes | ||||||
|  |             String updatedLanguageCodes = ""; | ||||||
|  |             for (Language language : savedLanguages) { | ||||||
|  |                 updatedLanguageCodes += language.getLanguageCode() + ", "; | ||||||
|  |             } | ||||||
|  |             // Remove the trailing comma and space if present | ||||||
|  |             if (!updatedLanguageCodes.isEmpty()) { | ||||||
|  |                 updatedLanguageCodes = updatedLanguageCodes.substring(0, updatedLanguageCodes.length() - 2); | ||||||
|  |             } | ||||||
|  |             saveLanguageValue(updatedLanguageCodes, "descriptionSecondaryLanguagePref"); | ||||||
|  | 
 | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -454,9 +462,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { | ||||||
| 
 | 
 | ||||||
|             assert languageCode != null; |             assert languageCode != null; | ||||||
|             if (languageCode.equals("")) { |             if (languageCode.equals("")) { | ||||||
|                 String fullCode = Locale.getDefault().getLanguage(); |                 selectedLanguages.put(0, 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); | ||||||
|             } |             } | ||||||
|  | @ -464,9 +470,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { | ||||||
| 
 | 
 | ||||||
|             assert languageCode != null; |             assert languageCode != null; | ||||||
|             if (languageCode.equals("")) { |             if (languageCode.equals("")) { | ||||||
|                 String fullCode = Locale.getDefault().getLanguage(); |                 selectedLanguages.put(0, 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); | ||||||
|  | @ -475,9 +479,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { | ||||||
| 
 | 
 | ||||||
|         assert languageCode != null; |         assert languageCode != null; | ||||||
|         if (languageCode.equals("")) { |         if (languageCode.equals("")) { | ||||||
|             String fullCode = Locale.getDefault().getLanguage(); |             selectedLanguages.put(0, 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); | ||||||
|  | @ -547,16 +549,13 @@ 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, true); |                     setLocale(requireActivity(), languageCode); | ||||||
|                     getActivity().recreate(); |                     getActivity().recreate(); | ||||||
|                     final Intent intent = new Intent(getActivity(), MainActivity.class); |                     final Intent intent = new Intent(getActivity(), MainActivity.class); | ||||||
|                     startActivity(intent); |                     startActivity(intent); | ||||||
|                 }else if(keyListPreference.equals("descriptionDefaultLanguagePref")){ |                 }else if(keyListPreference.equals("descriptionDefaultLanguagePref")){ | ||||||
|                     descriptionLanguageListPreference.setSummary(defLocale.getDisplayLanguage(defLocale)); |                     descriptionLanguageListPreference.setSummary(defLocale.getDisplayLanguage(defLocale)); | ||||||
|                 } |                 } | ||||||
|                 else{ |  | ||||||
|                     descriptionSecondaryLanguageListPreference.setSummary(defLocale.getDisplayLanguage(defLocale)); |  | ||||||
|                 } |  | ||||||
|                 dialog.dismiss(); |                 dialog.dismiss(); | ||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
|  | @ -615,7 +614,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, true); |             setLocale(requireActivity(), recentLanguageCode); | ||||||
|             getActivity().recreate(); |             getActivity().recreate(); | ||||||
|             final Intent intent = new Intent(getActivity(), MainActivity.class); |             final Intent intent = new Intent(getActivity(), MainActivity.class); | ||||||
|             startActivity(intent); |             startActivity(intent); | ||||||
|  | @ -642,28 +641,34 @@ public class SettingsFragment extends PreferenceFragmentCompat { | ||||||
|     /** |     /** | ||||||
|      * 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, boolean appUI) { |     public void setLocale(final Activity activity, String userSelectedValue) { | ||||||
| 
 | //        if (userSelectedValue.equals("")) { | ||||||
|         if (userSelectedValue.equals("")) { | //            userSelectedValue = Locale.getDefault().getLanguage(); | ||||||
|             userSelectedValue = Locale.getDefault().getLanguage(); | //        } | ||||||
|         } | // | ||||||
| 
 | //        String current = Locale.getDefault().getLanguage(); | ||||||
|         String current = Locale.getDefault().getLanguage(); | //        ArrayList<String> languageCodes = deSerialise(current); | ||||||
|         ArrayList<String> languageCodes = deSerialise(current); | //        if(appUI) { | ||||||
|         if(appUI) { | //            languageCodes.set(0, userSelectedValue); | ||||||
|             languageCodes.set(0, userSelectedValue); | //            userSelectedValue = reSerialise(languageCodes); | ||||||
|             userSelectedValue = reSerialise(languageCodes); | //            } | ||||||
|             } | //        else{ | ||||||
|         else{ | //            ArrayList<String> newLanguageCodes = new ArrayList<>(); | ||||||
|             ArrayList<String> newLanguageCodes = new ArrayList<>(); | //            ArrayList<String> userSelctedCode = deSerialise(userSelectedValue); | ||||||
|             ArrayList<String> userSelctedCode = deSerialise(userSelectedValue); | // | ||||||
| 
 | //            newLanguageCodes.add(languageCodes.get(0)); | ||||||
|             newLanguageCodes.add(languageCodes.get(0)); | //            for(String code : userSelctedCode){ | ||||||
|             for(String code : userSelctedCode){ | //                newLanguageCodes.add(code); | ||||||
|                 newLanguageCodes.add(code); | //            } | ||||||
|             } | //            userSelectedValue = reSerialise(newLanguageCodes); | ||||||
|             userSelectedValue = reSerialise(newLanguageCodes); | //        } | ||||||
|         } | // | ||||||
|  | //        System.out.println("Final locale"); | ||||||
|  | //        System.out.println(userSelectedValue); | ||||||
|  | // | ||||||
|  | //        System.out.println("vs"); | ||||||
|  | //        System.out.println(getCurrentLanguageCode("appUiDefaultLanguagePref")); | ||||||
|  | //        System.out.println(getCurrentLanguageCode("descriptionSecondaryLanguagePref")); | ||||||
| 
 | 
 | ||||||
|         final Locale locale = createLocale(userSelectedValue); |         final Locale locale = createLocale(userSelectedValue); | ||||||
|         Locale.setDefault(locale); |         Locale.setDefault(locale); | ||||||
|  |  | ||||||
|  | @ -18,12 +18,14 @@ WHERE { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   # Get the label in the preferred language of the user, or any other language if no label is available in that language. |   # Get the label in the preferred language of the user, or any other language if no label is available in that language. | ||||||
|   OPTIONAL {?item rdfs:label ?itemLabelPreferredLanguage. FILTER (lang(?itemLabelPreferredLanguage) = "en")} |   OPTIONAL {?item rdfs:label ?itemLabelPreferredLanguage. FILTER (lang(?itemLabelPreferredLanguage) = "${LANG}")} | ||||||
|  |   ${SECONDARYLABEL} | ||||||
|   OPTIONAL {?item rdfs:label ?itemLabelAnyLanguage} |   OPTIONAL {?item rdfs:label ?itemLabelAnyLanguage} | ||||||
|   BIND(COALESCE(?itemLabelPreferredLanguage, ?itemLabelAnyLanguage, "?") as ?label) |   BIND(COALESCE(?itemLabelPreferredLanguage, ?itemLabelAnyLanguage, "?") as ?label) | ||||||
| 
 | 
 | ||||||
|   # Get the description in the preferred language of the user, or any other language if no description is available in that language. |   # Get the description in the preferred language of the user, or any other language if no description is available in that language. | ||||||
|   OPTIONAL {?item schema:description ?itemDescriptionPreferredLanguage. FILTER (lang(?itemDescriptionPreferredLanguage) = "${LANG}")} |   OPTIONAL {?item schema:description ?itemDescriptionPreferredLanguage. FILTER (lang(?itemDescriptionPreferredLanguage) = "${LANG}")} | ||||||
|  |   ${SECONDARYDESCRIPTION} | ||||||
|   OPTIONAL {?item schema:description ?itemDescriptionAnyLanguage} |   OPTIONAL {?item schema:description ?itemDescriptionAnyLanguage} | ||||||
|   BIND(COALESCE(?itemDescriptionPreferredLanguage, ?itemDescriptionAnyLanguage, "?") as ?description) |   BIND(COALESCE(?itemDescriptionPreferredLanguage, ?itemDescriptionAnyLanguage, "?") as ?description) | ||||||
| 
 | 
 | ||||||
|  | @ -31,6 +33,7 @@ WHERE { | ||||||
|   OPTIONAL { |   OPTIONAL { | ||||||
|   ?item p:P31/ps:P31 ?class. |   ?item p:P31/ps:P31 ?class. | ||||||
|     OPTIONAL {?class rdfs:label ?classLabelPreferredLanguage. FILTER (lang(?classLabelPreferredLanguage) = "${LANG}")} |     OPTIONAL {?class rdfs:label ?classLabelPreferredLanguage. FILTER (lang(?classLabelPreferredLanguage) = "${LANG}")} | ||||||
|  |     ${SECONDARYCLASSLABEL} | ||||||
|     OPTIONAL {?class rdfs:label ?classLabelAnyLanguage} |     OPTIONAL {?class rdfs:label ?classLabelAnyLanguage} | ||||||
|     BIND(COALESCE(?classLabelPreferredLanguage, ?classLabelAnyLanguage, "?") as ?classLabel) |     BIND(COALESCE(?classLabelPreferredLanguage, ?classLabelAnyLanguage, "?") as ?classLabel) | ||||||
|   } |   } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Adith
						Adith