From 064218daf104e5d25f824386c1270fd01c6e86ed Mon Sep 17 00:00:00 2001 From: Invinciblelee <1760316362@qq.com> Date: Fri, 10 May 2019 18:42:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 7 + .../monke/monkeybook/base/MBaseActivity.java | 4 +- .../monke/monkeybook/bean/BookShelfBean.java | 4 +- .../monkeybook/help/ReadBookControl.java | 2 + .../model/BookRefreshModelImpl.java | 14 +- .../monke/monkeybook/model/WebBookModel.java | 1 + .../analyzeRule/BaseAnalyzerPresenter.java | 22 ++- .../analyzeRule/DefaultContentDelegate.java | 6 +- .../model/analyzeRule/HybridParser.java | 2 +- .../model/analyzeRule/RulePattern.java | 2 - .../model/analyzeRule/VariablesPattern.java | 1 - .../model/analyzeRule/assit/Global.java | 11 +- .../presenter/AudioBookPresenterImpl.java | 2 +- .../presenter/BookListPresenterImpl.java | 2 +- .../service/AudioBookPlayService.java | 13 +- .../monke/monkeybook/utils/ContextUtils.java | 55 ++++++ .../monke/monkeybook/utils/MarkdownUtils.java | 1 + .../monke/monkeybook/utils/StringUtils.java | 8 +- .../view/activity/MainActivity.java | 5 - .../view/adapter/BookShelfGridAdapter.java | 1 - .../view/adapter/BookShelfListAdapter.java | 1 - .../view/fragment/dialog/AlertController.java | 2 +- .../view/fragment/dialog/AlertDialog.java | 2 +- .../view/fragment/dialog/AppCompatDialog.java | 3 +- .../view/fragment/dialog/BookmarkDialog.java | 2 +- .../fragment/dialog/ChangeSourceDialog.java | 2 +- .../view/fragment/dialog/DownLoadDialog.java | 2 +- .../view/fragment/dialog/InputDialog.java | 2 +- .../view/fragment/dialog/LargeTextDialog.java | 21 +- .../view/fragment/dialog/ProgressDialog.java | 2 +- .../fragment/dialog/ReplaceRuleDialog.java | 2 +- .../view/popupwindow/CheckAddShelfPop.java | 3 +- .../widget/DialogContainerLayout.java | 65 ++++++- .../monkeybook/widget/page/NetPageLoader.java | 1 - .../main/res/layout/activity_read_style.xml | 2 +- app/src/main/res/layout/dialog_alert.xml | 180 +++++++++--------- app/src/main/res/layout/dialog_bookmark.xml | 1 - app/src/main/res/layout/dialog_large_text.xml | 4 +- .../main/res/layout/item_bookshelf_grid.xml | 24 +-- .../main/res/layout/item_bookshelf_list.xml | 28 +-- .../main/res/layout/pop_check_add_shelf.xml | 8 + app/src/main/res/values/pref_key_value.xml | 2 +- app/src/main/res/values/styles.xml | 4 +- app/version.properties | 4 +- .../com/monke/basemvplib/AjaxWebView.java | 13 +- .../com/monke/basemvplib/BaseModelImpl.java | 4 +- 46 files changed, 334 insertions(+), 213 deletions(-) create mode 100644 app/src/main/java/com/monke/monkeybook/utils/ContextUtils.java create mode 100644 app/src/main/res/layout/pop_check_add_shelf.xml diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 255f229..09466e1 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -1,6 +1,13 @@ ## 本软件为开源软件,没有上架Google Play,没有在任何地方售卖,如果想支持我请通过软件里的捐赠,不要在任何地方购买! ## 更新日志 #### 彩蛋,领支付宝红包有惊喜 +**2019/05/10** +*修复一些bug +*书架按钮长按更新 +*新增更新提醒标签 +*规则缓存 +*修复部分json格式判断失败 + **2019/05/05** *修复发现列表重复bug *修复内置书源 diff --git a/app/src/main/java/com/monke/monkeybook/base/MBaseActivity.java b/app/src/main/java/com/monke/monkeybook/base/MBaseActivity.java index 4e1c01a..9c20658 100644 --- a/app/src/main/java/com/monke/monkeybook/base/MBaseActivity.java +++ b/app/src/main/java/com/monke/monkeybook/base/MBaseActivity.java @@ -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) { diff --git a/app/src/main/java/com/monke/monkeybook/bean/BookShelfBean.java b/app/src/main/java/com/monke/monkeybook/bean/BookShelfBean.java index 68ccebb..afb9862 100644 --- a/app/src/main/java/com/monke/monkeybook/bean/BookShelfBean.java +++ b/app/src/main/java/com/monke/monkeybook/bean/BookShelfBean.java @@ -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; @@ -52,6 +50,8 @@ public class BookShelfBean implements Parcelable, VariableStore { private List bookmarkList = new ArrayList<>(); //书签列表 @Transient private boolean changeSource; + @Transient + private boolean isLoading; public BookShelfBean() { } diff --git a/app/src/main/java/com/monke/monkeybook/help/ReadBookControl.java b/app/src/main/java/com/monke/monkeybook/help/ReadBookControl.java index 25ef292..920bb50 100644 --- a/app/src/main/java/com/monke/monkeybook/help/ReadBookControl.java +++ b/app/src/main/java/com/monke/monkeybook/help/ReadBookControl.java @@ -382,6 +382,8 @@ public void setLastNoteUrl(String lastNoteUrl) { editor.apply(); } + + public int getTextSize() { return textSize; } diff --git a/app/src/main/java/com/monke/monkeybook/model/BookRefreshModelImpl.java b/app/src/main/java/com/monke/monkeybook/model/BookRefreshModelImpl.java index f14d461..7d90e21 100644 --- a/app/src/main/java/com/monke/monkeybook/model/BookRefreshModelImpl.java +++ b/app/src/main/java/com/monke/monkeybook/model/BookRefreshModelImpl.java @@ -157,8 +157,7 @@ private void newRefreshTask() { dispatchFinishEvent(); } } else { - bookShelfBean.setLoading(true); - dispatchRefreshEvent(bookShelfBean); + dispatchRefreshEvent(bookShelfBean, true); refreshBookShelf(bookShelfBean); } } @@ -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()); } @@ -213,7 +211,6 @@ private void whenRefreshNext(BookShelfBean bookShelfBean, boolean error) { private Observable saveBookToShelfO(BookShelfBean bookShelfBean) { return Observable.create(e -> { if (BookshelfHelp.isInBookShelf(bookShelfBean.getNoteUrl())) {//移出了书架 - BookshelfHelp.delChapterList(bookShelfBean.getNoteUrl()); BookshelfHelp.saveBookToShelf(bookShelfBean); } bookShelfBean.setChapterList(null, false); @@ -228,15 +225,16 @@ private void dispatchResultEvent(List 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); } } @@ -286,7 +284,7 @@ void moveToNext() { public interface OnBookRefreshListener { void onResult(List bookShelfBeans); - void onError(String msg); + void onMessage(String msg); void onRefresh(BookShelfBean bookShelfBean); diff --git a/app/src/main/java/com/monke/monkeybook/model/WebBookModel.java b/app/src/main/java/com/monke/monkeybook/model/WebBookModel.java index 212d38a..213a520 100644 --- a/app/src/main/java/com/monke/monkeybook/model/WebBookModel.java +++ b/app/src/main/java/com/monke/monkeybook/model/WebBookModel.java @@ -162,6 +162,7 @@ private Observable updateChapterList(BookShelfBean bookShelfBean, } if (!chapterList.isEmpty()) { + BookshelfHelp.delChapterList(bookShelfBean.getNoteUrl()); bookShelfBean.setChapterList(chapterList, true); bookShelfBean.upLastChapterName(); if (!TextUtils.isEmpty(bookShelfBean.getDurChapterName())) { diff --git a/app/src/main/java/com/monke/monkeybook/model/analyzeRule/BaseAnalyzerPresenter.java b/app/src/main/java/com/monke/monkeybook/model/analyzeRule/BaseAnalyzerPresenter.java index 65b34c8..7f56e7d 100644 --- a/app/src/main/java/com/monke/monkeybook/model/analyzeRule/BaseAnalyzerPresenter.java +++ b/app/src/main/java/com/monke/monkeybook/model/analyzeRule/BaseAnalyzerPresenter.java @@ -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; @@ -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); } @@ -94,23 +93,30 @@ String evalStringScript(@NonNull Object result, @NonNull RulePattern rulePattern } List evalStringArrayScript(@NonNull Object result, @NonNull RulePattern rulePattern) { - final List list = new ArrayList<>(); if (!rulePattern.javaScripts.isEmpty()) { for (String javaScript : rulePattern.javaScripts) { - List resultList = Global.evalArrayScript(javaScript, this, result, getBaseURL()); - list.addAll(ListUtils.toStringList(resultList)); + result = Global.evalArrayScript(javaScript, this, result, getBaseURL()); + } + } + final List list = new ArrayList<>(); + if (result instanceof List) { + for (Object object : (List) result) { + list.add(StringUtils.valueOf(object)); } } return list; } List evalObjectArrayScript(@NonNull Object result, @NonNull RulePattern rulePattern) { - final List 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 list = new ArrayList<>(); + if (result instanceof List) { + list.addAll((List) result); + } return list; } diff --git a/app/src/main/java/com/monke/monkeybook/model/analyzeRule/DefaultContentDelegate.java b/app/src/main/java/com/monke/monkeybook/model/analyzeRule/DefaultContentDelegate.java index 0d2ce46..e5bf3a4 100644 --- a/app/src/main/java/com/monke/monkeybook/model/analyzeRule/DefaultContentDelegate.java +++ b/app/src/main/java/com/monke/monkeybook/model/analyzeRule/DefaultContentDelegate.java @@ -179,8 +179,10 @@ private RawResult> 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()); diff --git a/app/src/main/java/com/monke/monkeybook/model/analyzeRule/HybridParser.java b/app/src/main/java/com/monke/monkeybook/model/analyzeRule/HybridParser.java index a452924..39e0445 100644 --- a/app/src/main/java/com/monke/monkeybook/model/analyzeRule/HybridParser.java +++ b/app/src/main/java/com/monke/monkeybook/model/analyzeRule/HybridParser.java @@ -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; } diff --git a/app/src/main/java/com/monke/monkeybook/model/analyzeRule/RulePattern.java b/app/src/main/java/com/monke/monkeybook/model/analyzeRule/RulePattern.java index 8a76f02..176acf9 100644 --- a/app/src/main/java/com/monke/monkeybook/model/analyzeRule/RulePattern.java +++ b/app/src/main/java/com/monke/monkeybook/model/analyzeRule/RulePattern.java @@ -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; @@ -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 : ""); } } diff --git a/app/src/main/java/com/monke/monkeybook/model/analyzeRule/VariablesPattern.java b/app/src/main/java/com/monke/monkeybook/model/analyzeRule/VariablesPattern.java index 16518b2..753e9aa 100644 --- a/app/src/main/java/com/monke/monkeybook/model/analyzeRule/VariablesPattern.java +++ b/app/src/main/java/com/monke/monkeybook/model/analyzeRule/VariablesPattern.java @@ -28,7 +28,6 @@ private VariablesPattern(@NonNull String ruleStr, int flag) { } analyzePutterMap(ruleStr); - } private boolean findWhere(String ruleStr, Pattern pattern) { diff --git a/app/src/main/java/com/monke/monkeybook/model/analyzeRule/assit/Global.java b/app/src/main/java/com/monke/monkeybook/model/analyzeRule/assit/Global.java index 870e5d5..a89154e 100644 --- a/app/src/main/java/com/monke/monkeybook/model/analyzeRule/assit/Global.java +++ b/app/src/main/java/com/monke/monkeybook/model/analyzeRule/assit/Global.java @@ -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; @@ -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) { } @@ -40,7 +43,7 @@ public static List evalArrayScript(String jsStr, JavaExecutor java, Obje final List resultList = new ArrayList<>(); if (object instanceof List) { resultList.addAll((List) object); - } else { + } else if (object != null) { resultList.add(object); } return resultList; diff --git a/app/src/main/java/com/monke/monkeybook/presenter/AudioBookPresenterImpl.java b/app/src/main/java/com/monke/monkeybook/presenter/AudioBookPresenterImpl.java index 0a28ac3..ab24ae4 100644 --- a/app/src/main/java/com/monke/monkeybook/presenter/AudioBookPresenterImpl.java +++ b/app/src/main/java/com/monke/monkeybook/presenter/AudioBookPresenterImpl.java @@ -47,7 +47,7 @@ public void onResult(List bookShelfBeans) { } @Override - public void onError(String msg) { + public void onMessage(String msg) { mView.toast(msg); } diff --git a/app/src/main/java/com/monke/monkeybook/presenter/BookListPresenterImpl.java b/app/src/main/java/com/monke/monkeybook/presenter/BookListPresenterImpl.java index 91d34fe..4b7ac85 100644 --- a/app/src/main/java/com/monke/monkeybook/presenter/BookListPresenterImpl.java +++ b/app/src/main/java/com/monke/monkeybook/presenter/BookListPresenterImpl.java @@ -77,7 +77,7 @@ public void onResult(List bookShelfBeans) { } @Override - public void onError(String msg) { + public void onMessage(String msg) { mView.refreshError(msg); } diff --git a/app/src/main/java/com/monke/monkeybook/service/AudioBookPlayService.java b/app/src/main/java/com/monke/monkeybook/service/AudioBookPlayService.java index 6994e43..7f7c33d 100644 --- a/app/src/main/java/com/monke/monkeybook/service/AudioBookPlayService.java +++ b/app/src/main/java/com/monke/monkeybook/service/AudioBookPlayService.java @@ -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(); } diff --git a/app/src/main/java/com/monke/monkeybook/utils/ContextUtils.java b/app/src/main/java/com/monke/monkeybook/utils/ContextUtils.java new file mode 100644 index 0000000..e88dc51 --- /dev/null +++ b/app/src/main/java/com/monke/monkeybook/utils/ContextUtils.java @@ -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); + } + + +} diff --git a/app/src/main/java/com/monke/monkeybook/utils/MarkdownUtils.java b/app/src/main/java/com/monke/monkeybook/utils/MarkdownUtils.java index c9e360d..afbe67e 100644 --- a/app/src/main/java/com/monke/monkeybook/utils/MarkdownUtils.java +++ b/app/src/main/java/com/monke/monkeybook/utils/MarkdownUtils.java @@ -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 = "\\*\\*\\*([^*]+)\\*\\*\\*"; diff --git a/app/src/main/java/com/monke/monkeybook/utils/StringUtils.java b/app/src/main/java/com/monke/monkeybook/utils/StringUtils.java index a909edf..3bb4893 100644 --- a/app/src/main/java/com/monke/monkeybook/utils/StringUtils.java +++ b/app/src/main/java/com/monke/monkeybook/utils/StringUtils.java @@ -212,7 +212,6 @@ public static int stringToInt(String str) { return -1; } - public static String clearString(String str) { if (str == null) { return ""; @@ -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(); } diff --git a/app/src/main/java/com/monke/monkeybook/view/activity/MainActivity.java b/app/src/main/java/com/monke/monkeybook/view/activity/MainActivity.java index d732945..3a69643 100644 --- a/app/src/main/java/com/monke/monkeybook/view/activity/MainActivity.java +++ b/app/src/main/java/com/monke/monkeybook/view/activity/MainActivity.java @@ -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("再按一次退出程序"); diff --git a/app/src/main/java/com/monke/monkeybook/view/adapter/BookShelfGridAdapter.java b/app/src/main/java/com/monke/monkeybook/view/adapter/BookShelfGridAdapter.java index 3a99842..50572f6 100644 --- a/app/src/main/java/com/monke/monkeybook/view/adapter/BookShelfGridAdapter.java +++ b/app/src/main/java/com/monke/monkeybook/view/adapter/BookShelfGridAdapter.java @@ -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); diff --git a/app/src/main/java/com/monke/monkeybook/view/adapter/BookShelfListAdapter.java b/app/src/main/java/com/monke/monkeybook/view/adapter/BookShelfListAdapter.java index b3e06db..7ac0e77 100644 --- a/app/src/main/java/com/monke/monkeybook/view/adapter/BookShelfListAdapter.java +++ b/app/src/main/java/com/monke/monkeybook/view/adapter/BookShelfListAdapter.java @@ -100,7 +100,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); diff --git a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/AlertController.java b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/AlertController.java index 62bfbc7..de00719 100644 --- a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/AlertController.java +++ b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/AlertController.java @@ -153,7 +153,7 @@ public void handleMessage(Message msg) { View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container) { if (mAlertView == null) { - mAlertView = inflater.inflate(R.layout.dialog_alert, container, false); + mAlertView = inflater.inflate(R.layout.dialog_alert, container, true); } return mAlertView; } diff --git a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/AlertDialog.java b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/AlertDialog.java index 41fcdd6..e17af11 100644 --- a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/AlertDialog.java +++ b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/AlertDialog.java @@ -46,7 +46,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { } @Override - public View onCreateDialogView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + public View onCreateDialogContentView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return mAlert.onCreateView(inflater, container); } diff --git a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/AppCompatDialog.java b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/AppCompatDialog.java index dd2c134..7c4af31 100644 --- a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/AppCompatDialog.java +++ b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/AppCompatDialog.java @@ -1,6 +1,7 @@ package com.monke.monkeybook.view.fragment.dialog; import android.app.Dialog; +import android.graphics.Color; import android.os.Bundle; import android.view.Gravity; import android.view.LayoutInflater; @@ -32,7 +33,7 @@ public final View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewG return mDialogView; } ViewGroup containerView = (ViewGroup) inflater.inflate(R.layout.dialog_design_container, container, false); - containerView.addView(onCreateDialogContentView(inflater, containerView, savedInstanceState)); + onCreateDialogContentView(inflater, containerView, savedInstanceState); mDialogView = containerView; return mDialogView; } diff --git a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/BookmarkDialog.java b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/BookmarkDialog.java index 0255ea3..eddf15c 100644 --- a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/BookmarkDialog.java +++ b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/BookmarkDialog.java @@ -50,7 +50,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { @Override public View onCreateDialogContentView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return inflater.inflate(R.layout.dialog_bookmark, container, false); + return inflater.inflate(R.layout.dialog_bookmark, container, true); } @Override diff --git a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/ChangeSourceDialog.java b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/ChangeSourceDialog.java index e07607f..3c9fb1e 100644 --- a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/ChangeSourceDialog.java +++ b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/ChangeSourceDialog.java @@ -92,7 +92,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { @Override public View onCreateDialogContentView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return inflater.inflate(R.layout.dialog_change_source, container, false); + return inflater.inflate(R.layout.dialog_change_source, container, true); } @Override diff --git a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/DownLoadDialog.java b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/DownLoadDialog.java index 2a6d95d..70c3c7f 100644 --- a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/DownLoadDialog.java +++ b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/DownLoadDialog.java @@ -45,7 +45,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { @Override public View onCreateDialogContentView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return inflater.inflate(R.layout.dialog_download_choice, container, false); + return inflater.inflate(R.layout.dialog_download_choice, container, true); } @Override diff --git a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/InputDialog.java b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/InputDialog.java index 51ac6b9..38710a3 100644 --- a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/InputDialog.java +++ b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/InputDialog.java @@ -38,7 +38,7 @@ public static void show(FragmentManager fragmentManager, String title, String de @Override public View onCreateDialogContentView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return inflater.inflate(R.layout.dialog_input, container, false); + return inflater.inflate(R.layout.dialog_input, container, true); } @Override diff --git a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/LargeTextDialog.java b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/LargeTextDialog.java index 542c334..e5de833 100644 --- a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/LargeTextDialog.java +++ b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/LargeTextDialog.java @@ -13,6 +13,8 @@ import com.monke.monkeybook.R; import com.monke.monkeybook.utils.MarkdownUtils; +import io.reactivex.schedulers.Schedulers; + public class LargeTextDialog extends AppCompatDialog { public static void show(FragmentManager fragmentManager, String text, boolean markdown) { @@ -26,21 +28,26 @@ public static void show(FragmentManager fragmentManager, String text, boolean ma @Override public View onCreateDialogContentView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return inflater.inflate(R.layout.dialog_large_text, container, false); + return inflater.inflate(R.layout.dialog_large_text, container, true); } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - AppCompatTextView tvContent = findViewById(R.id.tv_text); + final AppCompatTextView tvContent = findViewById(R.id.tv_text); + Bundle args = getArguments(); assert args != null; final String text = args.getString("text"); final boolean markdown = args.getBoolean("markdown"); - if (markdown) { - MarkdownUtils.setText(tvContent, text); - } else { - tvContent.setText(text); - } + Schedulers.single().scheduleDirect(() -> { + final CharSequence string; + if (markdown) { + string = MarkdownUtils.simpleMarkdownConverter(text); + } else { + string = text; + } + view.post(() -> tvContent.setText(string)); + }); } } diff --git a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/ProgressDialog.java b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/ProgressDialog.java index b001a51..2e596a6 100644 --- a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/ProgressDialog.java +++ b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/ProgressDialog.java @@ -65,7 +65,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { @Nullable @Override public View onCreateDialogContentView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return inflater.inflate(R.layout.dialog_loading, container, false); + return inflater.inflate(R.layout.dialog_loading, container, true); } @Override diff --git a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/ReplaceRuleDialog.java b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/ReplaceRuleDialog.java index d0a0ec8..412ccac 100644 --- a/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/ReplaceRuleDialog.java +++ b/app/src/main/java/com/monke/monkeybook/view/fragment/dialog/ReplaceRuleDialog.java @@ -42,7 +42,7 @@ public static void show(FragmentManager fragmentManager, ReplaceRuleBean replace @Override public View onCreateDialogContentView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return inflater.inflate(R.layout.dialog_replace_rule, container, false); + return inflater.inflate(R.layout.dialog_replace_rule, container, true); } @Override diff --git a/app/src/main/java/com/monke/monkeybook/view/popupwindow/CheckAddShelfPop.java b/app/src/main/java/com/monke/monkeybook/view/popupwindow/CheckAddShelfPop.java index 56839d4..a3df785 100644 --- a/app/src/main/java/com/monke/monkeybook/view/popupwindow/CheckAddShelfPop.java +++ b/app/src/main/java/com/monke/monkeybook/view/popupwindow/CheckAddShelfPop.java @@ -12,6 +12,7 @@ import androidx.annotation.NonNull; import com.monke.monkeybook.R; +import com.monke.monkeybook.widget.DialogContainerLayout; public class CheckAddShelfPop extends PopupWindow { private Context mContext; @@ -33,7 +34,7 @@ public CheckAddShelfPop(Context context, @NonNull String bookName, @NonNull OnIt this.isAudioBook = isAudioBook; this.bookName = bookName; this.itemClick = itemClick; - view = LayoutInflater.from(mContext).inflate(R.layout.dialog_alert, null); + view = LayoutInflater.from(mContext).inflate(R.layout.pop_check_add_shelf, null); this.setContentView(view); initView(); diff --git a/app/src/main/java/com/monke/monkeybook/widget/DialogContainerLayout.java b/app/src/main/java/com/monke/monkeybook/widget/DialogContainerLayout.java index 80d1646..76ec4c3 100644 --- a/app/src/main/java/com/monke/monkeybook/widget/DialogContainerLayout.java +++ b/app/src/main/java/com/monke/monkeybook/widget/DialogContainerLayout.java @@ -1,13 +1,20 @@ package com.monke.monkeybook.widget; +import android.content.ContentUris; import android.content.Context; +import android.graphics.Rect; import android.util.AttributeSet; +import android.util.Log; +import android.view.Display; +import android.view.View; +import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.cardview.widget.CardView; import com.monke.monkeybook.R; +import com.monke.monkeybook.utils.ContextUtils; import com.monke.monkeybook.utils.ScreenUtils; public class DialogContainerLayout extends CardView { @@ -16,7 +23,11 @@ public class DialogContainerLayout extends CardView { private int mMaxWidth; public DialogContainerLayout(@NonNull Context context, @Nullable AttributeSet attrs) { - super(context, attrs); + this(context, attrs, 0); + } + + public DialogContainerLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); int screenHeight = getResources().getDisplayMetrics().heightPixels; int screenWidth = getResources().getDisplayMetrics().widthPixels; int statusBarHeight = ScreenUtils.getStatusBarHeight(); @@ -25,13 +36,59 @@ public DialogContainerLayout(@NonNull Context context, @Nullable AttributeSet at mMaxWidth = screenWidth - offset; } - @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - int height = MeasureSpec.getSize(heightMeasureSpec); - heightMeasureSpec = MeasureSpec.makeMeasureSpec(Math.min(mMaxHeight, height), MeasureSpec.EXACTLY); int width = MeasureSpec.getSize(widthMeasureSpec); widthMeasureSpec = MeasureSpec.makeMeasureSpec(Math.min(width, mMaxWidth), MeasureSpec.EXACTLY); + + View child = getChildAt(0); + if(child != null && child.getLayoutParams().height != ViewGroup.LayoutParams.WRAP_CONTENT){ + final int height; + if(child.getLayoutParams().height > 0){ + height = child.getLayoutParams().height; + }else { + height = MeasureSpec.getSize(heightMeasureSpec); + } + heightMeasureSpec = MeasureSpec.makeMeasureSpec(Math.min(mMaxHeight, height), MeasureSpec.EXACTLY); + } + super.onMeasure(widthMeasureSpec, heightMeasureSpec); } + + @Override + public void addView(View child) { + if (getChildCount() > 2) { + throw new IllegalStateException("DialogContainerLayout can host only one direct child"); + } + + super.addView(child); + } + + @Override + public void addView(View child, int index) { + if (getChildCount() > 2) { + throw new IllegalStateException("DialogContainerLayout can host only one direct child"); + } + + super.addView(child, index); + } + + @Override + public void addView(View child, ViewGroup.LayoutParams params) { + if (getChildCount() > 2) { + throw new IllegalStateException("DialogContainerLayout can host only one direct child"); + } + + super.addView(child, params); + } + + @Override + public void addView(View child, int index, ViewGroup.LayoutParams params) { + if (getChildCount() > 2) { + throw new IllegalStateException("DialogContainerLayout can host only one direct child"); + } + + super.addView(child, index, params); + } + } diff --git a/app/src/main/java/com/monke/monkeybook/widget/page/NetPageLoader.java b/app/src/main/java/com/monke/monkeybook/widget/page/NetPageLoader.java index 4762c3d..05a2b2e 100644 --- a/app/src/main/java/com/monke/monkeybook/widget/page/NetPageLoader.java +++ b/app/src/main/java/com/monke/monkeybook/widget/page/NetPageLoader.java @@ -67,7 +67,6 @@ public void refreshChapterList() { bookShelfBean.setNewChapters(0); bookShelfBean.setFinalRefreshData(System.currentTimeMillis()); if (BookshelfHelp.isInBookShelf(bookShelfBean.getNoteUrl())) { - BookshelfHelp.delChapterList(bookShelfBean.getNoteUrl()); BookshelfHelp.saveBookToShelf(bookShelfBean); } }) diff --git a/app/src/main/res/layout/activity_read_style.xml b/app/src/main/res/layout/activity_read_style.xml index 0046267..30e0d61 100644 --- a/app/src/main/res/layout/activity_read_style.xml +++ b/app/src/main/res/layout/activity_read_style.xml @@ -31,7 +31,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" - android:background="@color/background" + android:background="@color/card_background" android:orientation="vertical" android:stateListAnimator="@animator/design_bottombar_state_list_animator"> diff --git a/app/src/main/res/layout/dialog_alert.xml b/app/src/main/res/layout/dialog_alert.xml index dbefba8..44b6f0e 100644 --- a/app/src/main/res/layout/dialog_alert.xml +++ b/app/src/main/res/layout/dialog_alert.xml @@ -1,121 +1,113 @@ - + android:gravity="center_horizontal" + android:orientation="vertical"> - - + + - - - - + android:ellipsize="end" + android:singleLine="true" + android:text="@string/dialog_title" + android:textAlignment="viewStart" /> - - - - - - + android:layout_height="@dimen/abc_dialog_title_divider_material" + android:visibility="visible" + tools:ignore="PrivateResource" /> + - - + - + android:layout_height="@dimen/abc_dialog_padding_top_material" + android:visibility="gone" + tools:ignore="PrivateResource" /> - - - + android:paddingLeft="?attr/dialogPreferredPadding" + android:paddingRight="?attr/dialogPreferredPadding" + android:text="@string/app_name" /> - + + - + - - - \ No newline at end of file + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_bookmark.xml b/app/src/main/res/layout/dialog_bookmark.xml index 20f7d89..492ec8e 100644 --- a/app/src/main/res/layout/dialog_bookmark.xml +++ b/app/src/main/res/layout/dialog_bookmark.xml @@ -1,5 +1,4 @@ - @@ -12,7 +13,6 @@ android:autoLink="all" android:lineSpacingMultiplier="1.2" android:linksClickable="true" - android:padding="10dp" android:textColor="@color/tv_text_default" /> diff --git a/app/src/main/res/layout/item_bookshelf_grid.xml b/app/src/main/res/layout/item_bookshelf_grid.xml index c288a6b..ef1580b 100644 --- a/app/src/main/res/layout/item_bookshelf_grid.xml +++ b/app/src/main/res/layout/item_bookshelf_grid.xml @@ -42,22 +42,14 @@ app:labelSinkWidth="4dp" tools:ignore="SmallSp" /> - - - - - + @@ -132,23 +132,13 @@ android:layout_weight="1" /> - - - - - + app:loadingWidth="2dp" /> diff --git a/app/src/main/res/layout/pop_check_add_shelf.xml b/app/src/main/res/layout/pop_check_add_shelf.xml new file mode 100644 index 0000000..142dca6 --- /dev/null +++ b/app/src/main/res/layout/pop_check_add_shelf.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/pref_key_value.xml b/app/src/main/res/values/pref_key_value.xml index 0769731..0f77f1f 100644 --- a/app/src/main/res/values/pref_key_value.xml +++ b/app/src/main/res/values/pref_key_value.xml @@ -21,7 +21,7 @@ http://read.hostfans.cn/bookSource.txt http://read.hostfans.cn/replaceRule.txt https://gedoor.github.io/MyBookshelf/sourcerule.html - https://github.com/gedoor/MyBookshelf + https://github.com/Invinciblelee/MyBookshelf-master https://gedoor.github.io/MyBookshelf/disclaimer.html https://gedoor.github.io/MyBookshelf/ https://github.com/Invinciblelee/MyBookshelf-master/releases diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 94c7c7e..23fa418 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -196,8 +196,8 @@ diff --git a/app/version.properties b/app/version.properties index af19f59..7375313 100644 --- a/app/version.properties +++ b/app/version.properties @@ -1,2 +1,2 @@ -#Fri May 10 00:18:14 CST 2019 -VERSION_CODE=2833 +#Fri May 10 18:35:53 CST 2019 +VERSION_CODE=2841 diff --git a/basemvplib/src/main/java/com/monke/basemvplib/AjaxWebView.java b/basemvplib/src/main/java/com/monke/basemvplib/AjaxWebView.java index 08aebdf..4151b46 100644 --- a/basemvplib/src/main/java/com/monke/basemvplib/AjaxWebView.java +++ b/basemvplib/src/main/java/com/monke/basemvplib/AjaxWebView.java @@ -27,7 +27,10 @@ public class AjaxWebView { - public AjaxWebView() { + private final AjaxHandler mHandler; + + public AjaxWebView(Callback callback) { + mHandler = new AjaxHandler(callback); } private static class AjaxHandler extends Handler { @@ -78,13 +81,13 @@ private void destroyWebView() { } @SuppressLint("SetJavaScriptEnabled") - public void ajax(AjaxParams params, Callback callback) { - new AjaxHandler(callback).obtainMessage(AjaxHandler.MSG_AJAX_START, params) + public void ajax(AjaxParams params) { + mHandler.obtainMessage(AjaxHandler.MSG_AJAX_START, params) .sendToTarget(); } - public void sniff(AjaxParams params, Callback callback) { - new AjaxHandler(callback).obtainMessage(AjaxHandler.MSG_SNIFF_START, params) + public void sniff(AjaxParams params) { + mHandler.obtainMessage(AjaxHandler.MSG_SNIFF_START, params) .sendToTarget(); } diff --git a/basemvplib/src/main/java/com/monke/basemvplib/BaseModelImpl.java b/basemvplib/src/main/java/com/monke/basemvplib/BaseModelImpl.java index cb8794d..a551017 100644 --- a/basemvplib/src/main/java/com/monke/basemvplib/BaseModelImpl.java +++ b/basemvplib/src/main/java/com/monke/basemvplib/BaseModelImpl.java @@ -16,11 +16,11 @@ protected T createService(String url, String encode, Class tClass) { protected Observable ajax(AjaxWebView.AjaxParams params) { - return Observable.create(emitter -> new AjaxWebView().ajax(params, new AjaxCallback(emitter))); + return Observable.create(emitter -> new AjaxWebView(new AjaxCallback(emitter)).ajax(params)); } protected Observable sniff(AjaxWebView.AjaxParams params) { - return Observable.create(emitter -> new AjaxWebView().sniff(params, new AjaxCallback(emitter))); + return Observable.create(emitter -> new AjaxWebView(new AjaxCallback(emitter)).sniff(params)); }