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);
|
Account account = new AccountDAO(getApplicationContext(),db).getAccountByID(userId);
|
||||||
String url = account.getAvatar();
|
String url = account.getAvatar();
|
||||||
if( url.startsWith("/") ){
|
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
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
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() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
JSONObject resobj;
|
JSONObject resobj;
|
||||||
|
@ -274,11 +274,12 @@ public class LoginActivity extends BaseActivity {
|
||||||
i.putExtra("instance", instance);
|
i.putExtra("instance", instance);
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
}
|
}
|
||||||
} catch (JSONException ignored) {}
|
} catch (JSONException ignored) {ignored.printStackTrace();}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
String message;
|
String message;
|
||||||
|
@ -326,7 +327,7 @@ public class LoginActivity extends BaseActivity {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
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() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
JSONObject resobj;
|
JSONObject resobj;
|
||||||
|
|
|
@ -144,7 +144,7 @@ public class RemoteFollowActivity extends BaseActivity implements OnRetrieveRemo
|
||||||
Account account = new AccountDAO(getApplicationContext(),db).getAccountByID(userId);
|
Account account = new AccountDAO(getApplicationContext(),db).getAccountByID(userId);
|
||||||
String url = account.getAvatar();
|
String url = account.getAvatar();
|
||||||
if( url.startsWith("/") ){
|
if( url.startsWith("/") ){
|
||||||
url = "https://" + Helper.getLiveInstance(getApplicationContext()) + account.getAvatar();
|
url = Helper.getLiveInstanceWithProtocol(getApplicationContext()) + account.getAvatar();
|
||||||
}
|
}
|
||||||
Glide.with(getApplicationContext())
|
Glide.with(getApplicationContext())
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
|
|
|
@ -412,7 +412,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
|
||||||
}
|
}
|
||||||
String urlHeader = account.getHeader();
|
String urlHeader = account.getHeader();
|
||||||
if (urlHeader.startsWith("/")) {
|
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")) {
|
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);
|
pp_actionBar = findViewById(R.id.pp_actionBar);
|
||||||
String url = account.getAvatar();
|
String url = account.getAvatar();
|
||||||
if( url.startsWith("/") ){
|
if( url.startsWith("/") ){
|
||||||
url = "https://" + Helper.getLiveInstance(getApplicationContext()) + account.getAvatar();
|
url = Helper.getLiveInstanceWithProtocol(getApplicationContext()) + account.getAvatar();
|
||||||
}
|
}
|
||||||
Glide.with(getApplicationContext())
|
Glide.with(getApplicationContext())
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
|
|
|
@ -151,7 +151,7 @@ public class ShowConversationActivity extends BaseActivity implements OnRetrieve
|
||||||
Account account = new AccountDAO(getApplicationContext(),db).getAccountByID(userId);
|
Account account = new AccountDAO(getApplicationContext(),db).getAccountByID(userId);
|
||||||
String url = account.getAvatar();
|
String url = account.getAvatar();
|
||||||
if( url.startsWith("/") ){
|
if( url.startsWith("/") ){
|
||||||
url = "https://" + Helper.getLiveInstance(getApplicationContext()) + account.getAvatar();
|
url = Helper.getLiveInstanceWithProtocol(getApplicationContext()) + account.getAvatar();
|
||||||
}
|
}
|
||||||
Glide.with(getApplicationContext())
|
Glide.with(getApplicationContext())
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
|
|
|
@ -347,7 +347,7 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
||||||
|
|
||||||
String url = account.getAvatar();
|
String url = account.getAvatar();
|
||||||
if( url.startsWith("/") ){
|
if( url.startsWith("/") ){
|
||||||
url = "https://" + Helper.getLiveInstance(getApplicationContext()) + account.getAvatar();
|
url = Helper.getLiveInstanceWithProtocol(getApplicationContext()) + account.getAvatar();
|
||||||
}
|
}
|
||||||
Glide.with(getApplicationContext())
|
Glide.with(getApplicationContext())
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
|
|
|
@ -119,7 +119,7 @@ public class WebviewConnectActivity extends BaseActivity {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
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;
|
JSONObject resobj;
|
||||||
try {
|
try {
|
||||||
resobj = new JSONObject(response);
|
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.REDIRECT_URI + "="+ Uri.encode(Helper.REDIRECT_CONTENT_WEB);
|
||||||
queryString += "&" + Helper.RESPONSE_TYPE +"=code";
|
queryString += "&" + Helper.RESPONSE_TYPE +"=code";
|
||||||
queryString += "&" + Helper.SCOPE +"=" + Helper.OAUTH_SCOPES;
|
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 java.lang.ref.WeakReference;
|
||||||
import fr.gouv.etalab.mastodon.client.API;
|
import fr.gouv.etalab.mastodon.client.API;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Results;
|
import fr.gouv.etalab.mastodon.client.Entities.Results;
|
||||||
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRemoteAccountInterface;
|
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){
|
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.listener = onRetrieveRemoteAccountInterface;
|
||||||
this.contextReference = new WeakReference<>(context);
|
this.contextReference = new WeakReference<>(context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2030,7 +2030,7 @@ public class API {
|
||||||
|
|
||||||
|
|
||||||
private String getAbsoluteUrl(String action) {
|
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;
|
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);
|
item.setIcon(R.drawable.ic_person);
|
||||||
String url = account.getAvatar();
|
String url = account.getAvatar();
|
||||||
if( url.startsWith("/") ){
|
if( url.startsWith("/") ){
|
||||||
url = "https://" + Helper.getLiveInstance(activity) + account.getAvatar();
|
url = Helper.getLiveInstanceWithProtocol(activity) + account.getAvatar();
|
||||||
}
|
}
|
||||||
Glide.with(activity.getApplicationContext())
|
Glide.with(activity.getApplicationContext())
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
|
@ -1093,7 +1105,7 @@ public class Helper {
|
||||||
*/
|
*/
|
||||||
public static void loadPictureIcon(final Activity activity, String url, final ImageView imageView){
|
public static void loadPictureIcon(final Activity activity, String url, final ImageView imageView){
|
||||||
if( url.startsWith("/") ){
|
if( url.startsWith("/") ){
|
||||||
url = "https://" + Helper.getLiveInstance(activity) + url;
|
url = Helper.getLiveInstanceWithProtocol(activity) + url;
|
||||||
}
|
}
|
||||||
|
|
||||||
Glide.with(activity.getApplicationContext())
|
Glide.with(activity.getApplicationContext())
|
||||||
|
@ -1169,14 +1181,14 @@ public class Helper {
|
||||||
displayedName.setText(account.getDisplay_name());
|
displayedName.setText(account.getDisplay_name());
|
||||||
String url = account.getAvatar();
|
String url = account.getAvatar();
|
||||||
if( url.startsWith("/") ){
|
if( url.startsWith("/") ){
|
||||||
url = "https://" + Helper.getLiveInstance(activity) + account.getAvatar();
|
url = Helper.getLiveInstanceWithProtocol(activity) + account.getAvatar();
|
||||||
}
|
}
|
||||||
Glide.with(activity.getApplicationContext())
|
Glide.with(activity.getApplicationContext())
|
||||||
.load(url)
|
.load(url)
|
||||||
.into(profilePicture);
|
.into(profilePicture);
|
||||||
String urlHeader = account.getHeader();
|
String urlHeader = account.getHeader();
|
||||||
if( urlHeader.startsWith("/") ){
|
if( urlHeader.startsWith("/") ){
|
||||||
urlHeader = "https://" + Helper.getLiveInstance(activity) + account.getHeader();
|
urlHeader = Helper.getLiveInstanceWithProtocol(activity) + account.getHeader();
|
||||||
}
|
}
|
||||||
if (!urlHeader.contains("missing.png")) {
|
if (!urlHeader.contains("missing.png")) {
|
||||||
Glide.with(activity.getApplicationContext())
|
Glide.with(activity.getApplicationContext())
|
||||||
|
|
|
@ -156,95 +156,185 @@ public class LiveNotificationService extends Service {
|
||||||
private void taks(Account account){
|
private void taks(Account account){
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
HttpsURLConnection httpsURLConnection = null;
|
HttpsURLConnection httpsURLConnection = null;
|
||||||
|
HttpURLConnection httpURLConnection = null;
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
Helper.EventStreaming lastEvent = null;
|
Helper.EventStreaming lastEvent = null;
|
||||||
|
|
||||||
if( account != null){
|
if( account != null){
|
||||||
isRunning.get(account.getAcct()+account.getInstance());
|
isRunning.get(account.getAcct()+account.getInstance());
|
||||||
if(!isRunning.containsKey(account.getAcct()+account.getInstance()) || ! isRunning.get(account.getAcct()+account.getInstance())) {
|
if(!isRunning.containsKey(account.getAcct()+account.getInstance()) || ! isRunning.get(account.getAcct()+account.getInstance())) {
|
||||||
try {
|
if (Helper.instanceWithProtocol(account.getInstance()).startsWith("https")) {
|
||||||
URL url = new URL("https://" + account.getInstance() + "/api/v1/streaming/user");
|
try {
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
URL url = new URL("https://" + account.getInstance() + "/api/v1/streaming/user");
|
||||||
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + account.getToken());
|
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||||
httpsURLConnection.setRequestProperty("Connection", "Keep-Alive");
|
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + account.getToken());
|
||||||
httpsURLConnection.setRequestProperty("Keep-Alive", "header");
|
httpsURLConnection.setRequestProperty("Connection", "Keep-Alive");
|
||||||
httpsURLConnection.setRequestProperty("Connection", "close");
|
httpsURLConnection.setRequestProperty("Keep-Alive", "header");
|
||||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
httpsURLConnection.setRequestProperty("Connection", "close");
|
||||||
httpsURLConnection.setRequestMethod("GET");
|
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||||
if (httpsURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
httpsURLConnection.setRequestMethod("GET");
|
||||||
inputStream = new BufferedInputStream(httpsURLConnection.getInputStream());
|
if (httpsURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||||
reader = new BufferedReader(new InputStreamReader(inputStream));
|
inputStream = new BufferedInputStream(httpsURLConnection.getInputStream());
|
||||||
String event;
|
reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||||
Helper.EventStreaming eventStreaming;
|
String event;
|
||||||
while ((event = reader.readLine()) != null) {
|
Helper.EventStreaming eventStreaming;
|
||||||
isRunning.put(account.getAcct()+account.getInstance(), true);
|
while ((event = reader.readLine()) != null) {
|
||||||
if ((lastEvent == Helper.EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) {
|
isRunning.put(account.getAcct() + account.getInstance(), true);
|
||||||
switch (event.trim()) {
|
if ((lastEvent == Helper.EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) {
|
||||||
case "event: update":
|
switch (event.trim()) {
|
||||||
lastEvent = Helper.EventStreaming.UPDATE;
|
case "event: update":
|
||||||
break;
|
lastEvent = Helper.EventStreaming.UPDATE;
|
||||||
case "event: notification":
|
break;
|
||||||
lastEvent = Helper.EventStreaming.NOTIFICATION;
|
case "event: notification":
|
||||||
break;
|
lastEvent = Helper.EventStreaming.NOTIFICATION;
|
||||||
case "event: delete":
|
break;
|
||||||
lastEvent = Helper.EventStreaming.DELETE;
|
case "event: delete":
|
||||||
break;
|
lastEvent = Helper.EventStreaming.DELETE;
|
||||||
default:
|
break;
|
||||||
lastEvent = Helper.EventStreaming.NONE;
|
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 {
|
} else {
|
||||||
eventStreaming = Helper.EventStreaming.UPDATE;
|
if (!event.startsWith("data: ")) {
|
||||||
}
|
lastEvent = Helper.EventStreaming.NONE;
|
||||||
lastEvent = Helper.EventStreaming.NONE;
|
continue;
|
||||||
try {
|
}
|
||||||
JSONObject eventJson = new JSONObject(event);
|
event = event.substring(6);
|
||||||
onRetrieveStreaming(eventStreaming, account, eventJson);
|
if (lastEvent == Helper.EventStreaming.UPDATE) {
|
||||||
} catch (JSONException ignored) { ignored.printStackTrace();
|
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) {
|
} 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