Post media with GNUSocial + pagination
This commit is contained in:
parent
51a7cee34c
commit
6b4ccc0f2f
|
@ -3063,7 +3063,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
public void manageFloatingButton(boolean display){
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
boolean displayFollowInstance = sharedpreferences.getBoolean(Helper.SET_DISPLAY_FOLLOW_INSTANCE, true);
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE ||social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE ||social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA|| social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if (display) {
|
||||
tootShow();
|
||||
if (!displayFollowInstance)
|
||||
|
@ -3080,7 +3080,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}
|
||||
}
|
||||
public void tootShow(){
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE ||social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE ||social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA|| social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
toot.show();
|
||||
}else{
|
||||
toot.hide();
|
||||
|
|
|
@ -288,6 +288,8 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
Button toot_cw = findViewById(R.id.toot_cw);
|
||||
toot_space_left = findViewById(R.id.toot_space_left);
|
||||
toot_visibility = findViewById(R.id.toot_visibility);
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
toot_visibility.setVisibility(View.GONE);
|
||||
toot_picture = findViewById(R.id.toot_picture);
|
||||
toot_picture_container = findViewById(R.id.toot_picture_container);
|
||||
toot_content = findViewById(R.id.toot_content);
|
||||
|
|
|
@ -23,10 +23,12 @@ import java.util.List;
|
|||
import java.util.regex.Matcher;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.GNUAPI;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnPostStatusActionInterface;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
|
@ -57,22 +59,38 @@ public class PostStatusAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
||||
|
||||
boolean isconnected = Helper.isConnectedToInternet(contextReference.get(), Helper.getLiveInstance(contextReference.get()));
|
||||
if( isconnected) {
|
||||
if (account == null) {
|
||||
apiResponse = new API(this.contextReference.get()).postStatusAction(status);
|
||||
} else
|
||||
apiResponse = new API(this.contextReference.get(), account.getInstance(), account.getToken()).postStatusAction(status);
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU){
|
||||
boolean isconnected = Helper.isConnectedToInternet(contextReference.get(), Helper.getLiveInstance(contextReference.get()));
|
||||
if( isconnected) {
|
||||
if (account == null) {
|
||||
apiResponse = new API(this.contextReference.get()).postStatusAction(status);
|
||||
} else
|
||||
apiResponse = new API(this.contextReference.get(), account.getInstance(), account.getToken()).postStatusAction(status);
|
||||
}else {
|
||||
apiResponse = new APIResponse();
|
||||
Error error = new Error();
|
||||
error.setError(contextReference.get().getString(R.string.no_internet));
|
||||
error.setStatusCode(-33);
|
||||
apiResponse.setError(error);
|
||||
}
|
||||
}else {
|
||||
apiResponse = new APIResponse();
|
||||
Error error = new Error();
|
||||
error.setError(contextReference.get().getString(R.string.no_internet));
|
||||
error.setStatusCode(-33);
|
||||
apiResponse.setError(error);
|
||||
boolean isconnected = Helper.isConnectedToInternet(contextReference.get(), Helper.getLiveInstance(contextReference.get()));
|
||||
if( isconnected) {
|
||||
if (account == null) {
|
||||
apiResponse = new GNUAPI(this.contextReference.get()).postStatusAction(status);
|
||||
} else
|
||||
apiResponse = new GNUAPI(this.contextReference.get(), account.getInstance(), account.getToken()).postStatusAction(status);
|
||||
}else {
|
||||
apiResponse = new APIResponse();
|
||||
Error error = new Error();
|
||||
error.setError(contextReference.get().getString(R.string.no_internet));
|
||||
error.setStatusCode(-33);
|
||||
apiResponse.setError(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.List;
|
|||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Notification;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMissingNotificationsInterface;
|
||||
|
@ -41,6 +42,7 @@ public class RetrieveMissingNotificationsAsyncTask extends AsyncTask<Void, Void,
|
|||
private WeakReference<Context> contextReference;
|
||||
private List<Notification> notifications;
|
||||
private DisplayNotificationsFragment.Type type;
|
||||
private Error error;
|
||||
|
||||
public RetrieveMissingNotificationsAsyncTask(Context context, DisplayNotificationsFragment.Type type, String since_id, OnRetrieveMissingNotificationsInterface onRetrieveMissingNotifications){
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
|
@ -54,6 +56,7 @@ public class RetrieveMissingNotificationsAsyncTask extends AsyncTask<Void, Void,
|
|||
protected Void doInBackground(Void... params) {
|
||||
API api = new API(this.contextReference.get());
|
||||
APIResponse apiResponse = api.getNotificationsSince(type, since_id, 40, false);
|
||||
error = apiResponse.getError();
|
||||
since_id = apiResponse.getSince_id();
|
||||
notifications = apiResponse.getNotifications();
|
||||
if( notifications != null && notifications.size() > 0) {
|
||||
|
@ -64,6 +67,7 @@ public class RetrieveMissingNotificationsAsyncTask extends AsyncTask<Void, Void,
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveMissingNotifications(notifications);
|
||||
if( error == null)
|
||||
listener.onRetrieveMissingNotifications(notifications);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,11 @@ import android.os.AsyncTask;
|
|||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Results;
|
||||
import fr.gouv.etalab.mastodon.client.GNUAPI;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearchInterface;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
|
@ -39,7 +42,7 @@ public class RetrieveSearchAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
private String query;
|
||||
private Results results;
|
||||
private OnRetrieveSearchInterface listener;
|
||||
private API api;
|
||||
private Error error;
|
||||
private WeakReference<Context> contextReference;
|
||||
private boolean tagsOnly = false;
|
||||
|
||||
|
@ -58,37 +61,67 @@ public class RetrieveSearchAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
api = new API(this.contextReference.get());
|
||||
if( !tagsOnly)
|
||||
results = api.search(query);
|
||||
else {
|
||||
//search tags only
|
||||
results = api.search(query);
|
||||
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
List<String> cachedTags = new TagsCacheDAO(contextReference.get(), db).getBy(query);
|
||||
if( results != null && results.getHashtags() != null){
|
||||
//If cache contains matching tags
|
||||
if( cachedTags != null){
|
||||
for(String apiTag: results.getHashtags()){
|
||||
//Cache doesn't contain the tags coming from the api (case insensitive)
|
||||
if(!Helper.containsCaseInsensitive(apiTag, cachedTags)){
|
||||
cachedTags.add(apiTag); //It's added
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
API api = new API(this.contextReference.get());
|
||||
if (!tagsOnly)
|
||||
results = api.search(query);
|
||||
else {
|
||||
//search tags only
|
||||
results = api.search(query);
|
||||
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
List<String> cachedTags = new TagsCacheDAO(contextReference.get(), db).getBy(query);
|
||||
if (results != null && results.getHashtags() != null) {
|
||||
//If cache contains matching tags
|
||||
if (cachedTags != null) {
|
||||
for (String apiTag : results.getHashtags()) {
|
||||
//Cache doesn't contain the tags coming from the api (case insensitive)
|
||||
if (!Helper.containsCaseInsensitive(apiTag, cachedTags)) {
|
||||
cachedTags.add(apiTag); //It's added
|
||||
}
|
||||
}
|
||||
results.setHashtags(cachedTags);
|
||||
}
|
||||
} else if (cachedTags != null) {
|
||||
if (results == null)
|
||||
results = new Results();
|
||||
results.setHashtags(cachedTags);
|
||||
}
|
||||
}else if( cachedTags != null) {
|
||||
if( results == null)
|
||||
results = new Results();
|
||||
results.setHashtags(cachedTags);
|
||||
}
|
||||
error = api.getError();
|
||||
}else{
|
||||
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
|
||||
if (!tagsOnly)
|
||||
results = gnuapi.search(query);
|
||||
else {
|
||||
//search tags only
|
||||
results = gnuapi.search(query);
|
||||
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
List<String> cachedTags = new TagsCacheDAO(contextReference.get(), db).getBy(query);
|
||||
if (results != null && results.getHashtags() != null) {
|
||||
//If cache contains matching tags
|
||||
if (cachedTags != null) {
|
||||
for (String apiTag : results.getHashtags()) {
|
||||
//Cache doesn't contain the tags coming from the api (case insensitive)
|
||||
if (!Helper.containsCaseInsensitive(apiTag, cachedTags)) {
|
||||
cachedTags.add(apiTag); //It's added
|
||||
}
|
||||
}
|
||||
results.setHashtags(cachedTags);
|
||||
}
|
||||
} else if (cachedTags != null) {
|
||||
if (results == null)
|
||||
results = new Results();
|
||||
results.setHashtags(cachedTags);
|
||||
}
|
||||
}
|
||||
error = gnuapi.getError();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveSearch(results, api.getError());
|
||||
listener.onRetrieveSearch(results, error);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2090,6 +2090,12 @@ public class API {
|
|||
limit = 30;
|
||||
params.put("limit",String.valueOf(limit));
|
||||
|
||||
if( context == null){
|
||||
apiResponse = new APIResponse();
|
||||
Error error = new Error();
|
||||
apiResponse.setError(error);
|
||||
return apiResponse;
|
||||
}
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean notif_follow, notif_add, notif_mention, notif_share;
|
||||
StringBuilder parameters = new StringBuilder();
|
||||
|
|
|
@ -20,7 +20,6 @@ import android.content.SharedPreferences;
|
|||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
@ -625,11 +624,9 @@ public class GNUAPI {
|
|||
limit = 80;
|
||||
params.put("count",String.valueOf(limit));
|
||||
statuses = new ArrayList<>();
|
||||
Log.v(Helper.TAG,getAbsoluteUrl("/direct_messages.json"));
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/direct_messages.json"), 60, params, prefKeyOauthTokenT);
|
||||
Log.v(Helper.TAG,response);
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
|
@ -701,9 +698,11 @@ public class GNUAPI {
|
|||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/statuses/home_timeline.json"), 60, params, prefKeyOauthTokenT);
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
if( statuses.size() > 0) {
|
||||
apiResponse.setSince_id(statuses.get(0).getId());
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
e.printStackTrace();
|
||||
|
@ -793,9 +792,11 @@ public class GNUAPI {
|
|||
else
|
||||
url = getAbsoluteUrl("/statuses/public_and_external_timeline.json");
|
||||
String response = httpsConnection.get(url, 60, params, prefKeyOauthTokenT);
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
if( statuses.size() > 0) {
|
||||
apiResponse.setSince_id(statuses.get(0).getId());
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
|
@ -1386,29 +1387,20 @@ public class GNUAPI {
|
|||
if( status.getContentType() != null)
|
||||
params.put("content_type", status.getContentType());
|
||||
if( status.getIn_reply_to_id() != null)
|
||||
params.put("in_reply_to_id", status.getIn_reply_to_id());
|
||||
params.put("in_reply_to_status_id", status.getIn_reply_to_id());
|
||||
if( status.getMedia_attachments() != null && status.getMedia_attachments().size() > 0 ) {
|
||||
StringBuilder parameters = new StringBuilder();
|
||||
for(Attachment attachment: status.getMedia_attachments())
|
||||
parameters.append("media_ids[]=").append(attachment.getId()).append("&");
|
||||
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(12));
|
||||
params.put("media_ids[]", parameters.toString());
|
||||
parameters.append(attachment.getId()).append(",");
|
||||
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1));
|
||||
params.put("media_ids", parameters.toString());
|
||||
}
|
||||
if( status.getScheduled_at() != null)
|
||||
params.put("scheduled_at", status.getScheduled_at());
|
||||
if( status.isSensitive())
|
||||
params.put("sensitive", Boolean.toString(status.isSensitive()));
|
||||
if( status.getSpoiler_text() != null)
|
||||
try {
|
||||
params.put("spoiler_text", URLEncoder.encode(status.getSpoiler_text(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
params.put("spoiler_text", status.getSpoiler_text());
|
||||
}
|
||||
params.put("visibility", status.getVisibility());
|
||||
params.put("possibly_sensitive", Boolean.toString(status.isSensitive()));
|
||||
statuses = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.post(getAbsoluteUrl("/statuses"), 60, params, prefKeyOauthTokenT);
|
||||
String response = httpsConnection.post(getAbsoluteUrl("/statuses/update.json"), 60, params, prefKeyOauthTokenT);
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
Status statusreturned = parseStatuses(context, new JSONObject(response));
|
||||
|
@ -1632,8 +1624,7 @@ public class GNUAPI {
|
|||
}
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/search"), 60, params, prefKeyOauthTokenT);
|
||||
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/search.json"), 60, params, prefKeyOauthTokenT);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
e.printStackTrace();
|
||||
|
@ -2082,7 +2073,43 @@ public class GNUAPI {
|
|||
return attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response an unique attachment
|
||||
* @param resobj JSONObject
|
||||
* @return Relationship
|
||||
*/
|
||||
static Attachment parseUploadedAttachmentResponse(JSONObject resobj){
|
||||
|
||||
Attachment attachment = new Attachment();
|
||||
try {
|
||||
if(resobj.has("media_id") )
|
||||
attachment.setId(resobj.get("media_id").toString());
|
||||
if( resobj.has("image") && resobj.getJSONObject("image").has("image_type"))
|
||||
attachment.setType("Image");
|
||||
else if(resobj.has("image") && resobj.getJSONObject("gif").has("image_type"))
|
||||
attachment.setType("GifV");
|
||||
else
|
||||
attachment.setType("video");
|
||||
attachment.setUrl(resobj.get("media_url").toString());
|
||||
try {
|
||||
attachment.setDescription(resobj.get("description").toString());
|
||||
}catch (JSONException ignore){}
|
||||
try{
|
||||
attachment.setRemote_url(resobj.get("url").toString());
|
||||
}catch (JSONException ignore){}
|
||||
try{
|
||||
attachment.setPreview_url(resobj.get("thumb_url").toString());
|
||||
}catch (JSONException ignore){}
|
||||
try{
|
||||
attachment.setMeta(resobj.get("meta").toString());
|
||||
}catch (JSONException ignore){}
|
||||
try{
|
||||
attachment.setText_url(resobj.get("text_url").toString());
|
||||
}catch (JSONException ignore){}
|
||||
|
||||
} catch (JSONException ignored) {}
|
||||
return attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response an unique notification
|
||||
|
|
|
@ -56,8 +56,10 @@ import java.util.regex.Pattern;
|
|||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.MediaActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.TootActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
|
@ -333,8 +335,10 @@ public class HttpsConnection {
|
|||
httpsURLConnection.setDoOutput(true);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
httpsURLConnection.setRequestMethod("POST");
|
||||
if (token != null)
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if( token != null && token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
||||
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||
|
||||
|
||||
|
@ -389,8 +393,10 @@ public class HttpsConnection {
|
|||
httpURLConnection.setConnectTimeout(timeout * 1000);
|
||||
httpURLConnection.setDoOutput(true);
|
||||
httpURLConnection.setRequestMethod("POST");
|
||||
if (token != null)
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if( token != null && token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", token);
|
||||
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||
|
||||
httpURLConnection.getOutputStream().write(postDataBytes);
|
||||
|
@ -433,8 +439,10 @@ public class HttpsConnection {
|
|||
httpsURLConnection.setDoOutput(true);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
httpsURLConnection.setRequestMethod("POST");
|
||||
if (token != null)
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if( token != null && token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
||||
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||
|
||||
|
||||
|
@ -773,8 +781,10 @@ public class HttpsConnection {
|
|||
httpsURLConnection.setRequestProperty("Cache-Control", "no-cache");
|
||||
httpsURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
httpsURLConnection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+ boundary);
|
||||
if (token != null)
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if( token != null && token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
||||
httpsURLConnection.setFixedLengthStreamingMode(lengthSent);
|
||||
|
||||
OutputStream outputStream = httpsURLConnection.getOutputStream();
|
||||
|
@ -883,8 +893,10 @@ public class HttpsConnection {
|
|||
httpURLConnection.setRequestProperty("Cache-Control", "no-cache");
|
||||
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
httpURLConnection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+ boundary);
|
||||
if (token != null)
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if( token != null && token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", token);
|
||||
httpURLConnection.setFixedLengthStreamingMode(lengthSent);
|
||||
|
||||
OutputStream outputStream = httpURLConnection.getOutputStream();
|
||||
|
@ -980,8 +992,10 @@ public class HttpsConnection {
|
|||
httpsURLConnection.setRequestProperty("X-HTTP-Method-Override", "PATCH");
|
||||
httpsURLConnection.setRequestMethod("POST");
|
||||
}
|
||||
if (token != null)
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if( token != null && token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
||||
httpsURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||
httpsURLConnection.setDoOutput(true);
|
||||
|
@ -1046,8 +1060,10 @@ public class HttpsConnection {
|
|||
httpURLConnection.setRequestProperty("X-HTTP-Method-Override", "PATCH");
|
||||
httpURLConnection.setRequestMethod("POST");
|
||||
}
|
||||
if (token != null)
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if( token != null && token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", token);
|
||||
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||
httpURLConnection.setDoOutput(true);
|
||||
|
@ -1109,7 +1125,11 @@ public class HttpsConnection {
|
|||
token = tokenUsed;
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(context, db).getAccountByToken(token);
|
||||
final URL url = new URL("https://" + account.getInstance() + "/api/v1/media");
|
||||
URL url;
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
url = new URL("https://" + account.getInstance() + "/api/v1/media");
|
||||
else
|
||||
url = new URL("https://" + account.getInstance() + "/api/media/upload.json");
|
||||
ByteArrayOutputStream ous = null;
|
||||
try {
|
||||
try {
|
||||
|
@ -1132,9 +1152,11 @@ public class HttpsConnection {
|
|||
int lengthSent = pixels.length;
|
||||
lengthSent += (twoHyphens + boundary + lineEnd).getBytes().length;
|
||||
lengthSent += (twoHyphens + boundary + twoHyphens +lineEnd).getBytes().length;
|
||||
lengthSent += ("Content-Disposition: form-data; name=\"file\"; filename=\""+fileName+"\"" + lineEnd).getBytes().length;
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
lengthSent += ("Content-Disposition: form-data; name=\"file\"; filename=\""+fileName+"\"" + lineEnd).getBytes().length;
|
||||
else
|
||||
lengthSent += ("Content-Disposition: form-data; name=\"media\"; filename=\""+fileName+"\"" + lineEnd).getBytes().length;
|
||||
lengthSent += 2 * (lineEnd).getBytes().length;
|
||||
|
||||
if (proxy != null)
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
else
|
||||
|
@ -1148,8 +1170,10 @@ public class HttpsConnection {
|
|||
httpsURLConnection.setUseCaches(false);
|
||||
|
||||
httpsURLConnection.setRequestMethod("POST");
|
||||
if (token != null)
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if( token != null && token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
||||
httpsURLConnection.setRequestProperty("Connection", "Keep-Alive");
|
||||
httpsURLConnection.setRequestProperty("Cache-Control", "no-cache");
|
||||
httpsURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
|
@ -1159,7 +1183,10 @@ public class HttpsConnection {
|
|||
DataOutputStream request = new DataOutputStream(httpsURLConnection.getOutputStream());
|
||||
|
||||
request.writeBytes(twoHyphens + boundary + lineEnd);
|
||||
request.writeBytes("Content-Disposition: form-data; name=\"file\"; filename=\""+fileName+"\"" + lineEnd);
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
request.writeBytes("Content-Disposition: form-data; name=\"file\"; filename=\""+fileName+"\"" + lineEnd);
|
||||
else
|
||||
request.writeBytes("Content-Disposition: form-data; name=\"media\"; filename=\""+fileName+"\"" + lineEnd);
|
||||
request.writeBytes(lineEnd);
|
||||
|
||||
//request.write(pixels);
|
||||
|
@ -1218,8 +1245,11 @@ public class HttpsConnection {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
final Attachment attachment = API.parseAttachmentResponse(new JSONObject(response));
|
||||
Attachment attachment;
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
attachment = API.parseAttachmentResponse(new JSONObject(response));
|
||||
else
|
||||
attachment = GNUAPI.parseUploadedAttachmentResponse(new JSONObject(response));
|
||||
responseStreamReader.close();
|
||||
responseStream.close();
|
||||
httpsURLConnection.getInputStream().close();
|
||||
|
@ -1304,8 +1334,10 @@ public class HttpsConnection {
|
|||
httpURLConnection.setUseCaches(false);
|
||||
|
||||
httpURLConnection.setRequestMethod("POST");
|
||||
if (token != null)
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if( token != null && token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", token);
|
||||
httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
|
||||
httpURLConnection.setRequestProperty("Cache-Control", "no-cache");
|
||||
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
|
@ -1373,7 +1405,11 @@ public class HttpsConnection {
|
|||
}});
|
||||
|
||||
|
||||
final Attachment attachment = API.parseAttachmentResponse(new JSONObject(response));
|
||||
Attachment attachment;
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
attachment = API.parseAttachmentResponse(new JSONObject(response));
|
||||
else
|
||||
attachment = GNUAPI.parseUploadedAttachmentResponse(new JSONObject(response));
|
||||
responseStreamReader.close();
|
||||
responseStream.close();
|
||||
httpURLConnection.getInputStream().close();
|
||||
|
@ -1432,8 +1468,10 @@ public class HttpsConnection {
|
|||
httpsURLConnection.setRequestProperty("User-Agent", Helper.USER_AGENT);
|
||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
if (token != null)
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if( token != null && token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
||||
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||
|
||||
httpsURLConnection.setRequestMethod("PUT");
|
||||
|
@ -1489,8 +1527,10 @@ public class HttpsConnection {
|
|||
httpURLConnection = (HttpURLConnection) url.openConnection();
|
||||
httpURLConnection.setRequestProperty("User-Agent", Helper.USER_AGENT);
|
||||
httpURLConnection.setConnectTimeout(timeout * 1000);
|
||||
if (token != null)
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if( token != null && token.startsWith("Basic "))
|
||||
httpURLConnection.setRequestProperty("Authorization", token);
|
||||
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
||||
|
||||
httpURLConnection.setRequestMethod("PUT");
|
||||
|
@ -1556,8 +1596,10 @@ public class HttpsConnection {
|
|||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setRequestProperty("User-Agent", Helper.USER_AGENT);
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
if (token != null)
|
||||
if (token != null && !token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
|
||||
else if( token != null && token.startsWith("Basic "))
|
||||
httpsURLConnection.setRequestProperty("Authorization", token);
|
||||
httpsURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
httpsURLConnection.setRequestMethod("DELETE");
|
||||
httpsURLConnection.setConnectTimeout(timeout * 1000);
|
||||
|
|
Loading…
Reference in New Issue