|
@@ -1,12 +1,18 @@
|
|
|
package com.fxy.utils;
|
|
|
|
|
|
+import android.content.Context;
|
|
|
+
|
|
|
+import com.fxy.baselibrary.language.other.CommSharedUtil;
|
|
|
import com.fxy.realm.AsyncUploadRealm;
|
|
|
|
|
|
+import java.util.Calendar;
|
|
|
+
|
|
|
import io.realm.Realm;
|
|
|
import io.realm.RealmResults;
|
|
|
|
|
|
public class UploadUtils {
|
|
|
- public static int getAwaitNum(Realm mRealm,String uploadType){
|
|
|
+ public static String currentUploadTimeTag="oss_current_upload_time";
|
|
|
+ public static int getAwaitNum(Realm mRealm,String uploadType){
|
|
|
RealmResults<AsyncUploadRealm> realmResults = mRealm.where(AsyncUploadRealm.class)
|
|
|
.equalTo("isDelete",0)
|
|
|
.equalTo("pushStatus",0)
|
|
@@ -24,4 +30,52 @@ public class UploadUtils {
|
|
|
realmResults.load();
|
|
|
return realmResults.size();
|
|
|
}
|
|
|
+ public static long getCurrentTime(){
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ return calendar.getTimeInMillis();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算两个时间戳之间的差异,并返回以秒为单位的结果。
|
|
|
+ *
|
|
|
+ * @param timestamp1 第一个时间戳(毫秒)
|
|
|
+ * @param timestamp2 第二个时间戳(毫秒)
|
|
|
+ * @return 差异的秒数
|
|
|
+ */
|
|
|
+ public static long calculateDifferenceInSeconds(long timestamp1, long timestamp2) {
|
|
|
+ // 计算两个时间戳之间的差异(毫秒)
|
|
|
+ long differenceInMillis = Math.abs(timestamp1 - timestamp2);
|
|
|
+
|
|
|
+ // 将差异转换为秒
|
|
|
+ return differenceInMillis / 1000;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean getUploadExists(Context context){
|
|
|
+ String currentUploadTimeStr = CommSharedUtil.getInstance(context).getString(currentUploadTimeTag,"");
|
|
|
+
|
|
|
+ if (currentUploadTimeStr.isEmpty()){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ long diff = calculateDifferenceInSeconds( getCurrentTime() , Long.getLong(currentUploadTimeStr));
|
|
|
+ return diff >= 60 * 5;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置上传时间
|
|
|
+ * @param context Context
|
|
|
+ */
|
|
|
+ public static void setUploadTime(Context context){
|
|
|
+ CommSharedUtil.getInstance(context).putString(currentUploadTimeTag,String.valueOf(getCurrentTime()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除上传时间
|
|
|
+ * @param context Context
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ public static boolean delUploadTime(Context context){
|
|
|
+ CommSharedUtil.getInstance(context).remove(currentUploadTimeTag);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
}
|