Clean API
This commit is contained in:
parent
b7b3a37a16
commit
6f3a05f06f
|
@ -234,7 +234,7 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
else
|
else
|
||||||
gnuapi = new GNUAPI(contextReference.get());
|
gnuapi = new GNUAPI(contextReference.get());
|
||||||
if (apiAction == API.StatusAction.REPORT)
|
if (apiAction == API.StatusAction.REPORT)
|
||||||
statusCode = gnuapi.reportAction(status, comment);
|
statusCode = gnuapi.reportAction(status);
|
||||||
else if (apiAction == API.StatusAction.CREATESTATUS)
|
else if (apiAction == API.StatusAction.CREATESTATUS)
|
||||||
statusCode = gnuapi.statusAction(status);
|
statusCode = gnuapi.statusAction(status);
|
||||||
else if (apiAction == API.StatusAction.MUTE_NOTIFICATIONS)
|
else if (apiAction == API.StatusAction.MUTE_NOTIFICATIONS)
|
||||||
|
|
|
@ -76,14 +76,14 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
|
||||||
GNUAPI gnuapi;
|
GNUAPI gnuapi;
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
gnuapi = new GNUAPI(this.contextReference.get());
|
gnuapi = new GNUAPI(this.contextReference.get());
|
||||||
apiResponse = gnuapi.getNotifications(type, max_id, display);
|
apiResponse = gnuapi.getNotifications(type, max_id);
|
||||||
} else {
|
} else {
|
||||||
if (this.contextReference.get() == null) {
|
if (this.contextReference.get() == null) {
|
||||||
apiResponse.setError(new Error());
|
apiResponse.setError(new Error());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
gnuapi = new GNUAPI(this.contextReference.get(), account.getInstance(), account.getToken());
|
gnuapi = new GNUAPI(this.contextReference.get(), account.getInstance(), account.getToken());
|
||||||
apiResponse = gnuapi.getNotificationsSince(type, max_id, display);
|
apiResponse = gnuapi.getNotificationsSince(type, max_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1152,6 +1152,7 @@ public class PeertubeAPI {
|
||||||
* @param since_id String since the id
|
* @param since_id String since the id
|
||||||
* @return APIResponse
|
* @return APIResponse
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("SameParameterValue")
|
||||||
private APIResponse getTL(String action, String sort, String filter, String max_id, String since_id, String min_id) throws HttpsConnection.HttpsConnectionException {
|
private APIResponse getTL(String action, String sort, String filter, String max_id, String since_id, String min_id) throws HttpsConnection.HttpsConnectionException {
|
||||||
|
|
||||||
HashMap<String, String> params = new HashMap<>();
|
HashMap<String, String> params = new HashMap<>();
|
||||||
|
@ -1381,7 +1382,7 @@ public class PeertubeAPI {
|
||||||
httpsConnection.post(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
|
httpsConnection.post(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
|
||||||
break;
|
break;
|
||||||
case "DELETE":
|
case "DELETE":
|
||||||
httpsConnection.delete(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
|
httpsConnection.delete(getAbsoluteUrl(action), 60, null, prefKeyOauthTokenT);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
httpsConnection.put(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
|
httpsConnection.put(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
|
||||||
|
|
|
@ -21,8 +21,6 @@ import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
import app.fedilab.android.activities.MainActivity;
|
|
||||||
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
|
|
||||||
import app.fedilab.android.client.Entities.Account;
|
import app.fedilab.android.client.Entities.Account;
|
||||||
import app.fedilab.android.client.Entities.Attachment;
|
import app.fedilab.android.client.Entities.Attachment;
|
||||||
import app.fedilab.android.client.Entities.Error;
|
import app.fedilab.android.client.Entities.Error;
|
||||||
|
@ -33,13 +31,12 @@ import app.fedilab.android.helper.Helper;
|
||||||
import app.fedilab.android.sqlite.AccountDAO;
|
import app.fedilab.android.sqlite.AccountDAO;
|
||||||
import app.fedilab.android.sqlite.Sqlite;
|
import app.fedilab.android.sqlite.Sqlite;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class PixelfedAPI {
|
public class PixelfedAPI {
|
||||||
|
|
||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
private List<PixelFedStory> pixelFedStories;
|
private List<PixelFedStory> pixelFedStories;
|
||||||
private List<PixelFedStoryItem> pixelFedStoryItems;
|
|
||||||
private int tootPerPage;
|
|
||||||
private String instance;
|
private String instance;
|
||||||
private String prefKeyOauthTokenT;
|
private String prefKeyOauthTokenT;
|
||||||
private APIResponse apiResponse;
|
private APIResponse apiResponse;
|
||||||
|
@ -53,10 +50,6 @@ public class PixelfedAPI {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
tootPerPage = sharedpreferences.getInt(Helper.SET_TOOT_PER_PAGE, Helper.TOOTS_PER_PAGE);
|
|
||||||
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED && tootPerPage > 30) {
|
|
||||||
tootPerPage = 30;
|
|
||||||
}
|
|
||||||
this.prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
this.prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||||
if (Helper.getLiveInstance(context) != null)
|
if (Helper.getLiveInstance(context) != null)
|
||||||
this.instance = Helper.getLiveInstance(context);
|
this.instance = Helper.getLiveInstance(context);
|
||||||
|
@ -113,7 +106,7 @@ public class PixelfedAPI {
|
||||||
pixelFedStory.setPhoto(jsonObject.getString("photo"));
|
pixelFedStory.setPhoto(jsonObject.getString("photo"));
|
||||||
pixelFedStory.setName(jsonObject.getString("name"));
|
pixelFedStory.setName(jsonObject.getString("name"));
|
||||||
pixelFedStory.setLink(jsonObject.getString("link"));
|
pixelFedStory.setLink(jsonObject.getString("link"));
|
||||||
pixelFedStory.setLastUpdated(new Date(Long.valueOf(jsonObject.getString("lastUpdated"))));
|
pixelFedStory.setLastUpdated(new Date(jsonObject.getLong("lastUpdated")));
|
||||||
pixelFedStory.setSeen(jsonObject.getBoolean("seen"));
|
pixelFedStory.setSeen(jsonObject.getBoolean("seen"));
|
||||||
pixelFedStory.setPixelFedStoryItems(parseStoryItems(jsonObject.getJSONArray("items")));
|
pixelFedStory.setPixelFedStoryItems(parseStoryItems(jsonObject.getJSONArray("items")));
|
||||||
} catch (JSONException ignored) {
|
} catch (JSONException ignored) {
|
||||||
|
@ -161,8 +154,8 @@ public class PixelfedAPI {
|
||||||
pixelFedStoryItem.setPreview(jsonObject.getString("preview"));
|
pixelFedStoryItem.setPreview(jsonObject.getString("preview"));
|
||||||
pixelFedStoryItem.setLink(jsonObject.getString("link"));
|
pixelFedStoryItem.setLink(jsonObject.getString("link"));
|
||||||
pixelFedStoryItem.setLinkText(jsonObject.getString("linkText"));
|
pixelFedStoryItem.setLinkText(jsonObject.getString("linkText"));
|
||||||
pixelFedStoryItem.setTime(new Date(Long.valueOf(jsonObject.getString("time"))));
|
pixelFedStoryItem.setTime(new Date(jsonObject.getLong("time")));
|
||||||
pixelFedStoryItem.setExpires_at(new Date(Long.valueOf(jsonObject.getString("expires_at"))));
|
pixelFedStoryItem.setExpires_at(new Date(jsonObject.getLong("expires_at")));
|
||||||
pixelFedStoryItem.setSeen(jsonObject.getBoolean("seen"));
|
pixelFedStoryItem.setSeen(jsonObject.getBoolean("seen"));
|
||||||
} catch (JSONException ignored) {
|
} catch (JSONException ignored) {
|
||||||
}
|
}
|
||||||
|
@ -263,7 +256,7 @@ public class PixelfedAPI {
|
||||||
* @return APIResponse
|
* @return APIResponse
|
||||||
*/
|
*/
|
||||||
public APIResponse getStoryItem(String id) {
|
public APIResponse getStoryItem(String id) {
|
||||||
pixelFedStoryItems = new ArrayList<>();
|
List<PixelFedStoryItem> pixelFedStoryItems = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||||
String response = httpsConnection.get(getAbsoluteUrl(String.format("/item/%s", id)), 10, null, prefKeyOauthTokenT);
|
String response = httpsConnection.get(getAbsoluteUrl(String.format("/item/%s", id)), 10, null, prefKeyOauthTokenT);
|
||||||
|
|
|
@ -146,7 +146,7 @@ public class NotificationsSyncJob extends Job {
|
||||||
apiResponse = api.getNotificationsSince(DisplayNotificationsFragment.Type.ALL, null, false);
|
apiResponse = api.getNotificationsSince(DisplayNotificationsFragment.Type.ALL, null, false);
|
||||||
} else {
|
} else {
|
||||||
GNUAPI gnuApi = new GNUAPI(getContext(), account.getInstance(), account.getToken());
|
GNUAPI gnuApi = new GNUAPI(getContext(), account.getInstance(), account.getToken());
|
||||||
apiResponse = gnuApi.getNotificationsSince(DisplayNotificationsFragment.Type.ALL, null, false);
|
apiResponse = gnuApi.getNotificationsSince(DisplayNotificationsFragment.Type.ALL, null);
|
||||||
}
|
}
|
||||||
onRetrieveNotifications(apiResponse, account);
|
onRetrieveNotifications(apiResponse, account);
|
||||||
}
|
}
|
||||||
|
@ -296,10 +296,7 @@ public class NotificationsSyncJob extends Job {
|
||||||
|
|
||||||
final String finalNotificationUrl = notificationUrl;
|
final String finalNotificationUrl = notificationUrl;
|
||||||
Helper.NotifType finalNotifType = notifType;
|
Helper.NotifType finalNotifType = notifType;
|
||||||
Runnable myRunnable = new Runnable() {
|
Runnable myRunnable = () -> Glide.with(getContext())
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Glide.with(getContext())
|
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
.load(finalNotificationUrl)
|
.load(finalNotificationUrl)
|
||||||
.listener(new RequestListener<Bitmap>() {
|
.listener(new RequestListener<Bitmap>() {
|
||||||
|
@ -335,8 +332,6 @@ public class NotificationsSyncJob extends Job {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
};
|
|
||||||
mainHandler.post(myRunnable);
|
mainHandler.post(myRunnable);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,7 +252,7 @@ public class LiveNotificationDelayedService extends Service {
|
||||||
} else {
|
} else {
|
||||||
GNUAPI gnuApi;
|
GNUAPI gnuApi;
|
||||||
gnuApi = new GNUAPI(getApplicationContext(), account.getInstance(), account.getToken());
|
gnuApi = new GNUAPI(getApplicationContext(), account.getInstance(), account.getToken());
|
||||||
apiResponse = gnuApi.getNotificationsSince(DisplayNotificationsFragment.Type.ALL, last_notifid, false);
|
apiResponse = gnuApi.getNotificationsSince(DisplayNotificationsFragment.Type.ALL, last_notifid);
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue