Upload
This commit is contained in:
parent
6689a9c3b4
commit
f7bb3ea9d9
|
@ -69,6 +69,11 @@
|
|||
android:configChanges="orientation|screenSize"
|
||||
android:label="@string/app_name"
|
||||
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||
<activity
|
||||
android:name=".PeertubeUploadActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:label="@string/app_name"
|
||||
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||
<receiver
|
||||
android:name=".services.PeertubeUploadReceiver"
|
||||
android:exported="false">
|
||||
|
|
|
@ -51,6 +51,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main_menu, menu);
|
||||
|
||||
MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
|
||||
SearchView searchView = (SearchView) myActionMenuItem.getActionView();
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
|
@ -73,6 +74,14 @@ public class MainActivity extends AppCompatActivity {
|
|||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
MenuItem uploadItem = menu.findItem(R.id.action_upload);
|
||||
if( Helper.isLoggedIn(MainActivity.this)) {
|
||||
uploadItem.setVisible(true);
|
||||
}else{
|
||||
uploadItem.setVisible(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -87,7 +96,11 @@ public class MainActivity extends AppCompatActivity {
|
|||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (item.getItemId() == R.id.action_upload) {
|
||||
Intent intent = new Intent(MainActivity.this, PeertubeUploadActivity.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,6 @@ import es.dmoral.toasty.Toasty;
|
|||
|
||||
import static app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask.action.GET_PLAYLIST;
|
||||
import static app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask.action.GET_PLAYLIST_FOR_VIDEO;
|
||||
import static app.fedilab.fedilabtube.helper.Helper.changeDrawableColor;
|
||||
import static app.fedilab.fedilabtube.helper.Helper.getAttColor;
|
||||
import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
|
||||
|
||||
|
@ -209,8 +208,6 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
peertube_information_container.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
String user_agent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT);
|
||||
webview_video.getSettings().setUserAgentString(user_agent);
|
||||
webview_video.getSettings().setAllowFileAccess(true);
|
||||
webview_video.setWebChromeClient(mastalabWebChromeClient);
|
||||
webview_video.getSettings().setDomStorageEnabled(true);
|
||||
|
@ -515,12 +512,11 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
|
||||
if (mode == Helper.VIDEO_MODE_DIRECT) {
|
||||
|
||||
String userAgent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT);
|
||||
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
||||
ProgressiveMediaSource videoSource;
|
||||
if (video_cache == 0) {
|
||||
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
|
||||
Util.getUserAgent(PeertubeActivity.this, userAgent), null);
|
||||
Util.getUserAgent(PeertubeActivity.this, null), null);
|
||||
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
|
||||
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, apiResponse.getPeertubes().get(0).isStreamService())));
|
||||
} else {
|
||||
|
@ -698,12 +694,11 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this);
|
||||
playerView.setPlayer(player);
|
||||
loader.setVisibility(View.GONE);
|
||||
String userAgent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT);
|
||||
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
||||
ProgressiveMediaSource videoSource;
|
||||
if (video_cache == 0) {
|
||||
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
|
||||
Util.getUserAgent(PeertubeActivity.this, userAgent), null);
|
||||
Util.getUserAgent(PeertubeActivity.this, null), null);
|
||||
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
|
||||
.createMediaSource(Uri.parse(peertube.getFileUrl(res, peertube.isStreamService())));
|
||||
} else {
|
||||
|
|
|
@ -14,20 +14,16 @@ import android.net.Uri;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
@ -84,18 +80,7 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri
|
|||
|
||||
if (getSupportActionBar() != null)
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
assert inflater != null;
|
||||
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(PeertubeUploadActivity.this), false);
|
||||
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
|
||||
TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
|
||||
toolbar_close.setOnClickListener(v -> finish());
|
||||
toolbar_title.setText(R.string.upload_video);
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_peertube_upload);
|
||||
|
||||
set_upload_file = findViewById(R.id.set_upload_file);
|
||||
|
@ -113,7 +98,6 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
@ -162,6 +146,16 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeComments(APIResponse apiResponse) {
|
||||
|
||||
|
@ -261,18 +255,10 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri
|
|||
}
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
|
||||
intent.setType("*/*");
|
||||
String[] mimetypes = {"video/*"};
|
||||
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
|
||||
startActivityForResult(intent, PICK_IVDEO);
|
||||
} else {
|
||||
intent.setType("video/*");
|
||||
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.toot_select_image));
|
||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
|
||||
startActivityForResult(chooserIntent, PICK_IVDEO);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -37,6 +37,9 @@ public class RetrievePeertubeChannelsAsyncTask extends AsyncTask<Void, Void, Voi
|
|||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(contextReference.get()));
|
||||
Account account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, instance);
|
||||
if( account == null) {
|
||||
account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, Helper.getPeertubeUrl(instance));
|
||||
}
|
||||
apiResponse = peertubeAPI.getPeertubeChannel(account.getUsername());
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import android.os.Build;
|
|||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.gotev.uploadservice.MultipartUploadRequest;
|
||||
import net.gotev.uploadservice.ServerResponse;
|
||||
|
@ -16,7 +15,6 @@ import net.gotev.uploadservice.UploadNotificationConfig;
|
|||
import net.gotev.uploadservice.UploadStatusDelegate;
|
||||
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
@ -60,7 +58,6 @@ public class HttpsConnection {
|
|||
private int CHUNK_SIZE = 4096;
|
||||
private SharedPreferences sharedpreferences;
|
||||
private Proxy proxy;
|
||||
private String USER_AGENT;
|
||||
|
||||
|
||||
public HttpsConnection(Context context) {
|
||||
|
@ -70,7 +67,6 @@ public class HttpsConnection {
|
|||
int type = sharedpreferences.getInt(Helper.SET_PROXY_TYPE, 0);
|
||||
proxy = null;
|
||||
|
||||
USER_AGENT = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT);
|
||||
if (proxyEnabled) {
|
||||
try {
|
||||
String host = sharedpreferences.getString(Helper.SET_PROXY_HOST, "127.0.0.1");
|
||||
|
@ -144,7 +140,6 @@ public class HttpsConnection {
|
|||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
||||
httpsURLConnection.setRequestProperty("http.keepAlive", "false");
|
||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||
httpsURLConnection.setRequestProperty("Accept", "application/json");
|
||||
httpsURLConnection.setUseCaches(true);
|
||||
|
@ -187,52 +182,6 @@ public class HttpsConnection {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Will check if the current url is redirecting
|
||||
*
|
||||
* @param urlConnection String the url to check
|
||||
* @return String null|string url redirection
|
||||
*/
|
||||
public String checkUrl(String urlConnection) {
|
||||
URL url;
|
||||
String redirect = null;
|
||||
try {
|
||||
url = new URL(urlConnection);
|
||||
if (proxy != null)
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
else
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setRequestProperty("http.keepAlive", "false");
|
||||
httpsURLConnection.setInstanceFollowRedirects(false);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
httpsURLConnection.setRequestMethod("HEAD");
|
||||
if (httpsURLConnection.getResponseCode() == 301) {
|
||||
Map<String, List<String>> map = httpsURLConnection.getHeaderFields();
|
||||
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
|
||||
if (entry.toString().toLowerCase().startsWith("location")) {
|
||||
Matcher matcher = Helper.urlPattern.matcher(entry.toString());
|
||||
if (matcher.find()) {
|
||||
redirect = matcher.group(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
httpsURLConnection.getInputStream().close();
|
||||
if (redirect != null && redirect.compareTo(urlConnection) != 0) {
|
||||
URL redirectURL = new URL(redirect);
|
||||
String host = redirectURL.getHost();
|
||||
String protocol = redirectURL.getProtocol();
|
||||
if (protocol == null || host == null) {
|
||||
redirect = null;
|
||||
}
|
||||
}
|
||||
return redirect;
|
||||
} catch (IOException | NoSuchAlgorithmException | KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public String get(String urlConnection) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
|
||||
|
||||
|
@ -246,7 +195,6 @@ public class HttpsConnection {
|
|||
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());
|
||||
httpsURLConnection.setRequestMethod("GET");
|
||||
httpsURLConnection.setDefaultUseCaches(true);
|
||||
|
@ -307,7 +255,6 @@ public class HttpsConnection {
|
|||
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());
|
||||
|
@ -353,117 +300,6 @@ public class HttpsConnection {
|
|||
}
|
||||
|
||||
|
||||
String postJson(String urlConnection, int timeout, JsonObject jsonObject, String token) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
|
||||
|
||||
URL url = new URL(urlConnection);
|
||||
byte[] postDataBytes;
|
||||
postDataBytes = jsonObject.toString().getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
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());
|
||||
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;
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
String postMisskey(String urlConnection, int timeout, JSONObject paramaters, String token) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
|
||||
URL url = new URL(urlConnection);
|
||||
byte[] postDataBytes = paramaters.toString().getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
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());
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* Download method which works for http and https connections
|
||||
|
@ -480,7 +316,6 @@ public class HttpsConnection {
|
|||
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
|
||||
|
@ -546,7 +381,6 @@ public class HttpsConnection {
|
|||
else
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
int responseCode = httpsURLConnection.getResponseCode();
|
||||
// always check HTTP response code first
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
|
@ -649,15 +483,9 @@ public class HttpsConnection {
|
|||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
else
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
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 "))
|
||||
|
@ -734,7 +562,6 @@ public class HttpsConnection {
|
|||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
else
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
|
@ -806,7 +633,6 @@ public class HttpsConnection {
|
|||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
else
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
|
|
|
@ -33,9 +33,6 @@ import app.fedilab.fedilabtube.client.entities.Account;
|
|||
import app.fedilab.fedilabtube.client.entities.AccountCreation;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
import app.fedilab.fedilabtube.client.entities.Instance;
|
||||
import app.fedilab.fedilabtube.client.entities.InstanceNodeInfo;
|
||||
import app.fedilab.fedilabtube.client.entities.InstanceReg;
|
||||
import app.fedilab.fedilabtube.client.entities.NodeInfo;
|
||||
import app.fedilab.fedilabtube.client.entities.Peertube;
|
||||
import app.fedilab.fedilabtube.client.entities.PeertubeAccountNotification;
|
||||
import app.fedilab.fedilabtube.client.entities.PeertubeActorFollow;
|
||||
|
@ -462,7 +459,7 @@ public class PeertubeAPI {
|
|||
* @param resobj JSONObject
|
||||
* @return Peertube
|
||||
*/
|
||||
private static List<Status> parseSinglePeertubeComments(Context context, String instance, JSONObject resobj) {
|
||||
private static List<Status> parseSinglePeertubeComments(String instance, JSONObject resobj) {
|
||||
List<Status> statuses = new ArrayList<>();
|
||||
try {
|
||||
JSONArray jsonArray = resobj.getJSONArray("data");
|
||||
|
@ -761,100 +758,6 @@ public class PeertubeAPI {
|
|||
return account;
|
||||
}
|
||||
|
||||
public InstanceNodeInfo displayNodeInfo(String domain) {
|
||||
|
||||
String response;
|
||||
InstanceNodeInfo instanceNodeInfo = new InstanceNodeInfo();
|
||||
if (domain.startsWith("http://")) {
|
||||
domain = domain.replace("http://", "");
|
||||
}
|
||||
if (domain.startsWith("https://")) {
|
||||
domain = domain.replace("https://", "");
|
||||
}
|
||||
try {
|
||||
response = new HttpsConnection(context).get("https://" + domain + "/.well-known/nodeinfo", 30, null, null);
|
||||
JSONArray jsonArray = new JSONObject(response).getJSONArray("links");
|
||||
ArrayList<NodeInfo> nodeInfos = new ArrayList<>();
|
||||
try {
|
||||
int i = 0;
|
||||
while (i < jsonArray.length()) {
|
||||
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
NodeInfo nodeInfo = new NodeInfo();
|
||||
nodeInfo.setHref(resobj.getString("href"));
|
||||
nodeInfo.setRel(resobj.getString("rel"));
|
||||
i++;
|
||||
nodeInfos.add(nodeInfo);
|
||||
}
|
||||
if (nodeInfos.size() > 0) {
|
||||
NodeInfo nodeInfo = nodeInfos.get(nodeInfos.size() - 1);
|
||||
response = new HttpsConnection(context).get(nodeInfo.getHref(), 30, null, null);
|
||||
JSONObject resobj = new JSONObject(response);
|
||||
JSONObject jsonObject = resobj.getJSONObject("software");
|
||||
String name = jsonObject.getString("name").toUpperCase();
|
||||
if (name.compareTo("CORGIDON") == 0) {
|
||||
name = "MASTODON";
|
||||
}
|
||||
instanceNodeInfo.setName(name);
|
||||
instanceNodeInfo.setVersion(jsonObject.getString("version"));
|
||||
instanceNodeInfo.setOpenRegistrations(resobj.getBoolean("openRegistrations"));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IOException | JSONException | NoSuchAlgorithmException | KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
response = new HttpsConnection(context).get("https://" + domain + "/api/v1/instance", 30, null, null);
|
||||
JSONObject jsonObject = new JSONObject(response);
|
||||
instanceNodeInfo.setName("MASTODON");
|
||||
instanceNodeInfo.setVersion(jsonObject.getString("version"));
|
||||
instanceNodeInfo.setOpenRegistrations(true);
|
||||
} catch (IOException e1) {
|
||||
instanceNodeInfo.setConnectionError(true);
|
||||
e1.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException | JSONException | KeyManagementException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (HttpsConnection.HttpsConnectionException e1) {
|
||||
if (e1.getStatusCode() == 404 || e1.getStatusCode() == 501) {
|
||||
instanceNodeInfo.setName("GNU");
|
||||
instanceNodeInfo.setVersion("unknown");
|
||||
instanceNodeInfo.setOpenRegistrations(true);
|
||||
e1.printStackTrace();
|
||||
} else {
|
||||
instanceNodeInfo.setName("MASTODON");
|
||||
instanceNodeInfo.setVersion("3.0");
|
||||
instanceNodeInfo.setOpenRegistrations(false);
|
||||
}
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
try {
|
||||
response = new HttpsConnection(context).get("https://" + domain + "/api/v1/instance", 30, null, null);
|
||||
JSONObject jsonObject = new JSONObject(response);
|
||||
instanceNodeInfo.setName("MASTODON");
|
||||
instanceNodeInfo.setVersion(jsonObject.getString("version"));
|
||||
instanceNodeInfo.setOpenRegistrations(true);
|
||||
} catch (IOException e1) {
|
||||
instanceNodeInfo.setConnectionError(true);
|
||||
e1.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException | JSONException | KeyManagementException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (HttpsConnection.HttpsConnectionException e1) {
|
||||
if (e1.getStatusCode() == 404 || e1.getStatusCode() == 501) {
|
||||
instanceNodeInfo.setName("GNU");
|
||||
instanceNodeInfo.setVersion("unknown");
|
||||
instanceNodeInfo.setOpenRegistrations(true);
|
||||
e1.printStackTrace();
|
||||
} else {
|
||||
instanceNodeInfo.setName("MASTODON");
|
||||
instanceNodeInfo.setVersion("3.0");
|
||||
instanceNodeInfo.setOpenRegistrations(false);
|
||||
}
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
return instanceNodeInfo;
|
||||
}
|
||||
|
||||
public APIResponse createAccount(AccountCreation accountCreation) {
|
||||
apiResponse = new APIResponse();
|
||||
|
@ -1721,7 +1624,7 @@ public class PeertubeAPI {
|
|||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(String.format("https://" + instance + "/api/v1/videos/%s/comment-threads", videoId), 10, null, null);
|
||||
JSONObject jsonObject = new JSONObject(response);
|
||||
statuses = parseSinglePeertubeComments(context, instance, jsonObject);
|
||||
statuses = parseSinglePeertubeComments(instance, jsonObject);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||
|
@ -1788,54 +1691,6 @@ public class PeertubeAPI {
|
|||
return peertubeNotifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response for several instance reg
|
||||
*
|
||||
* @param jsonArray JSONArray
|
||||
* @return List<Status>
|
||||
*/
|
||||
private List<InstanceReg> parseInstanceReg(JSONArray jsonArray) {
|
||||
|
||||
List<InstanceReg> instanceRegs = new ArrayList<>();
|
||||
try {
|
||||
int i = 0;
|
||||
while (i < jsonArray.length()) {
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
InstanceReg instanceReg = parseInstanceReg(resobj);
|
||||
i++;
|
||||
instanceRegs.add(instanceReg);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return instanceRegs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response an unique instance for registering
|
||||
*
|
||||
* @param resobj JSONObject
|
||||
* @return InstanceReg
|
||||
*/
|
||||
private InstanceReg parseInstanceReg(JSONObject resobj) {
|
||||
InstanceReg instanceReg = new InstanceReg();
|
||||
try {
|
||||
instanceReg.setDomain(resobj.getString("host"));
|
||||
instanceReg.setVersion(resobj.getString("version"));
|
||||
instanceReg.setDescription(resobj.getString("shortDescription"));
|
||||
instanceReg.setLanguage(resobj.getString("country"));
|
||||
instanceReg.setCategory("");
|
||||
instanceReg.setProxied_thumbnail("");
|
||||
instanceReg.setTotal_users(resobj.getInt("totalUsers"));
|
||||
instanceReg.setTotalInstanceFollowers(resobj.getInt("totalInstanceFollowers"));
|
||||
instanceReg.setTotalInstanceFollowing(resobj.getInt("totalInstanceFollowing"));
|
||||
instanceReg.setLast_week_users(0);
|
||||
instanceReg.setCountry(resobj.getString("country"));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return instanceReg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response for several howto
|
||||
|
|
|
@ -28,12 +28,11 @@ public class CacheDataSourceFactory implements DataSource.Factory {
|
|||
this.context = context;
|
||||
this.maxFileSize = 5 * 1024 * 1024;
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userAgent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT);
|
||||
DefaultBandwidthMeter.Builder bandwidthMeterBuilder = new DefaultBandwidthMeter.Builder(context);
|
||||
DefaultBandwidthMeter bandwidthMeter = bandwidthMeterBuilder.build();
|
||||
defaultDatasourceFactory = new DefaultDataSourceFactory(this.context,
|
||||
bandwidthMeter,
|
||||
new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter));
|
||||
new DefaultHttpDataSourceFactory(null, bandwidthMeter));
|
||||
}
|
||||
|
||||
public static SimpleCache getInstance(Context context) {
|
||||
|
|
|
@ -13,7 +13,6 @@ import android.graphics.Color;
|
|||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
|
@ -78,7 +77,6 @@ public class Helper {
|
|||
public static final Pattern hashtagPattern = Pattern.compile("(#[\\w_A-zÀ-ÿ]+)");
|
||||
public static final String SET_CUSTOM_USER_AGENT = "set_custom_user_agent";
|
||||
public static final String SET_VIDEO_CACHE = "set_video_cache";
|
||||
public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0";
|
||||
//Proxy
|
||||
public static final String SET_PROXY_ENABLED = "set_proxy_enabled";
|
||||
public static final String SET_PROXY_TYPE = "set_proxy_type";
|
||||
|
@ -493,8 +491,6 @@ public class Helper {
|
|||
webView.getSettings().setLoadsImagesAutomatically(true);
|
||||
webView.getSettings().setSupportMultipleWindows(false);
|
||||
webView.getSettings().setMediaPlaybackRequiresUserGesture(true);
|
||||
String user_agent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT);
|
||||
webView.getSettings().setUserAgentString(user_agent);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
CookieManager cookieManager = CookieManager.getInstance();
|
||||
cookieManager.setAcceptThirdPartyCookies(webView, false);
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
android:id="@+id/login_uid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/username"
|
||||
android:hint="@string/email_address"
|
||||
android:inputType="textEmailAddress"
|
||||
android:singleLine="true" />
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -9,7 +8,7 @@
|
|||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="50dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
|
@ -82,12 +81,14 @@
|
|||
|
||||
<EditText
|
||||
android:id="@+id/video_title"
|
||||
android:layout_width="250dp"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:hint="@string/title_video_peertube"
|
||||
android:inputType="text"
|
||||
android:singleLine="true" />
|
||||
android:singleLine="true"
|
||||
android:layout_gravity="center"
|
||||
android:importantForAutofill="no" />
|
||||
|
||||
<!-- Videos upload submit -->
|
||||
<Button
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
android:icon="@drawable/ic_baseline_add_circle_outline_24"
|
||||
android:title="@string/title_recently_added" />
|
||||
|
||||
|
||||
<item
|
||||
android:id="@+id/navigation_home"
|
||||
android:icon="@drawable/ic_home_black_24dp"
|
||||
|
|
|
@ -21,4 +21,9 @@
|
|||
android:icon="@drawable/ic_outline_account_circle_24"
|
||||
android:title="@string/account"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/action_upload"
|
||||
android:icon="@drawable/ic_baseline_cloud_upload_24"
|
||||
android:title="@string/upload_video"
|
||||
app:showAsAction="ifRoom" />
|
||||
</menu>
|
||||
|
|
|
@ -119,6 +119,7 @@
|
|||
|
||||
<string name="join_peertube">Rejoignez Peertube</string>
|
||||
<string name="username">Nom d’utilisateur</string>
|
||||
<string name="email_address">Adresse mèl</string>
|
||||
<string name="password">Mot de passe</string>
|
||||
<string name="add_account">Ajouter un compte</string>
|
||||
<string name="login">Connexion</string>
|
||||
|
|
Loading…
Reference in New Issue