Clean API
This commit is contained in:
parent
b7b3a37a16
commit
6f3a05f06f
|
@ -234,7 +234,7 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
else
|
||||
gnuapi = new GNUAPI(contextReference.get());
|
||||
if (apiAction == API.StatusAction.REPORT)
|
||||
statusCode = gnuapi.reportAction(status, comment);
|
||||
statusCode = gnuapi.reportAction(status);
|
||||
else if (apiAction == API.StatusAction.CREATESTATUS)
|
||||
statusCode = gnuapi.statusAction(status);
|
||||
else if (apiAction == API.StatusAction.MUTE_NOTIFICATIONS)
|
||||
|
|
|
@ -76,14 +76,14 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
GNUAPI gnuapi;
|
||||
if (account == null) {
|
||||
gnuapi = new GNUAPI(this.contextReference.get());
|
||||
apiResponse = gnuapi.getNotifications(type, max_id, display);
|
||||
apiResponse = gnuapi.getNotifications(type, max_id);
|
||||
} else {
|
||||
if (this.contextReference.get() == null) {
|
||||
apiResponse.setError(new Error());
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1152,6 +1152,7 @@ public class PeertubeAPI {
|
|||
* @param since_id String since the id
|
||||
* @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 {
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
|
@ -1381,7 +1382,7 @@ public class PeertubeAPI {
|
|||
httpsConnection.post(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
|
||||
break;
|
||||
case "DELETE":
|
||||
httpsConnection.delete(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
|
||||
httpsConnection.delete(getAbsoluteUrl(action), 60, null, prefKeyOauthTokenT);
|
||||
break;
|
||||
default:
|
||||
httpsConnection.put(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
|
||||
|
|
|
@ -21,8 +21,6 @@ import java.util.List;
|
|||
import java.util.Objects;
|
||||
|
||||
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.Attachment;
|
||||
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.Sqlite;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class PixelfedAPI {
|
||||
|
||||
|
||||
private Context context;
|
||||
private List<PixelFedStory> pixelFedStories;
|
||||
private List<PixelFedStoryItem> pixelFedStoryItems;
|
||||
private int tootPerPage;
|
||||
private String instance;
|
||||
private String prefKeyOauthTokenT;
|
||||
private APIResponse apiResponse;
|
||||
|
@ -53,10 +50,6 @@ public class PixelfedAPI {
|
|||
return;
|
||||
}
|
||||
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);
|
||||
if (Helper.getLiveInstance(context) != null)
|
||||
this.instance = Helper.getLiveInstance(context);
|
||||
|
@ -113,7 +106,7 @@ public class PixelfedAPI {
|
|||
pixelFedStory.setPhoto(jsonObject.getString("photo"));
|
||||
pixelFedStory.setName(jsonObject.getString("name"));
|
||||
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.setPixelFedStoryItems(parseStoryItems(jsonObject.getJSONArray("items")));
|
||||
} catch (JSONException ignored) {
|
||||
|
@ -161,8 +154,8 @@ public class PixelfedAPI {
|
|||
pixelFedStoryItem.setPreview(jsonObject.getString("preview"));
|
||||
pixelFedStoryItem.setLink(jsonObject.getString("link"));
|
||||
pixelFedStoryItem.setLinkText(jsonObject.getString("linkText"));
|
||||
pixelFedStoryItem.setTime(new Date(Long.valueOf(jsonObject.getString("time"))));
|
||||
pixelFedStoryItem.setExpires_at(new Date(Long.valueOf(jsonObject.getString("expires_at"))));
|
||||
pixelFedStoryItem.setTime(new Date(jsonObject.getLong("time")));
|
||||
pixelFedStoryItem.setExpires_at(new Date(jsonObject.getLong("expires_at")));
|
||||
pixelFedStoryItem.setSeen(jsonObject.getBoolean("seen"));
|
||||
} catch (JSONException ignored) {
|
||||
}
|
||||
|
@ -263,7 +256,7 @@ public class PixelfedAPI {
|
|||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getStoryItem(String id) {
|
||||
pixelFedStoryItems = new ArrayList<>();
|
||||
List<PixelFedStoryItem> pixelFedStoryItems = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
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);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
@ -296,47 +296,42 @@ public class NotificationsSyncJob extends Job {
|
|||
|
||||
final String finalNotificationUrl = notificationUrl;
|
||||
Helper.NotifType finalNotifType = notifType;
|
||||
Runnable myRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Glide.with(getContext())
|
||||
.asBitmap()
|
||||
.load(finalNotificationUrl)
|
||||
.listener(new RequestListener<Bitmap>() {
|
||||
Runnable myRunnable = () -> Glide.with(getContext())
|
||||
.asBitmap()
|
||||
.load(finalNotificationUrl)
|
||||
.listener(new RequestListener<Bitmap>() {
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
|
||||
@Override
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
|
||||
|
||||
notify_user(getContext(), account, intent, BitmapFactory.decodeResource(getContext().getResources(),
|
||||
getMainLogo(getContext())), finalNotifType, finalTitle, message);
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
|
||||
if (lastNotif == null || notifications.get(0).getId().compareTo(lastNotif) > 0) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notifications.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.into(new SimpleTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
|
||||
notify_user(getContext(), account, intent, resource, finalNotifType, finalTitle, message);
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
|
||||
if (lastNotif == null || notifications.get(0).getId().compareTo(lastNotif) > 0) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notifications.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
notify_user(getContext(), account, intent, BitmapFactory.decodeResource(getContext().getResources(),
|
||||
getMainLogo(getContext())), finalNotifType, finalTitle, message);
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
|
||||
if (lastNotif == null || notifications.get(0).getId().compareTo(lastNotif) > 0) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notifications.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.into(new SimpleTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
|
||||
notify_user(getContext(), account, intent, resource, finalNotifType, finalTitle, message);
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
|
||||
if (lastNotif == null || notifications.get(0).getId().compareTo(lastNotif) > 0) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notifications.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
});
|
||||
mainHandler.post(myRunnable);
|
||||
|
||||
}
|
||||
|
|
|
@ -252,7 +252,7 @@ public class LiveNotificationDelayedService extends Service {
|
|||
} else {
|
||||
GNUAPI gnuApi;
|
||||
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) {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue