Add status notification for followed account + fix crashes with photo editor
This commit is contained in:
parent
790e53096b
commit
5d7bffcf3a
|
@ -453,6 +453,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mPager = findViewById(R.id.account_viewpager);
|
mPager = findViewById(R.id.account_viewpager);
|
||||||
|
TabLayout.Tab tab = tabLayout.newTab();
|
||||||
if (!peertubeAccount) {
|
if (!peertubeAccount) {
|
||||||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.toots)));
|
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.toots)));
|
||||||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.following)));
|
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.following)));
|
||||||
|
|
|
@ -4913,6 +4913,7 @@ public class API {
|
||||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||||
notifications = parseNotificationResponse(new JSONArray(response));
|
notifications = parseNotificationResponse(new JSONArray(response));
|
||||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
setError(e.getStatusCode(), e);
|
setError(e.getStatusCode(), e);
|
||||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -77,7 +77,6 @@ import static app.fedilab.android.helper.Helper.urlPattern;
|
||||||
public class HttpsConnection {
|
public class HttpsConnection {
|
||||||
|
|
||||||
|
|
||||||
private HttpsURLConnection httpsURLConnection;
|
|
||||||
private HttpURLConnection httpURLConnection;
|
private HttpURLConnection httpURLConnection;
|
||||||
private String since_id, max_id;
|
private String since_id, max_id;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
@ -168,31 +167,33 @@ public class HttpsConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proxy != null)
|
if (proxy != null)
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
httpURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
httpURLConnection = (HttpsURLConnection) url.openConnection();
|
||||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
httpURLConnection.setConnectTimeout(timeout * 1000);
|
||||||
httpsURLConnection.setRequestProperty("http.keepAlive", "false");
|
httpURLConnection.setRequestProperty("http.keepAlive", "false");
|
||||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||||
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
httpURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||||
httpsURLConnection.setRequestProperty("Accept", "application/json");
|
httpURLConnection.setRequestProperty("Accept", "application/json");
|
||||||
httpsURLConnection.setUseCaches(true);
|
httpURLConnection.setUseCaches(true);
|
||||||
httpsURLConnection.setDefaultUseCaches(true);
|
httpURLConnection.setDefaultUseCaches(true);
|
||||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
if (httpURLConnection instanceof HttpsURLConnection) {
|
||||||
|
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||||
|
}
|
||||||
if (token != null && !token.startsWith("Basic "))
|
if (token != null && !token.startsWith("Basic "))
|
||||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||||
else if (token != null && token.startsWith("Basic "))
|
else if (token != null && token.startsWith("Basic "))
|
||||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
httpURLConnection.setRequestProperty("Authorization", token);
|
||||||
httpsURLConnection.setRequestMethod("GET");
|
httpURLConnection.setRequestMethod("GET");
|
||||||
String response;
|
String response;
|
||||||
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
|
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
||||||
response = converToString(httpsURLConnection.getInputStream());
|
response = converToString(httpURLConnection.getInputStream());
|
||||||
} else {
|
} else {
|
||||||
String error = null;
|
String error = null;
|
||||||
if (httpsURLConnection.getErrorStream() != null) {
|
if (httpURLConnection.getErrorStream() != null) {
|
||||||
InputStream stream = httpsURLConnection.getErrorStream();
|
InputStream stream = httpURLConnection.getErrorStream();
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
stream = httpsURLConnection.getInputStream();
|
stream = httpURLConnection.getInputStream();
|
||||||
}
|
}
|
||||||
try (Scanner scanner = new Scanner(stream)) {
|
try (Scanner scanner = new Scanner(stream)) {
|
||||||
scanner.useDelimiter("\\Z");
|
scanner.useDelimiter("\\Z");
|
||||||
|
@ -203,15 +204,15 @@ public class HttpsConnection {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int responseCode = httpsURLConnection.getResponseCode();
|
int responseCode = httpURLConnection.getResponseCode();
|
||||||
try {
|
try {
|
||||||
httpsURLConnection.getInputStream().close();
|
httpURLConnection.getInputStream().close();
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
throw new HttpsConnectionException(responseCode, error);
|
throw new HttpsConnectionException(responseCode, error);
|
||||||
}
|
}
|
||||||
getSinceMaxId();
|
getSinceMaxId();
|
||||||
httpsURLConnection.getInputStream().close();
|
httpURLConnection.getInputStream().close();
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,15 +229,17 @@ public class HttpsConnection {
|
||||||
try {
|
try {
|
||||||
url = new URL(urlConnection);
|
url = new URL(urlConnection);
|
||||||
if (proxy != null)
|
if (proxy != null)
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
httpURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
httpURLConnection = (HttpsURLConnection) url.openConnection();
|
||||||
httpsURLConnection.setRequestProperty("http.keepAlive", "false");
|
httpURLConnection.setRequestProperty("http.keepAlive", "false");
|
||||||
httpsURLConnection.setInstanceFollowRedirects(false);
|
httpURLConnection.setInstanceFollowRedirects(false);
|
||||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
if (httpURLConnection instanceof HttpsURLConnection) {
|
||||||
httpsURLConnection.setRequestMethod("HEAD");
|
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||||
if (httpsURLConnection.getResponseCode() == 301 || httpsURLConnection.getResponseCode() == 302) {
|
}
|
||||||
Map<String, List<String>> map = httpsURLConnection.getHeaderFields();
|
httpURLConnection.setRequestMethod("HEAD");
|
||||||
|
if (httpURLConnection.getResponseCode() == 301 || httpURLConnection.getResponseCode() == 302) {
|
||||||
|
Map<String, List<String>> map = httpURLConnection.getHeaderFields();
|
||||||
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
|
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
|
||||||
if (entry.toString().toLowerCase().startsWith("location")) {
|
if (entry.toString().toLowerCase().startsWith("location")) {
|
||||||
Matcher matcher = urlPattern.matcher(entry.toString());
|
Matcher matcher = urlPattern.matcher(entry.toString());
|
||||||
|
@ -246,7 +249,7 @@ public class HttpsConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
httpsURLConnection.getInputStream().close();
|
httpURLConnection.getInputStream().close();
|
||||||
if (redirect != null && redirect.compareTo(urlConnection) != 0) {
|
if (redirect != null && redirect.compareTo(urlConnection) != 0) {
|
||||||
URL redirectURL = new URL(redirect);
|
URL redirectURL = new URL(redirect);
|
||||||
String host = redirectURL.getHost();
|
String host = redirectURL.getHost();
|
||||||
|
@ -266,60 +269,18 @@ public class HttpsConnection {
|
||||||
public String get(String urlConnection) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
|
public String get(String urlConnection) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
|
||||||
|
|
||||||
URL url = new URL(urlConnection);
|
URL url = new URL(urlConnection);
|
||||||
if (urlConnection.startsWith("https://")) {
|
|
||||||
if (proxy != null)
|
if (proxy != null)
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
httpURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
httpURLConnection = (HttpsURLConnection) url.openConnection();
|
||||||
httpsURLConnection.setConnectTimeout(30 * 1000);
|
|
||||||
httpsURLConnection.setRequestProperty("http.keepAlive", "false");
|
|
||||||
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
|
||||||
httpsURLConnection.setRequestProperty("Accept", "application/json");
|
|
||||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
|
||||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
|
||||||
httpsURLConnection.setRequestMethod("GET");
|
|
||||||
httpsURLConnection.setDefaultUseCaches(true);
|
|
||||||
httpsURLConnection.setUseCaches(true);
|
|
||||||
String response;
|
|
||||||
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
|
|
||||||
getSinceMaxId();
|
|
||||||
response = converToString(httpsURLConnection.getInputStream());
|
|
||||||
} else {
|
|
||||||
String error = null;
|
|
||||||
if (httpsURLConnection.getErrorStream() != null) {
|
|
||||||
InputStream stream = httpsURLConnection.getErrorStream();
|
|
||||||
if (stream == null) {
|
|
||||||
stream = httpsURLConnection.getInputStream();
|
|
||||||
}
|
|
||||||
try (Scanner scanner = new Scanner(stream)) {
|
|
||||||
scanner.useDelimiter("\\Z");
|
|
||||||
if (scanner.hasNext()) {
|
|
||||||
error = scanner.next();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int responseCode = httpsURLConnection.getResponseCode();
|
|
||||||
try {
|
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
throw new HttpsConnectionException(responseCode, error);
|
|
||||||
}
|
|
||||||
getSinceMaxId();
|
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
return response;
|
|
||||||
} else {
|
|
||||||
if (proxy != null)
|
|
||||||
httpURLConnection = (HttpURLConnection) url.openConnection(proxy);
|
|
||||||
else
|
|
||||||
httpURLConnection = (HttpURLConnection) url.openConnection();
|
|
||||||
httpURLConnection.setConnectTimeout(30 * 1000);
|
httpURLConnection.setConnectTimeout(30 * 1000);
|
||||||
httpURLConnection.setRequestProperty("http.keepAlive", "false");
|
httpURLConnection.setRequestProperty("http.keepAlive", "false");
|
||||||
httpURLConnection.setRequestProperty("Content-Type", "application/json");
|
httpURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||||
httpURLConnection.setRequestProperty("Accept", "application/json");
|
httpURLConnection.setRequestProperty("Accept", "application/json");
|
||||||
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||||
|
if (httpURLConnection instanceof HttpsURLConnection) {
|
||||||
|
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||||
|
}
|
||||||
httpURLConnection.setRequestMethod("GET");
|
httpURLConnection.setRequestMethod("GET");
|
||||||
httpURLConnection.setDefaultUseCaches(true);
|
httpURLConnection.setDefaultUseCaches(true);
|
||||||
httpURLConnection.setUseCaches(true);
|
httpURLConnection.setUseCaches(true);
|
||||||
|
@ -356,9 +317,6 @@ public class HttpsConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String post(String urlConnection, int timeout, HashMap<String, String> paramaters, String token) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
|
public String post(String urlConnection, int timeout, HashMap<String, String> paramaters, String token) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
|
||||||
URL url = new URL(urlConnection);
|
URL url = new URL(urlConnection);
|
||||||
Map<String, Object> params = new LinkedHashMap<>();
|
Map<String, Object> params = new LinkedHashMap<>();
|
||||||
|
@ -378,62 +336,16 @@ public class HttpsConnection {
|
||||||
postData.append(param.getValue());
|
postData.append(param.getValue());
|
||||||
}
|
}
|
||||||
byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8);
|
byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8);
|
||||||
if (urlConnection.startsWith("https://")) {
|
|
||||||
if (proxy != null)
|
if (proxy != null)
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
httpURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
httpURLConnection = (HttpsURLConnection) url.openConnection();
|
||||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
|
||||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
|
||||||
httpsURLConnection.setDoOutput(true);
|
|
||||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
|
||||||
httpsURLConnection.setRequestMethod("POST");
|
|
||||||
if (token != null && !token.startsWith("Basic "))
|
|
||||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
|
||||||
else if (token != null && token.startsWith("Basic "))
|
|
||||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
|
||||||
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
|
||||||
|
|
||||||
|
|
||||||
httpsURLConnection.getOutputStream().write(postDataBytes);
|
|
||||||
String response;
|
|
||||||
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
|
|
||||||
getSinceMaxId();
|
|
||||||
response = converToString(httpsURLConnection.getInputStream());
|
|
||||||
} else {
|
|
||||||
String error = null;
|
|
||||||
if (httpsURLConnection.getErrorStream() != null) {
|
|
||||||
InputStream stream = httpsURLConnection.getErrorStream();
|
|
||||||
if (stream == null) {
|
|
||||||
stream = httpsURLConnection.getInputStream();
|
|
||||||
}
|
|
||||||
try (Scanner scanner = new Scanner(stream)) {
|
|
||||||
scanner.useDelimiter("\\Z");
|
|
||||||
if (scanner.hasNext()) {
|
|
||||||
error = scanner.next();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int responseCode = httpsURLConnection.getResponseCode();
|
|
||||||
try {
|
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
throw new HttpsConnectionException(responseCode, error);
|
|
||||||
}
|
|
||||||
getSinceMaxId();
|
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
return response;
|
|
||||||
} else {
|
|
||||||
if (proxy != null)
|
|
||||||
httpURLConnection = (HttpURLConnection) url.openConnection(proxy);
|
|
||||||
else
|
|
||||||
httpURLConnection = (HttpURLConnection) url.openConnection();
|
|
||||||
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||||
httpURLConnection.setConnectTimeout(timeout * 1000);
|
httpURLConnection.setConnectTimeout(timeout * 1000);
|
||||||
httpURLConnection.setDoOutput(true);
|
httpURLConnection.setDoOutput(true);
|
||||||
|
if (httpURLConnection instanceof HttpsURLConnection) {
|
||||||
|
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||||
|
}
|
||||||
httpURLConnection.setRequestMethod("POST");
|
httpURLConnection.setRequestMethod("POST");
|
||||||
if (token != null && !token.startsWith("Basic "))
|
if (token != null && !token.startsWith("Basic "))
|
||||||
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||||
|
@ -441,6 +353,7 @@ public class HttpsConnection {
|
||||||
httpURLConnection.setRequestProperty("Authorization", token);
|
httpURLConnection.setRequestProperty("Authorization", token);
|
||||||
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||||
|
|
||||||
|
|
||||||
httpURLConnection.getOutputStream().write(postDataBytes);
|
httpURLConnection.getOutputStream().write(postDataBytes);
|
||||||
String response;
|
String response;
|
||||||
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
||||||
|
@ -474,66 +387,12 @@ public class HttpsConnection {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
String postJson(String urlConnection, int timeout, JsonObject jsonObject, String token) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
|
String postJson(String urlConnection, int timeout, JsonObject jsonObject, String token) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
|
||||||
|
|
||||||
URL url = new URL(urlConnection);
|
URL url = new URL(urlConnection);
|
||||||
byte[] postDataBytes;
|
byte[] postDataBytes;
|
||||||
postDataBytes = jsonObject.toString().getBytes(StandardCharsets.UTF_8);
|
postDataBytes = jsonObject.toString().getBytes(StandardCharsets.UTF_8);
|
||||||
if (urlConnection.startsWith("https://")) {
|
|
||||||
|
|
||||||
if (proxy != null)
|
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
|
||||||
else
|
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
|
||||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
|
||||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
|
||||||
httpsURLConnection.setDoOutput(true);
|
|
||||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
|
||||||
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
|
||||||
httpsURLConnection.setRequestProperty("Accept", "application/json");
|
|
||||||
httpsURLConnection.setRequestMethod("POST");
|
|
||||||
if (token != null && !token.startsWith("Basic "))
|
|
||||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
|
||||||
else if (token != null && token.startsWith("Basic "))
|
|
||||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
|
||||||
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
|
||||||
|
|
||||||
|
|
||||||
httpsURLConnection.getOutputStream().write(postDataBytes);
|
|
||||||
String response;
|
|
||||||
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
|
|
||||||
getSinceMaxId();
|
|
||||||
response = converToString(httpsURLConnection.getInputStream());
|
|
||||||
} else {
|
|
||||||
String error = null;
|
|
||||||
if (httpsURLConnection.getErrorStream() != null) {
|
|
||||||
InputStream stream = httpsURLConnection.getErrorStream();
|
|
||||||
if (stream == null) {
|
|
||||||
stream = httpsURLConnection.getInputStream();
|
|
||||||
}
|
|
||||||
try (Scanner scanner = new Scanner(stream)) {
|
|
||||||
scanner.useDelimiter("\\Z");
|
|
||||||
if (scanner.hasNext()) {
|
|
||||||
error = scanner.next();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int responseCode = httpsURLConnection.getResponseCode();
|
|
||||||
try {
|
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
throw new HttpsConnectionException(responseCode, error);
|
|
||||||
}
|
|
||||||
getSinceMaxId();
|
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
return response;
|
|
||||||
} else {
|
|
||||||
if (proxy != null)
|
if (proxy != null)
|
||||||
httpURLConnection = (HttpURLConnection) url.openConnection(proxy);
|
httpURLConnection = (HttpURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
|
@ -541,6 +400,11 @@ public class HttpsConnection {
|
||||||
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||||
httpURLConnection.setConnectTimeout(timeout * 1000);
|
httpURLConnection.setConnectTimeout(timeout * 1000);
|
||||||
httpURLConnection.setDoOutput(true);
|
httpURLConnection.setDoOutput(true);
|
||||||
|
if (httpURLConnection instanceof HttpsURLConnection) {
|
||||||
|
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||||
|
}
|
||||||
|
httpURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||||
|
httpURLConnection.setRequestProperty("Accept", "application/json");
|
||||||
httpURLConnection.setRequestMethod("POST");
|
httpURLConnection.setRequestMethod("POST");
|
||||||
if (token != null && !token.startsWith("Basic "))
|
if (token != null && !token.startsWith("Basic "))
|
||||||
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||||
|
@ -548,6 +412,7 @@ public class HttpsConnection {
|
||||||
httpURLConnection.setRequestProperty("Authorization", token);
|
httpURLConnection.setRequestProperty("Authorization", token);
|
||||||
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||||
|
|
||||||
|
|
||||||
httpURLConnection.getOutputStream().write(postDataBytes);
|
httpURLConnection.getOutputStream().write(postDataBytes);
|
||||||
String response;
|
String response;
|
||||||
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
||||||
|
@ -579,7 +444,6 @@ public class HttpsConnection {
|
||||||
getSinceMaxId();
|
getSinceMaxId();
|
||||||
httpURLConnection.getInputStream().close();
|
httpURLConnection.getInputStream().close();
|
||||||
return response;
|
return response;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,32 +453,34 @@ public class HttpsConnection {
|
||||||
byte[] postDataBytes = paramaters.toString().getBytes(StandardCharsets.UTF_8);
|
byte[] postDataBytes = paramaters.toString().getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
if (proxy != null)
|
if (proxy != null)
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
httpURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
httpURLConnection = (HttpsURLConnection) url.openConnection();
|
||||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
httpURLConnection.setConnectTimeout(timeout * 1000);
|
||||||
httpsURLConnection.setDoOutput(true);
|
httpURLConnection.setDoOutput(true);
|
||||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
if (httpURLConnection instanceof HttpsURLConnection) {
|
||||||
httpsURLConnection.setRequestMethod("POST");
|
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||||
|
}
|
||||||
|
httpURLConnection.setRequestMethod("POST");
|
||||||
if (token != null && !token.startsWith("Basic "))
|
if (token != null && !token.startsWith("Basic "))
|
||||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||||
else if (token != null && token.startsWith("Basic "))
|
else if (token != null && token.startsWith("Basic "))
|
||||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
httpURLConnection.setRequestProperty("Authorization", token);
|
||||||
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||||
|
|
||||||
|
|
||||||
httpsURLConnection.getOutputStream().write(postDataBytes);
|
httpURLConnection.getOutputStream().write(postDataBytes);
|
||||||
String response;
|
String response;
|
||||||
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
|
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
||||||
getSinceMaxId();
|
getSinceMaxId();
|
||||||
response = converToString(httpsURLConnection.getInputStream());
|
response = converToString(httpURLConnection.getInputStream());
|
||||||
} else {
|
} else {
|
||||||
String error = null;
|
String error = null;
|
||||||
if (httpsURLConnection.getErrorStream() != null) {
|
if (httpURLConnection.getErrorStream() != null) {
|
||||||
InputStream stream = httpsURLConnection.getErrorStream();
|
InputStream stream = httpURLConnection.getErrorStream();
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
stream = httpsURLConnection.getInputStream();
|
stream = httpURLConnection.getInputStream();
|
||||||
}
|
}
|
||||||
try (Scanner scanner = new Scanner(stream)) {
|
try (Scanner scanner = new Scanner(stream)) {
|
||||||
scanner.useDelimiter("\\Z");
|
scanner.useDelimiter("\\Z");
|
||||||
|
@ -625,15 +491,15 @@ public class HttpsConnection {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int responseCode = httpsURLConnection.getResponseCode();
|
int responseCode = httpURLConnection.getResponseCode();
|
||||||
try {
|
try {
|
||||||
httpsURLConnection.getInputStream().close();
|
httpURLConnection.getInputStream().close();
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
throw new HttpsConnectionException(responseCode, error);
|
throw new HttpsConnectionException(responseCode, error);
|
||||||
}
|
}
|
||||||
getSinceMaxId();
|
getSinceMaxId();
|
||||||
httpsURLConnection.getInputStream().close();
|
httpURLConnection.getInputStream().close();
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -646,77 +512,6 @@ public class HttpsConnection {
|
||||||
public void download(final String downloadUrl, final OnDownloadInterface listener) {
|
public void download(final String downloadUrl, final OnDownloadInterface listener) {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
URL url;
|
URL url;
|
||||||
HttpsURLConnection httpsURLConnection;
|
|
||||||
HttpURLConnection httpURLConnection;
|
|
||||||
if (downloadUrl.startsWith("https://")) {
|
|
||||||
try {
|
|
||||||
url = new URL(downloadUrl);
|
|
||||||
if (proxy != null)
|
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
|
||||||
else
|
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
|
||||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
|
||||||
int responseCode = httpsURLConnection.getResponseCode();
|
|
||||||
|
|
||||||
// always check HTTP response code first
|
|
||||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
||||||
String fileName = "";
|
|
||||||
String disposition = httpsURLConnection.getHeaderField("Content-Disposition");
|
|
||||||
|
|
||||||
if (disposition != null) {
|
|
||||||
// extracts file name from header field
|
|
||||||
int index = disposition.indexOf("filename=");
|
|
||||||
if (index > 0) {
|
|
||||||
fileName = disposition.substring(index + 10,
|
|
||||||
disposition.length() - 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// extracts file name from URL
|
|
||||||
fileName = downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1
|
|
||||||
);
|
|
||||||
}
|
|
||||||
fileName = FileNameCleaner.cleanFileName(fileName);
|
|
||||||
// opens input stream from the HTTP connection
|
|
||||||
InputStream inputStream = httpsURLConnection.getInputStream();
|
|
||||||
File saveDir = context.getCacheDir();
|
|
||||||
final String saveFilePath = saveDir + File.separator + fileName;
|
|
||||||
|
|
||||||
// opens an output stream to save into file
|
|
||||||
FileOutputStream outputStream = new FileOutputStream(saveFilePath);
|
|
||||||
|
|
||||||
int bytesRead;
|
|
||||||
byte[] buffer = new byte[CHUNK_SIZE];
|
|
||||||
int contentSize = httpsURLConnection.getContentLength();
|
|
||||||
int downloadedFileSize = 0;
|
|
||||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
||||||
outputStream.write(buffer, 0, bytesRead);
|
|
||||||
downloadedFileSize += bytesRead;
|
|
||||||
if (context instanceof SlideMediaActivity) {
|
|
||||||
final int currentProgress = (downloadedFileSize * 100) / contentSize;
|
|
||||||
((SlideMediaActivity) context).runOnUiThread(() -> listener.onUpdateProgress(currentProgress > 0 ? currentProgress : 101));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
outputStream.close();
|
|
||||||
inputStream.close();
|
|
||||||
if (context instanceof TootActivity)
|
|
||||||
((TootActivity) context).runOnUiThread(() -> listener.onDownloaded(saveFilePath, downloadUrl, null));
|
|
||||||
if (context instanceof SlideMediaActivity)
|
|
||||||
((SlideMediaActivity) context).runOnUiThread(() -> listener.onDownloaded(saveFilePath, downloadUrl, null));
|
|
||||||
} else {
|
|
||||||
final Error error = new Error();
|
|
||||||
error.setError(String.valueOf(responseCode));
|
|
||||||
if (context instanceof TootActivity)
|
|
||||||
((TootActivity) context).runOnUiThread(() -> listener.onDownloaded(null, downloadUrl, error));
|
|
||||||
if (context instanceof SlideMediaActivity)
|
|
||||||
((SlideMediaActivity) context).runOnUiThread(() -> listener.onDownloaded(null, downloadUrl, error));
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
Error error = new Error();
|
|
||||||
error.setError(context.getString(R.string.toast_error));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
try {
|
try {
|
||||||
url = new URL(downloadUrl);
|
url = new URL(downloadUrl);
|
||||||
if (proxy != null)
|
if (proxy != null)
|
||||||
|
@ -784,7 +579,6 @@ public class HttpsConnection {
|
||||||
error.setError(context.getString(R.string.toast_error));
|
error.setError(context.getString(R.string.toast_error));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -797,34 +591,14 @@ public class HttpsConnection {
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (downloadUrl.startsWith("https://")) {
|
|
||||||
try {
|
try {
|
||||||
if (proxy != null)
|
if (proxy != null)
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
httpURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
httpURLConnection = (HttpsURLConnection) url.openConnection();
|
||||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
if (httpURLConnection instanceof HttpsURLConnection) {
|
||||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||||
int responseCode = httpsURLConnection.getResponseCode();
|
|
||||||
// always check HTTP response code first
|
|
||||||
if (responseCode >= 200 && responseCode < 400) {
|
|
||||||
// opens input stream from the HTTP connection
|
|
||||||
return httpsURLConnection.getInputStream();
|
|
||||||
}
|
}
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
} catch (IOException | NoSuchAlgorithmException | KeyManagementException ignored) {
|
|
||||||
}
|
|
||||||
if (httpsURLConnection != null)
|
|
||||||
try {
|
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
if (proxy != null)
|
|
||||||
httpURLConnection = (HttpURLConnection) url.openConnection(proxy);
|
|
||||||
else
|
|
||||||
httpURLConnection = (HttpURLConnection) url.openConnection();
|
|
||||||
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||||
int responseCode = httpURLConnection.getResponseCode();
|
int responseCode = httpURLConnection.getResponseCode();
|
||||||
// always check HTTP response code first
|
// always check HTTP response code first
|
||||||
|
@ -833,14 +607,13 @@ public class HttpsConnection {
|
||||||
return httpURLConnection.getInputStream();
|
return httpURLConnection.getInputStream();
|
||||||
}
|
}
|
||||||
httpURLConnection.getInputStream().close();
|
httpURLConnection.getInputStream().close();
|
||||||
} catch (IOException ignored) {
|
} catch (IOException | NoSuchAlgorithmException | KeyManagementException ignored) {
|
||||||
}
|
}
|
||||||
if (httpURLConnection != null)
|
if (httpURLConnection != null)
|
||||||
try {
|
try {
|
||||||
httpURLConnection.getInputStream().close();
|
httpURLConnection.getInputStream().close();
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -925,81 +698,16 @@ public class HttpsConnection {
|
||||||
}
|
}
|
||||||
byte[] postDataBytes = (postData.toString()).getBytes(StandardCharsets.UTF_8);
|
byte[] postDataBytes = (postData.toString()).getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
if (urlConnection.startsWith("https://")) {
|
|
||||||
if (proxy != null)
|
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
|
||||||
else
|
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
|
||||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
|
||||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
|
||||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
|
|
||||||
httpsURLConnection.setRequestMethod("PATCH");
|
|
||||||
} else {
|
|
||||||
httpsURLConnection.setRequestProperty("X-HTTP-Method-Override", "PATCH");
|
|
||||||
httpsURLConnection.setRequestMethod("POST");
|
|
||||||
}
|
|
||||||
if (token != null && !token.startsWith("Basic "))
|
|
||||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
|
||||||
else if (token != null && token.startsWith("Basic "))
|
|
||||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
|
||||||
httpsURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
|
||||||
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
|
||||||
httpsURLConnection.setDoOutput(true);
|
|
||||||
|
|
||||||
String response;
|
|
||||||
OutputStream outputStream = httpsURLConnection.getOutputStream();
|
|
||||||
outputStream.write(postDataBytes);
|
|
||||||
if (avatar != null) {
|
|
||||||
uploadMedia(urlConnection, avatar, null, avatarName);
|
|
||||||
}
|
|
||||||
if (header != null) {
|
|
||||||
uploadMedia(urlConnection, null, header, headerName);
|
|
||||||
}
|
|
||||||
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
|
|
||||||
response = converToString(httpsURLConnection.getInputStream());
|
|
||||||
} else {
|
|
||||||
String error = null;
|
|
||||||
if (httpsURLConnection.getErrorStream() != null) {
|
|
||||||
InputStream stream = httpsURLConnection.getErrorStream();
|
|
||||||
if (stream == null) {
|
|
||||||
stream = httpsURLConnection.getInputStream();
|
|
||||||
}
|
|
||||||
try (Scanner scanner = new Scanner(stream)) {
|
|
||||||
scanner.useDelimiter("\\Z");
|
|
||||||
if (scanner.hasNext()) {
|
|
||||||
error = scanner.next();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int responseCode = httpsURLConnection.getResponseCode();
|
|
||||||
try {
|
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
throw new HttpsConnectionException(responseCode, error);
|
|
||||||
}
|
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
return response;
|
|
||||||
} else {
|
|
||||||
if (proxy != null)
|
if (proxy != null)
|
||||||
httpURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
httpURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
httpURLConnection = (HttpsURLConnection) url.openConnection();
|
httpURLConnection = (HttpsURLConnection) url.openConnection();
|
||||||
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||||
httpURLConnection.setConnectTimeout(timeout * 1000);
|
httpURLConnection.setConnectTimeout(timeout * 1000);
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
|
if (httpURLConnection instanceof HttpsURLConnection) {
|
||||||
httpURLConnection.setRequestMethod("PATCH");
|
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||||
} else {
|
|
||||||
httpURLConnection.setRequestProperty("X-HTTP-Method-Override", "PATCH");
|
|
||||||
httpURLConnection.setRequestMethod("POST");
|
|
||||||
}
|
}
|
||||||
|
httpURLConnection.setRequestMethod("PATCH");
|
||||||
if (token != null && !token.startsWith("Basic "))
|
if (token != null && !token.startsWith("Basic "))
|
||||||
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||||
else if (token != null && token.startsWith("Basic "))
|
else if (token != null && token.startsWith("Basic "))
|
||||||
|
@ -1008,7 +716,7 @@ public class HttpsConnection {
|
||||||
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||||
httpURLConnection.setDoOutput(true);
|
httpURLConnection.setDoOutput(true);
|
||||||
|
|
||||||
|
String response;
|
||||||
OutputStream outputStream = httpURLConnection.getOutputStream();
|
OutputStream outputStream = httpURLConnection.getOutputStream();
|
||||||
outputStream.write(postDataBytes);
|
outputStream.write(postDataBytes);
|
||||||
if (avatar != null) {
|
if (avatar != null) {
|
||||||
|
@ -1017,9 +725,8 @@ public class HttpsConnection {
|
||||||
if (header != null) {
|
if (header != null) {
|
||||||
uploadMedia(urlConnection, null, header, headerName);
|
uploadMedia(urlConnection, null, header, headerName);
|
||||||
}
|
}
|
||||||
String response;
|
|
||||||
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
||||||
response = converToString(httpsURLConnection.getInputStream());
|
response = converToString(httpURLConnection.getInputStream());
|
||||||
} else {
|
} else {
|
||||||
String error = null;
|
String error = null;
|
||||||
if (httpURLConnection.getErrorStream() != null) {
|
if (httpURLConnection.getErrorStream() != null) {
|
||||||
|
@ -1041,12 +748,14 @@ public class HttpsConnection {
|
||||||
httpURLConnection.getInputStream().close();
|
httpURLConnection.getInputStream().close();
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
httpURLConnection.getInputStream().close();
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
throw new HttpsConnectionException(responseCode, error);
|
throw new HttpsConnectionException(responseCode, error);
|
||||||
}
|
}
|
||||||
httpURLConnection.getInputStream().close();
|
httpURLConnection.getInputStream().close();
|
||||||
return response;
|
return response;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1071,62 +780,15 @@ public class HttpsConnection {
|
||||||
}
|
}
|
||||||
byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8);
|
byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
if (urlConnection.startsWith("https://")) {
|
|
||||||
if (proxy != null)
|
if (proxy != null)
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
httpURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
httpURLConnection = (HttpsURLConnection) url.openConnection();
|
||||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
|
||||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
|
||||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
|
||||||
if (token != null && !token.startsWith("Basic "))
|
|
||||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
|
||||||
else if (token != null && token.startsWith("Basic "))
|
|
||||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
|
||||||
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
|
||||||
|
|
||||||
httpsURLConnection.setRequestMethod("PUT");
|
|
||||||
httpsURLConnection.setDoInput(true);
|
|
||||||
httpsURLConnection.setDoOutput(true);
|
|
||||||
|
|
||||||
httpsURLConnection.getOutputStream().write(postDataBytes);
|
|
||||||
String response;
|
|
||||||
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
|
|
||||||
getSinceMaxId();
|
|
||||||
response = converToString(httpsURLConnection.getInputStream());
|
|
||||||
} else {
|
|
||||||
String error = null;
|
|
||||||
if (httpsURLConnection.getErrorStream() != null) {
|
|
||||||
InputStream stream = httpsURLConnection.getErrorStream();
|
|
||||||
if (stream == null) {
|
|
||||||
stream = httpsURLConnection.getInputStream();
|
|
||||||
}
|
|
||||||
try (Scanner scanner = new Scanner(stream)) {
|
|
||||||
scanner.useDelimiter("\\Z");
|
|
||||||
if (scanner.hasNext()) {
|
|
||||||
error = scanner.next();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int responseCode = httpsURLConnection.getResponseCode();
|
|
||||||
try {
|
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
throw new HttpsConnectionException(responseCode, error);
|
|
||||||
}
|
|
||||||
getSinceMaxId();
|
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
return response;
|
|
||||||
} else {
|
|
||||||
if (proxy != null)
|
|
||||||
httpURLConnection = (HttpURLConnection) url.openConnection(proxy);
|
|
||||||
else
|
|
||||||
httpURLConnection = (HttpURLConnection) url.openConnection();
|
|
||||||
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||||
httpURLConnection.setConnectTimeout(timeout * 1000);
|
httpURLConnection.setConnectTimeout(timeout * 1000);
|
||||||
|
if (httpURLConnection instanceof HttpsURLConnection) {
|
||||||
|
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||||
|
}
|
||||||
if (token != null && !token.startsWith("Basic "))
|
if (token != null && !token.startsWith("Basic "))
|
||||||
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||||
else if (token != null && token.startsWith("Basic "))
|
else if (token != null && token.startsWith("Basic "))
|
||||||
|
@ -1168,7 +830,6 @@ public class HttpsConnection {
|
||||||
getSinceMaxId();
|
getSinceMaxId();
|
||||||
httpURLConnection.getInputStream().close();
|
httpURLConnection.getInputStream().close();
|
||||||
return response;
|
return response;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1193,68 +854,24 @@ public class HttpsConnection {
|
||||||
}
|
}
|
||||||
byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8);
|
byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
if (urlConnection.startsWith("https://")) {
|
|
||||||
if (proxy != null)
|
if (proxy != null)
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
httpURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
httpURLConnection = (HttpsURLConnection) url.openConnection();
|
||||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
|
||||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
|
||||||
if (token != null && !token.startsWith("Basic "))
|
|
||||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
|
||||||
else if (token != null && token.startsWith("Basic "))
|
|
||||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
|
||||||
httpsURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
|
||||||
httpsURLConnection.setRequestMethod("DELETE");
|
|
||||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
|
||||||
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
|
||||||
|
|
||||||
httpsURLConnection.getOutputStream().write(postDataBytes);
|
|
||||||
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
|
|
||||||
getSinceMaxId();
|
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
return httpsURLConnection.getResponseCode();
|
|
||||||
} else {
|
|
||||||
String error = null;
|
|
||||||
if (httpsURLConnection.getErrorStream() != null) {
|
|
||||||
InputStream stream = httpsURLConnection.getErrorStream();
|
|
||||||
if (stream == null) {
|
|
||||||
stream = httpsURLConnection.getInputStream();
|
|
||||||
}
|
|
||||||
try (Scanner scanner = new Scanner(stream)) {
|
|
||||||
scanner.useDelimiter("\\Z");
|
|
||||||
if (scanner.hasNext()) {
|
|
||||||
error = scanner.next();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int responseCode = httpsURLConnection.getResponseCode();
|
|
||||||
try {
|
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
throw new HttpsConnectionException(responseCode, error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (proxy != null)
|
|
||||||
httpURLConnection = (HttpURLConnection) url.openConnection(proxy);
|
|
||||||
else
|
|
||||||
httpURLConnection = (HttpURLConnection) url.openConnection();
|
|
||||||
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||||
|
if (httpURLConnection instanceof HttpsURLConnection) {
|
||||||
|
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||||
|
}
|
||||||
if (token != null && !token.startsWith("Basic "))
|
if (token != null && !token.startsWith("Basic "))
|
||||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||||
else if (token != null && token.startsWith("Basic "))
|
else if (token != null && token.startsWith("Basic "))
|
||||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
httpURLConnection.setRequestProperty("Authorization", token);
|
||||||
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||||
httpURLConnection.setRequestMethod("DELETE");
|
httpURLConnection.setRequestMethod("DELETE");
|
||||||
httpURLConnection.setConnectTimeout(timeout * 1000);
|
httpURLConnection.setConnectTimeout(timeout * 1000);
|
||||||
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||||
|
|
||||||
httpURLConnection.getOutputStream().write(postDataBytes);
|
httpURLConnection.getOutputStream().write(postDataBytes);
|
||||||
|
|
||||||
|
|
||||||
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
||||||
getSinceMaxId();
|
getSinceMaxId();
|
||||||
httpURLConnection.getInputStream().close();
|
httpURLConnection.getInputStream().close();
|
||||||
|
@ -1283,7 +900,6 @@ public class HttpsConnection {
|
||||||
throw new HttpsConnectionException(responseCode, error);
|
throw new HttpsConnectionException(responseCode, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public String getSince_id() {
|
public String getSince_id() {
|
||||||
return since_id;
|
return since_id;
|
||||||
|
@ -1297,10 +913,9 @@ public class HttpsConnection {
|
||||||
private void getSinceMaxId() {
|
private void getSinceMaxId() {
|
||||||
if (Helper.getLiveInstanceWithProtocol(context) == null)
|
if (Helper.getLiveInstanceWithProtocol(context) == null)
|
||||||
return;
|
return;
|
||||||
if (Helper.getLiveInstanceWithProtocol(context).startsWith("https://")) {
|
if (httpURLConnection == null)
|
||||||
if (httpsURLConnection == null)
|
|
||||||
return;
|
return;
|
||||||
Map<String, List<String>> map = httpsURLConnection.getHeaderFields();
|
Map<String, List<String>> map = httpURLConnection.getHeaderFields();
|
||||||
|
|
||||||
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
|
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
|
||||||
if (entry.toString().startsWith("Link") || entry.toString().startsWith("link")) {
|
if (entry.toString().startsWith("Link") || entry.toString().startsWith("link")) {
|
||||||
|
@ -1325,28 +940,6 @@ public class HttpsConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (httpURLConnection == null)
|
|
||||||
return;
|
|
||||||
Map<String, List<String>> map = httpURLConnection.getHeaderFields();
|
|
||||||
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
|
|
||||||
if (entry.toString().startsWith("Link") || entry.toString().startsWith("link")) {
|
|
||||||
Pattern patternMaxId = Pattern.compile("max_id=([0-9a-zA-Z]+).*");
|
|
||||||
Matcher matcherMaxId = patternMaxId.matcher(entry.toString());
|
|
||||||
if (matcherMaxId.find()) {
|
|
||||||
max_id = matcherMaxId.group(1);
|
|
||||||
}
|
|
||||||
if (entry.toString().startsWith("Link")) {
|
|
||||||
Pattern patternSinceId = Pattern.compile("since_id=([0-9a-zA-Z]+).*");
|
|
||||||
Matcher matcherSinceId = patternSinceId.matcher(entry.toString());
|
|
||||||
if (matcherSinceId.find()) {
|
|
||||||
since_id = matcherSinceId.group(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String converToString(InputStream inputStream) {
|
private String converToString(InputStream inputStream) {
|
||||||
|
@ -1355,20 +948,12 @@ public class HttpsConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
int getActionCode() {
|
int getActionCode() {
|
||||||
if (Helper.getLiveInstanceWithProtocol(context).startsWith("https://")) {
|
|
||||||
try {
|
|
||||||
return httpsURLConnection.getResponseCode();
|
|
||||||
} catch (IOException e) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
try {
|
||||||
return httpURLConnection.getResponseCode();
|
return httpURLConnection.getResponseCode();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public class HttpsConnectionException extends Exception {
|
public class HttpsConnectionException extends Exception {
|
||||||
|
|
|
@ -127,7 +127,6 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
||||||
private final List<Account> translators = new ArrayList<>();
|
private final List<Account> translators = new ArrayList<>();
|
||||||
private type type;
|
private type type;
|
||||||
private Context context;
|
private Context context;
|
||||||
private AsyncTask asyncTask;
|
|
||||||
private int countTrans, countLanguage, notificationCount, ledCount, videoSpinnerCount, liveNotificationCount;
|
private int countTrans, countLanguage, notificationCount, ledCount, videoSpinnerCount, liveNotificationCount;
|
||||||
private AccountSearchDevAdapter translatorManager;
|
private AccountSearchDevAdapter translatorManager;
|
||||||
private TextView set_folder;
|
private TextView set_folder;
|
||||||
|
@ -136,11 +135,9 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
||||||
|
|
||||||
|
|
||||||
//From: https://gist.github.com/asifmujteba/d89ba9074bc941de1eaa#file-asfurihelper
|
//From: https://gist.github.com/asifmujteba/d89ba9074bc941de1eaa#file-asfurihelper
|
||||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
|
||||||
public static String getPath(final Context context, final Uri uri) {
|
public static String getPath(final Context context, final Uri uri) {
|
||||||
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
|
||||||
// DocumentProvider
|
// DocumentProvider
|
||||||
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
|
if (DocumentsContract.isDocumentUri(context, uri)) {
|
||||||
// ExternalStorageProvider
|
// ExternalStorageProvider
|
||||||
if (isExternalStorageDocument(uri)) {
|
if (isExternalStorageDocument(uri)) {
|
||||||
final String docId = DocumentsContract.getDocumentId(uri);
|
final String docId = DocumentsContract.getDocumentId(uri);
|
||||||
|
@ -2570,10 +2567,6 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
||||||
|
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
if (type == LANGUAGE) {
|
|
||||||
if (asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
|
|
||||||
asyncTask.cancel(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum type {
|
public enum type {
|
||||||
|
|
|
@ -127,10 +127,11 @@ public class TabLayoutNotificationsFragment extends Fragment {
|
||||||
tabLayout.addTab(tabFav);
|
tabLayout.addTab(tabFav);
|
||||||
if (tabBoost.getCustomView() != null)
|
if (tabBoost.getCustomView() != null)
|
||||||
tabLayout.addTab(tabBoost);
|
tabLayout.addTab(tabBoost);
|
||||||
if (tabPoll.getCustomView() != null)
|
|
||||||
tabLayout.addTab(tabPoll);
|
|
||||||
if (tabStatus.getCustomView() != null)
|
if (tabStatus.getCustomView() != null)
|
||||||
tabLayout.addTab(tabStatus);
|
tabLayout.addTab(tabStatus);
|
||||||
|
if (tabPoll.getCustomView() != null)
|
||||||
|
tabLayout.addTab(tabPoll);
|
||||||
|
|
||||||
tabLayout.addTab(tabFollow);
|
tabLayout.addTab(tabFollow);
|
||||||
|
|
||||||
if (theme == Helper.THEME_BLACK)
|
if (theme == Helper.THEME_BLACK)
|
||||||
|
@ -196,7 +197,7 @@ public class TabLayoutNotificationsFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(@NotNull Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1139,8 +1139,8 @@ public class BaseHelper {
|
||||||
channelTitle = context.getString(R.string.channel_notif_media);
|
channelTitle = context.getString(R.string.channel_notif_media);
|
||||||
break;
|
break;
|
||||||
case TOOT:
|
case TOOT:
|
||||||
channelId = "channel_toot";
|
channelId = "channel_status";
|
||||||
channelTitle = context.getString(R.string.channel_notif_toot);
|
channelTitle = context.getString(R.string.channel_notif_status);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
channelId = "channel_boost";
|
channelId = "channel_boost";
|
||||||
|
@ -3454,7 +3454,7 @@ public class BaseHelper {
|
||||||
ContentResolver resolver = context.getContentResolver();
|
ContentResolver resolver = context.getContentResolver();
|
||||||
Cursor returnCursor =
|
Cursor returnCursor =
|
||||||
resolver.query(uri, null, null, null, null);
|
resolver.query(uri, null, null, null, null);
|
||||||
assert returnCursor != null;
|
if (returnCursor != null) {
|
||||||
try {
|
try {
|
||||||
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
||||||
returnCursor.moveToFirst();
|
returnCursor.moveToFirst();
|
||||||
|
@ -3473,6 +3473,16 @@ public class BaseHelper {
|
||||||
else
|
else
|
||||||
return "__" + suf + ".jpg";
|
return "__" + suf + ".jpg";
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Random r = new Random();
|
||||||
|
int suf = r.nextInt(9999 - 1000) + 1000;
|
||||||
|
ContentResolver cr = context.getContentResolver();
|
||||||
|
String mime = cr.getType(uri);
|
||||||
|
if (mime != null && mime.split("/").length > 1)
|
||||||
|
return "__" + suf + "." + mime.split("/")[1];
|
||||||
|
else
|
||||||
|
return "__" + suf + ".jpg";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap compressImageIfNeeded(Bitmap bmToCompress) {
|
public static Bitmap compressImageIfNeeded(Bitmap bmToCompress) {
|
||||||
|
|
|
@ -161,6 +161,7 @@ public class BaseNotificationsSyncJob extends Job {
|
||||||
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
||||||
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
|
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
|
||||||
boolean notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL, true);
|
boolean notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL, true);
|
||||||
|
boolean notif_status = sharedpreferences.getBoolean(Helper.SET_NOTIF_STATUS, true);
|
||||||
final String max_id = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
|
final String max_id = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
|
||||||
final List<Notification> notifications = new ArrayList<>();
|
final List<Notification> notifications = new ArrayList<>();
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
@ -178,6 +179,7 @@ public class BaseNotificationsSyncJob extends Job {
|
||||||
int newMentions = 0;
|
int newMentions = 0;
|
||||||
int newShare = 0;
|
int newShare = 0;
|
||||||
int newPolls = 0;
|
int newPolls = 0;
|
||||||
|
int newStatus = 0;
|
||||||
String notificationUrl = null;
|
String notificationUrl = null;
|
||||||
String title = null;
|
String title = null;
|
||||||
final String message;
|
final String message;
|
||||||
|
@ -199,6 +201,19 @@ public class BaseNotificationsSyncJob extends Job {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "status":
|
||||||
|
notifType = Helper.NotifType.STATUS;
|
||||||
|
if (notif_status) {
|
||||||
|
newStatus++;
|
||||||
|
if (notificationUrl == null) {
|
||||||
|
notificationUrl = notification.getAccount().getAvatar();
|
||||||
|
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
|
||||||
|
title = String.format("%s %s", notification.getAccount().getDisplay_name(), getContext().getString(R.string.notif_mention));
|
||||||
|
else
|
||||||
|
title = String.format("@%s %s", notification.getAccount().getAcct(), getContext().getString(R.string.notif_mention));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "reblog":
|
case "reblog":
|
||||||
notifType = Helper.NotifType.BOOST;
|
notifType = Helper.NotifType.BOOST;
|
||||||
if (notif_share) {
|
if (notif_share) {
|
||||||
|
@ -272,7 +287,7 @@ public class BaseNotificationsSyncJob extends Job {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int allNotifCount = newFollows + newAdds + newMentions + newShare + newPolls;
|
int allNotifCount = newFollows + newAdds + newMentions + newShare + newPolls + newStatus;
|
||||||
if (allNotifCount > 0) {
|
if (allNotifCount > 0) {
|
||||||
//Some others notification
|
//Some others notification
|
||||||
int other = allNotifCount - 1;
|
int other = allNotifCount - 1;
|
||||||
|
|
|
@ -67,12 +67,10 @@ public class BackupStatusService extends IntentService {
|
||||||
*
|
*
|
||||||
* @param name Used to name the worker thread, important only for debugging.
|
* @param name Used to name the worker thread, important only for debugging.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public BackupStatusService(String name) {
|
public BackupStatusService(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public BackupStatusService() {
|
public BackupStatusService() {
|
||||||
super("BackupStatusService");
|
super("BackupStatusService");
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,8 +342,9 @@ public abstract class BaseLiveNotificationService extends Service implements Net
|
||||||
boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
|
boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
|
||||||
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
||||||
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
|
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
|
||||||
|
boolean notif_status = sharedpreferences.getBoolean(Helper.SET_NOTIF_STATUS, true);
|
||||||
boolean notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL, true);
|
boolean notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL, true);
|
||||||
boolean somethingToPush = (notif_follow || notif_add || notif_mention || notif_share || notif_poll);
|
boolean somethingToPush = (notif_follow || notif_add || notif_mention || notif_share || notif_poll || notif_status);
|
||||||
String message = null;
|
String message = null;
|
||||||
if (somethingToPush) {
|
if (somethingToPush) {
|
||||||
switch (notification.getType()) {
|
switch (notification.getType()) {
|
||||||
|
@ -373,7 +374,7 @@ public abstract class BaseLiveNotificationService extends Service implements Net
|
||||||
break;
|
break;
|
||||||
case "status":
|
case "status":
|
||||||
notifType = Helper.NotifType.STATUS;
|
notifType = Helper.NotifType.STATUS;
|
||||||
if (notif_mention) {
|
if (notif_status) {
|
||||||
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
|
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
|
||||||
message = String.format("%s %s", notification.getAccount().getDisplay_name(), getString(R.string.notif_status));
|
message = String.format("%s %s", notification.getAccount().getDisplay_name(), getString(R.string.notif_status));
|
||||||
else
|
else
|
||||||
|
|
|
@ -60,12 +60,10 @@ public abstract class BaseStreamingFederatedTimelineService extends IntentServic
|
||||||
*
|
*
|
||||||
* @param name Used to name the worker thread, important only for debugging.
|
* @param name Used to name the worker thread, important only for debugging.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public BaseStreamingFederatedTimelineService(String name) {
|
public BaseStreamingFederatedTimelineService(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public BaseStreamingFederatedTimelineService() {
|
public BaseStreamingFederatedTimelineService() {
|
||||||
super("StreamingFederatedTimelineService");
|
super("StreamingFederatedTimelineService");
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,12 +60,10 @@ public abstract class BaseStreamingHomeTimelineService extends IntentService {
|
||||||
*
|
*
|
||||||
* @param name Used to name the worker thread, important only for debugging.
|
* @param name Used to name the worker thread, important only for debugging.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public BaseStreamingHomeTimelineService(String name) {
|
public BaseStreamingHomeTimelineService(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public BaseStreamingHomeTimelineService() {
|
public BaseStreamingHomeTimelineService() {
|
||||||
super("StreamingHomeTimelineService");
|
super("StreamingHomeTimelineService");
|
||||||
}
|
}
|
||||||
|
@ -104,14 +102,6 @@ public abstract class BaseStreamingHomeTimelineService extends IntentService {
|
||||||
Uri url = Uri.parse("wss://" + accountStream.getInstance() + "/api/v1/streaming/?stream=user&access_token=" + accountStream.getToken());
|
Uri url = Uri.parse("wss://" + accountStream.getInstance() + "/api/v1/streaming/?stream=user&access_token=" + accountStream.getToken());
|
||||||
AsyncHttpRequest.setDefaultHeaders(headers, url);
|
AsyncHttpRequest.setDefaultHeaders(headers, url);
|
||||||
Account finalAccountStream = accountStream;
|
Account finalAccountStream = accountStream;
|
||||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
|
|
||||||
try {
|
|
||||||
AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setSSLContext(new TLSSocketFactory(accountStream.getInstance()).getSSLContext());
|
|
||||||
AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setConnectAllAddresses(true);
|
|
||||||
} catch (KeyManagementException | NoSuchAlgorithmException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AsyncHttpClient.getDefaultInstance().websocket("wss://" + accountStream.getInstance() + "/api/v1/streaming/?stream=user&access_token=" + accountStream.getToken(), "wss", (ex, webSocket) -> {
|
AsyncHttpClient.getDefaultInstance().websocket("wss://" + accountStream.getInstance() + "/api/v1/streaming/?stream=user&access_token=" + accountStream.getToken(), "wss", (ex, webSocket) -> {
|
||||||
if (ex != null) {
|
if (ex != null) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
|
|
@ -104,14 +104,6 @@ public abstract class BaseStreamingLocalTimelineService extends IntentService {
|
||||||
Uri url = Uri.parse("wss://" + accountStream.getInstance() + "/api/v1/streaming/?stream=public:local&access_token=" + accountStream.getToken());
|
Uri url = Uri.parse("wss://" + accountStream.getInstance() + "/api/v1/streaming/?stream=public:local&access_token=" + accountStream.getToken());
|
||||||
AsyncHttpRequest.setDefaultHeaders(headers, url);
|
AsyncHttpRequest.setDefaultHeaders(headers, url);
|
||||||
Account finalAccountStream = accountStream;
|
Account finalAccountStream = accountStream;
|
||||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
|
|
||||||
try {
|
|
||||||
AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setSSLContext(new TLSSocketFactory(accountStream.getInstance()).getSSLContext());
|
|
||||||
AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setConnectAllAddresses(true);
|
|
||||||
} catch (KeyManagementException | NoSuchAlgorithmException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AsyncHttpClient.getDefaultInstance().websocket("wss://" + accountStream.getInstance() + "/api/v1/streaming/?stream=public:local&access_token=" + accountStream.getToken(), "wss", (ex, webSocket) -> {
|
AsyncHttpClient.getDefaultInstance().websocket("wss://" + accountStream.getInstance() + "/api/v1/streaming/?stream=public:local&access_token=" + accountStream.getToken(), "wss", (ex, webSocket) -> {
|
||||||
if (ex != null) {
|
if (ex != null) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
|
|
@ -214,11 +214,10 @@ public class LiveNotificationDelayedService extends Service {
|
||||||
|
|
||||||
private void startThread(Account accountStream, String key) {
|
private void startThread(Account accountStream, String key) {
|
||||||
Thread thread = new Thread() {
|
Thread thread = new Thread() {
|
||||||
@SuppressWarnings("ConstantConditions")
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (fetch) {
|
while (fetch) {
|
||||||
taks(accountStream);
|
task(accountStream);
|
||||||
fetch = (Helper.liveNotifType(LiveNotificationDelayedService.this) == Helper.NOTIF_DELAYED);
|
fetch = (Helper.liveNotifType(LiveNotificationDelayedService.this) == Helper.NOTIF_DELAYED);
|
||||||
if (sleeps.containsKey(key) && sleeps.get(key) != null) {
|
if (sleeps.containsKey(key) && sleeps.get(key) != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -241,8 +240,7 @@ public class LiveNotificationDelayedService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
private void task(Account account) {
|
||||||
private void taks(Account account) {
|
|
||||||
String key = account.getUsername() + "@" + account.getInstance();
|
String key = account.getUsername() + "@" + account.getInstance();
|
||||||
APIResponse apiResponse;
|
APIResponse apiResponse;
|
||||||
|
|
||||||
|
@ -341,8 +339,9 @@ public class LiveNotificationDelayedService extends Service {
|
||||||
boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
|
boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
|
||||||
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
||||||
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
|
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
|
||||||
|
boolean notif_status = sharedpreferences.getBoolean(Helper.SET_NOTIF_STATUS, true);
|
||||||
boolean notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL, true);
|
boolean notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL, true);
|
||||||
boolean somethingToPush = (notif_follow || notif_add || notif_mention || notif_share || notif_poll);
|
boolean somethingToPush = (notif_follow || notif_add || notif_mention || notif_share || notif_poll || notif_status);
|
||||||
|
|
||||||
String message = null;
|
String message = null;
|
||||||
if (somethingToPush) {
|
if (somethingToPush) {
|
||||||
|
@ -371,6 +370,30 @@ public class LiveNotificationDelayedService extends Service {
|
||||||
canSendBroadCast = false;
|
canSendBroadCast = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "status":
|
||||||
|
notifType = Helper.NotifType.STATUS;
|
||||||
|
if (notif_status) {
|
||||||
|
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
|
||||||
|
message = String.format("%s %s", notification.getAccount().getDisplay_name(), getString(R.string.notif_status));
|
||||||
|
else
|
||||||
|
message = String.format("@%s %s", notification.getAccount().getAcct(), getString(R.string.notif_status));
|
||||||
|
if (notification.getStatus() != null) {
|
||||||
|
if (notification.getStatus().getSpoiler_text() != null && notification.getStatus().getSpoiler_text().length() > 0) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||||
|
message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getSpoiler_text(), FROM_HTML_MODE_LEGACY));
|
||||||
|
else
|
||||||
|
message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getSpoiler_text()));
|
||||||
|
} else {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||||
|
message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getContent(), FROM_HTML_MODE_LEGACY));
|
||||||
|
else
|
||||||
|
message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getContent()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
canSendBroadCast = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "reblog":
|
case "reblog":
|
||||||
notifType = Helper.NotifType.BOOST;
|
notifType = Helper.NotifType.BOOST;
|
||||||
if (notif_share) {
|
if (notif_share) {
|
||||||
|
|
|
@ -591,7 +591,7 @@
|
||||||
<string name="channel_notif_poll">Poll Ended</string>
|
<string name="channel_notif_poll">Poll Ended</string>
|
||||||
<string name="channel_notif_toot">New Toot</string>
|
<string name="channel_notif_toot">New Toot</string>
|
||||||
<string name="channel_notif_backup">Toots Backup</string>
|
<string name="channel_notif_backup">Toots Backup</string>
|
||||||
<string name="channel_notif_status">New post</string>
|
<string name="channel_notif_status">New posts</string>
|
||||||
<string name="channel_notif_media">Media Download</string>
|
<string name="channel_notif_media">Media Download</string>
|
||||||
<string name="set_notif_sound">Change notification sound</string>
|
<string name="set_notif_sound">Change notification sound</string>
|
||||||
<string name="select_sound">Select Tone</string>
|
<string name="select_sound">Select Tone</string>
|
||||||
|
|
Loading…
Reference in New Issue