check if server supports translation earlier

closes #172
This commit is contained in:
sk 2022-12-20 11:19:50 +01:00
parent e1c258478f
commit f3db153ea9
2 changed files with 10 additions and 13 deletions

View File

@ -104,6 +104,7 @@ public class AccountSessionManager{
public void addAccount(Instance instance, Token token, Account self, Application app, AccountActivationInfo activationInfo){
instances.put(instance.uri, instance);
updateInstanceInfoV2(instance);
AccountSession session=new AccountSession(token, self, app, instance.uri, activationInfo==null, activationInfo);
sessions.put(session.getID(), session);
lastActiveAccountID=session.getID();
@ -329,9 +330,7 @@ public class AccountSessionManager{
instances.put(domain, instance);
updateInstanceEmojis(instance, domain);
try {
if (Integer.parseInt(instance.version.split("\\.")[0]) >= 4) {
updateInstanceInfoV2(domain);
}
updateInstanceInfoV2(instance);
} catch (Exception ignored) {}
}
@ -343,17 +342,17 @@ public class AccountSessionManager{
.execNoAuth(domain);
}
public void updateInstanceInfoV2(String domain) {
public void updateInstanceInfoV2(Instance instance) {
new GetInstance.V2().setCallback(new Callback<>() {
@Override
public void onSuccess(Instance.V2 v2) {
Instance instanceInfo = instances.get(domain);
if (instanceInfo != null) instanceInfo.v2 = v2;
if (instance != null) instance.v2 = v2;
writeAccountsFile();
}
@Override
public void onError(ErrorResponse errorResponse) {}
}).execNoAuth(domain);
}).execNoAuth(instance.uri);
}
private void updateInstanceEmojis(Instance instance, String domain){

View File

@ -41,10 +41,7 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
public final Status status;
public boolean translated = false;
public TranslatedStatus translation = null;
private AccountSession session;
private Instance instanceInfo;
private boolean translateEnabled;
public TextStatusDisplayItem(String parentID, CharSequence text, BaseStatusListFragment parentFragment, Status status){
super(parentID, parentFragment);
@ -57,8 +54,6 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
spoilerEmojiHelper.setText(parsedSpoilerText);
}
session = AccountSessionManager.getInstance().getAccount(parentFragment.getAccountID());
instanceInfo = AccountSessionManager.getInstance().getInstanceInfo(session.domain);
translateEnabled = instanceInfo.v2 != null && instanceInfo.v2.configuration.translation != null && instanceInfo.v2.configuration.translation.enabled;
}
@Override
@ -146,7 +141,10 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
itemView.setClickable(false);
}
translateWrap.setVisibility(item.textSelectable && item.translateEnabled &&
Instance instanceInfo = AccountSessionManager.getInstance().getInstanceInfo(item.session.domain);
boolean translateEnabled = instanceInfo.v2 != null && instanceInfo.v2.configuration.translation != null && instanceInfo.v2.configuration.translation.enabled;
translateWrap.setVisibility(item.textSelectable && translateEnabled &&
!item.status.visibility.isLessVisibleThan(StatusPrivacy.UNLISTED) &&
item.status.language != null &&
(item.session.preferences == null || !item.status.language.equalsIgnoreCase(item.session.preferences.postingDefaultLanguage))