Fixes a translation issue
This commit is contained in:
parent
902c80d35c
commit
50f822dca1
|
@ -42,6 +42,7 @@ import android.text.SpannableString;
|
|||
import android.text.Spanned;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
import android.util.Patterns;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -933,13 +934,13 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
i++;
|
||||
}
|
||||
if (translator == Helper.TRANS_YANDEX)
|
||||
new YandexQuery(StatusListAdapter.this).getYandexTextview(position, text, currentLocale);
|
||||
new YandexQuery(StatusListAdapter.this).getYandexTextview(status, text, currentLocale);
|
||||
else if( translator == Helper.TRANS_GOOGLE) {
|
||||
|
||||
while( text.charAt(text.length() -1) == '\n' && text.length() > 0)
|
||||
text = text.substring(0, text.length() -1);
|
||||
text += ".";
|
||||
new GoogleTranslateQuery(StatusListAdapter.this).getGoogleTextview(position, text.trim(), currentLocale);
|
||||
new GoogleTranslateQuery(StatusListAdapter.this).getGoogleTextview(status, text.trim(), currentLocale);
|
||||
}
|
||||
}else {
|
||||
status.setTranslationShown(!status.isTranslationShown());
|
||||
|
@ -1410,10 +1411,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onTranslatedTextview(int position, String translatedResult, Boolean error) {
|
||||
public void onTranslatedTextview(Status status, String translatedResult, Boolean error) {
|
||||
if( error){
|
||||
Toast.makeText(context, R.string.toast_error_translate, Toast.LENGTH_LONG).show();
|
||||
}else if( statuses.size() > position) {
|
||||
}else {
|
||||
try {
|
||||
String aJsonString = null;
|
||||
if (translator == Helper.TRANS_YANDEX)
|
||||
|
@ -1434,9 +1435,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
aJsonString = aJsonString.replace(pair.getKey().toString(), pair.getValue().toString());
|
||||
itT.remove();
|
||||
}
|
||||
statuses.get(position).setTranslated(true);
|
||||
statuses.get(position).setTranslationShown(true);
|
||||
statuses.get(position).setContent_translated(aJsonString);
|
||||
status.setTranslated(true);
|
||||
status.setTranslationShown(true);
|
||||
status.setContent_translated(aJsonString);
|
||||
statusListAdapter.notifyDataSetChanged();
|
||||
} catch (JSONException | UnsupportedEncodingException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -14,10 +14,12 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.interfaces;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 03/07/2017.
|
||||
* Yandex client API Handler
|
||||
*/
|
||||
public interface OnTranslatedInterface {
|
||||
void onTranslatedTextview(int position, String translatedResult, Boolean error);
|
||||
void onTranslatedTextview(Status status, String translatedResult, Boolean error);
|
||||
}
|
||||
|
|
|
@ -14,14 +14,11 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.translation;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.loopj.android.http.AsyncHttpResponseHandler;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
import cz.msebera.android.httpclient.Header;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnTranslatedInterface;
|
||||
|
||||
/**
|
||||
|
@ -37,7 +34,7 @@ public class GoogleTranslateQuery {
|
|||
this.listener = listenner;
|
||||
}
|
||||
|
||||
public void getGoogleTextview(final int position, final String text, final String toLanguage) throws JSONException {
|
||||
public void getGoogleTextview(final Status status, final String text, final String toLanguage) throws JSONException {
|
||||
|
||||
GoogleTranslateClient.get(text, toLanguage, new AsyncHttpResponseHandler() {
|
||||
@Override
|
||||
|
@ -47,12 +44,12 @@ public class GoogleTranslateQuery {
|
|||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
|
||||
String str_response = new String(response);
|
||||
listener.onTranslatedTextview(position, str_response,false);
|
||||
listener.onTranslatedTextview(status, str_response,false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
|
||||
listener.onTranslatedTextview(position, null, true);
|
||||
listener.onTranslatedTextview(status, null, true);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@ package fr.gouv.etalab.mastodon.translation;
|
|||
import com.loopj.android.http.AsyncHttpResponseHandler;
|
||||
import org.json.JSONException;
|
||||
import cz.msebera.android.httpclient.Header;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnTranslatedInterface;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +30,7 @@ public class YandexQuery {
|
|||
this.listener = listenner;
|
||||
}
|
||||
|
||||
public void getYandexTextview(final int position, final String text, final String toLanguage) throws JSONException {
|
||||
public void getYandexTextview(final Status status, final String text, final String toLanguage) throws JSONException {
|
||||
|
||||
YandexClient.get(text, toLanguage, new AsyncHttpResponseHandler() {
|
||||
@Override
|
||||
|
@ -40,12 +41,12 @@ public class YandexQuery {
|
|||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
|
||||
String str_response = new String(response);
|
||||
listener.onTranslatedTextview(position, str_response,false);
|
||||
listener.onTranslatedTextview(status, str_response,false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
|
||||
listener.onTranslatedTextview(position, null, true);
|
||||
listener.onTranslatedTextview(status, null, true);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue