parent
ecbb2e5edd
commit
1103642591
@ -1,286 +0,0 @@ |
|||||||
package com.novel.read.activity; |
|
||||||
|
|
||||||
import android.annotation.SuppressLint; |
|
||||||
import android.app.ProgressDialog; |
|
||||||
import android.content.Intent; |
|
||||||
import android.os.Bundle; |
|
||||||
|
|
||||||
import android.view.View; |
|
||||||
import android.widget.ImageView; |
|
||||||
import android.widget.TextView; |
|
||||||
import androidx.appcompat.widget.Toolbar; |
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager; |
|
||||||
import androidx.recyclerview.widget.RecyclerView; |
|
||||||
|
|
||||||
import com.common_lib.base.utils.ToastUtils; |
|
||||||
import com.mango.mangolib.event.EventManager; |
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.adapter.LoveLyAdapter; |
|
||||||
import com.novel.read.base.NovelBaseActivity; |
|
||||||
import com.novel.read.constants.Constant; |
|
||||||
import com.novel.read.event.BookArticleEvent; |
|
||||||
import com.novel.read.event.GetBookDetailEvent; |
|
||||||
import com.novel.read.event.GetRecommendBookEvent; |
|
||||||
import com.novel.read.event.UpdateBookEvent; |
|
||||||
import com.novel.read.http.AccountManager; |
|
||||||
import com.novel.read.model.db.BookChapterBean; |
|
||||||
import com.novel.read.model.db.CollBookBean; |
|
||||||
import com.novel.read.model.db.dbManage.BookRepository; |
|
||||||
import com.novel.read.model.protocol.BookDetailResp; |
|
||||||
import com.novel.read.model.protocol.RecommendBookResp; |
|
||||||
import com.novel.read.utlis.DateUtli; |
|
||||||
import com.novel.read.utlis.GlideImageLoader; |
|
||||||
import com.novel.read.widget.RefreshLayout; |
|
||||||
import com.squareup.otto.Subscribe; |
|
||||||
|
|
||||||
import org.litepal.LitePal; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
import butterknife.OnClick; |
|
||||||
|
|
||||||
import static com.novel.read.constants.Constant.RequestCode.REQUEST_READ; |
|
||||||
import static com.novel.read.constants.Constant.ResultCode.RESULT_IS_COLLECTED; |
|
||||||
|
|
||||||
public class NovelBookDetailActivity extends NovelBaseActivity { |
|
||||||
|
|
||||||
@BindView(R.id.toolbar) |
|
||||||
Toolbar toolbar; |
|
||||||
@BindView(R.id.iv_book) |
|
||||||
ImageView mIvBook; |
|
||||||
@BindView(R.id.tv_book_name) |
|
||||||
TextView mTvBookName; |
|
||||||
@BindView(R.id.tv_book_author) |
|
||||||
TextView mTvBookAuthor; |
|
||||||
@BindView(R.id.tv_book_length) |
|
||||||
TextView mTvBookLength; |
|
||||||
@BindView(R.id.tv_new_title) |
|
||||||
TextView mTvNewTitle; |
|
||||||
@BindView(R.id.tv_update_time) |
|
||||||
TextView mTvUpdateTime; |
|
||||||
@BindView(R.id.tv_human_num) |
|
||||||
TextView mTvHumanNum; |
|
||||||
@BindView(R.id.tv_love_look_num) |
|
||||||
TextView mTvLoveLookNum; |
|
||||||
@BindView(R.id.tv_Intro) |
|
||||||
TextView mTvIntro; |
|
||||||
@BindView(R.id.rlv_lovely) |
|
||||||
RecyclerView mRlvLovely; |
|
||||||
@BindView(R.id.tv_add_book) |
|
||||||
TextView mTvAddBook; |
|
||||||
@BindView(R.id.tv_start_read) |
|
||||||
TextView mTvStartRead; |
|
||||||
@BindView(R.id.refresh) |
|
||||||
RefreshLayout refreshLayout; |
|
||||||
|
|
||||||
private LoveLyAdapter mAdapter; |
|
||||||
private List<RecommendBookResp.BookBean> mList = new ArrayList<>(); |
|
||||||
|
|
||||||
private int mBookId; |
|
||||||
|
|
||||||
private boolean isCollected = false; |
|
||||||
private CollBookBean mCollBookBean; |
|
||||||
|
|
||||||
private ProgressDialog mProgressDialog; |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onCreate(Bundle savedInstanceState) { |
|
||||||
super.onCreate(savedInstanceState); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected int getLayoutId() { |
|
||||||
return R.layout.activity_book_detail; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initView() { |
|
||||||
mBookId = getIntent().getIntExtra(Constant.Bundle.BookId,0); |
|
||||||
mRlvLovely.setLayoutManager(new LinearLayoutManager(this)); |
|
||||||
mAdapter = new LoveLyAdapter(mList); |
|
||||||
mRlvLovely.setAdapter(mAdapter); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initData() { |
|
||||||
refreshLayout.showLoading(); |
|
||||||
refreshLayout.setOnReloadingListener(new RefreshLayout.OnReloadingListener() { |
|
||||||
@Override |
|
||||||
public void onReload() { |
|
||||||
getData(); |
|
||||||
} |
|
||||||
}); |
|
||||||
getData(); |
|
||||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() { |
|
||||||
@Override |
|
||||||
public void onClick(View view) { |
|
||||||
finish(); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
private void getData(){ |
|
||||||
AccountManager.getInstance().getRecommendBook(String.valueOf(mBookId), "10"); |
|
||||||
AccountManager.getInstance().getBookDetail(String.valueOf(mBookId)); |
|
||||||
} |
|
||||||
|
|
||||||
@OnClick({R.id.tv_add_book, R.id.tv_start_read}) |
|
||||||
public void onViewClicked(View view) { |
|
||||||
switch (view.getId()) { |
|
||||||
case R.id.tv_add_book: |
|
||||||
//点击存储
|
|
||||||
if (isCollected) { |
|
||||||
//放弃点击
|
|
||||||
BookRepository.getInstance().deleteCollBookInRx(mCollBookBean); |
|
||||||
mTvAddBook.setText(getResources().getString(R.string.add_book)); |
|
||||||
isCollected = false; |
|
||||||
} else { |
|
||||||
if (mProgressDialog == null) { |
|
||||||
mProgressDialog = new ProgressDialog(this); |
|
||||||
mProgressDialog.setTitle("正在添加到书架中"); |
|
||||||
} |
|
||||||
mProgressDialog.show(); |
|
||||||
AccountManager.getInstance().getBookArticle(String.valueOf(mBookId),"2","1","100000"); |
|
||||||
|
|
||||||
} |
|
||||||
break; |
|
||||||
case R.id.tv_start_read: |
|
||||||
// if (mCollBookBean.getInclude_image()==Constant.HasImage.has){
|
|
||||||
// startActivityForResult(new Intent(this, NovelWebReadActivity.class)
|
|
||||||
// .putExtra(NovelReadActivity.EXTRA_IS_COLLECTED, isCollected)
|
|
||||||
// .putExtra(NovelReadActivity.EXTRA_COLL_BOOK, mCollBookBean), REQUEST_READ);
|
|
||||||
// }else {
|
|
||||||
startActivityForResult(new Intent(this, NovelReadActivity.class) |
|
||||||
.putExtra(NovelReadActivity.EXTRA_IS_COLLECTED, isCollected) |
|
||||||
.putExtra(NovelReadActivity.EXTRA_COLL_BOOK, mCollBookBean), REQUEST_READ); |
|
||||||
// }
|
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n") |
|
||||||
@Subscribe |
|
||||||
public void getBookDetail(GetBookDetailEvent event) { |
|
||||||
refreshLayout.showFinish(); |
|
||||||
if (event.isFail()) { |
|
||||||
refreshLayout.showError(); |
|
||||||
} else { |
|
||||||
BookDetailResp.BookBean bookBean = event.getResult().getBook(); |
|
||||||
GlideImageLoader.displayCornerImage(this, bookBean.getCover(), mIvBook); |
|
||||||
mTvBookName.setText(bookBean.getTitle()); |
|
||||||
|
|
||||||
mTvBookAuthor.setText(bookBean.getAuthor() + " | "); |
|
||||||
mTvBookLength.setText(getString(R.string.book_word, bookBean.getWords() / 10000)); |
|
||||||
|
|
||||||
if (event.getResult().getLast_article()!=null){ |
|
||||||
mTvNewTitle.setText(getString(R.string.new_chapter,event.getResult().getLast_article().getTitle())); |
|
||||||
mTvUpdateTime.setText(DateUtli.dateConvert(event.getResult().getLast_article().getCreate_time(),0)); |
|
||||||
} |
|
||||||
|
|
||||||
mTvHumanNum.setText(bookBean.getHot() + ""); |
|
||||||
mTvLoveLookNum.setText(bookBean.getLike()); |
|
||||||
mTvIntro.setText(bookBean.getDescription()); |
|
||||||
mCollBookBean = BookRepository.getInstance().getCollBook(String.valueOf(bookBean.getId())); |
|
||||||
//判断是否收藏
|
|
||||||
if (mCollBookBean != null) { |
|
||||||
isCollected = true; |
|
||||||
mTvAddBook.setText(getResources().getString(R.string.already_add)); |
|
||||||
mTvStartRead.setText("继续阅读"); |
|
||||||
} else { |
|
||||||
mCollBookBean = event.getResult().getCollBookBean(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void getRecommendBook(GetRecommendBookEvent event) { |
|
||||||
if (event.isFail()) { |
|
||||||
|
|
||||||
} else { |
|
||||||
mList.clear(); |
|
||||||
mList.addAll(event.getResult().getBook()); |
|
||||||
mAdapter.notifyDataSetChanged(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onResume() { |
|
||||||
super.onResume(); |
|
||||||
EventManager.Companion.getInstance().registerSubscriber(this); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onPause() { |
|
||||||
super.onPause(); |
|
||||||
EventManager.Companion.getInstance().unregisterSubscriber(this); |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void getArticle(BookArticleEvent event){ |
|
||||||
|
|
||||||
if (event.isFail()){ |
|
||||||
dismiss(); |
|
||||||
ToastUtils.showNormalToast(this,getString(R.string.net_error)); |
|
||||||
}else { |
|
||||||
//存储收藏
|
|
||||||
boolean success = false; |
|
||||||
if (mCollBookBean!=null){ |
|
||||||
success = mCollBookBean.saveOrUpdate("bookId=?",mCollBookBean.getId()); |
|
||||||
} |
|
||||||
if (success){ |
|
||||||
List<BookChapterBean> bookChapterBean = event.getResult().getChapterBean(); |
|
||||||
for (int i = 0; i <bookChapterBean.size() ; i++) { |
|
||||||
bookChapterBean.get(i).setCollBookBean(mCollBookBean); |
|
||||||
} |
|
||||||
LitePal.saveAllAsync(bookChapterBean).listen(success1 -> { |
|
||||||
if (success1) { |
|
||||||
if (mTvAddBook!=null) { |
|
||||||
mTvAddBook.setText(getResources().getString(R.string.already_add)); |
|
||||||
} |
|
||||||
isCollected = true; |
|
||||||
}else { |
|
||||||
LitePal.deleteAll(CollBookBean.class,"bookId =?",mCollBookBean.getId()); |
|
||||||
ToastUtils.showNormalToast(this,getString(R.string.net_error)); |
|
||||||
} |
|
||||||
dismiss(); |
|
||||||
}); |
|
||||||
}else { |
|
||||||
ToastUtils.showNormalToast(this,getString(R.string.net_error)); |
|
||||||
dismiss(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
private void dismiss(){ |
|
||||||
if (mProgressDialog != null) { |
|
||||||
mProgressDialog.dismiss(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
|
||||||
super.onActivityResult(requestCode, resultCode, data); |
|
||||||
//如果进入阅读页面收藏了,页面结束的时候,就需要返回改变收藏按钮
|
|
||||||
if (requestCode == REQUEST_READ) { |
|
||||||
if (data == null) { |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
isCollected = data.getBooleanExtra(RESULT_IS_COLLECTED, false); |
|
||||||
|
|
||||||
if (isCollected) { |
|
||||||
mTvAddBook.setText(getResources().getString(R.string.already_add)); |
|
||||||
mTvStartRead.setText("继续阅读"); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onDestroy() { |
|
||||||
super.onDestroy(); |
|
||||||
EventManager.Companion.getInstance().postEvent(new UpdateBookEvent()); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,214 @@ |
|||||||
|
package com.novel.read.activity |
||||||
|
|
||||||
|
import android.annotation.SuppressLint |
||||||
|
import android.app.ProgressDialog |
||||||
|
import android.content.Intent |
||||||
|
import android.view.View |
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager |
||||||
|
import com.common_lib.base.utils.ToastUtils |
||||||
|
import com.mango.mangolib.event.EventManager |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.adapter.LoveLyAdapter |
||||||
|
import com.novel.read.base.NovelBaseActivity |
||||||
|
import com.novel.read.constants.Constant |
||||||
|
import com.novel.read.constants.Constant.RequestCode.Companion.REQUEST_READ |
||||||
|
import com.novel.read.constants.Constant.ResultCode.Companion.RESULT_IS_COLLECTED |
||||||
|
import com.novel.read.event.BookArticleEvent |
||||||
|
import com.novel.read.event.GetBookDetailEvent |
||||||
|
import com.novel.read.event.GetRecommendBookEvent |
||||||
|
import com.novel.read.event.UpdateBookEvent |
||||||
|
import com.novel.read.http.AccountManager |
||||||
|
import com.novel.read.model.db.CollBookBean |
||||||
|
import com.novel.read.model.db.dbManage.BookRepository |
||||||
|
import com.novel.read.model.protocol.RecommendBookResp |
||||||
|
import com.novel.read.utlis.DateUtli |
||||||
|
import com.novel.read.utlis.GlideImageLoader |
||||||
|
import com.squareup.otto.Subscribe |
||||||
|
import kotlinx.android.synthetic.main.activity_book_detail.* |
||||||
|
import org.litepal.LitePal |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
class NovelBookDetailActivity : NovelBaseActivity(), View.OnClickListener { |
||||||
|
|
||||||
|
private var mAdapter: LoveLyAdapter? = null |
||||||
|
private val mList = ArrayList<RecommendBookResp.BookBean>() |
||||||
|
|
||||||
|
private var mBookId: Int = 0 |
||||||
|
private var isCollected = false |
||||||
|
private var mCollBookBean: CollBookBean? = null |
||||||
|
|
||||||
|
private var mProgressDialog: ProgressDialog? = null |
||||||
|
|
||||||
|
override val layoutId: Int |
||||||
|
get() = R.layout.activity_book_detail |
||||||
|
|
||||||
|
override fun initView() { |
||||||
|
mBookId = intent.getIntExtra(Constant.Bundle.BookId, 0) |
||||||
|
rlv_lovely.layoutManager = LinearLayoutManager(this) |
||||||
|
mAdapter = LoveLyAdapter(mList) |
||||||
|
rlv_lovely.adapter = mAdapter |
||||||
|
} |
||||||
|
|
||||||
|
override fun initData() { |
||||||
|
refresh.showLoading() |
||||||
|
refresh.setOnReloadingListener { getData() } |
||||||
|
getData() |
||||||
|
toolbar.setNavigationOnClickListener { finish() } |
||||||
|
tv_add_book.setOnClickListener(this) |
||||||
|
tv_start_read.setOnClickListener(this) |
||||||
|
} |
||||||
|
|
||||||
|
private fun getData() { |
||||||
|
AccountManager.getInstance().getRecommendBook(mBookId.toString(), "10") |
||||||
|
AccountManager.getInstance().getBookDetail(mBookId.toString()) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onClick(v: View?) { |
||||||
|
when (v?.id) { |
||||||
|
R.id.tv_add_book -> |
||||||
|
//点击存储 |
||||||
|
if (isCollected) { |
||||||
|
//放弃点击 |
||||||
|
BookRepository.getInstance().deleteCollBookInRx(mCollBookBean) |
||||||
|
tv_add_book.text = resources.getString(R.string.add_book) |
||||||
|
isCollected = false |
||||||
|
} else { |
||||||
|
if (mProgressDialog == null) { |
||||||
|
mProgressDialog = ProgressDialog(this) |
||||||
|
mProgressDialog!!.setTitle("正在添加到书架中") |
||||||
|
} |
||||||
|
mProgressDialog!!.show() |
||||||
|
AccountManager.getInstance() |
||||||
|
.getBookArticle(mBookId.toString(), "2", "1", "100000") |
||||||
|
|
||||||
|
} |
||||||
|
R.id.tv_start_read -> |
||||||
|
startActivityForResult( |
||||||
|
Intent(this, NovelReadActivity::class.java) |
||||||
|
.putExtra(NovelReadActivity.EXTRA_IS_COLLECTED, isCollected) |
||||||
|
.putExtra(NovelReadActivity.EXTRA_COLL_BOOK, mCollBookBean), REQUEST_READ |
||||||
|
) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n") |
||||||
|
@Subscribe |
||||||
|
fun getBookDetail(event: GetBookDetailEvent) { |
||||||
|
refresh.showFinish() |
||||||
|
if (event.isFail) { |
||||||
|
refresh.showError() |
||||||
|
} else { |
||||||
|
val bookBean = event.result!!.book |
||||||
|
GlideImageLoader.displayCornerImage(this, bookBean.cover, iv_book) |
||||||
|
tv_book_name.text = bookBean.title |
||||||
|
|
||||||
|
tv_book_author.text = bookBean.author + " | " |
||||||
|
tv_book_length.text = getString(R.string.book_word, bookBean.words / 10000) |
||||||
|
|
||||||
|
if (event.result!!.last_article != null) { |
||||||
|
tv_new_title.text = |
||||||
|
getString(R.string.new_chapter, event.result!!.last_article.title) |
||||||
|
tv_update_time.text = |
||||||
|
DateUtli.dateConvert(event.result!!.last_article.create_time, 0) |
||||||
|
} |
||||||
|
|
||||||
|
tv_human_num.text = bookBean.hot.toString() + "" |
||||||
|
tv_love_look_num.text = bookBean.like |
||||||
|
tv_Intro.text = bookBean.description |
||||||
|
mCollBookBean = BookRepository.getInstance().getCollBook(bookBean.id.toString()) |
||||||
|
//判断是否收藏 |
||||||
|
if (mCollBookBean != null) { |
||||||
|
isCollected = true |
||||||
|
tv_add_book.text = resources.getString(R.string.already_add) |
||||||
|
tv_start_read.text = "继续阅读" |
||||||
|
} else { |
||||||
|
mCollBookBean = event.result!!.collBookBean |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun getRecommendBook(event: GetRecommendBookEvent) { |
||||||
|
if (event.isFail) { |
||||||
|
|
||||||
|
} else { |
||||||
|
mList.clear() |
||||||
|
mList.addAll(event.result!!.book) |
||||||
|
mAdapter!!.notifyDataSetChanged() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onResume() { |
||||||
|
super.onResume() |
||||||
|
EventManager.instance.registerSubscriber(this) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onPause() { |
||||||
|
super.onPause() |
||||||
|
EventManager.instance.unregisterSubscriber(this) |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun getArticle(event: BookArticleEvent) { |
||||||
|
if (event.isFail) { |
||||||
|
dismiss() |
||||||
|
ToastUtils.showNormalToast(this, getString(R.string.net_error)) |
||||||
|
} else { |
||||||
|
//存储收藏 |
||||||
|
var success = false |
||||||
|
if (mCollBookBean != null) { |
||||||
|
success = mCollBookBean!!.saveOrUpdate("bookId=?", mCollBookBean!!.id) |
||||||
|
} |
||||||
|
if (success) { |
||||||
|
val bookChapterBean = event.result!!.chapterBean |
||||||
|
for (i in bookChapterBean.indices) { |
||||||
|
bookChapterBean[i].collBookBean = mCollBookBean |
||||||
|
} |
||||||
|
LitePal.saveAllAsync(bookChapterBean).listen { success1 -> |
||||||
|
if (success1) { |
||||||
|
if (tv_add_book != null) { |
||||||
|
tv_add_book.text = resources.getString(R.string.already_add) |
||||||
|
} |
||||||
|
isCollected = true |
||||||
|
} else { |
||||||
|
LitePal.deleteAll(CollBookBean::class.java, "bookId =?", mCollBookBean!!.id) |
||||||
|
ToastUtils.showNormalToast(this, getString(R.string.net_error)) |
||||||
|
} |
||||||
|
dismiss() |
||||||
|
} |
||||||
|
} else { |
||||||
|
ToastUtils.showNormalToast(this, getString(R.string.net_error)) |
||||||
|
dismiss() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private fun dismiss() { |
||||||
|
if (mProgressDialog != null) { |
||||||
|
mProgressDialog!!.dismiss() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
||||||
|
super.onActivityResult(requestCode, resultCode, data) |
||||||
|
//如果进入阅读页面收藏了,页面结束的时候,就需要返回改变收藏按钮 |
||||||
|
if (requestCode == REQUEST_READ) { |
||||||
|
if (data == null) { |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
isCollected = data.getBooleanExtra(RESULT_IS_COLLECTED, false) |
||||||
|
|
||||||
|
if (isCollected) { |
||||||
|
tv_add_book.text = resources.getString(R.string.already_add) |
||||||
|
tv_start_read.text = "继续阅读" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onDestroy() { |
||||||
|
super.onDestroy() |
||||||
|
EventManager.instance.postEvent(UpdateBookEvent()) |
||||||
|
} |
||||||
|
} |
@ -1,120 +0,0 @@ |
|||||||
package com.novel.read.activity; |
|
||||||
|
|
||||||
import android.os.Bundle; |
|
||||||
|
|
||||||
import androidx.appcompat.widget.Toolbar; |
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager; |
|
||||||
import androidx.recyclerview.widget.RecyclerView; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.EventManager; |
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.adapter.BookListAdapter; |
|
||||||
import com.novel.read.base.NovelBaseActivity; |
|
||||||
import com.novel.read.constants.Constant; |
|
||||||
import com.novel.read.event.SearchListEvent; |
|
||||||
import com.novel.read.http.AccountManager; |
|
||||||
import com.novel.read.model.protocol.SearchResp; |
|
||||||
import com.novel.read.widget.RefreshLayout; |
|
||||||
import com.squareup.otto.Subscribe; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
|
|
||||||
import static com.novel.read.constants.Constant.COMMENT_SIZE; |
|
||||||
|
|
||||||
public class NovelBookTypeListActivity extends NovelBaseActivity { |
|
||||||
|
|
||||||
@BindView(R.id.toolbar) |
|
||||||
Toolbar toolbar; |
|
||||||
@BindView(R.id.rlv_type_list) |
|
||||||
RecyclerView mRlvTypeList; |
|
||||||
@BindView(R.id.refresh) |
|
||||||
RefreshLayout refreshLayout; |
|
||||||
private List<SearchResp.BookBean> mList; |
|
||||||
private BookListAdapter mAdapter; |
|
||||||
private String mCategoryId; |
|
||||||
private String mTitle; |
|
||||||
private int page = 1; |
|
||||||
private int loadSize; |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onCreate(Bundle savedInstanceState) { |
|
||||||
super.onCreate(savedInstanceState); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected int getLayoutId() { |
|
||||||
return R.layout.activity_book_type_list; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initView() { |
|
||||||
EventManager.Companion.getInstance().registerSubscriber(this); |
|
||||||
|
|
||||||
mCategoryId = getIntent().getStringExtra(Constant.Bundle.CategoryId); |
|
||||||
mTitle = getIntent().getStringExtra(Constant.Bundle.mTitle); |
|
||||||
|
|
||||||
mRlvTypeList.setLayoutManager(new LinearLayoutManager(this)); |
|
||||||
mList = new ArrayList<>(); |
|
||||||
|
|
||||||
mAdapter = new BookListAdapter(mList, mRlvTypeList); |
|
||||||
mRlvTypeList.setAdapter(mAdapter); |
|
||||||
|
|
||||||
mAdapter.setOnLoadMoreListener(() -> { |
|
||||||
if (mAdapter.isLoadingMore()) { |
|
||||||
|
|
||||||
} else { |
|
||||||
if (loadSize >= COMMENT_SIZE) { |
|
||||||
mAdapter.setLoadingMore(true); |
|
||||||
mList.add(null); |
|
||||||
mAdapter.notifyDataSetChanged(); |
|
||||||
page++; |
|
||||||
getData(); |
|
||||||
} |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initData() { |
|
||||||
refreshLayout.showLoading(); |
|
||||||
refreshLayout.setOnReloadingListener(this::getData); |
|
||||||
getData(); |
|
||||||
toolbar.setTitle(mTitle); |
|
||||||
toolbar.setNavigationOnClickListener(view -> finish()); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
private void getData() { |
|
||||||
AccountManager.getInstance().getSearchBookList(mCategoryId, "", page); |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void getSearchList(SearchListEvent event) { |
|
||||||
refreshLayout.showFinish(); |
|
||||||
if (event.isFail()) { |
|
||||||
refreshLayout.showError(); |
|
||||||
} else { |
|
||||||
loadSize = event.getResult().getBook().size(); |
|
||||||
if (mAdapter.isLoadingMore()){ |
|
||||||
mList.remove(mList.size() - 1); |
|
||||||
mList.addAll(event.getResult().getBook()); |
|
||||||
mAdapter.notifyDataSetChanged(); |
|
||||||
mAdapter.setLoadingMore(false); |
|
||||||
}else { |
|
||||||
mList.clear(); |
|
||||||
mList.addAll(event.getResult().getBook()); |
|
||||||
mAdapter.notifyDataSetChanged(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onDestroy() { |
|
||||||
super.onDestroy(); |
|
||||||
EventManager.Companion.getInstance().unregisterSubscriber(this); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,93 @@ |
|||||||
|
package com.novel.read.activity |
||||||
|
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager |
||||||
|
import com.mango.mangolib.event.EventManager |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.adapter.BookListAdapter |
||||||
|
import com.novel.read.base.NovelBaseActivity |
||||||
|
import com.novel.read.constants.Constant |
||||||
|
import com.novel.read.constants.Constant.COMMENT_SIZE |
||||||
|
import com.novel.read.event.SearchListEvent |
||||||
|
import com.novel.read.http.AccountManager |
||||||
|
import com.novel.read.inter.OnLoadMoreListener |
||||||
|
import com.novel.read.model.protocol.SearchResp |
||||||
|
import com.squareup.otto.Subscribe |
||||||
|
import kotlinx.android.synthetic.main.activity_book_type_list.* |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
class NovelBookTypeListActivity : NovelBaseActivity() { |
||||||
|
|
||||||
|
private var mList: MutableList<SearchResp.BookBean> = ArrayList() |
||||||
|
private var mAdapter: BookListAdapter? = null |
||||||
|
private var mCategoryId: String? = null |
||||||
|
private var mTitle: String? = null |
||||||
|
private var page = 1 |
||||||
|
private var loadSize: Int = 0 |
||||||
|
|
||||||
|
override val layoutId: Int get() = R.layout.activity_book_type_list |
||||||
|
|
||||||
|
override fun initView() { |
||||||
|
EventManager.instance.registerSubscriber(this) |
||||||
|
|
||||||
|
mCategoryId = intent.getStringExtra(Constant.Bundle.CategoryId) |
||||||
|
mTitle = intent.getStringExtra(Constant.Bundle.mTitle) |
||||||
|
|
||||||
|
rlv_type_list.layoutManager = LinearLayoutManager(this) |
||||||
|
mAdapter = BookListAdapter(mList, rlv_type_list) |
||||||
|
rlv_type_list.adapter = mAdapter |
||||||
|
|
||||||
|
mAdapter!!.setOnLoadMoreListener(object : OnLoadMoreListener { |
||||||
|
override fun onLoadMore() { |
||||||
|
if (mAdapter!!.isLoadingMore) { |
||||||
|
|
||||||
|
} else { |
||||||
|
if (loadSize >= COMMENT_SIZE) { |
||||||
|
mAdapter!!.isLoadingMore = true |
||||||
|
mList.add(SearchResp.BookBean()) |
||||||
|
mAdapter!!.notifyDataSetChanged() |
||||||
|
page++ |
||||||
|
getData() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
override fun initData() { |
||||||
|
refresh.showLoading() |
||||||
|
refresh.setOnReloadingListener { this.getData() } |
||||||
|
getData() |
||||||
|
toolbar.title = mTitle |
||||||
|
toolbar.setNavigationOnClickListener { view -> finish() } |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private fun getData() { |
||||||
|
AccountManager.getInstance().getSearchBookList(mCategoryId, "", page) |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun getSearchList(event: SearchListEvent) { |
||||||
|
refresh.showFinish() |
||||||
|
if (event.isFail) { |
||||||
|
refresh.showError() |
||||||
|
} else { |
||||||
|
loadSize = event.result!!.book.size |
||||||
|
if (mAdapter!!.isLoadingMore) { |
||||||
|
mList.removeAt(mList.size - 1) |
||||||
|
mList.addAll(event.result!!.book) |
||||||
|
mAdapter!!.notifyDataSetChanged() |
||||||
|
mAdapter!!.isLoadingMore = false |
||||||
|
} else { |
||||||
|
mList.clear() |
||||||
|
mList.addAll(event.result!!.book) |
||||||
|
mAdapter!!.notifyDataSetChanged() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onDestroy() { |
||||||
|
super.onDestroy() |
||||||
|
EventManager.instance.unregisterSubscriber(this) |
||||||
|
} |
||||||
|
} |
@ -1,255 +0,0 @@ |
|||||||
package com.novel.read.activity; |
|
||||||
|
|
||||||
import android.annotation.SuppressLint; |
|
||||||
import android.content.ActivityNotFoundException; |
|
||||||
import android.content.Context; |
|
||||||
import android.content.Intent; |
|
||||||
import android.net.Uri; |
|
||||||
import android.os.Bundle; |
|
||||||
|
|
||||||
import android.text.TextUtils; |
|
||||||
import android.util.Log; |
|
||||||
import android.view.KeyEvent; |
|
||||||
import android.view.MenuItem; |
|
||||||
import android.view.View; |
|
||||||
import android.widget.FrameLayout; |
|
||||||
|
|
||||||
import androidx.annotation.NonNull; |
|
||||||
import androidx.fragment.app.Fragment; |
|
||||||
import androidx.fragment.app.FragmentTransaction; |
|
||||||
|
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView; |
|
||||||
import com.mango.mangolib.event.EventManager; |
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.base.NovelBaseActivity; |
|
||||||
import com.novel.read.constants.Constant; |
|
||||||
import com.novel.read.event.HideBottomBarEvent; |
|
||||||
import com.novel.read.event.LoginEvent; |
|
||||||
import com.novel.read.event.SwitchFragmentEvent; |
|
||||||
import com.novel.read.event.UpdateBookEvent; |
|
||||||
import com.novel.read.event.VersionEvent; |
|
||||||
import com.novel.read.fragment.BookFragment; |
|
||||||
import com.novel.read.fragment.MoreFragment; |
|
||||||
import com.novel.read.fragment.RecommendFragment; |
|
||||||
import com.novel.read.fragment.StackFragment; |
|
||||||
import com.novel.read.http.AccountManager; |
|
||||||
import com.novel.read.model.db.dbManage.BookRepository; |
|
||||||
import com.novel.read.utlis.DateUtli; |
|
||||||
import com.novel.read.utlis.SpUtil; |
|
||||||
import com.novel.read.utlis.ToastUtil; |
|
||||||
import com.novel.read.utlis.VersionUtil; |
|
||||||
import com.novel.read.widget.dialog.AppraiseDialog; |
|
||||||
import com.squareup.otto.Subscribe; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
|
|
||||||
public class NovelMainActivity extends NovelBaseActivity { |
|
||||||
|
|
||||||
@BindView(R.id.fl_content) |
|
||||||
FrameLayout flContent; |
|
||||||
|
|
||||||
BottomNavigationView bottomBar; |
|
||||||
|
|
||||||
private List<Fragment> mFragmentList; |
|
||||||
private Fragment mCurrentFrag; |
|
||||||
private BookFragment mMainFragment; |
|
||||||
private RecommendFragment mRecommendFragment; |
|
||||||
private StackFragment mStackFragment; |
|
||||||
private MoreFragment mMoreFragment; |
|
||||||
|
|
||||||
@SuppressLint("MissingSuperCall") |
|
||||||
@Override |
|
||||||
protected void onSaveInstanceState(Bundle outState) { |
|
||||||
super.onSaveInstanceState(outState); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onCreate(Bundle savedInstanceState) { |
|
||||||
super.onCreate(savedInstanceState); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected int getLayoutId() { |
|
||||||
return R.layout.activity_main; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initView() { |
|
||||||
bottomBar = findViewById(R.id.bottom_bar); |
|
||||||
mCurrentFrag = new Fragment(); |
|
||||||
mMainFragment = BookFragment.newInstance(); |
|
||||||
mRecommendFragment = RecommendFragment.newInstance(); |
|
||||||
mStackFragment = StackFragment.newInstance(); |
|
||||||
mMoreFragment = MoreFragment.newInstance(); |
|
||||||
|
|
||||||
//计算apk的启动次数
|
|
||||||
int count = SpUtil.getIntValue(Constant.InstallCount, 0); |
|
||||||
SpUtil.setIntValue(Constant.InstallCount, count + 1); |
|
||||||
Log.e("count", "count: " + count); |
|
||||||
AccountManager.getInstance().login(this); |
|
||||||
AccountManager.getInstance().checkVersion(VersionUtil.getPackageCode(this)); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initData() { |
|
||||||
bottomBar.setOnNavigationItemSelectedListener(menuItem -> { |
|
||||||
switch (menuItem.getItemId()) { |
|
||||||
case R.id.tab_one: |
|
||||||
switchFragment(mMainFragment); |
|
||||||
return true; |
|
||||||
case R.id.tab_two: |
|
||||||
switchFragment(mRecommendFragment); |
|
||||||
return true; |
|
||||||
case R.id.tab_three: |
|
||||||
switchFragment(mStackFragment); |
|
||||||
return true; |
|
||||||
case R.id.tab_four: |
|
||||||
switchFragment(mMoreFragment); |
|
||||||
return true; |
|
||||||
} |
|
||||||
return false; |
|
||||||
}); |
|
||||||
|
|
||||||
if (BookRepository.getInstance().getCollBooks().size() > 0) { |
|
||||||
switchFragment(mMainFragment); |
|
||||||
} else { |
|
||||||
bottomBar.setSelectedItemId(R.id.tab_two); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void switchFragment(Fragment targetFragment) { |
|
||||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); |
|
||||||
if (!targetFragment.isAdded()) { |
|
||||||
//第一次使用switchFragment()时currentFragment为null,所以要判断一下
|
|
||||||
if (mCurrentFrag != null) { |
|
||||||
transaction.hide(mCurrentFrag); |
|
||||||
|
|
||||||
} |
|
||||||
transaction.add(R.id.fl_content, targetFragment, targetFragment.getClass().getName()); |
|
||||||
} else { |
|
||||||
transaction.hide(mCurrentFrag).show(targetFragment); |
|
||||||
|
|
||||||
} |
|
||||||
mCurrentFrag = targetFragment; |
|
||||||
transaction.commit(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onResume() { |
|
||||||
super.onResume(); |
|
||||||
EventManager.Companion.getInstance().registerSubscriber(this); |
|
||||||
if (SpUtil.getLongValue(Constant.InstallTime) == 0) { |
|
||||||
SpUtil.setLongValue(Constant.InstallTime, System.currentTimeMillis()); |
|
||||||
} else { |
|
||||||
if (DateUtli.checkInstallTime()&&!SpUtil.getBooleanValue(Constant.AppraiseShow)) { |
|
||||||
SpUtil.setBooleanValue(Constant.AppraiseShow, true); |
|
||||||
final AppraiseDialog dialog = new AppraiseDialog(this); |
|
||||||
dialog.AppraiseDialog(view -> { |
|
||||||
goToMarket(this, VersionUtil.getPackage(this)); |
|
||||||
dialog.dismiss(); |
|
||||||
}); |
|
||||||
dialog.show(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onPause() { |
|
||||||
super.onPause(); |
|
||||||
EventManager.Companion.getInstance().unregisterSubscriber(this); |
|
||||||
} |
|
||||||
|
|
||||||
public static void goToMarket(Context context, String packageName) { |
|
||||||
Uri uri = Uri.parse("market://details?id=" + packageName); |
|
||||||
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); |
|
||||||
final String GOOGLE_PLAY = "com.android.vending";//这里对应的是谷歌商店,跳转别的商店改成对应的即可
|
|
||||||
|
|
||||||
goToMarket.setPackage(GOOGLE_PLAY);//这里对应的是谷歌商店,跳转别的商店改成对应的即可
|
|
||||||
|
|
||||||
try { |
|
||||||
context.startActivity(goToMarket); |
|
||||||
} catch (ActivityNotFoundException e) { |
|
||||||
if (goToMarket.resolveActivity(context.getPackageManager()) != null) { //有浏览器
|
|
||||||
context.startActivity(goToMarket); |
|
||||||
}else { |
|
||||||
ToastUtil.show(context,"未检测到Google应用商店"); |
|
||||||
} |
|
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void checkVersion(VersionEvent event) { |
|
||||||
if (event.isFail()) { |
|
||||||
|
|
||||||
} else { |
|
||||||
if (TextUtils.isEmpty(event.getResult().getVersion().getSize())) { |
|
||||||
return; |
|
||||||
} |
|
||||||
//版本大小不为空 去更新。
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void login(LoginEvent event) { |
|
||||||
if (event.isFail()) { |
|
||||||
Log.e("NovelMainActivity", "login: " + event.getEr().getMsg()); |
|
||||||
} else { |
|
||||||
SpUtil.setStringValue(Constant.Uid, String.valueOf(event.getResult().getUid())); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//记录用户首次点击返回键的时间
|
|
||||||
private long firstTime = 0; |
|
||||||
|
|
||||||
@Override |
|
||||||
public boolean onKeyUp(int keyCode, KeyEvent event) { |
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { |
|
||||||
if (!isVisible(bottomBar)) { |
|
||||||
bottomBar.setVisibility(View.VISIBLE); |
|
||||||
mMainFragment.updateBook(new UpdateBookEvent()); |
|
||||||
} else { |
|
||||||
long secondTime = System.currentTimeMillis(); |
|
||||||
if (secondTime - firstTime > 1000) { |
|
||||||
firstTime = secondTime; |
|
||||||
ToastUtil.show(NovelMainActivity.this, "再次点击退出界面"); |
|
||||||
} else { |
|
||||||
finish(); |
|
||||||
} |
|
||||||
} |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
return super.onKeyUp(keyCode, event); |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void setBottomBar(HideBottomBarEvent event) { |
|
||||||
if (event.getResult()) { |
|
||||||
bottomBar.setVisibility(View.GONE); |
|
||||||
} else { |
|
||||||
bottomBar.setVisibility(View.VISIBLE); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onDestroy() { |
|
||||||
super.onDestroy(); |
|
||||||
} |
|
||||||
|
|
||||||
public static void reStart(Context context) { |
|
||||||
Intent intent = new Intent(context, NovelMainActivity.class); |
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); |
|
||||||
context.startActivity(intent); |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void toRecommendFragment(SwitchFragmentEvent event) { |
|
||||||
// switchFragment(mRecommendFragment);
|
|
||||||
bottomBar.setSelectedItemId(R.id.tab_two); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,164 @@ |
|||||||
|
package com.novel.read.activity |
||||||
|
|
||||||
|
import android.annotation.SuppressLint |
||||||
|
import android.content.ActivityNotFoundException |
||||||
|
import android.content.Context |
||||||
|
import android.content.Intent |
||||||
|
import android.net.Uri |
||||||
|
import android.os.Bundle |
||||||
|
import android.text.TextUtils |
||||||
|
import android.util.Log |
||||||
|
import android.view.KeyEvent |
||||||
|
import android.view.View |
||||||
|
import androidx.fragment.app.Fragment |
||||||
|
import com.mango.mangolib.event.EventManager |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.base.NovelBaseActivity |
||||||
|
import com.novel.read.constants.Constant |
||||||
|
import com.novel.read.event.* |
||||||
|
import com.novel.read.fragment.BookFragment |
||||||
|
import com.novel.read.fragment.MoreFragment |
||||||
|
import com.novel.read.fragment.RecommendFragment |
||||||
|
import com.novel.read.fragment.StackFragment |
||||||
|
import com.novel.read.http.AccountManager |
||||||
|
import com.novel.read.model.db.dbManage.BookRepository |
||||||
|
import com.novel.read.utlis.DateUtli |
||||||
|
import com.novel.read.utlis.SpUtil |
||||||
|
import com.novel.read.utlis.ToastUtil |
||||||
|
import com.novel.read.utlis.VersionUtil |
||||||
|
import com.novel.read.widget.dialog.AppraiseDialog |
||||||
|
import com.squareup.otto.Subscribe |
||||||
|
import kotlinx.android.synthetic.main.activity_main.* |
||||||
|
|
||||||
|
class NovelMainActivity : NovelBaseActivity() { |
||||||
|
|
||||||
|
private var mCurrentFrag: Fragment? = null |
||||||
|
private var mMainFragment: BookFragment? = null |
||||||
|
private var mRecommendFragment: RecommendFragment? = null |
||||||
|
private var mStackFragment: StackFragment? = null |
||||||
|
private var mMoreFragment: MoreFragment? = null |
||||||
|
|
||||||
|
//记录用户首次点击返回键的时间 |
||||||
|
private var firstTime: Long = 0 |
||||||
|
|
||||||
|
@SuppressLint("MissingSuperCall") |
||||||
|
override fun onSaveInstanceState(outState: Bundle) { |
||||||
|
super.onSaveInstanceState(outState) |
||||||
|
} |
||||||
|
|
||||||
|
override val layoutId: Int get() = R.layout.activity_main |
||||||
|
|
||||||
|
override fun initView() { |
||||||
|
mCurrentFrag = Fragment() |
||||||
|
mMainFragment = BookFragment.newInstance() |
||||||
|
mRecommendFragment = RecommendFragment.newInstance() |
||||||
|
mStackFragment = StackFragment.newInstance() |
||||||
|
mMoreFragment = MoreFragment.newInstance() |
||||||
|
AccountManager.getInstance().login(this) |
||||||
|
} |
||||||
|
|
||||||
|
override fun initData() { |
||||||
|
bottom_bar.setOnNavigationItemSelectedListener { menuItem -> |
||||||
|
when (menuItem.itemId) { |
||||||
|
R.id.tab_one -> { |
||||||
|
switchFragment(mMainFragment!!) |
||||||
|
return@setOnNavigationItemSelectedListener true |
||||||
|
} |
||||||
|
R.id.tab_two -> { |
||||||
|
switchFragment(mRecommendFragment!!) |
||||||
|
return@setOnNavigationItemSelectedListener true |
||||||
|
} |
||||||
|
R.id.tab_three -> { |
||||||
|
switchFragment(mStackFragment!!) |
||||||
|
return@setOnNavigationItemSelectedListener true |
||||||
|
} |
||||||
|
R.id.tab_four -> { |
||||||
|
switchFragment(mMoreFragment!!) |
||||||
|
return@setOnNavigationItemSelectedListener true |
||||||
|
} |
||||||
|
} |
||||||
|
false |
||||||
|
} |
||||||
|
|
||||||
|
if (BookRepository.getInstance().collBooks.size > 0) { |
||||||
|
switchFragment(mMainFragment!!) |
||||||
|
} else { |
||||||
|
bottom_bar.selectedItemId = R.id.tab_two |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private fun switchFragment(targetFragment: Fragment) { |
||||||
|
val transaction = supportFragmentManager.beginTransaction() |
||||||
|
if (!targetFragment.isAdded) { |
||||||
|
//第一次使用switchFragment()时currentFragment为null,所以要判断一下 |
||||||
|
if (mCurrentFrag != null) { |
||||||
|
transaction.hide(mCurrentFrag!!) |
||||||
|
} |
||||||
|
transaction.add(R.id.fl_content, targetFragment, targetFragment.javaClass.name) |
||||||
|
} else { |
||||||
|
transaction.hide(mCurrentFrag!!).show(targetFragment) |
||||||
|
} |
||||||
|
mCurrentFrag = targetFragment |
||||||
|
transaction.commit() |
||||||
|
} |
||||||
|
|
||||||
|
override fun onResume() { |
||||||
|
super.onResume() |
||||||
|
EventManager.instance.registerSubscriber(this) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onPause() { |
||||||
|
super.onPause() |
||||||
|
EventManager.instance.unregisterSubscriber(this) |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun login(event: LoginEvent) { |
||||||
|
if (event.isFail) { |
||||||
|
Log.e("NovelMainActivity", "login: " + event.er!!.msg) |
||||||
|
} else { |
||||||
|
SpUtil.setStringValue(Constant.Uid, event.result!!.uid.toString()) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean { |
||||||
|
if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) { |
||||||
|
if (!isVisible(bottom_bar)) { |
||||||
|
bottom_bar.visibility = View.VISIBLE |
||||||
|
mMainFragment!!.updateBook(UpdateBookEvent()) |
||||||
|
} else { |
||||||
|
val secondTime = System.currentTimeMillis() |
||||||
|
if (secondTime - firstTime > 1000) { |
||||||
|
firstTime = secondTime |
||||||
|
ToastUtil.show(this@NovelMainActivity, "再次点击退出界面") |
||||||
|
} else { |
||||||
|
finish() |
||||||
|
} |
||||||
|
} |
||||||
|
return true |
||||||
|
} |
||||||
|
return super.onKeyUp(keyCode, event) |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun setBottomBar(event: HideBottomBarEvent) { |
||||||
|
if (event.result!!) { |
||||||
|
bottom_bar.visibility = View.GONE |
||||||
|
} else { |
||||||
|
bottom_bar.visibility = View.VISIBLE |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun toRecommendFragment(event: SwitchFragmentEvent) { |
||||||
|
bottom_bar.selectedItemId = R.id.tab_two |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
fun reStart(context: Context) { |
||||||
|
val intent = Intent(context, NovelMainActivity::class.java) |
||||||
|
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK |
||||||
|
context.startActivity(intent) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,131 +0,0 @@ |
|||||||
package com.novel.read.activity; |
|
||||||
|
|
||||||
import android.os.Bundle; |
|
||||||
import android.view.View; |
|
||||||
|
|
||||||
import androidx.annotation.NonNull; |
|
||||||
import androidx.appcompat.widget.Toolbar; |
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager; |
|
||||||
import androidx.recyclerview.widget.RecyclerView; |
|
||||||
|
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.adapter.RankListAdapter; |
|
||||||
import com.novel.read.base.NovelBaseActivity; |
|
||||||
import com.novel.read.constants.Constant; |
|
||||||
import com.novel.read.http.AccountManager; |
|
||||||
import com.novel.read.model.protocol.RankByUpadateResp; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
import retrofit2.Call; |
|
||||||
import retrofit2.Callback; |
|
||||||
import retrofit2.Response; |
|
||||||
|
|
||||||
import static com.novel.read.constants.Constant.COMMENT_SIZE; |
|
||||||
|
|
||||||
/** |
|
||||||
* 推荐fragment中点击更多跳转来的。 |
|
||||||
*/ |
|
||||||
public class NovelRankListActivity extends NovelBaseActivity { |
|
||||||
|
|
||||||
@BindView(R.id.toolbar) |
|
||||||
Toolbar toolbar; |
|
||||||
@BindView(R.id.rlv_book_list) |
|
||||||
RecyclerView mRlvBookList; |
|
||||||
private RankListAdapter mAdapter; |
|
||||||
private List<RankByUpadateResp.BookBean> mList; |
|
||||||
private int page = 1; |
|
||||||
private int loadSize; |
|
||||||
private String type; |
|
||||||
private String sex; |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onCreate(Bundle savedInstanceState) { |
|
||||||
super.onCreate(savedInstanceState); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected int getLayoutId() { |
|
||||||
return R.layout.activity_rank_list; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initView() { |
|
||||||
mList = new ArrayList<>(); |
|
||||||
|
|
||||||
mRlvBookList.setLayoutManager(new LinearLayoutManager(this)); |
|
||||||
mAdapter = new RankListAdapter(mList, mRlvBookList); |
|
||||||
mRlvBookList.setAdapter(mAdapter); |
|
||||||
sex = getIntent().getStringExtra(Constant.Sex); |
|
||||||
type = getIntent().getStringExtra(Constant.Type); |
|
||||||
switch (type) { |
|
||||||
case Constant.ListType.Human: |
|
||||||
toolbar.setTitle(getString(R.string.popular_selection)); |
|
||||||
break; |
|
||||||
case Constant.ListType.EditRecommend: |
|
||||||
toolbar.setTitle(getString(R.string.edit_recommend)); |
|
||||||
break; |
|
||||||
case Constant.ListType.HotSearch: |
|
||||||
toolbar.setTitle(getString(R.string.hot_search)); |
|
||||||
break; |
|
||||||
} |
|
||||||
getData(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initData() { |
|
||||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() { |
|
||||||
@Override |
|
||||||
public void onClick(View view) { |
|
||||||
finish(); |
|
||||||
} |
|
||||||
}); |
|
||||||
mAdapter.setOnLoadMoreListener(() -> { |
|
||||||
if (mAdapter.isLoadingMore()) { |
|
||||||
|
|
||||||
} else { |
|
||||||
if (loadSize >= COMMENT_SIZE) { |
|
||||||
mAdapter.setLoadingMore(true); |
|
||||||
mList.add(null); |
|
||||||
mAdapter.notifyDataSetChanged(); |
|
||||||
page++; |
|
||||||
getData(); |
|
||||||
} |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
private void getData() { |
|
||||||
AccountManager.getInstance().getRankList(type, sex, Constant.DateTyp.Week, String.valueOf(page), new RankCallBack()); |
|
||||||
} |
|
||||||
|
|
||||||
private class RankCallBack implements Callback<RankByUpadateResp> { |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onResponse(@NonNull Call<RankByUpadateResp> call, @NonNull Response<RankByUpadateResp> response) { |
|
||||||
if (response.isSuccessful()) { |
|
||||||
if (response.body() != null) { |
|
||||||
loadSize = response.body().getBook().size(); |
|
||||||
if (mAdapter.isLoadingMore()) { |
|
||||||
mList.remove(mList.size() - 1); |
|
||||||
mList.addAll(response.body().getBook()); |
|
||||||
mAdapter.notifyDataSetChanged(); |
|
||||||
mAdapter.setLoadingMore(false); |
|
||||||
} else { |
|
||||||
mList.clear(); |
|
||||||
mList.addAll(response.body().getBook()); |
|
||||||
mAdapter.notifyDataSetChanged(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onFailure(@NonNull Call<RankByUpadateResp> call, @NonNull Throwable t) { |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,95 @@ |
|||||||
|
package com.novel.read.activity |
||||||
|
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.adapter.RankListAdapter |
||||||
|
import com.novel.read.base.NovelBaseActivity |
||||||
|
import com.novel.read.constants.Constant |
||||||
|
import com.novel.read.constants.Constant.COMMENT_SIZE |
||||||
|
import com.novel.read.http.AccountManager |
||||||
|
import com.novel.read.inter.OnLoadMoreListener |
||||||
|
import com.novel.read.model.protocol.RankByUpadateResp |
||||||
|
import kotlinx.android.synthetic.main.activity_rank_list.* |
||||||
|
import retrofit2.Call |
||||||
|
import retrofit2.Callback |
||||||
|
import retrofit2.Response |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
/** |
||||||
|
* 推荐fragment中点击更多跳转来的。 |
||||||
|
*/ |
||||||
|
class NovelRankListActivity : NovelBaseActivity() { |
||||||
|
|
||||||
|
private var mAdapter: RankListAdapter? = null |
||||||
|
private var mList: MutableList<RankByUpadateResp.BookBean> = ArrayList() |
||||||
|
private var page = 1 |
||||||
|
private var loadSize: Int = 0 |
||||||
|
private var type: String? = null |
||||||
|
private var sex: String? = null |
||||||
|
|
||||||
|
override val layoutId: Int get() = R.layout.activity_rank_list |
||||||
|
|
||||||
|
override fun initView() { |
||||||
|
rlv_book_list.layoutManager = LinearLayoutManager(this) |
||||||
|
mAdapter = RankListAdapter(mList, rlv_book_list) |
||||||
|
rlv_book_list.adapter = mAdapter |
||||||
|
sex = intent.getStringExtra(Constant.Sex) |
||||||
|
type = intent.getStringExtra(Constant.Type) |
||||||
|
when (type) { |
||||||
|
Constant.ListType.Human -> toolbar.title = getString(R.string.popular_selection) |
||||||
|
Constant.ListType.EditRecommend -> toolbar.title = getString(R.string.edit_recommend) |
||||||
|
Constant.ListType.HotSearch -> toolbar.title = getString(R.string.hot_search) |
||||||
|
} |
||||||
|
getData() |
||||||
|
} |
||||||
|
|
||||||
|
override fun initData() { |
||||||
|
toolbar.setNavigationOnClickListener { finish() } |
||||||
|
|
||||||
|
mAdapter!!.setOnLoadMoreListener(object : OnLoadMoreListener { |
||||||
|
override fun onLoadMore() { |
||||||
|
if (mAdapter!!.isLoadingMore) { |
||||||
|
|
||||||
|
} else { |
||||||
|
if (loadSize >= COMMENT_SIZE) { |
||||||
|
mAdapter!!.isLoadingMore = true |
||||||
|
mList.add(RankByUpadateResp.BookBean()) |
||||||
|
mAdapter!!.notifyDataSetChanged() |
||||||
|
page++ |
||||||
|
getData() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
private fun getData() { |
||||||
|
AccountManager.getInstance().getRankList(type, sex, Constant.DateTyp.Week, page.toString(), RankCallBack()) |
||||||
|
} |
||||||
|
|
||||||
|
private inner class RankCallBack : Callback<RankByUpadateResp> { |
||||||
|
|
||||||
|
override fun onResponse(call: Call<RankByUpadateResp>, response: Response<RankByUpadateResp>) { |
||||||
|
if (response.isSuccessful) { |
||||||
|
if (response.body() != null) { |
||||||
|
loadSize = response.body()!!.book.size |
||||||
|
if (mAdapter!!.isLoadingMore) { |
||||||
|
mList.removeAt(mList.size - 1) |
||||||
|
mList.addAll(response.body()!!.book) |
||||||
|
mAdapter!!.notifyDataSetChanged() |
||||||
|
mAdapter!!.isLoadingMore = false |
||||||
|
} else { |
||||||
|
mList.clear() |
||||||
|
mList.addAll(response.body()!!.book) |
||||||
|
mAdapter!!.notifyDataSetChanged() |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onFailure(call: Call<RankByUpadateResp>, t: Throwable) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,813 +0,0 @@ |
|||||||
package com.novel.read.activity; |
|
||||||
|
|
||||||
import android.annotation.SuppressLint; |
|
||||||
import android.app.Activity; |
|
||||||
import android.app.Service; |
|
||||||
import android.content.BroadcastReceiver; |
|
||||||
import android.content.ComponentName; |
|
||||||
import android.content.Context; |
|
||||||
import android.content.Intent; |
|
||||||
import android.content.IntentFilter; |
|
||||||
import android.content.ServiceConnection; |
|
||||||
import android.graphics.drawable.Drawable; |
|
||||||
import android.os.Build; |
|
||||||
import android.os.Bundle; |
|
||||||
import android.os.Handler; |
|
||||||
import android.os.IBinder; |
|
||||||
import android.os.Message; |
|
||||||
import android.util.Log; |
|
||||||
import android.view.Gravity; |
|
||||||
import android.view.KeyEvent; |
|
||||||
import android.view.View; |
|
||||||
import android.view.WindowManager; |
|
||||||
import android.view.animation.Animation; |
|
||||||
import android.view.animation.AnimationUtils; |
|
||||||
import android.widget.FrameLayout; |
|
||||||
import android.widget.ImageView; |
|
||||||
import android.widget.LinearLayout; |
|
||||||
import android.widget.ListView; |
|
||||||
import android.widget.SeekBar; |
|
||||||
import android.widget.TextView; |
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog; |
|
||||||
import androidx.appcompat.widget.LinearLayoutCompat; |
|
||||||
import androidx.appcompat.widget.Toolbar; |
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout; |
|
||||||
import androidx.core.content.ContextCompat; |
|
||||||
import androidx.core.view.GravityCompat; |
|
||||||
import androidx.core.widget.ContentLoadingProgressBar; |
|
||||||
import androidx.drawerlayout.widget.DrawerLayout; |
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager; |
|
||||||
import androidx.recyclerview.widget.RecyclerView; |
|
||||||
|
|
||||||
import com.common_lib.base.utils.ToastUtils; |
|
||||||
import com.google.android.material.appbar.AppBarLayout; |
|
||||||
import com.mango.mangolib.event.EventManager; |
|
||||||
import com.novel.read.BuildConfig; |
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.adapter.CategoryAdapter; |
|
||||||
import com.novel.read.adapter.MarkAdapter; |
|
||||||
import com.novel.read.base.MyApp; |
|
||||||
import com.novel.read.base.NovelBaseActivity; |
|
||||||
import com.novel.read.constants.Constant; |
|
||||||
import com.novel.read.event.AddBookSignEvent; |
|
||||||
import com.novel.read.event.BookArticleEvent; |
|
||||||
import com.novel.read.event.DeleteBookSignEvent; |
|
||||||
import com.novel.read.event.ErrorChapterEvent; |
|
||||||
import com.novel.read.event.FinishChapterEvent; |
|
||||||
import com.novel.read.event.GetBookSignEvent; |
|
||||||
import com.novel.read.event.RxBus; |
|
||||||
import com.novel.read.event.SetAdsBgEvent; |
|
||||||
import com.novel.read.http.AccountManager; |
|
||||||
import com.novel.read.model.db.BookChapterBean; |
|
||||||
import com.novel.read.model.db.CollBookBean; |
|
||||||
import com.novel.read.model.db.DownloadTaskBean; |
|
||||||
import com.novel.read.model.db.dbManage.BookRepository; |
|
||||||
import com.novel.read.model.protocol.MarkResp; |
|
||||||
import com.novel.read.service.DownloadMessage; |
|
||||||
import com.novel.read.service.DownloadService; |
|
||||||
import com.novel.read.utlis.BrightnessUtils; |
|
||||||
import com.novel.read.utlis.ScreenUtils; |
|
||||||
import com.novel.read.utlis.SpUtil; |
|
||||||
import com.novel.read.utlis.SystemBarUtils; |
|
||||||
import com.novel.read.widget.dialog.ReadSettingDialog; |
|
||||||
import com.novel.read.widget.page.PageLoader; |
|
||||||
import com.novel.read.widget.page.PageView; |
|
||||||
import com.novel.read.widget.page.ReadSettingManager; |
|
||||||
import com.novel.read.widget.page.TxtChapter; |
|
||||||
import com.squareup.otto.Subscribe; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
import java.util.Objects; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
|
|
||||||
import static android.view.View.GONE; |
|
||||||
import static android.view.View.LAYER_TYPE_SOFTWARE; |
|
||||||
import static android.view.View.VISIBLE; |
|
||||||
import static com.novel.read.constants.Constant.ResultCode.RESULT_IS_COLLECTED; |
|
||||||
|
|
||||||
public class NovelReadActivity extends NovelBaseActivity implements DownloadService.OnDownloadListener { |
|
||||||
|
|
||||||
@BindView(R.id.read_pv_page) |
|
||||||
PageView mPvPage; |
|
||||||
@BindView(R.id.read_abl_top_menu) |
|
||||||
AppBarLayout mAblTopMenu; |
|
||||||
@BindView(R.id.toolbar) |
|
||||||
Toolbar toolbar; |
|
||||||
@BindView(R.id.read_ll_bottom_menu) |
|
||||||
LinearLayoutCompat mLlBottomMenu; |
|
||||||
|
|
||||||
@BindView(R.id.read_dl_slide) |
|
||||||
DrawerLayout mDlSlide; |
|
||||||
@BindView(R.id.read_tv_category) |
|
||||||
TextView mTvCategory; |
|
||||||
@BindView(R.id.tv_light) |
|
||||||
TextView mTvLight; |
|
||||||
@BindView(R.id.read_setting_sb_brightness) |
|
||||||
SeekBar mSbBrightness; |
|
||||||
@BindView(R.id.tvBookReadMode) |
|
||||||
TextView mTvNightMode; |
|
||||||
@BindView(R.id.ll_light) |
|
||||||
LinearLayoutCompat mLLight; |
|
||||||
@BindView(R.id.tv_cache) |
|
||||||
TextView mTvCache; |
|
||||||
@BindView(R.id.tv_setting) |
|
||||||
TextView mTvSetting; |
|
||||||
@BindView(R.id.rlv_list) |
|
||||||
ListView mLvCategory; |
|
||||||
@BindView(R.id.tv_book_name) |
|
||||||
TextView mTvBookName; |
|
||||||
@BindView(R.id.read_tv_brief) |
|
||||||
TextView mTvBrief; |
|
||||||
@BindView(R.id.read_tv_community) |
|
||||||
TextView mTvMark; |
|
||||||
@BindView(R.id.rlReadMark) |
|
||||||
ConstraintLayout rlReadMark; |
|
||||||
@BindView(R.id.tvAddMark) |
|
||||||
TextView mTvAddMark; |
|
||||||
@BindView(R.id.tvClear) |
|
||||||
TextView mTvClear; |
|
||||||
@BindView(R.id.rlv_mark) |
|
||||||
RecyclerView mRlvMark; |
|
||||||
@BindView(R.id.ll_download) |
|
||||||
LinearLayoutCompat mLlDownLoad; |
|
||||||
@BindView(R.id.pb_loading) |
|
||||||
ContentLoadingProgressBar loadingProgressBar; |
|
||||||
@BindView(R.id.tv_progress) |
|
||||||
TextView mTvProgress; |
|
||||||
@BindView(R.id.cl_layout) |
|
||||||
ConstraintLayout mClLayout; |
|
||||||
@BindView(R.id.iv_guide) |
|
||||||
ImageView mIvGuide; |
|
||||||
private CategoryAdapter mCategoryAdapter; |
|
||||||
private List<TxtChapter> mChapters = new ArrayList<>(); |
|
||||||
private TxtChapter mCurrentChapter; //当前章节
|
|
||||||
private int currentChapter = 0; |
|
||||||
private MarkAdapter mMarkAdapter; |
|
||||||
private List<MarkResp.SignBean> mMarks = new ArrayList<>(); |
|
||||||
private PageLoader mPageLoader; |
|
||||||
private Animation mTopInAnim; |
|
||||||
private Animation mTopOutAnim; |
|
||||||
private Animation mBottomInAnim; |
|
||||||
private Animation mBottomOutAnim; |
|
||||||
|
|
||||||
private ReadSettingDialog mSettingDialog; |
|
||||||
private boolean isCollected = false; // isFromSDCard
|
|
||||||
private boolean isNightMode = false; |
|
||||||
private boolean isFullScreen = false; |
|
||||||
private boolean isRegistered = false; |
|
||||||
|
|
||||||
private CollBookBean mCollBook; |
|
||||||
private String mBookId; |
|
||||||
|
|
||||||
private static final String TAG = "NovelReadActivity"; |
|
||||||
public static final String EXTRA_COLL_BOOK = "extra_coll_book"; |
|
||||||
public static final String EXTRA_IS_COLLECTED = "extra_is_collected"; |
|
||||||
private static final int WHAT_CATEGORY = 1; |
|
||||||
private static final int WHAT_CHAPTER = 2; |
|
||||||
|
|
||||||
@SuppressLint("HandlerLeak") |
|
||||||
private Handler mHandler = new Handler() { |
|
||||||
@Override |
|
||||||
public void handleMessage(Message msg) { |
|
||||||
super.handleMessage(msg); |
|
||||||
switch (msg.what) { |
|
||||||
case WHAT_CATEGORY: |
|
||||||
mLvCategory.setSelection(mPageLoader.getChapterPos()); |
|
||||||
break; |
|
||||||
case WHAT_CHAPTER: |
|
||||||
mPageLoader.openChapter(); |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onCreate(Bundle savedInstanceState) { |
|
||||||
super.onCreate(savedInstanceState); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected int getLayoutId() { |
|
||||||
return R.layout.activity_read; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initView() { |
|
||||||
EventManager.Companion.getInstance().registerSubscriber(this); |
|
||||||
mCollBook = (CollBookBean) getIntent().getSerializableExtra(EXTRA_COLL_BOOK); |
|
||||||
isCollected = getIntent().getBooleanExtra(EXTRA_IS_COLLECTED, false); |
|
||||||
mBookId = mCollBook.getId(); |
|
||||||
initService(); |
|
||||||
// 如果 API < 18 取消硬件加速
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { |
|
||||||
mPvPage.setLayerType(LAYER_TYPE_SOFTWARE, null); |
|
||||||
} |
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
|
||||||
|
|
||||||
//获取页面加载器
|
|
||||||
mPageLoader = mPvPage.getPageLoader(mCollBook); |
|
||||||
|
|
||||||
mSettingDialog = new ReadSettingDialog(this, mPageLoader); |
|
||||||
//禁止滑动展示DrawerLayout
|
|
||||||
mDlSlide.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); |
|
||||||
//侧边打开后,返回键能够起作用
|
|
||||||
mDlSlide.setFocusableInTouchMode(false); |
|
||||||
//半透明化StatusBar
|
|
||||||
SystemBarUtils.transparentStatusBar(this); |
|
||||||
//隐藏StatusBar
|
|
||||||
mPvPage.post( |
|
||||||
this::hideSystemBar |
|
||||||
); |
|
||||||
mAblTopMenu.setPadding(0, ScreenUtils.getStatusBarHeight(), 0, 0); |
|
||||||
mLlDownLoad.setPadding(0, ScreenUtils.getStatusBarHeight(), 0, ScreenUtils.dpToPx(15)); |
|
||||||
|
|
||||||
WindowManager.LayoutParams lp = getWindow().getAttributes(); |
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { |
|
||||||
lp.layoutInDisplayCutoutMode = 1; |
|
||||||
} |
|
||||||
getWindow().setAttributes(lp); |
|
||||||
|
|
||||||
//设置当前Activity的Brightness
|
|
||||||
if (ReadSettingManager.getInstance().isBrightnessAuto()) { |
|
||||||
BrightnessUtils.setDefaultBrightness(this); |
|
||||||
} else { |
|
||||||
BrightnessUtils.setBrightness(this, ReadSettingManager.getInstance().getBrightness()); |
|
||||||
} |
|
||||||
|
|
||||||
//注册广播
|
|
||||||
IntentFilter intentFilter = new IntentFilter(); |
|
||||||
intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); |
|
||||||
intentFilter.addAction(Intent.ACTION_TIME_TICK); |
|
||||||
registerReceiver(mReceiver, intentFilter); |
|
||||||
|
|
||||||
if (!SpUtil.getBooleanValue(Constant.BookGuide,false)){ |
|
||||||
mIvGuide.setVisibility(VISIBLE); |
|
||||||
toggleMenu(false); |
|
||||||
} |
|
||||||
|
|
||||||
Log.e(TAG, "mBookId: " + mBookId); |
|
||||||
if (isCollected) { |
|
||||||
mPageLoader.getCollBook().setBookChapters(BookRepository.getInstance().getBookChaptersInRx(mBookId)); |
|
||||||
// 刷新章节列表
|
|
||||||
mPageLoader.refreshChapterList(); |
|
||||||
// 如果是网络小说并被标记更新的,则从网络下载目录
|
|
||||||
if (mCollBook.isUpdate() && !mCollBook.isLocal()) { |
|
||||||
AccountManager.getInstance().getBookArticle(mBookId, "2", "1", "10000"); |
|
||||||
} |
|
||||||
} else { |
|
||||||
AccountManager.getInstance().getBookArticle(mBookId, "2", "1", "10000"); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setAdsBg(new SetAdsBgEvent()); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initData() { |
|
||||||
mTvBookName.setText(mCollBook.getTitle()); |
|
||||||
mCategoryAdapter = new CategoryAdapter(); |
|
||||||
mLvCategory.setAdapter(mCategoryAdapter); |
|
||||||
mLvCategory.setFastScrollEnabled(true); |
|
||||||
mRlvMark.setLayoutManager(new LinearLayoutManager(this)); |
|
||||||
mMarkAdapter = new MarkAdapter(mMarks); |
|
||||||
mRlvMark.setAdapter(mMarkAdapter); |
|
||||||
isNightMode = ReadSettingManager.getInstance().isNightMode(); |
|
||||||
//夜间模式按钮的状态
|
|
||||||
toggleNightMode(); |
|
||||||
isFullScreen = ReadSettingManager.getInstance().isFullScreen(); |
|
||||||
toolbar.setNavigationOnClickListener(view -> finish()); |
|
||||||
mSbBrightness.setProgress(ReadSettingManager.getInstance().getBrightness()); |
|
||||||
mPageLoader.setOnPageChangeListener( |
|
||||||
new PageLoader.OnPageChangeListener() { |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onChapterChange(int pos) { |
|
||||||
mCategoryAdapter.setChapter(pos); |
|
||||||
mCurrentChapter = mChapters.get(pos); |
|
||||||
currentChapter = pos; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void requestChapters(List<TxtChapter> requestChapters) { |
|
||||||
AccountManager.getInstance().getBookArticleDetail(mBookId, requestChapters); |
|
||||||
mHandler.sendEmptyMessage(WHAT_CATEGORY); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onCategoryFinish(List<TxtChapter> chapters) { |
|
||||||
mChapters.clear(); |
|
||||||
mChapters.addAll(chapters); |
|
||||||
mCategoryAdapter.refreshItems(mChapters); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onPageCountChange(int count) { |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onPageChange(int pos) { |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
); |
|
||||||
mPvPage.setTouchListener(new PageView.TouchListener() { |
|
||||||
@Override |
|
||||||
public boolean onTouch() { |
|
||||||
return !hideReadMenu(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void center() { |
|
||||||
toggleMenu(true); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void prePage() { |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void nextPage() { |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void cancel() { |
|
||||||
} |
|
||||||
}); |
|
||||||
mTvCategory.setOnClickListener( |
|
||||||
(v) -> { |
|
||||||
//移动到指定位置
|
|
||||||
if (mCategoryAdapter.getCount() > 0) { |
|
||||||
mLvCategory.setSelection(mPageLoader.getChapterPos()); |
|
||||||
} |
|
||||||
//切换菜单
|
|
||||||
toggleMenu(true); |
|
||||||
//打开侧滑动栏
|
|
||||||
mDlSlide.openDrawer(GravityCompat.START); |
|
||||||
} |
|
||||||
); |
|
||||||
mTvLight.setOnClickListener(view -> { |
|
||||||
mLLight.setVisibility(GONE); |
|
||||||
rlReadMark.setVisibility(GONE); |
|
||||||
if (isVisible(mLLight)) { |
|
||||||
mLLight.setVisibility(GONE); |
|
||||||
} else { |
|
||||||
mLLight.setVisibility(VISIBLE); |
|
||||||
} |
|
||||||
}); |
|
||||||
mTvSetting.setOnClickListener(view -> { |
|
||||||
mLLight.setVisibility(GONE); |
|
||||||
rlReadMark.setVisibility(GONE); |
|
||||||
toggleMenu(false); |
|
||||||
mSettingDialog.show(); |
|
||||||
}); |
|
||||||
|
|
||||||
mSbBrightness.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { |
|
||||||
@Override |
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onStartTrackingTouch(SeekBar seekBar) { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onStopTrackingTouch(SeekBar seekBar) { |
|
||||||
int progress = seekBar.getProgress(); |
|
||||||
//设置当前 Activity 的亮度
|
|
||||||
BrightnessUtils.setBrightness(NovelReadActivity.this, progress); |
|
||||||
//存储亮度的进度条
|
|
||||||
ReadSettingManager.getInstance().setBrightness(progress); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
mTvNightMode.setOnClickListener( |
|
||||||
(v) -> { |
|
||||||
isNightMode = !isNightMode; |
|
||||||
mPageLoader.setNightMode(isNightMode); |
|
||||||
toggleNightMode(); |
|
||||||
} |
|
||||||
); |
|
||||||
|
|
||||||
mTvBrief.setOnClickListener(view -> { |
|
||||||
Intent intent = new Intent(this, NovelBookDetailActivity.class); |
|
||||||
intent.putExtra(Constant.Bundle.BookId, Integer.valueOf(mBookId)); |
|
||||||
startActivity(intent); |
|
||||||
}); |
|
||||||
|
|
||||||
mTvMark.setOnClickListener(view -> { |
|
||||||
if (isVisible(mLlBottomMenu)) { |
|
||||||
if (isVisible(rlReadMark)) { |
|
||||||
gone(rlReadMark); |
|
||||||
} else { |
|
||||||
gone(mLLight); |
|
||||||
updateMark(); |
|
||||||
visible(rlReadMark); |
|
||||||
} |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
mTvAddMark.setOnClickListener(view -> { |
|
||||||
if (mCurrentChapter != null) { |
|
||||||
mMarkAdapter.setEdit(false); |
|
||||||
AccountManager.getInstance().addSign(mBookId, mCurrentChapter.getChapterId(), mCurrentChapter.getTitle()); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
mTvClear.setOnClickListener(view -> { |
|
||||||
if (mMarkAdapter.getEdit()) { |
|
||||||
String sign = mMarkAdapter.getSelectList(); |
|
||||||
if (!sign.equals("")) { |
|
||||||
AccountManager.getInstance().deleteSign(sign); |
|
||||||
} |
|
||||||
mMarkAdapter.setEdit(false); |
|
||||||
} else { |
|
||||||
mMarkAdapter.setEdit(true); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
mTvCache.setOnClickListener(view -> { |
|
||||||
if (!isCollected) { //没有收藏 先收藏 然后弹框
|
|
||||||
//设置为已收藏
|
|
||||||
isCollected = true; |
|
||||||
//设置阅读时间
|
|
||||||
mCollBook.setLastRead(String.valueOf(System.currentTimeMillis())); |
|
||||||
BookRepository.getInstance().saveCollBookWithAsync(mCollBook); |
|
||||||
} |
|
||||||
showDownLoadDialog(); |
|
||||||
|
|
||||||
}); |
|
||||||
mLvCategory.setOnItemClickListener((parent, view, position, id) -> { |
|
||||||
mDlSlide.closeDrawer(GravityCompat.START); |
|
||||||
mPageLoader.skipToChapter(position); |
|
||||||
}); |
|
||||||
mIvGuide.setOnClickListener(view -> { |
|
||||||
mIvGuide.setVisibility(GONE); |
|
||||||
SpUtil.setBooleanValue(Constant.BookGuide, true); |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
private void showDownLoadDialog() { |
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
|
||||||
builder.setTitle(getString(R.string.d_cache_num)) |
|
||||||
.setItems(new String[]{getString(R.string.d_cache_last_50), getString(R.string.d_cache_last_all), getString(R.string.d_cache_all)}, (dialog, which) -> { |
|
||||||
switch (which) { |
|
||||||
case 0: //50章
|
|
||||||
int last = currentChapter + 50; |
|
||||||
if (last > mCollBook.getBookChapters().size()) { |
|
||||||
downLoadCache(mCollBook.getBookChapters(), mCollBook.getBookChapters().size()); |
|
||||||
} else { |
|
||||||
downLoadCache(mCollBook.getBookChapters(), last); |
|
||||||
} |
|
||||||
|
|
||||||
break; |
|
||||||
case 1: //后面所有
|
|
||||||
List<BookChapterBean> lastBeans = new ArrayList<>(); |
|
||||||
for (int i = currentChapter; i < mCollBook.getBookChapters().size(); i++) { |
|
||||||
lastBeans.add(mCollBook.getBookChapters().get(i)); |
|
||||||
} |
|
||||||
downLoadCache(lastBeans, mCollBook.getBookChapters().size() - currentChapter); |
|
||||||
break; |
|
||||||
case 2: //所有
|
|
||||||
downLoadCache(mCollBook.getBookChapters(), mCollBook.getBookChapters().size()); |
|
||||||
break; |
|
||||||
default: |
|
||||||
break; |
|
||||||
} |
|
||||||
toggleMenu(true); |
|
||||||
}); |
|
||||||
builder.show(); |
|
||||||
} |
|
||||||
|
|
||||||
private void downLoadCache(List<BookChapterBean> beans, int size) { |
|
||||||
DownloadTaskBean task = new DownloadTaskBean(); |
|
||||||
task.setTaskName(mCollBook.getTitle()); |
|
||||||
task.setBookId(mCollBook.getId()); |
|
||||||
task.setBookChapters(beans); //计算要缓存的章节
|
|
||||||
task.setCurrentChapter(currentChapter); |
|
||||||
task.setLastChapter(size); |
|
||||||
|
|
||||||
RxBus.getInstance().post(task); |
|
||||||
startService(new Intent(this, DownloadService.class)); |
|
||||||
} |
|
||||||
|
|
||||||
private void toggleNightMode() { |
|
||||||
if (isNightMode) { |
|
||||||
mTvNightMode.setText(getResources().getString(R.string.book_read_mode_day)); |
|
||||||
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.ic_read_menu_moring); |
|
||||||
mTvNightMode.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null); |
|
||||||
mClLayout.setBackgroundColor(getResources().getColor(R.color.nb_read_bg_night)); |
|
||||||
} else { |
|
||||||
mTvNightMode.setText(getResources().getString(R.string.book_read_mode_day)); |
|
||||||
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.ic_read_menu_night); |
|
||||||
mTvNightMode.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null); |
|
||||||
mClLayout.setBackgroundColor(getResources().getColor(ReadSettingManager.getInstance().getPageStyle().getBgColor())); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 隐藏阅读界面的菜单显示 |
|
||||||
* |
|
||||||
* @return 是否隐藏成功 |
|
||||||
*/ |
|
||||||
private boolean hideReadMenu() { |
|
||||||
hideSystemBar(); |
|
||||||
if (mAblTopMenu.getVisibility() == VISIBLE) { |
|
||||||
toggleMenu(true); |
|
||||||
return true; |
|
||||||
} else if (mSettingDialog.isShowing()) { |
|
||||||
mSettingDialog.dismiss(); |
|
||||||
return true; |
|
||||||
} |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
private void showSystemBar() { |
|
||||||
//显示
|
|
||||||
SystemBarUtils.showUnStableStatusBar(this); |
|
||||||
if (isFullScreen) { |
|
||||||
SystemBarUtils.showUnStableNavBar(this); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void hideSystemBar() { |
|
||||||
//隐藏
|
|
||||||
SystemBarUtils.hideStableStatusBar(this); |
|
||||||
if (isFullScreen) { |
|
||||||
SystemBarUtils.hideStableNavBar(this); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 切换菜单栏的可视状态 |
|
||||||
* 默认是隐藏的 |
|
||||||
*/ |
|
||||||
private void toggleMenu(boolean hideStatusBar) { |
|
||||||
initMenuAnim(); |
|
||||||
gone(mLLight, rlReadMark); |
|
||||||
if (mAblTopMenu.getVisibility() == View.VISIBLE) { |
|
||||||
//关闭
|
|
||||||
mAblTopMenu.startAnimation(mTopOutAnim); |
|
||||||
mLlBottomMenu.startAnimation(mBottomOutAnim); |
|
||||||
mAblTopMenu.setVisibility(GONE); |
|
||||||
mLlBottomMenu.setVisibility(GONE); |
|
||||||
|
|
||||||
if (hideStatusBar) { |
|
||||||
hideSystemBar(); |
|
||||||
} |
|
||||||
} else { |
|
||||||
mAblTopMenu.setVisibility(View.VISIBLE); |
|
||||||
mLlBottomMenu.setVisibility(View.VISIBLE); |
|
||||||
mAblTopMenu.startAnimation(mTopInAnim); |
|
||||||
mLlBottomMenu.startAnimation(mBottomInAnim); |
|
||||||
|
|
||||||
showSystemBar(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//初始化菜单动画
|
|
||||||
private void initMenuAnim() { |
|
||||||
if (mTopInAnim != null) return; |
|
||||||
mTopInAnim = AnimationUtils.loadAnimation(this, R.anim.slide_top_in); |
|
||||||
mTopOutAnim = AnimationUtils.loadAnimation(this, R.anim.slide_top_out); |
|
||||||
mBottomInAnim = AnimationUtils.loadAnimation(this, R.anim.slide_bottom_in); |
|
||||||
mBottomOutAnim = AnimationUtils.loadAnimation(this, R.anim.slide_bottom_out); |
|
||||||
//退出的速度要快
|
|
||||||
mTopOutAnim.setDuration(200); |
|
||||||
mBottomOutAnim.setDuration(200); |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void getBookArticle(BookArticleEvent event) { |
|
||||||
Log.e(TAG, "getBookArticle: "); |
|
||||||
if (event.isFail()) { |
|
||||||
|
|
||||||
} else { |
|
||||||
List<BookChapterBean> chapterBeans = event.getResult().getChapterBean(); |
|
||||||
mPageLoader.getCollBook().setBookChapters(chapterBeans); |
|
||||||
mPageLoader.refreshChapterList(); |
|
||||||
|
|
||||||
// 如果是目录更新的情况,那么就需要存储更新数据
|
|
||||||
if (mCollBook.isUpdate() && isCollected) { |
|
||||||
BookRepository.getInstance().saveBookChaptersWithAsync(event.getResult().getChapterBean(), mCollBook); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void finishChapter(FinishChapterEvent event) { |
|
||||||
if (mPageLoader.getPageStatus() == PageLoader.STATUS_LOADING) { |
|
||||||
mHandler.sendEmptyMessage(WHAT_CHAPTER); |
|
||||||
} |
|
||||||
// 当完成章节的时候,刷新列表
|
|
||||||
mCategoryAdapter.notifyDataSetChanged(); |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void errorChapter(ErrorChapterEvent event) { |
|
||||||
if (mPageLoader.getPageStatus() == PageLoader.STATUS_LOADING) { |
|
||||||
mPageLoader.chapterError(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void updateMark() { |
|
||||||
AccountManager.getInstance().getSignList(mBookId); |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void addSign(AddBookSignEvent event) { |
|
||||||
if (event.isFail()) { |
|
||||||
ToastUtils.showNormalToast(this, "添加书签失败,请检查网络设置"); |
|
||||||
} else { |
|
||||||
ToastUtils.showNormalToast(this, "添加书签成功"); |
|
||||||
updateMark(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void deleteSigin(DeleteBookSignEvent event) { |
|
||||||
if (event.isFail()) { |
|
||||||
ToastUtils.showNormalToast(this, event.getEr().getMsg()); |
|
||||||
} else { |
|
||||||
ToastUtils.showNormalToast(this, event.getResult().getMsg()); |
|
||||||
updateMark(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void getSignList(GetBookSignEvent event) { |
|
||||||
if (event.isFail()) { |
|
||||||
ToastUtils.showNormalToast(this, "获取书签失败,请检查网络设置"); |
|
||||||
} else { |
|
||||||
mMarks.clear(); |
|
||||||
mMarks.addAll(event.getResult().getSign()); |
|
||||||
mMarkAdapter.notifyDataSetChanged(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// 接收电池信息和时间更新的广播
|
|
||||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() { |
|
||||||
@Override |
|
||||||
public void onReceive(Context context, Intent intent) { |
|
||||||
if (Objects.requireNonNull(intent.getAction()).equals(Intent.ACTION_BATTERY_CHANGED)) { |
|
||||||
int level = intent.getIntExtra("level", 0); |
|
||||||
mPageLoader.updateBattery(level); |
|
||||||
} |
|
||||||
// 监听分钟的变化
|
|
||||||
else if (intent.getAction().equals(Intent.ACTION_TIME_TICK)) { |
|
||||||
mPageLoader.updateTime(); |
|
||||||
} |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void setAdsBg(SetAdsBgEvent event) { |
|
||||||
mClLayout.setBackgroundColor(getResources().getColor(ReadSettingManager.getInstance().getPageStyle().getBgColor())); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) { |
|
||||||
switch (keyCode) { |
|
||||||
case KeyEvent.KEYCODE_VOLUME_UP: |
|
||||||
return mPageLoader.skipToPrePage(); |
|
||||||
|
|
||||||
case KeyEvent.KEYCODE_VOLUME_DOWN: |
|
||||||
return mPageLoader.skipToNextPage(); |
|
||||||
} |
|
||||||
return super.onKeyDown(keyCode, event); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onBackPressed() { |
|
||||||
if (mAblTopMenu.getVisibility() == View.VISIBLE) { |
|
||||||
// 非全屏下才收缩,全屏下直接退出
|
|
||||||
if (!ReadSettingManager.getInstance().isFullScreen()) { |
|
||||||
toggleMenu(true); |
|
||||||
return; |
|
||||||
} |
|
||||||
} else if (mSettingDialog.isShowing()) { |
|
||||||
mSettingDialog.dismiss(); |
|
||||||
return; |
|
||||||
}else if (mDlSlide.isDrawerOpen(GravityCompat.START)) { |
|
||||||
mDlSlide.closeDrawer(GravityCompat.START); |
|
||||||
return; |
|
||||||
} |
|
||||||
Log.e(TAG, "onBackPressed: " + mCollBook.getBookChapters().isEmpty()); |
|
||||||
|
|
||||||
if (!mCollBook.isLocal() && !isCollected && !mCollBook.getBookChapters().isEmpty()) { |
|
||||||
AlertDialog alertDialog = new AlertDialog.Builder(this) |
|
||||||
.setTitle(getString(R.string.add_book)) |
|
||||||
.setMessage(getString(R.string.like_book)) |
|
||||||
.setPositiveButton(getString(R.string.sure), (dialog, which) -> { |
|
||||||
//设置为已收藏
|
|
||||||
isCollected = true; |
|
||||||
//设置阅读时间
|
|
||||||
mCollBook.setLastRead(String.valueOf(System.currentTimeMillis())); |
|
||||||
|
|
||||||
BookRepository.getInstance().saveCollBookWithAsync(mCollBook); |
|
||||||
|
|
||||||
exit(); |
|
||||||
}) |
|
||||||
.setNegativeButton(getString(R.string.cancel), (dialog, which) -> exit()).create(); |
|
||||||
alertDialog.show(); |
|
||||||
} else { |
|
||||||
exit(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// 退出
|
|
||||||
private void exit() { |
|
||||||
// 返回给BookDetail。
|
|
||||||
Intent result = new Intent(); |
|
||||||
result.putExtra(RESULT_IS_COLLECTED, isCollected); |
|
||||||
setResult(Activity.RESULT_OK, result); |
|
||||||
// 退出
|
|
||||||
super.onBackPressed(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onPause() { |
|
||||||
super.onPause(); |
|
||||||
if (isCollected) { |
|
||||||
mPageLoader.saveRecord(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onDestroy() { |
|
||||||
super.onDestroy(); |
|
||||||
EventManager.Companion.getInstance().unregisterSubscriber(this); |
|
||||||
mPageLoader.closeBook(); |
|
||||||
mPageLoader = null; |
|
||||||
unbindService(mConn); |
|
||||||
unregisterReceiver(mReceiver); |
|
||||||
} |
|
||||||
|
|
||||||
private DownloadService.IDownloadManager mService; |
|
||||||
private ServiceConnection mConn; |
|
||||||
|
|
||||||
private void initService() { |
|
||||||
|
|
||||||
mConn = new ServiceConnection() { |
|
||||||
@Override |
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) { |
|
||||||
mService = (DownloadService.IDownloadManager) service; |
|
||||||
mService.setOnDownloadListener(NovelReadActivity.this); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onServiceDisconnected(ComponentName name) { |
|
||||||
} |
|
||||||
}; |
|
||||||
//绑定
|
|
||||||
bindService(new Intent(this, DownloadService.class), mConn, Service.BIND_AUTO_CREATE); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onDownloadChange(int pos, int status, String msg) { |
|
||||||
// DownloadTaskBean bean = mDownloadAdapter.getItem(pos);
|
|
||||||
// bean.setStatus(status);
|
|
||||||
// if (DownloadTaskBean.STATUS_LOADING == status){
|
|
||||||
// bean.setCurrentChapter(Integer.valueOf(msg));
|
|
||||||
// }
|
|
||||||
// mDownloadAdapter.notifyItemChanged(pos);
|
|
||||||
Log.e(TAG, "onDownloadChange: " + pos + " " + status + " " + msg); |
|
||||||
|
|
||||||
if (msg.equals(getString(R.string.download_success)) || msg.equals(getString(R.string.download_error))) { |
|
||||||
//下载成功或失败后隐藏下载视图
|
|
||||||
if (mLlDownLoad != null) { |
|
||||||
mLlDownLoad.setVisibility(GONE); |
|
||||||
ToastUtils.showNormalToast(this, msg); |
|
||||||
} |
|
||||||
} else { |
|
||||||
if (mLlDownLoad != null) { |
|
||||||
mLlDownLoad.setVisibility(VISIBLE); |
|
||||||
mTvProgress.setText(getString(R.string.download_loading, |
|
||||||
mService.getDownloadTaskList().get(pos).getCurrentChapter(), |
|
||||||
mService.getDownloadTaskList().get(pos).getLastChapter())); |
|
||||||
loadingProgressBar.setMax(mService.getDownloadTaskList().get(pos).getLastChapter()); |
|
||||||
loadingProgressBar.setProgress(mService.getDownloadTaskList().get(pos).getCurrentChapter()); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
public void onDownloadResponse(int pos, int status) { |
|
||||||
// DownloadTaskBean bean = mDownloadAdapter.getItem(pos);
|
|
||||||
// bean.setStatus(status);
|
|
||||||
// mDownloadAdapter.notifyItemChanged(pos);
|
|
||||||
Log.e(TAG, "onDownloadResponse: " + pos + " " + status); |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void onDownLoadEvent(DownloadMessage message) { |
|
||||||
ToastUtils.showNormalToast(this, message.message); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,680 @@ |
|||||||
|
package com.novel.read.activity |
||||||
|
|
||||||
|
import android.annotation.SuppressLint |
||||||
|
import android.app.Activity |
||||||
|
import android.app.Service |
||||||
|
import android.content.* |
||||||
|
import android.os.Build |
||||||
|
import android.os.Handler |
||||||
|
import android.os.IBinder |
||||||
|
import android.os.Message |
||||||
|
import android.util.Log |
||||||
|
import android.view.KeyEvent |
||||||
|
import android.view.View.* |
||||||
|
import android.view.WindowManager |
||||||
|
import android.view.animation.Animation |
||||||
|
import android.view.animation.AnimationUtils |
||||||
|
import android.widget.SeekBar |
||||||
|
import androidx.appcompat.app.AlertDialog |
||||||
|
import androidx.core.content.ContextCompat |
||||||
|
import androidx.core.view.GravityCompat |
||||||
|
import androidx.drawerlayout.widget.DrawerLayout |
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager |
||||||
|
import com.common_lib.base.utils.ToastUtils |
||||||
|
import com.mango.mangolib.event.EventManager |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.adapter.CategoryAdapter |
||||||
|
import com.novel.read.adapter.MarkAdapter |
||||||
|
import com.novel.read.base.NovelBaseActivity |
||||||
|
import com.novel.read.constants.Constant |
||||||
|
import com.novel.read.constants.Constant.ResultCode.Companion.RESULT_IS_COLLECTED |
||||||
|
import com.novel.read.event.* |
||||||
|
import com.novel.read.http.AccountManager |
||||||
|
import com.novel.read.model.db.BookChapterBean |
||||||
|
import com.novel.read.model.db.CollBookBean |
||||||
|
import com.novel.read.model.db.DownloadTaskBean |
||||||
|
import com.novel.read.model.db.dbManage.BookRepository |
||||||
|
import com.novel.read.model.protocol.MarkResp |
||||||
|
import com.novel.read.service.DownloadMessage |
||||||
|
import com.novel.read.service.DownloadService |
||||||
|
import com.novel.read.utlis.BrightnessUtils |
||||||
|
import com.novel.read.utlis.ScreenUtils |
||||||
|
import com.novel.read.utlis.SpUtil |
||||||
|
import com.novel.read.utlis.SystemBarUtils |
||||||
|
import com.novel.read.widget.dialog.ReadSettingDialog |
||||||
|
import com.novel.read.widget.page.PageLoader |
||||||
|
import com.novel.read.widget.page.PageView |
||||||
|
import com.novel.read.widget.page.ReadSettingManager |
||||||
|
import com.novel.read.widget.page.TxtChapter |
||||||
|
import com.squareup.otto.Subscribe |
||||||
|
import kotlinx.android.synthetic.main.activity_read.* |
||||||
|
import kotlinx.android.synthetic.main.layout_download.* |
||||||
|
import kotlinx.android.synthetic.main.layout_light.* |
||||||
|
import kotlinx.android.synthetic.main.layout_read_mark.* |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
class NovelReadActivity : NovelBaseActivity(), DownloadService.OnDownloadListener { |
||||||
|
|
||||||
|
private var mCategoryAdapter: CategoryAdapter? = null |
||||||
|
private val mChapters = ArrayList<TxtChapter>() |
||||||
|
private var mCurrentChapter: TxtChapter? = null //当前章节 |
||||||
|
private var currentChapter = 0 |
||||||
|
private var mMarkAdapter: MarkAdapter? = null |
||||||
|
private val mMarks = ArrayList<MarkResp.SignBean>() |
||||||
|
private lateinit var mPageLoader: PageLoader |
||||||
|
private var mTopInAnim: Animation? = null |
||||||
|
private var mTopOutAnim: Animation? = null |
||||||
|
private var mBottomInAnim: Animation? = null |
||||||
|
private var mBottomOutAnim: Animation? = null |
||||||
|
|
||||||
|
private var mSettingDialog: ReadSettingDialog? = null |
||||||
|
private var isCollected = false // isFromSDCard |
||||||
|
private var isNightMode = false |
||||||
|
private var isFullScreen = false |
||||||
|
private val isRegistered = false |
||||||
|
|
||||||
|
private var mCollBook: CollBookBean? = null |
||||||
|
private var mBookId: String? = null |
||||||
|
|
||||||
|
@SuppressLint("HandlerLeak") |
||||||
|
private val mHandler = object : Handler() { |
||||||
|
override fun handleMessage(msg: Message) { |
||||||
|
super.handleMessage(msg) |
||||||
|
when (msg.what) { |
||||||
|
WHAT_CATEGORY -> rlv_list.setSelection(mPageLoader.chapterPos) |
||||||
|
WHAT_CHAPTER -> mPageLoader.openChapter() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override val layoutId: Int get() = R.layout.activity_read |
||||||
|
|
||||||
|
// 接收电池信息和时间更新的广播 |
||||||
|
private val mReceiver = object : BroadcastReceiver() { |
||||||
|
override fun onReceive(context: Context, intent: Intent) { |
||||||
|
if (Objects.requireNonNull(intent.action) == Intent.ACTION_BATTERY_CHANGED) { |
||||||
|
val level = intent.getIntExtra("level", 0) |
||||||
|
mPageLoader.updateBattery(level) |
||||||
|
} else if (intent.action == Intent.ACTION_TIME_TICK) { |
||||||
|
mPageLoader.updateTime() |
||||||
|
}// 监听分钟的变化 |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private var mService: DownloadService.IDownloadManager? = null |
||||||
|
private var mConn: ServiceConnection? = null |
||||||
|
|
||||||
|
override fun initView() { |
||||||
|
EventManager.instance.registerSubscriber(this) |
||||||
|
mCollBook = intent.getSerializableExtra(EXTRA_COLL_BOOK) as CollBookBean |
||||||
|
isCollected = intent.getBooleanExtra(EXTRA_IS_COLLECTED, false) |
||||||
|
mBookId = mCollBook!!.id |
||||||
|
initService() |
||||||
|
// 如果 API < 18 取消硬件加速 |
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { |
||||||
|
read_pv_page.setLayerType(LAYER_TYPE_SOFTWARE, null) |
||||||
|
} |
||||||
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) |
||||||
|
|
||||||
|
//获取页面加载器 |
||||||
|
mPageLoader = read_pv_page.getPageLoader(mCollBook) |
||||||
|
|
||||||
|
mSettingDialog = ReadSettingDialog(this, mPageLoader) |
||||||
|
//禁止滑动展示DrawerLayout |
||||||
|
read_dl_slide.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) |
||||||
|
//侧边打开后,返回键能够起作用 |
||||||
|
read_dl_slide.isFocusableInTouchMode = false |
||||||
|
//半透明化StatusBar |
||||||
|
SystemBarUtils.transparentStatusBar(this) |
||||||
|
//隐藏StatusBar |
||||||
|
read_pv_page!!.post { this.hideSystemBar() } |
||||||
|
read_abl_top_menu.setPadding(0, ScreenUtils.getStatusBarHeight(), 0, 0) |
||||||
|
ll_download.setPadding(0, ScreenUtils.getStatusBarHeight(), 0, ScreenUtils.dpToPx(15)) |
||||||
|
|
||||||
|
val lp = window.attributes |
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { |
||||||
|
lp.layoutInDisplayCutoutMode = 1 |
||||||
|
} |
||||||
|
window.attributes = lp |
||||||
|
|
||||||
|
//设置当前Activity的Brightness |
||||||
|
if (ReadSettingManager.getInstance().isBrightnessAuto) { |
||||||
|
BrightnessUtils.setDefaultBrightness(this) |
||||||
|
} else { |
||||||
|
BrightnessUtils.setBrightness(this, ReadSettingManager.getInstance().brightness) |
||||||
|
} |
||||||
|
|
||||||
|
//注册广播 |
||||||
|
val intentFilter = IntentFilter() |
||||||
|
intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED) |
||||||
|
intentFilter.addAction(Intent.ACTION_TIME_TICK) |
||||||
|
registerReceiver(mReceiver, intentFilter) |
||||||
|
|
||||||
|
if (!SpUtil.getBooleanValue(Constant.BookGuide, false)) { |
||||||
|
iv_guide.visibility = VISIBLE |
||||||
|
toggleMenu(false) |
||||||
|
} |
||||||
|
|
||||||
|
Log.e(TAG, "mBookId: " + mBookId!!) |
||||||
|
if (isCollected) { |
||||||
|
mPageLoader.collBook.bookChapters = |
||||||
|
BookRepository.getInstance().getBookChaptersInRx(mBookId) |
||||||
|
// 刷新章节列表 |
||||||
|
mPageLoader.refreshChapterList() |
||||||
|
// 如果是网络小说并被标记更新的,则从网络下载目录 |
||||||
|
if (mCollBook!!.isUpdate && !mCollBook!!.isLocal) { |
||||||
|
AccountManager.getInstance().getBookArticle(mBookId, "2", "1", "10000") |
||||||
|
} |
||||||
|
} else { |
||||||
|
AccountManager.getInstance().getBookArticle(mBookId, "2", "1", "10000") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun initData() { |
||||||
|
tv_book_name.text = mCollBook!!.title |
||||||
|
mCategoryAdapter = CategoryAdapter() |
||||||
|
rlv_list.adapter = mCategoryAdapter |
||||||
|
rlv_list.isFastScrollEnabled = true |
||||||
|
rlv_mark.layoutManager = LinearLayoutManager(this) |
||||||
|
mMarkAdapter = MarkAdapter(mMarks) |
||||||
|
rlv_mark.adapter = mMarkAdapter |
||||||
|
isNightMode = ReadSettingManager.getInstance().isNightMode |
||||||
|
//夜间模式按钮的状态 |
||||||
|
toggleNightMode() |
||||||
|
isFullScreen = ReadSettingManager.getInstance().isFullScreen |
||||||
|
toolbar.setNavigationOnClickListener { finish() } |
||||||
|
read_setting_sb_brightness.progress = ReadSettingManager.getInstance().brightness |
||||||
|
mPageLoader.setOnPageChangeListener( |
||||||
|
object : PageLoader.OnPageChangeListener { |
||||||
|
|
||||||
|
override fun onChapterChange(pos: Int) { |
||||||
|
mCategoryAdapter!!.setChapter(pos) |
||||||
|
mCurrentChapter = mChapters[pos] |
||||||
|
currentChapter = pos |
||||||
|
} |
||||||
|
|
||||||
|
override fun requestChapters(requestChapters: List<TxtChapter>) { |
||||||
|
AccountManager.getInstance().getBookArticleDetail(mBookId, requestChapters) |
||||||
|
mHandler.sendEmptyMessage(WHAT_CATEGORY) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onCategoryFinish(chapters: List<TxtChapter>) { |
||||||
|
mChapters.clear() |
||||||
|
mChapters.addAll(chapters) |
||||||
|
mCategoryAdapter!!.refreshItems(mChapters) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onPageCountChange(count: Int) {} |
||||||
|
|
||||||
|
override fun onPageChange(pos: Int) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
) |
||||||
|
read_pv_page.setTouchListener(object : PageView.TouchListener { |
||||||
|
override fun onTouch(): Boolean { |
||||||
|
return !hideReadMenu() |
||||||
|
} |
||||||
|
|
||||||
|
override fun center() { |
||||||
|
toggleMenu(true) |
||||||
|
} |
||||||
|
|
||||||
|
override fun prePage() {} |
||||||
|
|
||||||
|
override fun nextPage() {} |
||||||
|
|
||||||
|
override fun cancel() {} |
||||||
|
}) |
||||||
|
read_tv_category.setOnClickListener { |
||||||
|
//移动到指定位置 |
||||||
|
if (mCategoryAdapter!!.count > 0) { |
||||||
|
rlv_list.setSelection(mPageLoader.chapterPos) |
||||||
|
} |
||||||
|
//切换菜单 |
||||||
|
toggleMenu(true) |
||||||
|
//打开侧滑动栏 |
||||||
|
read_dl_slide.openDrawer(GravityCompat.START) |
||||||
|
} |
||||||
|
tv_light.setOnClickListener { |
||||||
|
ll_light.visibility = GONE |
||||||
|
rlReadMark.visibility = GONE |
||||||
|
if (isVisible(ll_light)) { |
||||||
|
ll_light.visibility = GONE |
||||||
|
} else { |
||||||
|
ll_light.visibility = VISIBLE |
||||||
|
} |
||||||
|
} |
||||||
|
tv_setting.setOnClickListener { |
||||||
|
ll_light.visibility = GONE |
||||||
|
rlReadMark.visibility = GONE |
||||||
|
toggleMenu(false) |
||||||
|
mSettingDialog!!.show() |
||||||
|
} |
||||||
|
|
||||||
|
read_setting_sb_brightness.setOnSeekBarChangeListener(object : |
||||||
|
SeekBar.OnSeekBarChangeListener { |
||||||
|
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
override fun onStartTrackingTouch(seekBar: SeekBar) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
override fun onStopTrackingTouch(seekBar: SeekBar) { |
||||||
|
val progress = seekBar.progress |
||||||
|
//设置当前 Activity 的亮度 |
||||||
|
BrightnessUtils.setBrightness(this@NovelReadActivity, progress) |
||||||
|
//存储亮度的进度条 |
||||||
|
ReadSettingManager.getInstance().brightness = progress |
||||||
|
} |
||||||
|
}) |
||||||
|
|
||||||
|
tvBookReadMode.setOnClickListener { |
||||||
|
isNightMode = !isNightMode |
||||||
|
mPageLoader.setNightMode(isNightMode) |
||||||
|
toggleNightMode() |
||||||
|
} |
||||||
|
|
||||||
|
read_tv_brief.setOnClickListener { |
||||||
|
val intent = Intent(this, NovelBookDetailActivity::class.java) |
||||||
|
intent.putExtra(Constant.Bundle.BookId, Integer.valueOf(mBookId!!)) |
||||||
|
startActivity(intent) |
||||||
|
} |
||||||
|
|
||||||
|
read_tv_community.setOnClickListener { |
||||||
|
if (isVisible(read_ll_bottom_menu)) { |
||||||
|
if (isVisible(rlReadMark)) { |
||||||
|
gone(rlReadMark) |
||||||
|
} else { |
||||||
|
gone(ll_light) |
||||||
|
updateMark() |
||||||
|
visible(rlReadMark) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
tvAddMark.setOnClickListener { |
||||||
|
if (mCurrentChapter != null) { |
||||||
|
mMarkAdapter!!.edit = false |
||||||
|
AccountManager.getInstance() |
||||||
|
.addSign(mBookId, mCurrentChapter!!.chapterId, mCurrentChapter!!.title) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
tvClear.setOnClickListener { |
||||||
|
if (mMarkAdapter!!.edit) { |
||||||
|
val sign = mMarkAdapter!!.selectList |
||||||
|
if (sign != "") { |
||||||
|
AccountManager.getInstance().deleteSign(sign) |
||||||
|
} |
||||||
|
mMarkAdapter!!.edit = false |
||||||
|
} else { |
||||||
|
mMarkAdapter!!.edit = true |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
tv_cache.setOnClickListener { |
||||||
|
if (!isCollected) { //没有收藏 先收藏 然后弹框 |
||||||
|
//设置为已收藏 |
||||||
|
isCollected = true |
||||||
|
//设置阅读时间 |
||||||
|
mCollBook!!.lastRead = System.currentTimeMillis().toString() |
||||||
|
BookRepository.getInstance().saveCollBookWithAsync(mCollBook!!) |
||||||
|
} |
||||||
|
showDownLoadDialog() |
||||||
|
|
||||||
|
} |
||||||
|
rlv_list.setOnItemClickListener { _, _, position, _ -> |
||||||
|
read_dl_slide.closeDrawer(GravityCompat.START) |
||||||
|
mPageLoader.skipToChapter(position) |
||||||
|
} |
||||||
|
iv_guide.setOnClickListener { |
||||||
|
iv_guide.visibility = GONE |
||||||
|
SpUtil.setBooleanValue(Constant.BookGuide, true) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private fun showDownLoadDialog() { |
||||||
|
val builder = AlertDialog.Builder(this) |
||||||
|
builder.setTitle(getString(R.string.d_cache_num)) |
||||||
|
.setItems( |
||||||
|
arrayOf( |
||||||
|
getString(R.string.d_cache_last_50), |
||||||
|
getString(R.string.d_cache_last_all), |
||||||
|
getString(R.string.d_cache_all) |
||||||
|
) |
||||||
|
) { _, which -> |
||||||
|
when (which) { |
||||||
|
0 //50章 |
||||||
|
-> { |
||||||
|
val last = currentChapter + 50 |
||||||
|
if (last > mCollBook!!.bookChapters.size) { |
||||||
|
downLoadCache(mCollBook!!.bookChapters, mCollBook!!.bookChapters.size) |
||||||
|
} else { |
||||||
|
downLoadCache(mCollBook!!.bookChapters, last) |
||||||
|
} |
||||||
|
} |
||||||
|
1 //后面所有 |
||||||
|
-> { |
||||||
|
val lastBeans = ArrayList<BookChapterBean>() |
||||||
|
for (i in currentChapter until mCollBook!!.bookChapters.size) { |
||||||
|
lastBeans.add(mCollBook!!.bookChapters[i]) |
||||||
|
} |
||||||
|
downLoadCache(lastBeans, mCollBook!!.bookChapters.size - currentChapter) |
||||||
|
} |
||||||
|
2 //所有 |
||||||
|
-> downLoadCache(mCollBook!!.bookChapters, mCollBook!!.bookChapters.size) |
||||||
|
else -> { |
||||||
|
} |
||||||
|
} |
||||||
|
toggleMenu(true) |
||||||
|
} |
||||||
|
builder.show() |
||||||
|
} |
||||||
|
|
||||||
|
private fun downLoadCache(beans: List<BookChapterBean>, size: Int) { |
||||||
|
val task = DownloadTaskBean() |
||||||
|
task.taskName = mCollBook!!.title |
||||||
|
task.bookId = mCollBook!!.id |
||||||
|
task.bookChapters = beans //计算要缓存的章节 |
||||||
|
task.currentChapter = currentChapter |
||||||
|
task.lastChapter = size |
||||||
|
|
||||||
|
RxBus.getInstance().post(task) |
||||||
|
startService(Intent(this, DownloadService::class.java)) |
||||||
|
} |
||||||
|
|
||||||
|
private fun toggleNightMode() { |
||||||
|
if (isNightMode) { |
||||||
|
tvBookReadMode.text = resources.getString(R.string.book_read_mode_day) |
||||||
|
val drawable = ContextCompat.getDrawable(this, R.drawable.ic_read_menu_moring) |
||||||
|
tvBookReadMode.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null) |
||||||
|
cl_layout.setBackgroundColor(resources.getColor(R.color.nb_read_bg_night)) |
||||||
|
} else { |
||||||
|
tvBookReadMode.text = resources.getString(R.string.book_read_mode_day) |
||||||
|
val drawable = ContextCompat.getDrawable(this, R.drawable.ic_read_menu_night) |
||||||
|
tvBookReadMode.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null) |
||||||
|
cl_layout.setBackgroundColor(resources.getColor(ReadSettingManager.getInstance().pageStyle.bgColor)) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 隐藏阅读界面的菜单显示 |
||||||
|
* |
||||||
|
* @return 是否隐藏成功 |
||||||
|
*/ |
||||||
|
private fun hideReadMenu(): Boolean { |
||||||
|
hideSystemBar() |
||||||
|
if (read_abl_top_menu.visibility == VISIBLE) { |
||||||
|
toggleMenu(true) |
||||||
|
return true |
||||||
|
} else if (mSettingDialog!!.isShowing) { |
||||||
|
mSettingDialog!!.dismiss() |
||||||
|
return true |
||||||
|
} |
||||||
|
return false |
||||||
|
} |
||||||
|
|
||||||
|
private fun showSystemBar() { |
||||||
|
//显示 |
||||||
|
SystemBarUtils.showUnStableStatusBar(this) |
||||||
|
if (isFullScreen) { |
||||||
|
SystemBarUtils.showUnStableNavBar(this) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private fun hideSystemBar() { |
||||||
|
//隐藏 |
||||||
|
SystemBarUtils.hideStableStatusBar(this) |
||||||
|
if (isFullScreen) { |
||||||
|
SystemBarUtils.hideStableNavBar(this) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 切换菜单栏的可视状态 |
||||||
|
* 默认是隐藏的 |
||||||
|
*/ |
||||||
|
private fun toggleMenu(hideStatusBar: Boolean) { |
||||||
|
initMenuAnim() |
||||||
|
gone(ll_light, rlReadMark) |
||||||
|
if (read_abl_top_menu.visibility == VISIBLE) { |
||||||
|
//关闭 |
||||||
|
read_abl_top_menu.startAnimation(mTopOutAnim) |
||||||
|
read_ll_bottom_menu.startAnimation(mBottomOutAnim) |
||||||
|
read_abl_top_menu.visibility = GONE |
||||||
|
read_ll_bottom_menu.visibility = GONE |
||||||
|
|
||||||
|
if (hideStatusBar) { |
||||||
|
hideSystemBar() |
||||||
|
} |
||||||
|
} else { |
||||||
|
read_abl_top_menu.visibility = VISIBLE |
||||||
|
read_ll_bottom_menu.visibility = VISIBLE |
||||||
|
read_abl_top_menu.startAnimation(mTopInAnim) |
||||||
|
read_ll_bottom_menu.startAnimation(mBottomInAnim) |
||||||
|
|
||||||
|
showSystemBar() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//初始化菜单动画 |
||||||
|
private fun initMenuAnim() { |
||||||
|
if (mTopInAnim != null) return |
||||||
|
mTopInAnim = AnimationUtils.loadAnimation(this, R.anim.slide_top_in) |
||||||
|
mTopOutAnim = AnimationUtils.loadAnimation(this, R.anim.slide_top_out) |
||||||
|
mBottomInAnim = AnimationUtils.loadAnimation(this, R.anim.slide_bottom_in) |
||||||
|
mBottomOutAnim = AnimationUtils.loadAnimation(this, R.anim.slide_bottom_out) |
||||||
|
//退出的速度要快 |
||||||
|
mTopOutAnim!!.duration = 200 |
||||||
|
mBottomOutAnim!!.duration = 200 |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun getBookArticle(event: BookArticleEvent) { |
||||||
|
Log.e(TAG, "getBookArticle: ") |
||||||
|
if (event.isFail) { |
||||||
|
|
||||||
|
} else { |
||||||
|
val chapterBeans = event.result!!.chapterBean |
||||||
|
mPageLoader.collBook.bookChapters = chapterBeans |
||||||
|
mPageLoader.refreshChapterList() |
||||||
|
|
||||||
|
// 如果是目录更新的情况,那么就需要存储更新数据 |
||||||
|
if (mCollBook!!.isUpdate && isCollected) { |
||||||
|
BookRepository.getInstance() |
||||||
|
.saveBookChaptersWithAsync(event.result!!.chapterBean, mCollBook!!) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun finishChapter(event: FinishChapterEvent) { |
||||||
|
if (mPageLoader.pageStatus == PageLoader.STATUS_LOADING) { |
||||||
|
mHandler.sendEmptyMessage(WHAT_CHAPTER) |
||||||
|
} |
||||||
|
// 当完成章节的时候,刷新列表 |
||||||
|
mCategoryAdapter!!.notifyDataSetChanged() |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun errorChapter(event: ErrorChapterEvent) { |
||||||
|
if (mPageLoader.pageStatus == PageLoader.STATUS_LOADING) { |
||||||
|
mPageLoader.chapterError() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private fun updateMark() { |
||||||
|
AccountManager.getInstance().getSignList(mBookId) |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun addSign(event: AddBookSignEvent) { |
||||||
|
if (event.isFail) { |
||||||
|
ToastUtils.showNormalToast(this, "添加书签失败,请检查网络设置") |
||||||
|
} else { |
||||||
|
ToastUtils.showNormalToast(this, "添加书签成功") |
||||||
|
updateMark() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun deleteSigin(event: DeleteBookSignEvent) { |
||||||
|
if (event.isFail) { |
||||||
|
ToastUtils.showNormalToast(this, event.er!!.msg) |
||||||
|
} else { |
||||||
|
ToastUtils.showNormalToast(this, event.result!!.msg) |
||||||
|
updateMark() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun getSignList(event: GetBookSignEvent) { |
||||||
|
if (event.isFail) { |
||||||
|
ToastUtils.showNormalToast(this, "获取书签失败,请检查网络设置") |
||||||
|
} else { |
||||||
|
mMarks.clear() |
||||||
|
mMarks.addAll(event.result!!.sign) |
||||||
|
mMarkAdapter!!.notifyDataSetChanged() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean { |
||||||
|
when (keyCode) { |
||||||
|
KeyEvent.KEYCODE_VOLUME_UP -> return mPageLoader.skipToPrePage() |
||||||
|
|
||||||
|
KeyEvent.KEYCODE_VOLUME_DOWN -> return mPageLoader.skipToNextPage() |
||||||
|
} |
||||||
|
return super.onKeyDown(keyCode, event) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onBackPressed() { |
||||||
|
if (read_abl_top_menu.visibility == VISIBLE) { |
||||||
|
// 非全屏下才收缩,全屏下直接退出 |
||||||
|
if (!ReadSettingManager.getInstance().isFullScreen) { |
||||||
|
toggleMenu(true) |
||||||
|
return |
||||||
|
} |
||||||
|
} else if (mSettingDialog!!.isShowing) { |
||||||
|
mSettingDialog!!.dismiss() |
||||||
|
return |
||||||
|
} else if (read_dl_slide.isDrawerOpen(GravityCompat.START)) { |
||||||
|
read_dl_slide.closeDrawer(GravityCompat.START) |
||||||
|
return |
||||||
|
} |
||||||
|
Log.e(TAG, "onBackPressed: " + mCollBook!!.bookChapters.isEmpty()) |
||||||
|
|
||||||
|
if (!mCollBook!!.isLocal && !isCollected && !mCollBook!!.bookChapters.isEmpty()) { |
||||||
|
val alertDialog = AlertDialog.Builder(this) |
||||||
|
.setTitle(getString(R.string.add_book)) |
||||||
|
.setMessage(getString(R.string.like_book)) |
||||||
|
.setPositiveButton(getString(R.string.sure)) { dialog, which -> |
||||||
|
//设置为已收藏 |
||||||
|
isCollected = true |
||||||
|
//设置阅读时间 |
||||||
|
mCollBook!!.lastRead = System.currentTimeMillis().toString() |
||||||
|
|
||||||
|
BookRepository.getInstance().saveCollBookWithAsync(mCollBook!!) |
||||||
|
|
||||||
|
exit() |
||||||
|
} |
||||||
|
.setNegativeButton(getString(R.string.cancel)) { dialog, which -> exit() }.create() |
||||||
|
alertDialog.show() |
||||||
|
} else { |
||||||
|
exit() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 退出 |
||||||
|
private fun exit() { |
||||||
|
// 返回给BookDetail。 |
||||||
|
val result = Intent() |
||||||
|
result.putExtra(RESULT_IS_COLLECTED, isCollected) |
||||||
|
setResult(Activity.RESULT_OK, result) |
||||||
|
// 退出 |
||||||
|
super.onBackPressed() |
||||||
|
} |
||||||
|
|
||||||
|
override fun onPause() { |
||||||
|
super.onPause() |
||||||
|
if (isCollected) { |
||||||
|
mPageLoader.saveRecord() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onDestroy() { |
||||||
|
super.onDestroy() |
||||||
|
EventManager.instance.unregisterSubscriber(this) |
||||||
|
mPageLoader.closeBook() |
||||||
|
// mPageLoader = null |
||||||
|
unbindService(mConn) |
||||||
|
unregisterReceiver(mReceiver) |
||||||
|
} |
||||||
|
|
||||||
|
private fun initService() { |
||||||
|
|
||||||
|
mConn = object : ServiceConnection { |
||||||
|
override fun onServiceConnected(name: ComponentName, service: IBinder) { |
||||||
|
mService = service as DownloadService.IDownloadManager |
||||||
|
mService!!.setOnDownloadListener(this@NovelReadActivity) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onServiceDisconnected(name: ComponentName) {} |
||||||
|
} |
||||||
|
//绑定 |
||||||
|
bindService(Intent(this, DownloadService::class.java), mConn, Service.BIND_AUTO_CREATE) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onDownloadChange(pos: Int, status: Int, msg: String) { |
||||||
|
// DownloadTaskBean bean = mDownloadAdapter.getItem(pos); |
||||||
|
// bean.setStatus(status); |
||||||
|
// if (DownloadTaskBean.STATUS_LOADING == status){ |
||||||
|
// bean.setCurrentChapter(Integer.valueOf(msg)); |
||||||
|
// } |
||||||
|
// mDownloadAdapter.notifyItemChanged(pos); |
||||||
|
Log.e(TAG, "onDownloadChange: $pos $status $msg") |
||||||
|
|
||||||
|
if (msg == getString(R.string.download_success) || msg == getString(R.string.download_error)) { |
||||||
|
//下载成功或失败后隐藏下载视图 |
||||||
|
if (ll_download != null) { |
||||||
|
ll_download.visibility = GONE |
||||||
|
ToastUtils.showNormalToast(this, msg) |
||||||
|
} |
||||||
|
} else { |
||||||
|
if (ll_download != null) { |
||||||
|
ll_download.visibility = VISIBLE |
||||||
|
tv_progress.text = getString( |
||||||
|
R.string.download_loading, |
||||||
|
mService!!.downloadTaskList[pos].currentChapter, |
||||||
|
mService!!.downloadTaskList[pos].lastChapter |
||||||
|
) |
||||||
|
pb_loading.max = mService!!.downloadTaskList[pos].lastChapter |
||||||
|
pb_loading.progress = mService!!.downloadTaskList[pos].currentChapter |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
override fun onDownloadResponse(pos: Int, status: Int) { |
||||||
|
// DownloadTaskBean bean = mDownloadAdapter.getItem(pos); |
||||||
|
// bean.setStatus(status); |
||||||
|
// mDownloadAdapter.notifyItemChanged(pos); |
||||||
|
Log.e(TAG, "onDownloadResponse: $pos $status") |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun onDownLoadEvent(message: DownloadMessage) { |
||||||
|
ToastUtils.showNormalToast(this, message.message) |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
|
||||||
|
private const val TAG = "NovelReadActivity" |
||||||
|
const val EXTRA_COLL_BOOK = "extra_coll_book" |
||||||
|
const val EXTRA_IS_COLLECTED = "extra_is_collected" |
||||||
|
private const val WHAT_CATEGORY = 1 |
||||||
|
private const val WHAT_CHAPTER = 2 |
||||||
|
} |
||||||
|
} |
@ -1,105 +0,0 @@ |
|||||||
package com.novel.read.activity; |
|
||||||
|
|
||||||
import android.os.Bundle; |
|
||||||
import android.view.View; |
|
||||||
|
|
||||||
import androidx.appcompat.widget.Toolbar; |
|
||||||
import androidx.fragment.app.Fragment; |
|
||||||
import androidx.viewpager.widget.ViewPager; |
|
||||||
|
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.adapter.ViewPageAdapter; |
|
||||||
import com.novel.read.base.NovelBaseActivity; |
|
||||||
import com.novel.read.constants.Constant; |
|
||||||
import com.novel.read.fragment.BookListFragment; |
|
||||||
import com.novel.read.widget.VpTabLayout; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
|
|
||||||
public class NovelRecommendBookListActivity extends NovelBaseActivity { |
|
||||||
|
|
||||||
@BindView(R.id.toolbar) |
|
||||||
Toolbar toolbar; |
|
||||||
@BindView(R.id.vp_tab) |
|
||||||
VpTabLayout mVpTab; |
|
||||||
@BindView(R.id.vp_recommend_type) |
|
||||||
ViewPager mVpRecommendType; |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onCreate(Bundle savedInstanceState) { |
|
||||||
super.onCreate(savedInstanceState); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected int getLayoutId() { |
|
||||||
return R.layout.activity_recommend_book_list; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initView() { |
|
||||||
List<Fragment> fragmentList = new ArrayList<>(); |
|
||||||
String sex = getIntent().getStringExtra(Constant.Sex); |
|
||||||
String type = getIntent().getStringExtra(Constant.Type); |
|
||||||
if (type.equals(Constant.ListType.Human)){ |
|
||||||
toolbar.setTitle(getString(R.string.popular_selection)); |
|
||||||
}else if (type.equals(Constant.ListType.EditRecommend)){ |
|
||||||
toolbar.setTitle(getString(R.string.edit_recommend)); |
|
||||||
}else if (type.equals(Constant.ListType.HotSearch)){ |
|
||||||
toolbar.setTitle(getString(R.string.hot_search)); |
|
||||||
} |
|
||||||
|
|
||||||
BookListFragment generalFragment = BookListFragment.newInstance(type, Constant.DateTyp.General, sex); |
|
||||||
BookListFragment monthFragment = BookListFragment.newInstance(type, Constant.DateTyp.Month, sex); |
|
||||||
BookListFragment weekFragment = BookListFragment.newInstance(type, Constant.DateTyp.Week, sex); |
|
||||||
fragmentList.add(generalFragment); |
|
||||||
fragmentList.add(monthFragment); |
|
||||||
fragmentList.add(weekFragment); |
|
||||||
ViewPageAdapter pageAdapter = new ViewPageAdapter(getSupportFragmentManager(), fragmentList); |
|
||||||
mVpRecommendType.setAdapter(pageAdapter); |
|
||||||
mVpRecommendType.setOffscreenPageLimit(2); |
|
||||||
mVpRecommendType.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { |
|
||||||
@Override |
|
||||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onPageSelected(int position) { |
|
||||||
mVpTab.setAnim(position, mVpRecommendType); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onPageScrollStateChanged(int state) { |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initData() { |
|
||||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() { |
|
||||||
@Override |
|
||||||
public void onClick(View view) { |
|
||||||
finish(); |
|
||||||
} |
|
||||||
}); |
|
||||||
mVpTab.setOnTabBtnClickListener(new VpTabLayout.OnTabClickListener() { |
|
||||||
@Override |
|
||||||
public void onTabBtnClick(VpTabLayout.CommonTabBtn var1, View var2) { |
|
||||||
switch (var1) { |
|
||||||
case ONE: |
|
||||||
mVpTab.setAnim(0, mVpRecommendType); |
|
||||||
break; |
|
||||||
case TWO: |
|
||||||
mVpTab.setAnim(1, mVpRecommendType); |
|
||||||
break; |
|
||||||
case THREE: |
|
||||||
mVpTab.setAnim(2, mVpRecommendType); |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,64 @@ |
|||||||
|
package com.novel.read.activity |
||||||
|
|
||||||
|
import android.view.View |
||||||
|
import androidx.fragment.app.Fragment |
||||||
|
import androidx.viewpager.widget.ViewPager |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.adapter.ViewPageAdapter |
||||||
|
import com.novel.read.base.NovelBaseActivity |
||||||
|
import com.novel.read.constants.Constant |
||||||
|
import com.novel.read.fragment.BookListFragment |
||||||
|
import com.novel.read.widget.VpTabLayout |
||||||
|
import kotlinx.android.synthetic.main.activity_recommend_book_list.* |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
class NovelRecommendBookListActivity : NovelBaseActivity() { |
||||||
|
|
||||||
|
override val layoutId: Int get() = R.layout.activity_recommend_book_list |
||||||
|
|
||||||
|
override fun initView() { |
||||||
|
val fragmentList = ArrayList<Fragment>() |
||||||
|
val sex = intent.getStringExtra(Constant.Sex) |
||||||
|
val type = intent.getStringExtra(Constant.Type) |
||||||
|
when (type) { |
||||||
|
Constant.ListType.Human -> toolbar.title = getString(R.string.popular_selection) |
||||||
|
Constant.ListType.EditRecommend -> toolbar.title = getString(R.string.edit_recommend) |
||||||
|
Constant.ListType.HotSearch -> toolbar.title = getString(R.string.hot_search) |
||||||
|
} |
||||||
|
val generalFragment = BookListFragment.newInstance(type, Constant.DateTyp.General, sex) |
||||||
|
val monthFragment = BookListFragment.newInstance(type, Constant.DateTyp.Month, sex) |
||||||
|
val weekFragment = BookListFragment.newInstance(type, Constant.DateTyp.Week, sex) |
||||||
|
fragmentList.add(generalFragment) |
||||||
|
fragmentList.add(monthFragment) |
||||||
|
fragmentList.add(weekFragment) |
||||||
|
val pageAdapter = ViewPageAdapter(supportFragmentManager, fragmentList) |
||||||
|
vp_recommend_type.adapter = pageAdapter |
||||||
|
vp_recommend_type.offscreenPageLimit = 2 |
||||||
|
vp_recommend_type.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { |
||||||
|
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
override fun onPageSelected(position: Int) { |
||||||
|
vp_tab.setAnim(position, vp_recommend_type) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onPageScrollStateChanged(state: Int) {} |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
override fun initData() { |
||||||
|
toolbar!!.setNavigationOnClickListener { finish() } |
||||||
|
|
||||||
|
vp_tab.setOnTabBtnClickListener(object : VpTabLayout.OnTabClickListener { |
||||||
|
override fun onTabBtnClick(var1: VpTabLayout.CommonTabBtn, var2: View) { |
||||||
|
when (var1) { |
||||||
|
VpTabLayout.CommonTabBtn.ONE -> vp_tab.setAnim(0, vp_recommend_type) |
||||||
|
VpTabLayout.CommonTabBtn.TWO -> vp_tab.setAnim(1, vp_recommend_type) |
||||||
|
VpTabLayout.CommonTabBtn.THREE -> vp_tab.setAnim(2, vp_recommend_type) |
||||||
|
} |
||||||
|
} |
||||||
|
}) |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -1,295 +0,0 @@ |
|||||||
package com.novel.read.activity; |
|
||||||
|
|
||||||
import android.os.Bundle; |
|
||||||
import android.text.Editable; |
|
||||||
import android.text.TextUtils; |
|
||||||
import android.text.TextWatcher; |
|
||||||
import android.view.KeyEvent; |
|
||||||
import android.view.View; |
|
||||||
import android.widget.EditText; |
|
||||||
import android.widget.TextView; |
|
||||||
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager; |
|
||||||
import androidx.recyclerview.widget.RecyclerView; |
|
||||||
|
|
||||||
import com.google.android.flexbox.AlignItems; |
|
||||||
import com.google.android.flexbox.FlexDirection; |
|
||||||
import com.google.android.flexbox.FlexWrap; |
|
||||||
import com.google.android.flexbox.FlexboxLayoutManager; |
|
||||||
import com.mango.mangolib.event.EventManager; |
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.adapter.HistoryAdapter; |
|
||||||
import com.novel.read.adapter.HotAdapter; |
|
||||||
import com.novel.read.adapter.SearchAdapter; |
|
||||||
import com.novel.read.base.NovelBaseActivity; |
|
||||||
import com.novel.read.event.HotSearchEvent; |
|
||||||
import com.novel.read.event.SearchListEvent; |
|
||||||
import com.novel.read.http.AccountManager; |
|
||||||
import com.novel.read.model.db.SearchListTable; |
|
||||||
import com.novel.read.model.protocol.SearchResp; |
|
||||||
import com.novel.read.utlis.DialogUtils; |
|
||||||
import com.novel.read.widget.HeadLayout; |
|
||||||
import com.novel.read.widget.RefreshLayout; |
|
||||||
import com.spreada.utils.chinese.ZHConverter; |
|
||||||
import com.squareup.otto.Subscribe; |
|
||||||
|
|
||||||
import org.litepal.LitePal; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
import butterknife.OnClick; |
|
||||||
|
|
||||||
import static com.novel.read.constants.Constant.COMMENT_SIZE; |
|
||||||
|
|
||||||
public class NovelSearchActivity extends NovelBaseActivity { |
|
||||||
|
|
||||||
@BindView(R.id.tv_search) |
|
||||||
EditText mTvSearch; |
|
||||||
@BindView(R.id.tv_cancel) |
|
||||||
TextView tvCancel; |
|
||||||
@BindView(R.id.head_hot) |
|
||||||
HeadLayout headHot; |
|
||||||
@BindView(R.id.rlv_hot) |
|
||||||
RecyclerView mRlvHot; |
|
||||||
@BindView(R.id.head_history) |
|
||||||
HeadLayout headHistory; |
|
||||||
@BindView(R.id.rlv_history) |
|
||||||
RecyclerView mRlvHistory; |
|
||||||
@BindView(R.id.rlv_search) |
|
||||||
RecyclerView mRlvSearch; |
|
||||||
@BindView(R.id.refresh) |
|
||||||
RefreshLayout refreshLayout; |
|
||||||
|
|
||||||
private List<String> mHotList = new ArrayList<>(); |
|
||||||
private HotAdapter mHotAdapter; |
|
||||||
|
|
||||||
private List<SearchListTable> mHisList = new ArrayList<>(); |
|
||||||
private HistoryAdapter mHisAdapter; |
|
||||||
|
|
||||||
private List<SearchResp.BookBean> mSearchList = new ArrayList<>(); |
|
||||||
private SearchAdapter mSearchAdapter; |
|
||||||
|
|
||||||
private int page = 1; |
|
||||||
private int loadSize; |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onCreate(Bundle savedInstanceState) { |
|
||||||
super.onCreate(savedInstanceState); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected int getLayoutId() { |
|
||||||
return R.layout.activity_search; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initView() { |
|
||||||
EventManager.Companion.getInstance().registerSubscriber(this); |
|
||||||
|
|
||||||
FlexboxLayoutManager manager = new FlexboxLayoutManager(this); |
|
||||||
//设置主轴排列方式
|
|
||||||
manager.setFlexDirection(FlexDirection.ROW); |
|
||||||
//设置是否换行
|
|
||||||
manager.setFlexWrap(FlexWrap.WRAP); |
|
||||||
manager.setAlignItems(AlignItems.STRETCH); |
|
||||||
mRlvHot.setLayoutManager(manager); |
|
||||||
mHotAdapter = new HotAdapter(mHotList); |
|
||||||
mRlvHot.setAdapter(mHotAdapter); |
|
||||||
|
|
||||||
mHisList = LitePal.order("saveTime desc").limit(5).find(SearchListTable.class); |
|
||||||
FlexboxLayoutManager manager2 = new FlexboxLayoutManager(this); |
|
||||||
//设置主轴排列方式
|
|
||||||
manager2.setFlexDirection(FlexDirection.ROW); |
|
||||||
//设置是否换行
|
|
||||||
manager2.setFlexWrap(FlexWrap.WRAP); |
|
||||||
manager2.setAlignItems(AlignItems.STRETCH); |
|
||||||
mHisAdapter = new HistoryAdapter(mHisList); |
|
||||||
mRlvHistory.setLayoutManager(manager2); |
|
||||||
mRlvHistory.setAdapter(mHisAdapter); |
|
||||||
|
|
||||||
mRlvSearch.setLayoutManager(new LinearLayoutManager(this)); |
|
||||||
mSearchAdapter = new SearchAdapter(mSearchList, mRlvSearch); |
|
||||||
mRlvSearch.setAdapter(mSearchAdapter); |
|
||||||
mSearchAdapter.setOnLoadMoreListener(() -> { |
|
||||||
if (mSearchAdapter.isLoadingMore()) { |
|
||||||
|
|
||||||
} else { |
|
||||||
if (loadSize >= COMMENT_SIZE) { |
|
||||||
mSearchAdapter.setLoadingMore(true); |
|
||||||
mSearchList.add(null); |
|
||||||
mSearchAdapter.notifyDataSetChanged(); |
|
||||||
page++; |
|
||||||
getData(); |
|
||||||
} |
|
||||||
} |
|
||||||
}); |
|
||||||
AccountManager.getInstance().getHotSearch(); |
|
||||||
} |
|
||||||
|
|
||||||
private void getData() { |
|
||||||
String str = convertCC(mTvSearch.getText().toString().trim()); |
|
||||||
AccountManager.getInstance().getSearchBookList("", str, page); |
|
||||||
} |
|
||||||
|
|
||||||
//繁簡轉換
|
|
||||||
public String convertCC(String input) { |
|
||||||
if (TextUtils.isEmpty(input) || input.length() == 0) |
|
||||||
return ""; |
|
||||||
return ZHConverter.getInstance(ZHConverter.SIMPLIFIED).convert(input); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initData() { |
|
||||||
//输入框
|
|
||||||
mTvSearch.addTextChangedListener(new TextWatcher() { |
|
||||||
@Override |
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) { |
|
||||||
if (s.toString().trim().equals("")) { |
|
||||||
refreshLayout.setVisibility(View.GONE); |
|
||||||
headHot.setVisibility(View.VISIBLE); |
|
||||||
headHistory.setVisibility(View.VISIBLE); |
|
||||||
mRlvHot.setVisibility(View.VISIBLE); |
|
||||||
mRlvHistory.setVisibility(View.VISIBLE); |
|
||||||
} else { |
|
||||||
refreshLayout.setVisibility(View.VISIBLE); |
|
||||||
headHot.setVisibility(View.GONE); |
|
||||||
headHistory.setVisibility(View.GONE); |
|
||||||
mRlvHot.setVisibility(View.GONE); |
|
||||||
mRlvHistory.setVisibility(View.GONE); |
|
||||||
refreshLayout.showLoading(); |
|
||||||
page = 1; |
|
||||||
getData(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void afterTextChanged(Editable s) { |
|
||||||
|
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
//键盘的搜索
|
|
||||||
mTvSearch.setOnKeyListener((v, keyCode, event) -> { |
|
||||||
//修改回车键功能
|
|
||||||
if (keyCode == KeyEvent.KEYCODE_ENTER) { |
|
||||||
mSearchAdapter.setHolderType(true); |
|
||||||
saveKey(); |
|
||||||
return true; |
|
||||||
} |
|
||||||
return false; |
|
||||||
}); |
|
||||||
|
|
||||||
mHotAdapter.setOnItemClickListener((view, pos) -> { |
|
||||||
mSearchAdapter.setHolderType(true); |
|
||||||
refreshLayout.setVisibility(View.VISIBLE); |
|
||||||
mTvSearch.setText(mHotList.get(pos)); |
|
||||||
saveKey(); |
|
||||||
}); |
|
||||||
|
|
||||||
mHisAdapter.setOnItemClickListener((view, pos) -> { |
|
||||||
mSearchAdapter.setHolderType(true); |
|
||||||
refreshLayout.setVisibility(View.VISIBLE); |
|
||||||
mTvSearch.setText(mHisList.get(pos).getKey()); |
|
||||||
saveKey(); |
|
||||||
}); |
|
||||||
|
|
||||||
mSearchAdapter.setOnItemClickListener((view, pos) -> { |
|
||||||
mSearchAdapter.setHolderType(true); |
|
||||||
mTvSearch.setText(mSearchList.get(pos).getTitle()); |
|
||||||
saveKey(); |
|
||||||
}); |
|
||||||
headHistory.setOnClickListener(view -> DialogUtils.getInstance() |
|
||||||
.showAlertDialog(NovelSearchActivity.this, |
|
||||||
getString(R.string.clear_search), (dialogInterface, i) -> { |
|
||||||
LitePal.deleteAll(SearchListTable.class); |
|
||||||
mHisList.clear(); |
|
||||||
mHisList.addAll(LitePal.order("saveTime desc").limit(5).find(SearchListTable.class)); |
|
||||||
mHisAdapter.notifyDataSetChanged(); |
|
||||||
})); |
|
||||||
|
|
||||||
refreshLayout.setOnReloadingListener(new RefreshLayout.OnReloadingListener() { |
|
||||||
@Override |
|
||||||
public void onReload() { |
|
||||||
getData(); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
private void saveKey() { |
|
||||||
if (mTvSearch.getText().toString().trim().equals("")) { |
|
||||||
return; |
|
||||||
} |
|
||||||
SearchListTable searchListTable = new SearchListTable(); |
|
||||||
searchListTable.setKey(mTvSearch.getText().toString().trim()); |
|
||||||
searchListTable.setSaveTime(System.currentTimeMillis()); |
|
||||||
searchListTable.saveOrUpdate("key=?", mTvSearch.getText().toString().trim()); |
|
||||||
mHisList.clear(); |
|
||||||
mHisList.addAll(LitePal.order("saveTime desc").limit(5).find(SearchListTable.class)); |
|
||||||
mHisAdapter.notifyDataSetChanged(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onBackPressed() { |
|
||||||
if (refreshLayout.getVisibility() == View.VISIBLE) { |
|
||||||
mTvSearch.setText(""); |
|
||||||
mSearchAdapter.setHolderType(false); |
|
||||||
page = 1; |
|
||||||
} else { |
|
||||||
super.onBackPressed(); |
|
||||||
overridePendingTransition(R.anim.message_fade_in, R.anim.message_fade_out); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@OnClick(R.id.tv_cancel) |
|
||||||
public void onViewClicked() { |
|
||||||
onBackPressed(); |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void getHotSearch(HotSearchEvent event) { |
|
||||||
|
|
||||||
if (event.isFail()) { |
|
||||||
|
|
||||||
} else { |
|
||||||
mHotList.clear(); |
|
||||||
mHotList.addAll(event.getResult().getKey()); |
|
||||||
mHotAdapter.notifyDataSetChanged(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void getSearchList(SearchListEvent event) { |
|
||||||
refreshLayout.showFinish(); |
|
||||||
if (event.isFail()) { |
|
||||||
refreshLayout.showError(); |
|
||||||
} else { |
|
||||||
loadSize = event.getResult().getBook().size(); |
|
||||||
if (mSearchAdapter.isLoadingMore()){ |
|
||||||
mSearchList.remove(mSearchList.size() - 1); |
|
||||||
mSearchList.addAll(event.getResult().getBook()); |
|
||||||
mSearchAdapter.notifyDataSetChanged(); |
|
||||||
mSearchAdapter.setLoadingMore(false); |
|
||||||
}else { |
|
||||||
mSearchList.clear(); |
|
||||||
mSearchList.addAll(event.getResult().getBook()); |
|
||||||
mSearchAdapter.notifyDataSetChanged(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onDestroy() { |
|
||||||
super.onDestroy(); |
|
||||||
EventManager.Companion.getInstance().unregisterSubscriber(this); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,251 @@ |
|||||||
|
package com.novel.read.activity |
||||||
|
|
||||||
|
import android.text.Editable |
||||||
|
import android.text.TextUtils |
||||||
|
import android.text.TextWatcher |
||||||
|
import android.view.KeyEvent |
||||||
|
import android.view.View |
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager |
||||||
|
import com.google.android.flexbox.AlignItems |
||||||
|
import com.google.android.flexbox.FlexDirection |
||||||
|
import com.google.android.flexbox.FlexWrap |
||||||
|
import com.google.android.flexbox.FlexboxLayoutManager |
||||||
|
import com.mango.mangolib.event.EventManager |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.adapter.HistoryAdapter |
||||||
|
import com.novel.read.adapter.HotAdapter |
||||||
|
import com.novel.read.adapter.SearchAdapter |
||||||
|
import com.novel.read.base.NovelBaseActivity |
||||||
|
import com.novel.read.constants.Constant.COMMENT_SIZE |
||||||
|
import com.novel.read.event.HotSearchEvent |
||||||
|
import com.novel.read.event.SearchListEvent |
||||||
|
import com.novel.read.http.AccountManager |
||||||
|
import com.novel.read.inter.OnLoadMoreListener |
||||||
|
import com.novel.read.model.db.SearchListTable |
||||||
|
import com.novel.read.model.protocol.SearchResp |
||||||
|
import com.novel.read.utlis.DialogUtils |
||||||
|
import com.spreada.utils.chinese.ZHConverter |
||||||
|
import com.squareup.otto.Subscribe |
||||||
|
import kotlinx.android.synthetic.main.activity_search.* |
||||||
|
import kotlinx.android.synthetic.main.title_search.* |
||||||
|
import org.litepal.LitePal |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
class NovelSearchActivity : NovelBaseActivity() { |
||||||
|
|
||||||
|
private val mHotList = ArrayList<String>() |
||||||
|
private var mHotAdapter: HotAdapter? = null |
||||||
|
|
||||||
|
private var mHisList: MutableList<SearchListTable> = ArrayList() |
||||||
|
private var mHisAdapter: HistoryAdapter? = null |
||||||
|
|
||||||
|
private val mSearchList = ArrayList<SearchResp.BookBean>() |
||||||
|
private var mSearchAdapter: SearchAdapter? = null |
||||||
|
|
||||||
|
private var page = 1 |
||||||
|
private var loadSize: Int = 0 |
||||||
|
|
||||||
|
override val layoutId: Int get() = R.layout.activity_search |
||||||
|
|
||||||
|
override fun initView() { |
||||||
|
EventManager.instance.registerSubscriber(this) |
||||||
|
|
||||||
|
val manager = FlexboxLayoutManager(this) |
||||||
|
//设置主轴排列方式 |
||||||
|
manager.flexDirection = FlexDirection.ROW |
||||||
|
//设置是否换行 |
||||||
|
manager.flexWrap = FlexWrap.WRAP |
||||||
|
manager.alignItems = AlignItems.STRETCH |
||||||
|
rlv_hot.layoutManager = manager |
||||||
|
mHotAdapter = HotAdapter(mHotList) |
||||||
|
rlv_hot.adapter = mHotAdapter |
||||||
|
|
||||||
|
mHisList = LitePal.order("saveTime desc").limit(5).find(SearchListTable::class.java) |
||||||
|
val manager2 = FlexboxLayoutManager(this) |
||||||
|
//设置主轴排列方式 |
||||||
|
manager2.flexDirection = FlexDirection.ROW |
||||||
|
//设置是否换行 |
||||||
|
manager2.flexWrap = FlexWrap.WRAP |
||||||
|
manager2.alignItems = AlignItems.STRETCH |
||||||
|
mHisAdapter = HistoryAdapter(mHisList) |
||||||
|
rlv_history.layoutManager = manager2 |
||||||
|
rlv_history.adapter = mHisAdapter |
||||||
|
|
||||||
|
rlv_search.layoutManager = LinearLayoutManager(this) |
||||||
|
mSearchAdapter = SearchAdapter(mSearchList, rlv_search) |
||||||
|
rlv_search.adapter = mSearchAdapter |
||||||
|
|
||||||
|
mSearchAdapter!!.setOnLoadMoreListener(object : OnLoadMoreListener { |
||||||
|
override fun onLoadMore() { |
||||||
|
if (mSearchAdapter!!.isLoadingMore) { |
||||||
|
|
||||||
|
} else { |
||||||
|
if (loadSize >= COMMENT_SIZE) { |
||||||
|
mSearchAdapter!!.isLoadingMore = true |
||||||
|
mSearchList.add(SearchResp.BookBean()) |
||||||
|
mSearchAdapter!!.notifyDataSetChanged() |
||||||
|
page++ |
||||||
|
getData() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}) |
||||||
|
|
||||||
|
AccountManager.getInstance().getHotSearch() |
||||||
|
} |
||||||
|
|
||||||
|
private fun getData() { |
||||||
|
val str = convertCC(tv_search.text.toString().trim { it <= ' ' }) |
||||||
|
AccountManager.getInstance().getSearchBookList("", str, page) |
||||||
|
} |
||||||
|
|
||||||
|
//繁簡轉換 |
||||||
|
fun convertCC(input: String): String { |
||||||
|
return if (TextUtils.isEmpty(input) || input.isEmpty()) "" else ZHConverter.getInstance( |
||||||
|
ZHConverter.SIMPLIFIED |
||||||
|
).convert(input) |
||||||
|
} |
||||||
|
|
||||||
|
override fun initData() { |
||||||
|
//输入框 |
||||||
|
tv_search.addTextChangedListener(object : TextWatcher { |
||||||
|
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { |
||||||
|
if (s.toString().trim { it <= ' ' } == "") { |
||||||
|
refresh.visibility = View.GONE |
||||||
|
head_hot.visibility = View.VISIBLE |
||||||
|
head_history.visibility = View.VISIBLE |
||||||
|
rlv_hot.visibility = View.VISIBLE |
||||||
|
rlv_history.visibility = View.VISIBLE |
||||||
|
} else { |
||||||
|
refresh.visibility = View.VISIBLE |
||||||
|
head_hot.visibility = View.GONE |
||||||
|
head_history.visibility = View.GONE |
||||||
|
rlv_hot.visibility = View.GONE |
||||||
|
rlv_history.visibility = View.GONE |
||||||
|
refresh.showLoading() |
||||||
|
page = 1 |
||||||
|
getData() |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
override fun afterTextChanged(s: Editable) { |
||||||
|
|
||||||
|
} |
||||||
|
}) |
||||||
|
|
||||||
|
//键盘的搜索 |
||||||
|
tv_search.setOnKeyListener { v, keyCode, event -> |
||||||
|
//修改回车键功能 |
||||||
|
if (keyCode == KeyEvent.KEYCODE_ENTER) { |
||||||
|
mSearchAdapter!!.setHolderType(true) |
||||||
|
saveKey() |
||||||
|
return@setOnKeyListener true |
||||||
|
} |
||||||
|
false |
||||||
|
} |
||||||
|
|
||||||
|
mHotAdapter!!.setOnItemClickListener { view, pos -> |
||||||
|
mSearchAdapter!!.setHolderType(true) |
||||||
|
refresh.visibility = View.VISIBLE |
||||||
|
tv_search.setText(mHotList[pos]) |
||||||
|
saveKey() |
||||||
|
} |
||||||
|
|
||||||
|
mHisAdapter!!.setOnItemClickListener { view, pos -> |
||||||
|
mSearchAdapter!!.setHolderType(true) |
||||||
|
refresh.visibility = View.VISIBLE |
||||||
|
tv_search.setText(mHisList[pos].key) |
||||||
|
saveKey() |
||||||
|
} |
||||||
|
|
||||||
|
mSearchAdapter!!.setOnItemClickListener { view, pos -> |
||||||
|
mSearchAdapter!!.setHolderType(true) |
||||||
|
tv_search.setText(mSearchList[pos].title) |
||||||
|
saveKey() |
||||||
|
} |
||||||
|
head_history.setOnClickListener { view -> |
||||||
|
DialogUtils.getInstance() |
||||||
|
.showAlertDialog( |
||||||
|
this@NovelSearchActivity, |
||||||
|
getString(R.string.clear_search) |
||||||
|
) { dialogInterface, i -> |
||||||
|
LitePal.deleteAll(SearchListTable::class.java) |
||||||
|
mHisList.clear() |
||||||
|
mHisList.addAll(LitePal.order("saveTime desc").limit(5).find(SearchListTable::class.java)) |
||||||
|
mHisAdapter!!.notifyDataSetChanged() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
tv_cancel.setOnClickListener { |
||||||
|
onBackPressed() |
||||||
|
} |
||||||
|
|
||||||
|
refresh.setOnReloadingListener { getData() } |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private fun saveKey() { |
||||||
|
if (tv_search.text.toString().trim { it <= ' ' } == "") { |
||||||
|
return |
||||||
|
} |
||||||
|
val searchListTable = SearchListTable() |
||||||
|
searchListTable.key = tv_search.text.toString().trim { it <= ' ' } |
||||||
|
searchListTable.saveTime = System.currentTimeMillis() |
||||||
|
searchListTable.saveOrUpdate("key=?", tv_search.text.toString().trim { it <= ' ' }) |
||||||
|
mHisList.clear() |
||||||
|
mHisList.addAll(LitePal.order("saveTime desc").limit(5).find(SearchListTable::class.java)) |
||||||
|
mHisAdapter!!.notifyDataSetChanged() |
||||||
|
} |
||||||
|
|
||||||
|
override fun onBackPressed() { |
||||||
|
if (refresh.visibility == View.VISIBLE) { |
||||||
|
tv_search.setText("") |
||||||
|
mSearchAdapter!!.setHolderType(false) |
||||||
|
page = 1 |
||||||
|
} else { |
||||||
|
super.onBackPressed() |
||||||
|
overridePendingTransition(R.anim.message_fade_in, R.anim.message_fade_out) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun getHotSearch(event: HotSearchEvent) { |
||||||
|
if (event.isFail) { |
||||||
|
|
||||||
|
} else { |
||||||
|
mHotList.clear() |
||||||
|
mHotList.addAll(event.result!!.key) |
||||||
|
mHotAdapter!!.notifyDataSetChanged() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun getSearchList(event: SearchListEvent) { |
||||||
|
refresh.showFinish() |
||||||
|
if (event.isFail) { |
||||||
|
refresh.showError() |
||||||
|
} else { |
||||||
|
loadSize = event.result!!.book.size |
||||||
|
if (mSearchAdapter!!.isLoadingMore) { |
||||||
|
mSearchList.removeAt(mSearchList.size - 1) |
||||||
|
mSearchList.addAll(event.result!!.book) |
||||||
|
mSearchAdapter!!.notifyDataSetChanged() |
||||||
|
mSearchAdapter!!.isLoadingMore = false |
||||||
|
} else { |
||||||
|
mSearchList.clear() |
||||||
|
mSearchList.addAll(event.result!!.book) |
||||||
|
mSearchAdapter!!.notifyDataSetChanged() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onDestroy() { |
||||||
|
super.onDestroy() |
||||||
|
EventManager.instance.unregisterSubscriber(this) |
||||||
|
} |
||||||
|
} |
@ -1,174 +0,0 @@ |
|||||||
package com.novel.read.activity; |
|
||||||
|
|
||||||
import android.annotation.SuppressLint; |
|
||||||
import android.app.AlertDialog; |
|
||||||
import android.os.Bundle; |
|
||||||
import android.text.TextUtils; |
|
||||||
import android.view.View; |
|
||||||
import android.widget.TextView; |
|
||||||
|
|
||||||
import androidx.appcompat.widget.Toolbar; |
|
||||||
|
|
||||||
import com.allenliu.versionchecklib.v2.AllenVersionChecker; |
|
||||||
import com.allenliu.versionchecklib.v2.builder.DownloadBuilder; |
|
||||||
import com.allenliu.versionchecklib.v2.builder.UIData; |
|
||||||
import com.mango.mangolib.event.EventManager; |
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.base.NovelBaseActivity; |
|
||||||
import com.novel.read.constants.Constant; |
|
||||||
import com.novel.read.event.UpdateBookEvent; |
|
||||||
import com.novel.read.event.VersionEvent; |
|
||||||
import com.novel.read.http.AccountManager; |
|
||||||
import com.novel.read.model.protocol.VersionResp; |
|
||||||
import com.novel.read.utlis.CleanCacheUtils; |
|
||||||
import com.novel.read.utlis.LocalManageUtil; |
|
||||||
import com.novel.read.utlis.SpUtil; |
|
||||||
import com.novel.read.utlis.VersionUtil; |
|
||||||
import com.squareup.otto.Subscribe; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
import butterknife.OnClick; |
|
||||||
|
|
||||||
public class NovelSettingActivity extends NovelBaseActivity { |
|
||||||
|
|
||||||
@BindView(R.id.toolbar) |
|
||||||
Toolbar toolbar; |
|
||||||
@BindView(R.id.tv_language) |
|
||||||
TextView mTvLanguage; |
|
||||||
@BindView(R.id.tv_cache_num) |
|
||||||
TextView mTvCacheNum; |
|
||||||
@BindView(R.id.tv_version) |
|
||||||
TextView mTvVersion; |
|
||||||
@BindView(R.id.tv_check) |
|
||||||
TextView mTvCheck; |
|
||||||
private VersionResp resp; |
|
||||||
@Override |
|
||||||
protected void onCreate(Bundle savedInstanceState) { |
|
||||||
super.onCreate(savedInstanceState); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected int getLayoutId() { |
|
||||||
return R.layout.activity_setting; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initView() { |
|
||||||
EventManager.Companion.getInstance().registerSubscriber(this); |
|
||||||
} |
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n") |
|
||||||
@Override |
|
||||||
protected void initData() { |
|
||||||
mTvLanguage.setText(getResources().getStringArray(R.array.setting_dialog_language_choice)[SpUtil.getIntValue(Constant.Language, 1)]); |
|
||||||
mTvVersion.setText("V" + VersionUtil.getPackageName(this)); |
|
||||||
try { |
|
||||||
final String cacheSize = CleanCacheUtils.getInstance().getTotalCacheSize(NovelSettingActivity.this); |
|
||||||
mTvCacheNum.setText(cacheSize); |
|
||||||
} catch (Exception e) { |
|
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
|
|
||||||
toolbar.setNavigationOnClickListener(view -> finish()); |
|
||||||
|
|
||||||
AccountManager.getInstance().checkVersion(VersionUtil.getPackageCode(this)); |
|
||||||
} |
|
||||||
|
|
||||||
@OnClick({R.id.ll_choose_language, R.id.ll_clear_cache, R.id.tv_check}) |
|
||||||
public void onViewClicked(View view) { |
|
||||||
switch (view.getId()) { |
|
||||||
case R.id.ll_choose_language: |
|
||||||
showLanguageDialog(); |
|
||||||
break; |
|
||||||
case R.id.ll_clear_cache: |
|
||||||
//默认不勾选清空书架列表,防手抖!!
|
|
||||||
final boolean[] selected = {true, false}; |
|
||||||
new AlertDialog.Builder(this) |
|
||||||
.setTitle(getString(R.string.clear_cache)) |
|
||||||
.setCancelable(true) |
|
||||||
.setMultiChoiceItems(new String[]{getString(R.string.clear_cache), getString(R.string.clear_book)}, selected, (dialog, which, isChecked) -> selected[which] = isChecked) |
|
||||||
.setPositiveButton(getString(R.string.sure), (dialog, which) -> { |
|
||||||
new Thread(() -> { |
|
||||||
CleanCacheUtils.getInstance().clearCache(selected[0], selected[1], NovelSettingActivity.this); |
|
||||||
String cacheSize = ""; |
|
||||||
try { |
|
||||||
cacheSize = CleanCacheUtils.getInstance().getTotalCacheSize(NovelSettingActivity.this); |
|
||||||
} catch (Exception e) { |
|
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
String finalCacheSize = cacheSize; |
|
||||||
runOnUiThread(() -> { |
|
||||||
EventManager.Companion.getInstance().postEvent(new UpdateBookEvent()); |
|
||||||
mTvCacheNum.setText(finalCacheSize); |
|
||||||
}); |
|
||||||
}).start(); |
|
||||||
dialog.dismiss(); |
|
||||||
}) |
|
||||||
.setNegativeButton(getString(R.string.cancel), (dialog, which) -> dialog.dismiss()) |
|
||||||
.create().show(); |
|
||||||
break; |
|
||||||
case R.id.tv_check: |
|
||||||
//版本大小不为空 去更新。
|
|
||||||
updateApk(resp); |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public void showLanguageDialog() { |
|
||||||
new AlertDialog.Builder(this) |
|
||||||
.setTitle(getString(R.string.choose_language)) |
|
||||||
.setSingleChoiceItems(getResources().getStringArray(R.array.setting_dialog_language_choice), |
|
||||||
SpUtil.getIntValue(Constant.Language, 1), |
|
||||||
(dialog, which) -> { |
|
||||||
String language = getResources().getStringArray(R.array.setting_dialog_language_choice)[which]; |
|
||||||
mTvLanguage.setText(language); |
|
||||||
SpUtil.setIntValue(Constant.Language, which); |
|
||||||
dialog.dismiss(); |
|
||||||
|
|
||||||
if (which == 0) { |
|
||||||
selectLanguage(0); |
|
||||||
} else { |
|
||||||
selectLanguage(1); |
|
||||||
} |
|
||||||
}) |
|
||||||
.create().show(); |
|
||||||
} |
|
||||||
|
|
||||||
private void selectLanguage(int select) { |
|
||||||
LocalManageUtil.saveSelectLanguage(this, select); |
|
||||||
NovelMainActivity.reStart(this); |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void checkVersion(VersionEvent event){ |
|
||||||
if (event.isFail()){ |
|
||||||
|
|
||||||
}else { |
|
||||||
if (TextUtils.isEmpty(event.getResult().getVersion().getSize())){ |
|
||||||
return; |
|
||||||
} |
|
||||||
resp = event.getResult(); |
|
||||||
mTvCheck.setVisibility(View.VISIBLE); |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void updateApk(VersionResp resp){ |
|
||||||
VersionResp.VersionBean versionBean = resp.getVersion(); |
|
||||||
DownloadBuilder builder = AllenVersionChecker |
|
||||||
.getInstance() |
|
||||||
.downloadOnly(UIData.create() |
|
||||||
.setTitle(getString(R.string.new_version,versionBean.getVersion())) |
|
||||||
.setContent(versionBean.getContent()) |
|
||||||
.setDownloadUrl(versionBean.getDownload()) |
|
||||||
); |
|
||||||
builder.executeMission(this); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onDestroy() { |
|
||||||
super.onDestroy(); |
|
||||||
EventManager.Companion.getInstance().unregisterSubscriber(this); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,154 @@ |
|||||||
|
package com.novel.read.activity |
||||||
|
|
||||||
|
import android.annotation.SuppressLint |
||||||
|
import android.app.AlertDialog |
||||||
|
import android.text.TextUtils |
||||||
|
import android.view.View |
||||||
|
import com.allenliu.versionchecklib.v2.AllenVersionChecker |
||||||
|
import com.allenliu.versionchecklib.v2.builder.UIData |
||||||
|
import com.mango.mangolib.event.EventManager |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.base.NovelBaseActivity |
||||||
|
import com.novel.read.constants.Constant |
||||||
|
import com.novel.read.event.UpdateBookEvent |
||||||
|
import com.novel.read.event.VersionEvent |
||||||
|
import com.novel.read.http.AccountManager |
||||||
|
import com.novel.read.model.protocol.VersionResp |
||||||
|
import com.novel.read.utlis.CleanCacheUtils |
||||||
|
import com.novel.read.utlis.LocalManageUtil |
||||||
|
import com.novel.read.utlis.SpUtil |
||||||
|
import com.novel.read.utlis.VersionUtil |
||||||
|
import com.squareup.otto.Subscribe |
||||||
|
import kotlinx.android.synthetic.main.activity_setting.* |
||||||
|
|
||||||
|
class NovelSettingActivity : NovelBaseActivity(), View.OnClickListener { |
||||||
|
|
||||||
|
private var resp: VersionResp? = null |
||||||
|
|
||||||
|
override val layoutId: Int get() = R.layout.activity_setting |
||||||
|
|
||||||
|
override fun initView() { |
||||||
|
EventManager.instance.registerSubscriber(this) |
||||||
|
} |
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n") |
||||||
|
override fun initData() { |
||||||
|
tv_language.text = resources.getStringArray(R.array.setting_dialog_language_choice)[SpUtil.getIntValue(Constant.Language, 1)] |
||||||
|
tv_version.text = "V" + VersionUtil.getPackageName(this)!! |
||||||
|
try { |
||||||
|
val cacheSize = CleanCacheUtils.getInstance().getTotalCacheSize(this@NovelSettingActivity) |
||||||
|
tv_cache_num.text = cacheSize |
||||||
|
} catch (e: Exception) { |
||||||
|
e.printStackTrace() |
||||||
|
} |
||||||
|
toolbar.setNavigationOnClickListener { finish() } |
||||||
|
AccountManager.getInstance().checkVersion(VersionUtil.getPackageCode(this)) |
||||||
|
|
||||||
|
ll_choose_language.setOnClickListener(this) |
||||||
|
ll_clear_cache.setOnClickListener(this) |
||||||
|
tv_check.setOnClickListener(this) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onClick(v: View?) { |
||||||
|
when (v?.id) { |
||||||
|
R.id.ll_choose_language -> showLanguageDialog() |
||||||
|
R.id.ll_clear_cache -> { |
||||||
|
//默认不勾选清空书架列表,防手抖!! |
||||||
|
val selected = booleanArrayOf(true, false) |
||||||
|
AlertDialog.Builder(this) |
||||||
|
.setTitle(getString(R.string.clear_cache)) |
||||||
|
.setCancelable(true) |
||||||
|
.setMultiChoiceItems( |
||||||
|
arrayOf( |
||||||
|
getString(R.string.clear_cache), |
||||||
|
getString(R.string.clear_book) |
||||||
|
), selected |
||||||
|
) { _, which, isChecked -> selected[which] = isChecked } |
||||||
|
.setPositiveButton(getString(R.string.sure)) { dialog, _ -> |
||||||
|
Thread { |
||||||
|
CleanCacheUtils.getInstance() |
||||||
|
.clearCache(selected[0], selected[1], this@NovelSettingActivity) |
||||||
|
var cacheSize = "" |
||||||
|
try { |
||||||
|
cacheSize = |
||||||
|
CleanCacheUtils.getInstance() |
||||||
|
.getTotalCacheSize(this@NovelSettingActivity) |
||||||
|
} catch (e: Exception) { |
||||||
|
e.printStackTrace() |
||||||
|
} |
||||||
|
val finalCacheSize = cacheSize |
||||||
|
runOnUiThread { |
||||||
|
EventManager.instance.postEvent(UpdateBookEvent()) |
||||||
|
tv_cache_num.text = finalCacheSize |
||||||
|
} |
||||||
|
}.start() |
||||||
|
dialog.dismiss() |
||||||
|
} |
||||||
|
.setNegativeButton(getString(R.string.cancel)) { dialog, which -> dialog.dismiss() } |
||||||
|
.create().show() |
||||||
|
} |
||||||
|
R.id.tv_check -> |
||||||
|
//版本大小不为空 去更新。 |
||||||
|
updateApk(resp!!) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private fun showLanguageDialog() { |
||||||
|
AlertDialog.Builder(this) |
||||||
|
.setTitle(getString(R.string.choose_language)) |
||||||
|
.setSingleChoiceItems( |
||||||
|
resources.getStringArray(R.array.setting_dialog_language_choice), |
||||||
|
SpUtil.getIntValue(Constant.Language, 1) |
||||||
|
) { dialog, which -> |
||||||
|
val language = |
||||||
|
resources.getStringArray(R.array.setting_dialog_language_choice)[which] |
||||||
|
tv_language.text = language |
||||||
|
SpUtil.setIntValue(Constant.Language, which) |
||||||
|
dialog.dismiss() |
||||||
|
|
||||||
|
if (which == 0) { |
||||||
|
selectLanguage(0) |
||||||
|
} else { |
||||||
|
selectLanguage(1) |
||||||
|
} |
||||||
|
} |
||||||
|
.create().show() |
||||||
|
} |
||||||
|
|
||||||
|
private fun selectLanguage(select: Int) { |
||||||
|
LocalManageUtil.saveSelectLanguage(this, select) |
||||||
|
NovelMainActivity.reStart(this) |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun checkVersion(event: VersionEvent) { |
||||||
|
if (event.isFail) { |
||||||
|
|
||||||
|
} else { |
||||||
|
if (TextUtils.isEmpty(event.result!!.version.size)) { |
||||||
|
return |
||||||
|
} |
||||||
|
resp = event.result |
||||||
|
tv_check.visibility = View.VISIBLE |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private fun updateApk(resp: VersionResp) { |
||||||
|
val versionBean = resp.version |
||||||
|
val builder = AllenVersionChecker |
||||||
|
.getInstance() |
||||||
|
.downloadOnly( |
||||||
|
UIData.create() |
||||||
|
.setTitle(getString(R.string.new_version, versionBean.version)) |
||||||
|
.setContent(versionBean.content) |
||||||
|
.setDownloadUrl(versionBean.download) |
||||||
|
) |
||||||
|
builder.executeMission(this) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onDestroy() { |
||||||
|
super.onDestroy() |
||||||
|
EventManager.instance.unregisterSubscriber(this) |
||||||
|
} |
||||||
|
} |
@ -1,102 +0,0 @@ |
|||||||
package com.novel.read.activity; |
|
||||||
|
|
||||||
import android.content.Intent; |
|
||||||
import android.os.Bundle; |
|
||||||
import android.view.View; |
|
||||||
import android.widget.TextView; |
|
||||||
|
|
||||||
import androidx.annotation.NonNull; |
|
||||||
import androidx.appcompat.app.AppCompatActivity; |
|
||||||
|
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.utlis.PermissionUtil; |
|
||||||
import com.novel.read.utlis.StatusBarUtil; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
import butterknife.ButterKnife; |
|
||||||
import butterknife.Unbinder; |
|
||||||
|
|
||||||
public class NovelSplashActivity extends AppCompatActivity implements PermissionUtil.PermissionCallBack { |
|
||||||
@BindView(R.id.tvSkip) |
|
||||||
TextView tvSkip; |
|
||||||
|
|
||||||
private boolean flag = false; |
|
||||||
private Runnable runnable; |
|
||||||
|
|
||||||
protected PermissionUtil mPermissionUtil; |
|
||||||
private static final int PERMISSION_CODE = 999; |
|
||||||
private Unbinder unbinder; |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onCreate(Bundle savedInstanceState) { |
|
||||||
super.onCreate(savedInstanceState); |
|
||||||
StatusBarUtil.setBarsStyle(this, R.color.colorPrimary, true); |
|
||||||
setContentView(R.layout.activity_splash); |
|
||||||
unbinder = ButterKnife.bind(this); |
|
||||||
|
|
||||||
mPermissionUtil = PermissionUtil.getInstance(); |
|
||||||
mPermissionUtil.requestPermissions(this, PERMISSION_CODE, this); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
|
||||||
mPermissionUtil.requestResult(this, permissions, grantResults, this); |
|
||||||
} |
|
||||||
|
|
||||||
private void init() { |
|
||||||
runnable = new Runnable() { |
|
||||||
@Override |
|
||||||
public void run() { |
|
||||||
goHome(); |
|
||||||
} |
|
||||||
}; |
|
||||||
tvSkip.postDelayed(runnable, 2000); |
|
||||||
tvSkip.setOnClickListener(new View.OnClickListener() { |
|
||||||
@Override |
|
||||||
public void onClick(View v) { |
|
||||||
goHome(); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
private synchronized void goHome() { |
|
||||||
if (!flag) { |
|
||||||
flag = true; |
|
||||||
startActivity(new Intent(this, NovelMainActivity.class)); |
|
||||||
finish(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onDestroy() { |
|
||||||
super.onDestroy(); |
|
||||||
flag = true; |
|
||||||
tvSkip.removeCallbacks(runnable); |
|
||||||
unbinder.unbind(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onResume() { |
|
||||||
super.onResume(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onPause() { |
|
||||||
super.onPause(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onPermissionSuccess() { |
|
||||||
init(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onPermissionReject(String strMessage) { |
|
||||||
finish(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onPermissionFail() { |
|
||||||
mPermissionUtil.requestPermissions(this, PERMISSION_CODE,this); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,69 @@ |
|||||||
|
package com.novel.read.activity |
||||||
|
|
||||||
|
import android.content.Intent |
||||||
|
import android.os.Bundle |
||||||
|
import androidx.appcompat.app.AppCompatActivity |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.utlis.PermissionUtil |
||||||
|
import com.novel.read.utlis.StatusBarUtil |
||||||
|
import kotlinx.android.synthetic.main.activity_splash.* |
||||||
|
|
||||||
|
class NovelSplashActivity : AppCompatActivity(), PermissionUtil.PermissionCallBack { |
||||||
|
|
||||||
|
private var flag = false |
||||||
|
private var runnable: Runnable? = null |
||||||
|
|
||||||
|
private var mPermissionUtil: PermissionUtil = PermissionUtil.getInstance() |
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) { |
||||||
|
super.onCreate(savedInstanceState) |
||||||
|
StatusBarUtil.setBarsStyle(this, R.color.colorPrimary, true) |
||||||
|
setContentView(R.layout.activity_splash) |
||||||
|
mPermissionUtil.requestPermissions(this, PERMISSION_CODE, this) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onRequestPermissionsResult( |
||||||
|
requestCode: Int, |
||||||
|
permissions: Array<String>, |
||||||
|
grantResults: IntArray |
||||||
|
) { |
||||||
|
mPermissionUtil.requestResult(this, permissions, grantResults, this) |
||||||
|
} |
||||||
|
|
||||||
|
private fun init() { |
||||||
|
runnable = Runnable { goHome() } |
||||||
|
tvSkip.postDelayed(runnable, 2000) |
||||||
|
tvSkip.setOnClickListener { goHome() } |
||||||
|
} |
||||||
|
|
||||||
|
@Synchronized |
||||||
|
private fun goHome() { |
||||||
|
if (!flag) { |
||||||
|
flag = true |
||||||
|
startActivity(Intent(this, NovelMainActivity::class.java)) |
||||||
|
finish() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onDestroy() { |
||||||
|
super.onDestroy() |
||||||
|
flag = true |
||||||
|
tvSkip.removeCallbacks(runnable) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onPermissionSuccess() { |
||||||
|
init() |
||||||
|
} |
||||||
|
|
||||||
|
override fun onPermissionReject(strMessage: String) { |
||||||
|
finish() |
||||||
|
} |
||||||
|
|
||||||
|
override fun onPermissionFail() { |
||||||
|
mPermissionUtil.requestPermissions(this, PERMISSION_CODE, this) |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
private val PERMISSION_CODE = 999 |
||||||
|
} |
||||||
|
} |
@ -1,26 +0,0 @@ |
|||||||
package com.novel.read.base; |
|
||||||
|
|
||||||
import android.app.Service; |
|
||||||
|
|
||||||
import io.reactivex.disposables.CompositeDisposable; |
|
||||||
import io.reactivex.disposables.Disposable; |
|
||||||
|
|
||||||
public abstract class BaseService extends Service { |
|
||||||
|
|
||||||
private CompositeDisposable mDisposable; |
|
||||||
|
|
||||||
protected void addDisposable(Disposable disposable){ |
|
||||||
if (mDisposable == null){ |
|
||||||
mDisposable = new CompositeDisposable(); |
|
||||||
} |
|
||||||
mDisposable.add(disposable); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onDestroy() { |
|
||||||
super.onDestroy(); |
|
||||||
if (mDisposable != null){ |
|
||||||
mDisposable.dispose(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,25 @@ |
|||||||
|
package com.novel.read.base |
||||||
|
|
||||||
|
import android.app.Service |
||||||
|
|
||||||
|
import io.reactivex.disposables.CompositeDisposable |
||||||
|
import io.reactivex.disposables.Disposable |
||||||
|
|
||||||
|
abstract class BaseService : Service() { |
||||||
|
|
||||||
|
private var mDisposable: CompositeDisposable? = null |
||||||
|
|
||||||
|
protected fun addDisposable(disposable: Disposable) { |
||||||
|
if (mDisposable == null) { |
||||||
|
mDisposable = CompositeDisposable() |
||||||
|
} |
||||||
|
mDisposable!!.add(disposable) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onDestroy() { |
||||||
|
super.onDestroy() |
||||||
|
if (mDisposable != null) { |
||||||
|
mDisposable!!.dispose() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,71 +0,0 @@ |
|||||||
package com.novel.read.base; |
|
||||||
|
|
||||||
import android.app.Application; |
|
||||||
|
|
||||||
import android.content.Context; |
|
||||||
import android.content.Intent; |
|
||||||
import android.content.res.Configuration; |
|
||||||
import android.util.Log; |
|
||||||
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatDelegate; |
|
||||||
|
|
||||||
import com.novel.read.constants.Constant; |
|
||||||
import com.novel.read.service.DownloadService; |
|
||||||
import com.novel.read.utlis.LocalManageUtil; |
|
||||||
import com.novel.read.utlis.SpUtil; |
|
||||||
import com.tencent.bugly.crashreport.CrashReport; |
|
||||||
|
|
||||||
|
|
||||||
import org.litepal.LitePal; |
|
||||||
|
|
||||||
/** |
|
||||||
* create by 赵利君 on 2019/6/10 |
|
||||||
* describe: |
|
||||||
*/ |
|
||||||
public class MyApp extends Application { |
|
||||||
|
|
||||||
private static Context sInstance; |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onCreate() { |
|
||||||
super.onCreate(); |
|
||||||
sInstance = this; |
|
||||||
LitePal.initialize(this); |
|
||||||
setNight(); |
|
||||||
LocalManageUtil.setApplicationLanguage(this); |
|
||||||
startService(new Intent(getContext(), DownloadService.class)); |
|
||||||
CrashReport.initCrashReport(getApplicationContext(), Constant.buglyId, false); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
private void setNight() { |
|
||||||
if (SpUtil.getBooleanValue(Constant.NIGHT, false)) { |
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); |
|
||||||
} else { |
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static Context getContext() { |
|
||||||
return sInstance; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
protected void attachBaseContext(Context base) { |
|
||||||
SpUtil.init(base); |
|
||||||
//保存系统选择语言
|
|
||||||
LocalManageUtil.saveSystemCurrentLanguage(base); |
|
||||||
super.attachBaseContext(LocalManageUtil.setLocal(base)); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onConfigurationChanged(Configuration newConfig) { |
|
||||||
super.onConfigurationChanged(newConfig); |
|
||||||
//保存系统选择语言
|
|
||||||
LocalManageUtil.onConfigurationChanged(getApplicationContext()); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,65 @@ |
|||||||
|
package com.novel.read.base |
||||||
|
|
||||||
|
import android.app.Application |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.content.Intent |
||||||
|
import android.content.res.Configuration |
||||||
|
import android.util.Log |
||||||
|
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate |
||||||
|
|
||||||
|
import com.novel.read.constants.Constant |
||||||
|
import com.novel.read.service.DownloadService |
||||||
|
import com.novel.read.utlis.LocalManageUtil |
||||||
|
import com.novel.read.utlis.SpUtil |
||||||
|
|
||||||
|
|
||||||
|
import org.litepal.LitePal |
||||||
|
import kotlin.properties.Delegates |
||||||
|
|
||||||
|
/** |
||||||
|
* create by zlj on 2019/6/10 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class MyApp : Application() { |
||||||
|
|
||||||
|
override fun onCreate() { |
||||||
|
super.onCreate() |
||||||
|
context = applicationContext |
||||||
|
LitePal.initialize(this) |
||||||
|
setNight() |
||||||
|
LocalManageUtil.setApplicationLanguage(this) |
||||||
|
startService(Intent(context, DownloadService::class.java)) |
||||||
|
} |
||||||
|
|
||||||
|
private fun setNight() { |
||||||
|
if (SpUtil.getBooleanValue(Constant.NIGHT, false)) { |
||||||
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) |
||||||
|
} else { |
||||||
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
override fun attachBaseContext(base: Context) { |
||||||
|
SpUtil.init(base) |
||||||
|
//保存系统选择语言 |
||||||
|
LocalManageUtil.saveSystemCurrentLanguage(base) |
||||||
|
super.attachBaseContext(LocalManageUtil.setLocal(base)) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onConfigurationChanged(newConfig: Configuration) { |
||||||
|
super.onConfigurationChanged(newConfig) |
||||||
|
//保存系统选择语言 |
||||||
|
LocalManageUtil.onConfigurationChanged(applicationContext) |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
var context: Context by Delegates.notNull() |
||||||
|
private set |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -1,139 +0,0 @@ |
|||||||
package com.novel.read.base; |
|
||||||
|
|
||||||
import android.content.Context; |
|
||||||
import android.content.Intent; |
|
||||||
import android.os.Bundle; |
|
||||||
|
|
||||||
import android.view.View; |
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity; |
|
||||||
import androidx.appcompat.app.AppCompatDelegate; |
|
||||||
|
|
||||||
|
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.constants.Constant; |
|
||||||
import com.novel.read.utlis.LocalManageUtil; |
|
||||||
import com.novel.read.utlis.SpUtil; |
|
||||||
import com.novel.read.utlis.StatusBarUtil; |
|
||||||
|
|
||||||
import butterknife.ButterKnife; |
|
||||||
import butterknife.Unbinder; |
|
||||||
|
|
||||||
/** |
|
||||||
* create by 赵利君 on 2019/6/10 |
|
||||||
* describe: |
|
||||||
*/ |
|
||||||
public abstract class NovelBaseActivity extends AppCompatActivity { |
|
||||||
Unbinder mBind; |
|
||||||
private boolean mCheckNet = true;//是否检查网络连接
|
|
||||||
public boolean mNetworkChange = false;//获取网络是否连接
|
|
||||||
private boolean mNowMode; |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onCreate(Bundle savedInstanceState) { |
|
||||||
super.onCreate(savedInstanceState); |
|
||||||
StatusBarUtil.setBarsStyle(this, R.color.colorPrimary, true); |
|
||||||
mNowMode = SpUtil.getBooleanValue(Constant.NIGHT); |
|
||||||
setContentView(getLayoutId()); |
|
||||||
mBind = ButterKnife.bind(this); |
|
||||||
initView(); |
|
||||||
initData(); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
protected void setTheme() { |
|
||||||
if (SpUtil.getBooleanValue(Constant.NIGHT) != mNowMode) { |
|
||||||
if (SpUtil.getBooleanValue(Constant.NIGHT)) { |
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); |
|
||||||
} else { |
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); |
|
||||||
} |
|
||||||
recreate(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected abstract int getLayoutId(); |
|
||||||
|
|
||||||
protected abstract void initView(); |
|
||||||
|
|
||||||
protected abstract void initData(); |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onDestroy() { |
|
||||||
super.onDestroy(); |
|
||||||
mBind.unbind(); |
|
||||||
} |
|
||||||
|
|
||||||
public void toActivity(Class<?> cls) { |
|
||||||
Intent intent = new Intent(this, cls); |
|
||||||
startActivity(intent); |
|
||||||
} |
|
||||||
|
|
||||||
public void toActivity(Class<?> toClsActivity, Bundle bundle) { |
|
||||||
Intent intent = new Intent(this, toClsActivity); |
|
||||||
if (bundle != null) { |
|
||||||
intent.putExtras(bundle); |
|
||||||
} |
|
||||||
startActivity(intent); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public boolean isNetworkChange() { |
|
||||||
return mNetworkChange; |
|
||||||
} |
|
||||||
|
|
||||||
public void setNetworkChange(boolean mNetworkChange) { |
|
||||||
this.mNetworkChange = mNetworkChange; |
|
||||||
} |
|
||||||
|
|
||||||
public boolean getIsCheckNet() { |
|
||||||
return mCheckNet; |
|
||||||
} |
|
||||||
|
|
||||||
public void setIsCheckNet(boolean checkNet) { |
|
||||||
this.mCheckNet = checkNet; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onResume() { |
|
||||||
super.onResume(); |
|
||||||
setTheme(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onPause() { |
|
||||||
super.onPause(); |
|
||||||
} |
|
||||||
|
|
||||||
protected void gone(final View... views) { |
|
||||||
if (views != null && views.length > 0) { |
|
||||||
for (View view : views) { |
|
||||||
if (view != null) { |
|
||||||
view.setVisibility(View.GONE); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected void visible(final View... views) { |
|
||||||
if (views != null && views.length > 0) { |
|
||||||
for (View view : views) { |
|
||||||
if (view != null) { |
|
||||||
view.setVisibility(View.VISIBLE); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected boolean isVisible(View view) { |
|
||||||
return view.getVisibility() == View.VISIBLE; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
protected void attachBaseContext(Context newBase) { |
|
||||||
super.attachBaseContext(LocalManageUtil.setLocal(newBase)); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,79 @@ |
|||||||
|
package com.novel.read.base |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.content.Intent |
||||||
|
import android.os.Bundle |
||||||
|
import android.view.View |
||||||
|
import androidx.appcompat.app.AppCompatActivity |
||||||
|
import androidx.appcompat.app.AppCompatDelegate |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.constants.Constant |
||||||
|
import com.novel.read.utlis.LocalManageUtil |
||||||
|
import com.novel.read.utlis.SpUtil |
||||||
|
import com.novel.read.utlis.StatusBarUtil |
||||||
|
|
||||||
|
/** |
||||||
|
* create by 赵利君 on 2019/6/10 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
abstract class NovelBaseActivity : AppCompatActivity() { |
||||||
|
var isCheckNet = true//是否检查网络连接 |
||||||
|
var isNetworkChange = false//获取网络是否连接 |
||||||
|
private var mNowMode: Boolean = false |
||||||
|
|
||||||
|
protected abstract val layoutId: Int |
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) { |
||||||
|
super.onCreate(savedInstanceState) |
||||||
|
StatusBarUtil.setBarsStyle(this, R.color.colorPrimary, true) |
||||||
|
mNowMode = SpUtil.getBooleanValue(Constant.NIGHT) |
||||||
|
setContentView(layoutId) |
||||||
|
initView() |
||||||
|
initData() |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private fun setTheme() { |
||||||
|
if (SpUtil.getBooleanValue(Constant.NIGHT) != mNowMode) { |
||||||
|
if (SpUtil.getBooleanValue(Constant.NIGHT)) { |
||||||
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) |
||||||
|
} else { |
||||||
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) |
||||||
|
} |
||||||
|
recreate() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected abstract fun initView() |
||||||
|
|
||||||
|
protected abstract fun initData() |
||||||
|
|
||||||
|
override fun onResume() { |
||||||
|
super.onResume() |
||||||
|
setTheme() |
||||||
|
} |
||||||
|
|
||||||
|
protected fun gone(vararg views: View) { |
||||||
|
if (views.isNotEmpty()) { |
||||||
|
for (view in views) { |
||||||
|
view.visibility = View.GONE |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected fun visible(vararg views: View) { |
||||||
|
if (views.isNotEmpty()) { |
||||||
|
for (view in views) { |
||||||
|
view.visibility = View.VISIBLE |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected fun isVisible(view: View): Boolean { |
||||||
|
return view.visibility == View.VISIBLE |
||||||
|
} |
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context) { |
||||||
|
super.attachBaseContext(LocalManageUtil.setLocal(newBase)) |
||||||
|
} |
||||||
|
} |
@ -1,59 +0,0 @@ |
|||||||
package com.novel.read.base; |
|
||||||
|
|
||||||
|
|
||||||
import android.content.Intent; |
|
||||||
import android.os.Bundle; |
|
||||||
|
|
||||||
import android.view.LayoutInflater; |
|
||||||
import android.view.View; |
|
||||||
import android.view.ViewGroup; |
|
||||||
|
|
||||||
import androidx.annotation.NonNull; |
|
||||||
import androidx.annotation.Nullable; |
|
||||||
import androidx.fragment.app.Fragment; |
|
||||||
|
|
||||||
import butterknife.ButterKnife; |
|
||||||
import butterknife.Unbinder; |
|
||||||
|
|
||||||
|
|
||||||
public abstract class NovelBaseFragment extends Fragment { |
|
||||||
|
|
||||||
private Unbinder bind; |
|
||||||
|
|
||||||
@Override |
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, |
|
||||||
Bundle savedInstanceState) { |
|
||||||
|
|
||||||
View mContextView = inflater.inflate(getLayoutId(), container, false); |
|
||||||
bind = ButterKnife.bind(this, mContextView); |
|
||||||
initView(); |
|
||||||
initData(); |
|
||||||
return mContextView; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
protected abstract int getLayoutId(); |
|
||||||
|
|
||||||
protected abstract void initView(); |
|
||||||
|
|
||||||
protected abstract void initData(); |
|
||||||
|
|
||||||
public void toActivity(Class<?> cls) { |
|
||||||
Intent intent = new Intent(getActivity(), cls); |
|
||||||
startActivity(intent); |
|
||||||
} |
|
||||||
|
|
||||||
public void toActivity(Class<?> toClsActivity, Bundle bundle) { |
|
||||||
Intent intent = new Intent(getActivity(), toClsActivity); |
|
||||||
if (bundle != null) { |
|
||||||
intent.putExtras(bundle); |
|
||||||
} |
|
||||||
startActivity(intent); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onDestroyView() { |
|
||||||
super.onDestroyView(); |
|
||||||
bind.unbind(); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,59 @@ |
|||||||
|
package com.novel.read.base |
||||||
|
|
||||||
|
|
||||||
|
import android.content.Intent |
||||||
|
import android.os.Bundle |
||||||
|
|
||||||
|
import android.view.LayoutInflater |
||||||
|
import android.view.View |
||||||
|
import android.view.ViewGroup |
||||||
|
import androidx.annotation.LayoutRes |
||||||
|
import androidx.fragment.app.Fragment |
||||||
|
|
||||||
|
|
||||||
|
abstract class NovelBaseFragment : Fragment() { |
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
||||||
|
return inflater.inflate(getLayoutId(),null) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||||
|
super.onViewCreated(view, savedInstanceState) |
||||||
|
initView() |
||||||
|
initData() |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 加载布局 |
||||||
|
*/ |
||||||
|
@LayoutRes |
||||||
|
abstract fun getLayoutId():Int |
||||||
|
|
||||||
|
abstract fun initView() |
||||||
|
|
||||||
|
abstract fun initData() |
||||||
|
|
||||||
|
fun toActivity(toClsActivity: Class<*>) { |
||||||
|
this.toActivity(toClsActivity, null as Bundle?) |
||||||
|
} |
||||||
|
|
||||||
|
fun toActivity(toClsActivity: Class<*>, bundle: Bundle?) { |
||||||
|
val intent = Intent(this.context, toClsActivity) |
||||||
|
if (bundle != null) { |
||||||
|
intent.putExtras(bundle) |
||||||
|
} |
||||||
|
|
||||||
|
this.startActivity(intent) |
||||||
|
} |
||||||
|
|
||||||
|
fun toActivityForResult(toClsActivity: Class<*>, bundle: Bundle?, requestCode: Int) { |
||||||
|
val intent = Intent(this.context, toClsActivity) |
||||||
|
if (bundle != null) { |
||||||
|
intent.putExtras(bundle) |
||||||
|
} |
||||||
|
|
||||||
|
startActivityForResult(intent, requestCode) |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -1,110 +0,0 @@ |
|||||||
/** |
|
||||||
* Copyright 2016 JustWayward Team |
|
||||||
* <p> |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* <p> |
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p> |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
package com.novel.read.constants; |
|
||||||
|
|
||||||
|
|
||||||
import android.graphics.Color; |
|
||||||
|
|
||||||
import com.novel.read.utlis.FileUtils; |
|
||||||
|
|
||||||
import java.io.File; |
|
||||||
|
|
||||||
public class Constant { |
|
||||||
public static final String NIGHT = "NIGHT"; |
|
||||||
public static final String Language = "Language"; |
|
||||||
public static final String BookSort = "BookSort"; |
|
||||||
public static final String Uid = "Uid"; |
|
||||||
public static final String Sex = "Sex"; |
|
||||||
public static final String Type = "Type"; |
|
||||||
public static final String DateType = "DateType"; |
|
||||||
public static final String InstallTime = "InstallTime"; //apk的安装时间
|
|
||||||
public static final String InstallCount = "InstallCount"; //apk的打开次数
|
|
||||||
public static final String AppraiseShow = "AppraiseShow"; //评价弹框是否提示过
|
|
||||||
public static final String BookGuide = "BookGuide"; //图书引导是否提示过
|
|
||||||
|
|
||||||
public static final String FORMAT_BOOK_DATE = "yyyy-MM-dd HH:mm:ss"; |
|
||||||
public static final String FORMAT_TIME = "HH:mm"; |
|
||||||
public static final int COMMENT_SIZE = 10; |
|
||||||
|
|
||||||
public static final String FeedBackEmail = "qdxs01@gmail.com"; |
|
||||||
|
|
||||||
/** |
|
||||||
* 百度语音合成 |
|
||||||
*/ |
|
||||||
//壳001 免费小说
|
|
||||||
public static final String appId = "16826023"; |
|
||||||
public static final String appKey = "vEuU5gIWGwq5hivdTAaKz0P9"; |
|
||||||
public static final String secretKey = "FcWRYUIrOPyE7dy51qfYZmg8Y1ZyP1c4 "; |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* 腾讯bugly |
|
||||||
*/ |
|
||||||
public static final String buglyId = "aec152f916";//壳包001
|
|
||||||
|
|
||||||
|
|
||||||
//BookCachePath (因为getCachePath引用了Context,所以必须是静态变量,不能够是静态常量)
|
|
||||||
public static String BOOK_CACHE_PATH = FileUtils.getCachePath() + File.separator |
|
||||||
+ "book_cache" + File.separator; |
|
||||||
|
|
||||||
public static final int[] tagColors = new int[]{ |
|
||||||
Color.parseColor("#90C5F0"), |
|
||||||
Color.parseColor("#91CED5"), |
|
||||||
Color.parseColor("#F88F55"), |
|
||||||
Color.parseColor("#C0AFD0"), |
|
||||||
Color.parseColor("#E78F8F"), |
|
||||||
Color.parseColor("#67CCB7"), |
|
||||||
Color.parseColor("#F6BC7E"), |
|
||||||
Color.parseColor("#90C5F0"), |
|
||||||
Color.parseColor("#91CED5"), |
|
||||||
}; |
|
||||||
|
|
||||||
//榜单类型
|
|
||||||
public interface ListType { |
|
||||||
String Human = "1"; |
|
||||||
String EditRecommend = "2"; |
|
||||||
String HotSearch = "3"; |
|
||||||
} |
|
||||||
|
|
||||||
public interface GenderType { |
|
||||||
String Man = "1"; |
|
||||||
String Woman = "2"; |
|
||||||
} |
|
||||||
|
|
||||||
public interface DateTyp { |
|
||||||
String General = "3"; |
|
||||||
String Month = "2"; |
|
||||||
String Week = "1"; |
|
||||||
} |
|
||||||
|
|
||||||
public interface Bundle { |
|
||||||
String CategoryId = "category_id"; |
|
||||||
String mTitle = "mTitle"; |
|
||||||
String BookId = "BookId"; |
|
||||||
} |
|
||||||
|
|
||||||
public interface HasImage { |
|
||||||
int has = 1; |
|
||||||
} |
|
||||||
|
|
||||||
public interface RequestCode { |
|
||||||
int REQUEST_READ = 1; |
|
||||||
} |
|
||||||
|
|
||||||
public interface ResultCode { |
|
||||||
String RESULT_IS_COLLECTED = "result_is_collected"; |
|
||||||
} |
|
||||||
} |
|
@ -1,17 +0,0 @@ |
|||||||
package com.novel.read.event; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.BaseEvent; |
|
||||||
import com.mango.mangolib.http.ErrorResponse; |
|
||||||
|
|
||||||
/** |
|
||||||
* create by 赵利君 on 2019/6/25 |
|
||||||
* describe: |
|
||||||
*/ |
|
||||||
public class AddBookSignEvent extends BaseEvent<ErrorResponse> { |
|
||||||
public AddBookSignEvent(ErrorResponse result) { |
|
||||||
super(result); |
|
||||||
} |
|
||||||
|
|
||||||
public AddBookSignEvent() { |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,14 @@ |
|||||||
|
package com.novel.read.event |
||||||
|
|
||||||
|
import com.mango.mangolib.event.BaseEvent |
||||||
|
import com.mango.mangolib.http.ErrorResponse |
||||||
|
|
||||||
|
/** |
||||||
|
* create by 赵利君 on 2019/6/25 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class AddBookSignEvent : BaseEvent<ErrorResponse> { |
||||||
|
constructor(result: ErrorResponse) : super(result) {} |
||||||
|
|
||||||
|
constructor() {} |
||||||
|
} |
@ -1,13 +0,0 @@ |
|||||||
package com.novel.read.event; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.BaseEvent; |
|
||||||
import com.mango.mangolib.http.ErrorResponse; |
|
||||||
|
|
||||||
public class DeleteBookSignEvent extends BaseEvent<ErrorResponse> { |
|
||||||
public DeleteBookSignEvent(ErrorResponse result) { |
|
||||||
super(result); |
|
||||||
} |
|
||||||
|
|
||||||
public DeleteBookSignEvent() { |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,6 @@ |
|||||||
|
package com.novel.read.event |
||||||
|
|
||||||
|
import com.mango.mangolib.event.BaseEvent |
||||||
|
import com.mango.mangolib.http.ErrorResponse |
||||||
|
|
||||||
|
class DeleteBookSignEvent(result: ErrorResponse) : BaseEvent<ErrorResponse>(result) |
@ -1,17 +0,0 @@ |
|||||||
package com.novel.read.event; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.BaseEvent; |
|
||||||
import com.novel.read.model.db.CollBookBean; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by newbiechen on 17-5-27. |
|
||||||
*/ |
|
||||||
|
|
||||||
public class DeleteResponseEvent extends BaseEvent { |
|
||||||
public boolean isDelete; |
|
||||||
public CollBookBean collBook; |
|
||||||
public DeleteResponseEvent(boolean isDelete, CollBookBean collBook){ |
|
||||||
this.isDelete = isDelete; |
|
||||||
this.collBook = collBook; |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,6 @@ |
|||||||
|
package com.novel.read.event |
||||||
|
|
||||||
|
import com.mango.mangolib.event.BaseEvent |
||||||
|
import com.novel.read.model.db.CollBookBean |
||||||
|
|
||||||
|
class DeleteResponseEvent(var isDelete: Boolean, var collBook: CollBookBean) : BaseEvent<Any>() |
@ -1,16 +0,0 @@ |
|||||||
package com.novel.read.event; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.BaseEvent; |
|
||||||
import com.novel.read.model.db.CollBookBean; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by newbiechen on 17-5-27. |
|
||||||
*/ |
|
||||||
|
|
||||||
public class DeleteTaskEvent extends BaseEvent { |
|
||||||
public CollBookBean collBook; |
|
||||||
|
|
||||||
public DeleteTaskEvent(CollBookBean collBook){ |
|
||||||
this.collBook = collBook; |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,6 @@ |
|||||||
|
package com.novel.read.event |
||||||
|
|
||||||
|
import com.mango.mangolib.event.BaseEvent |
||||||
|
import com.novel.read.model.db.CollBookBean |
||||||
|
|
||||||
|
class DeleteTaskEvent(var collBook: CollBookBean) : BaseEvent<Any>() |
@ -1,12 +0,0 @@ |
|||||||
package com.novel.read.event; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.BaseEvent; |
|
||||||
|
|
||||||
public class ErrorChapterEvent extends BaseEvent { |
|
||||||
public ErrorChapterEvent(Object result) { |
|
||||||
super(result); |
|
||||||
} |
|
||||||
|
|
||||||
public ErrorChapterEvent() { |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,9 @@ |
|||||||
|
package com.novel.read.event |
||||||
|
|
||||||
|
import com.mango.mangolib.event.BaseEvent |
||||||
|
|
||||||
|
class ErrorChapterEvent : BaseEvent<Any> { |
||||||
|
constructor(result: Any) : super(result) |
||||||
|
|
||||||
|
constructor() |
||||||
|
} |
@ -1,12 +0,0 @@ |
|||||||
package com.novel.read.event; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.BaseEvent; |
|
||||||
|
|
||||||
public class FinishChapterEvent extends BaseEvent { |
|
||||||
public FinishChapterEvent(Object result) { |
|
||||||
super(result); |
|
||||||
} |
|
||||||
|
|
||||||
public FinishChapterEvent() { |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,9 @@ |
|||||||
|
package com.novel.read.event |
||||||
|
|
||||||
|
import com.mango.mangolib.event.BaseEvent |
||||||
|
|
||||||
|
class FinishChapterEvent : BaseEvent<Any> { |
||||||
|
constructor(result: Any) : super(result) |
||||||
|
|
||||||
|
constructor() |
||||||
|
} |
@ -1,18 +0,0 @@ |
|||||||
package com.novel.read.event; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.BaseEvent; |
|
||||||
import com.novel.read.model.protocol.CategoryTypeResp; |
|
||||||
|
|
||||||
/** |
|
||||||
* create by 赵利君 on 2019/6/18 |
|
||||||
* describe: |
|
||||||
*/ |
|
||||||
public class GetCategoryTypeEvent extends BaseEvent<CategoryTypeResp> { |
|
||||||
|
|
||||||
public GetCategoryTypeEvent(CategoryTypeResp result) { |
|
||||||
super(result); |
|
||||||
} |
|
||||||
|
|
||||||
public GetCategoryTypeEvent() { |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,15 @@ |
|||||||
|
package com.novel.read.event |
||||||
|
|
||||||
|
import com.mango.mangolib.event.BaseEvent |
||||||
|
import com.novel.read.model.protocol.CategoryTypeResp |
||||||
|
|
||||||
|
/** |
||||||
|
* create by zlj on 2019/6/18 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class GetCategoryTypeEvent : BaseEvent<CategoryTypeResp> { |
||||||
|
|
||||||
|
constructor(result: CategoryTypeResp) : super(result) {} |
||||||
|
|
||||||
|
constructor() {} |
||||||
|
} |
@ -1,12 +0,0 @@ |
|||||||
package com.novel.read.event; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.BaseEvent; |
|
||||||
|
|
||||||
public class HideBottomBarEvent extends BaseEvent<Boolean> { |
|
||||||
public HideBottomBarEvent(Boolean result) { |
|
||||||
super(result); |
|
||||||
} |
|
||||||
|
|
||||||
public HideBottomBarEvent() { |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,5 @@ |
|||||||
|
package com.novel.read.event |
||||||
|
|
||||||
|
import com.mango.mangolib.event.BaseEvent |
||||||
|
|
||||||
|
class HideBottomBarEvent(result: Boolean?) : BaseEvent<Boolean>(result!!) |
@ -1,18 +0,0 @@ |
|||||||
package com.novel.read.event; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.BaseEvent; |
|
||||||
import com.novel.read.model.protocol.HotSearchResp; |
|
||||||
|
|
||||||
/** |
|
||||||
* create by 赵利君 on 2019/6/18 |
|
||||||
* describe: |
|
||||||
*/ |
|
||||||
public class HotSearchEvent extends BaseEvent<HotSearchResp> { |
|
||||||
|
|
||||||
public HotSearchEvent(HotSearchResp result) { |
|
||||||
super(result); |
|
||||||
} |
|
||||||
|
|
||||||
public HotSearchEvent() { |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,10 @@ |
|||||||
|
package com.novel.read.event |
||||||
|
|
||||||
|
import com.mango.mangolib.event.BaseEvent |
||||||
|
import com.novel.read.model.protocol.HotSearchResp |
||||||
|
|
||||||
|
/** |
||||||
|
* create by zlj on 2019/6/18 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class HotSearchEvent(result: HotSearchResp) : BaseEvent<HotSearchResp>(result) |
@ -1,18 +0,0 @@ |
|||||||
package com.novel.read.event; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.BaseEvent; |
|
||||||
import com.novel.read.model.protocol.RankByUpadateResp; |
|
||||||
|
|
||||||
/** |
|
||||||
* create by 赵利君 on 2019/6/18 |
|
||||||
* describe: |
|
||||||
*/ |
|
||||||
public class RankByUpdateEvent extends BaseEvent<RankByUpadateResp> { |
|
||||||
|
|
||||||
public RankByUpdateEvent(RankByUpadateResp result) { |
|
||||||
super(result); |
|
||||||
} |
|
||||||
|
|
||||||
public RankByUpdateEvent() { |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,15 @@ |
|||||||
|
package com.novel.read.event |
||||||
|
|
||||||
|
import com.mango.mangolib.event.BaseEvent |
||||||
|
import com.novel.read.model.protocol.RankByUpadateResp |
||||||
|
|
||||||
|
/** |
||||||
|
* create by 赵利君 on 2019/6/18 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class RankByUpdateEvent : BaseEvent<RankByUpadateResp> { |
||||||
|
|
||||||
|
constructor(result: RankByUpadateResp) : super(result) {} |
||||||
|
|
||||||
|
constructor() {} |
||||||
|
} |
@ -1,8 +0,0 @@ |
|||||||
package com.novel.read.event; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.BaseEvent; |
|
||||||
|
|
||||||
public class SetAdsBgEvent extends BaseEvent { |
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -1,13 +0,0 @@ |
|||||||
package com.novel.read.event; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.BaseEvent; |
|
||||||
|
|
||||||
public class SwitchFragmentEvent extends BaseEvent { |
|
||||||
|
|
||||||
public SwitchFragmentEvent(Object result) { |
|
||||||
super(result); |
|
||||||
} |
|
||||||
|
|
||||||
public SwitchFragmentEvent() { |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,10 @@ |
|||||||
|
package com.novel.read.event |
||||||
|
|
||||||
|
import com.mango.mangolib.event.BaseEvent |
||||||
|
|
||||||
|
class SwitchFragmentEvent : BaseEvent<Any> { |
||||||
|
|
||||||
|
constructor(result: Any) : super(result) {} |
||||||
|
|
||||||
|
constructor() {} |
||||||
|
} |
@ -1,13 +0,0 @@ |
|||||||
package com.novel.read.event; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.BaseEvent; |
|
||||||
|
|
||||||
public class UpdateBookEvent extends BaseEvent<String> { |
|
||||||
|
|
||||||
public UpdateBookEvent(String result) { |
|
||||||
super(result); |
|
||||||
} |
|
||||||
|
|
||||||
public UpdateBookEvent() { |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,10 @@ |
|||||||
|
package com.novel.read.event |
||||||
|
|
||||||
|
import com.mango.mangolib.event.BaseEvent |
||||||
|
|
||||||
|
class UpdateBookEvent : BaseEvent<String> { |
||||||
|
|
||||||
|
constructor(result: String) : super(result) {} |
||||||
|
|
||||||
|
constructor() {} |
||||||
|
} |
@ -1,302 +0,0 @@ |
|||||||
package com.novel.read.fragment; |
|
||||||
|
|
||||||
import android.app.AlertDialog; |
|
||||||
import android.os.Bundle; |
|
||||||
import android.util.Log; |
|
||||||
import android.view.View; |
|
||||||
import android.widget.TextView; |
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatDelegate; |
|
||||||
import androidx.appcompat.widget.Toolbar; |
|
||||||
import androidx.recyclerview.widget.GridLayoutManager; |
|
||||||
import androidx.recyclerview.widget.RecyclerView; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.EventManager; |
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.activity.NovelMainActivity; |
|
||||||
import com.novel.read.activity.NovelSearchActivity; |
|
||||||
import com.novel.read.adapter.BookAdapter; |
|
||||||
import com.novel.read.base.NovelBaseFragment; |
|
||||||
import com.novel.read.constants.Constant; |
|
||||||
import com.novel.read.event.HideBottomBarEvent; |
|
||||||
import com.novel.read.event.SwitchFragmentEvent; |
|
||||||
import com.novel.read.event.UpdateBookEvent; |
|
||||||
import com.novel.read.http.AccountManager; |
|
||||||
import com.novel.read.model.db.BookRecordBean; |
|
||||||
import com.novel.read.model.db.CollBookBean; |
|
||||||
import com.novel.read.model.db.dbManage.BookRepository; |
|
||||||
import com.novel.read.model.protocol.BookDetailResp; |
|
||||||
import com.novel.read.utlis.LocalManageUtil; |
|
||||||
import com.novel.read.utlis.RxUtils; |
|
||||||
import com.novel.read.utlis.SpUtil; |
|
||||||
import com.novel.read.utlis.ToastUtil; |
|
||||||
import com.squareup.otto.Subscribe; |
|
||||||
|
|
||||||
import org.litepal.LitePal; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.Iterator; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
import io.reactivex.Single; |
|
||||||
import io.reactivex.SingleObserver; |
|
||||||
import io.reactivex.disposables.Disposable; |
|
||||||
|
|
||||||
/** |
|
||||||
* create by 赵利君 on 2019/10/14 |
|
||||||
* describe: |
|
||||||
*/ |
|
||||||
public class BookFragment extends NovelBaseFragment { |
|
||||||
|
|
||||||
@BindView(R.id.title) |
|
||||||
Toolbar title; |
|
||||||
@BindView(R.id.title_edit) |
|
||||||
Toolbar titleEdit; |
|
||||||
@BindView(R.id.rlv_book) |
|
||||||
RecyclerView mRlvBook; |
|
||||||
@BindView(R.id.tv_cancel) |
|
||||||
TextView mTvCancel; |
|
||||||
@BindView(R.id.tv_delete) |
|
||||||
TextView mTvDelete; |
|
||||||
private BookAdapter mAdapter; |
|
||||||
private List<CollBookBean> mList = new ArrayList<>(); |
|
||||||
private boolean isInit = true; |
|
||||||
|
|
||||||
public static BookFragment newInstance() { |
|
||||||
Bundle args = new Bundle(); |
|
||||||
BookFragment fragment = new BookFragment(); |
|
||||||
fragment.setArguments(args); |
|
||||||
return fragment; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected int getLayoutId() { |
|
||||||
return R.layout.fragment_book; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initView() { |
|
||||||
EventManager.Companion.getInstance().registerSubscriber(this); |
|
||||||
|
|
||||||
mList.addAll(BookRepository.getInstance().getCollBooks()); |
|
||||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 3); |
|
||||||
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { |
|
||||||
@Override |
|
||||||
public int getSpanSize(int i) { |
|
||||||
if (mList == null || mList.size() == 0) { |
|
||||||
return 3; |
|
||||||
} else { |
|
||||||
return 1; |
|
||||||
} |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
mRlvBook.setLayoutManager(gridLayoutManager); |
|
||||||
mAdapter = new BookAdapter(mList); |
|
||||||
mRlvBook.setAdapter(mAdapter); |
|
||||||
if (isInit) { |
|
||||||
isInit = false; |
|
||||||
update(mList); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initData() { |
|
||||||
title.inflateMenu(R.menu.title_book); |
|
||||||
titleEdit.inflateMenu(R.menu.title_edit); |
|
||||||
setOnClick(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
private void setOnClick() { |
|
||||||
title.setOnMenuItemClickListener(menuItem -> { |
|
||||||
switch (menuItem.getItemId()) { |
|
||||||
case R.id.action_search: |
|
||||||
toActivity(NovelSearchActivity.class); |
|
||||||
getActivity().overridePendingTransition(R.anim.message_fade_in, R.anim.message_fade_out); |
|
||||||
break; |
|
||||||
case R.id.edit_book: |
|
||||||
if (mList == null || mList.size() == 0) { //没书的时候提醒用户不能编辑
|
|
||||||
ToastUtil.show(getActivity(), getString(R.string.please_add_book)); |
|
||||||
} else { |
|
||||||
mAdapter.setEdit(true); |
|
||||||
mTvCancel.setVisibility(View.VISIBLE); |
|
||||||
mTvDelete.setVisibility(View.VISIBLE); |
|
||||||
titleEdit.setVisibility(View.VISIBLE); |
|
||||||
title.setVisibility(View.GONE); |
|
||||||
EventManager.Companion.getInstance().postEvent(new HideBottomBarEvent(true)); |
|
||||||
} |
|
||||||
break; |
|
||||||
case R.id.book_sort: |
|
||||||
showBookSortDialog(); |
|
||||||
break; |
|
||||||
case R.id.menu2: |
|
||||||
showLanguageDialog(); |
|
||||||
break; |
|
||||||
case R.id.menu3: |
|
||||||
if (SpUtil.getBooleanValue(Constant.NIGHT)) { |
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); |
|
||||||
SpUtil.setBooleanValue(Constant.NIGHT, false); |
|
||||||
} else { |
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); |
|
||||||
SpUtil.setBooleanValue(Constant.NIGHT, true); |
|
||||||
} |
|
||||||
getActivity().recreate(); |
|
||||||
break; |
|
||||||
} |
|
||||||
return true; |
|
||||||
}); |
|
||||||
titleEdit.setOnMenuItemClickListener(menuItem -> { |
|
||||||
if (menuItem.getItemId() == R.id.action_edit) { |
|
||||||
for (int i = 0; i < mList.size(); i++) { |
|
||||||
mList.get(i).setSelect(true); |
|
||||||
} |
|
||||||
mAdapter.notifyDataSetChanged(); |
|
||||||
} |
|
||||||
return true; |
|
||||||
}); |
|
||||||
mTvCancel.setOnClickListener(view -> { |
|
||||||
EventManager.Companion.getInstance().postEvent(new HideBottomBarEvent(false)); |
|
||||||
updateBook(new UpdateBookEvent()); |
|
||||||
}); |
|
||||||
|
|
||||||
mTvDelete.setOnClickListener(view -> { |
|
||||||
List<CollBookBean> deleteList = mAdapter.getSelectList(); |
|
||||||
for (int i = 0; i < deleteList.size(); i++) { |
|
||||||
if (deleteList.get(i).isSaved()) { |
|
||||||
int count = deleteList.get(i).delete(); |
|
||||||
LitePal.deleteAll(BookRecordBean.class, "bookId=?", mList.get(i).getId()); |
|
||||||
Log.e("count", "setOnClick: " + count); |
|
||||||
} |
|
||||||
} |
|
||||||
ToastUtil.show(getActivity(), getString(R.string.delete_success)); |
|
||||||
EventManager.Companion.getInstance().postEvent(new HideBottomBarEvent(false)); |
|
||||||
updateBook(new UpdateBookEvent()); |
|
||||||
}); |
|
||||||
|
|
||||||
mAdapter.setOnItemClickListener((view, pos) -> { |
|
||||||
EventManager.Companion.getInstance().postEvent(new SwitchFragmentEvent()); |
|
||||||
}); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
private void showLanguageDialog() { |
|
||||||
Log.e("showLanguageDialog", "showLanguageDialog: " + SpUtil.getIntValue(Constant.Language, 0)); |
|
||||||
new AlertDialog.Builder(getActivity()) |
|
||||||
.setTitle(getString(R.string.choose_language)) |
|
||||||
.setSingleChoiceItems(getResources().getStringArray(R.array.setting_dialog_language_choice), SpUtil.getIntValue(Constant.Language, 1), |
|
||||||
(dialog, which) -> { |
|
||||||
String language = getResources().getStringArray(R.array.setting_dialog_language_choice)[which]; |
|
||||||
SpUtil.setIntValue(Constant.Language, which); |
|
||||||
dialog.dismiss(); |
|
||||||
|
|
||||||
if (which == 0) { |
|
||||||
selectLanguage(0); |
|
||||||
} else { |
|
||||||
selectLanguage(1); |
|
||||||
} |
|
||||||
}) |
|
||||||
.create().show(); |
|
||||||
} |
|
||||||
|
|
||||||
private void selectLanguage(int select) { |
|
||||||
LocalManageUtil.saveSelectLanguage(getActivity(), select); |
|
||||||
NovelMainActivity.reStart(getActivity()); |
|
||||||
} |
|
||||||
|
|
||||||
private void showBookSortDialog() { |
|
||||||
new AlertDialog.Builder(getActivity()) |
|
||||||
.setTitle(getString(R.string.choose_language)) |
|
||||||
.setSingleChoiceItems(getResources().getStringArray(R.array.setting_dialog_sort_choice), |
|
||||||
SpUtil.getBooleanValue(Constant.BookSort, false) ? 0 : 1, |
|
||||||
(dialog, which) -> { |
|
||||||
if (which == 0) { |
|
||||||
SpUtil.setBooleanValue(Constant.BookSort, true); |
|
||||||
} else { |
|
||||||
SpUtil.setBooleanValue(Constant.BookSort, false); |
|
||||||
} |
|
||||||
updateBook(new UpdateBookEvent()); |
|
||||||
dialog.dismiss(); |
|
||||||
}) |
|
||||||
.create().show(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onResume() { |
|
||||||
super.onResume(); |
|
||||||
updateBook(new UpdateBookEvent()); |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void updateBook(UpdateBookEvent event) { |
|
||||||
mTvCancel.setVisibility(View.GONE); |
|
||||||
mTvDelete.setVisibility(View.GONE); |
|
||||||
title.setVisibility(View.VISIBLE); |
|
||||||
titleEdit.setVisibility(View.GONE); |
|
||||||
mList.clear(); |
|
||||||
mList.addAll(BookRepository.getInstance().getCollBooks()); |
|
||||||
mAdapter.setEdit(false); |
|
||||||
} |
|
||||||
|
|
||||||
private void update(List<CollBookBean> collBookBeans) { //检测书籍更新
|
|
||||||
if (collBookBeans == null || collBookBeans.isEmpty()) return; |
|
||||||
List<CollBookBean> collBooks = new ArrayList<>(collBookBeans); |
|
||||||
List<Single<BookDetailResp>> observables = new ArrayList<>(collBooks.size()); |
|
||||||
Iterator<CollBookBean> it = collBooks.iterator(); |
|
||||||
while (it.hasNext()) { |
|
||||||
CollBookBean collBook = it.next(); |
|
||||||
//删除本地文件
|
|
||||||
if (collBook.isLocal()) { |
|
||||||
it.remove(); |
|
||||||
} else { |
|
||||||
observables.add(AccountManager.getInstance().getBookDetails(collBook.getId())); |
|
||||||
} |
|
||||||
} |
|
||||||
//zip可能不是一个好方法。
|
|
||||||
Single.zip(observables, objects -> { |
|
||||||
List<CollBookBean> newCollBooks = new ArrayList<>(objects.length); |
|
||||||
for (int i = 0; i < collBooks.size(); ++i) { |
|
||||||
CollBookBean oldCollBook = collBooks.get(i); |
|
||||||
CollBookBean newCollBook = ((BookDetailResp) objects[i]).getCollBookBean(); |
|
||||||
//如果是oldBook是update状态,或者newCollBook与oldBook章节数不同
|
|
||||||
if (oldCollBook.isUpdate() || !oldCollBook.getLastChapter().equals(newCollBook.getLastChapter())) { |
|
||||||
newCollBook.setIsUpdate(true); |
|
||||||
} else { |
|
||||||
newCollBook.setIsUpdate(false); |
|
||||||
} |
|
||||||
newCollBook.setLastRead(oldCollBook.getLastRead()); |
|
||||||
newCollBooks.add(newCollBook); |
|
||||||
//存储到数据库中
|
|
||||||
BookRepository.getInstance().saveCollBooks(newCollBooks); |
|
||||||
} |
|
||||||
return newCollBooks; |
|
||||||
}) |
|
||||||
.compose(RxUtils::toSimpleSingle) |
|
||||||
.subscribe(new SingleObserver<List<CollBookBean>>() { |
|
||||||
@Override |
|
||||||
public void onSubscribe(Disposable d) { |
|
||||||
// addDisposable(d);
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onSuccess(List<CollBookBean> value) { |
|
||||||
//跟原先比较
|
|
||||||
mList.clear(); |
|
||||||
mList.addAll(BookRepository.getInstance().getCollBooks()); |
|
||||||
mAdapter.notifyDataSetChanged(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onError(Throwable e) { |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onDestroy() { |
|
||||||
super.onDestroy(); |
|
||||||
EventManager.Companion.getInstance().unregisterSubscriber(this); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,275 @@ |
|||||||
|
package com.novel.read.fragment |
||||||
|
|
||||||
|
import android.app.AlertDialog |
||||||
|
import android.os.Bundle |
||||||
|
import android.util.Log |
||||||
|
import android.view.View |
||||||
|
import androidx.appcompat.app.AppCompatDelegate |
||||||
|
import androidx.recyclerview.widget.GridLayoutManager |
||||||
|
import com.mango.mangolib.event.EventManager |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.activity.NovelMainActivity |
||||||
|
import com.novel.read.activity.NovelSearchActivity |
||||||
|
import com.novel.read.adapter.BookAdapter |
||||||
|
import com.novel.read.base.NovelBaseFragment |
||||||
|
import com.novel.read.constants.Constant |
||||||
|
import com.novel.read.event.HideBottomBarEvent |
||||||
|
import com.novel.read.event.SwitchFragmentEvent |
||||||
|
import com.novel.read.event.UpdateBookEvent |
||||||
|
import com.novel.read.http.AccountManager |
||||||
|
import com.novel.read.model.db.BookRecordBean |
||||||
|
import com.novel.read.model.db.CollBookBean |
||||||
|
import com.novel.read.model.db.dbManage.BookRepository |
||||||
|
import com.novel.read.model.protocol.BookDetailResp |
||||||
|
import com.novel.read.utlis.LocalManageUtil |
||||||
|
import com.novel.read.utlis.RxUtils |
||||||
|
import com.novel.read.utlis.SpUtil |
||||||
|
import com.novel.read.utlis.ToastUtil |
||||||
|
import com.squareup.otto.Subscribe |
||||||
|
import io.reactivex.Single |
||||||
|
import io.reactivex.SingleObserver |
||||||
|
import io.reactivex.disposables.Disposable |
||||||
|
import kotlinx.android.synthetic.main.fragment_book.* |
||||||
|
import org.litepal.LitePal |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
/** |
||||||
|
* create by 赵利君 on 2019/10/14 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class BookFragment : NovelBaseFragment() { |
||||||
|
|
||||||
|
private var mAdapter: BookAdapter? = null |
||||||
|
private val mList = ArrayList<CollBookBean>() |
||||||
|
private var isInit = true |
||||||
|
|
||||||
|
override fun getLayoutId(): Int { |
||||||
|
return R.layout.fragment_book |
||||||
|
} |
||||||
|
|
||||||
|
override fun initView() { |
||||||
|
EventManager.instance.registerSubscriber(this) |
||||||
|
|
||||||
|
mList.addAll(BookRepository.getInstance().collBooks) |
||||||
|
val gridLayoutManager = GridLayoutManager(activity, 3) |
||||||
|
gridLayoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() { |
||||||
|
override fun getSpanSize(i: Int): Int { |
||||||
|
return if (mList.size == 0) { |
||||||
|
3 |
||||||
|
} else { |
||||||
|
1 |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
rlv_book.layoutManager = gridLayoutManager |
||||||
|
mAdapter = BookAdapter(mList) |
||||||
|
rlv_book.adapter = mAdapter |
||||||
|
if (isInit) { |
||||||
|
isInit = false |
||||||
|
update(mList) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun initData() { |
||||||
|
title.inflateMenu(R.menu.title_book) |
||||||
|
title_edit.inflateMenu(R.menu.title_edit) |
||||||
|
setOnClick() |
||||||
|
} |
||||||
|
|
||||||
|
private fun setOnClick() { |
||||||
|
title.setOnMenuItemClickListener { menuItem -> |
||||||
|
when (menuItem.itemId) { |
||||||
|
R.id.action_search -> { |
||||||
|
toActivity(NovelSearchActivity::class.java) |
||||||
|
activity!!.overridePendingTransition( |
||||||
|
R.anim.message_fade_in, |
||||||
|
R.anim.message_fade_out |
||||||
|
) |
||||||
|
} |
||||||
|
R.id.edit_book -> if (mList.size == 0) { //没书的时候提醒用户不能编辑 |
||||||
|
ToastUtil.show(activity, getString(R.string.please_add_book)) |
||||||
|
} else { |
||||||
|
mAdapter!!.setEdit(true) |
||||||
|
tv_cancel.visibility = View.VISIBLE |
||||||
|
tv_delete.visibility = View.VISIBLE |
||||||
|
title_edit.visibility = View.VISIBLE |
||||||
|
title.visibility = View.GONE |
||||||
|
EventManager.instance.postEvent(HideBottomBarEvent(true)) |
||||||
|
} |
||||||
|
R.id.book_sort -> showBookSortDialog() |
||||||
|
R.id.menu2 -> showLanguageDialog() |
||||||
|
R.id.menu3 -> { |
||||||
|
if (SpUtil.getBooleanValue(Constant.NIGHT)) { |
||||||
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) |
||||||
|
SpUtil.setBooleanValue(Constant.NIGHT, false) |
||||||
|
} else { |
||||||
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) |
||||||
|
SpUtil.setBooleanValue(Constant.NIGHT, true) |
||||||
|
} |
||||||
|
activity!!.recreate() |
||||||
|
} |
||||||
|
} |
||||||
|
true |
||||||
|
} |
||||||
|
title_edit.setOnMenuItemClickListener { menuItem -> |
||||||
|
if (menuItem.itemId == R.id.action_edit) { |
||||||
|
for (i in mList.indices) { |
||||||
|
mList[i].isSelect = true |
||||||
|
} |
||||||
|
mAdapter!!.notifyDataSetChanged() |
||||||
|
} |
||||||
|
true |
||||||
|
} |
||||||
|
tv_cancel.setOnClickListener { view -> |
||||||
|
EventManager.instance.postEvent(HideBottomBarEvent(false)) |
||||||
|
updateBook(UpdateBookEvent()) |
||||||
|
} |
||||||
|
|
||||||
|
tv_delete.setOnClickListener { view -> |
||||||
|
val deleteList = mAdapter!!.selectList |
||||||
|
for (i in deleteList.indices) { |
||||||
|
if (deleteList[i].isSaved) { |
||||||
|
val count = deleteList[i].delete() |
||||||
|
LitePal.deleteAll(BookRecordBean::class.java, "bookId=?", mList[i].id) |
||||||
|
Log.e("count", "setOnClick: $count") |
||||||
|
} |
||||||
|
} |
||||||
|
ToastUtil.show(activity, getString(R.string.delete_success)) |
||||||
|
EventManager.instance.postEvent(HideBottomBarEvent(false)) |
||||||
|
updateBook(UpdateBookEvent()) |
||||||
|
} |
||||||
|
|
||||||
|
mAdapter!!.setOnItemClickListener { view, pos -> |
||||||
|
EventManager.instance.postEvent( |
||||||
|
SwitchFragmentEvent() |
||||||
|
) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private fun showLanguageDialog() { |
||||||
|
AlertDialog.Builder(activity) |
||||||
|
.setTitle(getString(R.string.choose_language)) |
||||||
|
.setSingleChoiceItems( |
||||||
|
resources.getStringArray(R.array.setting_dialog_language_choice), |
||||||
|
SpUtil.getIntValue(Constant.Language, 1) |
||||||
|
) { dialog, which -> |
||||||
|
resources.getStringArray(R.array.setting_dialog_language_choice)[which] |
||||||
|
SpUtil.setIntValue(Constant.Language, which) |
||||||
|
dialog.dismiss() |
||||||
|
if (which == 0) { |
||||||
|
selectLanguage(0) |
||||||
|
} else { |
||||||
|
selectLanguage(1) |
||||||
|
} |
||||||
|
}.create().show() |
||||||
|
} |
||||||
|
|
||||||
|
private fun selectLanguage(select: Int) { |
||||||
|
LocalManageUtil.saveSelectLanguage(activity, select) |
||||||
|
NovelMainActivity.reStart(activity!!) |
||||||
|
} |
||||||
|
|
||||||
|
private fun showBookSortDialog() { |
||||||
|
AlertDialog.Builder(activity) |
||||||
|
.setTitle(getString(R.string.choose_language)) |
||||||
|
.setSingleChoiceItems( |
||||||
|
resources.getStringArray(R.array.setting_dialog_sort_choice), |
||||||
|
if (SpUtil.getBooleanValue(Constant.BookSort, false)) 0 else 1 |
||||||
|
) { dialog, which -> |
||||||
|
if (which == 0) { |
||||||
|
SpUtil.setBooleanValue(Constant.BookSort, true) |
||||||
|
} else { |
||||||
|
SpUtil.setBooleanValue(Constant.BookSort, false) |
||||||
|
} |
||||||
|
updateBook(UpdateBookEvent()) |
||||||
|
dialog.dismiss() |
||||||
|
} |
||||||
|
.create().show() |
||||||
|
} |
||||||
|
|
||||||
|
override fun onResume() { |
||||||
|
super.onResume() |
||||||
|
updateBook(UpdateBookEvent()) |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun updateBook(event: UpdateBookEvent) { |
||||||
|
tv_cancel.visibility = View.GONE |
||||||
|
tv_delete.visibility = View.GONE |
||||||
|
title.visibility = View.VISIBLE |
||||||
|
title_edit.visibility = View.GONE |
||||||
|
mList.clear() |
||||||
|
mList.addAll(BookRepository.getInstance().collBooks) |
||||||
|
mAdapter!!.setEdit(false) |
||||||
|
} |
||||||
|
|
||||||
|
private fun update(collBookBeans: List<CollBookBean>?) { //检测书籍更新 |
||||||
|
if (collBookBeans == null || collBookBeans.isEmpty()) return |
||||||
|
val collBooks = ArrayList(collBookBeans) |
||||||
|
val observables = ArrayList<Single<BookDetailResp>>(collBooks.size) |
||||||
|
val it = collBooks.iterator() |
||||||
|
while (it.hasNext()) { |
||||||
|
val collBook = it.next() |
||||||
|
//删除本地文件 |
||||||
|
if (collBook.isLocal) { |
||||||
|
it.remove() |
||||||
|
} else { |
||||||
|
observables.add(AccountManager.getInstance().getBookDetails(collBook.id)) |
||||||
|
} |
||||||
|
} |
||||||
|
//zip可能不是一个好方法。 |
||||||
|
Single.zip<BookDetailResp, List<CollBookBean>>(observables) { objects -> |
||||||
|
val newCollBooks = ArrayList<CollBookBean>(objects.size) |
||||||
|
for (i in collBooks.indices) { |
||||||
|
val oldCollBook = collBooks[i] |
||||||
|
val newCollBook = (objects[i] as BookDetailResp).collBookBean |
||||||
|
//如果是oldBook是update状态,或者newCollBook与oldBook章节数不同 |
||||||
|
if (oldCollBook.isUpdate || oldCollBook.lastChapter != newCollBook.lastChapter) { |
||||||
|
newCollBook.setIsUpdate(true) |
||||||
|
} else { |
||||||
|
newCollBook.setIsUpdate(false) |
||||||
|
} |
||||||
|
newCollBook.lastRead = oldCollBook.lastRead |
||||||
|
newCollBooks.add(newCollBook) |
||||||
|
//存储到数据库中 |
||||||
|
BookRepository.getInstance().saveCollBooks(newCollBooks) |
||||||
|
} |
||||||
|
newCollBooks |
||||||
|
}.compose<List<CollBookBean>> { |
||||||
|
RxUtils.toSimpleSingle( |
||||||
|
it |
||||||
|
) |
||||||
|
}.subscribe(object : SingleObserver<List<CollBookBean>> { |
||||||
|
override fun onSubscribe(d: Disposable) { |
||||||
|
} |
||||||
|
|
||||||
|
override fun onSuccess(value: List<CollBookBean>) { |
||||||
|
//跟原先比较 |
||||||
|
mList.clear() |
||||||
|
mList.addAll(BookRepository.getInstance().collBooks) |
||||||
|
mAdapter!!.notifyDataSetChanged() |
||||||
|
} |
||||||
|
|
||||||
|
override fun onError(e: Throwable) {} |
||||||
|
} |
||||||
|
) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onDestroy() { |
||||||
|
super.onDestroy() |
||||||
|
EventManager.instance.unregisterSubscriber(this) |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
|
||||||
|
fun newInstance(): BookFragment { |
||||||
|
val args = Bundle() |
||||||
|
val fragment = BookFragment() |
||||||
|
fragment.arguments = args |
||||||
|
return fragment |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,119 +0,0 @@ |
|||||||
package com.novel.read.fragment; |
|
||||||
|
|
||||||
import android.os.Bundle; |
|
||||||
|
|
||||||
import androidx.annotation.NonNull; |
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager; |
|
||||||
import androidx.recyclerview.widget.RecyclerView; |
|
||||||
|
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.adapter.RankListAdapter; |
|
||||||
import com.novel.read.base.NovelBaseFragment; |
|
||||||
import com.novel.read.constants.Constant; |
|
||||||
import com.novel.read.http.AccountManager; |
|
||||||
import com.novel.read.model.protocol.RankByUpadateResp; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
import retrofit2.Call; |
|
||||||
import retrofit2.Callback; |
|
||||||
import retrofit2.Response; |
|
||||||
|
|
||||||
import static com.novel.read.constants.Constant.COMMENT_SIZE; |
|
||||||
|
|
||||||
|
|
||||||
public class BookListFragment extends NovelBaseFragment { |
|
||||||
|
|
||||||
@BindView(R.id.rlv_book_list) |
|
||||||
RecyclerView mRlvBookList; |
|
||||||
private RankListAdapter mAdapter; |
|
||||||
private List<RankByUpadateResp.BookBean> mList; |
|
||||||
String sex; |
|
||||||
String dateType; |
|
||||||
String type; |
|
||||||
private int page = 1; |
|
||||||
private int loadSize; |
|
||||||
|
|
||||||
public static BookListFragment newInstance(String type, String dateType, String sex) { |
|
||||||
Bundle args = new Bundle(); |
|
||||||
args.putString(Constant.Sex, sex); |
|
||||||
args.putString(Constant.DateType, dateType); |
|
||||||
args.putString(Constant.Type, type); |
|
||||||
BookListFragment fragment = new BookListFragment(); |
|
||||||
fragment.setArguments(args); |
|
||||||
return fragment; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected int getLayoutId() { |
|
||||||
return R.layout.fragment_book_list; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initView() { |
|
||||||
mList = new ArrayList<>(); |
|
||||||
|
|
||||||
mRlvBookList.setLayoutManager(new LinearLayoutManager(getActivity())); |
|
||||||
mAdapter = new RankListAdapter(mList,mRlvBookList); |
|
||||||
mRlvBookList.setAdapter(mAdapter); |
|
||||||
|
|
||||||
if (getArguments() != null) { |
|
||||||
sex = getArguments().getString(Constant.Sex); |
|
||||||
dateType = getArguments().getString(Constant.DateType); |
|
||||||
type = getArguments().getString(Constant.Type); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initData() { |
|
||||||
getData(); |
|
||||||
mAdapter.setOnLoadMoreListener(() -> { |
|
||||||
if (mAdapter.isLoadingMore()) { |
|
||||||
|
|
||||||
} else { |
|
||||||
if (loadSize >= COMMENT_SIZE) { |
|
||||||
mAdapter.setLoadingMore(true); |
|
||||||
mList.add(null); |
|
||||||
mAdapter.notifyDataSetChanged(); |
|
||||||
page++; |
|
||||||
getData(); |
|
||||||
} |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
private void getData() { |
|
||||||
AccountManager.getInstance().getRankList(type, sex, dateType, String.valueOf(page), new RankCallBack()); |
|
||||||
} |
|
||||||
|
|
||||||
private class RankCallBack implements Callback<RankByUpadateResp> { |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onResponse(@NonNull Call<RankByUpadateResp> call, @NonNull Response<RankByUpadateResp> response) { |
|
||||||
if (response.isSuccessful()) { |
|
||||||
|
|
||||||
if (response.body() != null) { |
|
||||||
loadSize = response.body().getBook().size(); |
|
||||||
if (mAdapter.isLoadingMore()) { |
|
||||||
mList.remove(mList.size() - 1); |
|
||||||
mList.addAll(response.body().getBook()); |
|
||||||
mAdapter.notifyDataSetChanged(); |
|
||||||
mAdapter.setLoadingMore(false); |
|
||||||
}else { |
|
||||||
mList.clear(); |
|
||||||
mList.addAll(response.body().getBook()); |
|
||||||
mAdapter.notifyDataSetChanged(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onFailure(@NonNull Call<RankByUpadateResp> call, @NonNull Throwable t) { |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,109 @@ |
|||||||
|
package com.novel.read.fragment |
||||||
|
|
||||||
|
import android.os.Bundle |
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.adapter.RankListAdapter |
||||||
|
import com.novel.read.base.NovelBaseFragment |
||||||
|
import com.novel.read.constants.Constant |
||||||
|
import com.novel.read.constants.Constant.COMMENT_SIZE |
||||||
|
import com.novel.read.http.AccountManager |
||||||
|
import com.novel.read.inter.OnLoadMoreListener |
||||||
|
import com.novel.read.model.protocol.RankByUpadateResp |
||||||
|
import kotlinx.android.synthetic.main.fragment_book_list.* |
||||||
|
import retrofit2.Call |
||||||
|
import retrofit2.Callback |
||||||
|
import retrofit2.Response |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
|
||||||
|
class BookListFragment : NovelBaseFragment() { |
||||||
|
|
||||||
|
private var mAdapter: RankListAdapter? = null |
||||||
|
private var mList: MutableList<RankByUpadateResp.BookBean> = ArrayList() |
||||||
|
private var sex: String? = null |
||||||
|
private var dateType: String? = null |
||||||
|
private var type: String? = null |
||||||
|
private var page = 1 |
||||||
|
private var loadSize: Int = 0 |
||||||
|
|
||||||
|
override fun getLayoutId(): Int { |
||||||
|
return R.layout.fragment_book_list |
||||||
|
} |
||||||
|
|
||||||
|
override fun initView() { |
||||||
|
rlv_book_list.layoutManager = LinearLayoutManager(activity) |
||||||
|
mAdapter = RankListAdapter(mList, rlv_book_list) |
||||||
|
rlv_book_list.adapter = mAdapter |
||||||
|
|
||||||
|
arguments?.let { |
||||||
|
sex = it.getString(Constant.Sex) |
||||||
|
dateType = it.getString(Constant.DateType) |
||||||
|
type = it.getString(Constant.Type) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
override fun initData() { |
||||||
|
getData() |
||||||
|
|
||||||
|
mAdapter!!.setOnLoadMoreListener(object : OnLoadMoreListener { |
||||||
|
override fun onLoadMore() { |
||||||
|
if (mAdapter!!.isLoadingMore) { |
||||||
|
|
||||||
|
} else { |
||||||
|
if (loadSize >= COMMENT_SIZE) { |
||||||
|
mAdapter!!.isLoadingMore = true |
||||||
|
mList.add(RankByUpadateResp.BookBean()) |
||||||
|
mAdapter!!.notifyDataSetChanged() |
||||||
|
page++ |
||||||
|
getData() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}) |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private fun getData() { |
||||||
|
AccountManager.getInstance().getRankList(type, sex, dateType, page.toString(), RankCallBack()) |
||||||
|
} |
||||||
|
|
||||||
|
private inner class RankCallBack : Callback<RankByUpadateResp> { |
||||||
|
|
||||||
|
override fun onResponse(call: Call<RankByUpadateResp>, response: Response<RankByUpadateResp>) { |
||||||
|
if (response.isSuccessful) { |
||||||
|
if (response.body() != null) { |
||||||
|
loadSize = response.body()!!.book.size |
||||||
|
if (mAdapter!!.isLoadingMore) { |
||||||
|
mList.removeAt(mList.size - 1) |
||||||
|
mList.addAll(response.body()!!.book) |
||||||
|
mAdapter!!.notifyDataSetChanged() |
||||||
|
mAdapter!!.isLoadingMore = false |
||||||
|
} else { |
||||||
|
mList.clear() |
||||||
|
mList.addAll(response.body()!!.book) |
||||||
|
mAdapter!!.notifyDataSetChanged() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onFailure(call: Call<RankByUpadateResp>, t: Throwable) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
|
||||||
|
fun newInstance(type: String, dateType: String, sex: String): BookListFragment { |
||||||
|
val args = Bundle() |
||||||
|
args.putString(Constant.Sex, sex) |
||||||
|
args.putString(Constant.DateType, dateType) |
||||||
|
args.putString(Constant.Type, type) |
||||||
|
val fragment = BookListFragment() |
||||||
|
fragment.arguments = args |
||||||
|
return fragment |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,173 +0,0 @@ |
|||||||
package com.novel.read.fragment; |
|
||||||
|
|
||||||
import android.os.Bundle; |
|
||||||
|
|
||||||
import androidx.annotation.NonNull; |
|
||||||
import androidx.recyclerview.widget.GridLayoutManager; |
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager; |
|
||||||
import androidx.recyclerview.widget.RecyclerView; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.EventManager; |
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.adapter.EditRecommendAdapter; |
|
||||||
import com.novel.read.adapter.HumanAdapter; |
|
||||||
import com.novel.read.adapter.RankAdapter; |
|
||||||
import com.novel.read.base.NovelBaseFragment; |
|
||||||
import com.novel.read.constants.Constant; |
|
||||||
import com.novel.read.http.AccountManager; |
|
||||||
import com.novel.read.model.protocol.RecommendListResp; |
|
||||||
import com.novel.read.widget.HeadLayout; |
|
||||||
import com.novel.read.widget.RefreshLayout; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
import retrofit2.Call; |
|
||||||
import retrofit2.Callback; |
|
||||||
import retrofit2.Response; |
|
||||||
|
|
||||||
|
|
||||||
public class ManFragment extends NovelBaseFragment { |
|
||||||
|
|
||||||
|
|
||||||
@BindView(R.id.head_pop) |
|
||||||
HeadLayout mHeadPop; |
|
||||||
@BindView(R.id.rlv_pop) |
|
||||||
RecyclerView mRlvPop; |
|
||||||
@BindView(R.id.head_recommend) |
|
||||||
HeadLayout mHeadRecommend; |
|
||||||
@BindView(R.id.rlv_recommend) |
|
||||||
RecyclerView mRlvRecommend; |
|
||||||
@BindView(R.id.head_update) |
|
||||||
HeadLayout headUpdate; |
|
||||||
@BindView(R.id.rlv_update) |
|
||||||
RecyclerView mRlvUpdate; |
|
||||||
@BindView(R.id.swipe) |
|
||||||
RefreshLayout refreshLayout; |
|
||||||
|
|
||||||
private HumanAdapter mHumanAdapter; |
|
||||||
private List<RecommendListResp.ListBean> mHumanList = new ArrayList<>(); |
|
||||||
private EditRecommendAdapter mEditAdapter; |
|
||||||
private List<RecommendListResp.ListBean> mEditList = new ArrayList<>(); |
|
||||||
private RankAdapter mRankAdapter; |
|
||||||
private List<RecommendListResp.ListBean> mRankList = new ArrayList<>(); |
|
||||||
|
|
||||||
public static ManFragment newInstance(String sex) { |
|
||||||
Bundle args = new Bundle(); |
|
||||||
args.putString(Constant.Sex, sex); |
|
||||||
ManFragment fragment = new ManFragment(); |
|
||||||
fragment.setArguments(args); |
|
||||||
return fragment; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected int getLayoutId() { |
|
||||||
return R.layout.fragment_man; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initView() { |
|
||||||
EventManager.Companion.getInstance().registerSubscriber(this); |
|
||||||
|
|
||||||
mRlvPop.setLayoutManager(new GridLayoutManager(getActivity(), 3)); |
|
||||||
mHumanAdapter = new HumanAdapter(mHumanList); |
|
||||||
mRlvPop.setAdapter(mHumanAdapter); |
|
||||||
|
|
||||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); |
|
||||||
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); |
|
||||||
mRlvRecommend.setLayoutManager(linearLayoutManager); |
|
||||||
mEditAdapter = new EditRecommendAdapter(mEditList); |
|
||||||
mRlvRecommend.setAdapter(mEditAdapter); |
|
||||||
|
|
||||||
mRlvUpdate.setLayoutManager(new GridLayoutManager(getActivity(), 3)); |
|
||||||
mRankAdapter = new RankAdapter(mRankList); |
|
||||||
mRlvUpdate.setAdapter(mRankAdapter); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initData() { |
|
||||||
refreshLayout.showLoading(); |
|
||||||
getData(); |
|
||||||
refreshLayout.setOnReloadingListener(new RefreshLayout.OnReloadingListener() { |
|
||||||
@Override |
|
||||||
public void onReload() { |
|
||||||
getData(); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
private void getData() { |
|
||||||
AccountManager.getInstance().getRecommendList(Constant.ListType.Human, new HumanCallBack()); |
|
||||||
AccountManager.getInstance().getRecommendList(Constant.ListType.EditRecommend, new EditCallBack()); |
|
||||||
AccountManager.getInstance().getRecommendList(Constant.ListType.HotSearch, new HotSearchCallBack()); |
|
||||||
} |
|
||||||
|
|
||||||
private class HumanCallBack implements Callback<RecommendListResp> { |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onResponse(@NonNull Call<RecommendListResp> call, @NonNull Response<RecommendListResp> response) { |
|
||||||
if (response.isSuccessful() && response.body() != null) { |
|
||||||
mHumanList.clear(); |
|
||||||
mHumanList.addAll(response.body().getList()); |
|
||||||
mHumanAdapter.notifyDataSetChanged(); |
|
||||||
|
|
||||||
} else { |
|
||||||
refreshLayout.showError(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onFailure(Call<RecommendListResp> call, Throwable t) { |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private class EditCallBack implements Callback<RecommendListResp> { |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onResponse(@NonNull Call<RecommendListResp> call, @NonNull Response<RecommendListResp> response) { |
|
||||||
if (response.isSuccessful() && response.body() != null) { |
|
||||||
mEditList.clear(); |
|
||||||
mEditList.addAll(response.body().getList()); |
|
||||||
mEditAdapter.notifyDataSetChanged(); |
|
||||||
|
|
||||||
} else { |
|
||||||
refreshLayout.showError(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onFailure(Call<RecommendListResp> call, Throwable t) { |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private class HotSearchCallBack implements Callback<RecommendListResp> { |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onResponse(@NonNull Call<RecommendListResp> call, @NonNull Response<RecommendListResp> response) { |
|
||||||
refreshLayout.showFinish(); |
|
||||||
if (response.isSuccessful() && response.body() != null) { |
|
||||||
|
|
||||||
mRankList.clear(); |
|
||||||
mRankList.addAll(response.body().getList()); |
|
||||||
mRankAdapter.notifyDataSetChanged(); |
|
||||||
} else { |
|
||||||
refreshLayout.showError(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onFailure(Call<RecommendListResp> call, Throwable t) { |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
public void onDestroy() { |
|
||||||
super.onDestroy(); |
|
||||||
EventManager.Companion.getInstance().unregisterSubscriber(this); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,145 @@ |
|||||||
|
package com.novel.read.fragment |
||||||
|
|
||||||
|
import android.os.Bundle |
||||||
|
import androidx.recyclerview.widget.GridLayoutManager |
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager |
||||||
|
import com.mango.mangolib.event.EventManager |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.adapter.EditRecommendAdapter |
||||||
|
import com.novel.read.adapter.HumanAdapter |
||||||
|
import com.novel.read.adapter.RankAdapter |
||||||
|
import com.novel.read.base.NovelBaseFragment |
||||||
|
import com.novel.read.constants.Constant |
||||||
|
import com.novel.read.http.AccountManager |
||||||
|
import com.novel.read.model.protocol.RecommendListResp |
||||||
|
import kotlinx.android.synthetic.main.fragment_man.* |
||||||
|
import retrofit2.Call |
||||||
|
import retrofit2.Callback |
||||||
|
import retrofit2.Response |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
|
||||||
|
class ManFragment : NovelBaseFragment() { |
||||||
|
|
||||||
|
private var mHumanAdapter: HumanAdapter? = null |
||||||
|
private val mHumanList = ArrayList<RecommendListResp.ListBean>() |
||||||
|
private var mEditAdapter: EditRecommendAdapter? = null |
||||||
|
private val mEditList = ArrayList<RecommendListResp.ListBean>() |
||||||
|
private var mRankAdapter: RankAdapter? = null |
||||||
|
private val mRankList = ArrayList<RecommendListResp.ListBean>() |
||||||
|
|
||||||
|
override fun getLayoutId(): Int { |
||||||
|
return R.layout.fragment_man |
||||||
|
} |
||||||
|
|
||||||
|
override fun initView() { |
||||||
|
EventManager.instance.registerSubscriber(this) |
||||||
|
|
||||||
|
rlv_pop.layoutManager = GridLayoutManager(activity, 3) |
||||||
|
mHumanAdapter = HumanAdapter(mHumanList) |
||||||
|
rlv_pop.adapter = mHumanAdapter |
||||||
|
|
||||||
|
val linearLayoutManager = LinearLayoutManager(activity) |
||||||
|
linearLayoutManager.orientation = LinearLayoutManager.HORIZONTAL |
||||||
|
rlv_recommend.layoutManager = linearLayoutManager |
||||||
|
mEditAdapter = EditRecommendAdapter(mEditList) |
||||||
|
rlv_recommend.adapter = mEditAdapter |
||||||
|
|
||||||
|
rlv_update.layoutManager = GridLayoutManager(activity, 3) |
||||||
|
mRankAdapter = RankAdapter(mRankList) |
||||||
|
rlv_update.adapter = mRankAdapter |
||||||
|
} |
||||||
|
|
||||||
|
override fun initData() { |
||||||
|
swipe.showLoading() |
||||||
|
getData() |
||||||
|
swipe.setOnReloadingListener { getData() } |
||||||
|
} |
||||||
|
|
||||||
|
private fun getData() { |
||||||
|
AccountManager.getInstance().getRecommendList(Constant.ListType.Human, HumanCallBack()) |
||||||
|
AccountManager.getInstance() |
||||||
|
.getRecommendList(Constant.ListType.EditRecommend, EditCallBack()) |
||||||
|
AccountManager.getInstance() |
||||||
|
.getRecommendList(Constant.ListType.HotSearch, HotSearchCallBack()) |
||||||
|
} |
||||||
|
|
||||||
|
private inner class HumanCallBack : Callback<RecommendListResp> { |
||||||
|
|
||||||
|
override fun onResponse( |
||||||
|
call: Call<RecommendListResp>, |
||||||
|
response: Response<RecommendListResp> |
||||||
|
) { |
||||||
|
if (response.isSuccessful && response.body() != null) { |
||||||
|
mHumanList.clear() |
||||||
|
mHumanList.addAll(response.body()!!.list) |
||||||
|
mHumanAdapter!!.notifyDataSetChanged() |
||||||
|
} else { |
||||||
|
swipe.showError() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onFailure(call: Call<RecommendListResp>, t: Throwable) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private inner class EditCallBack : Callback<RecommendListResp> { |
||||||
|
|
||||||
|
override fun onResponse( |
||||||
|
call: Call<RecommendListResp>, |
||||||
|
response: Response<RecommendListResp> |
||||||
|
) { |
||||||
|
if (response.isSuccessful && response.body() != null) { |
||||||
|
mEditList.clear() |
||||||
|
mEditList.addAll(response.body()!!.list) |
||||||
|
mEditAdapter!!.notifyDataSetChanged() |
||||||
|
|
||||||
|
} else { |
||||||
|
swipe.showError() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onFailure(call: Call<RecommendListResp>, t: Throwable) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private inner class HotSearchCallBack : Callback<RecommendListResp> { |
||||||
|
|
||||||
|
override fun onResponse( |
||||||
|
call: Call<RecommendListResp>, |
||||||
|
response: Response<RecommendListResp> |
||||||
|
) { |
||||||
|
swipe.showFinish() |
||||||
|
if (response.isSuccessful && response.body() != null) { |
||||||
|
mRankList.clear() |
||||||
|
mRankList.addAll(response.body()!!.list) |
||||||
|
mRankAdapter!!.notifyDataSetChanged() |
||||||
|
} else { |
||||||
|
swipe.showError() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onFailure(call: Call<RecommendListResp>, t: Throwable) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
override fun onDestroy() { |
||||||
|
super.onDestroy() |
||||||
|
EventManager.instance.unregisterSubscriber(this) |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
|
||||||
|
fun newInstance(sex: String): ManFragment { |
||||||
|
val args = Bundle() |
||||||
|
args.putString(Constant.Sex, sex) |
||||||
|
val fragment = ManFragment() |
||||||
|
fragment.arguments = args |
||||||
|
return fragment |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,152 +0,0 @@ |
|||||||
package com.novel.read.fragment; |
|
||||||
|
|
||||||
import android.content.ActivityNotFoundException; |
|
||||||
import android.content.Context; |
|
||||||
import android.content.Intent; |
|
||||||
import android.net.Uri; |
|
||||||
import android.os.Bundle; |
|
||||||
import android.view.View; |
|
||||||
import android.widget.TextView; |
|
||||||
|
|
||||||
import androidx.appcompat.widget.Toolbar; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.EventManager; |
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.activity.NovelSearchActivity; |
|
||||||
import com.novel.read.activity.NovelSettingActivity; |
|
||||||
import com.novel.read.base.NovelBaseFragment; |
|
||||||
import com.novel.read.constants.Constant; |
|
||||||
import com.novel.read.event.ReStartEvent; |
|
||||||
import com.novel.read.utlis.ToastUtil; |
|
||||||
import com.novel.read.utlis.VersionUtil; |
|
||||||
import com.novel.read.widget.dialog.AppraiseDialog; |
|
||||||
import com.squareup.otto.Subscribe; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
import butterknife.OnClick; |
|
||||||
|
|
||||||
/** |
|
||||||
* create by 赵利君 on 2019/6/10 |
|
||||||
* describe: |
|
||||||
*/ |
|
||||||
public class MoreFragment extends NovelBaseFragment { |
|
||||||
|
|
||||||
@BindView(R.id.toolbar) |
|
||||||
Toolbar title; |
|
||||||
@BindView(R.id.tv_options) |
|
||||||
TextView tvOptions; |
|
||||||
@BindView(R.id.tv_appraise) |
|
||||||
TextView tvAppraise; |
|
||||||
@BindView(R.id.tv_setting) |
|
||||||
TextView tvSetting; |
|
||||||
|
|
||||||
|
|
||||||
public static MoreFragment newInstance() { |
|
||||||
Bundle args = new Bundle(); |
|
||||||
MoreFragment fragment = new MoreFragment(); |
|
||||||
fragment.setArguments(args); |
|
||||||
return fragment; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected int getLayoutId() { |
|
||||||
return R.layout.fragment_more; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initView() { |
|
||||||
EventManager.Companion.getInstance().registerSubscriber(this); |
|
||||||
title.inflateMenu(R.menu.title_more); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initData() { |
|
||||||
title.setOnMenuItemClickListener(menuItem -> { |
|
||||||
if (menuItem.getItemId() == R.id.action_search) { |
|
||||||
toActivity(NovelSearchActivity.class); |
|
||||||
getActivity().overridePendingTransition(R.anim.message_fade_in, R.anim.message_fade_out); |
|
||||||
} |
|
||||||
return true; |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@OnClick({R.id.tv_options, R.id.tv_appraise, R.id.tv_setting}) |
|
||||||
public void onViewClicked(View view) { |
|
||||||
switch (view.getId()) { |
|
||||||
case R.id.tv_options: |
|
||||||
feedback(); |
|
||||||
break; |
|
||||||
case R.id.tv_appraise: |
|
||||||
final AppraiseDialog dialog = new AppraiseDialog(getActivity()); |
|
||||||
dialog.AppraiseDialog(new View.OnClickListener() { |
|
||||||
@Override |
|
||||||
public void onClick(View view) { |
|
||||||
goToMarket(getActivity(), VersionUtil.getPackage(getActivity())); |
|
||||||
dialog.dismiss(); |
|
||||||
} |
|
||||||
}); |
|
||||||
dialog.show(); |
|
||||||
|
|
||||||
break; |
|
||||||
case R.id.tv_setting: |
|
||||||
toActivity(NovelSettingActivity.class); |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) { |
|
||||||
super.onActivityResult(requestCode, resultCode, data); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public static void goToMarket(Context context, String packageName) { |
|
||||||
Uri uri = Uri.parse("market://details?id=" + packageName); |
|
||||||
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); |
|
||||||
final String GOOGLE_PLAY = "com.android.vending";//这里对应的是谷歌商店,跳转别的商店改成对应的即可
|
|
||||||
|
|
||||||
goToMarket.setPackage(GOOGLE_PLAY);//这里对应的是谷歌商店,跳转别的商店改成对应的即可
|
|
||||||
|
|
||||||
try { |
|
||||||
context.startActivity(goToMarket); |
|
||||||
} catch (ActivityNotFoundException e) { |
|
||||||
if (goToMarket.resolveActivity(context.getPackageManager()) != null) { //有浏览器
|
|
||||||
context.startActivity(goToMarket); |
|
||||||
}else { |
|
||||||
ToastUtil.show(context,"未检测到Google应用商店"); |
|
||||||
} |
|
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void feedback() { |
|
||||||
Intent email = new Intent(Intent.ACTION_SEND); |
|
||||||
//邮件发送类型:无附件,纯文本
|
|
||||||
email.setType("plain/text"); |
|
||||||
//邮件接收者(数组,可以是多位接收者)
|
|
||||||
String[] emailReceiver = new String[]{Constant.FeedBackEmail}; |
|
||||||
String emailTitle = getString(R.string.opinions); |
|
||||||
String emailContent = ""; |
|
||||||
//设置邮件地址
|
|
||||||
email.putExtra(Intent.EXTRA_EMAIL, emailReceiver); |
|
||||||
//设置邮件标题
|
|
||||||
email.putExtra(Intent.EXTRA_SUBJECT, emailTitle); |
|
||||||
//设置发送的内容
|
|
||||||
email.putExtra(Intent.EXTRA_TEXT, emailContent); |
|
||||||
//调用系统的邮件系统
|
|
||||||
startActivity(Intent.createChooser(email, "请选择邮件发送软件")); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onDestroy() { |
|
||||||
super.onDestroy(); |
|
||||||
EventManager.Companion.getInstance().unregisterSubscriber(this); |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void restart(ReStartEvent event) { |
|
||||||
getActivity().recreate(); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,128 @@ |
|||||||
|
package com.novel.read.fragment |
||||||
|
|
||||||
|
import android.content.ActivityNotFoundException |
||||||
|
import android.content.Context |
||||||
|
import android.content.Intent |
||||||
|
import android.net.Uri |
||||||
|
import android.os.Bundle |
||||||
|
import android.view.View |
||||||
|
import com.mango.mangolib.event.EventManager |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.activity.NovelSearchActivity |
||||||
|
import com.novel.read.activity.NovelSettingActivity |
||||||
|
import com.novel.read.base.NovelBaseFragment |
||||||
|
import com.novel.read.constants.Constant |
||||||
|
import com.novel.read.event.ReStartEvent |
||||||
|
import com.novel.read.utlis.ToastUtil |
||||||
|
import com.novel.read.utlis.VersionUtil |
||||||
|
import com.novel.read.widget.dialog.AppraiseDialog |
||||||
|
import com.squareup.otto.Subscribe |
||||||
|
import kotlinx.android.synthetic.main.fragment_more.* |
||||||
|
|
||||||
|
/** |
||||||
|
* create by 赵利君 on 2019/6/10 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class MoreFragment : NovelBaseFragment() { |
||||||
|
|
||||||
|
override fun getLayoutId(): Int { |
||||||
|
return R.layout.fragment_more |
||||||
|
} |
||||||
|
|
||||||
|
override fun initView() { |
||||||
|
EventManager.instance.registerSubscriber(this) |
||||||
|
toolbar.inflateMenu(R.menu.title_more) |
||||||
|
} |
||||||
|
|
||||||
|
override fun initData() { |
||||||
|
toolbar.setOnMenuItemClickListener { menuItem -> |
||||||
|
if (menuItem.itemId == R.id.action_search) { |
||||||
|
toActivity(NovelSearchActivity::class.java) |
||||||
|
activity!!.overridePendingTransition( |
||||||
|
R.anim.message_fade_in, |
||||||
|
R.anim.message_fade_out |
||||||
|
) |
||||||
|
} |
||||||
|
true |
||||||
|
} |
||||||
|
|
||||||
|
//意见反馈 |
||||||
|
tv_options.setOnClickListener { |
||||||
|
feedback() |
||||||
|
} |
||||||
|
|
||||||
|
//评价 |
||||||
|
tv_appraise.setOnClickListener { |
||||||
|
val dialog = AppraiseDialog(activity!!) |
||||||
|
dialog.appraiseDialog(View.OnClickListener { |
||||||
|
goToMarket(activity!!, VersionUtil.getPackage(activity)) |
||||||
|
dialog.dismiss() |
||||||
|
}) |
||||||
|
dialog.show() |
||||||
|
} |
||||||
|
|
||||||
|
//设置 |
||||||
|
tv_setting.setOnClickListener { |
||||||
|
toActivity(NovelSettingActivity::class.java) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private fun feedback() { |
||||||
|
val email = Intent(Intent.ACTION_SEND) |
||||||
|
//邮件发送类型:无附件,纯文本 |
||||||
|
email.type = "plain/text" |
||||||
|
//邮件接收者(数组,可以是多位接收者) |
||||||
|
val emailReceiver = arrayOf(Constant.FeedBackEmail) |
||||||
|
val emailTitle = getString(R.string.opinions) |
||||||
|
val emailContent = "" |
||||||
|
//设置邮件地址 |
||||||
|
email.putExtra(Intent.EXTRA_EMAIL, emailReceiver) |
||||||
|
//设置邮件标题 |
||||||
|
email.putExtra(Intent.EXTRA_SUBJECT, emailTitle) |
||||||
|
//设置发送的内容 |
||||||
|
email.putExtra(Intent.EXTRA_TEXT, emailContent) |
||||||
|
//调用系统的邮件系统 |
||||||
|
startActivity(Intent.createChooser(email, "请选择邮件发送软件")) |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun restart(event: ReStartEvent) { |
||||||
|
activity!!.recreate() |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
fun newInstance(): MoreFragment { |
||||||
|
val args = Bundle() |
||||||
|
val fragment = MoreFragment() |
||||||
|
fragment.arguments = args |
||||||
|
return fragment |
||||||
|
} |
||||||
|
|
||||||
|
fun goToMarket(context: Context, packageName: String?) { |
||||||
|
val uri = Uri.parse("market://details?id=" + packageName!!) |
||||||
|
val goToMarket = Intent(Intent.ACTION_VIEW, uri) |
||||||
|
val googlePlay = "com.android.vending"//这里对应的是谷歌商店,跳转别的商店改成对应的即可 |
||||||
|
|
||||||
|
goToMarket.setPackage(googlePlay)//这里对应的是谷歌商店,跳转别的商店改成对应的即可 |
||||||
|
|
||||||
|
try { |
||||||
|
context.startActivity(goToMarket) |
||||||
|
} catch (e: ActivityNotFoundException) { |
||||||
|
if (goToMarket.resolveActivity(context.packageManager) != null) { //有浏览器 |
||||||
|
context.startActivity(goToMarket) |
||||||
|
} else { |
||||||
|
ToastUtil.show(context, "未检测到Google应用商店") |
||||||
|
} |
||||||
|
e.printStackTrace() |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onDestroy() { |
||||||
|
super.onDestroy() |
||||||
|
EventManager.instance.unregisterSubscriber(this) |
||||||
|
} |
||||||
|
} |
@ -1,67 +0,0 @@ |
|||||||
package com.novel.read.fragment; |
|
||||||
|
|
||||||
import android.os.Bundle; |
|
||||||
import android.view.View; |
|
||||||
import android.widget.TextView; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.EventManager; |
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.activity.NovelSearchActivity; |
|
||||||
import com.novel.read.base.NovelBaseFragment; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
import butterknife.OnClick; |
|
||||||
|
|
||||||
/** |
|
||||||
* create by 赵利君 on 2019/6/10 |
|
||||||
* describe: |
|
||||||
*/ |
|
||||||
public class RecommendFragment extends NovelBaseFragment { |
|
||||||
|
|
||||||
@BindView(R.id.tv_search) |
|
||||||
TextView mTvSearch; |
|
||||||
|
|
||||||
public static RecommendFragment newInstance() { |
|
||||||
Bundle args = new Bundle(); |
|
||||||
RecommendFragment fragment = new RecommendFragment(); |
|
||||||
fragment.setArguments(args); |
|
||||||
return fragment; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected int getLayoutId() { |
|
||||||
return R.layout.fragment_recommend; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initView() { |
|
||||||
EventManager.Companion.getInstance().registerSubscriber(this); |
|
||||||
// List<Fragment> fragmentList = new ArrayList<>();
|
|
||||||
// ManFragment manFragment = ManFragment.newInstance(Constant.GenderType.Man);
|
|
||||||
// WomanFragment womanFragment = WomanFragment.newInstance(Constant.GenderType.Woman);
|
|
||||||
// fragmentList.add(manFragment);
|
|
||||||
// fragmentList.add(womanFragment);
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initData() { |
|
||||||
} |
|
||||||
|
|
||||||
@OnClick({ R.id.tv_search}) |
|
||||||
public void onViewClicked(View view) { |
|
||||||
switch (view.getId()) { |
|
||||||
case R.id.tv_search: |
|
||||||
toActivity(NovelSearchActivity.class); |
|
||||||
getActivity().overridePendingTransition(R.anim.message_fade_in, R.anim.message_fade_out); |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
public void onDestroy() { |
|
||||||
super.onDestroy(); |
|
||||||
EventManager.Companion.getInstance().unregisterSubscriber(this); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,52 @@ |
|||||||
|
package com.novel.read.fragment |
||||||
|
|
||||||
|
import android.os.Bundle |
||||||
|
import com.mango.mangolib.event.EventManager |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.activity.NovelSearchActivity |
||||||
|
import com.novel.read.base.NovelBaseFragment |
||||||
|
import kotlinx.android.synthetic.main.title_recommend.* |
||||||
|
|
||||||
|
/** |
||||||
|
* create by zlj on 2019/6/10 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class RecommendFragment : NovelBaseFragment() { |
||||||
|
|
||||||
|
override fun getLayoutId(): Int { |
||||||
|
return R.layout.fragment_recommend |
||||||
|
} |
||||||
|
|
||||||
|
override fun initView() { |
||||||
|
EventManager.instance.registerSubscriber(this) |
||||||
|
// List<Fragment> fragmentList = new ArrayList<>(); |
||||||
|
// ManFragment manFragment = ManFragment.newInstance(Constant.GenderType.Man); |
||||||
|
// WomanFragment womanFragment = WomanFragment.newInstance(Constant.GenderType.Woman); |
||||||
|
// fragmentList.add(manFragment); |
||||||
|
// fragmentList.add(womanFragment); |
||||||
|
} |
||||||
|
|
||||||
|
override fun initData() { |
||||||
|
tv_search.setOnClickListener { |
||||||
|
toActivity(NovelSearchActivity::class.java) |
||||||
|
activity!!.overridePendingTransition( |
||||||
|
R.anim.message_fade_in, |
||||||
|
R.anim.message_fade_out |
||||||
|
) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onDestroy() { |
||||||
|
super.onDestroy() |
||||||
|
EventManager.instance.unregisterSubscriber(this) |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
fun newInstance(): RecommendFragment { |
||||||
|
val args = Bundle() |
||||||
|
val fragment = RecommendFragment() |
||||||
|
fragment.arguments = args |
||||||
|
return fragment |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,104 +0,0 @@ |
|||||||
package com.novel.read.fragment; |
|
||||||
|
|
||||||
import android.os.Bundle; |
|
||||||
|
|
||||||
import android.widget.TextView; |
|
||||||
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager; |
|
||||||
import androidx.recyclerview.widget.RecyclerView; |
|
||||||
import com.mango.mangolib.event.EventManager; |
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.activity.NovelSearchActivity; |
|
||||||
import com.novel.read.adapter.StackAdapter; |
|
||||||
import com.novel.read.base.NovelBaseFragment; |
|
||||||
import com.novel.read.event.GetCategoryTypeEvent; |
|
||||||
import com.novel.read.http.AccountManager; |
|
||||||
import com.novel.read.model.protocol.CategoryTypeResp; |
|
||||||
import com.novel.read.widget.RefreshLayout; |
|
||||||
import com.squareup.otto.Subscribe; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
import butterknife.OnClick; |
|
||||||
|
|
||||||
/** |
|
||||||
* create by 赵利君 on 2019/6/10 |
|
||||||
* describe: |
|
||||||
*/ |
|
||||||
public class StackFragment extends NovelBaseFragment { |
|
||||||
|
|
||||||
@BindView(R.id.tv_search) |
|
||||||
TextView tvSearch; |
|
||||||
@BindView(R.id.rlv_book_type) |
|
||||||
RecyclerView mRlBookType; |
|
||||||
private StackAdapter mAdapter; |
|
||||||
@BindView(R.id.refresh) |
|
||||||
RefreshLayout refreshLayout; |
|
||||||
private List<CategoryTypeResp.CategoryBean> mList; |
|
||||||
|
|
||||||
public static StackFragment newInstance() { |
|
||||||
Bundle args = new Bundle(); |
|
||||||
StackFragment fragment = new StackFragment(); |
|
||||||
fragment.setArguments(args); |
|
||||||
return fragment; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected int getLayoutId() { |
|
||||||
return R.layout.fragment_stack; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initView() { |
|
||||||
EventManager.Companion.getInstance().registerSubscriber(this); |
|
||||||
mList = new ArrayList<>(); |
|
||||||
mRlBookType.setLayoutManager(new GridLayoutManager(getActivity(),2)); |
|
||||||
mAdapter = new StackAdapter(mList); |
|
||||||
mRlBookType.setAdapter(mAdapter); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initData() { |
|
||||||
refreshLayout.showLoading(); |
|
||||||
getData(); |
|
||||||
refreshLayout.setOnReloadingListener(new RefreshLayout.OnReloadingListener() { |
|
||||||
@Override |
|
||||||
public void onReload() { |
|
||||||
getData(); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
private void getData(){ |
|
||||||
AccountManager.getInstance().getCategoryType(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@OnClick(R.id.tv_search) |
|
||||||
public void onViewClicked() { |
|
||||||
toActivity(NovelSearchActivity.class); |
|
||||||
getActivity().overridePendingTransition(R.anim.message_fade_in, R.anim.message_fade_out); |
|
||||||
} |
|
||||||
|
|
||||||
@Subscribe |
|
||||||
public void getCategoryType(GetCategoryTypeEvent event){ |
|
||||||
refreshLayout.showFinish(); |
|
||||||
if (event.isFail()){ |
|
||||||
refreshLayout.showError(); |
|
||||||
}else { |
|
||||||
mList.clear(); |
|
||||||
mList.addAll(event.getResult().getCategory()); |
|
||||||
mAdapter.notifyDataSetChanged(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onDestroy() { |
|
||||||
super.onDestroy(); |
|
||||||
EventManager.Companion.getInstance().unregisterSubscriber(this); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,80 @@ |
|||||||
|
package com.novel.read.fragment |
||||||
|
|
||||||
|
import android.os.Bundle |
||||||
|
import androidx.recyclerview.widget.GridLayoutManager |
||||||
|
import com.mango.mangolib.event.EventManager |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.activity.NovelSearchActivity |
||||||
|
import com.novel.read.adapter.StackAdapter |
||||||
|
import com.novel.read.base.NovelBaseFragment |
||||||
|
import com.novel.read.event.GetCategoryTypeEvent |
||||||
|
import com.novel.read.http.AccountManager |
||||||
|
import com.novel.read.model.protocol.CategoryTypeResp |
||||||
|
import com.squareup.otto.Subscribe |
||||||
|
import kotlinx.android.synthetic.main.fragment_stack.* |
||||||
|
import kotlinx.android.synthetic.main.title_stack.* |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
/** |
||||||
|
* create by zlj on 2019/6/10 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class StackFragment : NovelBaseFragment() { |
||||||
|
|
||||||
|
private var mAdapter: StackAdapter? = null |
||||||
|
private var mList: MutableList<CategoryTypeResp.CategoryBean>? = null |
||||||
|
|
||||||
|
override fun getLayoutId(): Int { |
||||||
|
return R.layout.fragment_stack |
||||||
|
} |
||||||
|
|
||||||
|
override fun initView() { |
||||||
|
EventManager.instance.registerSubscriber(this) |
||||||
|
mList = ArrayList() |
||||||
|
rlv_book_type.layoutManager = GridLayoutManager(activity, 2) |
||||||
|
mAdapter = StackAdapter(mList) |
||||||
|
rlv_book_type.adapter = mAdapter |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
override fun initData() { |
||||||
|
refresh.showLoading() |
||||||
|
getData() |
||||||
|
refresh.setOnReloadingListener { getData() } |
||||||
|
|
||||||
|
tv_search.setOnClickListener { |
||||||
|
toActivity(NovelSearchActivity::class.java) |
||||||
|
activity!!.overridePendingTransition(R.anim.message_fade_in, R.anim.message_fade_out) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private fun getData() { |
||||||
|
AccountManager.getInstance().getCategoryType() |
||||||
|
} |
||||||
|
|
||||||
|
@Subscribe |
||||||
|
fun getCategoryType(event: GetCategoryTypeEvent) { |
||||||
|
refresh.showFinish() |
||||||
|
if (event.isFail) { |
||||||
|
refresh.showError() |
||||||
|
} else { |
||||||
|
mList!!.clear() |
||||||
|
mList!!.addAll(event.result!!.category) |
||||||
|
mAdapter!!.notifyDataSetChanged() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onDestroy() { |
||||||
|
super.onDestroy() |
||||||
|
EventManager.instance.unregisterSubscriber(this) |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
fun newInstance(): StackFragment { |
||||||
|
val args = Bundle() |
||||||
|
val fragment = StackFragment() |
||||||
|
fragment.arguments = args |
||||||
|
return fragment |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,209 +0,0 @@ |
|||||||
package com.novel.read.fragment; |
|
||||||
|
|
||||||
import android.os.Bundle; |
|
||||||
import android.view.View; |
|
||||||
|
|
||||||
import androidx.annotation.NonNull; |
|
||||||
import androidx.recyclerview.widget.GridLayoutManager; |
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager; |
|
||||||
import androidx.recyclerview.widget.RecyclerView; |
|
||||||
|
|
||||||
import com.mango.mangolib.event.EventManager; |
|
||||||
import com.novel.read.R; |
|
||||||
import com.novel.read.activity.NovelRankListActivity; |
|
||||||
import com.novel.read.activity.NovelRecommendBookListActivity; |
|
||||||
import com.novel.read.adapter.EditRecommendAdapter; |
|
||||||
import com.novel.read.adapter.HumanAdapter; |
|
||||||
import com.novel.read.adapter.RankAdapter; |
|
||||||
import com.novel.read.base.NovelBaseFragment; |
|
||||||
import com.novel.read.constants.Constant; |
|
||||||
import com.novel.read.http.AccountManager; |
|
||||||
import com.novel.read.model.protocol.RecommendListResp; |
|
||||||
import com.novel.read.widget.HeadLayout; |
|
||||||
import com.novel.read.widget.RefreshLayout; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import butterknife.BindView; |
|
||||||
import butterknife.OnClick; |
|
||||||
import retrofit2.Call; |
|
||||||
import retrofit2.Callback; |
|
||||||
import retrofit2.Response; |
|
||||||
|
|
||||||
|
|
||||||
public class WomanFragment extends NovelBaseFragment { |
|
||||||
|
|
||||||
|
|
||||||
@BindView(R.id.head_pop) |
|
||||||
HeadLayout mHeadPop; |
|
||||||
@BindView(R.id.rlv_pop) |
|
||||||
RecyclerView mRlvPop; |
|
||||||
@BindView(R.id.head_recommend) |
|
||||||
HeadLayout headRecommend; |
|
||||||
@BindView(R.id.rlv_recommend) |
|
||||||
RecyclerView mRlvRecommend; |
|
||||||
@BindView(R.id.head_update) |
|
||||||
HeadLayout headUpdate; |
|
||||||
@BindView(R.id.rlv_update) |
|
||||||
RecyclerView mRlvUpdate; |
|
||||||
@BindView(R.id.swipe) |
|
||||||
RefreshLayout refreshLayout; |
|
||||||
|
|
||||||
private HumanAdapter mHumanAdapter; |
|
||||||
private List<RecommendListResp.ListBean> mHumanList = new ArrayList<>(); |
|
||||||
private EditRecommendAdapter mEditAdapter; |
|
||||||
private List<RecommendListResp.ListBean> mEditList = new ArrayList<>(); |
|
||||||
private RankAdapter mRankAdapter; |
|
||||||
private List<RecommendListResp.ListBean> mRankList = new ArrayList<>(); |
|
||||||
|
|
||||||
public static WomanFragment newInstance(String sex) { |
|
||||||
Bundle args = new Bundle(); |
|
||||||
args.putString(Constant.Sex, sex); |
|
||||||
WomanFragment fragment = new WomanFragment(); |
|
||||||
fragment.setArguments(args); |
|
||||||
return fragment; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected int getLayoutId() { |
|
||||||
return R.layout.fragment_man; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initView() { |
|
||||||
EventManager.Companion.getInstance().registerSubscriber(this); |
|
||||||
|
|
||||||
mRlvPop.setLayoutManager(new GridLayoutManager(getActivity(), 3)); |
|
||||||
mHumanAdapter = new HumanAdapter(mHumanList); |
|
||||||
mRlvPop.setAdapter(mHumanAdapter); |
|
||||||
|
|
||||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); |
|
||||||
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); |
|
||||||
mRlvRecommend.setLayoutManager(linearLayoutManager); |
|
||||||
mEditAdapter = new EditRecommendAdapter(mEditList); |
|
||||||
mRlvRecommend.setAdapter(mEditAdapter); |
|
||||||
|
|
||||||
mRlvUpdate.setLayoutManager(new GridLayoutManager(getActivity(),3)); |
|
||||||
mRankAdapter = new RankAdapter(mRankList); |
|
||||||
mRlvUpdate.setAdapter(mRankAdapter); |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void initData() { |
|
||||||
if (getArguments() != null) { |
|
||||||
String sex = getArguments().getString(Constant.Sex); |
|
||||||
refreshLayout.showLoading(); |
|
||||||
getData(sex); |
|
||||||
refreshLayout.setOnReloadingListener(new RefreshLayout.OnReloadingListener() { |
|
||||||
@Override |
|
||||||
public void onReload() { |
|
||||||
getData(sex); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
} |
|
||||||
mHeadPop.setRightTextClickListener(new View.OnClickListener() { |
|
||||||
@Override |
|
||||||
public void onClick(View view) { |
|
||||||
|
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
private void getData(String sex){ |
|
||||||
AccountManager.getInstance().getRecommendList(Constant.ListType.Human,new HumanCallBack()); |
|
||||||
AccountManager.getInstance().getRecommendList(Constant.ListType.EditRecommend,new EditCallBack()); |
|
||||||
AccountManager.getInstance().getRecommendList(Constant.ListType.HotSearch,new HotSearchCallBack()); |
|
||||||
// AccountManager.getInstance().getRankByUpdate(1,9,new HotSearchCallBack());
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@OnClick({R.id.head_pop, R.id.head_recommend, R.id.head_update}) |
|
||||||
public void onViewClicked(View view) { |
|
||||||
Bundle bundle = new Bundle(); |
|
||||||
bundle.putString(Constant.Sex,Constant.GenderType.Woman); |
|
||||||
switch (view.getId()) { |
|
||||||
case R.id.head_pop: |
|
||||||
bundle.putString(Constant.Type,Constant.ListType.Human); |
|
||||||
toActivity(NovelRecommendBookListActivity.class,bundle); |
|
||||||
break; |
|
||||||
case R.id.head_recommend: |
|
||||||
bundle.putString(Constant.Type,Constant.ListType.EditRecommend); |
|
||||||
toActivity(NovelRankListActivity.class,bundle); |
|
||||||
break; |
|
||||||
case R.id.head_update: |
|
||||||
bundle.putString(Constant.Type,Constant.ListType.HotSearch); |
|
||||||
toActivity(NovelRankListActivity.class,bundle); |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private class HumanCallBack implements Callback<RecommendListResp> { |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onResponse(@NonNull Call<RecommendListResp> call, @NonNull Response<RecommendListResp> response) { |
|
||||||
if (response.isSuccessful()&& response.body() != null){ |
|
||||||
mHumanList.clear(); |
|
||||||
mHumanList.addAll(response.body().getList()); |
|
||||||
mHumanAdapter.notifyDataSetChanged(); |
|
||||||
|
|
||||||
}else { |
|
||||||
refreshLayout.showError(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onFailure(Call<RecommendListResp> call, Throwable t) { |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private class EditCallBack implements Callback<RecommendListResp> { |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onResponse(@NonNull Call<RecommendListResp> call, @NonNull Response<RecommendListResp> response) { |
|
||||||
if (response.isSuccessful()&& response.body() != null){ |
|
||||||
mEditList.clear(); |
|
||||||
mEditList.addAll(response.body().getList()); |
|
||||||
mEditAdapter.notifyDataSetChanged(); |
|
||||||
|
|
||||||
}else { |
|
||||||
refreshLayout.showError(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onFailure(Call<RecommendListResp> call, Throwable t) { |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private class HotSearchCallBack implements Callback<RecommendListResp> { |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onResponse(@NonNull Call<RecommendListResp> call, @NonNull Response<RecommendListResp> response) { |
|
||||||
refreshLayout.showFinish(); |
|
||||||
if (response.isSuccessful()&&response.body()!=null){ |
|
||||||
mRankList.clear(); |
|
||||||
mRankList.addAll(response.body().getList()); |
|
||||||
mRankAdapter.notifyDataSetChanged(); |
|
||||||
}else { |
|
||||||
refreshLayout.showError(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onFailure(Call<RecommendListResp> call, Throwable t) { |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onDestroy() { |
|
||||||
super.onDestroy(); |
|
||||||
EventManager.Companion.getInstance().unregisterSubscriber(this); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,171 @@ |
|||||||
|
package com.novel.read.fragment |
||||||
|
|
||||||
|
import android.os.Bundle |
||||||
|
import android.view.View |
||||||
|
import androidx.recyclerview.widget.GridLayoutManager |
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager |
||||||
|
import com.mango.mangolib.event.EventManager |
||||||
|
import com.novel.read.R |
||||||
|
import com.novel.read.activity.NovelRankListActivity |
||||||
|
import com.novel.read.activity.NovelRecommendBookListActivity |
||||||
|
import com.novel.read.adapter.EditRecommendAdapter |
||||||
|
import com.novel.read.adapter.HumanAdapter |
||||||
|
import com.novel.read.adapter.RankAdapter |
||||||
|
import com.novel.read.base.NovelBaseFragment |
||||||
|
import com.novel.read.constants.Constant |
||||||
|
import com.novel.read.http.AccountManager |
||||||
|
import com.novel.read.model.protocol.RecommendListResp |
||||||
|
import kotlinx.android.synthetic.main.fragment_man.* |
||||||
|
import retrofit2.Call |
||||||
|
import retrofit2.Callback |
||||||
|
import retrofit2.Response |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
|
||||||
|
class WomanFragment : NovelBaseFragment(), View.OnClickListener { |
||||||
|
|
||||||
|
private var mHumanAdapter: HumanAdapter? = null |
||||||
|
private val mHumanList = ArrayList<RecommendListResp.ListBean>() |
||||||
|
private var mEditAdapter: EditRecommendAdapter? = null |
||||||
|
private val mEditList = ArrayList<RecommendListResp.ListBean>() |
||||||
|
private var mRankAdapter: RankAdapter? = null |
||||||
|
private val mRankList = ArrayList<RecommendListResp.ListBean>() |
||||||
|
|
||||||
|
override fun getLayoutId(): Int { |
||||||
|
return R.layout.fragment_man |
||||||
|
} |
||||||
|
|
||||||
|
override fun initView() { |
||||||
|
EventManager.instance.registerSubscriber(this) |
||||||
|
|
||||||
|
rlv_pop.layoutManager = GridLayoutManager(activity, 3) |
||||||
|
mHumanAdapter = HumanAdapter(mHumanList) |
||||||
|
rlv_pop.adapter = mHumanAdapter |
||||||
|
|
||||||
|
val linearLayoutManager = LinearLayoutManager(activity) |
||||||
|
linearLayoutManager.orientation = LinearLayoutManager.HORIZONTAL |
||||||
|
rlv_recommend.layoutManager = linearLayoutManager |
||||||
|
mEditAdapter = EditRecommendAdapter(mEditList) |
||||||
|
rlv_recommend.adapter = mEditAdapter |
||||||
|
|
||||||
|
rlv_update.layoutManager = GridLayoutManager(activity, 3) |
||||||
|
mRankAdapter = RankAdapter(mRankList) |
||||||
|
rlv_update.adapter = mRankAdapter |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
override fun initData() { |
||||||
|
arguments?.let { |
||||||
|
val sex = it.getString(Constant.Sex) |
||||||
|
swipe.showLoading() |
||||||
|
getData(sex) |
||||||
|
swipe.setOnReloadingListener { getData(sex) } |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private fun getData(sex: String?) { |
||||||
|
AccountManager.getInstance().getRecommendList(Constant.ListType.Human, HumanCallBack()) |
||||||
|
AccountManager.getInstance() |
||||||
|
.getRecommendList(Constant.ListType.EditRecommend, EditCallBack()) |
||||||
|
AccountManager.getInstance() |
||||||
|
.getRecommendList(Constant.ListType.HotSearch, HotSearchCallBack()) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onClick(v: View) { |
||||||
|
val bundle = Bundle() |
||||||
|
bundle.putString(Constant.Sex, Constant.GenderType.Woman) |
||||||
|
when (view?.id) { |
||||||
|
R.id.head_pop -> { |
||||||
|
bundle.putString(Constant.Type, Constant.ListType.Human) |
||||||
|
toActivity(NovelRecommendBookListActivity::class.java, bundle) |
||||||
|
} |
||||||
|
R.id.head_recommend -> { |
||||||
|
bundle.putString(Constant.Type, Constant.ListType.EditRecommend) |
||||||
|
toActivity(NovelRankListActivity::class.java, bundle) |
||||||
|
} |
||||||
|
R.id.head_update -> { |
||||||
|
bundle.putString(Constant.Type, Constant.ListType.HotSearch) |
||||||
|
toActivity(NovelRankListActivity::class.java, bundle) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private inner class HumanCallBack : Callback<RecommendListResp> { |
||||||
|
|
||||||
|
override fun onResponse( |
||||||
|
call: Call<RecommendListResp>, |
||||||
|
response: Response<RecommendListResp> |
||||||
|
) { |
||||||
|
if (response.isSuccessful && response.body() != null) { |
||||||
|
mHumanList.clear() |
||||||
|
mHumanList.addAll(response.body()!!.list) |
||||||
|
mHumanAdapter!!.notifyDataSetChanged() |
||||||
|
|
||||||
|
} else { |
||||||
|
swipe.showError() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onFailure(call: Call<RecommendListResp>, t: Throwable) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private inner class EditCallBack : Callback<RecommendListResp> { |
||||||
|
|
||||||
|
override fun onResponse( |
||||||
|
call: Call<RecommendListResp>, |
||||||
|
response: Response<RecommendListResp> |
||||||
|
) { |
||||||
|
if (response.isSuccessful && response.body() != null) { |
||||||
|
mEditList.clear() |
||||||
|
mEditList.addAll(response.body()!!.list) |
||||||
|
mEditAdapter!!.notifyDataSetChanged() |
||||||
|
|
||||||
|
} else { |
||||||
|
swipe.showError() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onFailure(call: Call<RecommendListResp>, t: Throwable) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private inner class HotSearchCallBack : Callback<RecommendListResp> { |
||||||
|
|
||||||
|
override fun onResponse( |
||||||
|
call: Call<RecommendListResp>, |
||||||
|
response: Response<RecommendListResp> |
||||||
|
) { |
||||||
|
swipe.showFinish() |
||||||
|
if (response.isSuccessful && response.body() != null) { |
||||||
|
mRankList.clear() |
||||||
|
mRankList.addAll(response.body()!!.list) |
||||||
|
mRankAdapter!!.notifyDataSetChanged() |
||||||
|
} else { |
||||||
|
swipe.showError() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onFailure(call: Call<RecommendListResp>, t: Throwable) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onDestroy() { |
||||||
|
super.onDestroy() |
||||||
|
EventManager.instance.unregisterSubscriber(this) |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
fun newInstance(sex: String): WomanFragment { |
||||||
|
val args = Bundle() |
||||||
|
args.putString(Constant.Sex, sex) |
||||||
|
val fragment = WomanFragment() |
||||||
|
fragment.arguments = args |
||||||
|
return fragment |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,68 +0,0 @@ |
|||||||
package com.novel.read.widget; |
|
||||||
|
|
||||||
import android.content.Context; |
|
||||||
import android.content.res.TypedArray; |
|
||||||
import android.graphics.drawable.Drawable; |
|
||||||
import android.util.AttributeSet; |
|
||||||
import android.view.LayoutInflater; |
|
||||||
import android.widget.LinearLayout; |
|
||||||
import android.widget.TextView; |
|
||||||
|
|
||||||
import androidx.annotation.Nullable; |
|
||||||
import androidx.core.content.ContextCompat; |
|
||||||
|
|
||||||
import com.novel.read.R; |
|
||||||
|
|
||||||
public class HeadLayout extends LinearLayout { |
|
||||||
|
|
||||||
private TextView mTvHead; |
|
||||||
private TextView mTvMore; |
|
||||||
public HeadLayout(Context context, @Nullable AttributeSet attrs) { |
|
||||||
super(context, attrs); |
|
||||||
LayoutInflater.from(context).inflate(R.layout.widget_head, this, true); |
|
||||||
initViews(); |
|
||||||
initAttr(attrs); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
private void initViews() { |
|
||||||
mTvHead=findViewById(R.id.tv_head); |
|
||||||
mTvMore = findViewById(R.id.tv_more); |
|
||||||
} |
|
||||||
private void initAttr(AttributeSet attrs) { |
|
||||||
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.HeadLayout); |
|
||||||
boolean showHead = typedArray.getBoolean(R.styleable.HeadLayout_showHead, true); |
|
||||||
int headText=typedArray.getResourceId(R.styleable.HeadLayout_headText,R.string.empty_info); |
|
||||||
int headImg= typedArray.getResourceId(R.styleable.HeadLayout_headImg, R.mipmap.ic_launcher); |
|
||||||
boolean showRight = typedArray.getBoolean(R.styleable.HeadLayout_showRightText, true); |
|
||||||
int rightText=typedArray.getResourceId(R.styleable.HeadLayout_rightText,R.string.empty_info); |
|
||||||
int rightImg=typedArray.getResourceId(R.styleable.HeadLayout_rightImg,R.mipmap.ic_launcher); |
|
||||||
if (showHead){ |
|
||||||
mTvHead.setText(headText); |
|
||||||
Drawable drawable = ContextCompat.getDrawable(getContext(), headImg); |
|
||||||
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); |
|
||||||
mTvHead.setCompoundDrawables(drawable, null, null, null); |
|
||||||
}else { |
|
||||||
mTvHead.setVisibility(GONE); |
|
||||||
} |
|
||||||
if (showRight){ |
|
||||||
mTvMore.setText(rightText); |
|
||||||
if (rightImg!=R.mipmap.ic_launcher){ |
|
||||||
Drawable drawable = ContextCompat.getDrawable(getContext(), rightImg); |
|
||||||
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); |
|
||||||
mTvHead.setCompoundDrawables(null, null, drawable, null); |
|
||||||
} |
|
||||||
}else { |
|
||||||
mTvMore.setVisibility(GONE); |
|
||||||
} |
|
||||||
|
|
||||||
typedArray.recycle(); |
|
||||||
} |
|
||||||
|
|
||||||
//设置点击右边文字的监听
|
|
||||||
public void setRightTextClickListener(OnClickListener listener) { |
|
||||||
mTvMore.setOnClickListener(listener); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,55 @@ |
|||||||
|
package com.novel.read.widget |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.util.AttributeSet |
||||||
|
import android.view.LayoutInflater |
||||||
|
import android.view.View |
||||||
|
import android.widget.LinearLayout |
||||||
|
import androidx.core.content.ContextCompat |
||||||
|
import com.novel.read.R |
||||||
|
import kotlinx.android.synthetic.main.widget_head.view.* |
||||||
|
|
||||||
|
class HeadLayout(context: Context, attrs: AttributeSet?) : LinearLayout(context, attrs) { |
||||||
|
|
||||||
|
init { |
||||||
|
LayoutInflater.from(context).inflate(R.layout.widget_head, this, true) |
||||||
|
initAttr(attrs) |
||||||
|
} |
||||||
|
|
||||||
|
private fun initAttr(attrs: AttributeSet?) { |
||||||
|
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.HeadLayout) |
||||||
|
val showHead = typedArray.getBoolean(R.styleable.HeadLayout_showHead, true) |
||||||
|
val headText = typedArray.getResourceId(R.styleable.HeadLayout_headText, R.string.empty_info) |
||||||
|
val headImg = typedArray.getResourceId(R.styleable.HeadLayout_headImg, R.mipmap.ic_launcher) |
||||||
|
val showRight = typedArray.getBoolean(R.styleable.HeadLayout_showRightText, true) |
||||||
|
val rightText = typedArray.getResourceId(R.styleable.HeadLayout_rightText, R.string.empty_info) |
||||||
|
val rightImg = typedArray.getResourceId(R.styleable.HeadLayout_rightImg, R.mipmap.ic_launcher) |
||||||
|
if (showHead) { |
||||||
|
tv_head.setText(headText) |
||||||
|
val drawable = ContextCompat.getDrawable(context, headImg) |
||||||
|
drawable!!.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight) |
||||||
|
tv_head.setCompoundDrawables(drawable, null, null, null) |
||||||
|
} else { |
||||||
|
tv_head.visibility = View.GONE |
||||||
|
} |
||||||
|
if (showRight) { |
||||||
|
tv_more.setText(rightText) |
||||||
|
if (rightImg != R.mipmap.ic_launcher) { |
||||||
|
val drawable = ContextCompat.getDrawable(context, rightImg) |
||||||
|
drawable!!.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight) |
||||||
|
tv_head.setCompoundDrawables(null, null, drawable, null) |
||||||
|
} |
||||||
|
} else { |
||||||
|
tv_more.visibility = View.GONE |
||||||
|
} |
||||||
|
|
||||||
|
typedArray.recycle() |
||||||
|
} |
||||||
|
|
||||||
|
//设置点击右边文字的监听 |
||||||
|
fun setRightTextClickListener(listener: View.OnClickListener) { |
||||||
|
tv_more.setOnClickListener(listener) |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -1,175 +0,0 @@ |
|||||||
package com.novel.read.widget; |
|
||||||
|
|
||||||
import android.animation.Animator; |
|
||||||
import android.animation.AnimatorListenerAdapter; |
|
||||||
import android.animation.ValueAnimator; |
|
||||||
import android.content.Context; |
|
||||||
import android.content.res.TypedArray; |
|
||||||
import android.util.AttributeSet; |
|
||||||
import android.view.LayoutInflater; |
|
||||||
import android.view.View; |
|
||||||
import android.view.animation.AccelerateInterpolator; |
|
||||||
import android.widget.TextView; |
|
||||||
|
|
||||||
import androidx.annotation.Nullable; |
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout; |
|
||||||
import androidx.core.content.ContextCompat; |
|
||||||
import androidx.viewpager.widget.ViewPager; |
|
||||||
|
|
||||||
import com.novel.read.R; |
|
||||||
|
|
||||||
public class VpTabLayout extends ConstraintLayout implements View.OnClickListener { |
|
||||||
|
|
||||||
private boolean animFinish = true; //防止动画还未结束就开始另一个动画
|
|
||||||
private TextView mTvOne; |
|
||||||
private TextView mTvTwo; |
|
||||||
private TextView mTvThree; |
|
||||||
private View mView; |
|
||||||
private VpTabLayout.OnTabClickListener mBtnClickListener; |
|
||||||
private Context mContext; |
|
||||||
|
|
||||||
public VpTabLayout(Context context, AttributeSet attrs) { |
|
||||||
super(context, attrs); |
|
||||||
mContext = context; |
|
||||||
LayoutInflater.from(context).inflate(R.layout.widget_tab, this, true); |
|
||||||
initViews(); |
|
||||||
initAttr(attrs); |
|
||||||
} |
|
||||||
|
|
||||||
private void initViews() { |
|
||||||
mTvOne = findViewById(R.id.tv_one); |
|
||||||
mTvTwo = findViewById(R.id.tv_second); |
|
||||||
mTvThree = findViewById(R.id.tv_third); |
|
||||||
mView = findViewById(R.id.view); |
|
||||||
mTvOne.setOnClickListener(this); |
|
||||||
mTvTwo.setOnClickListener(this); |
|
||||||
mTvThree.setOnClickListener(this); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
private void initAttr(AttributeSet attrs) { |
|
||||||
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.VpTabLayout); |
|
||||||
int oneText = typedArray.getResourceId(R.styleable.VpTabLayout_oneText, R.string.empty_info); |
|
||||||
int twoText = typedArray.getResourceId(R.styleable.VpTabLayout_twoText, R.string.empty_info); |
|
||||||
int threeText = typedArray.getResourceId(R.styleable.VpTabLayout_threeText, R.string.empty_info); |
|
||||||
|
|
||||||
mTvOne.setText(oneText); |
|
||||||
mTvTwo.setText(twoText); |
|
||||||
mTvThree.setText(threeText); |
|
||||||
|
|
||||||
typedArray.recycle(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
//设置动画
|
|
||||||
public void setAnim(final int position, final ViewPager viewPager) { |
|
||||||
if (!animFinish) { |
|
||||||
return; |
|
||||||
} |
|
||||||
animFinish = false; |
|
||||||
ValueAnimator animator = null; |
|
||||||
switch (position) { |
|
||||||
case 0: |
|
||||||
animator = ValueAnimator.ofFloat(mView.getX(), mTvOne.getX()); |
|
||||||
animator.setTarget(mTvOne); |
|
||||||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
|
||||||
@Override |
|
||||||
public void onAnimationUpdate(ValueAnimator valueAnimator) { |
|
||||||
mView.setX((Float) valueAnimator.getAnimatedValue()); |
|
||||||
} |
|
||||||
}); |
|
||||||
animator.addListener(new AnimatorListenerAdapter() { |
|
||||||
@Override |
|
||||||
public void onAnimationEnd(Animator animation) { |
|
||||||
super.onAnimationEnd(animation); |
|
||||||
viewPager.setCurrentItem(position); |
|
||||||
mTvOne.setTextColor(ContextCompat.getColor(mContext,R.color.white)); |
|
||||||
mTvTwo.setTextColor(ContextCompat.getColor(mContext,R.color.colorTitle)); |
|
||||||
mTvThree.setTextColor(ContextCompat.getColor(mContext,R.color.colorTitle)); |
|
||||||
animFinish = true; |
|
||||||
} |
|
||||||
}); |
|
||||||
break; |
|
||||||
case 1: |
|
||||||
animator = ValueAnimator.ofFloat(mView.getX(), mTvTwo.getX()); |
|
||||||
animator.setTarget(mTvTwo); |
|
||||||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
|
||||||
@Override |
|
||||||
public void onAnimationUpdate(ValueAnimator valueAnimator) { |
|
||||||
mView.setX((Float) valueAnimator.getAnimatedValue()); |
|
||||||
} |
|
||||||
}); |
|
||||||
animator.addListener(new AnimatorListenerAdapter() { |
|
||||||
@Override |
|
||||||
public void onAnimationEnd(Animator animation) { |
|
||||||
super.onAnimationEnd(animation); |
|
||||||
viewPager.setCurrentItem(position); |
|
||||||
mTvOne.setTextColor(ContextCompat.getColor(mContext,R.color.colorTitle)); |
|
||||||
mTvTwo.setTextColor(ContextCompat.getColor(mContext,R.color.white)); |
|
||||||
mTvThree.setTextColor(ContextCompat.getColor(mContext,R.color.colorTitle)); |
|
||||||
animFinish = true; |
|
||||||
} |
|
||||||
}); |
|
||||||
break; |
|
||||||
case 2: |
|
||||||
animator = ValueAnimator.ofFloat(mView.getX(), mTvThree.getX()); |
|
||||||
animator.setTarget(mTvThree); |
|
||||||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
|
||||||
@Override |
|
||||||
public void onAnimationUpdate(ValueAnimator valueAnimator) { |
|
||||||
mView.setX((Float) valueAnimator.getAnimatedValue()); |
|
||||||
} |
|
||||||
}); |
|
||||||
animator.addListener(new AnimatorListenerAdapter() { |
|
||||||
@Override |
|
||||||
public void onAnimationEnd(Animator animation) { |
|
||||||
super.onAnimationEnd(animation); |
|
||||||
viewPager.setCurrentItem(position); |
|
||||||
mTvOne.setTextColor(ContextCompat.getColor(mContext,R.color.colorTitle)); |
|
||||||
mTvTwo.setTextColor(ContextCompat.getColor(mContext,R.color.colorTitle)); |
|
||||||
mTvThree.setTextColor(ContextCompat.getColor(mContext,R.color.white)); |
|
||||||
animFinish = true; |
|
||||||
} |
|
||||||
}); |
|
||||||
break; |
|
||||||
default: |
|
||||||
break; |
|
||||||
|
|
||||||
} |
|
||||||
if (animator != null) { |
|
||||||
animator.setDuration(200); |
|
||||||
animator.setInterpolator(new AccelerateInterpolator()); |
|
||||||
animator.start(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void setOnTabBtnClickListener(@Nullable VpTabLayout.OnTabClickListener listener) { |
|
||||||
this.mBtnClickListener = listener; |
|
||||||
} |
|
||||||
|
|
||||||
public void onClick(View v) { |
|
||||||
if (this.mBtnClickListener != null) { |
|
||||||
if (v.equals(this.mTvOne)) { |
|
||||||
this.mBtnClickListener.onTabBtnClick(VpTabLayout.CommonTabBtn.ONE, v); |
|
||||||
} else if (v.equals(this.mTvTwo)) { |
|
||||||
this.mBtnClickListener.onTabBtnClick(VpTabLayout.CommonTabBtn.TWO, v); |
|
||||||
} else if (v.equals(this.mTvThree)) { |
|
||||||
this.mBtnClickListener.onTabBtnClick(VpTabLayout.CommonTabBtn.THREE, v); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public static enum CommonTabBtn { |
|
||||||
ONE, |
|
||||||
TWO, |
|
||||||
THREE; |
|
||||||
|
|
||||||
private CommonTabBtn() { |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public interface OnTabClickListener { |
|
||||||
void onTabBtnClick(VpTabLayout.CommonTabBtn var1, View var2); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,157 @@ |
|||||||
|
package com.novel.read.widget |
||||||
|
|
||||||
|
import android.animation.Animator |
||||||
|
import android.animation.AnimatorListenerAdapter |
||||||
|
import android.animation.ValueAnimator |
||||||
|
import android.content.Context |
||||||
|
import android.content.res.TypedArray |
||||||
|
import android.util.AttributeSet |
||||||
|
import android.view.LayoutInflater |
||||||
|
import android.view.View |
||||||
|
import android.view.animation.AccelerateInterpolator |
||||||
|
import android.widget.TextView |
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout |
||||||
|
import androidx.core.content.ContextCompat |
||||||
|
import androidx.viewpager.widget.ViewPager |
||||||
|
|
||||||
|
import com.novel.read.R |
||||||
|
import kotlinx.android.synthetic.main.widget_tab.view.* |
||||||
|
|
||||||
|
class VpTabLayout(private val mContext: Context, attrs: AttributeSet) : |
||||||
|
ConstraintLayout(mContext, attrs), View.OnClickListener { |
||||||
|
|
||||||
|
private var animFinish = true //防止动画还未结束就开始另一个动画 |
||||||
|
private var mBtnClickListener: OnTabClickListener? = null |
||||||
|
|
||||||
|
init { |
||||||
|
LayoutInflater.from(mContext).inflate(R.layout.widget_tab, this, true) |
||||||
|
initViews() |
||||||
|
initAttr(attrs) |
||||||
|
} |
||||||
|
|
||||||
|
private fun initViews() { |
||||||
|
tv_one.setOnClickListener(this) |
||||||
|
tv_second.setOnClickListener(this) |
||||||
|
tv_third.setOnClickListener(this) |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private fun initAttr(attrs: AttributeSet) { |
||||||
|
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.VpTabLayout) |
||||||
|
val oneText = typedArray.getResourceId(R.styleable.VpTabLayout_oneText, R.string.empty_info) |
||||||
|
val twoText = typedArray.getResourceId(R.styleable.VpTabLayout_twoText, R.string.empty_info) |
||||||
|
val threeText = |
||||||
|
typedArray.getResourceId(R.styleable.VpTabLayout_threeText, R.string.empty_info) |
||||||
|
|
||||||
|
tv_one.setText(oneText) |
||||||
|
tv_second.setText(twoText) |
||||||
|
tv_third.setText(threeText) |
||||||
|
|
||||||
|
typedArray.recycle() |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
//设置动画 |
||||||
|
fun setAnim(position: Int, viewPager: ViewPager) { |
||||||
|
if (!animFinish) { |
||||||
|
return |
||||||
|
} |
||||||
|
animFinish = false |
||||||
|
var animator: ValueAnimator? = null |
||||||
|
when (position) { |
||||||
|
0 -> { |
||||||
|
animator = ValueAnimator.ofFloat(view.x, tv_one.x) |
||||||
|
animator!!.setTarget(tv_one) |
||||||
|
animator.addUpdateListener { valueAnimator -> |
||||||
|
view.x = valueAnimator.animatedValue as Float |
||||||
|
} |
||||||
|
animator.addListener(object : AnimatorListenerAdapter() { |
||||||
|
override fun onAnimationEnd(animation: Animator) { |
||||||
|
super.onAnimationEnd(animation) |
||||||
|
viewPager.currentItem = position |
||||||
|
tv_one.setTextColor(ContextCompat.getColor(mContext, R.color.white)) |
||||||
|
tv_second.setTextColor(ContextCompat.getColor(mContext, R.color.colorTitle)) |
||||||
|
tv_third.setTextColor( |
||||||
|
ContextCompat.getColor( |
||||||
|
mContext, |
||||||
|
R.color.colorTitle |
||||||
|
) |
||||||
|
) |
||||||
|
animFinish = true |
||||||
|
} |
||||||
|
}) |
||||||
|
} |
||||||
|
1 -> { |
||||||
|
animator = ValueAnimator.ofFloat(view.x, tv_second.x) |
||||||
|
animator!!.setTarget(tv_second) |
||||||
|
animator.addUpdateListener { valueAnimator -> |
||||||
|
view.x = valueAnimator.animatedValue as Float |
||||||
|
} |
||||||
|
animator.addListener(object : AnimatorListenerAdapter() { |
||||||
|
override fun onAnimationEnd(animation: Animator) { |
||||||
|
super.onAnimationEnd(animation) |
||||||
|
viewPager.currentItem = position |
||||||
|
tv_one.setTextColor(ContextCompat.getColor(mContext, R.color.colorTitle)) |
||||||
|
tv_second.setTextColor(ContextCompat.getColor(mContext, R.color.white)) |
||||||
|
tv_third.setTextColor( |
||||||
|
ContextCompat.getColor( |
||||||
|
mContext, |
||||||
|
R.color.colorTitle |
||||||
|
) |
||||||
|
) |
||||||
|
animFinish = true |
||||||
|
} |
||||||
|
}) |
||||||
|
} |
||||||
|
2 -> { |
||||||
|
animator = ValueAnimator.ofFloat(view.x, tv_third.x) |
||||||
|
animator!!.setTarget(tv_third) |
||||||
|
animator.addUpdateListener { valueAnimator -> |
||||||
|
view.x = valueAnimator.animatedValue as Float |
||||||
|
} |
||||||
|
animator.addListener(object : AnimatorListenerAdapter() { |
||||||
|
override fun onAnimationEnd(animation: Animator) { |
||||||
|
super.onAnimationEnd(animation) |
||||||
|
viewPager.currentItem = position |
||||||
|
tv_one.setTextColor(ContextCompat.getColor(mContext, R.color.colorTitle)) |
||||||
|
tv_second.setTextColor(ContextCompat.getColor(mContext, R.color.colorTitle)) |
||||||
|
tv_third.setTextColor(ContextCompat.getColor(mContext, R.color.white)) |
||||||
|
animFinish = true |
||||||
|
} |
||||||
|
}) |
||||||
|
} |
||||||
|
else -> { |
||||||
|
} |
||||||
|
} |
||||||
|
if (animator != null) { |
||||||
|
animator.duration = 200 |
||||||
|
animator.interpolator = AccelerateInterpolator() |
||||||
|
animator.start() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
fun setOnTabBtnClickListener(listener: OnTabClickListener?) { |
||||||
|
this.mBtnClickListener = listener |
||||||
|
} |
||||||
|
|
||||||
|
override fun onClick(v: View) { |
||||||
|
if (this.mBtnClickListener != null) { |
||||||
|
when (v) { |
||||||
|
this.tv_one -> this.mBtnClickListener!!.onTabBtnClick(CommonTabBtn.ONE, v) |
||||||
|
this.tv_second -> this.mBtnClickListener!!.onTabBtnClick(CommonTabBtn.TWO, v) |
||||||
|
this.tv_third -> this.mBtnClickListener!!.onTabBtnClick(CommonTabBtn.THREE, v) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
enum class CommonTabBtn() { |
||||||
|
ONE, |
||||||
|
TWO, |
||||||
|
THREE |
||||||
|
} |
||||||
|
|
||||||
|
interface OnTabClickListener { |
||||||
|
fun onTabBtnClick(var1: CommonTabBtn, var2: View) |
||||||
|
} |
||||||
|
} |
@ -1,44 +0,0 @@ |
|||||||
package com.novel.read.widget.dialog; |
|
||||||
|
|
||||||
import android.app.Dialog; |
|
||||||
import android.content.Context; |
|
||||||
import android.view.LayoutInflater; |
|
||||||
import android.view.View; |
|
||||||
import android.widget.LinearLayout; |
|
||||||
import android.widget.TextView; |
|
||||||
|
|
||||||
import androidx.annotation.NonNull; |
|
||||||
|
|
||||||
import com.novel.read.R; |
|
||||||
|
|
||||||
public class AppraiseDialog extends Dialog { |
|
||||||
private View view; |
|
||||||
private TextView mTvSure; |
|
||||||
public AppraiseDialog(@NonNull Context context) { |
|
||||||
super(context, R.style.dialog); |
|
||||||
view = LayoutInflater.from(context).inflate(R.layout.dialog_go_appraise, null); |
|
||||||
view.setHasTransientState(true); |
|
||||||
setContentView(view,new LinearLayout.LayoutParams( |
|
||||||
LinearLayout.LayoutParams.MATCH_PARENT, |
|
||||||
LinearLayout.LayoutParams.MATCH_PARENT)); |
|
||||||
setCancelable(false); |
|
||||||
initView(); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
private void initView() { |
|
||||||
TextView mTvCancel = findViewById(R.id.tv_cancel); |
|
||||||
mTvSure = findViewById(R.id.tv_appraise); |
|
||||||
mTvCancel.setOnClickListener(new View.OnClickListener() { |
|
||||||
@Override |
|
||||||
public void onClick(View view) { |
|
||||||
dismiss(); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
public void AppraiseDialog(View.OnClickListener receiveClickListener){ |
|
||||||
mTvSure.setOnClickListener(receiveClickListener); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue