Simplify login
This commit is contained in:
parent
bd6d0bdd3f
commit
689e16bf62
|
@ -8,14 +8,9 @@ import android.text.SpannableString;
|
|||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.UnderlineSpan;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -26,9 +21,8 @@ import org.json.JSONException;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import app.fedilab.fedilabtube.asynctasks.UpdateAccountInfoAsyncTask;
|
||||
|
@ -42,13 +36,10 @@ public class LoginActivity extends AppCompatActivity {
|
|||
|
||||
private static String client_id;
|
||||
private static String client_secret;
|
||||
private static String instance;
|
||||
private static String host;
|
||||
private EditText login_uid;
|
||||
private EditText login_passwd;
|
||||
private Button connectionButton;
|
||||
private String actionToken;
|
||||
private Spinner info_instance;
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -63,11 +54,15 @@ public class LoginActivity extends AppCompatActivity {
|
|||
TextView create_an_account_peertube = findViewById(R.id.create_an_account_peertube);
|
||||
|
||||
|
||||
SpannableString content_create = new SpannableString(getString(R.string.join_peertube));
|
||||
content_create.setSpan(new UnderlineSpan(), 0, content_create.length(), 0);
|
||||
content_create.setSpan(new ForegroundColorSpan(ContextCompat.getColor(LoginActivity.this, R.color.colorAccent)), 0, content_create.length(),
|
||||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
create_an_account_peertube.setText(content_create);
|
||||
|
||||
create_an_account_peertube.setOnClickListener(v -> {
|
||||
Intent mainActivity = new Intent(LoginActivity.this, PeertubeRegisterActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putString("instance", host);
|
||||
mainActivity.putExtras(b);
|
||||
startActivity(mainActivity);
|
||||
});
|
||||
|
@ -76,169 +71,128 @@ public class LoginActivity extends AppCompatActivity {
|
|||
login_uid = findViewById(R.id.login_uid);
|
||||
login_passwd = findViewById(R.id.login_passwd);
|
||||
connectionButton = findViewById(R.id.login_button);
|
||||
info_instance = findViewById(R.id.info_instance);
|
||||
|
||||
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, Helper.academies);
|
||||
info_instance.setAdapter(arrayAdapter);
|
||||
|
||||
info_instance.setSelection(0);
|
||||
info_instance.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
host = Helper.academies[position];
|
||||
SpannableString content_create = new SpannableString(getString(R.string.join_peertube_on, host));
|
||||
content_create.setSpan(new UnderlineSpan(), 0, content_create.length(), 0);
|
||||
content_create.setSpan(new ForegroundColorSpan(ContextCompat.getColor(LoginActivity.this, R.color.colorAccent)), 0, content_create.length(),
|
||||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
create_an_account_peertube.setText(content_create);
|
||||
retrievesClientId();
|
||||
connectionButton.setOnClickListener(v -> {
|
||||
|
||||
if (!android.util.Patterns.EMAIL_ADDRESS.matcher(login_uid.getText().toString().trim()).matches()) {
|
||||
Toasty.error(LoginActivity.this, getString(R.string.email_error)).show();
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
String[] emailArray = login_uid.getText().toString().split("@");
|
||||
if (emailArray.length > 1 && !Arrays.asList(Helper.valideEmails).contains(emailArray[1])) {
|
||||
Toasty.error(LoginActivity.this, getString(R.string.email_error_domain, emailArray[1])).show();
|
||||
return;
|
||||
}
|
||||
});
|
||||
String host = emailArray[1];
|
||||
String instance = Helper.getPeertubeUrl(host);
|
||||
final HashMap<String, String> parameters = new HashMap<>();
|
||||
connectionButton.setEnabled(false);
|
||||
|
||||
|
||||
connectionButton.setEnabled(false);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
retrievesClientId();
|
||||
}
|
||||
|
||||
private void retrievesClientId() {
|
||||
String instanceFromField = info_instance.getSelectedItem().toString();
|
||||
if (instanceFromField.startsWith("http://")) {
|
||||
instanceFromField = instanceFromField.replace("http://", "");
|
||||
}
|
||||
if (instanceFromField.startsWith("https://")) {
|
||||
instanceFromField = instanceFromField.replace("https://", "");
|
||||
}
|
||||
String host = instanceFromField;
|
||||
try {
|
||||
URL url = new URL(instanceFromField);
|
||||
host = url.getHost();
|
||||
} catch (MalformedURLException ignored) {
|
||||
}
|
||||
instance = Helper.getPeertubeUrl(host);
|
||||
try {
|
||||
instance = URLEncoder.encode(instance, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Toasty.error(LoginActivity.this, getString(R.string.client_error), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
actionToken = "/api/v1/oauth-clients/local";
|
||||
final HashMap<String, String> parameters = new HashMap<>();
|
||||
parameters.put(Helper.CLIENT_NAME, Helper.CLIENT_NAME_VALUE);
|
||||
parameters.put(Helper.REDIRECT_URIS, Helper.REDIRECT_CONTENT);
|
||||
parameters.put(Helper.SCOPES, Helper.OAUTH_SCOPES_PEERTUBE);
|
||||
parameters.put(Helper.WEBSITE, Helper.WEBSITE_VALUE);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
String response = new HttpsConnection(LoginActivity.this, instance).get("https://" + instance + actionToken, 30, parameters, null);
|
||||
runOnUiThread(() -> {
|
||||
instance = URLEncoder.encode(instance, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Toasty.error(LoginActivity.this, getString(R.string.client_error), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
actionToken = "/api/v1/oauth-clients/local";
|
||||
parameters.clear();
|
||||
parameters.put(Helper.CLIENT_NAME, Helper.CLIENT_NAME_VALUE);
|
||||
parameters.put(Helper.REDIRECT_URIS, Helper.REDIRECT_CONTENT);
|
||||
parameters.put(Helper.SCOPES, Helper.OAUTH_SCOPES_PEERTUBE);
|
||||
parameters.put(Helper.WEBSITE, Helper.WEBSITE_VALUE);
|
||||
String finalInstance = instance;
|
||||
new Thread(() -> {
|
||||
try {
|
||||
String response = new HttpsConnection(LoginActivity.this).get("https://" + finalInstance + actionToken, 30, parameters, null);
|
||||
JSONObject resobj;
|
||||
try {
|
||||
resobj = new JSONObject(response);
|
||||
client_id = resobj.get(Helper.CLIENT_ID).toString();
|
||||
client_secret = resobj.get(Helper.CLIENT_SECRET).toString();
|
||||
manageClient(client_id, client_secret);
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.CLIENT_ID, client_id);
|
||||
editor.putString(Helper.CLIENT_SECRET, client_secret);
|
||||
editor.apply();
|
||||
parameters.clear();
|
||||
parameters.put(Helper.CLIENT_ID, sharedpreferences.getString(Helper.CLIENT_ID, null));
|
||||
parameters.put(Helper.CLIENT_SECRET, sharedpreferences.getString(Helper.CLIENT_SECRET, null));
|
||||
parameters.put("grant_type", "password");
|
||||
try {
|
||||
parameters.put("username", URLEncoder.encode(login_uid.getText().toString().trim().toLowerCase(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
parameters.put("username", login_uid.getText().toString().trim().toLowerCase());
|
||||
}
|
||||
try {
|
||||
parameters.put("password", URLEncoder.encode(login_passwd.getText().toString(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
parameters.put("password", login_passwd.getText().toString());
|
||||
}
|
||||
parameters.put("scope", "user");
|
||||
String oauthUrl = "/api/v1/users/token";
|
||||
try {
|
||||
String responseLogin = new HttpsConnection(LoginActivity.this).post("https://" + finalInstance + oauthUrl, 30, parameters, null);
|
||||
runOnUiThread(() -> {
|
||||
JSONObject resobjLogin;
|
||||
try {
|
||||
resobjLogin = new JSONObject(responseLogin);
|
||||
String token = resobjLogin.get("access_token").toString();
|
||||
String refresh_token = null;
|
||||
if (resobjLogin.has("refresh_token"))
|
||||
refresh_token = resobjLogin.getString("refresh_token");
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
|
||||
editor.apply();
|
||||
//Update the account with the token;
|
||||
new UpdateAccountInfoAsyncTask(LoginActivity.this, token, client_id, client_secret, refresh_token, host).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
runOnUiThread(() -> connectionButton.setEnabled(true));
|
||||
}
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
runOnUiThread(() -> {
|
||||
connectionButton.setEnabled(true);
|
||||
String message;
|
||||
if (e.getLocalizedMessage() != null && e.getLocalizedMessage().trim().length() > 0)
|
||||
message = e.getLocalizedMessage();
|
||||
else if (e.getMessage() != null && e.getMessage().trim().length() > 0)
|
||||
message = e.getMessage();
|
||||
else
|
||||
message = getString(R.string.client_error);
|
||||
Toasty.error(LoginActivity.this, message, Toast.LENGTH_LONG).show();
|
||||
});
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
runOnUiThread(() -> connectionButton.setEnabled(true));
|
||||
}
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
runOnUiThread(() -> {
|
||||
|
||||
String message = null;
|
||||
if (e.getLocalizedMessage() != null) {
|
||||
message = e.getMessage();
|
||||
}
|
||||
if (message == null) {
|
||||
message = getString(R.string.client_error);
|
||||
}
|
||||
|
||||
Toasty.error(LoginActivity.this, message, Toast.LENGTH_LONG).show();
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
String finalHost = host;
|
||||
connectionButton.setOnClickListener(v -> {
|
||||
|
||||
connectionButton.setEnabled(false);
|
||||
parameters.clear();
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
parameters.put(Helper.CLIENT_ID, sharedpreferences.getString(Helper.CLIENT_ID, null));
|
||||
parameters.put(Helper.CLIENT_SECRET, sharedpreferences.getString(Helper.CLIENT_SECRET, null));
|
||||
parameters.put("grant_type", "password");
|
||||
try {
|
||||
parameters.put("username", URLEncoder.encode(login_uid.getText().toString().trim().toLowerCase(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
parameters.put("username", login_uid.getText().toString().trim().toLowerCase());
|
||||
}
|
||||
try {
|
||||
parameters.put("password", URLEncoder.encode(login_passwd.getText().toString(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
parameters.put("password", login_passwd.getText().toString());
|
||||
}
|
||||
parameters.put("scope", "user");
|
||||
String oauthUrl = "/api/v1/users/token";
|
||||
new Thread(() -> {
|
||||
try {
|
||||
String response = new HttpsConnection(LoginActivity.this, instance).post("https://" + instance + oauthUrl, 30, parameters, null);
|
||||
runOnUiThread(() -> {
|
||||
JSONObject resobj;
|
||||
try {
|
||||
resobj = new JSONObject(response);
|
||||
String token = resobj.get("access_token").toString();
|
||||
String refresh_token = null;
|
||||
if (resobj.has("refresh_token"))
|
||||
refresh_token = resobj.getString("refresh_token");
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
|
||||
editor.apply();
|
||||
//Update the account with the token;
|
||||
new UpdateAccountInfoAsyncTask(LoginActivity.this, token, client_id, client_secret, refresh_token, finalHost).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
runOnUiThread(() -> {
|
||||
connectionButton.setEnabled(true);
|
||||
runOnUiThread(() -> {
|
||||
String message;
|
||||
if (e.getLocalizedMessage() != null && e.getLocalizedMessage().trim().length() > 0)
|
||||
message = e.getLocalizedMessage();
|
||||
else if (e.getMessage() != null && e.getMessage().trim().length() > 0)
|
||||
message = e.getMessage();
|
||||
else
|
||||
message = getString(R.string.client_error);
|
||||
Toasty.error(LoginActivity.this, message, Toast.LENGTH_LONG).show();
|
||||
});
|
||||
String message = null;
|
||||
if (e.getLocalizedMessage() != null) {
|
||||
message = e.getMessage();
|
||||
}
|
||||
if (message == null) {
|
||||
message = getString(R.string.client_error);
|
||||
}
|
||||
Toasty.error(LoginActivity.this, message, Toast.LENGTH_LONG).show();
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
private void manageClient(String client_id, String client_secret) {
|
||||
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.CLIENT_ID, client_id);
|
||||
editor.putString(Helper.CLIENT_SECRET, client_secret);
|
||||
editor.apply();
|
||||
connectionButton.setEnabled(true);
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
|
|
|
@ -115,7 +115,6 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
private ImageView send;
|
||||
private TextView add_comment_read;
|
||||
private EditText add_comment_write;
|
||||
private String instance;
|
||||
private List<String> playlistForVideo;
|
||||
private List<Playlist> playlists;
|
||||
|
||||
|
@ -162,7 +161,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(PeertubeActivity.this));
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(PeertubeActivity.this));
|
||||
Account account = new AccountDAO(PeertubeActivity.this, db).getUniqAccount(userId, instance);
|
||||
Helper.loadGiF(PeertubeActivity.this, account, my_pp);
|
||||
Bundle b = getIntent().getExtras();
|
||||
|
@ -486,7 +485,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
});
|
||||
|
||||
try {
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(new TLSSocketFactory(instance));
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(new TLSSocketFactory());
|
||||
} catch (KeyManagementException | NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -40,14 +40,6 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
|
|||
if (getSupportActionBar() != null)
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
Bundle b = getIntent().getExtras();
|
||||
if (b != null) {
|
||||
instance = b.getString("instance");
|
||||
}
|
||||
if (instance == null) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
signup = findViewById(R.id.signup);
|
||||
EditText username = findViewById(R.id.username);
|
||||
EditText email = findViewById(R.id.email);
|
||||
|
@ -73,19 +65,23 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
|
|||
return;
|
||||
}
|
||||
String[] emailArray = email.getText().toString().split("@");
|
||||
if( emailArray.length > 1 && !Arrays.asList(Helper.valideEmails).contains(emailArray[1])) {
|
||||
if (emailArray.length > 1 && !Arrays.asList(Helper.valideEmails).contains(emailArray[1])) {
|
||||
Toasty.error(PeertubeRegisterActivity.this, getString(R.string.email_error_domain, emailArray[1])).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.getText().toString().trim().length() < 8) {
|
||||
Toasty.error(PeertubeRegisterActivity.this, getString(R.string.password_too_short)).show();
|
||||
return;
|
||||
}
|
||||
if (username.getText().toString().matches("[a-zA-Z0-9_]")) {
|
||||
if (username.getText().toString().matches("[a-z0-9_]")) {
|
||||
Toasty.error(PeertubeRegisterActivity.this, getString(R.string.username_error)).show();
|
||||
return;
|
||||
}
|
||||
signup.setEnabled(false);
|
||||
|
||||
String host = emailArray[1];
|
||||
instance = Helper.getPeertubeUrl(host);
|
||||
AccountCreation accountCreation = new AccountCreation();
|
||||
accountCreation.setEmail(email.getText().toString().trim());
|
||||
accountCreation.setPassword(password.getText().toString().trim());
|
||||
|
@ -103,7 +99,7 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
|
|||
);
|
||||
agreement_text.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
agreement_text.setText(Html.fromHtml(content_agreement));
|
||||
setTitle(instance);
|
||||
setTitle(R.string.create_an_account);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -145,7 +141,7 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
|
|||
});
|
||||
AlertDialog alertDialog = dialogBuilder.create();
|
||||
alertDialog.setTitle(getString(R.string.account_created));
|
||||
alertDialog.setMessage(getString(R.string.account_created_message, this.instance));
|
||||
alertDialog.setMessage(getString(R.string.account_created_message, apiResponse.getStringData()));
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
|
|
@ -24,6 +24,7 @@ public class APIResponse {
|
|||
private String since_id, max_id;
|
||||
private List<String> playlistForVideos;
|
||||
private Instance instance;
|
||||
private String stringData;
|
||||
|
||||
public List<Account> getAccounts() {
|
||||
return accounts;
|
||||
|
@ -126,4 +127,12 @@ public class APIResponse {
|
|||
public void setStatuses(List<Status> statuses) {
|
||||
this.statuses = statuses;
|
||||
}
|
||||
|
||||
public String getStringData() {
|
||||
return stringData;
|
||||
}
|
||||
|
||||
public void setStringData(String stringData) {
|
||||
this.stringData = stringData;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,12 +60,10 @@ public class HttpsConnection {
|
|||
private int CHUNK_SIZE = 4096;
|
||||
private SharedPreferences sharedpreferences;
|
||||
private Proxy proxy;
|
||||
private String instance;
|
||||
private String USER_AGENT;
|
||||
|
||||
|
||||
public HttpsConnection(Context context, String instance) {
|
||||
this.instance = instance;
|
||||
public HttpsConnection(Context context) {
|
||||
this.context = context;
|
||||
sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean proxyEnabled = sharedpreferences.getBoolean(Helper.SET_PROXY_ENABLED, false);
|
||||
|
@ -98,10 +96,6 @@ public class HttpsConnection {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
if (instance != null && instance.endsWith(".onion")) {
|
||||
HttpsURLConnection.setDefaultHostnameVerifier((arg0, arg1) -> true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -155,7 +149,7 @@ public class HttpsConnection {
|
|||
httpsURLConnection.setRequestProperty("Accept", "application/json");
|
||||
httpsURLConnection.setUseCaches(true);
|
||||
httpsURLConnection.setDefaultUseCaches(true);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if (token != null && token.startsWith("Basic "))
|
||||
|
@ -210,7 +204,7 @@ public class HttpsConnection {
|
|||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setRequestProperty("http.keepAlive", "false");
|
||||
httpsURLConnection.setInstanceFollowRedirects(false);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
httpsURLConnection.setRequestMethod("HEAD");
|
||||
if (httpsURLConnection.getResponseCode() == 301) {
|
||||
Map<String, List<String>> map = httpsURLConnection.getHeaderFields();
|
||||
|
@ -253,7 +247,7 @@ public class HttpsConnection {
|
|||
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||
httpsURLConnection.setRequestProperty("Accept", "application/json");
|
||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
httpsURLConnection.setRequestMethod("GET");
|
||||
httpsURLConnection.setDefaultUseCaches(true);
|
||||
httpsURLConnection.setUseCaches(true);
|
||||
|
@ -316,7 +310,7 @@ public class HttpsConnection {
|
|||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
||||
httpsURLConnection.setDoOutput(true);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
httpsURLConnection.setRequestMethod("POST");
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
|
@ -372,7 +366,7 @@ public class HttpsConnection {
|
|||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
||||
httpsURLConnection.setDoOutput(true);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||
httpsURLConnection.setRequestProperty("Accept", "application/json");
|
||||
httpsURLConnection.setRequestMethod("POST");
|
||||
|
@ -428,7 +422,7 @@ public class HttpsConnection {
|
|||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
||||
httpsURLConnection.setDoOutput(true);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
httpsURLConnection.setRequestMethod("POST");
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
|
@ -551,7 +545,7 @@ public class HttpsConnection {
|
|||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
else
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
int responseCode = httpsURLConnection.getResponseCode();
|
||||
// always check HTTP response code first
|
||||
|
@ -657,7 +651,7 @@ public class HttpsConnection {
|
|||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
|
||||
httpsURLConnection.setRequestMethod("PATCH");
|
||||
} else {
|
||||
|
@ -742,7 +736,7 @@ public class HttpsConnection {
|
|||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if (token != null && token.startsWith("Basic "))
|
||||
|
@ -813,7 +807,7 @@ public class HttpsConnection {
|
|||
else
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if (token != null && token.startsWith("Basic "))
|
||||
|
|
|
@ -547,7 +547,7 @@ public class PeertubeAPI {
|
|||
*/
|
||||
public APIResponse getInstance() {
|
||||
try {
|
||||
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/instance"), 30, null, prefKeyOauthTokenT);
|
||||
String response = new HttpsConnection(context).get(getAbsoluteUrl("/instance"), 30, null, prefKeyOauthTokenT);
|
||||
Instance instanceEntity = parseInstance(new JSONObject(response));
|
||||
apiResponse.setInstance(instanceEntity);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
|
@ -609,7 +609,7 @@ public class PeertubeAPI {
|
|||
params.put("scheduleUpdate", "null");
|
||||
List<Peertube> peertubes = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
httpsConnection.put(getAbsoluteUrl(String.format("/videos/%s", peertube.getId())), 60, params, prefKeyOauthTokenT);
|
||||
peertubes.add(peertube);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
|
@ -630,7 +630,7 @@ public class PeertubeAPI {
|
|||
PeertubeInformation peertubeInformation = new PeertubeInformation();
|
||||
try {
|
||||
|
||||
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/videos/categories"), 60, null, null);
|
||||
String response = new HttpsConnection(context).get(getAbsoluteUrl("/videos/categories"), 60, null, null);
|
||||
JSONObject categories = new JSONObject(response);
|
||||
LinkedHashMap<Integer, String> _pcategories = new LinkedHashMap<>();
|
||||
for (int i = 1; i <= categories.length(); i++) {
|
||||
|
@ -639,7 +639,7 @@ public class PeertubeAPI {
|
|||
}
|
||||
peertubeInformation.setCategories(_pcategories);
|
||||
|
||||
response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/videos/languages"), 60, null, null);
|
||||
response = new HttpsConnection(context).get(getAbsoluteUrl("/videos/languages"), 60, null, null);
|
||||
JSONObject languages = new JSONObject(response);
|
||||
LinkedHashMap<String, String> _languages = new LinkedHashMap<>();
|
||||
Iterator<String> iter = languages.keys();
|
||||
|
@ -652,7 +652,7 @@ public class PeertubeAPI {
|
|||
}
|
||||
peertubeInformation.setLanguages(_languages);
|
||||
|
||||
response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/videos/privacies"), 60, null, null);
|
||||
response = new HttpsConnection(context).get(getAbsoluteUrl("/videos/privacies"), 60, null, null);
|
||||
JSONObject privacies = new JSONObject(response);
|
||||
LinkedHashMap<Integer, String> _pprivacies = new LinkedHashMap<>();
|
||||
for (int i = 1; i <= privacies.length(); i++) {
|
||||
|
@ -662,7 +662,7 @@ public class PeertubeAPI {
|
|||
peertubeInformation.setPrivacies(_pprivacies);
|
||||
|
||||
|
||||
response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/video-playlists/privacies"), 60, null, null);
|
||||
response = new HttpsConnection(context).get(getAbsoluteUrl("/video-playlists/privacies"), 60, null, null);
|
||||
JSONObject plprivacies = new JSONObject(response);
|
||||
LinkedHashMap<Integer, String> _plprivacies = new LinkedHashMap<>();
|
||||
for (int i = 1; i <= plprivacies.length(); i++) {
|
||||
|
@ -671,7 +671,7 @@ public class PeertubeAPI {
|
|||
}
|
||||
peertubeInformation.setPlaylistPrivacies(_plprivacies);
|
||||
|
||||
response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/videos/licences"), 60, null, null);
|
||||
response = new HttpsConnection(context).get(getAbsoluteUrl("/videos/licences"), 60, null, null);
|
||||
JSONObject licences = new JSONObject(response);
|
||||
LinkedHashMap<Integer, String> _plicences = new LinkedHashMap<>();
|
||||
for (int i = 1; i <= licences.length(); i++) {
|
||||
|
@ -687,7 +687,7 @@ public class PeertubeAPI {
|
|||
lang = PeertubeInformation.langueMapped.get(Locale.getDefault().getLanguage());
|
||||
|
||||
if (lang != null && !lang.startsWith("en")) {
|
||||
response = new HttpsConnection(context, this.instance).get(String.format("https://" + instance + "/client/locales/%s/server.json", lang), 60, null, null);
|
||||
response = new HttpsConnection(context).get(String.format("https://" + instance + "/client/locales/%s/server.json", lang), 60, null, null);
|
||||
JSONObject translations = new JSONObject(response);
|
||||
LinkedHashMap<String, String> _translations = new LinkedHashMap<>();
|
||||
Iterator<String> itertrans = translations.keys();
|
||||
|
@ -719,7 +719,7 @@ public class PeertubeAPI {
|
|||
social = nodeinfo.getName();
|
||||
}
|
||||
try {
|
||||
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/users/me"), 60, null, prefKeyOauthTokenT);
|
||||
String response = new HttpsConnection(context).get(getAbsoluteUrl("/users/me"), 60, null, prefKeyOauthTokenT);
|
||||
JSONObject accountObject = new JSONObject(response).getJSONObject("account");
|
||||
account = parseAccountResponsePeertube(accountObject);
|
||||
if (social != null) {
|
||||
|
@ -750,7 +750,7 @@ public class PeertubeAPI {
|
|||
|
||||
String response;
|
||||
try {
|
||||
response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/users/me"), 60, null, targetedAccount.getToken());
|
||||
response = new HttpsConnection(context).get(getAbsoluteUrl("/users/me"), 60, null, targetedAccount.getToken());
|
||||
JSONObject accountObject = new JSONObject(response).getJSONObject("account");
|
||||
account = parseAccountResponsePeertube(accountObject);
|
||||
if (social != null) {
|
||||
|
@ -782,7 +782,7 @@ public class PeertubeAPI {
|
|||
domain = domain.replace("https://", "");
|
||||
}
|
||||
try {
|
||||
response = new HttpsConnection(context, domain).get("https://" + domain + "/.well-known/nodeinfo", 30, null, null);
|
||||
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 {
|
||||
|
@ -798,7 +798,7 @@ public class PeertubeAPI {
|
|||
}
|
||||
if (nodeInfos.size() > 0) {
|
||||
NodeInfo nodeInfo = nodeInfos.get(nodeInfos.size() - 1);
|
||||
response = new HttpsConnection(context, this.instance).get(nodeInfo.getHref(), 30, null, null);
|
||||
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();
|
||||
|
@ -815,7 +815,7 @@ public class PeertubeAPI {
|
|||
} catch (IOException | JSONException | NoSuchAlgorithmException | KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
response = new HttpsConnection(context, this.instance).get("https://" + domain + "/api/v1/instance", 30, null, null);
|
||||
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"));
|
||||
|
@ -839,7 +839,7 @@ public class PeertubeAPI {
|
|||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
try {
|
||||
response = new HttpsConnection(context, this.instance).get("https://" + domain + "/api/v1/instance", 30, null, null);
|
||||
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"));
|
||||
|
@ -874,8 +874,8 @@ public class PeertubeAPI {
|
|||
params.put("username", accountCreation.getUsername());
|
||||
params.put("email", accountCreation.getEmail());
|
||||
params.put("password", accountCreation.getPassword());
|
||||
new HttpsConnection(context, this.instance).post(getAbsoluteUrl("/users/register"), 30, params, null);
|
||||
|
||||
new HttpsConnection(context).post(getAbsoluteUrl("/users/register"), 30, params, null);
|
||||
apiResponse.setStringData(accountCreation.getEmail());
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
|
@ -898,7 +898,7 @@ public class PeertubeAPI {
|
|||
params.put("client_secret", client_secret);
|
||||
params.put("refresh_token", refresh_token);
|
||||
try {
|
||||
String response = new HttpsConnection(context, this.instance).post(getAbsoluteUrl("/users/token"), 60, params, null);
|
||||
String response = new HttpsConnection(context).post(getAbsoluteUrl("/users/token"), 60, params, null);
|
||||
JSONObject resobj = new JSONObject(response);
|
||||
String token = resobj.get("access_token").toString();
|
||||
if (resobj.has("refresh_token"))
|
||||
|
@ -921,7 +921,7 @@ public class PeertubeAPI {
|
|||
|
||||
account = new Account();
|
||||
try {
|
||||
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl(String.format("/accounts/%s", accountId)), 60, null, prefKeyOauthTokenT);
|
||||
String response = new HttpsConnection(context).get(getAbsoluteUrl(String.format("/accounts/%s", accountId)), 60, null, prefKeyOauthTokenT);
|
||||
account = parseAccountResponsePeertube(new JSONObject(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -944,7 +944,7 @@ public class PeertubeAPI {
|
|||
params.put("uris", uri);
|
||||
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/users/me/subscriptions/exist"), 60, params, prefKeyOauthTokenT);
|
||||
return new JSONObject(response).getBoolean(uri);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
|
@ -995,7 +995,7 @@ public class PeertubeAPI {
|
|||
List<Peertube> peertubes = new ArrayList<>();
|
||||
try {
|
||||
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/users/me/history/videos"), 60, params, prefKeyOauthTokenT);
|
||||
|
||||
JSONArray jsonArray = new JSONObject(response).getJSONArray("data");
|
||||
|
@ -1040,7 +1040,7 @@ public class PeertubeAPI {
|
|||
List<Peertube> peertubes = new ArrayList<>();
|
||||
try {
|
||||
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/users/me/videos"), 60, params, prefKeyOauthTokenT);
|
||||
|
||||
JSONArray jsonArray = new JSONObject(response).getJSONArray("data");
|
||||
|
@ -1075,7 +1075,7 @@ public class PeertubeAPI {
|
|||
params.put("count", String.valueOf(tootPerPage));
|
||||
List<Peertube> peertubes = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl(String.format("/accounts/%s/videos", acct)), 60, params, prefKeyOauthTokenT);
|
||||
JSONArray jsonArray = new JSONObject(response).getJSONArray("data");
|
||||
peertubes = parsePeertube(jsonArray);
|
||||
|
@ -1128,7 +1128,7 @@ public class PeertubeAPI {
|
|||
params.put("count", String.valueOf(tootPerPage));
|
||||
List<PeertubeNotification> peertubeNotifications = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/users/me/notifications"), 60, params, prefKeyOauthTokenT);
|
||||
JSONArray jsonArray = new JSONObject(response).getJSONArray("data");
|
||||
peertubeNotifications = parsePeertubeNotifications(jsonArray);
|
||||
|
@ -1173,7 +1173,7 @@ public class PeertubeAPI {
|
|||
List<Peertube> peertubes = new ArrayList<>();
|
||||
try {
|
||||
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl(String.format("/video-channels/%s/videos", acct)), 60, params, prefKeyOauthTokenT);
|
||||
|
||||
JSONArray jsonArray = new JSONObject(response).getJSONArray("data");
|
||||
|
@ -1346,7 +1346,7 @@ public class PeertubeAPI {
|
|||
params.put("nsfw", String.valueOf(nsfw));
|
||||
List<Peertube> peertubes = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
|
||||
if (!action.equals("/overviews/videos")) {
|
||||
JSONArray values = new JSONObject(response).getJSONArray("data");
|
||||
|
@ -1406,7 +1406,7 @@ public class PeertubeAPI {
|
|||
|
||||
List<Account> accounts = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl(String.format("/accounts/%s/video-channels", name)), 60, null, null);
|
||||
JSONArray jsonArray = new JSONObject(response).getJSONArray("data");
|
||||
accounts = parseAccountResponsePeertube(jsonArray);
|
||||
|
@ -1428,7 +1428,7 @@ public class PeertubeAPI {
|
|||
|
||||
Peertube peertube = null;
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(String.format("https://" + instance + "/api/v1/videos/%s", videoId), 60, null, token);
|
||||
JSONObject jsonObject = new JSONObject(response);
|
||||
peertube = parseSinglePeertube(instance, jsonObject);
|
||||
|
@ -1452,7 +1452,7 @@ public class PeertubeAPI {
|
|||
@SuppressWarnings("SameParameterValue")
|
||||
public String getRating(String id) {
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl(String.format("/users/me/videos/%s/rating", id)), 60, null, prefKeyOauthTokenT);
|
||||
return new JSONObject(response).get("rating").toString();
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
|
@ -1546,7 +1546,7 @@ public class PeertubeAPI {
|
|||
return -1;
|
||||
}
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
switch (actionCall) {
|
||||
case "POST":
|
||||
httpsConnection.post(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
|
||||
|
@ -1578,7 +1578,7 @@ public class PeertubeAPI {
|
|||
params.put("videoIds", videoId);
|
||||
List<String> ids = new ArrayList<>();
|
||||
try {
|
||||
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/users/me/video-playlists/videos-exist"), 60, params, prefKeyOauthTokenT);
|
||||
String response = new HttpsConnection(context).get(getAbsoluteUrl("/users/me/video-playlists/videos-exist"), 60, params, prefKeyOauthTokenT);
|
||||
|
||||
JSONArray jsonArray = new JSONObject(response).getJSONArray(videoId);
|
||||
try {
|
||||
|
@ -1612,7 +1612,7 @@ public class PeertubeAPI {
|
|||
|
||||
List<Playlist> playlists = new ArrayList<>();
|
||||
try {
|
||||
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl(String.format("/accounts/%s/video-playlists", username)), 60, null, prefKeyOauthTokenT);
|
||||
String response = new HttpsConnection(context).get(getAbsoluteUrl(String.format("/accounts/%s/video-playlists", username)), 60, null, prefKeyOauthTokenT);
|
||||
playlists = parsePlaylists(context, new JSONObject(response).getJSONArray("data"));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
|
@ -1631,7 +1631,7 @@ public class PeertubeAPI {
|
|||
*/
|
||||
public int deletePlaylist(String playlistId) {
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
httpsConnection.delete(getAbsoluteUrl(String.format("/video-playlists/%s", playlistId)), 60, null, prefKeyOauthTokenT);
|
||||
actionCode = httpsConnection.getActionCode();
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
|
@ -1651,7 +1651,7 @@ public class PeertubeAPI {
|
|||
*/
|
||||
public int deleteVideoPlaylist(String playlistId, String videoId) {
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
httpsConnection.delete(getAbsoluteUrl(String.format("/video-playlists/%s/videos/%s", playlistId, videoId)), 60, null, prefKeyOauthTokenT);
|
||||
actionCode = httpsConnection.getActionCode();
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
|
@ -1671,7 +1671,7 @@ public class PeertubeAPI {
|
|||
*/
|
||||
public int addVideoPlaylist(String playlistId, String videoId) {
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("videoId", videoId);
|
||||
httpsConnection.post(getAbsoluteUrl(String.format("/video-playlists/%s/videos", playlistId)), 60, params, prefKeyOauthTokenT);
|
||||
|
@ -1705,7 +1705,7 @@ public class PeertubeAPI {
|
|||
params.put("sort", "-updatedAt");
|
||||
List<Peertube> peertubes = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl(String.format("/video-playlists/%s/videos", playlistid)), 60, params, prefKeyOauthTokenT);
|
||||
JSONArray jsonArray = new JSONObject(response).getJSONArray("data");
|
||||
peertubes = parsePeertube(jsonArray);
|
||||
|
@ -1728,7 +1728,7 @@ public class PeertubeAPI {
|
|||
public APIResponse getSinglePeertubeComments(String instance, String videoId) {
|
||||
List<Status> statuses = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
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);
|
||||
|
@ -1762,7 +1762,7 @@ public class PeertubeAPI {
|
|||
|
||||
List<Peertube> peertubes = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get("https://" + instance + "/api/v1/search/videos", 10, params, null);
|
||||
JSONArray jsonArray = new JSONObject(response).getJSONArray("data");
|
||||
peertubes = parsePeertube(jsonArray);
|
||||
|
|
|
@ -17,7 +17,7 @@ public class TLSSocketFactory extends SSLSocketFactory {
|
|||
private SSLContext sslContext;
|
||||
|
||||
|
||||
public TLSSocketFactory(String instance) throws KeyManagementException, NoSuchAlgorithmException {
|
||||
public TLSSocketFactory() throws KeyManagementException, NoSuchAlgorithmException {
|
||||
|
||||
sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(null, null, null);
|
||||
|
|
|
@ -3,6 +3,7 @@ package app.fedilab.fedilabtube.client.entities;
|
|||
public class AccountCreation {
|
||||
|
||||
private String username;
|
||||
private String displayName;
|
||||
private String email;
|
||||
private String password;
|
||||
private String passwordConfirm;
|
||||
|
@ -38,4 +39,12 @@ public class AccountCreation {
|
|||
public void setPasswordConfirm(String passwordConfirm) {
|
||||
this.passwordConfirm = passwordConfirm;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ import android.net.Uri;
|
|||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
@ -196,6 +195,19 @@ public class Helper {
|
|||
* @return String the peertube URL
|
||||
*/
|
||||
public static String getPeertubeUrl(String acad) {
|
||||
|
||||
if (acad.compareTo("education.gouv.fr") == 0 || acad.compareTo("igesr.gouv.fr") == 0) {
|
||||
acad = "education.fr";
|
||||
} else if (acad.compareTo("ac-nancy-metz.fr") == 0) {
|
||||
acad = "ac-nancy.fr";
|
||||
} else if (acad.compareTo("clermont.fr") == 0) {
|
||||
acad = "clermont-ferrand.fr";
|
||||
} else if (acad.compareTo("ac-wf.wf") == 0 || acad.compareTo("ac-mayotte.fr") == 0 || acad.compareTo("ac-noumea.nc") == 0
|
||||
|| acad.compareTo("ac-guadeloupe.fr") == 0 || acad.compareTo("monvr.pf") == 0 || acad.compareTo("ac-reunion.fr") == 0 ||
|
||||
acad.compareTo("ac-martinique.fr") == 0 || acad.compareTo("ac-guyane.fr") == 0
|
||||
) {
|
||||
acad = "outremer.fr";
|
||||
}
|
||||
return "tube-" + acad.replaceAll("ac-|\\.fr", "") + ".beta.education.fr";
|
||||
}
|
||||
|
||||
|
|
|
@ -23,19 +23,10 @@
|
|||
android:layout_marginTop="20dp"
|
||||
android:contentDescription="@string/app_logo"
|
||||
android:src="@drawable/ic_launcher_foreground"
|
||||
app:layout_constraintEnd_toStartOf="@+id/info_instance"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/info_instance"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/main_logo"
|
||||
app:layout_constraintTop_toTopOf="@+id/main_logo"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/main_logo"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/create_an_account_peertube"
|
||||
|
@ -45,7 +36,7 @@
|
|||
android:layout_marginTop="20dp"
|
||||
android:drawablePadding="10dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/join_peertube_on"
|
||||
android:text="@string/join_peertube"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
|
|
@ -130,20 +130,16 @@
|
|||
<string name="agreement_check_peertube">J\'ai au moins 16 ans et je suis d\'accord avec les %1$s de cette instance</string>
|
||||
<string name="sign_up">S’inscrire</string>
|
||||
<string name="account_created">Compte créé !</string>
|
||||
<string name="account_created_message"> Your account has been created!\n\n
|
||||
Think to validate your email within the 48 next hours.\n\n
|
||||
You can now connect your account by writing <b>%1$s</b> in the first field and click on <b>Connect</b>.\n\n
|
||||
<b>Important</b>: If your instance required validation, you will receive an email once it is validated!
|
||||
</string>
|
||||
<string name="account_created_message">Votre compte est créé !\n\nVous allez recevoir un email de confirmation à l\'adresse <b>%1$s</b>.\n\nCliquez sur le lien présent dans le mail pour valider votre compte.</string>
|
||||
<string name="all_field_filled">Veuillez remplir tous les champs !</string>
|
||||
<string name="password_error">Les mots de passe ne sont pas identiques !</string>
|
||||
<string name="email_error">L\'e-mail ne semble pas être valide !</string>
|
||||
<string name="password_too_short">Le mot de passe doit contenir au moins 8 caractères</string>
|
||||
<string name="username_error">Le nom d\'utilisateur·rice doit contenir uniquement des lettres, des chiffres et des caractères de soulignement</string>
|
||||
<string name="username_error">Le nom d\'utilisateur·rice doit être en minuscule, contenir uniquement des lettres, des chiffres, des points et des caractères de soulignement</string>
|
||||
<string name="tos">conditions de service</string>
|
||||
<string name="server_rules">règles du serveur</string>
|
||||
<string name="agreement_check">J\'accepte les %1$s et les %2$s</string>
|
||||
<string name="join_peertube_on">Rejoindre <b>%1$s</b></string>
|
||||
<string name="email_error_domain">Les adresses mails %1$s ne sont pas autorisées !</string>
|
||||
<string name="create_an_account">Créer un compte</string>
|
||||
|
||||
</resources>
|
Loading…
Reference in New Issue