Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
Invinciblelee committed May 10, 2019
1 parent 433e75a commit 064218d
Show file tree
Hide file tree
Showing 46 changed files with 334 additions and 213 deletions.
7 changes: 7 additions & 0 deletions app/src/main/assets/updateLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
## 本软件为开源软件,没有上架Google Play,没有在任何地方售卖,如果想支持我请通过软件里的捐赠,不要在任何地方购买!
## 更新日志
#### 彩蛋,领支付宝红包有惊喜
**2019/05/10**
*修复一些bug
*书架按钮长按更新
*新增更新提醒标签
*规则缓存
*修复部分json格式判断失败

**2019/05/05**
*修复发现列表重复bug
*修复内置书源
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ public void applyNightTheme() {
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
getDelegate().applyDayNight();
if(!isFinishing()) {
getDelegate().applyDayNight();
}
}

public void startActivityByAnim(Intent intent, int animIn, int animExit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
public class BookShelfBean implements Parcelable, VariableStore {
@Transient
public static final String LOCAL_TAG = "loc_book";
@Transient
private boolean isLoading;

@Id
private String noteUrl; //对应BookInfoBean noteUrl;
Expand Down Expand Up @@ -52,6 +50,8 @@ public class BookShelfBean implements Parcelable, VariableStore {
private List<BookmarkBean> bookmarkList = new ArrayList<>(); //书签列表
@Transient
private boolean changeSource;
@Transient
private boolean isLoading;

public BookShelfBean() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ public void setLastNoteUrl(String lastNoteUrl) {
editor.apply();
}



public int getTextSize() {
return textSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ private void newRefreshTask() {
dispatchFinishEvent();
}
} else {
bookShelfBean.setLoading(true);
dispatchRefreshEvent(bookShelfBean);
dispatchRefreshEvent(bookShelfBean, true);
refreshBookShelf(bookShelfBean);
}
}
Expand Down Expand Up @@ -190,8 +189,7 @@ public void onError(Throwable e) {
}

private void whenRefreshNext(BookShelfBean bookShelfBean, boolean error) {
bookShelfBean.setLoading(false);
dispatchRefreshEvent(bookShelfBean);
dispatchRefreshEvent(bookShelfBean, false);
if (error) {
errBooks.add(bookShelfBean.getBookInfoBean().getName());
}
Expand All @@ -213,7 +211,6 @@ private void whenRefreshNext(BookShelfBean bookShelfBean, boolean error) {
private Observable<BookShelfBean> saveBookToShelfO(BookShelfBean bookShelfBean) {
return Observable.create(e -> {
if (BookshelfHelp.isInBookShelf(bookShelfBean.getNoteUrl())) {//移出了书架
BookshelfHelp.delChapterList(bookShelfBean.getNoteUrl());
BookshelfHelp.saveBookToShelf(bookShelfBean);
}
bookShelfBean.setChapterList(null, false);
Expand All @@ -228,15 +225,16 @@ private void dispatchResultEvent(List<BookShelfBean> bookShelfBeans) {
}
}

private void dispatchRefreshEvent(BookShelfBean bookShelfBean) {
private void dispatchRefreshEvent(BookShelfBean bookShelfBean, boolean loading) {
if (refreshListener != null) {
bookShelfBean.setLoading(loading);
refreshListener.onRefresh(bookShelfBean);
}
}

private void dispatchErrorEvent(String msg) {
if (refreshListener != null) {
refreshListener.onError(msg);
refreshListener.onMessage(msg);
}
}

Expand Down Expand Up @@ -286,7 +284,7 @@ void moveToNext() {
public interface OnBookRefreshListener {
void onResult(List<BookShelfBean> bookShelfBeans);

void onError(String msg);
void onMessage(String msg);

void onRefresh(BookShelfBean bookShelfBean);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ private Observable<BookShelfBean> updateChapterList(BookShelfBean bookShelfBean,
}

if (!chapterList.isEmpty()) {
BookshelfHelp.delChapterList(bookShelfBean.getNoteUrl());
bookShelfBean.setChapterList(chapterList, true);
bookShelfBean.upLastChapterName();
if (!TextUtils.isEmpty(bookShelfBean.getDurChapterName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.monke.monkeybook.bean.VariableStore;
import com.monke.monkeybook.model.SimpleModel;
import com.monke.monkeybook.model.analyzeRule.assit.Global;
import com.monke.monkeybook.utils.ListUtils;
import com.monke.monkeybook.utils.StringUtils;
import com.monke.monkeybook.utils.URLUtils;

Expand Down Expand Up @@ -45,11 +44,11 @@ final VariableStore getVariableStore() {
return mAnalyzer.getConfig().getVariableStore();
}

Object getCache(String key) {
final Object getCache(String key) {
return mCache.get(key);
}

void putCache(String key, Object value) {
final void putCache(String key, Object value) {
mCache.put(key, value);
}

Expand Down Expand Up @@ -94,23 +93,30 @@ String evalStringScript(@NonNull Object result, @NonNull RulePattern rulePattern
}

List<String> evalStringArrayScript(@NonNull Object result, @NonNull RulePattern rulePattern) {
final List<String> list = new ArrayList<>();
if (!rulePattern.javaScripts.isEmpty()) {
for (String javaScript : rulePattern.javaScripts) {
List<Object> resultList = Global.evalArrayScript(javaScript, this, result, getBaseURL());
list.addAll(ListUtils.toStringList(resultList));
result = Global.evalArrayScript(javaScript, this, result, getBaseURL());
}
}
final List<String> list = new ArrayList<>();
if (result instanceof List) {
for (Object object : (List) result) {
list.add(StringUtils.valueOf(object));
}
}
return list;
}

List<Object> evalObjectArrayScript(@NonNull Object result, @NonNull RulePattern rulePattern) {
final List<Object> list = new ArrayList<>();
if (!rulePattern.javaScripts.isEmpty()) {
for (String javaScript : rulePattern.javaScripts) {
list.addAll(Global.evalArrayScript(javaScript, this, result, getBaseURL()));
result = Global.evalArrayScript(javaScript, this, result, getBaseURL());
}
}
final List<Object> list = new ArrayList<>();
if (result instanceof List) {
list.addAll((List) result);
}
return list;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ private RawResult<List<ChapterBean>> getRawChaptersResult(String s, String ruleC
final String url;
if (content instanceof NativeObject) {
NativeObject object = (NativeObject) content;
name = StringUtils.valueOf(object.get("name"));
url = StringUtils.valueOf(object.get("url"));
String nameKey = StringUtils.checkBlank(getBookSource().getRuleChapterName(), "name");
String urlKey = StringUtils.checkBlank(getBookSource().getRuleContentUrl(), "url");
name = StringUtils.valueOf(object.get(nameKey));
url = StringUtils.valueOf(object.get(urlKey));
} else {
mAnalyzer.setContent(content);
name = mAnalyzer.getResultContent(getBookSource().getRuleChapterName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Object fromObject(Object source) {
sourceChangedJS = true;
sourceChangedJP = true;
sourceChangedCS = true;
isJSon = Global.isJson(StringUtils.valueOf(source));
isJSon = Global.isJson(source);
return source;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.monke.monkeybook.model.analyzeRule;

import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -79,7 +78,6 @@ private String replaceVariableValue(VariableStore variableStore, String rawRule)
while (getMatcher.find()) {
final String group = getMatcher.group();
final String value = variableStore.getVariable(group.substring(6, group.length() - 1));
Log.e("TAG", group + " " + value);
rawRule = rawRule.replace(group, value != null ? value : "");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ private VariablesPattern(@NonNull String ruleStr, int flag) {
}

analyzePutterMap(ruleStr);

}

private boolean findWhere(String ruleStr, Pattern pattern) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.google.gson.GsonBuilder;
import com.monke.monkeybook.help.Logger;
import com.monke.monkeybook.model.analyzeRule.JavaExecutor;
import com.monke.monkeybook.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -26,9 +25,13 @@ public final class Global {
private Global() {
}

public static boolean isJson(String string) {
public static boolean isJson(Object object) {
try {
GSON.fromJson(string, Object.class);
if (object instanceof String) {
GSON.fromJson((String) object, Object.class);
} else {
GSON.toJson(object);
}
return true;
} catch (Exception ignore) {
}
Expand All @@ -40,7 +43,7 @@ public static List<Object> evalArrayScript(String jsStr, JavaExecutor java, Obje
final List<Object> resultList = new ArrayList<>();
if (object instanceof List) {
resultList.addAll((List) object);
} else {
} else if (object != null) {
resultList.add(object);
}
return resultList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void onResult(List<BookShelfBean> bookShelfBeans) {
}

@Override
public void onError(String msg) {
public void onMessage(String msg) {
mView.toast(msg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void onResult(List<BookShelfBean> bookShelfBeans) {
}

@Override
public void onError(String msg) {
public void onMessage(String msg) {
mView.refreshError(msg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,15 +722,14 @@ private void cancelProgressTimer() {
private void setAlarmTimer() {
if (mAlertTimer == null || mAlertTimer.isShutdown()) {
mAlertTimer = Executors.newSingleThreadScheduledExecutor();
mAlertTimer.scheduleAtFixedRate(() -> {
Intent intent = new Intent(AudioBookPlayService.this, AudioBookPlayService.class);
intent.setAction(ACTION_TIMER_PROGRESS);
intent.putExtra("minute", -1);
startService(intent);
}, 60 * 1000, 60 * 1000, TimeUnit.MILLISECONDS);
}

mAlertTimer.scheduleAtFixedRate(() -> {
Intent intent = new Intent(AudioBookPlayService.this, AudioBookPlayService.class);
intent.setAction(ACTION_TIMER_PROGRESS);
intent.putExtra("minute", -1);
startService(intent);
}, 60 * 1000, 60 * 1000, TimeUnit.MILLISECONDS);

sendEvent(ACTION_TIMER_PROGRESS, AudioPlayInfo.timerDown(timerUntilFinish));
updateNotification();
}
Expand Down
55 changes: 55 additions & 0 deletions app/src/main/java/com/monke/monkeybook/utils/ContextUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.monke.monkeybook.utils;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

public class ContextUtils {

private ContextUtils(){

}

public static Activity scanForActivity(Context context) {
if (context == null) return null;

if (context instanceof Activity) {
return (Activity) context;
} else if (context instanceof ContextWrapper) {
return scanForActivity(((ContextWrapper) context).getBaseContext());
}

return null;
}

public static Activity scanForActivity(View view) {
if (view == null) return null;

Context context = view.getContext();
return scanForActivity(context);
}

public static AppCompatActivity getCompatActivity(Context context) {
if (context == null) return null;
if (context instanceof AppCompatActivity) {
return (AppCompatActivity) context;
} else if (context instanceof androidx.appcompat.view.ContextThemeWrapper) {
return getCompatActivity(((androidx.appcompat.view.ContextThemeWrapper) context).getBaseContext());
}else if(context instanceof android.view.ContextThemeWrapper){
return getCompatActivity(((android.view.ContextThemeWrapper) context).getBaseContext());
}
return null;
}

public static AppCompatActivity getCompatActivity(View view) {
if (view == null) return null;

Context context = view.getContext();
return getCompatActivity(context);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class MarkdownUtils {

@SuppressWarnings("deprecation")
public static CharSequence simpleMarkdownConverter(String text) {
if(text == null) return "";
Pattern listPtn = Pattern.compile("^[\\-*] ");
Pattern headPtn = Pattern.compile("^(#{1,6}) ");
String strongemPtn = "\\*\\*\\*([^*]+)\\*\\*\\*";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ public static int stringToInt(String str) {
return -1;
}


public static String clearString(String str) {
if (str == null) {
return "";
Expand Down Expand Up @@ -343,6 +342,13 @@ public static boolean isNotBlank(String text) {
return !isBlank(text);
}

public static String checkBlank(String text, String defVal) {
if (isBlank(text)) {
return defVal == null ? "" : defVal;
}
return text;
}

public static String trim(String string) {
return string == null ? "" : string.trim();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,6 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
return super.onKeyDown(keyCode, event);
}

@Override
public void recreate() {
super.recreate();
}

public void exit() {
if ((System.currentTimeMillis() - exitTime) > 2000) {
showSnackBar("再按一次退出程序");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void onBindViewHolder(@NonNull MyViewHolder holder, int position, @NonNul
}

if (item.isLoading()) {
holder.tvHasNew.setVisibility(View.INVISIBLE);
holder.rotateLoading.setVisibility(View.VISIBLE);
} else {
holder.rotateLoading.setVisibility(View.INVISIBLE);
Expand Down
Loading

0 comments on commit 064218d

Please sign in to comment.