tlmarker1968

Untitled

Oct 22nd, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1. the managerLauncherApi file:
  2.  
  3. package com.phehossof.launcher;
  4.  
  5. import com.google.gson.GsonBuilder;
  6.  
  7. import java.util.ArrayList;
  8. import java.util.List;
  9.  
  10. import retrofit2.Call;
  11. import retrofit2.Callback;
  12. import retrofit2.Retrofit;
  13. import retrofit2.converter.gson.GsonConverterFactory;
  14.  
  15. class ManagerLauncherApi {
  16.  
  17.     private static InterfaceLauncherApi service;
  18.     private static ManagerLauncherApi managerLauncherApi;
  19.  
  20.     ManagerLauncherApi() {
  21.         String BASE_URL = "http://phoenixhospman.com/api/launcher/";
  22.         Retrofit retrofit = new Retrofit.Builder()
  23.                 .baseUrl(BASE_URL)
  24.                 .addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
  25.                 .build();
  26.         service = retrofit.create(InterfaceLauncherApi.class);
  27.     }
  28.  
  29.     static synchronized ManagerLauncherApi getInstance() {
  30.         if (managerLauncherApi == null) {
  31.             managerLauncherApi = new ManagerLauncherApi();
  32.         }
  33.         return managerLauncherApi;
  34.     }
  35.  
  36.     InterfaceLauncherApi getApi() {
  37.         return service;
  38.     }
  39.  
  40.     void logon(String username, String password, Callback<List<ObjectUser>> callback) {
  41.         Call<List<ObjectUser>> logonCall = service.logon(username, password);
  42.         logonCall.enqueue(callback);
  43.     }
  44.  
  45.     void getGradeName(int grade, Callback<List<ObjectGrade>> callback) {
  46.         Call<List<ObjectGrade>> gradeNameCall = service.getGradeName(grade);
  47.         gradeNameCall.enqueue(callback);
  48.     }
  49.  
  50.     void getDepartmentName(int department, Callback<List<ObjectDepartment>> callback) {
  51.         Call<List<ObjectDepartment>> departmentCall = service.getDepartmentName(department);
  52.         departmentCall.enqueue(callback);
  53.     }
  54. }
  55.  
  56. and in the interfaceLauncherApi file
  57.  
  58. package com.phehossof.launcher;
  59.  
  60. import java.util.ArrayList;
  61. import java.util.List;
  62.  
  63. import retrofit2.Call;
  64. import retrofit2.http.GET;
  65. import retrofit2.http.Path;
  66.  
  67. public interface InterfaceLauncherApi {
  68.  
  69.     @GET("logon/{username}/{password}")
  70.     Call<List<ObjectUser>> logon(@Path("username") String username,
  71.                                  @Path("password") String password);
  72.  
  73.     @GET("getGradeName/{grade}")
  74.     Call<List<ObjectGrade>> getGradeName(@Path("grade") int grade);
  75.  
  76.     @GET("getDepartmentName/{department}")
  77.     Call<List<ObjectDepartment>> getDepartmentName(@Path("department") int department);
  78. }
Advertisement
Add Comment
Please, Sign In to add comment