Updates the lib to fit my needs
This commit is contained in:
parent
0a1e908e4e
commit
9ffa5820b4
|
@ -43,7 +43,7 @@ dependencies {
|
|||
implementation 'com.google.code.gson:gson:2.8.0'
|
||||
implementation 'org.jsoup:jsoup:1.10.3'
|
||||
implementation 'de.hdodenhof:circleimageview:2.2.0'
|
||||
implementation 'com.github.mukeshsolanki:country-picker-android:1.1.9'
|
||||
implementation 'com.github.stom79:country-picker-android:1.2.0-beta-1'
|
||||
safetynetImplementation 'com.google.android.gms:play-services-safetynet:11.4.2'
|
||||
safetynetImplementation 'io.github.kobakei:ratethisapp:1.2.0'
|
||||
}
|
||||
|
|
|
@ -98,6 +98,7 @@ import java.util.Date;
|
|||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -773,19 +774,26 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
}
|
||||
if( toot_content.getText().length() == 0 && toot_cw_content.getText().length() == 0)
|
||||
return true;
|
||||
String dateString = sharedpreferences.getString(Helper.LAST_TRANSLATION_TIME, null);
|
||||
if( dateString != null){
|
||||
Date date = Helper.stringToDate(getApplicationContext(), dateString);
|
||||
Date dateCompare = new Date( System.currentTimeMillis() + (TimeUnit.SECONDS.toMillis(Helper.SECONDES_BETWEEN_TRANSLATE)));
|
||||
if( date.before(dateCompare))
|
||||
Toast.makeText(getApplicationContext(),R.string.please_wait,Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
picker.setListener(new CountryPickerListener() {
|
||||
@SuppressLint("InflateParams")
|
||||
@Override
|
||||
public void onSelectCountry(String name, String code, String dialCode, int flagDrawableResID) {
|
||||
public void onSelectCountry(String name, String code, String dialCode, String locale, int flagDrawableResID) {
|
||||
picker.dismiss();
|
||||
AlertDialog.Builder transAlert = new AlertDialog.Builder(TootActivity.this);
|
||||
transAlert.setTitle(R.string.translate_toot);
|
||||
|
||||
popup_trans = getLayoutInflater().inflate( R.layout.popup_translate, null );
|
||||
transAlert.setView(popup_trans);
|
||||
|
||||
new Translate(getApplicationContext(), Helper.targetField.CW, code, TootActivity.this).privacy(toot_cw_content.getText().toString());
|
||||
new Translate(getApplicationContext(), Helper.targetField.STATUS, code, TootActivity.this).privacy(toot_content.getText().toString());
|
||||
new Translate(getApplicationContext(), Helper.targetField.CW, locale, TootActivity.this).privacy(toot_cw_content.getText().toString());
|
||||
new Translate(getApplicationContext(), Helper.targetField.STATUS, locale, TootActivity.this).privacy(toot_content.getText().toString());
|
||||
transAlert.setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
dialog.dismiss();
|
||||
|
@ -1689,7 +1697,11 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
@Override
|
||||
public void onTranslated(Translate translate, Helper.targetField targetField, String translatedResult, Boolean error) {
|
||||
try {
|
||||
String aJsonString = translate.replace(translatedResult);
|
||||
String aJsonString;
|
||||
if( translatedResult != null && translatedResult.length() > 0)
|
||||
aJsonString = translate.replace(translatedResult);
|
||||
else
|
||||
aJsonString = "";
|
||||
if( popup_trans != null ) {
|
||||
ProgressBar trans_progress_cw = popup_trans.findViewById(R.id.trans_progress_cw);
|
||||
ProgressBar trans_progress_toot = popup_trans.findViewById(R.id.trans_progress_toot);
|
||||
|
|
|
@ -254,6 +254,9 @@ public class Helper {
|
|||
public static final int MINUTES_BETWEEN_NOTIFICATIONS_REFRESH = 15;
|
||||
public static final int MINUTES_BETWEEN_HOME_TIMELINE = 30;
|
||||
|
||||
//Translate wait time
|
||||
public static final String LAST_TRANSLATION_TIME = "last_translation_time";
|
||||
public static final int SECONDES_BETWEEN_TRANSLATE = 60;
|
||||
//Intent
|
||||
public static final String INTENT_ACTION = "intent_action";
|
||||
|
||||
|
|
|
@ -168,20 +168,11 @@ public class Translate {
|
|||
}
|
||||
i++;
|
||||
}
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
int translator = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
|
||||
if( status == null) {
|
||||
if (translator == Helper.TRANS_YANDEX) {
|
||||
if (content != null)
|
||||
new YandexQuery(this.listener).getYandexTranslation(this, Helper.targetField.STATUS, content, this.targetedLanguage);
|
||||
if (targetField == Helper.targetField.CW)
|
||||
new YandexQuery(this.listener).getYandexTranslation(this, Helper.targetField.CW, content, this.targetedLanguage);
|
||||
}
|
||||
new YandexQuery(this.listener).getYandexTranslation(this,targetField, content, this.targetedLanguage);
|
||||
}else {
|
||||
if (translator == Helper.TRANS_YANDEX) {
|
||||
new YandexQuery(this.listener).getYandexTextview(this, this.status, content, this.targetedLanguage);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Toast.makeText(context, R.string.toast_error_translate, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
@ -250,9 +241,11 @@ public class Translate {
|
|||
}
|
||||
|
||||
private String yandexTranslateToText(String text) throws JSONException, UnsupportedEncodingException{
|
||||
String aJsonString = null;
|
||||
if( text !=null) {
|
||||
JSONObject translationJson = new JSONObject(text);
|
||||
JSONArray aJsonArray = translationJson.getJSONArray("text");
|
||||
String aJsonString = aJsonArray.get(0).toString();
|
||||
aJsonString = aJsonArray.get(0).toString();
|
||||
|
||||
/* The one instance where I've seen this happen,
|
||||
the special tag was originally a hashtag ("__t1__"),
|
||||
|
@ -264,6 +257,7 @@ public class Translate {
|
|||
aJsonString = aJsonString.replace("&", "&");
|
||||
|
||||
aJsonString = URLDecoder.decode(aJsonString, "UTF-8");
|
||||
}
|
||||
return aJsonString;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.translation;
|
||||
|
||||
|
||||
import com.loopj.android.http.AsyncHttpClient;
|
||||
import com.loopj.android.http.AsyncHttpResponseHandler;
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.translation;
|
||||
|
||||
|
||||
import com.loopj.android.http.AsyncHttpResponseHandler;
|
||||
import org.json.JSONException;
|
||||
import cz.msebera.android.httpclient.Header;
|
||||
|
@ -34,7 +33,7 @@ class YandexQuery {
|
|||
}
|
||||
|
||||
void getYandexTextview(final Translate translate, final Status status, final String text, final String toLanguage) throws JSONException {
|
||||
|
||||
if( text != null && text.length() > 0) {
|
||||
YandexClient.get(text, toLanguage, new AsyncHttpResponseHandler() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
|
@ -44,7 +43,7 @@ class YandexQuery {
|
|||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
|
||||
String str_response = new String(response);
|
||||
listener.onTranslatedTextview(translate, status, str_response,false);
|
||||
listener.onTranslatedTextview(translate, status, str_response, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,9 +52,12 @@ class YandexQuery {
|
|||
}
|
||||
|
||||
});
|
||||
}else {
|
||||
listener.onTranslatedTextview(translate, status, "", false);
|
||||
}
|
||||
}
|
||||
void getYandexTranslation(final Translate translate, final Helper.targetField target, final String content, final String toLanguage) throws JSONException {
|
||||
|
||||
if( content != null && content.length() > 0) {
|
||||
YandexClient.get(content, toLanguage, new AsyncHttpResponseHandler() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
|
@ -65,14 +67,18 @@ class YandexQuery {
|
|||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
|
||||
String str_response = new String(response);
|
||||
listener.onTranslated(translate, target, str_response,false);
|
||||
listener.onTranslated(translate, target, str_response, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
|
||||
e.printStackTrace();
|
||||
listener.onTranslated(translate, target, null, true);
|
||||
}
|
||||
|
||||
});
|
||||
}else{
|
||||
listener.onTranslated(translate, target, "", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -428,4 +428,5 @@
|
|||
<string name="select_accounts">Select some accounts</string>
|
||||
<string name="upload_form_description">Für Menschen mit Sehbehinderung beschreiben</string>
|
||||
<string name="translate">Translate</string>
|
||||
<string name="please_wait">Please, wait few seconds before making this action.</string>
|
||||
</resources>
|
||||
|
|
|
@ -435,4 +435,5 @@
|
|||
<string name="select_accounts">Sélectionnez des comptes</string>
|
||||
<string name="upload_form_description">Décrire pour les malvoyants</string>
|
||||
<string name="translate">Traduire</string>
|
||||
<string name="please_wait">Veuillez patienter quelques secondes avant de faire cette action.</string>
|
||||
</resources>
|
|
@ -432,4 +432,5 @@
|
|||
<string name="select_accounts">Kies enkele accounts</string>
|
||||
<string name="upload_form_description">Omschrijf dit voor mensen met een visuele beperking</string>
|
||||
<string name="translate">Translate</string>
|
||||
<string name="please_wait">Please, wait few seconds before making this action.</string>
|
||||
</resources>
|
||||
|
|
|
@ -434,4 +434,5 @@
|
|||
<string name="select_accounts">Select some accounts</string>
|
||||
<string name="upload_form_description">Describe for the visually impaired</string>
|
||||
<string name="translate">Translate</string>
|
||||
<string name="please_wait">Please, wait few seconds before making this action.</string>
|
||||
</resources>
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
<string name="show_replies">Show replies</string>
|
||||
<string name="action_open_in_web">Open in browser</string>
|
||||
<string name="translate">Translate</string>
|
||||
<string name="please_wait">Please, wait few seconds before making this action.</string>
|
||||
<!--- Menu -->
|
||||
<string name="home_menu">Home</string>
|
||||
<string name="local_menu">Local timeline</string>
|
||||
|
|
Loading…
Reference in New Issue