|
@@ -16,14 +16,19 @@ import com.squareup.picasso.Picasso;
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Comparator;
|
|
import java.util.Comparator;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
import java.util.Locale;
|
|
|
import java.util.Timer;
|
|
import java.util.Timer;
|
|
|
import java.util.TimerTask;
|
|
import java.util.TimerTask;
|
|
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
|
+import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import cat.ereza.customactivityoncrash.config.CaocConfig;
|
|
import cat.ereza.customactivityoncrash.config.CaocConfig;
|
|
|
import es.dmoral.toasty.Toasty;
|
|
import es.dmoral.toasty.Toasty;
|
|
@@ -35,25 +40,25 @@ import retrofit2.Response;
|
|
|
|
|
|
|
|
public class MyApplication extends Application {
|
|
public class MyApplication extends Application {
|
|
|
|
|
|
|
|
- public static List<RoomMeetings> todayMeetings;
|
|
|
|
|
|
|
+ public static List<Meeting> todayMeetings;
|
|
|
public static Room roomInfo;
|
|
public static Room roomInfo;
|
|
|
private static String password;
|
|
private static String password;
|
|
|
|
|
|
|
|
|
|
+ private ScheduledExecutorService executorService;
|
|
|
private SharedPreferences sharedPreferences;
|
|
private SharedPreferences sharedPreferences;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
public static void setPassword(Context context, String password) {
|
|
public static void setPassword(Context context, String password) {
|
|
|
MyApplication.password = password;
|
|
MyApplication.password = password;
|
|
|
SharedPreferences sharedPreferences = context.getSharedPreferences(SettingsActivity.PREF_NAME_SETTINGS, MODE_PRIVATE);
|
|
SharedPreferences sharedPreferences = context.getSharedPreferences(SettingsActivity.PREF_NAME_SETTINGS, MODE_PRIVATE);
|
|
|
sharedPreferences.edit().putString(Constants.PREF_PASSWORD, password).apply();
|
|
sharedPreferences.edit().putString(Constants.PREF_PASSWORD, password).apply();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static String getPassword() {
|
|
|
|
|
- return password;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onCreate() {
|
|
public void onCreate() {
|
|
|
super.onCreate();
|
|
super.onCreate();
|
|
|
|
|
+ executorService = Executors.newScheduledThreadPool(2);
|
|
|
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));
|
|
roomInfo = Room.fromBase64(sharedPreferences.getString(Constants.PREF_ROOM_INFO, null));
|
|
|
if (roomInfo != null) {
|
|
if (roomInfo != null) {
|
|
@@ -70,12 +75,16 @@ public class MyApplication extends Application {
|
|
|
todayMeetings = new ArrayList<>();
|
|
todayMeetings = new ArrayList<>();
|
|
|
}
|
|
}
|
|
|
MockServer.start(this);
|
|
MockServer.start(this);
|
|
|
- new Timer().schedule(new TimerTask() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- getMeetings();
|
|
|
|
|
- }
|
|
|
|
|
- }, 0, 10 * 1000);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ executorService.scheduleAtFixedRate(this::getMeetings, 0, 10 * 1000, TimeUnit.MILLISECONDS);
|
|
|
|
|
+// new Timer().schedule(new TimerTask() {
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public void run() {
|
|
|
|
|
+// getMeetings();
|
|
|
|
|
+// }
|
|
|
|
|
+// }, 0, 10 * 1000);
|
|
|
|
|
+
|
|
|
|
|
+ SoundUtil.init(this);
|
|
|
|
|
|
|
|
CaocConfig.Builder.create()
|
|
CaocConfig.Builder.create()
|
|
|
.backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT) //default: CaocConfig.BACKGROUND_MODE_SHOW_CUSTOM
|
|
.backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT) //default: CaocConfig.BACKGROUND_MODE_SHOW_CUSTOM
|
|
@@ -101,23 +110,39 @@ public class MyApplication extends Application {
|
|
|
@Override
|
|
@Override
|
|
|
public void onResponse(@NonNull Call<List<RoomMeetings>> call, @NonNull Response<List<RoomMeetings>> response) {
|
|
public void onResponse(@NonNull Call<List<RoomMeetings>> call, @NonNull Response<List<RoomMeetings>> response) {
|
|
|
if (response.code() == 200) {
|
|
if (response.code() == 200) {
|
|
|
- todayMeetings = response.body();
|
|
|
|
|
- if (todayMeetings != null) {
|
|
|
|
|
- for (RoomMeetings todayMeeting : todayMeetings) {
|
|
|
|
|
- if (todayMeeting.getMeetings() != null) {
|
|
|
|
|
- todayMeeting.getMeetings().sort((o1, o2) -> {
|
|
|
|
|
- try {
|
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
|
|
|
|
|
- Date date1 = sdf.parse(o1.getBeginTimeStr());
|
|
|
|
|
- Date date2 = sdf.parse(o2.getBeginTimeStr());
|
|
|
|
|
- return date1.compareTo(date2);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- return 0;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (response.body() == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Meeting> list = new ArrayList<>();
|
|
|
|
|
+ for (RoomMeetings roomMeetings : response.body()) {
|
|
|
|
|
+ if (roomMeetings.getMeetings() != null) {
|
|
|
|
|
+ list.addAll(roomMeetings.getMeetings());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
|
|
|
|
|
+ Iterator<Meeting> iterable = list.iterator();
|
|
|
|
|
+ while (iterable.hasNext()) {
|
|
|
|
|
+ Meeting meeting = iterable.next();
|
|
|
|
|
+ try {
|
|
|
|
|
+ Date end = sdf.parse(meeting.getEndTimeStr());
|
|
|
|
|
+ if (end != null && end.before(new Date())) {
|
|
|
|
|
+ iterable.remove();
|
|
|
}
|
|
}
|
|
|
|
|
+ } catch (ParseException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ list.sort((o1, o2) -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Date date1 = sdf.parse(o1.getBeginTimeStr());
|
|
|
|
|
+ Date date2 = sdf.parse(o2.getBeginTimeStr());
|
|
|
|
|
+ return date1.compareTo(date2);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ todayMeetings = list;
|
|
|
EventBus.getDefault().post(Constants.EVENT_MEETINGS);
|
|
EventBus.getDefault().post(Constants.EVENT_MEETINGS);
|
|
|
} else {
|
|
} else {
|
|
|
try {
|
|
try {
|