Commit a0428127 authored by xiaoye's avatar xiaoye

补充userId

parent 18d1e3bd
......@@ -48,6 +48,10 @@ public class Deck implements Parcelable {
* 卡组广场用的卡组id,可以为空
*/
public String deckId = null;
/**
* 卡组广场用的用户id,可以为空
*/
public String userId = null;
public Deck() {
mainlist = new ArrayList<>();
......@@ -195,7 +199,11 @@ public class Deck implements Parcelable {
dest.writeList(this.sideList);
}
public void setId(String id) {
public void setDeckId(String id) {
deckId = id;
}
public void setUserId(String id) {
userId = id;
}
}
......@@ -30,6 +30,7 @@ public class DeckInfo {
private int mainCount, extraCount, sideCount;
public String deckId = null;//当前的卡组id(卡组广场)
public String userId = null;//当前的用户id(卡组广场)
public DeckInfo() {
mainCards = new ArrayList<>();
......@@ -356,7 +357,11 @@ public class DeckInfo {
return allCards;
}
public void setId(String id) {
public void setDeckId(String id) {
deckId = id;
}
public void setUserId(String id) {
userId = id;
}
}
......@@ -70,10 +70,14 @@ public class DeckLoader {
type = DeckItemType.MainCard;
} else if (line.startsWith("#extra")) {
type = DeckItemType.ExtraCard;
} else if (line.startsWith("###")) {
line = line.trim().substring(3);
if (line.length() > 0)
deck.setUserId(line);
} else if (line.startsWith("##")) {
line = line.trim().substring(2);
if (line.length() > 0)
deck.setId(line);
deck.setDeckId(line);
} else {
type = DeckItemType.Pack;
}
......@@ -137,7 +141,9 @@ public class DeckLoader {
int code;
isChanged = false;
if (deck.deckId != null)
deckInfo.setId(deck.deckId);
deckInfo.setDeckId(deck.deckId);
if (deck.userId != null)
deckInfo.setUserId(deck.userId);
for (Integer id : deck.getMainlist()) {
if (tmp.get(id) != null) {
if (released_code_list.contains(tmp.get(id).getCode())) {//先查看id对应的卡片密码是否在正式数组中存在
......
......@@ -69,6 +69,7 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
private String mDeckMd5;
private DeckInfo mDeckInfo;
private String deckId = null;
private String userId = null;
public DeckAdapater(Context context, RecyclerView recyclerView, ImageLoader imageLoader) {
this.context = context;
......@@ -450,7 +451,7 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
public boolean save(File file, boolean withoutId) {
//保存了,记录状态
mDeckMd5 = DeckItemUtils.makeMd5(mItems);
return DeckItemUtils.save(mItems, withoutId ? null : deckId, file);
return DeckItemUtils.save(mItems, withoutId ? null : deckId, withoutId ? null : userId, file);
}
public Deck toDeck(File file) {
......@@ -463,6 +464,7 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
private void loadData(DeckInfo deckInfo, boolean isPack) {
deckId = null;
userId = null;
mCount.clear();
mMainCount = 0;
mExtraCount = 0;
......@@ -662,7 +664,11 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
return mItems.size();
}
public void setId(String id) {
public void setDeckId(String id) {
deckId = id;
}
public void setUserId(String id) {
userId = id;
}
}
......@@ -117,7 +117,7 @@ class DeckItemUtils {
* @param file 原有file
* @return 如果file为null,返回false
*/
public static boolean save(List<DeckItem> items, String deckId, File file) {
public static boolean save(List<DeckItem> items, String deckId, String userId, File file) {
FileOutputStream outputStream = null;
OutputStreamWriter writer = null;
try {
......@@ -166,6 +166,8 @@ class DeckItemUtils {
}
if (deckId != null)
writer.write(("\n##" + deckId).toCharArray());
if (userId != null)
writer.write(("\n###" + userId).toCharArray());
writer.flush();
outputStream.flush();
} catch (IOException e) {
......@@ -181,7 +183,9 @@ class DeckItemUtils {
public static void makeItems(DeckInfo deckInfo, boolean isPack, DeckAdapater adapater) {
if (deckInfo != null) {
if (deckInfo.deckId != null)
adapater.setId(deckInfo.deckId);
adapater.setDeckId(deckInfo.deckId);
if (deckInfo.userId != null)
adapater.setUserId(deckInfo.userId);
DeckItem.resetLabel(deckInfo, isPack);
adapater.addItem(new DeckItem(DeckItemType.MainLabel));
List<Card> main = deckInfo.getMainCards();
......
......@@ -64,6 +64,8 @@ public class DeckUtils {
}
if (deck.deckId != null)
writer.write(("\n##" + deck.deckId).toCharArray());
if (deck.userId != null)
writer.write(("\n###" + deck.userId).toCharArray());
writer.flush();
outputStream.flush();
} catch (IOException e) {
......
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