|
|
@@ -37,6 +37,8 @@ public class MyApplication extends Application {
|
|
|
public static Room roomInfo;
|
|
|
public static String password;
|
|
|
|
|
|
+ private SharedPreferences sharedPreferences;
|
|
|
+
|
|
|
public static void setPassword(Context context, String password) {
|
|
|
MyApplication.password = password;
|
|
|
SharedPreferences sharedPreferences = context.getSharedPreferences(SettingsActivity.PREF_NAME_SETTINGS, MODE_PRIVATE);
|
|
|
@@ -46,7 +48,7 @@ public class MyApplication extends Application {
|
|
|
@Override
|
|
|
public void onCreate() {
|
|
|
super.onCreate();
|
|
|
- SharedPreferences sharedPreferences = getSharedPreferences(SettingsActivity.PREF_NAME_SETTINGS, MODE_PRIVATE);
|
|
|
+ sharedPreferences = getSharedPreferences(SettingsActivity.PREF_NAME_SETTINGS, MODE_PRIVATE);
|
|
|
roomInfo = Room.fromBase64(sharedPreferences.getString(Constants.PREF_ROOM_INFO, null));
|
|
|
password = sharedPreferences.getString(Constants.PREF_PASSWORD, null);
|
|
|
if (password == null && roomInfo != null) {
|
|
|
@@ -60,38 +62,50 @@ public class MyApplication extends Application {
|
|
|
todayMeetings = new ArrayList<>();
|
|
|
}
|
|
|
MockServer.start(this);
|
|
|
- Timer timer = new Timer();
|
|
|
- timer.schedule(new TimerTask() {
|
|
|
+ new Timer().schedule(new TimerTask() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- Room room = Room.fromBase64(sharedPreferences.getString(Constants.PREF_ROOM_INFO, null));
|
|
|
- if (room != null) {
|
|
|
- Date date = new Date();
|
|
|
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
|
|
|
- String dateStr = simpleDateFormat.format(date);
|
|
|
- RetrofitManager.getInstance().getRetrofit().create(ApiService.class)
|
|
|
- .roomMeetings(dateStr + "00:00:00", dateStr + "23:59:59", room.getRoomNo()).enqueue(new Callback<List<RoomMeetings>>() {
|
|
|
- @Override
|
|
|
- public void onResponse(@NonNull Call<List<RoomMeetings>> call, @NonNull Response<List<RoomMeetings>> response) {
|
|
|
- if (response.code() == 200) {
|
|
|
- todayMeetings = response.body();
|
|
|
- EventBus.getDefault().post(Constants.EVENT_MEETINGS);
|
|
|
- } else {
|
|
|
- try {
|
|
|
- Toasty.error(MyApplication.this, response.errorBody().string()).show();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ getMeetings();
|
|
|
+ }
|
|
|
+ }, 0, 10 * 60 * 1000);
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public void onFailure(@NonNull Call<List<RoomMeetings>> call, @NonNull Throwable t) {
|
|
|
- Toasty.info(MyApplication.this, "获取会议列表失败").show();
|
|
|
+ private void getMeetings() {
|
|
|
+ Room room = Room.fromBase64(sharedPreferences.getString(Constants.PREF_ROOM_INFO, null));
|
|
|
+ if (room != null) {
|
|
|
+ Date date = new Date();
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
|
|
|
+ String dateStr = simpleDateFormat.format(date);
|
|
|
+ RetrofitManager.getInstance().getRetrofit().create(ApiService.class)
|
|
|
+ .roomMeetings(dateStr + "00:00:00", dateStr + "23:59:59", room.getRoomNo()).enqueue(new Callback<List<RoomMeetings>>() {
|
|
|
+ @Override
|
|
|
+ public void onResponse(@NonNull Call<List<RoomMeetings>> call, @NonNull Response<List<RoomMeetings>> response) {
|
|
|
+ if (response.code() == 200) {
|
|
|
+ todayMeetings = response.body();
|
|
|
+ EventBus.getDefault().post(Constants.EVENT_MEETINGS);
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ Toasty.error(MyApplication.this, response.errorBody().string()).show();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(@NonNull Call<List<RoomMeetings>> call, @NonNull Throwable t) {
|
|
|
+ Toasty.info(MyApplication.this, "获取会议列表失败").show();
|
|
|
}
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateMeetings() {
|
|
|
+ new Timer().schedule(new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ getMeetings();
|
|
|
}
|
|
|
- }, 0, 10 * 60 * 1000);
|
|
|
+ }, 0);
|
|
|
}
|
|
|
}
|