Skip to content

Commit

Permalink
1.0.0 performance improvement in download; UI improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
wxwang committed Jan 12, 2018
1 parent f7d26bd commit 0efb363
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 125 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ build/

# Local configuration file (sdk path, etc)
local.properties
gradle.properties

# Proguard folder generated by Eclipse
proguard/
Expand All @@ -39,7 +40,7 @@ captures/
.idea/gradle.xml
.idea/dictionaries
.idea/libraries

.idea/
# Keystore files
*.jks

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.lazyeraser.imas.derehelper"
minSdkVersion 17
targetSdkVersion 25
versionCode 9
versionName "0.9.9"
versionCode 10
versionName "1.0.0"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/lazyeraser/imas/cgss/utils/DBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ public void onCreate(SQLiteDatabase db) {

}

public void beginTran(){
getWritableDatabase().beginTransaction();
}

public void setTranSuccess(){
getWritableDatabase().setTransactionSuccessful();
}

public void endTran(){
getWritableDatabase().endTransaction();
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
allTableExe(db, "DROP TABLE IF EXISTS ", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ private void drawGrid(Canvas canvas) {

// time line
mBitPaint.setTextSize(width * 0.03f);
mBitPaint.setTextAlign(Paint.Align.RIGHT);
mBitPaint.setTextAlign(Paint.Align.LEFT);
for (int i = totalSec; i >= 0; i--) {
canvas.drawLine(
0, oneSecY * i,
width, oneSecY * i,
mBitPaint);
int sec = totalSec - i;
int min = sec / 60;
canvas.drawText(String.format("%02d:%02d", min, sec - (60 * min)), width, (oneSecY * i) - 5, mBitPaint);
canvas.drawText(String.format("%02d:%02d", min, sec - (60 * min)), 0, (oneSecY * i) - 5, mBitPaint);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AboutViewModel extends BaseViewModel {

public AboutViewModel(BaseActivity mContext) {
super(mContext);
versionName.set(BuildConfig.VERSION_NAME);
versionName.set(" " + BuildConfig.VERSION_NAME);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,19 @@ private boolean checkRare(Card card){
return false;
}

private boolean checkID(Card card, List<Integer> idList){
private boolean checkID(Card card){
for (Integer integer : evoFilter) {
if (card.getEvolution_id() != 0){
if (idList.contains(card.getId()) && integer == 0){
return true;
for (Integer i : getTypeFilter) {
if (getTypeMap.get(i).contains(card.getId()) && integer == 0){
return true;
}
}
}else {
if (idList.contains(card.getId() - integer)){
return true;
for (Integer i : getTypeFilter) {
if (getTypeMap.get(i).contains(card.getId() - integer)){
return true;
}
}
}
}
Expand All @@ -268,58 +272,69 @@ private boolean checkID(Card card, List<Integer> idList){


private void filterCards(){
List<Integer> idList = new ArrayList<>();
for (Integer integer : getTypeFilter) {
idList.addAll(getTypeMap.get(integer));
}
// 过滤
for (Card card : cardDataList.get().keySet()) {
CardViewModel vm = cardDataList.get().get(card);
if (typeFilter.contains(card.getAttribute().toUpperCase()) && checkRare(card) && checkSkillType(card) && checkID(card, idList)) {
// 符合条件 如不在当前显示的列表中则加入
if (!itemViewModel.contains(vm)){
itemViewModel.add(vm);
}
}else {
// 不符合 如果存在则remove
if (itemViewModel.contains(vm)){
itemViewModel.remove(vm);
Observable<List<Integer>> co = Observable.create(subscriber -> {
List<Integer> cardsToShow = new ArrayList<>();
for (Card card : cardDataList.get().keySet()) {
if (typeFilter.contains(card.getAttribute().toUpperCase()) && checkRare(card) && checkSkillType(card) && checkID(card)) {
cardsToShow.add(card.getId());
}
}
}
subscriber.onNext(cardsToShow);
subscriber.onCompleted();
});
co.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(cards -> {
for (Card card : cardDataList.get().keySet()) {
CardViewModel vm = cardDataList.get().get(card);
if (cards.contains(card.getId())) {
// 符合条件 如不在当前显示的列表中则加入
if (!itemViewModel.contains(vm)){
itemViewModel.add(vm);
}
}else {
// 不符合 如果存在则remove
if (itemViewModel.contains(vm)){
itemViewModel.remove(vm);
}
}
}
Collections.sort(itemViewModel, (a, b) -> {
Card cardA = a.card.get();
Card cardB = b.card.get();
boolean desc = sortMethod == 0;
int valueA;
int valueB;
switch (sortType){
case 1:
valueA = cardA.getVisual_max() + cardA.getBonus_visual();
valueB = cardB.getVisual_max() + cardB.getBonus_visual();
break;
case 2:
valueA = cardA.getVocal_max() + cardA.getBonus_vocal();
valueB = cardB.getVocal_max() + cardB.getBonus_vocal();
break;
case 3:
valueA = cardA.getDance_max() + cardA.getBonus_dance();
valueB = cardB.getDance_max() + cardB.getBonus_dance();
break;
case 4:
valueA = cardA.getOverall_max() + cardA.getOverall_bonus();
valueB = cardB.getOverall_max() + cardB.getOverall_bonus();
break;
default: // also for type ID
valueA = cardA.getSeries_id() - (100000 * SStaticR.typeMap_int.get(cardA.getAttribute().toLowerCase()));
valueB = cardB.getSeries_id() - (100000 * SStaticR.typeMap_int.get(cardB.getAttribute().toLowerCase()));
break;
}
return (desc ? 1 : -1) * (valueB == valueA ? 0 : valueB < valueA ? -1 : 1);
});
umi.dismissLoading();
});


// 排序
Collections.sort(itemViewModel, (a, b) -> {
Card cardA = a.card.get();
Card cardB = b.card.get();
boolean desc = sortMethod == 0;
int valueA;
int valueB;
switch (sortType){
case 1:
valueA = cardA.getVisual_max() + cardA.getBonus_visual();
valueB = cardB.getVisual_max() + cardB.getBonus_visual();
break;
case 2:
valueA = cardA.getVocal_max() + cardA.getBonus_vocal();
valueB = cardB.getVocal_max() + cardB.getBonus_vocal();
break;
case 3:
valueA = cardA.getDance_max() + cardA.getBonus_dance();
valueB = cardB.getDance_max() + cardB.getBonus_dance();
break;
case 4:
valueA = cardA.getOverall_max() + cardA.getOverall_bonus();
valueB = cardB.getOverall_max() + cardB.getOverall_bonus();
break;
default: // also for type ID
valueA = cardA.getSeries_id() - (100000 * SStaticR.typeMap_int.get(cardA.getAttribute().toLowerCase()));
valueB = cardB.getSeries_id() - (100000 * SStaticR.typeMap_int.get(cardB.getAttribute().toLowerCase()));
break;
}
return (desc ? 1 : -1) * (valueB == valueA ? 0 : valueB < valueA ? -1 : 1);
});
umi.dismissLoading();

}

public static final Map<Integer, List<Integer>> getTypeMap = new HashMap<>(); // 0-常驻,1-限定,2-FES,3-活动
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ private void setData(Chara chara) {
constellation.set(!SStaticR.connMap.containsKey(con_jp) ? con_jp : mContext.getString(SStaticR.connMap.get(con_jp)));
age.set(getRealText(chara.getAge(), 6) + mContext.getString(R.string.unit_age));
hometown.set(getRealText(chara.getHome_town(), 2));
weight.set(getRealText(chara.getWeight(), 6) + mContext.getString(R.string.unit_weight));
String weightW = getRealText(chara.getWeight(), 6);
weight.set(weightW.equals(String.valueOf(chara.getWeight())) ? weightW + mContext.getString(R.string.unit_weight) : weightW);
}

public CharaViewModel(BaseActivity mContext, String charaId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ private void checkData() {
update = true;
}
if (update){
umi.dismissLoading();
haveUpdate.set(true);
android.databinding.Observable.OnPropertyChangedCallback agreeCallBack = new android.databinding.Observable.OnPropertyChangedCallback() {
@Override
Expand All @@ -159,7 +160,6 @@ public void onPropertyChanged(android.databinding.Observable observable, int i)
}else {
upToDate.set(true);
}
umi.dismissLoading();
}, ExceptionHandler::handleException);


Expand Down Expand Up @@ -318,7 +318,7 @@ private void doUpDateDB(boolean updateManifest, String truthVersion) {

List<Card> newCardList = new ArrayList<>();
// 数据库操作
Observable<Boolean> dataBaseOB = Observable.create(subscriber -> {
Observable<Integer> dataBaseOB = Observable.create(subscriber -> {
ContentValues contentValues = new ContentValues();
Map<Integer, CharaIndex> charaIndexMap_exist = new HashMap<>();
Map<Integer, CharaIndex> charaIndexMap_new = new HashMap<>();
Expand All @@ -329,62 +329,75 @@ private void doUpDateDB(boolean updateManifest, String truthVersion) {
CharaIndex ci = JsonUtils.getBeanFromJson(json, CharaIndex.class);
charaIndexMap_exist.put(ci.getChara_id(), ci);
}
// SparseArray<CharaIndex> charaIndexMap = new SparseArray<>();
for (Card card : newCardList) {
contentValues.clear();
contentValues.put("id", String.valueOf(card.getId()));
contentValues.put("json", JsonUtils.getJsonFromBean(card));
subscriber.onNext(DBHelper.with(mContext).insertData(DBHelper.TABLE_NAME_Card, contentValues));
boolean oldChara = charaIndexMap_exist.containsKey(card.getChara_id());

if (oldChara) { // 旧偶像有新卡
if (!charaIndexMap_update.containsKey(card.getChara_id())) {
total++;

DBHelper.with(mContext).beginTran();
try {
for (Card card : newCardList) {
contentValues.clear();
contentValues.put("id", String.valueOf(card.getId()));
contentValues.put("json", JsonUtils.getJsonFromBean(card));
DBHelper.with(mContext).insertData(DBHelper.TABLE_NAME_Card, contentValues);
boolean oldChara = charaIndexMap_exist.containsKey(card.getChara_id());

if (oldChara) { // 旧偶像有新卡
if (!charaIndexMap_update.containsKey(card.getChara_id())) {
total++;
}
charaIndexMap_update.put(card.getChara_id(), charaIndexMap_exist.get(card.getChara_id()));
}
charaIndexMap_update.put(card.getChara_id(), charaIndexMap_exist.get(card.getChara_id()));
}

if (!oldChara && !charaIndexMap_new.containsKey(card.getChara_id())) { // 新偶像,先新增
Chara chara = card.getChara();
charaMap.put(card.getChara_id(), chara);
CharaIndex charaIndex = new CharaIndex();
charaIndex.setChara_id(chara.getChara_id());
charaIndex.setConventional(chara.getConventional());
charaIndex.setKana_spaced(chara.getKana_spaced());
charaIndex.setKanji_spaced(chara.getKanji_spaced());
List<Integer> cardList = new ArrayList<>();
cardList.add(card.getId());
charaIndex.setCards(cardList);
charaIndexMap_new.put(chara.getChara_id(), charaIndex);
total = total + 2;
} else {
if (oldChara) {
charaIndexMap_update.get(card.getChara_id()).getCards().add(card.getId());
if (!oldChara && !charaIndexMap_new.containsKey(card.getChara_id())) { // 新偶像,先新增
Chara chara = card.getChara();
charaMap.put(card.getChara_id(), chara);
CharaIndex charaIndex = new CharaIndex();
charaIndex.setChara_id(chara.getChara_id());
charaIndex.setConventional(chara.getConventional());
charaIndex.setKana_spaced(chara.getKana_spaced());
charaIndex.setKanji_spaced(chara.getKanji_spaced());
List<Integer> cardList = new ArrayList<>();
cardList.add(card.getId());
charaIndex.setCards(cardList);
charaIndexMap_new.put(chara.getChara_id(), charaIndex);
total = total + 2;
} else {
charaIndexMap_new.get(card.getChara_id()).getCards().add(card.getId());
if (oldChara) {
charaIndexMap_update.get(card.getChara_id()).getCards().add(card.getId());
} else {
charaIndexMap_new.get(card.getChara_id()).getCards().add(card.getId());
}
}
}
}
// 更新旧偶像卡片目录
for (CharaIndex charaIndex : charaIndexMap_update.values()) {
contentValues.clear();
contentValues.put("id", String.valueOf(charaIndex.getChara_id()));
contentValues.put("json", JsonUtils.getJsonFromBean(charaIndex));
subscriber.onNext(DBHelper.with(mContext).updateData(DBHelper.TABLE_NAME_Chara_Index, contentValues, "id = ?", new String[]{String.valueOf(charaIndex.getChara_id())}));
}
// 偶像目录信息新增
for (CharaIndex charaIndex : charaIndexMap_new.values()) {
contentValues.clear();
contentValues.put("id", String.valueOf(charaIndex.getChara_id()));
contentValues.put("json", JsonUtils.getJsonFromBean(charaIndex));
subscriber.onNext(DBHelper.with(mContext).insertData(DBHelper.TABLE_NAME_Chara_Index, contentValues));
}
// 偶像详情信息增加
for (Chara chara : charaMap.values()) {
contentValues.clear();
contentValues.put("id", String.valueOf(chara.getChara_id()));
contentValues.put("json", JsonUtils.getJsonFromBean(chara));
subscriber.onNext(DBHelper.with(mContext).insertData(DBHelper.TABLE_NAME_Chara_Detail, contentValues));
subscriber.onNext(newCardList.size());
// 更新旧偶像卡片目录
for (CharaIndex charaIndex : charaIndexMap_update.values()) {
contentValues.clear();
contentValues.put("id", String.valueOf(charaIndex.getChara_id()));
contentValues.put("json", JsonUtils.getJsonFromBean(charaIndex));
DBHelper.with(mContext).updateData(DBHelper.TABLE_NAME_Chara_Index, contentValues, "id = ?", new String[]{String.valueOf(charaIndex.getChara_id())});
}
subscriber.onNext(charaIndexMap_update.size());
// 偶像目录信息新增
for (CharaIndex charaIndex : charaIndexMap_new.values()) {
contentValues.clear();
contentValues.put("id", String.valueOf(charaIndex.getChara_id()));
contentValues.put("json", JsonUtils.getJsonFromBean(charaIndex));
DBHelper.with(mContext).insertData(DBHelper.TABLE_NAME_Chara_Index, contentValues);
}
subscriber.onNext(charaIndexMap_new.size());
// 偶像详情信息增加
for (Chara chara : charaMap.values()) {
contentValues.clear();
contentValues.put("id", String.valueOf(chara.getChara_id()));
contentValues.put("json", JsonUtils.getJsonFromBean(chara));
DBHelper.with(mContext).insertData(DBHelper.TABLE_NAME_Chara_Detail, contentValues);
}
subscriber.onNext(charaMap.size());
DBHelper.with(mContext).setTranSuccess();
}catch (Exception e){
e.printStackTrace();
subscriber.onNext(-1);
}finally {
DBHelper.with(mContext).endTran();
}
subscriber.onCompleted();
});
Expand All @@ -399,11 +412,12 @@ private void doUpDateDB(boolean updateManifest, String truthVersion) {
dataBaseOB.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(((ActivityLifecycleProvider) mContext).bindToLifecycle())
.subscribe(b -> { // 更新处理进度
if (b) {
.subscribe(integer -> { // 更新处理进度
if (integer >= 0) {
solved += integer;
if (solved < total - 1) {
progress.set((float) ++solved / (float) total);
progressTxt.set(getProgress());
/*progress.set((float) ++solved / (float) total);
progressTxt.set(getProgress());*/
} else if (!updateManifest || truthVersion == null) {
progress.set(1);
progressTxt.set("100%");
Expand Down
Loading

0 comments on commit 0efb363

Please sign in to comment.