Commit 2c7d8c68 authored by wangfugui's avatar wangfugui

修复bug

parent e36c905e
......@@ -26,7 +26,8 @@ import ocgcore.data.Card;
public class DeckSquareFileUtil {
//
private static final String TAG = DeckSquareListAdapter.class.getSimpleName();
private static final String TAG = "seesee decksquareApiUtil";
//private static final String TAG = DeckSquareListAdapter.class.getSimpleName();
// public static List<String> readLastLinesWithNIO(File file, int numLines) {
// try {
......@@ -57,7 +58,7 @@ public class DeckSquareFileUtil {
String line = null;
while ((line = reader.readLine()) != null) {
LogUtil.i(TAG, line);
// LogUtil.i(TAG, line);
if (line.startsWith("###")) {//注意,先判断###,后判断##。因为###会包括##的情况
try {
String data = line.replace("#", "");
......@@ -207,20 +208,10 @@ public class DeckSquareFileUtil {
return content;
}
/**
* 保存文件到指定路径,并设置指定的最后修改时间
*
* @param path 保存路径
* @param fileName 文件名
* @param content 文件内容
* @param modificationTime 期望的最后修改时间(毫秒时间戳)
* @return 保存是否成功
*/
public static boolean saveFileToPath(String path, String fileName, String content, long modificationTime) {
public static boolean saveFile(File file, String content, long modificationTime) {
FileOutputStream fos = null;
try {
// 创建文件对象
File file = new File(path, fileName);
fos = new FileOutputStream(file);
// 创建文件输出流
// 写入内容
......@@ -251,6 +242,33 @@ public class DeckSquareFileUtil {
return true;
}
/**
*
* @param fileFullPath 文件的完整路径
* @param content
* @param modificationTime
* @return
*/
public static boolean saveFileToPath(String fileFullPath, String content, long modificationTime) {
File file = new File(fileFullPath);
return saveFile(file, content, modificationTime);
}
/**
* 保存文件到指定路径,并设置指定的最后修改时间
*
* @param fileParentPath 保存文件的父目录路径
* @param fileName 文件名
* @param content 文件内容
* @param modificationTime 最后修改时间(毫秒时间戳)
* @return 保存是否成功
*/
public static boolean saveFileToPath(String fileParentPath, String fileName, String content, long modificationTime) {
File file = new File(fileParentPath, fileName);
return saveFile(file, content, modificationTime);
}
public static List<Card> convertTempDeckYdk(String deckYdk) {
String[] deckLine = deckYdk.split("\r\n|\r|\n");
......@@ -277,13 +295,17 @@ public class DeckSquareFileUtil {
}
public static long convertToUnixTimestamp(String dateTimeStr) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
sdf.setLenient(false);
Date date = sdf.parse(dateTimeStr);
return date.getTime();
public static long convertToUnixTimestamp(String dateTimeStr) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
sdf.setLenient(false);
Date date = sdf.parse(dateTimeStr);
return date.getTime();
}catch(ParseException e){
e.printStackTrace();
}
return 0;
}
}
......@@ -128,7 +128,7 @@ public class DeckSquareMyDeckFragment extends Fragment {
LogUtil.i(TAG, "Sync decks fail" + e.getMessage());
}).done((result) -> {
String info = "sync decks: upload " + result.toUpload.size() + ", download " + result.download.size();
String info = "sync decks: upload " + result.syncUpload.size() + ", download " + result.newDownload.size();
YGOUtil.showTextToast(info, Toast.LENGTH_LONG);
});
......@@ -216,7 +216,7 @@ public class DeckSquareMyDeckFragment extends Fragment {
YGOUtil.showTextToast("Sync decks fail", Toast.LENGTH_LONG);
LogUtil.i(TAG, "Sync decks fail" + e.getMessage());
}).done((result) -> {
String info = "sync decks: upload " + result.toUpload.size() + ", download " + result.download.size();
String info = "sync decks: upload " + result.syncUpload.size() + ", download " + result.newDownload.size();
YGOUtil.showTextToast(info, Toast.LENGTH_LONG);
});
......
package cn.garymb.ygomobile.deck_square.api_response;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class DeckMultiIdResponse {
@Expose
public int code;
@Expose
public String message;
@Expose
@SerializedName("data")
public List<String> deckId;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public List<String> getDeckId() {
return deckId;
}
public void setDeckId(List<String> deckId) {
this.deckId = deckId;
}
@Override
public String toString() {
return "DeckMultiIdResponse{" +
"code=" + code +
", message='" + message + '\'' +
", deckId=" + deckId +
'}';
}
}
package cn.garymb.ygomobile.deck_square.api_response;
/* 同步卡组响应体类*/
public class SyncDecksResponse {
private Integer code;
private String message;
private Integer data;
public SyncDecksResponse(Integer code, String message, Integer data) {
this.code = code;
this.message = message;
this.data = data;
}
// getters and setters
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Integer getData() {
return data;
}
public void setData(Integer data) {
this.data = data;
}
}
package cn.garymb.ygomobile.deck_square.bo;
import org.minidns.record.A;
import java.util.ArrayList;
import java.util.List;
import cn.garymb.ygomobile.deck_square.api_response.MyOnlineDeckDetail;
import cn.garymb.ygomobile.deck_square.api_response.SyncDecksResponse;
import cn.garymb.ygomobile.deck_square.api_response.PushDeckResponse;
public class SyncMutliDeckResult {
boolean flag = false;
String info = null;
public SyncDecksResponse pushResponse;
public PushDeckResponse pushResponse;
public List<MyDeckItem> toUpload;//用于记录已推送的卡组
public List<MyOnlineDeckDetail> download;
public List<MyDeckItem> syncUpload;//用于记录已推送的卡组
public List<MyDeckItem> newUpload;//用于记录第一次推送到云的卡组
public List<MyDeckItem> syncDownload;//用于记录已推送的卡组
public List<MyOnlineDeckDetail> newDownload;
public List<DownloadResult> downloadResponse;
public static class DownloadResult {
......@@ -37,16 +41,20 @@ public class SyncMutliDeckResult {
public SyncMutliDeckResult() {
flag = true;
downloadResponse = new ArrayList<>();
download = new ArrayList<>();
toUpload = new ArrayList<>();
newDownload = new ArrayList<>();
syncUpload = new ArrayList<>();
newUpload = new ArrayList<>();
syncDownload = new ArrayList<>();
}
public SyncMutliDeckResult(boolean flag, String info) {
this.flag = flag;
this.info = info;
downloadResponse = new ArrayList<>();
download = new ArrayList<>();
toUpload = new ArrayList<>();
newDownload = new ArrayList<>();
syncUpload = new ArrayList<>();
newUpload = new ArrayList<>();
syncDownload = new ArrayList<>();
}
public boolean isFlag() {
......@@ -64,4 +72,10 @@ public class SyncMutliDeckResult {
public void setInfo(String info) {
this.info = info;
}
public String getMessage() {
String info = "sync decks: " + syncUpload.size() + ", push new:" + newUpload.size() + ", download " + newDownload.size();
return info;
}
}
......@@ -4,6 +4,7 @@ import static android.content.Context.CLIPBOARD_SERVICE;
import static cn.garymb.ygomobile.Constants.ORI_DECK;
import static cn.garymb.ygomobile.Constants.YDK_FILE_EX;
import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_SHARE_FILE;
import static cn.garymb.ygomobile.deck_square.DeckSquareFileUtil.convertToUnixTimestamp;
import android.content.ClipData;
import android.content.ClipboardManager;
......@@ -1351,7 +1352,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
String fileFullName = deckData.getDeckName() + ".ydk";
File dir = new File(getActivity().getApplicationInfo().dataDir, "cache");
//将卡组存到cache缓存目录中
boolean result = DeckSquareFileUtil.saveFileToPath(dir.getPath(), fileFullName, deckData.getDeckYdk(), Long.valueOf(deckData.getDeckUpdateDate()));
boolean result = DeckSquareFileUtil.saveFileToPath(dir.getPath(), fileFullName, deckData.getDeckYdk(), convertToUnixTimestamp(deckData.getDeckUpdateDate()));
if (result) {//存储成功,使用预加载功能
LogUtil.i(TAG, "square deck detail done");
//File file = new File(dir, fileFullName);
......
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