From 44e6210c38f6311a71e04283a93fdd5f32c9a32e Mon Sep 17 00:00:00 2001 From: zlj <390057892@qq.com> Date: Fri, 15 Nov 2019 17:03:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E9=83=A8=E5=88=86java?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/litepal.xml | 2 +- .../activity/NovelBookTypeListActivity.kt | 2 +- .../com/novel/read/fragment/BookFragment.kt | 6 +- .../com/novel/read/fragment/MoreFragment.kt | 1 - .../com/novel/read/http/AccountManager.kt | 1 - .../novel/read/model/db/BookRecordBean.java | 43 ---- .../com/novel/read/model/db/BookRecordBean.kt | 17 ++ .../com/novel/read/model/db/CollBookBean.java | 4 +- .../novel/read/model/db/DownloadTaskBean.java | 2 +- .../novel/read/model/db/SearchListTable.java | 42 ---- .../novel/read/model/db/SearchListTable.kt | 29 +++ .../read/model/db/dbManage/BookManager.java | 10 +- .../read/model/protocol/BookArticleResp.java | 2 +- .../read/model/protocol/BookDetailResp.java | 6 +- .../read/model/protocol/ChapterInfoPackage.kt | 2 +- .../novel/read/service/DownloadMessage.java | 5 - .../novel/read/service/DownloadService.java | 4 - .../com/novel/read/utlis/PermissionUtil.java | 234 ++++++++---------- .../com/novel/read/widget/RefreshLayout.java | 59 ++--- .../novel/read/widget/page/PageLoader.java | 2 +- .../com/novel/read/widget/page/PageView.java | 2 - .../com/novel/read/widget/page/TxtPage.java | 4 +- .../widget/page/anim/SimulationPageAnim.kt | 16 +- .../read/widget/page/anim/SlidePageAnim.kt | 8 +- 24 files changed, 203 insertions(+), 300 deletions(-) delete mode 100644 app/src/main/java/com/novel/read/model/db/BookRecordBean.java create mode 100644 app/src/main/java/com/novel/read/model/db/BookRecordBean.kt delete mode 100644 app/src/main/java/com/novel/read/model/db/SearchListTable.java create mode 100644 app/src/main/java/com/novel/read/model/db/SearchListTable.kt diff --git a/app/src/main/assets/litepal.xml b/app/src/main/assets/litepal.xml index e2e2dc6..486ab39 100644 --- a/app/src/main/assets/litepal.xml +++ b/app/src/main/assets/litepal.xml @@ -2,7 +2,7 @@ - + diff --git a/app/src/main/java/com/novel/read/activity/NovelBookTypeListActivity.kt b/app/src/main/java/com/novel/read/activity/NovelBookTypeListActivity.kt index 8c8b471..1ce4a2a 100644 --- a/app/src/main/java/com/novel/read/activity/NovelBookTypeListActivity.kt +++ b/app/src/main/java/com/novel/read/activity/NovelBookTypeListActivity.kt @@ -58,7 +58,7 @@ class NovelBookTypeListActivity : NovelBaseActivity() { refresh.setOnReloadingListener { this.getData() } getData() toolbar.title = mTitle - toolbar.setNavigationOnClickListener { view -> finish() } + toolbar.setNavigationOnClickListener { finish() } } diff --git a/app/src/main/java/com/novel/read/fragment/BookFragment.kt b/app/src/main/java/com/novel/read/fragment/BookFragment.kt index bf8522d..0202933 100644 --- a/app/src/main/java/com/novel/read/fragment/BookFragment.kt +++ b/app/src/main/java/com/novel/read/fragment/BookFragment.kt @@ -121,12 +121,12 @@ class BookFragment : NovelBaseFragment() { } true } - tv_cancel.setOnClickListener { view -> + tv_cancel.setOnClickListener { EventManager.instance.postEvent(HideBottomBarEvent(false)) updateBook(UpdateBookEvent()) } - tv_delete.setOnClickListener { view -> + tv_delete.setOnClickListener { val deleteList = mAdapter.selectList for (i in deleteList.indices) { if (deleteList[i].isSaved) { @@ -140,7 +140,7 @@ class BookFragment : NovelBaseFragment() { updateBook(UpdateBookEvent()) } - mAdapter.setOnItemClickListener { view, pos -> + mAdapter.setOnItemClickListener { _, _ -> EventManager.instance.postEvent( SwitchFragmentEvent() ) diff --git a/app/src/main/java/com/novel/read/fragment/MoreFragment.kt b/app/src/main/java/com/novel/read/fragment/MoreFragment.kt index d801135..1b55bb8 100644 --- a/app/src/main/java/com/novel/read/fragment/MoreFragment.kt +++ b/app/src/main/java/com/novel/read/fragment/MoreFragment.kt @@ -101,7 +101,6 @@ class MoreFragment : NovelBaseFragment() { fragment.arguments = args return fragment } - } override fun onDestroy() { diff --git a/app/src/main/java/com/novel/read/http/AccountManager.kt b/app/src/main/java/com/novel/read/http/AccountManager.kt index ecc3db1..f002b3e 100644 --- a/app/src/main/java/com/novel/read/http/AccountManager.kt +++ b/app/src/main/java/com/novel/read/http/AccountManager.kt @@ -42,7 +42,6 @@ import io.reactivex.schedulers.Schedulers import okhttp3.MediaType import okhttp3.RequestBody import retrofit2.Callback -import java.util.Map /** * Created by zlj on 2017/2/14. diff --git a/app/src/main/java/com/novel/read/model/db/BookRecordBean.java b/app/src/main/java/com/novel/read/model/db/BookRecordBean.java deleted file mode 100644 index c3e764b..0000000 --- a/app/src/main/java/com/novel/read/model/db/BookRecordBean.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.novel.read.model.db; - -import org.litepal.crud.LitePalSupport; - -import java.io.Serializable; - -/** - * Created by newbiechen on 17-5-20. - */ -public class BookRecordBean extends LitePalSupport implements Serializable { - //所属的书的id - private String bookId; - //阅读到了第几章 - private int chapter; - //当前的页码 - private int pagePos; - - - - public String getBookId() { - return bookId; - } - - public void setBookId(String bookId) { - this.bookId = bookId; - } - - public int getChapter() { - return chapter; - } - - public void setChapter(int chapter) { - this.chapter = chapter; - } - - public int getPagePos() { - return pagePos; - } - - public void setPagePos(int pagePos) { - this.pagePos = pagePos; - } -} diff --git a/app/src/main/java/com/novel/read/model/db/BookRecordBean.kt b/app/src/main/java/com/novel/read/model/db/BookRecordBean.kt new file mode 100644 index 0000000..09ff07b --- /dev/null +++ b/app/src/main/java/com/novel/read/model/db/BookRecordBean.kt @@ -0,0 +1,17 @@ +package com.novel.read.model.db + +import org.litepal.crud.LitePalSupport + +import java.io.Serializable + +/** + * Created by zlj + */ +class BookRecordBean : LitePalSupport(), Serializable { + //所属的书的id + var bookId: String = "" + //阅读到了第几章 + var chapter: Int = 0 + //当前的页码 + var pagePos: Int = 0 +} diff --git a/app/src/main/java/com/novel/read/model/db/CollBookBean.java b/app/src/main/java/com/novel/read/model/db/CollBookBean.java index ac844e3..f53a0fb 100644 --- a/app/src/main/java/com/novel/read/model/db/CollBookBean.java +++ b/app/src/main/java/com/novel/read/model/db/CollBookBean.java @@ -14,9 +14,7 @@ import java.util.List; */ public class CollBookBean extends LitePalSupport implements Serializable { - public static final int STATUS_UNCACHE = 0; //未缓存 - public static final int STATUS_CACHING = 1; //正在缓存 - public static final int STATUS_CACHED = 2; //已经缓存 + /** * _id : 53663ae356bdc93e49004474 * title : 逍遥派 diff --git a/app/src/main/java/com/novel/read/model/db/DownloadTaskBean.java b/app/src/main/java/com/novel/read/model/db/DownloadTaskBean.java index 516223b..dc64f21 100644 --- a/app/src/main/java/com/novel/read/model/db/DownloadTaskBean.java +++ b/app/src/main/java/com/novel/read/model/db/DownloadTaskBean.java @@ -7,7 +7,7 @@ import java.util.ArrayList; import java.util.List; /** - * Created by newbiechen on 17-5-11. + * Created by zlj */ public class DownloadTaskBean extends LitePalSupport { public static final int STATUS_LOADING = 1; diff --git a/app/src/main/java/com/novel/read/model/db/SearchListTable.java b/app/src/main/java/com/novel/read/model/db/SearchListTable.java deleted file mode 100644 index 1dd57d0..0000000 --- a/app/src/main/java/com/novel/read/model/db/SearchListTable.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.novel.read.model.db; - - -import androidx.annotation.Nullable; - -import org.litepal.crud.LitePalSupport; - -import java.io.Serializable; - -/** - * create by zlj on 2019/6/19 - * describe: - */ -public class SearchListTable extends LitePalSupport implements Serializable { - - private String key; - private long saveTime; - - public String getKey() { - return key == null ? "" : key; - } - - public void setKey(String key) { - this.key = key; - } - - public long getSaveTime() { - return saveTime; - } - - public void setSaveTime(long saveTime) { - this.saveTime = saveTime; - } - - @Override - public boolean equals(@Nullable Object obj) { - if (obj != null && obj.toString().equals(key)) { - return true; - } - return super.equals(obj); - } -} diff --git a/app/src/main/java/com/novel/read/model/db/SearchListTable.kt b/app/src/main/java/com/novel/read/model/db/SearchListTable.kt new file mode 100644 index 0000000..6d6053a --- /dev/null +++ b/app/src/main/java/com/novel/read/model/db/SearchListTable.kt @@ -0,0 +1,29 @@ +package com.novel.read.model.db + + +import org.litepal.crud.LitePalSupport + +import java.io.Serializable + +/** + * create by zlj on 2019/6/19 + * describe: + */ +class SearchListTable : LitePalSupport(), Serializable { + + var key: String = "" + var saveTime: Long = 0 + + + override fun equals(other: Any?): Boolean { + return if (other != null && other.toString() == key) { + true + } else super.equals(other) + } + + override fun hashCode(): Int { + var result = key.hashCode() + result = 31 * result + saveTime.hashCode() + return result + } +} diff --git a/app/src/main/java/com/novel/read/model/db/dbManage/BookManager.java b/app/src/main/java/com/novel/read/model/db/dbManage/BookManager.java index 85d2ccc..b28cfa2 100644 --- a/app/src/main/java/com/novel/read/model/db/dbManage/BookManager.java +++ b/app/src/main/java/com/novel/read/model/db/dbManage/BookManager.java @@ -53,7 +53,7 @@ public class BookManager { File file = getBookFile(bookId, chapterName); //TODO:数据加载默认utf-8(以后会增加判断),FileUtils采用Reader获取数据的,可能用byte会更好一点 char[] array = FileUtils.getFileContent(file).toCharArray(); - WeakReference charReference = new WeakReference(array); + WeakReference charReference = new WeakReference<>(array); cache.size = array.length; cache.data = charReference; cacheMap.put(chapterName, cache); @@ -167,9 +167,9 @@ public class BookManager { /** * 创建或获取存储文件 - * @param folderName - * @param fileName - * @return + * @param folderName 文件夹 + * @param fileName 文件 + * @return 文件 */ public static File getBookFile(String folderName, String fileName){ return FileUtils.getFile(Constant.BOOK_CACHE_PATH + folderName @@ -186,7 +186,7 @@ public class BookManager { * 过) * @param folderName : bookId * @param fileName: chapterName - * @return + * @return 是否被缓存过 */ public static boolean isChapterCached(String folderName, String fileName){ File file = new File(Constant.BOOK_CACHE_PATH + folderName diff --git a/app/src/main/java/com/novel/read/model/protocol/BookArticleResp.java b/app/src/main/java/com/novel/read/model/protocol/BookArticleResp.java index 3a18393..a5b0807 100644 --- a/app/src/main/java/com/novel/read/model/protocol/BookArticleResp.java +++ b/app/src/main/java/com/novel/read/model/protocol/BookArticleResp.java @@ -82,7 +82,7 @@ public class BookArticleResp implements Serializable { return bookChapterBean; } - public List createChapterBean() { + private List createChapterBean() { List mList = new ArrayList<>(); for (ArticleBean articleBean:getArticle()){ mList.add(new BookChapterBean(String.valueOf(articleBean.getId()),articleBean.getTitle())); diff --git a/app/src/main/java/com/novel/read/model/protocol/BookDetailResp.java b/app/src/main/java/com/novel/read/model/protocol/BookDetailResp.java index eaa94ff..981d7ca 100644 --- a/app/src/main/java/com/novel/read/model/protocol/BookDetailResp.java +++ b/app/src/main/java/com/novel/read/model/protocol/BookDetailResp.java @@ -182,7 +182,7 @@ public class BookDetailResp { return collBookBean; } - public CollBookBean createCollBookBean(){ + private CollBookBean createCollBookBean(){ CollBookBean bean = new CollBookBean(); bean.setId(String.valueOf(getBook().getId())); bean.setTitle(getBook().getTitle()); @@ -190,14 +190,10 @@ public class BookDetailResp { bean.setShortIntro(getBook().getDescription()); bean.setCover(getBook().getCover()); bean.setInclude_image(getBook().getInclude_image()); -// bean.setHasCp(getBook().isHasCp()); -// bean.setLatelyFollower(getBook().getLatelyFollower()); -// bean.setRetentionRatio(Double.parseDouble(getBook().getRetentionRatio())); if (getLast_article()!=null){ bean.setUpdated(String.valueOf(getLast_article().getCreate_time())); bean.setLastChapter(getLast_article().getTitle()); } -// bean.setChaptersCount(getBook().getChaptersCount()); return bean; } } diff --git a/app/src/main/java/com/novel/read/model/protocol/ChapterInfoPackage.kt b/app/src/main/java/com/novel/read/model/protocol/ChapterInfoPackage.kt index 081e1df..c8177f3 100644 --- a/app/src/main/java/com/novel/read/model/protocol/ChapterInfoPackage.kt +++ b/app/src/main/java/com/novel/read/model/protocol/ChapterInfoPackage.kt @@ -6,7 +6,7 @@ import java.io.Serializable class ChapterInfoPackage : Serializable { - var article: List? = null + var article: List = ArrayList() } diff --git a/app/src/main/java/com/novel/read/service/DownloadMessage.java b/app/src/main/java/com/novel/read/service/DownloadMessage.java index e141cb6..6b35680 100644 --- a/app/src/main/java/com/novel/read/service/DownloadMessage.java +++ b/app/src/main/java/com/novel/read/service/DownloadMessage.java @@ -2,11 +2,6 @@ package com.novel.read.service; import com.mango.mangolib.event.BaseEvent; -/** - * Created by newbiechen on 17-5-10. - * 下载进度事件 - */ - public class DownloadMessage extends BaseEvent { public String message; diff --git a/app/src/main/java/com/novel/read/service/DownloadService.java b/app/src/main/java/com/novel/read/service/DownloadService.java index 752ca88..ba880f4 100644 --- a/app/src/main/java/com/novel/read/service/DownloadService.java +++ b/app/src/main/java/com/novel/read/service/DownloadService.java @@ -34,10 +34,6 @@ import java.util.concurrent.Executors; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; -/** - * Created by newbiechen on 17-5-10. - */ - public class DownloadService extends BaseService { private static final String TAG = "DownloadService"; //加载状态 diff --git a/app/src/main/java/com/novel/read/utlis/PermissionUtil.java b/app/src/main/java/com/novel/read/utlis/PermissionUtil.java index b9a5f01..bceed44 100644 --- a/app/src/main/java/com/novel/read/utlis/PermissionUtil.java +++ b/app/src/main/java/com/novel/read/utlis/PermissionUtil.java @@ -11,150 +11,118 @@ import com.novel.read.R; import java.util.ArrayList; import java.util.List; -/** - * Created by loki - * Date 2018/9/3. - */ - public class PermissionUtil { - private static PermissionUtil permissionUtil = null; - private static List mListPermissions; - - - private static String[] PERMISSIONS_LIST = { - Manifest.permission.INTERNET, - Manifest.permission.ACCESS_NETWORK_STATE, - Manifest.permission.ACCESS_WIFI_STATE, - Manifest.permission.ACCESS_NETWORK_STATE, -// Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS, // not work -// Manifest.permission.WRITE_SETTINGS, // not grant -// Manifest.permission.GET_TASKS // dep - }; - - private static final String PERMISSIONS_STORAGE = Manifest.permission.WRITE_EXTERNAL_STORAGE; - private static final String PERMISSIONS_PHONE = Manifest.permission.READ_PHONE_STATE; - private static final String PERMISSIONS_SETTINGS = Manifest.permission.WRITE_SETTINGS; - - /** - * 添加权限 - * author LH - * data 2016/7/27 11:27 - */ - private void addAllPermissions(List mListPermissions) { - mListPermissions.add(PERMISSIONS_STORAGE); -// mListPermissions.add(PERMISSIONS_PHONE); - } - - /** - * 单例模式初始化 - * author LH - * data 2016/7/27 11:27 - */ - public static PermissionUtil getInstance() { - if (permissionUtil == null) { - permissionUtil = new PermissionUtil(); - } - return permissionUtil; - } - - /** - * 判断当前为M以上版本 - * author LH - * data 2016/7/27 11:29 - */ - public boolean isOverMarshmallow() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; - } - - /** - * 获得没有授权的权限 - * author LH - * data 2016/7/27 11:46 - */ - @TargetApi(value = Build.VERSION_CODES.M) - public List findDeniedPermissions(Activity activity, List permissions) { - List denyPermissions = new ArrayList<>(); - for (String value : permissions) { - if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED) { - denyPermissions.add(value); - } + private static PermissionUtil permissionUtil = null; + private static List mListPermissions; + + + private static String[] PERMISSIONS_LIST = { + Manifest.permission.INTERNET, + Manifest.permission.ACCESS_NETWORK_STATE, + Manifest.permission.ACCESS_WIFI_STATE, + Manifest.permission.ACCESS_NETWORK_STATE, + }; + + private static final String PERMISSIONS_STORAGE = Manifest.permission.WRITE_EXTERNAL_STORAGE; + private static final String PERMISSIONS_PHONE = Manifest.permission.READ_PHONE_STATE; + private static final String PERMISSIONS_SETTINGS = Manifest.permission.WRITE_SETTINGS; + + + private void addAllPermissions(List mListPermissions) { + mListPermissions.add(PERMISSIONS_STORAGE); } - return denyPermissions; - } - - /** - * 获取所有权限 - * author LH - * data 2016/7/27 13:37 - */ - @TargetApi(value = Build.VERSION_CODES.M) - public void requestPermissions(Activity activity, int requestCode, PermissionCallBack permissionCallBack) { - if (mListPermissions == null) { - mListPermissions = new ArrayList<>(); - addAllPermissions(mListPermissions); + + + public static PermissionUtil getInstance() { + if (permissionUtil == null) { + permissionUtil = new PermissionUtil(); + } + return permissionUtil; } - if (!isOverMarshmallow()) { - permissionCallBack.onPermissionSuccess(); - return; + + public boolean isOverMarshmallow() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; } - mListPermissions = findDeniedPermissions(activity, mListPermissions); - if (mListPermissions != null && mListPermissions.size() > 0) { - activity.requestPermissions(mListPermissions.toArray(new String[mListPermissions.size()]), - requestCode); - } else { - permissionCallBack.onPermissionSuccess(); + + @TargetApi(value = Build.VERSION_CODES.M) + public List findDeniedPermissions(Activity activity, List permissions) { + List denyPermissions = new ArrayList<>(); + for (String value : permissions) { + if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED) { + denyPermissions.add(value); + } + } + return denyPermissions; } - } - - public void requestResult(Activity activity, String[] permissions, int[] grantResults, PermissionCallBack permissionCallBack) { - mListPermissions = new ArrayList<>(); - ArrayList noPermissions = new ArrayList<>(); - ArrayList rejectPermissons = new ArrayList<>(); - for (int i = 0; i < grantResults.length; i++) { - if (grantResults[i] != PackageManager.PERMISSION_GRANTED) { - if (isOverMarshmallow()) { - boolean isShould = activity.shouldShowRequestPermissionRationale(permissions[i]); - mListPermissions.add(permissions[i]); - if (isShould) { - noPermissions.add(permissions[i]); - } else { - rejectPermissons.add(permissions[i]); - } + + @TargetApi(value = Build.VERSION_CODES.M) + public void requestPermissions(Activity activity, int requestCode, PermissionCallBack permissionCallBack) { + if (mListPermissions == null) { + mListPermissions = new ArrayList<>(); + addAllPermissions(mListPermissions); + } + if (!isOverMarshmallow()) { + permissionCallBack.onPermissionSuccess(); + return; + } + mListPermissions = findDeniedPermissions(activity, mListPermissions); + if (mListPermissions != null && mListPermissions.size() > 0) { + activity.requestPermissions(mListPermissions.toArray(new String[mListPermissions.size()]), + requestCode); + } else { + permissionCallBack.onPermissionSuccess(); } - } } - if (noPermissions.size() > 0) { - permissionCallBack.onPermissionFail(); - } else if (rejectPermissons.size() > 0) { - ArrayList permissonsList = new ArrayList<>(); - for (int i = 0; i < rejectPermissons.size(); i++) { - String strPermissons = rejectPermissons.get(i); - if (PERMISSIONS_STORAGE.equals(strPermissons)) { - permissonsList.add("storage"); - } else if (PERMISSIONS_PHONE.equals(strPermissons)) { - permissonsList.add("phone"); + public void requestResult(Activity activity, String[] permissions, int[] grantResults, PermissionCallBack permissionCallBack) { + mListPermissions = new ArrayList<>(); + ArrayList noPermissions = new ArrayList<>(); + ArrayList rejectPermissons = new ArrayList<>(); + for (int i = 0; i < grantResults.length; i++) { + if (grantResults[i] != PackageManager.PERMISSION_GRANTED) { + if (isOverMarshmallow()) { + boolean isShould = activity.shouldShowRequestPermissionRationale(permissions[i]); + mListPermissions.add(permissions[i]); + if (isShould) { + noPermissions.add(permissions[i]); + } else { + rejectPermissons.add(permissions[i]); + } + } + } + } + + if (noPermissions.size() > 0) { + permissionCallBack.onPermissionFail(); + } else if (rejectPermissons.size() > 0) { + ArrayList permissonsList = new ArrayList<>(); + for (int i = 0; i < rejectPermissons.size(); i++) { + String strPermissons = rejectPermissons.get(i); + if (PERMISSIONS_STORAGE.equals(strPermissons)) { + permissonsList.add("storage"); + } else if (PERMISSIONS_PHONE.equals(strPermissons)) { + permissonsList.add("phone"); + } + } + String strPermissons = permissonsList.toString(); + strPermissons = strPermissons.replace("[", ""); + strPermissons = strPermissons.replace("]", ""); + strPermissons = strPermissons.replace(",", "、"); + String strAppName = activity.getString(R.string.app_name); + String strMessage = "permission"; + strMessage = String.format(strMessage, strAppName, strPermissons, "\""); + permissionCallBack.onPermissionReject(strMessage); + + } else { + permissionCallBack.onPermissionSuccess(); } - } - String strPermissons = permissonsList.toString(); - strPermissons = strPermissons.replace("[", ""); - strPermissons = strPermissons.replace("]", ""); - strPermissons = strPermissons.replace(",", "、"); - String strAppName = activity.getString(R.string.app_name); - String strMessage = "permission"; - strMessage = String.format(strMessage, strAppName, strPermissons, "\""); - permissionCallBack.onPermissionReject(strMessage); - - } else { - permissionCallBack.onPermissionSuccess(); } - } - public interface PermissionCallBack { - void onPermissionSuccess(); + public interface PermissionCallBack { + void onPermissionSuccess(); - void onPermissionReject(String strMessage); + void onPermissionReject(String strMessage); - void onPermissionFail(); - } + void onPermissionFail(); + } } diff --git a/app/src/main/java/com/novel/read/widget/RefreshLayout.java b/app/src/main/java/com/novel/read/widget/RefreshLayout.java index a6f205d..d5511d5 100644 --- a/app/src/main/java/com/novel/read/widget/RefreshLayout.java +++ b/app/src/main/java/com/novel/read/widget/RefreshLayout.java @@ -36,11 +36,11 @@ public class RefreshLayout extends FrameLayout { private int mStatus = 0; public RefreshLayout(Context context) { - this(context,null); + this(context, null); } public RefreshLayout(Context context, AttributeSet attrs) { - this(context, attrs,0); + this(context, attrs, 0); } public RefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) { @@ -50,16 +50,16 @@ public class RefreshLayout extends FrameLayout { initView(); } - private void initAttrs(AttributeSet attrs){ + private void initAttrs(AttributeSet attrs) { TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.RefreshLayout); - mEmptyViewId = typedArray.getResourceId(R.styleable.RefreshLayout_layout_refresh_empty,R.layout.view_empty); - mErrorViewId = typedArray.getResourceId(R.styleable.RefreshLayout_layout_refresh_error,R.layout.view_net_error); - mLoadingViewId = typedArray.getResourceId(R.styleable.RefreshLayout_layout_refresh_loading,R.layout.view_loading); + mEmptyViewId = typedArray.getResourceId(R.styleable.RefreshLayout_layout_refresh_empty, R.layout.view_empty); + mErrorViewId = typedArray.getResourceId(R.styleable.RefreshLayout_layout_refresh_error, R.layout.view_net_error); + mLoadingViewId = typedArray.getResourceId(R.styleable.RefreshLayout_layout_refresh_loading, R.layout.view_loading); typedArray.recycle(); } - private void initView(){ + private void initView() { //添加在empty、error、loading 情况下的布局 mEmptyView = inflateView(mEmptyViewId); @@ -73,7 +73,7 @@ public class RefreshLayout extends FrameLayout { //设置监听器 mErrorView.setOnClickListener( (view) -> { - if (mListener != null){ + if (mListener != null) { toggleStatus(STATUS_LOADING); mListener.onReload(); } @@ -90,7 +90,7 @@ public class RefreshLayout extends FrameLayout { @Override public void onViewAdded(View child) { super.onViewAdded(child); - if (getChildCount() == 4){ + if (getChildCount() == 4) { mContentView = child; } } @@ -131,43 +131,43 @@ public class RefreshLayout extends FrameLayout { super.addView(child, index, params); } - public void showLoading(){ - if (mStatus != STATUS_LOADING){ + public void showLoading() { + if (mStatus != STATUS_LOADING) { toggleStatus(STATUS_LOADING); } } - public void showFinish(){ - if (mStatus == STATUS_LOADING){ + public void showFinish() { + if (mStatus == STATUS_LOADING) { toggleStatus(STATUS_FINISH); } } - public void showError(){ - if (mStatus != STATUS_ERROR){ + public void showError() { + if (mStatus != STATUS_ERROR) { toggleStatus(STATUS_ERROR); } } - public void showEmpty(){ - if (mStatus != STATUS_EMPTY){ + public void showEmpty() { + if (mStatus != STATUS_EMPTY) { toggleStatus(STATUS_EMPTY); } } //视图根据状态切换 - private void toggleStatus(int status){ - switch (status){ + private void toggleStatus(int status) { + switch (status) { case STATUS_LOADING: mLoadingView.setVisibility(VISIBLE); mEmptyView.setVisibility(GONE); mErrorView.setVisibility(GONE); - if (mContentView != null){ + if (mContentView != null) { mContentView.setVisibility(GONE); } break; case STATUS_FINISH: - if (mContentView != null){ + if (mContentView != null) { mContentView.setVisibility(VISIBLE); } mLoadingView.setVisibility(GONE); @@ -178,7 +178,7 @@ public class RefreshLayout extends FrameLayout { mErrorView.setVisibility(VISIBLE); mLoadingView.setVisibility(GONE); mEmptyView.setVisibility(GONE); - if (mContentView != null){ + if (mContentView != null) { mContentView.setVisibility(GONE); } break; @@ -186,7 +186,7 @@ public class RefreshLayout extends FrameLayout { mEmptyView.setVisibility(VISIBLE); mErrorView.setVisibility(GONE); mLoadingView.setVisibility(GONE); - if (mContentView != null){ + if (mContentView != null) { mContentView.setVisibility(GONE); } break; @@ -194,17 +194,12 @@ public class RefreshLayout extends FrameLayout { mStatus = status; } - protected int getStatus(){ - return mStatus; - } - - public void setOnReloadingListener(OnReloadingListener listener){ + public void setOnReloadingListener(OnReloadingListener listener) { mListener = listener; } - private View inflateView(int id){ - return LayoutInflater.from(mContext) - .inflate(id,this,false); + private View inflateView(int id) { + return LayoutInflater.from(mContext).inflate(id, this, false); } //数据存储 @@ -255,7 +250,7 @@ public class RefreshLayout extends FrameLayout { } //添加错误重新加载的监听 - public interface OnReloadingListener{ + public interface OnReloadingListener { void onReload(); } } diff --git a/app/src/main/java/com/novel/read/widget/page/PageLoader.java b/app/src/main/java/com/novel/read/widget/page/PageLoader.java index 823ab05..1785a49 100644 --- a/app/src/main/java/com/novel/read/widget/page/PageLoader.java +++ b/app/src/main/java/com/novel/read/widget/page/PageLoader.java @@ -874,7 +874,7 @@ public abstract class PageLoader { int para = mTextPara + (int) mTextPaint.getTextSize(); int titleInterval = mTitleInterval + (int) mTitlePaint.getTextSize(); int titlePara = mTitlePara + (int) mTextPaint.getTextSize(); - String str = null; + String str; //对标题进行绘制 for (int i = 0; i < mCurPage.titleLines; ++i) { diff --git a/app/src/main/java/com/novel/read/widget/page/PageView.java b/app/src/main/java/com/novel/read/widget/page/PageView.java index 44ec573..c62e47d 100644 --- a/app/src/main/java/com/novel/read/widget/page/PageView.java +++ b/app/src/main/java/com/novel/read/widget/page/PageView.java @@ -24,8 +24,6 @@ import com.novel.read.widget.page.anim.SlidePageAnim; */ public class PageView extends View { - private final static String TAG = "BookPageWidget"; - private int mViewWidth = 0; // 当前View的宽 private int mViewHeight = 0; // 当前View的高 diff --git a/app/src/main/java/com/novel/read/widget/page/TxtPage.java b/app/src/main/java/com/novel/read/widget/page/TxtPage.java index 1d74090..e1b93b2 100644 --- a/app/src/main/java/com/novel/read/widget/page/TxtPage.java +++ b/app/src/main/java/com/novel/read/widget/page/TxtPage.java @@ -18,9 +18,7 @@ public class TxtPage { return title == null ? "" : title; } - public int getTitleLines() { - return titleLines; - } + public List getLines() { if (lines == null) { diff --git a/app/src/main/java/com/novel/read/widget/page/anim/SimulationPageAnim.kt b/app/src/main/java/com/novel/read/widget/page/anim/SimulationPageAnim.kt index f64586e..68ba596 100644 --- a/app/src/main/java/com/novel/read/widget/page/anim/SimulationPageAnim.kt +++ b/app/src/main/java/com/novel/read/widget/page/anim/SimulationPageAnim.kt @@ -74,7 +74,7 @@ class SimulationPageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListe override fun drawMove(canvas: Canvas) { when (mDirection) { - PageAnimation.Direction.NEXT -> { + Direction.NEXT -> { calcPoints() drawCurrentPageArea(canvas, mCurBitmap, mPath0) drawNextPageAreaAndShadow(canvas, mNextBitmap) @@ -108,13 +108,13 @@ class SimulationPageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListe // dy 垂直方向滑动的距离,负值会使滚动向上滚动 if (isCancel) { - if (mCornerX > 0 && mDirection == PageAnimation.Direction.NEXT) { + if (mCornerX > 0 && mDirection == Direction.NEXT) { dx = (mScreenWidth - mTouchX).toInt() } else { dx = -mTouchX.toInt() } - if (mDirection != PageAnimation.Direction.NEXT) { + if (mDirection != Direction.NEXT) { dx = (-(mScreenWidth + mTouchX)).toInt() } @@ -124,7 +124,7 @@ class SimulationPageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListe dy = -mTouchY.toInt() // 防止mTouchY最终变为0 } } else { - if (mCornerX > 0 && mDirection == PageAnimation.Direction.NEXT) { + if (mCornerX > 0 && mDirection == Direction.NEXT) { dx = -(mScreenWidth + mTouchX).toInt() } else { dx = (mScreenWidth - mTouchX + mScreenWidth).toInt() @@ -142,14 +142,14 @@ class SimulationPageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListe super.setDirection(direction) when (direction) { - PageAnimation.Direction.PRE -> + Direction.PRE -> //上一页滑动不出现对角 if (mStartX > mScreenWidth / 2) { calcCornerXY(mStartX, mScreenHeight.toFloat()) } else { calcCornerXY(mScreenWidth - mStartX, mScreenHeight.toFloat()) } - PageAnimation.Direction.NEXT -> if (mScreenWidth / 2 > mStartX) { + Direction.NEXT -> if (mScreenWidth / 2 > mStartX) { calcCornerXY(mScreenWidth - mStartX, mStartY) } } @@ -163,11 +163,11 @@ class SimulationPageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListe override fun setTouchPoint(x: Float, y: Float) { super.setTouchPoint(x, y) //触摸y中间位置吧y变成屏幕高度 - if (mStartY > mScreenHeight / 3 && mStartY < mScreenHeight * 2 / 3 || mDirection == PageAnimation.Direction.PRE) { + if (mStartY > mScreenHeight / 3 && mStartY < mScreenHeight * 2 / 3 || mDirection == Direction.PRE) { mTouchY = mScreenHeight.toFloat() } - if (mStartY > mScreenHeight / 3 && mStartY < mScreenHeight / 2 && mDirection == PageAnimation.Direction.NEXT) { + if (mStartY > mScreenHeight / 3 && mStartY < mScreenHeight / 2 && mDirection == Direction.NEXT) { mTouchY = 1f } } diff --git a/app/src/main/java/com/novel/read/widget/page/anim/SlidePageAnim.kt b/app/src/main/java/com/novel/read/widget/page/anim/SlidePageAnim.kt index 6a27996..355f3e7 100644 --- a/app/src/main/java/com/novel/read/widget/page/anim/SlidePageAnim.kt +++ b/app/src/main/java/com/novel/read/widget/page/anim/SlidePageAnim.kt @@ -26,9 +26,9 @@ class SlidePageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListener) } override fun drawMove(canvas: Canvas) { - var dis = 0 + var dis: Int when (mDirection) { - PageAnimation.Direction.NEXT -> { + Direction.NEXT -> { //左半边的剩余区域 dis = (mScreenWidth - mStartX + mTouchX).toInt() if (dis > mScreenWidth) { @@ -68,9 +68,9 @@ class SlidePageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListener) override fun startAnim() { super.startAnim() - var dx = 0 + val dx: Int when (mDirection) { - PageAnimation.Direction.NEXT -> if (isCancel) { + Direction.NEXT -> if (isCancel) { var dis = (mScreenWidth - mStartX + mTouchX).toInt() if (dis > mScreenWidth) { dis = mScreenWidth