Commit 845503aa authored by qq247321453's avatar qq247321453

Fix CardFavorites

parent d7b7a81d
package cn.garymb.ygomobile.ui.cards;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
import java.io.File;
......@@ -16,7 +17,7 @@ import ocgcore.data.Card;
public class CardFavorites {
private final List<Integer> mList = new ArrayList<>();
private static final String TAG = "CardFavorites";
private static final CardFavorites sCardFavorites = new CardFavorites();
public static CardFavorites get() {
......@@ -76,19 +77,26 @@ public class CardFavorites {
List<String> lines;
if (config.exists()) {
//重命名
if(!config.renameTo(AppsSettings.get().getSystemConfig())) {
if (!config.renameTo(AppsSettings.get().getSystemConfig())) {
Log.w(TAG, "copy txt to conf");
try {
FileUtils.copyFile(AppsSettings.get().getFavoriteFile().getPath(), AppsSettings.get().getSystemConfig().getPath());
} catch (IOException e) {
//TODO 复制失败,直接删除?
FileUtils.deleteFile(AppsSettings.get().getFavoriteFile());
}
} else {
Log.d(TAG, "rename txt to conf");
}
config = AppsSettings.get().getSystemConfig();
} else {
config = AppsSettings.get().getSystemConfig();
}
if (!config.exists()) {
Log.w(TAG, "config is no exists:" + config.getPath());
return;
}
//Log.d(TAG, "load favorites:"+config.getPath());
lines = FileUtils.readLines(config.getPath(), Constants.DEF_ENCODING);
for (String line : lines) {
String tmp = line.trim();
......@@ -96,6 +104,7 @@ public class CardFavorites {
mList.add(Integer.parseInt(tmp));
}
}
Log.d(TAG, "load favorites success:"+mList.size());
}
public void save() {
......
......@@ -63,8 +63,6 @@ public class MainActivity extends HomeActivity {
// ActivityCompat.requestPermissions(this, PERMISSIONS, 0);
//资源复制
checkRes();
//加载收藏夹
CardFavorites.get().load();
}
@SuppressLint({"StringFormatMatches", "StringFormatInvalid"})
......@@ -82,6 +80,8 @@ public class MainActivity extends HomeActivity {
private void checkRes() {
checkResourceDownload((error, isNew) -> {
//加载收藏夹
CardFavorites.get().load();
if (error < 0) {
enableStart = false;
} else {
......
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