mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-07-08 04:40:28 +03:00
Merge branch 'Fix_523' into develop
This commit is contained in:
commit
5b8d589598
11 changed files with 158 additions and 75 deletions
|
@ -202,7 +202,7 @@ public class CheckHomeCacheActivity extends BaseBarActivity {
|
||||||
IndexAxisValueFormatter formatter = new IndexAxisValueFormatter() {
|
IndexAxisValueFormatter formatter = new IndexAxisValueFormatter() {
|
||||||
@Override
|
@Override
|
||||||
public String getFormattedValue(float value) {
|
public String getFormattedValue(float value) {
|
||||||
if (value < xVals.size()) {
|
if (value >= 0 && value < xVals.size()) {
|
||||||
return xVals.get((int) value);
|
return xVals.get((int) value);
|
||||||
} else
|
} else
|
||||||
return "";
|
return "";
|
||||||
|
@ -363,7 +363,7 @@ public class CheckHomeCacheActivity extends BaseBarActivity {
|
||||||
IndexAxisValueFormatter formatter = new IndexAxisValueFormatter() {
|
IndexAxisValueFormatter formatter = new IndexAxisValueFormatter() {
|
||||||
@Override
|
@Override
|
||||||
public String getFormattedValue(float value) {
|
public String getFormattedValue(float value) {
|
||||||
if (value < xVals2.size()) {
|
if (value >= 0 && value < xVals2.size()) {
|
||||||
return xVals2.get((int) value);
|
return xVals2.get((int) value);
|
||||||
} else
|
} else
|
||||||
return "";
|
return "";
|
||||||
|
|
|
@ -15,6 +15,7 @@ package app.fedilab.android.mastodon.client.endpoints;
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import app.fedilab.android.mastodon.client.entities.api.Account;
|
import app.fedilab.android.mastodon.client.entities.api.Account;
|
||||||
|
@ -25,14 +26,17 @@ import app.fedilab.android.mastodon.client.entities.api.Poll;
|
||||||
import app.fedilab.android.mastodon.client.entities.api.ScheduledStatus;
|
import app.fedilab.android.mastodon.client.entities.api.ScheduledStatus;
|
||||||
import app.fedilab.android.mastodon.client.entities.api.Status;
|
import app.fedilab.android.mastodon.client.entities.api.Status;
|
||||||
import app.fedilab.android.mastodon.client.entities.api.StatusSource;
|
import app.fedilab.android.mastodon.client.entities.api.StatusSource;
|
||||||
|
import app.fedilab.android.mastodon.client.entities.api.params.StatusParams;
|
||||||
import okhttp3.MultipartBody;
|
import okhttp3.MultipartBody;
|
||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
|
import retrofit2.http.Body;
|
||||||
import retrofit2.http.DELETE;
|
import retrofit2.http.DELETE;
|
||||||
import retrofit2.http.Field;
|
import retrofit2.http.Field;
|
||||||
import retrofit2.http.FormUrlEncoded;
|
import retrofit2.http.FormUrlEncoded;
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
import retrofit2.http.Header;
|
import retrofit2.http.Header;
|
||||||
|
import retrofit2.http.Headers;
|
||||||
import retrofit2.http.Multipart;
|
import retrofit2.http.Multipart;
|
||||||
import retrofit2.http.POST;
|
import retrofit2.http.POST;
|
||||||
import retrofit2.http.PUT;
|
import retrofit2.http.PUT;
|
||||||
|
@ -74,6 +78,16 @@ public interface MastodonStatusesService {
|
||||||
@Header("Authorization") String token,
|
@Header("Authorization") String token,
|
||||||
@Path("id") String id);
|
@Path("id") String id);
|
||||||
|
|
||||||
|
|
||||||
|
@Headers({"Accept: application/json"})
|
||||||
|
@PUT("statuses/{id}")
|
||||||
|
Call<Status> updateStatus(
|
||||||
|
@Header("Idempotency-Key") String idempotency_Key,
|
||||||
|
@Header("Authorization") String token,
|
||||||
|
@Path("id") String id,
|
||||||
|
@Body StatusParams statusParams
|
||||||
|
);
|
||||||
|
|
||||||
//Post a status
|
//Post a status
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@PUT("statuses/{id}")
|
@PUT("statuses/{id}")
|
||||||
|
@ -92,9 +106,9 @@ public interface MastodonStatusesService {
|
||||||
@Field("spoiler_text") String spoiler_text,
|
@Field("spoiler_text") String spoiler_text,
|
||||||
@Field("visibility") String visibility,
|
@Field("visibility") String visibility,
|
||||||
@Field("language") String language,
|
@Field("language") String language,
|
||||||
@Field("media_attributes[][id]") List<String> media_id,
|
@Field("media_attributes[]") LinkedHashMap<String, String> media_id,
|
||||||
@Field("media_attributes[][description]") List<String> media_description,
|
@Field("media_attributes[]") LinkedHashMap<String, String> media_description,
|
||||||
@Field("media_attributes[][focus]") List<String> focus
|
@Field("media_attributes[]") LinkedHashMap<String, String> focus
|
||||||
);
|
);
|
||||||
|
|
||||||
//Post a scheduled status
|
//Post a scheduled status
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
package app.fedilab.android.mastodon.client.entities.api.params;
|
||||||
|
/* Copyright 2025 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Fedilab
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class StatusParams implements Serializable {
|
||||||
|
@SerializedName("id")
|
||||||
|
public String id;
|
||||||
|
@SerializedName("status")
|
||||||
|
public String status;
|
||||||
|
@SerializedName("media_ids")
|
||||||
|
public List<String> media_ids;
|
||||||
|
@SerializedName("poll")
|
||||||
|
public PollParams pollParams;
|
||||||
|
@SerializedName("in_reply_to_id")
|
||||||
|
public String in_reply_to_id;
|
||||||
|
@SerializedName("sensitive")
|
||||||
|
public Boolean sensitive;
|
||||||
|
@SerializedName("spoiler_text")
|
||||||
|
public String spoiler_text;
|
||||||
|
@SerializedName("visibility")
|
||||||
|
public String visibility;
|
||||||
|
@SerializedName("language")
|
||||||
|
public String language;
|
||||||
|
@SerializedName("media_attributes")
|
||||||
|
public List<MediaParams> media_attributes;
|
||||||
|
|
||||||
|
public static class PollParams implements Serializable{
|
||||||
|
@SerializedName("options")
|
||||||
|
public List<String> poll_options;
|
||||||
|
@SerializedName("expires_in")
|
||||||
|
public Integer poll_expire_in;
|
||||||
|
@SerializedName("multiple")
|
||||||
|
public Boolean poll_multiple;
|
||||||
|
@SerializedName("hide_totals")
|
||||||
|
public Boolean poll_hide_totals;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MediaParams implements Serializable {
|
||||||
|
@SerializedName("id")
|
||||||
|
public String id;
|
||||||
|
@SerializedName("description")
|
||||||
|
public String description;
|
||||||
|
@SerializedName("focus")
|
||||||
|
public String focus;
|
||||||
|
}
|
||||||
|
}
|
|
@ -106,7 +106,9 @@ public class CustomEmoji extends ReplacementSpan {
|
||||||
if (drawableCallBack != null) {
|
if (drawableCallBack != null) {
|
||||||
drawableCallBack.invalidateDrawable(drawable);
|
drawableCallBack.invalidateDrawable(drawable);
|
||||||
}
|
}
|
||||||
view.invalidate();
|
if(view != null) {
|
||||||
|
view.invalidate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -72,8 +72,15 @@ public class TranslateHelper {
|
||||||
String translatorVersion = sharedpreferences.getString(context.getString(R.string.SET_TRANSLATOR_VERSION), "PRO");
|
String translatorVersion = sharedpreferences.getString(context.getString(R.string.SET_TRANSLATOR_VERSION), "PRO");
|
||||||
params.setPro(translatorVersion.equals("PRO"));
|
params.setPro(translatorVersion.equals("PRO"));
|
||||||
String apikey = sharedpreferences.getString(context.getString(R.string.SET_TRANSLATOR_API_KEY), null);
|
String apikey = sharedpreferences.getString(context.getString(R.string.SET_TRANSLATOR_API_KEY), null);
|
||||||
if (apikey != null) {
|
if (apikey != null && !apikey.trim().isEmpty()) {
|
||||||
myTransL.setDeeplAPIKey(apikey.trim());
|
myTransL.setDeeplAPIKey(apikey.trim());
|
||||||
|
} else { //Issue with API key (empty or null)
|
||||||
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
|
editor.putString(context.getString(R.string.SET_TRANSLATOR), "FEDILAB");
|
||||||
|
editor.commit();
|
||||||
|
et = MyTransL.translatorEngine.LIBRETRANSLATE;
|
||||||
|
myTransL.setTranslator(et);
|
||||||
|
myTransL.setLibretranslateDomain("translate.fedilab.app");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ import com.google.gson.Gson;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.IDN;
|
import java.net.IDN;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -59,6 +60,7 @@ import app.fedilab.android.mastodon.client.entities.api.Attachment;
|
||||||
import app.fedilab.android.mastodon.client.entities.api.Poll;
|
import app.fedilab.android.mastodon.client.entities.api.Poll;
|
||||||
import app.fedilab.android.mastodon.client.entities.api.ScheduledStatus;
|
import app.fedilab.android.mastodon.client.entities.api.ScheduledStatus;
|
||||||
import app.fedilab.android.mastodon.client.entities.api.Status;
|
import app.fedilab.android.mastodon.client.entities.api.Status;
|
||||||
|
import app.fedilab.android.mastodon.client.entities.api.params.StatusParams;
|
||||||
import app.fedilab.android.mastodon.client.entities.app.Account;
|
import app.fedilab.android.mastodon.client.entities.app.Account;
|
||||||
import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
|
import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
|
||||||
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
|
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
|
||||||
|
@ -164,9 +166,8 @@ public class ComposeWorker extends Worker {
|
||||||
}
|
}
|
||||||
dataPost.messageToSend = statuses.size() - startingPosition;
|
dataPost.messageToSend = statuses.size() - startingPosition;
|
||||||
dataPost.messageSent = 0;
|
dataPost.messageSent = 0;
|
||||||
List<String> media_edit_id = null;
|
List<StatusParams.MediaParams> media_attributes = null;
|
||||||
List<String> media_edit_description = null;
|
|
||||||
List<String> media_edit_focus = null;
|
|
||||||
for (int i = startingPosition; i < statuses.size(); i++) {
|
for (int i = startingPosition; i < statuses.size(); i++) {
|
||||||
if (dataPost.notificationBuilder != null) {
|
if (dataPost.notificationBuilder != null) {
|
||||||
dataPost.notificationBuilder.setProgress(100, dataPost.messageSent * 100 / dataPost.messageToSend, true);
|
dataPost.notificationBuilder.setProgress(100, dataPost.messageSent * 100 / dataPost.messageToSend, true);
|
||||||
|
@ -179,15 +180,15 @@ public class ComposeWorker extends Worker {
|
||||||
attachmentIds = new ArrayList<>();
|
attachmentIds = new ArrayList<>();
|
||||||
for (Attachment attachment : statuses.get(i).media_attachments) {
|
for (Attachment attachment : statuses.get(i).media_attachments) {
|
||||||
if (attachment.id != null) {
|
if (attachment.id != null) {
|
||||||
if (media_edit_id == null) {
|
if (media_attributes == null) {
|
||||||
media_edit_id = new ArrayList<>();
|
media_attributes = new ArrayList<>();
|
||||||
media_edit_description = new ArrayList<>();
|
|
||||||
media_edit_focus = new ArrayList<>();
|
|
||||||
}
|
}
|
||||||
|
StatusParams.MediaParams mediaParams = new StatusParams.MediaParams();
|
||||||
|
mediaParams.id = attachment.id;
|
||||||
|
mediaParams.description = attachment.description;
|
||||||
|
mediaParams.focus = attachment.focus;
|
||||||
attachmentIds.add(attachment.id);
|
attachmentIds.add(attachment.id);
|
||||||
media_edit_id.add(attachment.id);
|
media_attributes.add(mediaParams);
|
||||||
media_edit_description.add(attachment.description);
|
|
||||||
media_edit_focus.add(attachment.focus);
|
|
||||||
} else {
|
} else {
|
||||||
MultipartBody.Part fileMultipartBody;
|
MultipartBody.Part fileMultipartBody;
|
||||||
if (watermark && attachment.mimeType != null && attachment.mimeType.contains("image")) {
|
if (watermark && attachment.mimeType != null && attachment.mimeType.contains("image")) {
|
||||||
|
@ -207,7 +208,6 @@ public class ComposeWorker extends Worker {
|
||||||
attachmentIds.add(replyId);
|
attachmentIds.add(replyId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<String> poll_options = null;
|
List<String> poll_options = null;
|
||||||
|
@ -274,10 +274,25 @@ public class ComposeWorker extends Worker {
|
||||||
statusCall = mastodonStatusesService.createStatus(null, dataPost.token, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in,
|
statusCall = mastodonStatusesService.createStatus(null, dataPost.token, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in,
|
||||||
poll_multiple, poll_hide_totals, statuses.get(i).quote_id == null ? in_reply_to_status : null, statuses.get(i).sensitive, statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null, statuses.get(i).visibility.toLowerCase(), statuses.get(i).language, statuses.get(i).quote_id, statuses.get(i).content_type);
|
poll_multiple, poll_hide_totals, statuses.get(i).quote_id == null ? in_reply_to_status : null, statuses.get(i).sensitive, statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null, statuses.get(i).visibility.toLowerCase(), statuses.get(i).language, statuses.get(i).quote_id, statuses.get(i).content_type);
|
||||||
} else { //Status is edited
|
} else { //Status is edited
|
||||||
statusCall = mastodonStatusesService.updateStatus(null, dataPost.token, dataPost.statusEditId, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in,
|
StatusParams statusParams = new StatusParams();
|
||||||
poll_multiple, poll_hide_totals, statuses.get(i).quote_id == null ? in_reply_to_status : null, statuses.get(i).sensitive,
|
statusParams.status = statuses.get(i).text;
|
||||||
statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null, statuses.get(i).visibility.toLowerCase(), statuses.get(i).language,
|
statusParams.media_ids = attachmentIds;
|
||||||
media_edit_id, media_edit_description, media_edit_focus);
|
if(poll_options != null) {
|
||||||
|
statusParams.pollParams = new StatusParams.PollParams();
|
||||||
|
statusParams.pollParams.poll_options = poll_options;
|
||||||
|
statusParams.pollParams.poll_expire_in = poll_expire_in;
|
||||||
|
statusParams.pollParams.poll_multiple = poll_multiple;
|
||||||
|
statusParams.pollParams.poll_hide_totals = poll_hide_totals;
|
||||||
|
}
|
||||||
|
statusParams.in_reply_to_id = statuses.get(i).quote_id == null ? in_reply_to_status : null;
|
||||||
|
statusParams.sensitive = statuses.get(i).sensitive;
|
||||||
|
statusParams.spoiler_text = statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null;
|
||||||
|
statusParams.visibility = statuses.get(i).visibility.toLowerCase();
|
||||||
|
statusParams.language = statuses.get(i).language;
|
||||||
|
statusParams.media_attributes = media_attributes;
|
||||||
|
statusCall = mastodonStatusesService.updateStatus(null, dataPost.token,
|
||||||
|
dataPost.statusEditId,
|
||||||
|
statusParams);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Response<Status> statusResponse = statusCall.execute();
|
Response<Status> statusResponse = statusCall.execute();
|
||||||
|
|
|
@ -471,7 +471,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
} else if (list_id != null) {
|
} else if (list_id != null) {
|
||||||
ident = "@l@" + list_id;
|
ident = "@l@" + list_id;
|
||||||
} else if (remoteInstance != null && !checkRemotely) {
|
} else if (remoteInstance != null && !checkRemotely) {
|
||||||
if (pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER || pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER_TAG) {
|
if (pinnedTimeline != null && pinnedTimeline.remoteInstance != null && (pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER || pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER_TAG)) {
|
||||||
ident = "@R@" + pinnedTimeline.remoteInstance.host;
|
ident = "@R@" + pinnedTimeline.remoteInstance.host;
|
||||||
} else {
|
} else {
|
||||||
ident = "@R@" + remoteInstance;
|
ident = "@R@" + remoteInstance;
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class MyTransL {
|
||||||
private static MyTransL myTransL;
|
private static MyTransL myTransL;
|
||||||
private static String libretranslateDomain;
|
private static String libretranslateDomain;
|
||||||
private static String lingvaDomain;
|
private static String lingvaDomain;
|
||||||
private final translatorEngine te;
|
private translatorEngine te;
|
||||||
private String yandexAPIKey, deeplAPIKey, systranAPIKey, libreTranslateAPIKey, lingvaAPIKey;
|
private String yandexAPIKey, deeplAPIKey, systranAPIKey, libreTranslateAPIKey, lingvaAPIKey;
|
||||||
private int timeout = 30;
|
private int timeout = 30;
|
||||||
private boolean obfuscation = false;
|
private boolean obfuscation = false;
|
||||||
|
@ -38,6 +38,10 @@ public class MyTransL {
|
||||||
this.te = te;
|
this.te = te;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTranslator(translatorEngine te) {
|
||||||
|
this.te = te;
|
||||||
|
}
|
||||||
|
|
||||||
public static synchronized MyTransL getInstance(translatorEngine te) {
|
public static synchronized MyTransL getInstance(translatorEngine te) {
|
||||||
if (myTransL == null)
|
if (myTransL == null)
|
||||||
myTransL = new MyTransL(te);
|
myTransL = new MyTransL(te);
|
||||||
|
|
|
@ -29,6 +29,8 @@ import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
@ -125,6 +127,7 @@ public class TransAsync {
|
||||||
str_response = new Client().get(url, this.timeout);
|
str_response = new Client().get(url, this.timeout);
|
||||||
} else if (te == MyTransL.translatorEngine.DEEPL) {
|
} else if (te == MyTransL.translatorEngine.DEEPL) {
|
||||||
String key = MyTransL.getInstance(te).getDeeplAPIKey();
|
String key = MyTransL.getInstance(te).getDeeplAPIKey();
|
||||||
|
params.setSplit_sentences(true);
|
||||||
url = Helper.getDeeplAbsoluteUrl(contentToSend, toLanguage, params, key);
|
url = Helper.getDeeplAbsoluteUrl(contentToSend, toLanguage, params, key);
|
||||||
str_response = new Client().get(url, this.timeout);
|
str_response = new Client().get(url, this.timeout);
|
||||||
} else if (te == MyTransL.translatorEngine.SYSTRAN) {
|
} else if (te == MyTransL.translatorEngine.SYSTRAN) {
|
||||||
|
@ -149,7 +152,7 @@ public class TransAsync {
|
||||||
} else if (te == MyTransL.translatorEngine.LINGVA) {
|
} else if (te == MyTransL.translatorEngine.LINGVA) {
|
||||||
String key = MyTransL.getInstance(te).getLibreTranslateAPIKey();
|
String key = MyTransL.getInstance(te).getLibreTranslateAPIKey();
|
||||||
//String contentToSendEncoded = URLEncoder.encode(contentToSend, "UTF-8");
|
//String contentToSendEncoded = URLEncoder.encode(contentToSend, "UTF-8");
|
||||||
String lingvaURL = MyTransL.getLingvaUrl() + this.params.getSource_lang() + "/" + toLanguage + "/" + contentToSend;
|
String lingvaURL = MyTransL.getLingvaUrl() + this.params.getSource_lang() + "/" + toLanguage + "/" + URLEncoder.encode(contentToSend, "utf-8");
|
||||||
str_response = new Client().get(lingvaURL, this.timeout);
|
str_response = new Client().get(lingvaURL, this.timeout);
|
||||||
}
|
}
|
||||||
} catch (IOException | NoSuchAlgorithmException | KeyManagementException err) {
|
} catch (IOException | NoSuchAlgorithmException | KeyManagementException err) {
|
||||||
|
|
|
@ -64,18 +64,11 @@ public class Client {
|
||||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
||||||
httpsURLConnection.setRequestProperty("http.keepAlive", "false");
|
httpsURLConnection.setRequestProperty("http.keepAlive", "false");
|
||||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP)
|
|
||||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
|
||||||
httpsURLConnection.setRequestMethod("GET");
|
httpsURLConnection.setRequestMethod("GET");
|
||||||
//Read the reply
|
//Read the reply
|
||||||
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
|
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
|
||||||
Reader in;
|
Reader in;
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
|
in = new BufferedReader(new InputStreamReader(httpsURLConnection.getInputStream(), StandardCharsets.UTF_8));
|
||||||
in = new BufferedReader(new InputStreamReader(httpsURLConnection.getInputStream(), StandardCharsets.UTF_8));
|
|
||||||
} else {
|
|
||||||
//noinspection CharsetObjectCanBeUsed
|
|
||||||
in = new BufferedReader(new InputStreamReader(httpsURLConnection.getInputStream(), "UTF-8"));
|
|
||||||
}
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int c; (c = in.read()) >= 0; )
|
for (int c; (c = in.read()) >= 0; )
|
||||||
sb.append((char) c);
|
sb.append((char) c);
|
||||||
|
@ -84,13 +77,8 @@ public class Client {
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
} else {
|
} else {
|
||||||
Reader in;
|
Reader in;
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
|
in = new BufferedReader(new InputStreamReader(httpsURLConnection.getErrorStream(), StandardCharsets.UTF_8));
|
||||||
in = new BufferedReader(new InputStreamReader(httpsURLConnection.getErrorStream(), StandardCharsets.UTF_8));
|
StringBuilder sb = new StringBuilder();
|
||||||
} else {
|
|
||||||
//noinspection CharsetObjectCanBeUsed
|
|
||||||
in = new BufferedReader(new InputStreamReader(httpsURLConnection.getErrorStream(), "UTF-8"));
|
|
||||||
}
|
|
||||||
StringBuilder sb = new StringBuilder();// TODO Auto-generated catch block
|
|
||||||
for (int c; (c = in.read()) >= 0; )
|
for (int c; (c = in.read()) >= 0; )
|
||||||
sb.append((char) c);
|
sb.append((char) c);
|
||||||
httpsURLConnection.disconnect();
|
httpsURLConnection.disconnect();
|
||||||
|
@ -115,19 +103,12 @@ public class Client {
|
||||||
URL url = new URL(urlConnection);
|
URL url = new URL(urlConnection);
|
||||||
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||||
byte[] postDataBytes;
|
byte[] postDataBytes;
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
postDataBytes = jsonObject.toString().getBytes(StandardCharsets.UTF_8);
|
||||||
postDataBytes = jsonObject.toString().getBytes(StandardCharsets.UTF_8);
|
|
||||||
} else {
|
|
||||||
//noinspection CharsetObjectCanBeUsed
|
|
||||||
postDataBytes = jsonObject.toString().getBytes("utf-8");
|
|
||||||
}
|
|
||||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
||||||
httpsURLConnection.setDoInput(true);
|
httpsURLConnection.setDoInput(true);
|
||||||
httpsURLConnection.setDoOutput(true);
|
httpsURLConnection.setDoOutput(true);
|
||||||
httpsURLConnection.setUseCaches(false);
|
httpsURLConnection.setUseCaches(false);
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
|
|
||||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
|
||||||
httpsURLConnection.setRequestMethod("POST");
|
httpsURLConnection.setRequestMethod("POST");
|
||||||
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||||
httpsURLConnection.setRequestProperty("Accept", "application/json");
|
httpsURLConnection.setRequestProperty("Accept", "application/json");
|
||||||
|
@ -140,12 +121,7 @@ public class Client {
|
||||||
//Read the reply
|
//Read the reply
|
||||||
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
|
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
|
||||||
Reader in;
|
Reader in;
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
in = new BufferedReader(new InputStreamReader(httpsURLConnection.getInputStream(), StandardCharsets.UTF_8));
|
||||||
in = new BufferedReader(new InputStreamReader(httpsURLConnection.getInputStream(), StandardCharsets.UTF_8));
|
|
||||||
} else {
|
|
||||||
//noinspection CharsetObjectCanBeUsed
|
|
||||||
in = new BufferedReader(new InputStreamReader(httpsURLConnection.getInputStream(), "UTF-8"));
|
|
||||||
}
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int c; (c = in.read()) >= 0; )
|
for (int c; (c = in.read()) >= 0; )
|
||||||
sb.append((char) c);
|
sb.append((char) c);
|
||||||
|
@ -154,12 +130,7 @@ public class Client {
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
} else {
|
} else {
|
||||||
Reader in;
|
Reader in;
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
in = new BufferedReader(new InputStreamReader(httpsURLConnection.getErrorStream(), StandardCharsets.UTF_8));
|
||||||
in = new BufferedReader(new InputStreamReader(httpsURLConnection.getErrorStream(), StandardCharsets.UTF_8));
|
|
||||||
} else {
|
|
||||||
//noinspection CharsetObjectCanBeUsed
|
|
||||||
in = new BufferedReader(new InputStreamReader(httpsURLConnection.getErrorStream(), "UTF-8"));
|
|
||||||
}
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int c; (c = in.read()) >= 0; )
|
for (int c; (c = in.read()) >= 0; )
|
||||||
sb.append((char) c);
|
sb.append((char) c);
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -156,11 +157,11 @@ public class Translate {
|
||||||
String text = spannableString.toString();
|
String text = spannableString.toString();
|
||||||
Matcher matcher;
|
Matcher matcher;
|
||||||
|
|
||||||
//Mentions with instances (@name@domain) will be replaced by __o0__, __o1__, etc.
|
//Mentions with instances (@name@domain) will be replaced
|
||||||
int i = 0;
|
int i = 0;
|
||||||
matcher = mentionOtherInstancePattern.matcher(text);
|
matcher = mentionOtherInstancePattern.matcher(text);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String key = "$o" + i;
|
String key = "§" + i;
|
||||||
String value = matcher.group(0);
|
String value = matcher.group(0);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
this.mentionConversion.put(key, value);
|
this.mentionConversion.put(key, value);
|
||||||
|
@ -170,10 +171,9 @@ public class Translate {
|
||||||
}
|
}
|
||||||
//Extracts Emails
|
//Extracts Emails
|
||||||
matcher = Patterns.EMAIL_ADDRESS.matcher(text);
|
matcher = Patterns.EMAIL_ADDRESS.matcher(text);
|
||||||
i = 0;
|
//replaces them by a kind of variable which shouldn't be translated
|
||||||
//replaces them by a kind of variable which shouldn't be translated ie: __e0__, __e1__, etc.
|
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String key = "$e" + i;
|
String key = "§" + i;
|
||||||
String value = matcher.group(0);
|
String value = matcher.group(0);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
this.mailConversion.put(key, value);
|
this.mailConversion.put(key, value);
|
||||||
|
@ -182,11 +182,10 @@ public class Translate {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Same for mentions with __m0__, __m1__, etc.
|
//Same for mentions w
|
||||||
i = 0;
|
|
||||||
matcher = mentionPattern.matcher(text);
|
matcher = mentionPattern.matcher(text);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String key = "$m" + i;
|
String key = "§" + i;
|
||||||
String value = matcher.group(0);
|
String value = matcher.group(0);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
this.mentionConversion.put(key, value);
|
this.mentionConversion.put(key, value);
|
||||||
|
@ -197,10 +196,9 @@ public class Translate {
|
||||||
|
|
||||||
//Extracts urls
|
//Extracts urls
|
||||||
matcher = Patterns.WEB_URL.matcher(text);
|
matcher = Patterns.WEB_URL.matcher(text);
|
||||||
i = 0;
|
//replaces them by a kind of variable which shouldn't be translated ie: _
|
||||||
//replaces them by a kind of variable which shouldn't be translated ie: __u0__, __u1__, etc.
|
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String key = "$u" + i;
|
String key = "§" + i;
|
||||||
String value = matcher.group(0);
|
String value = matcher.group(0);
|
||||||
int end = matcher.end();
|
int end = matcher.end();
|
||||||
if (spannableString.length() > end && spannableString.charAt(end) == '/') {
|
if (spannableString.length() > end && spannableString.charAt(end) == '/') {
|
||||||
|
@ -213,11 +211,9 @@ public class Translate {
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
i = 0;
|
|
||||||
//Same for tags with __t0__, __t1__, etc.
|
|
||||||
matcher = hashtagPattern.matcher(text);
|
matcher = hashtagPattern.matcher(text);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String key = "$t" + i;
|
String key = "§" + i;
|
||||||
String value = matcher.group(0);
|
String value = matcher.group(0);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
this.tagConversion.put(key, value);
|
this.tagConversion.put(key, value);
|
||||||
|
@ -348,7 +344,13 @@ public class Translate {
|
||||||
try {
|
try {
|
||||||
JSONObject translationJson = new JSONObject(response);
|
JSONObject translationJson = new JSONObject(response);
|
||||||
//Retrieves the translated content
|
//Retrieves the translated content
|
||||||
translate.setTranslatedContent(translationJson.getString("translation"));
|
String content;
|
||||||
|
try {
|
||||||
|
content = URLDecoder.decode(translationJson.getString("translation"), "utf-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
content = translationJson.getString("translation");
|
||||||
|
}
|
||||||
|
translate.setTranslatedContent(content);
|
||||||
//Retrieves the initial language
|
//Retrieves the initial language
|
||||||
translate.setInitialLanguage(initialLanguage);
|
translate.setInitialLanguage(initialLanguage);
|
||||||
} catch (JSONException e1) {
|
} catch (JSONException e1) {
|
||||||
|
|
Loading…
Reference in a new issue