Update messaging service to actually make requests to the request queue. Still WIP, since it will need to return data to server and whatnot.
This commit is contained in:
parent
d274d47c6c
commit
6cd22ee6ce
@ -7,13 +7,22 @@ import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
|
||||
import java.sql.Time;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import dev.garrettmills.starship.hyperlink.relay.ServerSentRequest;
|
||||
import dev.garrettmills.starship.hyperlink.util.APIv1;
|
||||
import dev.garrettmills.starship.hyperlink.util.GsonRequest;
|
||||
import dev.garrettmills.starship.hyperlink.util.NotAuthenticatedException;
|
||||
|
||||
public class MessagingService extends Service {
|
||||
private final Handler handler = new Handler();
|
||||
@ -49,11 +58,11 @@ public class MessagingService extends Service {
|
||||
TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
handler.post(() -> {
|
||||
if ( !tick() ) {
|
||||
stopSelf();
|
||||
}
|
||||
});
|
||||
handler.post(() -> {
|
||||
if ( !tick() ) {
|
||||
stopSelf();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -61,7 +70,27 @@ public class MessagingService extends Service {
|
||||
}
|
||||
|
||||
private boolean tick() {
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
|
||||
try {
|
||||
headers.put("X-Hyperlink-Access-Token", APIv1.getToken().getToken());
|
||||
} catch (NotAuthenticatedException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GsonRequest<ServerSentRequest[]> request = new GsonRequest<>(
|
||||
APIv1.resolveEndpoint("/request/queue"),
|
||||
ServerSentRequest[].class,
|
||||
headers,
|
||||
(Response.Listener<ServerSentRequest[]>) response -> {
|
||||
for (ServerSentRequest ssr : response) {
|
||||
handleServerSentRequest(ssr);
|
||||
}
|
||||
},
|
||||
error -> Log.e("MessagingService", error.getMessage())
|
||||
);
|
||||
|
||||
Hyperlink.httpRequestQueue.add(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -71,6 +100,6 @@ public class MessagingService extends Service {
|
||||
}
|
||||
|
||||
protected void handleServerSentRequest(ServerSentRequest request) {
|
||||
|
||||
Log.d("MessagingService", "Received server-sent request " + request.getUUID() + " to endpoint " + request.getEndpoint());
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
package dev.garrettmills.starship.hyperlink.relay;
|
||||
|
||||
public enum ServerRequestEndpoint {
|
||||
LIST_THREADS
|
||||
}
|
@ -2,13 +2,13 @@ package dev.garrettmills.starship.hyperlink.relay;
|
||||
|
||||
public class ServerSentRequest {
|
||||
private String server_request_id;
|
||||
private ServerRequestEndpoint endpoint;
|
||||
private String endpoint;
|
||||
|
||||
public String getUUID() {
|
||||
return server_request_id;
|
||||
}
|
||||
|
||||
public ServerRequestEndpoint getEndpoint() {
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user