MyApplication.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package com.ht.gate;
  2. import android.app.Application;
  3. import android.content.SharedPreferences;
  4. import androidx.annotation.NonNull;
  5. import com.ht.gate.domain.Meeting;
  6. import com.ht.gate.domain.Room;
  7. import com.ht.gate.domain.RoomMeetings;
  8. import java.text.SimpleDateFormat;
  9. import java.util.ArrayList;
  10. import java.util.Date;
  11. import java.util.List;
  12. import java.util.Locale;
  13. import java.util.Timer;
  14. import java.util.TimerTask;
  15. import okhttp3.OkHttpClient;
  16. import okhttp3.logging.HttpLoggingInterceptor;
  17. import retrofit2.Call;
  18. import retrofit2.Callback;
  19. import retrofit2.Response;
  20. public class MyApplication extends Application {
  21. public static List<Meeting> todayMeetings;
  22. @Override
  23. public void onCreate() {
  24. super.onCreate();
  25. SharedPreferences sharedPreferences = getSharedPreferences(SettingsActivity.PREF_NAME_SETTINGS, MODE_PRIVATE);
  26. String spaceName = sharedPreferences.getString(SettingsActivity.PREF_KEY_SPACE_NAME, null);
  27. if (spaceName == null) {
  28. spaceName = "财富管理室";
  29. sharedPreferences.edit().putString(SettingsActivity.PREF_KEY_SPACE_NAME, spaceName).apply();
  30. }
  31. RetrofitManager.getInstance().init();
  32. if (todayMeetings == null) {
  33. todayMeetings = new ArrayList<>();
  34. }
  35. Timer timer = new Timer();
  36. timer.schedule(new TimerTask() {
  37. @Override
  38. public void run() {
  39. Room room = Room.fromBase64(sharedPreferences.getString("room", null));
  40. if (room != null) {
  41. Date date = new Date();
  42. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
  43. String dateStr = simpleDateFormat.format(date);
  44. RetrofitManager.getInstance().getRetrofit().create(ApiService.class)
  45. .roomMeetings(dateStr + "00:00:00", dateStr + "23:59:59", room.getRoomNo()).enqueue(new Callback<List<RoomMeetings>>() {
  46. @Override
  47. public void onResponse(@NonNull Call<List<RoomMeetings>> call, @NonNull Response<List<RoomMeetings>> response) {
  48. }
  49. @Override
  50. public void onFailure(@NonNull Call<List<RoomMeetings>> call, @NonNull Throwable t) {
  51. }
  52. });
  53. }
  54. }
  55. }, 0, 60 * 1000);
  56. }
  57. }