mirror of
https://framagit.org/tom79/fedilab-tube
synced 2025-04-22 06:17:18 +02:00
some changes
This commit is contained in:
parent
51860ff399
commit
c30e2d6a40
@ -15,7 +15,9 @@ android {
|
|||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
dexOptions {
|
||||||
|
javaMaxHeapSize "4g"
|
||||||
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
minifyEnabled false
|
minifyEnabled false
|
||||||
@ -53,6 +55,7 @@ dependencies {
|
|||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
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.github.GrenderG:Toasty:1.4.2'
|
||||||
implementation 'com.google.android.exoplayer:exoplayer:2.10.6'
|
implementation 'com.google.android.exoplayer:exoplayer:2.10.6'
|
||||||
implementation "com.github.mabbas007:TagsEditText:1.0.5"
|
implementation "com.github.mabbas007:TagsEditText:1.0.5"
|
||||||
|
@ -28,6 +28,25 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</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>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -9,6 +9,9 @@ public class FedilabTupe extends MultiDexApplication {
|
|||||||
@Override
|
@Override
|
||||||
protected void attachBaseContext(Context base) {
|
protected void attachBaseContext(Context base) {
|
||||||
super.attachBaseContext(base);
|
super.attachBaseContext(base);
|
||||||
MultiDex.install(this);
|
|
||||||
|
MultiDex.install(FedilabTupe.this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -56,7 +56,6 @@ public class HttpsConnection {
|
|||||||
|
|
||||||
|
|
||||||
private HttpsURLConnection httpsURLConnection;
|
private HttpsURLConnection httpsURLConnection;
|
||||||
private HttpURLConnection httpURLConnection;
|
|
||||||
private String since_id, max_id;
|
private String since_id, max_id;
|
||||||
private Context context;
|
private Context context;
|
||||||
private int CHUNK_SIZE = 4096;
|
private int CHUNK_SIZE = 4096;
|
||||||
@ -246,7 +245,6 @@ public class HttpsConnection {
|
|||||||
|
|
||||||
|
|
||||||
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);
|
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
@ -290,52 +288,6 @@ public class HttpsConnection {
|
|||||||
getSinceMaxId();
|
getSinceMaxId();
|
||||||
httpsURLConnection.getInputStream().close();
|
httpsURLConnection.getInputStream().close();
|
||||||
return response;
|
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());
|
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);
|
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
@ -406,54 +357,6 @@ public class HttpsConnection {
|
|||||||
getSinceMaxId();
|
getSinceMaxId();
|
||||||
httpsURLConnection.getInputStream().close();
|
httpsURLConnection.getInputStream().close();
|
||||||
return response;
|
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);
|
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)
|
if (proxy != null)
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
@ -513,54 +415,6 @@ public class HttpsConnection {
|
|||||||
getSinceMaxId();
|
getSinceMaxId();
|
||||||
httpsURLConnection.getInputStream().close();
|
httpsURLConnection.getInputStream().close();
|
||||||
return response;
|
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")
|
@SuppressWarnings("SameParameterValue")
|
||||||
@ -627,8 +481,6 @@ public class HttpsConnection {
|
|||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
URL url;
|
URL url;
|
||||||
HttpsURLConnection httpsURLConnection;
|
HttpsURLConnection httpsURLConnection;
|
||||||
HttpURLConnection httpURLConnection;
|
|
||||||
if (downloadUrl.startsWith("https://")) {
|
|
||||||
try {
|
try {
|
||||||
url = new URL(downloadUrl);
|
url = new URL(downloadUrl);
|
||||||
if (proxy != null)
|
if (proxy != null)
|
||||||
@ -683,64 +535,6 @@ public class HttpsConnection {
|
|||||||
Error error = new Error();
|
Error error = new Error();
|
||||||
error.setError(context.getString(R.string.toast_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();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -753,7 +547,6 @@ 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);
|
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
@ -775,28 +568,6 @@ public class HttpsConnection {
|
|||||||
httpsURLConnection.getInputStream().close();
|
httpsURLConnection.getInputStream().close();
|
||||||
} catch (Exception ignored) {
|
} 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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -881,7 +652,6 @@ 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);
|
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
@ -943,66 +713,6 @@ public class HttpsConnection {
|
|||||||
}
|
}
|
||||||
httpsURLConnection.getInputStream().close();
|
httpsURLConnection.getInputStream().close();
|
||||||
return response;
|
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);
|
byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
if (urlConnection.startsWith("https://")) {
|
|
||||||
if (proxy != null)
|
if (proxy != null)
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
@ -1076,55 +785,6 @@ public class HttpsConnection {
|
|||||||
getSinceMaxId();
|
getSinceMaxId();
|
||||||
httpsURLConnection.getInputStream().close();
|
httpsURLConnection.getInputStream().close();
|
||||||
return response;
|
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);
|
byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
if (urlConnection.startsWith("https://")) {
|
|
||||||
if (proxy != null)
|
if (proxy != null)
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
@ -1193,52 +852,6 @@ public class HttpsConnection {
|
|||||||
}
|
}
|
||||||
throw new HttpsConnectionException(responseCode, error);
|
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() {
|
public String getSince_id() {
|
||||||
@ -1251,9 +864,7 @@ public class HttpsConnection {
|
|||||||
|
|
||||||
|
|
||||||
private void getSinceMaxId() {
|
private void getSinceMaxId() {
|
||||||
if (Helper.getLiveInstanceWithProtocol(context) == null)
|
|
||||||
return;
|
|
||||||
if (Helper.getLiveInstanceWithProtocol(context).startsWith("https://")) {
|
|
||||||
if (httpsURLConnection == null)
|
if (httpsURLConnection == null)
|
||||||
return;
|
return;
|
||||||
Map<String, List<String>> map = httpsURLConnection.getHeaderFields();
|
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) {
|
private String converToString(InputStream inputStream) {
|
||||||
@ -1311,19 +900,11 @@ public class HttpsConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int getActionCode() {
|
int getActionCode() {
|
||||||
if (Helper.getLiveInstanceWithProtocol(context).startsWith("https://")) {
|
|
||||||
try {
|
try {
|
||||||
return httpsURLConnection.getResponseCode();
|
return httpsURLConnection.getResponseCode();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
return httpURLConnection.getResponseCode();
|
|
||||||
} catch (IOException e) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1975,7 +1975,7 @@ public class PeertubeAPI {
|
|||||||
|
|
||||||
|
|
||||||
private String getAbsoluteUrl(String action) {
|
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;
|
package app.fedilab.fedilabtube.helper;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.DownloadManager;
|
import android.app.DownloadManager;
|
||||||
import android.content.Context;
|
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_EMBEDDED_BROWSER = "set_embedded_browser";
|
||||||
public static final String SET_CUSTOM_TABS = "set_custom_tabs";
|
public static final String SET_CUSTOM_TABS = "set_custom_tabs";
|
||||||
public static final String SET_DISPLAY_CONFIRM = "set_display_confirm";
|
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
|
* Returns the peertube URL depending of the academic domain name
|
||||||
* @param acad String academic domain name
|
* @param acad String academic domain name
|
||||||
* @return String the peertube URL
|
* @return String the peertube URL
|
||||||
*/
|
*/
|
||||||
public static String getPeertubeUrl(String acad) {
|
private static String getPeertubeUrl(String acad) {
|
||||||
return "https://tube-"+acad.replace("ac\\-|\\.fr","")+".beta.education.fr/";
|
return "tube-"+acad.replaceAll("ac-|\\.fr","")+".beta.education.fr";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -178,19 +179,13 @@ public class Helper {
|
|||||||
*/
|
*/
|
||||||
public static String getLiveInstance(Context context) {
|
public static String getLiveInstance(Context context) {
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
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 instanceWithProtocol(Context context) {
|
||||||
public static String getLiveInstanceWithProtocol(Context context) {
|
return "https://"+getLiveInstance(context);
|
||||||
return instanceWithProtocol(getLiveInstance(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static String instanceWithProtocol(String instance) {
|
|
||||||
if (instance == null)
|
|
||||||
return null;
|
|
||||||
return "https://" + instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -349,15 +344,11 @@ public class Helper {
|
|||||||
|
|
||||||
|
|
||||||
public static void loadGiF(final Context context, Account account, final ImageView imageView) {
|
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();
|
String url = account.getAvatar();
|
||||||
if (url != null && url.startsWith("/")) {
|
if (url != null && url.startsWith("/")) {
|
||||||
url = Helper.getLiveInstanceWithProtocol(context) + url;
|
url = Helper.getLiveInstance(context) + url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Glide.with(imageView.getContext())
|
Glide.with(imageView.getContext())
|
||||||
.asDrawable()
|
.asDrawable()
|
||||||
@ -426,6 +417,7 @@ public class Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
public static CustomWebview initializeWebview(Activity activity, int webviewId, View rootView) {
|
public static CustomWebview initializeWebview(Activity activity, int webviewId, View rootView) {
|
||||||
|
|
||||||
CustomWebview webView;
|
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:layout_constraintRight_toRightOf="parent"
|
||||||
app:menu="@menu/bottom_nav_menu" />
|
app:menu="@menu/bottom_nav_menu" />
|
||||||
|
|
||||||
<androidx.fragment.app.FragmentContainerView
|
<fragment
|
||||||
android:id="@+id/nav_host_fragment"
|
android:id="@+id/nav_host_fragment"
|
||||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
tools:layout="@layout/fragment_video" >
|
tools:layout="@layout/fragment_video" >
|
||||||
<argument
|
<argument
|
||||||
android:name="type"
|
android:name="type"
|
||||||
app:argType="app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask.Type"
|
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type"
|
||||||
android:defaultValue="PLOCAL"/>
|
android:defaultValue="PLOCAL"/>
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
@ -23,7 +23,7 @@
|
|||||||
tools:layout="@layout/fragment_video">
|
tools:layout="@layout/fragment_video">
|
||||||
<argument
|
<argument
|
||||||
android:name="type"
|
android:name="type"
|
||||||
app:argType="app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask.Type"
|
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type"
|
||||||
android:defaultValue="PRECENTLYADDED"/>
|
android:defaultValue="PRECENTLYADDED"/>
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
@ -34,7 +34,7 @@
|
|||||||
tools:layout="@layout/fragment_video">
|
tools:layout="@layout/fragment_video">
|
||||||
<argument
|
<argument
|
||||||
android:name="type"
|
android:name="type"
|
||||||
app:argType="app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask.Type"
|
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type"
|
||||||
android:defaultValue="PMOSTLIKED"/>
|
android:defaultValue="PMOSTLIKED"/>
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
@ -45,7 +45,7 @@
|
|||||||
tools:layout="@layout/fragment_video">
|
tools:layout="@layout/fragment_video">
|
||||||
<argument
|
<argument
|
||||||
android:name="type"
|
android:name="type"
|
||||||
app:argType="app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask.Type"
|
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type"
|
||||||
android:defaultValue="PTRENDING"/>
|
android:defaultValue="PTRENDING"/>
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
@ -56,7 +56,7 @@
|
|||||||
tools:layout="@layout/fragment_video">
|
tools:layout="@layout/fragment_video">
|
||||||
<argument
|
<argument
|
||||||
android:name="type"
|
android:name="type"
|
||||||
app:argType="app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask.Type"
|
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type"
|
||||||
android:defaultValue="PPUBLIC"/>
|
android:defaultValue="PPUBLIC"/>
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user