Fix crashes

This commit is contained in:
Thomas 2020-10-05 14:34:01 +02:00
parent 8548777c50
commit 3be0cd727f
2 changed files with 25 additions and 27 deletions

View File

@ -543,10 +543,14 @@ public class RetrofitPeertubeAPI {
} catch (IOException e) {
e.printStackTrace();
}
String lang = null;
if (PeertubeInformation.langueMapped.containsKey(Locale.getDefault().getLanguage()))
lang = PeertubeInformation.langueMapped.get(Locale.getDefault().getLanguage());
String lang = Locale.getDefault().getLanguage();
if( lang.contains("-")) {
if( !lang.split("-")[0].trim().toLowerCase().startsWith("zh")){
lang = lang.split("-")[0];
}else {
lang = lang.split("-")[0] + "-" + lang.split("-")[1].toUpperCase();
}
}
Call<Map<String, String>> translations = initTranslation().getTranslations(lang);
try {
Response<Map<String, String>> response = translations.execute();
@ -556,7 +560,23 @@ public class RetrofitPeertubeAPI {
Error error = new Error();
error.setStatusCode(response.code());
if (response.errorBody() != null) {
error.setError(response.errorBody().string());
translations = initTranslation().getTranslations("en");
try {
response = translations.execute();
if (response.isSuccessful()) {
peertubeInformation.setTranslations(response.body());
} else {
error = new Error();
error.setStatusCode(response.code());
if (response.errorBody() != null) {
error.setError(response.errorBody().string());
} else {
error.setError(_context.getString(R.string.toast_error));
}
}
} catch (IOException e) {
e.printStackTrace();
}
} else {
error.setError(_context.getString(R.string.toast_error));
}

View File

@ -14,33 +14,11 @@ package app.fedilab.fedilabtube.client.entities;
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import java.util.LinkedHashMap;
import java.util.Map;
public class PeertubeInformation {
public static final Map<String, String> langueMapped;
static {
Map<String, String> aMap = new LinkedHashMap<>();
aMap.put("ca", "ca-ES");
aMap.put("de", "de-DE");
aMap.put("en", "en-US");
aMap.put("es", "es-ES");
aMap.put("eo", "eo");
aMap.put("eu", "eu-ES");
aMap.put("fr", "fr-FR");
aMap.put("oc", "oc");
aMap.put("pt", "pt-BR");
aMap.put("sv", "sv-SE");
aMap.put("cs", "cs-CZ");
aMap.put("zh-CN", "zh-Hans-CN");
aMap.put("zh-TW", "zh-Hans-TW");
langueMapped = aMap;
}
private Map<Integer, String> categories;
private Map<String, String> languages;
private Map<Integer, String> licences;