Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- the managerLauncherApi file:
- package com.phehossof.launcher;
- import com.google.gson.GsonBuilder;
- import java.util.ArrayList;
- import java.util.List;
- import retrofit2.Call;
- import retrofit2.Callback;
- import retrofit2.Retrofit;
- import retrofit2.converter.gson.GsonConverterFactory;
- class ManagerLauncherApi {
- private static InterfaceLauncherApi service;
- private static ManagerLauncherApi managerLauncherApi;
- ManagerLauncherApi() {
- String BASE_URL = "http://phoenixhospman.com/api/launcher/";
- Retrofit retrofit = new Retrofit.Builder()
- .baseUrl(BASE_URL)
- .addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
- .build();
- service = retrofit.create(InterfaceLauncherApi.class);
- }
- static synchronized ManagerLauncherApi getInstance() {
- if (managerLauncherApi == null) {
- managerLauncherApi = new ManagerLauncherApi();
- }
- return managerLauncherApi;
- }
- InterfaceLauncherApi getApi() {
- return service;
- }
- void logon(String username, String password, Callback<List<ObjectUser>> callback) {
- Call<List<ObjectUser>> logonCall = service.logon(username, password);
- logonCall.enqueue(callback);
- }
- void getGradeName(int grade, Callback<List<ObjectGrade>> callback) {
- Call<List<ObjectGrade>> gradeNameCall = service.getGradeName(grade);
- gradeNameCall.enqueue(callback);
- }
- void getDepartmentName(int department, Callback<List<ObjectDepartment>> callback) {
- Call<List<ObjectDepartment>> departmentCall = service.getDepartmentName(department);
- departmentCall.enqueue(callback);
- }
- }
- and in the interfaceLauncherApi file
- package com.phehossof.launcher;
- import java.util.ArrayList;
- import java.util.List;
- import retrofit2.Call;
- import retrofit2.http.GET;
- import retrofit2.http.Path;
- public interface InterfaceLauncherApi {
- @GET("logon/{username}/{password}")
- Call<List<ObjectUser>> logon(@Path("username") String username,
- @Path("password") String password);
- @GET("getGradeName/{grade}")
- Call<List<ObjectGrade>> getGradeName(@Path("grade") int grade);
- @GET("getDepartmentName/{department}")
- Call<List<ObjectDepartment>> getDepartmentName(@Path("department") int department);
- }
Advertisement
Add Comment
Please, Sign In to add comment