feat: hacking together a prototype for the api abstraction layer

So far it works for the home timelines, next I gotta figure out how to see what type of server a logged in account is from
This commit is contained in:
LucasGGamerM 2023-05-09 20:50:26 -03:00
parent eb78823cb1
commit 3c14ec8195
2 changed files with 7 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import android.util.Log;
import org.joinmastodon.android.BuildConfig;
import org.joinmastodon.android.MastodonApp;
import org.joinmastodon.android.api.adapter.ApiAdapter;
import org.joinmastodon.android.api.requests.notifications.GetNotifications;
import org.joinmastodon.android.api.requests.timelines.GetHomeTimeline;
import org.joinmastodon.android.api.session.AccountSession;
@ -88,7 +89,8 @@ public class CacheController{
Log.w(TAG, "getHomeTimeline: corrupted status object in database", x);
}
}
new GetHomeTimeline(maxID, null, count, null)
ApiAdapter apiAdapter = new ApiAdapter(ApiAdapter.ServerType.MASTODON);
apiAdapter.getHomeTimeline(maxID, null, count, null)
.setCallback(new Callback<>(){
@Override
public void onSuccess(List<Status> result){

View File

@ -5,6 +5,8 @@ import org.joinmastodon.android.api.requests.statuses.GetStatusByID;
import org.joinmastodon.android.api.requests.timelines.GetHomeTimeline;
import org.joinmastodon.android.model.Status;
import java.util.List;
public class ApiAdapter {
public final ServerType serverType;
@ -12,7 +14,7 @@ public class ApiAdapter {
this.serverType = serverType;
}
public MastodonAPIRequest getPostById(String id){
public MastodonAPIRequest<?> getPostById(String id){
switch (serverType){
case MASTODON -> {
return new GetStatusByID(id);
@ -24,7 +26,7 @@ public class ApiAdapter {
return null;
}
public MastodonAPIRequest getHomeTimeline(String maxID, String minID, int limit, String sinceID){
public MastodonAPIRequest<List<Status>> getHomeTimeline(String maxID, String minID, int limit, String sinceID){
switch (serverType){
case MASTODON -> {
return new GetHomeTimeline(maxID, minID, limit, sinceID);