some changes
This commit is contained in:
parent
51860ff399
commit
c30e2d6a40
|
@ -15,7 +15,9 @@ android {
|
|||
multiDexEnabled true
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
dexOptions {
|
||||
javaMaxHeapSize "4g"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
|
@ -53,6 +55,7 @@ dependencies {
|
|||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
|
||||
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
|
||||
implementation 'com.github.GrenderG:Toasty:1.4.2'
|
||||
implementation 'com.google.android.exoplayer:exoplayer:2.10.6'
|
||||
implementation "com.github.mabbas007:TagsEditText:1.0.5"
|
||||
|
|
|
@ -28,6 +28,25 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
|
||||
|
||||
<activity
|
||||
android:name=".PeertubeActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:label="@string/app_name" />
|
||||
<activity
|
||||
android:name=".PeertubeEditUploadActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:label="@string/app_name"
|
||||
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||
<receiver
|
||||
android:name="app.fedilab.android.services.PeertubeUploadReceiver"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="app.fedilab.android.uploadservice.broadcast.status" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -9,6 +9,9 @@ public class FedilabTupe extends MultiDexApplication {
|
|||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(base);
|
||||
MultiDex.install(this);
|
||||
|
||||
MultiDex.install(FedilabTupe.this);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -56,7 +56,6 @@ public class HttpsConnection {
|
|||
|
||||
|
||||
private HttpsURLConnection httpsURLConnection;
|
||||
private HttpURLConnection httpURLConnection;
|
||||
private String since_id, max_id;
|
||||
private Context context;
|
||||
private int CHUNK_SIZE = 4096;
|
||||
|
@ -246,7 +245,6 @@ public class HttpsConnection {
|
|||
|
||||
|
||||
URL url = new URL(urlConnection);
|
||||
if (urlConnection.startsWith("https://")) {
|
||||
if (proxy != null)
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
else
|
||||
|
@ -290,52 +288,6 @@ public class HttpsConnection {
|
|||
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.setRequestProperty("http.keepAlive", "false");
|
||||
httpURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||
httpURLConnection.setRequestProperty("Accept", "application/json");
|
||||
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
httpURLConnection.setRequestMethod("GET");
|
||||
httpURLConnection.setDefaultUseCaches(true);
|
||||
httpURLConnection.setUseCaches(true);
|
||||
String response;
|
||||
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
||||
getSinceMaxId();
|
||||
response = converToString(httpURLConnection.getInputStream());
|
||||
} else {
|
||||
String error = null;
|
||||
if (httpURLConnection.getErrorStream() != null) {
|
||||
InputStream stream = httpURLConnection.getErrorStream();
|
||||
if (stream == null) {
|
||||
stream = httpURLConnection.getInputStream();
|
||||
}
|
||||
try (Scanner scanner = new Scanner(stream)) {
|
||||
scanner.useDelimiter("\\Z");
|
||||
if (scanner.hasNext()) {
|
||||
error = scanner.next();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
int responseCode = httpURLConnection.getResponseCode();
|
||||
try {
|
||||
httpURLConnection.getInputStream().close();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
throw new HttpsConnectionException(responseCode, error);
|
||||
}
|
||||
getSinceMaxId();
|
||||
httpURLConnection.getInputStream().close();
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -358,7 +310,6 @@ public class HttpsConnection {
|
|||
postData.append(param.getValue());
|
||||
}
|
||||
byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8);
|
||||
if (urlConnection.startsWith("https://")) {
|
||||
if (proxy != null)
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
else
|
||||
|
@ -406,54 +357,6 @@ public class HttpsConnection {
|
|||
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.setConnectTimeout(timeout * 1000);
|
||||
httpURLConnection.setDoOutput(true);
|
||||
httpURLConnection.setRequestMethod("POST");
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if (token != null && token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", token);
|
||||
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||
|
||||
httpURLConnection.getOutputStream().write(postDataBytes);
|
||||
String response;
|
||||
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
||||
getSinceMaxId();
|
||||
response = converToString(httpURLConnection.getInputStream());
|
||||
} else {
|
||||
String error = null;
|
||||
if (httpURLConnection.getErrorStream() != null) {
|
||||
InputStream stream = httpURLConnection.getErrorStream();
|
||||
if (stream == null) {
|
||||
stream = httpURLConnection.getInputStream();
|
||||
}
|
||||
try (Scanner scanner = new Scanner(stream)) {
|
||||
scanner.useDelimiter("\\Z");
|
||||
if (scanner.hasNext()) {
|
||||
error = scanner.next();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
int responseCode = httpURLConnection.getResponseCode();
|
||||
try {
|
||||
httpURLConnection.getInputStream().close();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
throw new HttpsConnectionException(responseCode, error);
|
||||
}
|
||||
getSinceMaxId();
|
||||
httpURLConnection.getInputStream().close();
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -462,7 +365,6 @@ public class HttpsConnection {
|
|||
URL url = new URL(urlConnection);
|
||||
byte[] postDataBytes;
|
||||
postDataBytes = jsonObject.toString().getBytes(StandardCharsets.UTF_8);
|
||||
if (urlConnection.startsWith("https://")) {
|
||||
|
||||
if (proxy != null)
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
|
@ -513,54 +415,6 @@ public class HttpsConnection {
|
|||
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.setConnectTimeout(timeout * 1000);
|
||||
httpURLConnection.setDoOutput(true);
|
||||
httpURLConnection.setRequestMethod("POST");
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if (token != null && token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", token);
|
||||
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||
|
||||
httpURLConnection.getOutputStream().write(postDataBytes);
|
||||
String response;
|
||||
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
||||
getSinceMaxId();
|
||||
response = converToString(httpURLConnection.getInputStream());
|
||||
} else {
|
||||
String error = null;
|
||||
if (httpURLConnection.getErrorStream() != null) {
|
||||
InputStream stream = httpURLConnection.getErrorStream();
|
||||
if (stream == null) {
|
||||
stream = httpURLConnection.getInputStream();
|
||||
}
|
||||
try (Scanner scanner = new Scanner(stream)) {
|
||||
scanner.useDelimiter("\\Z");
|
||||
if (scanner.hasNext()) {
|
||||
error = scanner.next();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
int responseCode = httpURLConnection.getResponseCode();
|
||||
try {
|
||||
httpURLConnection.getInputStream().close();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
throw new HttpsConnectionException(responseCode, error);
|
||||
}
|
||||
getSinceMaxId();
|
||||
httpURLConnection.getInputStream().close();
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
|
@ -627,8 +481,6 @@ public class HttpsConnection {
|
|||
new Thread(() -> {
|
||||
URL url;
|
||||
HttpsURLConnection httpsURLConnection;
|
||||
HttpURLConnection httpURLConnection;
|
||||
if (downloadUrl.startsWith("https://")) {
|
||||
try {
|
||||
url = new URL(downloadUrl);
|
||||
if (proxy != null)
|
||||
|
@ -683,64 +535,6 @@ public class HttpsConnection {
|
|||
Error error = new Error();
|
||||
error.setError(context.getString(R.string.toast_error));
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
url = new URL(downloadUrl);
|
||||
if (proxy != null)
|
||||
httpURLConnection = (HttpURLConnection) url.openConnection(proxy);
|
||||
else
|
||||
httpURLConnection = (HttpURLConnection) url.openConnection();
|
||||
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
int responseCode = httpURLConnection.getResponseCode();
|
||||
|
||||
// always check HTTP response code first
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
String fileName = "";
|
||||
String disposition = httpURLConnection.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 = httpURLConnection.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 = httpURLConnection.getContentLength();
|
||||
int downloadedFileSize = 0;
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, bytesRead);
|
||||
downloadedFileSize += bytesRead;
|
||||
}
|
||||
outputStream.close();
|
||||
inputStream.close();
|
||||
} else {
|
||||
final Error error = new Error();
|
||||
error.setError(String.valueOf(responseCode));
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
error.setError(context.getString(R.string.toast_error));
|
||||
}
|
||||
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
@ -753,7 +547,6 @@ public class HttpsConnection {
|
|||
} catch (MalformedURLException e) {
|
||||
return null;
|
||||
}
|
||||
if (downloadUrl.startsWith("https://")) {
|
||||
try {
|
||||
if (proxy != null)
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
|
@ -775,28 +568,6 @@ public class HttpsConnection {
|
|||
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);
|
||||
int responseCode = httpURLConnection.getResponseCode();
|
||||
// always check HTTP response code first
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
// opens input stream from the HTTP connection
|
||||
return httpURLConnection.getInputStream();
|
||||
}
|
||||
httpURLConnection.getInputStream().close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
if (httpURLConnection != null)
|
||||
try {
|
||||
httpURLConnection.getInputStream().close();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -881,7 +652,6 @@ public class HttpsConnection {
|
|||
}
|
||||
byte[] postDataBytes = (postData.toString()).getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
if (urlConnection.startsWith("https://")) {
|
||||
if (proxy != null)
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
else
|
||||
|
@ -943,66 +713,6 @@ public class HttpsConnection {
|
|||
}
|
||||
httpsURLConnection.getInputStream().close();
|
||||
return response;
|
||||
} else {
|
||||
if (proxy != null)
|
||||
httpURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
else
|
||||
httpURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
httpURLConnection.setConnectTimeout(timeout * 1000);
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
|
||||
httpURLConnection.setRequestMethod("PATCH");
|
||||
} else {
|
||||
httpURLConnection.setRequestProperty("X-HTTP-Method-Override", "PATCH");
|
||||
httpURLConnection.setRequestMethod("POST");
|
||||
}
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if (token != null && token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", token);
|
||||
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||
httpURLConnection.setDoOutput(true);
|
||||
|
||||
|
||||
OutputStream outputStream = httpURLConnection.getOutputStream();
|
||||
outputStream.write(postDataBytes);
|
||||
if (avatar != null) {
|
||||
uploadMedia(urlConnection, avatar, null, avatarName);
|
||||
}
|
||||
if (header != null) {
|
||||
uploadMedia(urlConnection, null, header, headerName);
|
||||
}
|
||||
String response;
|
||||
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
||||
response = converToString(httpsURLConnection.getInputStream());
|
||||
} else {
|
||||
String error = null;
|
||||
if (httpURLConnection.getErrorStream() != null) {
|
||||
InputStream stream = httpURLConnection.getErrorStream();
|
||||
if (stream == null) {
|
||||
stream = httpURLConnection.getInputStream();
|
||||
}
|
||||
try (Scanner scanner = new Scanner(stream)) {
|
||||
scanner.useDelimiter("\\Z");
|
||||
if (scanner.hasNext()) {
|
||||
error = scanner.next();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
int responseCode = httpURLConnection.getResponseCode();
|
||||
try {
|
||||
httpURLConnection.getInputStream().close();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
throw new HttpsConnectionException(responseCode, error);
|
||||
}
|
||||
httpURLConnection.getInputStream().close();
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1027,7 +737,6 @@ public class HttpsConnection {
|
|||
}
|
||||
byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
if (urlConnection.startsWith("https://")) {
|
||||
if (proxy != null)
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
else
|
||||
|
@ -1076,55 +785,6 @@ public class HttpsConnection {
|
|||
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.setConnectTimeout(timeout * 1000);
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if (token != null && token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", token);
|
||||
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||
|
||||
httpURLConnection.setRequestMethod("PUT");
|
||||
httpURLConnection.setDoInput(true);
|
||||
httpURLConnection.setDoOutput(true);
|
||||
|
||||
httpURLConnection.getOutputStream().write(postDataBytes);
|
||||
String response;
|
||||
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
||||
getSinceMaxId();
|
||||
response = converToString(httpURLConnection.getInputStream());
|
||||
} else {
|
||||
String error = null;
|
||||
if (httpURLConnection.getErrorStream() != null) {
|
||||
InputStream stream = httpURLConnection.getErrorStream();
|
||||
if (stream == null) {
|
||||
stream = httpURLConnection.getInputStream();
|
||||
}
|
||||
try (Scanner scanner = new Scanner(stream)) {
|
||||
scanner.useDelimiter("\\Z");
|
||||
if (scanner.hasNext()) {
|
||||
error = scanner.next();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
int responseCode = httpURLConnection.getResponseCode();
|
||||
try {
|
||||
httpURLConnection.getInputStream().close();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
throw new HttpsConnectionException(responseCode, error);
|
||||
}
|
||||
getSinceMaxId();
|
||||
httpURLConnection.getInputStream().close();
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1149,7 +809,6 @@ public class HttpsConnection {
|
|||
}
|
||||
byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
if (urlConnection.startsWith("https://")) {
|
||||
if (proxy != null)
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
else
|
||||
|
@ -1193,52 +852,6 @@ public class HttpsConnection {
|
|||
}
|
||||
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);
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if (token != null && token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
||||
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
httpURLConnection.setRequestMethod("DELETE");
|
||||
httpURLConnection.setConnectTimeout(timeout * 1000);
|
||||
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||
|
||||
httpURLConnection.getOutputStream().write(postDataBytes);
|
||||
|
||||
|
||||
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
||||
getSinceMaxId();
|
||||
httpURLConnection.getInputStream().close();
|
||||
return httpURLConnection.getResponseCode();
|
||||
} else {
|
||||
String error = null;
|
||||
if (httpURLConnection.getErrorStream() != null) {
|
||||
InputStream stream = httpURLConnection.getErrorStream();
|
||||
if (stream == null) {
|
||||
stream = httpURLConnection.getInputStream();
|
||||
}
|
||||
try (Scanner scanner = new Scanner(stream)) {
|
||||
scanner.useDelimiter("\\Z");
|
||||
if (scanner.hasNext()) {
|
||||
error = scanner.next();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
int responseCode = httpURLConnection.getResponseCode();
|
||||
try {
|
||||
httpURLConnection.getInputStream().close();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
throw new HttpsConnectionException(responseCode, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getSince_id() {
|
||||
|
@ -1251,9 +864,7 @@ public class HttpsConnection {
|
|||
|
||||
|
||||
private void getSinceMaxId() {
|
||||
if (Helper.getLiveInstanceWithProtocol(context) == null)
|
||||
return;
|
||||
if (Helper.getLiveInstanceWithProtocol(context).startsWith("https://")) {
|
||||
|
||||
if (httpsURLConnection == null)
|
||||
return;
|
||||
Map<String, List<String>> map = httpsURLConnection.getHeaderFields();
|
||||
|
@ -1281,28 +892,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) {
|
||||
|
@ -1311,19 +900,11 @@ public class HttpsConnection {
|
|||
}
|
||||
|
||||
int getActionCode() {
|
||||
if (Helper.getLiveInstanceWithProtocol(context).startsWith("https://")) {
|
||||
try {
|
||||
return httpsURLConnection.getResponseCode();
|
||||
} catch (IOException e) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return httpURLConnection.getResponseCode();
|
||||
} catch (IOException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1975,7 +1975,7 @@ public class PeertubeAPI {
|
|||
|
||||
|
||||
private String getAbsoluteUrl(String action) {
|
||||
return Helper.instanceWithProtocol(this.instance) + "/api/v1" + action;
|
||||
return Helper.instanceWithProtocol(context) + "/api/v1" + action;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package app.fedilab.fedilabtube.helper;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
|
@ -159,14 +160,14 @@ public class Helper {
|
|||
public static final String SET_EMBEDDED_BROWSER = "set_embedded_browser";
|
||||
public static final String SET_CUSTOM_TABS = "set_custom_tabs";
|
||||
public static final String SET_DISPLAY_CONFIRM = "set_display_confirm";
|
||||
|
||||
public static final String INTENT_ADD_UPLOADED_MEDIA = "intent_add_uploaded_media";
|
||||
/**
|
||||
* Returns the peertube URL depending of the academic domain name
|
||||
* @param acad String academic domain name
|
||||
* @return String the peertube URL
|
||||
*/
|
||||
public static String getPeertubeUrl(String acad) {
|
||||
return "https://tube-"+acad.replace("ac\\-|\\.fr","")+".beta.education.fr/";
|
||||
private static String getPeertubeUrl(String acad) {
|
||||
return "tube-"+acad.replaceAll("ac-|\\.fr","")+".beta.education.fr";
|
||||
}
|
||||
|
||||
|
||||
|
@ -178,19 +179,13 @@ public class Helper {
|
|||
*/
|
||||
public static String getLiveInstance(Context context) {
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
return sharedpreferences.getString(Helper.PREF_INSTANCE, null);
|
||||
String acad = sharedpreferences.getString(Helper.PREF_INSTANCE, "ac-lyon.fr");
|
||||
return getPeertubeUrl(acad);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String getLiveInstanceWithProtocol(Context context) {
|
||||
return instanceWithProtocol(getLiveInstance(context));
|
||||
}
|
||||
|
||||
|
||||
public static String instanceWithProtocol(String instance) {
|
||||
if (instance == null)
|
||||
return null;
|
||||
return "https://" + instance;
|
||||
public static String instanceWithProtocol(Context context) {
|
||||
return "https://"+getLiveInstance(context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -349,15 +344,11 @@ public class Helper {
|
|||
|
||||
|
||||
public static void loadGiF(final Context context, Account account, final ImageView imageView) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
||||
String url = account.getAvatar();
|
||||
if (url != null && url.startsWith("/")) {
|
||||
url = Helper.getLiveInstanceWithProtocol(context) + url;
|
||||
url = Helper.getLiveInstance(context) + url;
|
||||
}
|
||||
|
||||
|
||||
|
||||
try {
|
||||
Glide.with(imageView.getContext())
|
||||
.asDrawable()
|
||||
|
@ -426,6 +417,7 @@ public class Helper {
|
|||
}
|
||||
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
public static CustomWebview initializeWebview(Activity activity, int webviewId, View rootView) {
|
||||
|
||||
CustomWebview webView;
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package app.fedilab.fedilabtube.services;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import net.gotev.uploadservice.ServerResponse;
|
||||
import net.gotev.uploadservice.UploadInfo;
|
||||
import net.gotev.uploadservice.UploadServiceBroadcastReceiver;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
|
||||
|
||||
public class PeertubeUploadReceiver extends UploadServiceBroadcastReceiver {
|
||||
|
||||
|
||||
@Override
|
||||
public void onProgress(Context context, UploadInfo uploadInfo) {
|
||||
// your code here
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse,
|
||||
Exception exception) {
|
||||
// your code here
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
|
||||
try {
|
||||
JSONObject response = new JSONObject(serverResponse.getBodyAsString());
|
||||
|
||||
if (!response.has("video")) { //IT's not from Peertube
|
||||
ArrayList<String> file = uploadInfo.getSuccessfullyUploadedFiles();
|
||||
Intent addMedia = new Intent(Helper.INTENT_ADD_UPLOADED_MEDIA);
|
||||
addMedia.putExtra("response", serverResponse.getBodyAsString());
|
||||
addMedia.putStringArrayListExtra("uploadInfo", file);
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(addMedia);
|
||||
} else {
|
||||
String videoID = response.getJSONObject("video").get("id").toString();
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.VIDEO_ID, videoID);
|
||||
editor.commit();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled(Context context, UploadInfo uploadInfo) {
|
||||
// your code here
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@
|
|||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:menu="@menu/bottom_nav_menu" />
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
<fragment
|
||||
android:id="@+id/nav_host_fragment"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
tools:layout="@layout/fragment_video" >
|
||||
<argument
|
||||
android:name="type"
|
||||
app:argType="app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask.Type"
|
||||
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type"
|
||||
android:defaultValue="PLOCAL"/>
|
||||
</fragment>
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
|||
tools:layout="@layout/fragment_video">
|
||||
<argument
|
||||
android:name="type"
|
||||
app:argType="app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask.Type"
|
||||
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type"
|
||||
android:defaultValue="PRECENTLYADDED"/>
|
||||
</fragment>
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
|||
tools:layout="@layout/fragment_video">
|
||||
<argument
|
||||
android:name="type"
|
||||
app:argType="app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask.Type"
|
||||
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type"
|
||||
android:defaultValue="PMOSTLIKED"/>
|
||||
</fragment>
|
||||
|
||||
|
@ -45,7 +45,7 @@
|
|||
tools:layout="@layout/fragment_video">
|
||||
<argument
|
||||
android:name="type"
|
||||
app:argType="app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask.Type"
|
||||
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type"
|
||||
android:defaultValue="PTRENDING"/>
|
||||
</fragment>
|
||||
|
||||
|
@ -56,7 +56,7 @@
|
|||
tools:layout="@layout/fragment_video">
|
||||
<argument
|
||||
android:name="type"
|
||||
app:argType="app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask.Type"
|
||||
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type"
|
||||
android:defaultValue="PPUBLIC"/>
|
||||
</fragment>
|
||||
|
||||
|
|
Loading…
Reference in New Issue