Force repo update after changing language.

This zeros out the etag in the fdroid_repo table and then asks
the update service to perform an update.

The end result is that changing the language will result in the metadata
being shown in that language.

Note: This doesn't immediately work due to pending changes around
Locale.setDefault() and the change in case from Summary to summary in
the server metadata.
This commit is contained in:
Peter Serwylo 2017-05-02 16:22:36 +10:00
parent e02c0cb555
commit 18f8817388
2 changed files with 17 additions and 0 deletions

View File

@ -286,6 +286,18 @@ public class RepoProvider extends FDroidProvider {
return count; return count;
} }
/**
* Helper method to ensure that next time the user asks for a repository update, we will
* fetch the metadata and update regardless of whether the metadata has changed or not.
* This is useful for when we change languages, because we need to ask the user to fetch
* the metadata again, so that we can extract the correctly-localized metadata.
*/
public static void clearEtags(Context context) {
ContentValues values = new ContentValues(1);
values.put(Cols.LAST_ETAG, (String) null);
context.getContentResolver().update(getContentUri(), values, null, null);
}
} }
private static final String PROVIDER_NAME = "RepoProvider"; private static final String PROVIDER_NAME = "RepoProvider";

View File

@ -22,6 +22,7 @@ import org.fdroid.fdroid.Languages;
import org.fdroid.fdroid.Preferences; import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService; import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.data.RepoProvider;
import org.fdroid.fdroid.installer.InstallHistoryService; import org.fdroid.fdroid.installer.InstallHistoryService;
import org.fdroid.fdroid.installer.PrivilegedInstaller; import org.fdroid.fdroid.installer.PrivilegedInstaller;
@ -158,6 +159,10 @@ public class PreferencesFragment extends PreferenceFragment
if (changing) { if (changing) {
Activity activity = getActivity(); Activity activity = getActivity();
Languages.setLanguage(activity, Preferences.get().getLanguage(), false); Languages.setLanguage(activity, Preferences.get().getLanguage(), false);
RepoProvider.Helper.clearEtags(getContext());
UpdateService.updateNow(getContext());
Languages.forceChangeLanguage(activity); Languages.forceChangeLanguage(activity);
} }
break; break;