转换部分java代码

old
zlj 5 years ago
parent 13e9fa78b3
commit 44e6210c38
  1. 2
      app/src/main/assets/litepal.xml
  2. 2
      app/src/main/java/com/novel/read/activity/NovelBookTypeListActivity.kt
  3. 6
      app/src/main/java/com/novel/read/fragment/BookFragment.kt
  4. 1
      app/src/main/java/com/novel/read/fragment/MoreFragment.kt
  5. 1
      app/src/main/java/com/novel/read/http/AccountManager.kt
  6. 43
      app/src/main/java/com/novel/read/model/db/BookRecordBean.java
  7. 17
      app/src/main/java/com/novel/read/model/db/BookRecordBean.kt
  8. 4
      app/src/main/java/com/novel/read/model/db/CollBookBean.java
  9. 2
      app/src/main/java/com/novel/read/model/db/DownloadTaskBean.java
  10. 42
      app/src/main/java/com/novel/read/model/db/SearchListTable.java
  11. 29
      app/src/main/java/com/novel/read/model/db/SearchListTable.kt
  12. 10
      app/src/main/java/com/novel/read/model/db/dbManage/BookManager.java
  13. 2
      app/src/main/java/com/novel/read/model/protocol/BookArticleResp.java
  14. 6
      app/src/main/java/com/novel/read/model/protocol/BookDetailResp.java
  15. 2
      app/src/main/java/com/novel/read/model/protocol/ChapterInfoPackage.kt
  16. 5
      app/src/main/java/com/novel/read/service/DownloadMessage.java
  17. 4
      app/src/main/java/com/novel/read/service/DownloadService.java
  18. 234
      app/src/main/java/com/novel/read/utlis/PermissionUtil.java
  19. 59
      app/src/main/java/com/novel/read/widget/RefreshLayout.java
  20. 2
      app/src/main/java/com/novel/read/widget/page/PageLoader.java
  21. 2
      app/src/main/java/com/novel/read/widget/page/PageView.java
  22. 4
      app/src/main/java/com/novel/read/widget/page/TxtPage.java
  23. 16
      app/src/main/java/com/novel/read/widget/page/anim/SimulationPageAnim.kt
  24. 8
      app/src/main/java/com/novel/read/widget/page/anim/SlidePageAnim.kt

@ -2,7 +2,7 @@
<litepal> <litepal>
<dbname value="readDb" /> <dbname value="readDb" />
<version value="8" /> <version value="9" />
<list> <list>
<!--搜索记录表--> <!--搜索记录表-->

@ -58,7 +58,7 @@ class NovelBookTypeListActivity : NovelBaseActivity() {
refresh.setOnReloadingListener { this.getData() } refresh.setOnReloadingListener { this.getData() }
getData() getData()
toolbar.title = mTitle toolbar.title = mTitle
toolbar.setNavigationOnClickListener { view -> finish() } toolbar.setNavigationOnClickListener { finish() }
} }

@ -121,12 +121,12 @@ class BookFragment : NovelBaseFragment() {
} }
true true
} }
tv_cancel.setOnClickListener { view -> tv_cancel.setOnClickListener {
EventManager.instance.postEvent(HideBottomBarEvent(false)) EventManager.instance.postEvent(HideBottomBarEvent(false))
updateBook(UpdateBookEvent()) updateBook(UpdateBookEvent())
} }
tv_delete.setOnClickListener { view -> tv_delete.setOnClickListener {
val deleteList = mAdapter.selectList val deleteList = mAdapter.selectList
for (i in deleteList.indices) { for (i in deleteList.indices) {
if (deleteList[i].isSaved) { if (deleteList[i].isSaved) {
@ -140,7 +140,7 @@ class BookFragment : NovelBaseFragment() {
updateBook(UpdateBookEvent()) updateBook(UpdateBookEvent())
} }
mAdapter.setOnItemClickListener { view, pos -> mAdapter.setOnItemClickListener { _, _ ->
EventManager.instance.postEvent( EventManager.instance.postEvent(
SwitchFragmentEvent() SwitchFragmentEvent()
) )

@ -101,7 +101,6 @@ class MoreFragment : NovelBaseFragment() {
fragment.arguments = args fragment.arguments = args
return fragment return fragment
} }
} }
override fun onDestroy() { override fun onDestroy() {

@ -42,7 +42,6 @@ import io.reactivex.schedulers.Schedulers
import okhttp3.MediaType import okhttp3.MediaType
import okhttp3.RequestBody import okhttp3.RequestBody
import retrofit2.Callback import retrofit2.Callback
import java.util.Map
/** /**
* Created by zlj on 2017/2/14. * Created by zlj on 2017/2/14.

@ -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;
}
}

@ -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
}

@ -14,9 +14,7 @@ import java.util.List;
*/ */
public class CollBookBean extends LitePalSupport implements Serializable { 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 * _id : 53663ae356bdc93e49004474
* title : 逍遥派 * title : 逍遥派

@ -7,7 +7,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Created by newbiechen on 17-5-11. * Created by zlj
*/ */
public class DownloadTaskBean extends LitePalSupport { public class DownloadTaskBean extends LitePalSupport {
public static final int STATUS_LOADING = 1; public static final int STATUS_LOADING = 1;

@ -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);
}
}

@ -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
}
}

@ -53,7 +53,7 @@ public class BookManager {
File file = getBookFile(bookId, chapterName); File file = getBookFile(bookId, chapterName);
//TODO:数据加载默认utf-8(以后会增加判断),FileUtils采用Reader获取数据的,可能用byte会更好一点 //TODO:数据加载默认utf-8(以后会增加判断),FileUtils采用Reader获取数据的,可能用byte会更好一点
char[] array = FileUtils.getFileContent(file).toCharArray(); char[] array = FileUtils.getFileContent(file).toCharArray();
WeakReference<char[]> charReference = new WeakReference<char[]>(array); WeakReference<char[]> charReference = new WeakReference<>(array);
cache.size = array.length; cache.size = array.length;
cache.data = charReference; cache.data = charReference;
cacheMap.put(chapterName, cache); cacheMap.put(chapterName, cache);
@ -167,9 +167,9 @@ public class BookManager {
/** /**
* 创建或获取存储文件 * 创建或获取存储文件
* @param folderName * @param folderName 文件夹
* @param fileName * @param fileName 文件
* @return * @return 文件
*/ */
public static File getBookFile(String folderName, String fileName){ public static File getBookFile(String folderName, String fileName){
return FileUtils.getFile(Constant.BOOK_CACHE_PATH + folderName return FileUtils.getFile(Constant.BOOK_CACHE_PATH + folderName
@ -186,7 +186,7 @@ public class BookManager {
* ) * )
* @param folderName : bookId * @param folderName : bookId
* @param fileName: chapterName * @param fileName: chapterName
* @return * @return 是否被缓存过
*/ */
public static boolean isChapterCached(String folderName, String fileName){ public static boolean isChapterCached(String folderName, String fileName){
File file = new File(Constant.BOOK_CACHE_PATH + folderName File file = new File(Constant.BOOK_CACHE_PATH + folderName

@ -82,7 +82,7 @@ public class BookArticleResp implements Serializable {
return bookChapterBean; return bookChapterBean;
} }
public List<BookChapterBean> createChapterBean() { private List<BookChapterBean> createChapterBean() {
List<BookChapterBean> mList = new ArrayList<>(); List<BookChapterBean> mList = new ArrayList<>();
for (ArticleBean articleBean:getArticle()){ for (ArticleBean articleBean:getArticle()){
mList.add(new BookChapterBean(String.valueOf(articleBean.getId()),articleBean.getTitle())); mList.add(new BookChapterBean(String.valueOf(articleBean.getId()),articleBean.getTitle()));

@ -182,7 +182,7 @@ public class BookDetailResp {
return collBookBean; return collBookBean;
} }
public CollBookBean createCollBookBean(){ private CollBookBean createCollBookBean(){
CollBookBean bean = new CollBookBean(); CollBookBean bean = new CollBookBean();
bean.setId(String.valueOf(getBook().getId())); bean.setId(String.valueOf(getBook().getId()));
bean.setTitle(getBook().getTitle()); bean.setTitle(getBook().getTitle());
@ -190,14 +190,10 @@ public class BookDetailResp {
bean.setShortIntro(getBook().getDescription()); bean.setShortIntro(getBook().getDescription());
bean.setCover(getBook().getCover()); bean.setCover(getBook().getCover());
bean.setInclude_image(getBook().getInclude_image()); bean.setInclude_image(getBook().getInclude_image());
// bean.setHasCp(getBook().isHasCp());
// bean.setLatelyFollower(getBook().getLatelyFollower());
// bean.setRetentionRatio(Double.parseDouble(getBook().getRetentionRatio()));
if (getLast_article()!=null){ if (getLast_article()!=null){
bean.setUpdated(String.valueOf(getLast_article().getCreate_time())); bean.setUpdated(String.valueOf(getLast_article().getCreate_time()));
bean.setLastChapter(getLast_article().getTitle()); bean.setLastChapter(getLast_article().getTitle());
} }
// bean.setChaptersCount(getBook().getChaptersCount());
return bean; return bean;
} }
} }

@ -6,7 +6,7 @@ import java.io.Serializable
class ChapterInfoPackage : Serializable { class ChapterInfoPackage : Serializable {
var article: List<ChapterInfoBean>? = null var article: List<ChapterInfoBean> = ArrayList()
} }

@ -2,11 +2,6 @@ package com.novel.read.service;
import com.mango.mangolib.event.BaseEvent; import com.mango.mangolib.event.BaseEvent;
/**
* Created by newbiechen on 17-5-10.
* 下载进度事件
*/
public class DownloadMessage extends BaseEvent { public class DownloadMessage extends BaseEvent {
public String message; public String message;

@ -34,10 +34,6 @@ import java.util.concurrent.Executors;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
/**
* Created by newbiechen on 17-5-10.
*/
public class DownloadService extends BaseService { public class DownloadService extends BaseService {
private static final String TAG = "DownloadService"; private static final String TAG = "DownloadService";
//加载状态 //加载状态

@ -11,150 +11,118 @@ import com.novel.read.R;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* Created by loki
* Date 2018/9/3.
*/
public class PermissionUtil { public class PermissionUtil {
private static PermissionUtil permissionUtil = null; private static PermissionUtil permissionUtil = null;
private static List<String> mListPermissions; private static List<String> mListPermissions;
private static String[] PERMISSIONS_LIST = { private static String[] PERMISSIONS_LIST = {
Manifest.permission.INTERNET, Manifest.permission.INTERNET,
Manifest.permission.ACCESS_NETWORK_STATE, Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_WIFI_STATE, Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.ACCESS_NETWORK_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;
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<String> mListPermissions) {
mListPermissions.add(PERMISSIONS_STORAGE);
/**
* 添加权限
* author LH
* data 2016/7/27 11:27
*/
private void addAllPermissions(List<String> 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<String> findDeniedPermissions(Activity activity, List<String> permissions) {
List<String> denyPermissions = new ArrayList<>();
for (String value : permissions) {
if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED) {
denyPermissions.add(value);
}
} }
return denyPermissions;
}
public static PermissionUtil getInstance() {
/** if (permissionUtil == null) {
* 获取所有权限 permissionUtil = new PermissionUtil();
* author LH }
* data 2016/7/27 13:37 return permissionUtil;
*/
@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(); public boolean isOverMarshmallow() {
return; return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
} }
mListPermissions = findDeniedPermissions(activity, mListPermissions);
if (mListPermissions != null && mListPermissions.size() > 0) { @TargetApi(value = Build.VERSION_CODES.M)
activity.requestPermissions(mListPermissions.toArray(new String[mListPermissions.size()]), public List<String> findDeniedPermissions(Activity activity, List<String> permissions) {
requestCode); List<String> denyPermissions = new ArrayList<>();
} else { for (String value : permissions) {
permissionCallBack.onPermissionSuccess(); if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED) {
denyPermissions.add(value);
}
}
return denyPermissions;
} }
}
@TargetApi(value = Build.VERSION_CODES.M)
public void requestResult(Activity activity, String[] permissions, int[] grantResults, PermissionCallBack permissionCallBack) { public void requestPermissions(Activity activity, int requestCode, PermissionCallBack permissionCallBack) {
mListPermissions = new ArrayList<>(); if (mListPermissions == null) {
ArrayList<String> noPermissions = new ArrayList<>(); mListPermissions = new ArrayList<>();
ArrayList<String> rejectPermissons = new ArrayList<>(); addAllPermissions(mListPermissions);
for (int i = 0; i < grantResults.length; i++) { }
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) { if (!isOverMarshmallow()) {
if (isOverMarshmallow()) { permissionCallBack.onPermissionSuccess();
boolean isShould = activity.shouldShowRequestPermissionRationale(permissions[i]); return;
mListPermissions.add(permissions[i]); }
if (isShould) { mListPermissions = findDeniedPermissions(activity, mListPermissions);
noPermissions.add(permissions[i]); if (mListPermissions != null && mListPermissions.size() > 0) {
} else { activity.requestPermissions(mListPermissions.toArray(new String[mListPermissions.size()]),
rejectPermissons.add(permissions[i]); requestCode);
} } else {
permissionCallBack.onPermissionSuccess();
} }
}
} }
if (noPermissions.size() > 0) { public void requestResult(Activity activity, String[] permissions, int[] grantResults, PermissionCallBack permissionCallBack) {
permissionCallBack.onPermissionFail(); mListPermissions = new ArrayList<>();
} else if (rejectPermissons.size() > 0) { ArrayList<String> noPermissions = new ArrayList<>();
ArrayList<String> permissonsList = new ArrayList<>(); ArrayList<String> rejectPermissons = new ArrayList<>();
for (int i = 0; i < rejectPermissons.size(); i++) { for (int i = 0; i < grantResults.length; i++) {
String strPermissons = rejectPermissons.get(i); if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
if (PERMISSIONS_STORAGE.equals(strPermissons)) { if (isOverMarshmallow()) {
permissonsList.add("storage"); boolean isShould = activity.shouldShowRequestPermissionRationale(permissions[i]);
} else if (PERMISSIONS_PHONE.equals(strPermissons)) { mListPermissions.add(permissions[i]);
permissonsList.add("phone"); if (isShould) {
noPermissions.add(permissions[i]);
} else {
rejectPermissons.add(permissions[i]);
}
}
}
}
if (noPermissions.size() > 0) {
permissionCallBack.onPermissionFail();
} else if (rejectPermissons.size() > 0) {
ArrayList<String> 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 { public interface PermissionCallBack {
void onPermissionSuccess(); void onPermissionSuccess();
void onPermissionReject(String strMessage); void onPermissionReject(String strMessage);
void onPermissionFail(); void onPermissionFail();
} }
} }

@ -36,11 +36,11 @@ public class RefreshLayout extends FrameLayout {
private int mStatus = 0; private int mStatus = 0;
public RefreshLayout(Context context) { public RefreshLayout(Context context) {
this(context,null); this(context, null);
} }
public RefreshLayout(Context context, AttributeSet attrs) { public RefreshLayout(Context context, AttributeSet attrs) {
this(context, attrs,0); this(context, attrs, 0);
} }
public RefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) { public RefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) {
@ -50,16 +50,16 @@ public class RefreshLayout extends FrameLayout {
initView(); initView();
} }
private void initAttrs(AttributeSet attrs){ private void initAttrs(AttributeSet attrs) {
TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.RefreshLayout); TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.RefreshLayout);
mEmptyViewId = typedArray.getResourceId(R.styleable.RefreshLayout_layout_refresh_empty,R.layout.view_empty); 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); 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); mLoadingViewId = typedArray.getResourceId(R.styleable.RefreshLayout_layout_refresh_loading, R.layout.view_loading);
typedArray.recycle(); typedArray.recycle();
} }
private void initView(){ private void initView() {
//添加在empty、error、loading 情况下的布局 //添加在empty、error、loading 情况下的布局
mEmptyView = inflateView(mEmptyViewId); mEmptyView = inflateView(mEmptyViewId);
@ -73,7 +73,7 @@ public class RefreshLayout extends FrameLayout {
//设置监听器 //设置监听器
mErrorView.setOnClickListener( mErrorView.setOnClickListener(
(view) -> { (view) -> {
if (mListener != null){ if (mListener != null) {
toggleStatus(STATUS_LOADING); toggleStatus(STATUS_LOADING);
mListener.onReload(); mListener.onReload();
} }
@ -90,7 +90,7 @@ public class RefreshLayout extends FrameLayout {
@Override @Override
public void onViewAdded(View child) { public void onViewAdded(View child) {
super.onViewAdded(child); super.onViewAdded(child);
if (getChildCount() == 4){ if (getChildCount() == 4) {
mContentView = child; mContentView = child;
} }
} }
@ -131,43 +131,43 @@ public class RefreshLayout extends FrameLayout {
super.addView(child, index, params); super.addView(child, index, params);
} }
public void showLoading(){ public void showLoading() {
if (mStatus != STATUS_LOADING){ if (mStatus != STATUS_LOADING) {
toggleStatus(STATUS_LOADING); toggleStatus(STATUS_LOADING);
} }
} }
public void showFinish(){ public void showFinish() {
if (mStatus == STATUS_LOADING){ if (mStatus == STATUS_LOADING) {
toggleStatus(STATUS_FINISH); toggleStatus(STATUS_FINISH);
} }
} }
public void showError(){ public void showError() {
if (mStatus != STATUS_ERROR){ if (mStatus != STATUS_ERROR) {
toggleStatus(STATUS_ERROR); toggleStatus(STATUS_ERROR);
} }
} }
public void showEmpty(){ public void showEmpty() {
if (mStatus != STATUS_EMPTY){ if (mStatus != STATUS_EMPTY) {
toggleStatus(STATUS_EMPTY); toggleStatus(STATUS_EMPTY);
} }
} }
//视图根据状态切换 //视图根据状态切换
private void toggleStatus(int status){ private void toggleStatus(int status) {
switch (status){ switch (status) {
case STATUS_LOADING: case STATUS_LOADING:
mLoadingView.setVisibility(VISIBLE); mLoadingView.setVisibility(VISIBLE);
mEmptyView.setVisibility(GONE); mEmptyView.setVisibility(GONE);
mErrorView.setVisibility(GONE); mErrorView.setVisibility(GONE);
if (mContentView != null){ if (mContentView != null) {
mContentView.setVisibility(GONE); mContentView.setVisibility(GONE);
} }
break; break;
case STATUS_FINISH: case STATUS_FINISH:
if (mContentView != null){ if (mContentView != null) {
mContentView.setVisibility(VISIBLE); mContentView.setVisibility(VISIBLE);
} }
mLoadingView.setVisibility(GONE); mLoadingView.setVisibility(GONE);
@ -178,7 +178,7 @@ public class RefreshLayout extends FrameLayout {
mErrorView.setVisibility(VISIBLE); mErrorView.setVisibility(VISIBLE);
mLoadingView.setVisibility(GONE); mLoadingView.setVisibility(GONE);
mEmptyView.setVisibility(GONE); mEmptyView.setVisibility(GONE);
if (mContentView != null){ if (mContentView != null) {
mContentView.setVisibility(GONE); mContentView.setVisibility(GONE);
} }
break; break;
@ -186,7 +186,7 @@ public class RefreshLayout extends FrameLayout {
mEmptyView.setVisibility(VISIBLE); mEmptyView.setVisibility(VISIBLE);
mErrorView.setVisibility(GONE); mErrorView.setVisibility(GONE);
mLoadingView.setVisibility(GONE); mLoadingView.setVisibility(GONE);
if (mContentView != null){ if (mContentView != null) {
mContentView.setVisibility(GONE); mContentView.setVisibility(GONE);
} }
break; break;
@ -194,17 +194,12 @@ public class RefreshLayout extends FrameLayout {
mStatus = status; mStatus = status;
} }
protected int getStatus(){ public void setOnReloadingListener(OnReloadingListener listener) {
return mStatus;
}
public void setOnReloadingListener(OnReloadingListener listener){
mListener = listener; mListener = listener;
} }
private View inflateView(int id){ private View inflateView(int id) {
return LayoutInflater.from(mContext) return LayoutInflater.from(mContext).inflate(id, this, false);
.inflate(id,this,false);
} }
//数据存储 //数据存储
@ -255,7 +250,7 @@ public class RefreshLayout extends FrameLayout {
} }
//添加错误重新加载的监听 //添加错误重新加载的监听
public interface OnReloadingListener{ public interface OnReloadingListener {
void onReload(); void onReload();
} }
} }

@ -874,7 +874,7 @@ public abstract class PageLoader {
int para = mTextPara + (int) mTextPaint.getTextSize(); int para = mTextPara + (int) mTextPaint.getTextSize();
int titleInterval = mTitleInterval + (int) mTitlePaint.getTextSize(); int titleInterval = mTitleInterval + (int) mTitlePaint.getTextSize();
int titlePara = mTitlePara + (int) mTextPaint.getTextSize(); int titlePara = mTitlePara + (int) mTextPaint.getTextSize();
String str = null; String str;
//对标题进行绘制 //对标题进行绘制
for (int i = 0; i < mCurPage.titleLines; ++i) { for (int i = 0; i < mCurPage.titleLines; ++i) {

@ -24,8 +24,6 @@ import com.novel.read.widget.page.anim.SlidePageAnim;
*/ */
public class PageView extends View { public class PageView extends View {
private final static String TAG = "BookPageWidget";
private int mViewWidth = 0; // 当前View的宽 private int mViewWidth = 0; // 当前View的宽
private int mViewHeight = 0; // 当前View的高 private int mViewHeight = 0; // 当前View的高

@ -18,9 +18,7 @@ public class TxtPage {
return title == null ? "" : title; return title == null ? "" : title;
} }
public int getTitleLines() {
return titleLines;
}
public List<String> getLines() { public List<String> getLines() {
if (lines == null) { if (lines == null) {

@ -74,7 +74,7 @@ class SimulationPageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListe
override fun drawMove(canvas: Canvas) { override fun drawMove(canvas: Canvas) {
when (mDirection) { when (mDirection) {
PageAnimation.Direction.NEXT -> { Direction.NEXT -> {
calcPoints() calcPoints()
drawCurrentPageArea(canvas, mCurBitmap, mPath0) drawCurrentPageArea(canvas, mCurBitmap, mPath0)
drawNextPageAreaAndShadow(canvas, mNextBitmap) drawNextPageAreaAndShadow(canvas, mNextBitmap)
@ -108,13 +108,13 @@ class SimulationPageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListe
// dy 垂直方向滑动的距离,负值会使滚动向上滚动 // dy 垂直方向滑动的距离,负值会使滚动向上滚动
if (isCancel) { if (isCancel) {
if (mCornerX > 0 && mDirection == PageAnimation.Direction.NEXT) { if (mCornerX > 0 && mDirection == Direction.NEXT) {
dx = (mScreenWidth - mTouchX).toInt() dx = (mScreenWidth - mTouchX).toInt()
} else { } else {
dx = -mTouchX.toInt() dx = -mTouchX.toInt()
} }
if (mDirection != PageAnimation.Direction.NEXT) { if (mDirection != Direction.NEXT) {
dx = (-(mScreenWidth + mTouchX)).toInt() dx = (-(mScreenWidth + mTouchX)).toInt()
} }
@ -124,7 +124,7 @@ class SimulationPageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListe
dy = -mTouchY.toInt() // 防止mTouchY最终变为0 dy = -mTouchY.toInt() // 防止mTouchY最终变为0
} }
} else { } else {
if (mCornerX > 0 && mDirection == PageAnimation.Direction.NEXT) { if (mCornerX > 0 && mDirection == Direction.NEXT) {
dx = -(mScreenWidth + mTouchX).toInt() dx = -(mScreenWidth + mTouchX).toInt()
} else { } else {
dx = (mScreenWidth - mTouchX + mScreenWidth).toInt() dx = (mScreenWidth - mTouchX + mScreenWidth).toInt()
@ -142,14 +142,14 @@ class SimulationPageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListe
super.setDirection(direction) super.setDirection(direction)
when (direction) { when (direction) {
PageAnimation.Direction.PRE -> Direction.PRE ->
//上一页滑动不出现对角 //上一页滑动不出现对角
if (mStartX > mScreenWidth / 2) { if (mStartX > mScreenWidth / 2) {
calcCornerXY(mStartX, mScreenHeight.toFloat()) calcCornerXY(mStartX, mScreenHeight.toFloat())
} else { } else {
calcCornerXY(mScreenWidth - mStartX, mScreenHeight.toFloat()) calcCornerXY(mScreenWidth - mStartX, mScreenHeight.toFloat())
} }
PageAnimation.Direction.NEXT -> if (mScreenWidth / 2 > mStartX) { Direction.NEXT -> if (mScreenWidth / 2 > mStartX) {
calcCornerXY(mScreenWidth - mStartX, mStartY) 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) { override fun setTouchPoint(x: Float, y: Float) {
super.setTouchPoint(x, y) super.setTouchPoint(x, y)
//触摸y中间位置吧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() 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 mTouchY = 1f
} }
} }

@ -26,9 +26,9 @@ class SlidePageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListener)
} }
override fun drawMove(canvas: Canvas) { override fun drawMove(canvas: Canvas) {
var dis = 0 var dis: Int
when (mDirection) { when (mDirection) {
PageAnimation.Direction.NEXT -> { Direction.NEXT -> {
//左半边的剩余区域 //左半边的剩余区域
dis = (mScreenWidth - mStartX + mTouchX).toInt() dis = (mScreenWidth - mStartX + mTouchX).toInt()
if (dis > mScreenWidth) { if (dis > mScreenWidth) {
@ -68,9 +68,9 @@ class SlidePageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListener)
override fun startAnim() { override fun startAnim() {
super.startAnim() super.startAnim()
var dx = 0 val dx: Int
when (mDirection) { when (mDirection) {
PageAnimation.Direction.NEXT -> if (isCancel) { Direction.NEXT -> if (isCancel) {
var dis = (mScreenWidth - mStartX + mTouchX).toInt() var dis = (mScreenWidth - mStartX + mTouchX).toInt()
if (dis > mScreenWidth) { if (dis > mScreenWidth) {
dis = mScreenWidth dis = mScreenWidth

Loading…
Cancel
Save