Commit dc5e8e37 authored by fallenstardust's avatar fallenstardust Committed by GitHub

Merge pull request #204 from jwyxym/master

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