Allows onion urls
This commit is contained in:
parent
66e19d9ebd
commit
b058df8353
|
@ -138,7 +138,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
|
|||
Account account = new AccountDAO(getApplicationContext(),db).getAccountByID(userId);
|
||||
String url = account.getAvatar();
|
||||
if( url.startsWith("/") ){
|
||||
url = "https://" + Helper.getLiveInstance(getApplicationContext()) + account.getAvatar();
|
||||
url = Helper.getLiveInstanceWithProtocol(getApplicationContext()) + account.getAvatar();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -252,7 +252,7 @@ public class LoginActivity extends BaseActivity {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final String response = new HttpsConnection(LoginActivity.this).post("https://" + instance + action, 30, parameters, null );
|
||||
final String response = new HttpsConnection(LoginActivity.this).post(Helper.instanceWithProtocol(instance) + action, 30, parameters, null );
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
JSONObject resobj;
|
||||
|
@ -274,11 +274,12 @@ public class LoginActivity extends BaseActivity {
|
|||
i.putExtra("instance", instance);
|
||||
startActivity(i);
|
||||
}
|
||||
} catch (JSONException ignored) {}
|
||||
} catch (JSONException ignored) {ignored.printStackTrace();}
|
||||
}
|
||||
});
|
||||
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
String message;
|
||||
|
@ -326,7 +327,7 @@ public class LoginActivity extends BaseActivity {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final String response = new HttpsConnection(LoginActivity.this).post("https://" + instance + "/oauth/token", 30, parameters, null );
|
||||
final String response = new HttpsConnection(LoginActivity.this).post(Helper.instanceWithProtocol(instance) + "/oauth/token", 30, parameters, null );
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
JSONObject resobj;
|
||||
|
|
|
@ -144,7 +144,7 @@ public class RemoteFollowActivity extends BaseActivity implements OnRetrieveRemo
|
|||
Account account = new AccountDAO(getApplicationContext(),db).getAccountByID(userId);
|
||||
String url = account.getAvatar();
|
||||
if( url.startsWith("/") ){
|
||||
url = "https://" + Helper.getLiveInstance(getApplicationContext()) + account.getAvatar();
|
||||
url = Helper.getLiveInstanceWithProtocol(getApplicationContext()) + account.getAvatar();
|
||||
}
|
||||
Glide.with(getApplicationContext())
|
||||
.asBitmap()
|
||||
|
|
|
@ -412,7 +412,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
|
|||
}
|
||||
String urlHeader = account.getHeader();
|
||||
if (urlHeader.startsWith("/")) {
|
||||
urlHeader = "https://" + Helper.getLiveInstance(ShowAccountActivity.this) + account.getHeader();
|
||||
urlHeader = Helper.getLiveInstanceWithProtocol(ShowAccountActivity.this) + account.getHeader();
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && !urlHeader.contains("missing.png")) {
|
||||
|
||||
|
@ -451,7 +451,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
|
|||
pp_actionBar = findViewById(R.id.pp_actionBar);
|
||||
String url = account.getAvatar();
|
||||
if( url.startsWith("/") ){
|
||||
url = "https://" + Helper.getLiveInstance(getApplicationContext()) + account.getAvatar();
|
||||
url = Helper.getLiveInstanceWithProtocol(getApplicationContext()) + account.getAvatar();
|
||||
}
|
||||
Glide.with(getApplicationContext())
|
||||
.asBitmap()
|
||||
|
|
|
@ -151,7 +151,7 @@ public class ShowConversationActivity extends BaseActivity implements OnRetrieve
|
|||
Account account = new AccountDAO(getApplicationContext(),db).getAccountByID(userId);
|
||||
String url = account.getAvatar();
|
||||
if( url.startsWith("/") ){
|
||||
url = "https://" + Helper.getLiveInstance(getApplicationContext()) + account.getAvatar();
|
||||
url = Helper.getLiveInstanceWithProtocol(getApplicationContext()) + account.getAvatar();
|
||||
}
|
||||
Glide.with(getApplicationContext())
|
||||
.asBitmap()
|
||||
|
|
|
@ -347,7 +347,7 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
|
||||
String url = account.getAvatar();
|
||||
if( url.startsWith("/") ){
|
||||
url = "https://" + Helper.getLiveInstance(getApplicationContext()) + account.getAvatar();
|
||||
url = Helper.getLiveInstanceWithProtocol(getApplicationContext()) + account.getAvatar();
|
||||
}
|
||||
Glide.with(getApplicationContext())
|
||||
.asBitmap()
|
||||
|
|
|
@ -119,7 +119,7 @@ public class WebviewConnectActivity extends BaseActivity {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final String response = new HttpsConnection(WebviewConnectActivity.this).post("https://" + instance + action, 30, parameters, null);
|
||||
final String response = new HttpsConnection(WebviewConnectActivity.this).post(Helper.instanceWithProtocol(instance) + action, 30, parameters, null);
|
||||
JSONObject resobj;
|
||||
try {
|
||||
resobj = new JSONObject(response);
|
||||
|
@ -160,7 +160,7 @@ public class WebviewConnectActivity extends BaseActivity {
|
|||
queryString += "&" + Helper.REDIRECT_URI + "="+ Uri.encode(Helper.REDIRECT_CONTENT_WEB);
|
||||
queryString += "&" + Helper.RESPONSE_TYPE +"=code";
|
||||
queryString += "&" + Helper.SCOPE +"=" + Helper.OAUTH_SCOPES;
|
||||
return "https://" + instance + Helper.EP_AUTHORIZE + "?" + queryString;
|
||||
return Helper.instanceWithProtocol(instance) + Helper.EP_AUTHORIZE + "?" + queryString;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import android.os.AsyncTask;
|
|||
import java.lang.ref.WeakReference;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Results;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRemoteAccountInterface;
|
||||
|
||||
|
||||
|
@ -38,7 +39,7 @@ public class RetrieveRemoteDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
|
||||
|
||||
public RetrieveRemoteDataAsyncTask(Context context, String username, String instance, OnRetrieveRemoteAccountInterface onRetrieveRemoteAccountInterface){
|
||||
this.url = "https://" + instance + "/@" + username;
|
||||
this.url = Helper.instanceWithProtocol(instance) + "/@" + username;
|
||||
this.listener = onRetrieveRemoteAccountInterface;
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
}
|
||||
|
|
|
@ -2030,7 +2030,7 @@ public class API {
|
|||
|
||||
|
||||
private String getAbsoluteUrl(String action) {
|
||||
return "https://" + this.instance + "/api/v1" + action;
|
||||
return Helper.instanceWithProtocol(this.instance) + "/api/v1" + action;
|
||||
}
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -895,6 +895,18 @@ public class Helper {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static String getLiveInstanceWithProtocol(Context context) {
|
||||
return instanceWithProtocol(getLiveInstance(context));
|
||||
}
|
||||
|
||||
public static String instanceWithProtocol(String instance){
|
||||
if( instance == null)
|
||||
return null;
|
||||
if( instance.endsWith(".onion"))
|
||||
return "http://" + instance;
|
||||
else
|
||||
return "https://" + instance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -958,7 +970,7 @@ public class Helper {
|
|||
item.setIcon(R.drawable.ic_person);
|
||||
String url = account.getAvatar();
|
||||
if( url.startsWith("/") ){
|
||||
url = "https://" + Helper.getLiveInstance(activity) + account.getAvatar();
|
||||
url = Helper.getLiveInstanceWithProtocol(activity) + account.getAvatar();
|
||||
}
|
||||
Glide.with(activity.getApplicationContext())
|
||||
.asBitmap()
|
||||
|
@ -1093,7 +1105,7 @@ public class Helper {
|
|||
*/
|
||||
public static void loadPictureIcon(final Activity activity, String url, final ImageView imageView){
|
||||
if( url.startsWith("/") ){
|
||||
url = "https://" + Helper.getLiveInstance(activity) + url;
|
||||
url = Helper.getLiveInstanceWithProtocol(activity) + url;
|
||||
}
|
||||
|
||||
Glide.with(activity.getApplicationContext())
|
||||
|
@ -1169,14 +1181,14 @@ public class Helper {
|
|||
displayedName.setText(account.getDisplay_name());
|
||||
String url = account.getAvatar();
|
||||
if( url.startsWith("/") ){
|
||||
url = "https://" + Helper.getLiveInstance(activity) + account.getAvatar();
|
||||
url = Helper.getLiveInstanceWithProtocol(activity) + account.getAvatar();
|
||||
}
|
||||
Glide.with(activity.getApplicationContext())
|
||||
.load(url)
|
||||
.into(profilePicture);
|
||||
String urlHeader = account.getHeader();
|
||||
if( urlHeader.startsWith("/") ){
|
||||
urlHeader = "https://" + Helper.getLiveInstance(activity) + account.getHeader();
|
||||
urlHeader = Helper.getLiveInstanceWithProtocol(activity) + account.getHeader();
|
||||
}
|
||||
if (!urlHeader.contains("missing.png")) {
|
||||
Glide.with(activity.getApplicationContext())
|
||||
|
|
|
@ -156,95 +156,185 @@ public class LiveNotificationService extends Service {
|
|||
private void taks(Account account){
|
||||
InputStream inputStream = null;
|
||||
HttpsURLConnection httpsURLConnection = null;
|
||||
HttpURLConnection httpURLConnection = null;
|
||||
BufferedReader reader = null;
|
||||
Helper.EventStreaming lastEvent = null;
|
||||
|
||||
if( account != null){
|
||||
isRunning.get(account.getAcct()+account.getInstance());
|
||||
if(!isRunning.containsKey(account.getAcct()+account.getInstance()) || ! isRunning.get(account.getAcct()+account.getInstance())) {
|
||||
try {
|
||||
URL url = new URL("https://" + account.getInstance() + "/api/v1/streaming/user");
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + account.getToken());
|
||||
httpsURLConnection.setRequestProperty("Connection", "Keep-Alive");
|
||||
httpsURLConnection.setRequestProperty("Keep-Alive", "header");
|
||||
httpsURLConnection.setRequestProperty("Connection", "close");
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
httpsURLConnection.setRequestMethod("GET");
|
||||
if (httpsURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||
inputStream = new BufferedInputStream(httpsURLConnection.getInputStream());
|
||||
reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
String event;
|
||||
Helper.EventStreaming eventStreaming;
|
||||
while ((event = reader.readLine()) != null) {
|
||||
isRunning.put(account.getAcct()+account.getInstance(), true);
|
||||
if ((lastEvent == Helper.EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) {
|
||||
switch (event.trim()) {
|
||||
case "event: update":
|
||||
lastEvent = Helper.EventStreaming.UPDATE;
|
||||
break;
|
||||
case "event: notification":
|
||||
lastEvent = Helper.EventStreaming.NOTIFICATION;
|
||||
break;
|
||||
case "event: delete":
|
||||
lastEvent = Helper.EventStreaming.DELETE;
|
||||
break;
|
||||
default:
|
||||
lastEvent = Helper.EventStreaming.NONE;
|
||||
}
|
||||
} else {
|
||||
if (!event.startsWith("data: ")) {
|
||||
lastEvent = Helper.EventStreaming.NONE;
|
||||
continue;
|
||||
}
|
||||
event = event.substring(6);
|
||||
if (lastEvent == Helper.EventStreaming.UPDATE) {
|
||||
eventStreaming = Helper.EventStreaming.UPDATE;
|
||||
} else if (lastEvent == Helper.EventStreaming.NOTIFICATION) {
|
||||
eventStreaming = Helper.EventStreaming.NOTIFICATION;
|
||||
} else if (lastEvent == Helper.EventStreaming.DELETE) {
|
||||
eventStreaming = Helper.EventStreaming.DELETE;
|
||||
event = "{id:" + event + "}";
|
||||
if (Helper.instanceWithProtocol(account.getInstance()).startsWith("https")) {
|
||||
try {
|
||||
URL url = new URL("https://" + account.getInstance() + "/api/v1/streaming/user");
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + account.getToken());
|
||||
httpsURLConnection.setRequestProperty("Connection", "Keep-Alive");
|
||||
httpsURLConnection.setRequestProperty("Keep-Alive", "header");
|
||||
httpsURLConnection.setRequestProperty("Connection", "close");
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
httpsURLConnection.setRequestMethod("GET");
|
||||
if (httpsURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||
inputStream = new BufferedInputStream(httpsURLConnection.getInputStream());
|
||||
reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
String event;
|
||||
Helper.EventStreaming eventStreaming;
|
||||
while ((event = reader.readLine()) != null) {
|
||||
isRunning.put(account.getAcct() + account.getInstance(), true);
|
||||
if ((lastEvent == Helper.EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) {
|
||||
switch (event.trim()) {
|
||||
case "event: update":
|
||||
lastEvent = Helper.EventStreaming.UPDATE;
|
||||
break;
|
||||
case "event: notification":
|
||||
lastEvent = Helper.EventStreaming.NOTIFICATION;
|
||||
break;
|
||||
case "event: delete":
|
||||
lastEvent = Helper.EventStreaming.DELETE;
|
||||
break;
|
||||
default:
|
||||
lastEvent = Helper.EventStreaming.NONE;
|
||||
}
|
||||
} else {
|
||||
eventStreaming = Helper.EventStreaming.UPDATE;
|
||||
}
|
||||
lastEvent = Helper.EventStreaming.NONE;
|
||||
try {
|
||||
JSONObject eventJson = new JSONObject(event);
|
||||
onRetrieveStreaming(eventStreaming, account, eventJson);
|
||||
} catch (JSONException ignored) { ignored.printStackTrace();
|
||||
if (!event.startsWith("data: ")) {
|
||||
lastEvent = Helper.EventStreaming.NONE;
|
||||
continue;
|
||||
}
|
||||
event = event.substring(6);
|
||||
if (lastEvent == Helper.EventStreaming.UPDATE) {
|
||||
eventStreaming = Helper.EventStreaming.UPDATE;
|
||||
} else if (lastEvent == Helper.EventStreaming.NOTIFICATION) {
|
||||
eventStreaming = Helper.EventStreaming.NOTIFICATION;
|
||||
} else if (lastEvent == Helper.EventStreaming.DELETE) {
|
||||
eventStreaming = Helper.EventStreaming.DELETE;
|
||||
event = "{id:" + event + "}";
|
||||
} else {
|
||||
eventStreaming = Helper.EventStreaming.UPDATE;
|
||||
}
|
||||
lastEvent = Helper.EventStreaming.NONE;
|
||||
try {
|
||||
JSONObject eventJson = new JSONObject(event);
|
||||
onRetrieveStreaming(eventStreaming, account, eventJson);
|
||||
} catch (JSONException ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
isRunning.put(account.getAcct() + account.getInstance(), false);
|
||||
}
|
||||
isRunning.put(account.getAcct() + account.getInstance(), false);
|
||||
}
|
||||
|
||||
} catch (Exception ignored) {
|
||||
isRunning.put(account.getAcct() + account.getInstance(), false);
|
||||
ignored.printStackTrace();
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
if (inputStream != null) {
|
||||
httpsURLConnection.disconnect();
|
||||
}
|
||||
SystemClock.sleep(5000);
|
||||
Intent streamingIntent = new Intent(this, LiveNotificationService.class);
|
||||
streamingIntent.putExtra("userId", account.getId());
|
||||
try {
|
||||
startService(streamingIntent);
|
||||
} catch (Exception ignored) {
|
||||
isRunning.put(account.getAcct() + account.getInstance(), false);
|
||||
ignored.printStackTrace();
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
if (inputStream != null) {
|
||||
httpsURLConnection.disconnect();
|
||||
}
|
||||
SystemClock.sleep(5000);
|
||||
Intent streamingIntent = new Intent(this, LiveNotificationService.class);
|
||||
streamingIntent.putExtra("userId", account.getId());
|
||||
try {
|
||||
startService(streamingIntent);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}else {
|
||||
try {
|
||||
URL url = new URL("https://" + account.getInstance() + "/api/v1/streaming/user");
|
||||
httpURLConnection = (HttpURLConnection) url.openConnection();
|
||||
httpURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||
httpURLConnection.setRequestProperty("Authorization", "Bearer " + account.getToken());
|
||||
httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
|
||||
httpURLConnection.setRequestProperty("Keep-Alive", "header");
|
||||
httpURLConnection.setRequestProperty("Connection", "close");
|
||||
httpURLConnection.setRequestMethod("GET");
|
||||
if (httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||
inputStream = new BufferedInputStream(httpURLConnection.getInputStream());
|
||||
reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
String event;
|
||||
Helper.EventStreaming eventStreaming;
|
||||
while ((event = reader.readLine()) != null) {
|
||||
isRunning.put(account.getAcct() + account.getInstance(), true);
|
||||
if ((lastEvent == Helper.EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) {
|
||||
switch (event.trim()) {
|
||||
case "event: update":
|
||||
lastEvent = Helper.EventStreaming.UPDATE;
|
||||
break;
|
||||
case "event: notification":
|
||||
lastEvent = Helper.EventStreaming.NOTIFICATION;
|
||||
break;
|
||||
case "event: delete":
|
||||
lastEvent = Helper.EventStreaming.DELETE;
|
||||
break;
|
||||
default:
|
||||
lastEvent = Helper.EventStreaming.NONE;
|
||||
}
|
||||
} else {
|
||||
if (!event.startsWith("data: ")) {
|
||||
lastEvent = Helper.EventStreaming.NONE;
|
||||
continue;
|
||||
}
|
||||
event = event.substring(6);
|
||||
if (lastEvent == Helper.EventStreaming.UPDATE) {
|
||||
eventStreaming = Helper.EventStreaming.UPDATE;
|
||||
} else if (lastEvent == Helper.EventStreaming.NOTIFICATION) {
|
||||
eventStreaming = Helper.EventStreaming.NOTIFICATION;
|
||||
} else if (lastEvent == Helper.EventStreaming.DELETE) {
|
||||
eventStreaming = Helper.EventStreaming.DELETE;
|
||||
event = "{id:" + event + "}";
|
||||
} else {
|
||||
eventStreaming = Helper.EventStreaming.UPDATE;
|
||||
}
|
||||
lastEvent = Helper.EventStreaming.NONE;
|
||||
try {
|
||||
JSONObject eventJson = new JSONObject(event);
|
||||
onRetrieveStreaming(eventStreaming, account, eventJson);
|
||||
} catch (JSONException ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
isRunning.put(account.getAcct() + account.getInstance(), false);
|
||||
}
|
||||
|
||||
} catch (Exception ignored) {
|
||||
isRunning.put(account.getAcct() + account.getInstance(), false);
|
||||
ignored.printStackTrace();
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
if (inputStream != null) {
|
||||
httpURLConnection.disconnect();
|
||||
}
|
||||
SystemClock.sleep(5000);
|
||||
Intent streamingIntent = new Intent(this, LiveNotificationService.class);
|
||||
streamingIntent.putExtra("userId", account.getId());
|
||||
try {
|
||||
startService(streamingIntent);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue