Commit cc0cd259 authored by fallenstardust's avatar fallenstardust

复制一份synchroinzeDeck执行但不比较时间直接推送

parent e3069d02
...@@ -251,7 +251,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -251,7 +251,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
mContext = (BaseActivity) getActivity(); mContext = (BaseActivity) getActivity();
/** 自动同步 */ /** 自动同步 */
if (SharedPreferenceUtil.getServerToken() != null) { if (SharedPreferenceUtil.getServerToken() != null) {
VUiKit.defer().when(DeckSquareApiUtil::synchronizeDecksV2).fail((e) -> { VUiKit.defer().when(DeckSquareApiUtil::synchronizeDecks).fail((e) -> {
LogUtil.i(TAG, "sync deck fail" + e.getMessage()); LogUtil.i(TAG, "sync deck fail" + e.getMessage());
}).done((result) -> { }).done((result) -> {
}); });
...@@ -1349,7 +1349,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1349,7 +1349,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
if (deckData != null) { if (deckData != null) {
mDeckId = deckData.getDeckId(); mDeckId = deckData.getDeckId();
deckData.getDeckYdk(); deckData.getDeckYdk();
String fileFullName = deckData.getDeckName() + ".ydk"; String fileFullName = deckData.getDeckName() + YDK_FILE_EX;
File dir = new File(getActivity().getApplicationInfo().dataDir, "cache"); File dir = new File(getActivity().getApplicationInfo().dataDir, "cache");
//将卡组存到cache缓存目录中 //将卡组存到cache缓存目录中
boolean result = DeckSquareFileUtil.saveFileToPath(dir.getPath(), fileFullName, deckData.getDeckYdk(), convertToUnixTimestamp(deckData.getDeckUpdateDate())); boolean result = DeckSquareFileUtil.saveFileToPath(dir.getPath(), fileFullName, deckData.getDeckYdk(), convertToUnixTimestamp(deckData.getDeckUpdateDate()));
......
package cn.garymb.ygomobile.ui.cards.deck_square; package cn.garymb.ygomobile.ui.cards.deck_square;
import static cn.garymb.ygomobile.ui.cards.deck.DeckUtils.save;
import android.widget.Toast; import android.widget.Toast;
import com.google.gson.Gson; import com.google.gson.Gson;
...@@ -89,7 +91,7 @@ public class DeckSquareApiUtil { ...@@ -89,7 +91,7 @@ public class DeckSquareApiUtil {
String url = "http://rarnu.xyz:38383/api/mdpro3/deck/list"; String url = "http://rarnu.xyz:38383/api/mdpro3/deck/list";
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("ReqSource", "MDPro3"); headers.put("ReqSource", "YGOMobile");
Map<String, Object> paramMap = new HashMap<>(); Map<String, Object> paramMap = new HashMap<>();
...@@ -126,7 +128,7 @@ public class DeckSquareApiUtil { ...@@ -126,7 +128,7 @@ public class DeckSquareApiUtil {
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("ReqSource", "MDPro3"); headers.put("ReqSource", "YGOMobile");
headers.put("token", loginToken.getServerToken()); headers.put("token", loginToken.getServerToken());
Response response = OkhttpUtil.synchronousGet(url, null, headers); Response response = OkhttpUtil.synchronousGet(url, null, headers);
...@@ -153,7 +155,7 @@ public class DeckSquareApiUtil { ...@@ -153,7 +155,7 @@ public class DeckSquareApiUtil {
String url = "http://rarnu.xyz:38383/api/mdpro3/deck/" + deckId; String url = "http://rarnu.xyz:38383/api/mdpro3/deck/" + deckId;
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("ReqSource", "MDPro3"); headers.put("ReqSource", "YGOMobile");
Response response = OkhttpUtil.synchronousGet(url, null, headers); Response response = OkhttpUtil.synchronousGet(url, null, headers);
String responseBodyString = response.body().string(); String responseBodyString = response.body().string();
...@@ -187,7 +189,7 @@ public class DeckSquareApiUtil { ...@@ -187,7 +189,7 @@ public class DeckSquareApiUtil {
PushDeckResponse result = null; PushDeckResponse result = null;
String url = "http://rarnu.xyz:38383/api/mdpro3/sync/single"; String url = "http://rarnu.xyz:38383/api/mdpro3/sync/single";
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("ReqSource", "MDPro3"); headers.put("ReqSource", "YGOMobile");
headers.put("token", loginToken.getServerToken()); headers.put("token", loginToken.getServerToken());
...@@ -227,7 +229,6 @@ public class DeckSquareApiUtil { ...@@ -227,7 +229,6 @@ public class DeckSquareApiUtil {
*/ */
private static PushDeckResponse pushDecks(List<MyDeckItem> deckDataList, LoginToken loginToken, List<String> deckIdList) throws IOException { private static PushDeckResponse pushDecks(List<MyDeckItem> deckDataList, LoginToken loginToken, List<String> deckIdList) throws IOException {
List<PushMultiDeck.DeckData> decks = new ArrayList<>(); List<PushMultiDeck.DeckData> decks = new ArrayList<>();
List<String> deckContents = new ArrayList<>();
if (deckDataList.size() != deckIdList.size()) { if (deckDataList.size() != deckIdList.size()) {
return null; return null;
} }
...@@ -264,7 +265,7 @@ public class DeckSquareApiUtil { ...@@ -264,7 +265,7 @@ public class DeckSquareApiUtil {
String getDeckIdUrl = "http://rarnu.xyz:38383/api/mdpro3/deck/deckId"; String getDeckIdUrl = "http://rarnu.xyz:38383/api/mdpro3/deck/deckId";
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("ReqSource", "MDPro3"); headers.put("ReqSource", "YGOMobile");
headers.put("token", loginToken.getServerToken()); headers.put("token", loginToken.getServerToken());
Gson gson = new Gson(); Gson gson = new Gson();
...@@ -301,6 +302,7 @@ public class DeckSquareApiUtil { ...@@ -301,6 +302,7 @@ public class DeckSquareApiUtil {
* @throws IOException * @throws IOException
*/ */
public static PushDeckResponse requestIdAndPushNewDecks(List<MyDeckItem> deckDataList, LoginToken loginToken) throws IOException { public static PushDeckResponse requestIdAndPushNewDecks(List<MyDeckItem> deckDataList, LoginToken loginToken) throws IOException {
LogUtil.d("seesee","有没有运行这里啊"+deckDataList +" "+ loginToken);
if (loginToken == null) { if (loginToken == null) {
return null; return null;
} }
...@@ -309,7 +311,7 @@ public class DeckSquareApiUtil { ...@@ -309,7 +311,7 @@ public class DeckSquareApiUtil {
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("ReqSource", "MDPro3"); headers.put("ReqSource", "YGOMobile");
headers.put("token", loginToken.getServerToken()); headers.put("token", loginToken.getServerToken());
Map<String, Object> paramMap = new HashMap<>(); Map<String, Object> paramMap = new HashMap<>();
...@@ -359,7 +361,7 @@ public class DeckSquareApiUtil { ...@@ -359,7 +361,7 @@ public class DeckSquareApiUtil {
String url = "http://rarnu.xyz:38383/api/mdpro3/sync/multi"; String url = "http://rarnu.xyz:38383/api/mdpro3/sync/multi";
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("ReqSource", "MDPro3"); headers.put("ReqSource", "YGOMobile");
headers.put("token", loginToken.getServerToken()); headers.put("token", loginToken.getServerToken());
PushDeckResponse result = null; PushDeckResponse result = null;
...@@ -391,7 +393,7 @@ public class DeckSquareApiUtil { ...@@ -391,7 +393,7 @@ public class DeckSquareApiUtil {
String url = "http://rarnu.xyz:38383/api/mdpro3/deck/like/" + deckId; String url = "http://rarnu.xyz:38383/api/mdpro3/deck/like/" + deckId;
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("ReqSource", "MDPro3"); headers.put("ReqSource", "YGOMobile");
Response response = OkhttpUtil.postJson(url, null, headers); Response response = OkhttpUtil.postJson(url, null, headers);
String responseBodyString = response.body().string(); String responseBodyString = response.body().string();
...@@ -416,7 +418,7 @@ public class DeckSquareApiUtil { ...@@ -416,7 +418,7 @@ public class DeckSquareApiUtil {
String url = "http://rarnu.xyz:38383/api/mdpro3/deck/public"; String url = "http://rarnu.xyz:38383/api/mdpro3/deck/public";
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("ReqSource", "MDPro3"); headers.put("ReqSource", "YGOMobile");
headers.put("token", loginToken.getServerToken()); headers.put("token", loginToken.getServerToken());
Gson gson = new Gson(); Gson gson = new Gson();
...@@ -487,7 +489,7 @@ public class DeckSquareApiUtil { ...@@ -487,7 +489,7 @@ public class DeckSquareApiUtil {
PushDeckResponse result = null; PushDeckResponse result = null;
String url = "http://rarnu.xyz:38383/api/mdpro3/sync/single"; String url = "http://rarnu.xyz:38383/api/mdpro3/sync/single";
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("ReqSource", "MDPro3"); headers.put("ReqSource", "YGOMobile");
headers.put("token", loginToken.getServerToken()); headers.put("token", loginToken.getServerToken());
...@@ -567,21 +569,22 @@ public class DeckSquareApiUtil { ...@@ -567,21 +569,22 @@ public class DeckSquareApiUtil {
// 比对更新时间 // 比对更新时间
long localUpdateDate = localDeck.getUpdateTimestamp(); long localUpdateDate = localDeck.getUpdateTimestamp();
long onlineUpdateDate = DeckSquareFileUtil.convertToUnixTimestamp(onlineDeck.getDeckUpdateDate());//todo 这里应该把2025-05-19T06:11:17转成毫秒,onlineDeck.getDeckUpdateDate(); long onlineUpdateDate = DeckSquareFileUtil.convertToUnixTimestamp(onlineDeck.getDeckUpdateDate());//todo 这里应该把2025-05-19T06:11:17转成毫秒,onlineDeck.getDeckUpdateDate();
LogUtil.d("seesee 本地和在线时间差",String.valueOf(localUpdateDate - onlineUpdateDate)); LogUtil.d("seesee 本地和在线时间差",localDeckName+": "+(localUpdateDate - onlineUpdateDate > 0 ? "本地的-新": "在线的-新"));
LogUtil.d("seesee 差多少",localDeckName+": "+(localUpdateDate - onlineUpdateDate));
if (onlineUpdateDate > localUpdateDate) { if (onlineUpdateDate > localUpdateDate) {
// 在线卡组更新时间更晚,下载在线卡组覆盖本地卡组 // 在线卡组更新时间更晚,下载在线卡组覆盖本地卡组
LogUtil.w(TAG, "sync-download deck: " + localDeck.getDeckPath()); LogUtil.w(TAG, "seesee *下载* " + localDeck.getDeckPath());
autoSyncResult.syncDownload.add(localDeck); autoSyncResult.syncDownload.add(localDeck);
downloadOnlineDeck(onlineDeck, localDeck.getDeckPath(), onlineUpdateDate); downloadOnlineDeck(onlineDeck, localDeck.getDeckPath(), onlineUpdateDate);
//} else if (onlineUpdateDate == localUpdateDate) { } else if (onlineUpdateDate == localUpdateDate) {
// LogUtil.w(TAG, "no need to sync deck: " + localDeck.getDeckName()); LogUtil.w(TAG, "seesee 不需要同步: " + localDeck.getDeckName());
// //时间戳相同,不需要更新 //时间戳相同,不需要更新
} else { } else {
// 本地卡组更新时间更晚,上传本地卡组覆盖在线卡组 // 本地卡组更新时间更晚,上传本地卡组覆盖在线卡组
localDeck.setDeckName(localDeck.getDeckName().replace(Constants.YDK_FILE_EX,""));//TODO 上版本很多人已经传了带.ydk的云备份,姑且只在这次再次上传时去掉.ydk localDeck.setDeckName(localDeck.getDeckName().replace(Constants.YDK_FILE_EX,""));//TODO 上版本很多人已经传了带.ydk的云备份,姑且只在这次再次上传时去掉.ydk
localDeck.setDeckCoverCard1(DeckUtil.getFirstCardCode(localDeck.getDeckPath())); localDeck.setDeckCoverCard1(DeckUtil.getFirstCardCode(localDeck.getDeckPath()));
localDeck.setDeckId(onlineDeck.getDeckId()); localDeck.setDeckId(onlineDeck.getDeckId());
LogUtil.w(TAG, "seesee sync-upload deck: " + localDeck.getDeckName() + "、封面id:"+ localDeck.getDeckCoverCard1()); LogUtil.w(TAG, "seesee -上传-" + localDeck.getDeckName());
syncUploadDecks.add(localDeck); syncUploadDecks.add(localDeck);
autoSyncResult.syncUpload.add(localDeck); autoSyncResult.syncUpload.add(localDeck);
...@@ -623,12 +626,102 @@ public class DeckSquareApiUtil { ...@@ -623,12 +626,102 @@ public class DeckSquareApiUtil {
} }
public static SyncMutliDeckResult synchronizeDecks() throws IOException {
SyncMutliDeckResult autoSyncResult = new SyncMutliDeckResult();
// 检查用户是否登录
LoginToken loginToken = DeckSquareApiUtil.getLoginData();
if (loginToken == null) {
autoSyncResult.setFlag(false);
autoSyncResult.setInfo("need login");
return autoSyncResult;
}
// 获取本地卡组列表
List<MyDeckItem> localDecks = DeckSquareFileUtil.getMyDeckItem();
// 获取在线卡组列表
MyDeckResponse onlineDecksResponse = DeckSquareApiUtil.getUserDecks(loginToken);
if (onlineDecksResponse == null || onlineDecksResponse.getData() == null) {
autoSyncResult.setFlag(false);
autoSyncResult.setInfo("no online decks");
return autoSyncResult;
}
List<MyOnlineDeckDetail> onlineDecks = onlineDecksResponse.getData();
// 用于标记在线卡组是否在本地有对应
Map<String, Boolean> onlineDeckProcessed = new HashMap<>();
for (MyOnlineDeckDetail onlineDeck : onlineDecks) {
onlineDeckProcessed.put(onlineDeck.getDeckName(), false);
}
List<MyDeckItem> syncUploadDecks = new ArrayList<>();
List<MyDeckItem> newPushDecks = new ArrayList<>();
// 遍历本地卡组,处理同名卡组的情况
for (MyDeckItem localDeck : localDecks) {
boolean foundOnlineDeck = false;
String localDeckName = localDeck.getDeckName().replace(Constants.YDK_FILE_EX, "");
for (MyOnlineDeckDetail onlineDeck : onlineDecks) {
String onLineDeckName = onlineDeck.getDeckName().replace(Constants.YDK_FILE_EX, "");
if (localDeckName.equals(onLineDeckName)) {
// 标记该在线卡组已处理
onlineDeckProcessed.put(onLineDeckName, true);
// 标记该本地卡组已处理
foundOnlineDeck = true;
// 将每个本地卡组作为数组元素添加入syncUploadDecks
localDeck.setDeckName(localDeck.getDeckName().replace(Constants.YDK_FILE_EX,""));//TODO 上版本很多人已经传了带.ydk的云备份,姑且只在这次再次上传时去掉.ydk
localDeck.setDeckCoverCard1(DeckUtil.getFirstCardCode(localDeck.getDeckPath()));
localDeck.setDeckId(onlineDeck.getDeckId());
syncUploadDecks.add(localDeck);
autoSyncResult.syncUpload.add(localDeck);
break;
}
}
// 本地卡组在在线列表中不存在,则需要获取新的deckid来直接上传
if (!foundOnlineDeck) {
localDeck.setDeckName(localDeck.getDeckName().replace(Constants.YDK_FILE_EX,""));
localDeck.setDeckCoverCard1(DeckUtil.getFirstCardCode(localDeck.getDeckPath()));
LogUtil.w(TAG, "seesee +要上传的 本地卡组: " + localDeck.getDeckName());
newPushDecks.add(localDeck);
autoSyncResult.newUpload.add(localDeck);
}
}
// 上传本地卡组覆盖在线卡组
PushDeckResponse response = syncMyDecks(syncUploadDecks, loginToken);
autoSyncResult.pushResponse = response;
if (!newPushDecks.isEmpty()) {
LogUtil.w(TAG, "seesee *newPushDecks: " + newPushDecks.isEmpty() + ": " +newPushDecks);
requestIdAndPushNewDecks(newPushDecks, loginToken);
}
// 处理只存在于在线的卡组(即本地没有同名卡组)
for (MyOnlineDeckDetail onlineDeck : onlineDecks) {
String onLineDeckName = onlineDeck.getDeckName().replace(Constants.YDK_FILE_EX, "");
LogUtil.w(TAG, "seesee *在线卡组*onLineDeckName: " + onLineDeckName);
if (!onlineDeckProcessed.get(onLineDeckName)) {
autoSyncResult.newDownload.add(onlineDeck);
LogUtil.w(TAG, "see sync-download new deck: " + onlineDeck.getDeckName());
SyncMutliDeckResult.DownloadResult downloadResult = downloadMissingDeckToLocal(onlineDeck, DeckSquareFileUtil.convertToUnixTimestamp(onlineDeck.getDeckUpdateDate()));
autoSyncResult.downloadResponse.add(downloadResult);
}
}
LogUtil.w(TAG, "seesee *结果*newDownload: " + autoSyncResult.newDownload);
//LogUtil.w(TAG, "seesee *结果*newUpload: " + autoSyncResult.syncDownload);
LogUtil.w(TAG, "seesee *结果*downloadResponse: " + autoSyncResult.downloadResponse);
return autoSyncResult;
}
private static SyncMutliDeckResult.DownloadResult downloadMissingDeckToLocal(MyOnlineDeckDetail onlineDeck, Long onlineUpdateDate) { private static SyncMutliDeckResult.DownloadResult downloadMissingDeckToLocal(MyOnlineDeckDetail onlineDeck, Long onlineUpdateDate) {
try { try {
// 根据卡组ID查询在线卡组详情 // 根据卡组ID查询在线卡组详情
DownloadDeckResponse deckResponse = DeckSquareApiUtil.getDeckById(onlineDeck.getDeckId()); DownloadDeckResponse deckResponse = DeckSquareApiUtil.getDeckById(onlineDeck.getDeckId());
if (deckResponse == null || deckResponse.getData() == null) { if (deckResponse == null || deckResponse.getData() == null) {
LogUtil.e(TAG, "Failed to get deck details for: " + onlineDeck.getDeckName()); LogUtil.e(TAG, "seesee Failed to get deck details for: " + onlineDeck.getDeckName());
return new SyncMutliDeckResult.DownloadResult(false, onlineDeck.getDeckId(), "Failed to get deck details for: " + onlineDeck.getDeckName()); return new SyncMutliDeckResult.DownloadResult(false, onlineDeck.getDeckId(), "Failed to get deck details for: " + onlineDeck.getDeckName());
} }
...@@ -639,7 +732,7 @@ public class DeckSquareApiUtil { ...@@ -639,7 +732,7 @@ public class DeckSquareApiUtil {
if (!dir.exists()) { if (!dir.exists()) {
boolean created = dir.mkdirs(); boolean created = dir.mkdirs();
if (!created) { if (!created) {
LogUtil.e(TAG, "Failed to create directory: " + deckDirectory); LogUtil.e(TAG, "seesee Failed to create directory: " + deckDirectory);
return new SyncMutliDeckResult.DownloadResult(false, onlineDeck.getDeckId(), "Failed to create directory: " + deckDirectory); return new SyncMutliDeckResult.DownloadResult(false, onlineDeck.getDeckId(), "Failed to create directory: " + deckDirectory);
} }
} }
...@@ -655,23 +748,15 @@ public class DeckSquareApiUtil { ...@@ -655,23 +748,15 @@ public class DeckSquareApiUtil {
// 保存在线卡组到本地 // 保存在线卡组到本地
boolean saved = DeckSquareFileUtil.saveFileToPath(fileFullPath, deckResponse.getData().getDeckYdk(), onlineUpdateDate); boolean saved = DeckSquareFileUtil.saveFileToPath(fileFullPath, deckResponse.getData().getDeckYdk(), onlineUpdateDate);
if (!saved) { if (!saved) {
LogUtil.e(TAG, "Failed to save deck file: " + fileFullPath); LogUtil.e(TAG, "seesee Failed to save deck file: " + fileFullPath);
return new SyncMutliDeckResult.DownloadResult(false, onlineDeck.getDeckId(), "Failed to save deck file: " + fileFullPath); return new SyncMutliDeckResult.DownloadResult(false, onlineDeck.getDeckId(), "Failed to save deck file: " + fileFullPath);
} }
LogUtil.i(TAG, "Deck saved to: " + fileFullPath); LogUtil.i(TAG, "seesee Deck saved to: " + fileFullPath);
// 更新本地卡组列表
MyDeckItem newLocalDeck = new MyDeckItem();
newLocalDeck.setDeckName(fileName);
newLocalDeck.setDeckPath(fileFullPath);
newLocalDeck.setDeckId(onlineDeck.getDeckId());
newLocalDeck.setIdUploaded(2); // 已上传状态
newLocalDeck.setUpdateDate(onlineDeck.getDeckUpdateDate());
return new SyncMutliDeckResult.DownloadResult(true, onlineDeck.getDeckId()); return new SyncMutliDeckResult.DownloadResult(true, onlineDeck.getDeckId());
} catch (Exception e) { } catch (Exception e) {
LogUtil.e(TAG, "Error downloading missing deck: " + e.getMessage()); LogUtil.e(TAG, "seesee Error downloading missing deck: " + e.getMessage());
e.printStackTrace(); e.printStackTrace();
return new SyncMutliDeckResult.DownloadResult(false, onlineDeck.getDeckId(), "Error downloading missing deck: " + e.getMessage()); return new SyncMutliDeckResult.DownloadResult(false, onlineDeck.getDeckId(), "Error downloading missing deck: " + e.getMessage());
} }
......
package cn.garymb.ygomobile.ui.cards.deck_square; package cn.garymb.ygomobile.ui.cards.deck_square;
import android.os.Build;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -9,6 +11,10 @@ import java.io.InputStreamReader; ...@@ -9,6 +11,10 @@ import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -26,7 +32,7 @@ import ocgcore.data.Card; ...@@ -26,7 +32,7 @@ import ocgcore.data.Card;
public class DeckSquareFileUtil { public class DeckSquareFileUtil {
// //
private static final String TAG = "seesee decksquareApiUtil"; private static final String TAG = "decksquareApiUtil";
//private static final String TAG = DeckSquareListAdapter.class.getSimpleName(); //private static final String TAG = DeckSquareListAdapter.class.getSimpleName();
// public static List<String> readLastLinesWithNIO(File file, int numLines) { // public static List<String> readLastLinesWithNIO(File file, int numLines) {
...@@ -141,8 +147,6 @@ public class DeckSquareFileUtil { ...@@ -141,8 +147,6 @@ public class DeckSquareFileUtil {
String deckId = getId(file); String deckId = getId(file);
MyDeckItem item = new MyDeckItem(); MyDeckItem item = new MyDeckItem();
item.setDeckName(file.getName()); item.setDeckName(file.getName());
item.setUpdateTimestamp(file.lastModified()); item.setUpdateTimestamp(file.lastModified());
item.setDeckPath(file.getPath()); item.setDeckPath(file.getPath());
if (deckId != null) { if (deckId != null) {
...@@ -295,17 +299,23 @@ public class DeckSquareFileUtil { ...@@ -295,17 +299,23 @@ public class DeckSquareFileUtil {
} }
public static long convertToUnixTimestamp(String dateTimeStr) { public static long convertToUnixTimestamp(String DateTime) {
try { try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); //DateTime 格式为 ""yyyy-MM-dd'T'HH:mm:ss""
sdf.setTimeZone(TimeZone.getTimeZone("UTC")); DateTimeFormatter formatter = null;
sdf.setLenient(false); // 解析为本地时间,再关联到 UTC+8 时区
Date date = sdf.parse(dateTimeStr); LocalDateTime localDateTime = null;
return date.getTime(); ZonedDateTime zonedDateTime = null;
}catch(ParseException e){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
localDateTime = LocalDateTime.parse(DateTime, formatter);
zonedDateTime = localDateTime.atZone(ZoneId.of("Asia/Shanghai"));
return zonedDateTime.toInstant().toEpochMilli();
}
} catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return 0;
} }
return 0; return 0;
} }
...@@ -317,7 +327,7 @@ public class DeckSquareFileUtil { ...@@ -317,7 +327,7 @@ public class DeckSquareFileUtil {
public static String convertToGMTDate(long timestamp) { public static String convertToGMTDate(long timestamp) {
try { try {
// 创建格式化器并设置时区为 GMT // 创建格式化器并设置时区为 GMT
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.CHINA);
sdf.setTimeZone(TimeZone.getTimeZone("GMT")); sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
// 格式化时间戳 // 格式化时间戳
......
...@@ -58,7 +58,7 @@ public class DeckSquareMyDeckFragment extends Fragment { ...@@ -58,7 +58,7 @@ public class DeckSquareMyDeckFragment extends Fragment {
binding.tvMycardUserName.setText(SharedPreferenceUtil.getMyCardUserName()); binding.tvMycardUserName.setText(SharedPreferenceUtil.getMyCardUserName());
GlideCompat.with(getActivity()).load(ChatMessage.getAvatarUrl(SharedPreferenceUtil.getMyCardUserName())).into(binding.myDeckAvatar);//刷新头像图片 GlideCompat.with(getActivity()).load(ChatMessage.getAvatarUrl(SharedPreferenceUtil.getMyCardUserName())).into(binding.myDeckAvatar);//刷新头像图片
} }
//DeckSquareApiUtil.synchronizeDecks();
binding.btnLogin.setOnClickListener(v -> attemptLogin()); binding.btnLogin.setOnClickListener(v -> attemptLogin());
binding.btnRegister.setOnClickListener(v -> WebActivity.open(getContext(), getString(R.string.register), MyCard.URL_MC_SIGN_UP)); binding.btnRegister.setOnClickListener(v -> WebActivity.open(getContext(), getString(R.string.register), MyCard.URL_MC_SIGN_UP));
deckListAdapter = new MyDeckListAdapter(R.layout.item_my_deck, onDeckMenuListener, mDialogListener); deckListAdapter = new MyDeckListAdapter(R.layout.item_my_deck, onDeckMenuListener, mDialogListener);
...@@ -197,7 +197,7 @@ public class DeckSquareMyDeckFragment extends Fragment { ...@@ -197,7 +197,7 @@ public class DeckSquareMyDeckFragment extends Fragment {
/** 自动同步 */ /** 自动同步 */
VUiKit.defer().when(() -> { VUiKit.defer().when(() -> {
return DeckSquareApiUtil.synchronizeDecksV2(); return DeckSquareApiUtil.synchronizeDecks();
}).fail((e) -> { }).fail((e) -> {
YGOUtil.showTextToast("Sync decks fail", Toast.LENGTH_LONG); YGOUtil.showTextToast("Sync decks fail", Toast.LENGTH_LONG);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment