diff --git a/.idea/misc.xml b/.idea/misc.xml index 703e5d4..89482aa 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,7 +5,12 @@ - + + + + + + diff --git a/README.md b/README.md index 412e49d..52124c0 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,11 @@ + 使用郭神的LitePal框架存储 - * 语音朗读、插画等功能都进行了实现 + * 语音朗读、插画、国际化、黑夜模式等功能都进行了实现 - 适配了安卓9.0,使用AndroidX控件,对刘海屏等异形屏幕有了很好的支持 -注: 之前项目采用Java编写,目前正在重构转KT代码,之后会上传Kt源代码。欢迎大家提问题。本人一定尽快修复 +注: 之前项目采用Java编写,目前正在重构转KT代码。欢迎大家提问题。本人一定尽快修复 ## 使用技术 Kt、AndroidX、Retrofit、Okhttp3、Glide、LitePal等 diff --git a/app/build.gradle b/app/build.gradle index 6dd2ccb..5ecf23e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,8 +34,6 @@ dependencies { androidTestImplementation rootProject.ext.dependencies["espresso_core"] implementation project(path: ':net_serivce') implementation project(path: ':common_lib') - //注解 - implementation "com.jakewharton:butterknife:10.0.0" - annotationProcessor "com.jakewharton:butterknife-compiler:10.0.0" + implementation 'com.allenliu.versionchecklib:library:2.2.0' } diff --git a/app/src/main/java/com/novel/read/activity/NovelBookDetailActivity.java b/app/src/main/java/com/novel/read/activity/NovelBookDetailActivity.java deleted file mode 100644 index 953abb1..0000000 --- a/app/src/main/java/com/novel/read/activity/NovelBookDetailActivity.java +++ /dev/null @@ -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 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 = event.getResult().getChapterBean(); - for (int i = 0; i { - 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()); - } -} diff --git a/app/src/main/java/com/novel/read/activity/NovelBookDetailActivity.kt b/app/src/main/java/com/novel/read/activity/NovelBookDetailActivity.kt new file mode 100644 index 0000000..cda341d --- /dev/null +++ b/app/src/main/java/com/novel/read/activity/NovelBookDetailActivity.kt @@ -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() + + 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()) + } +} diff --git a/app/src/main/java/com/novel/read/activity/NovelBookTypeListActivity.java b/app/src/main/java/com/novel/read/activity/NovelBookTypeListActivity.java deleted file mode 100644 index 59c77a9..0000000 --- a/app/src/main/java/com/novel/read/activity/NovelBookTypeListActivity.java +++ /dev/null @@ -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 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); - } -} diff --git a/app/src/main/java/com/novel/read/activity/NovelBookTypeListActivity.kt b/app/src/main/java/com/novel/read/activity/NovelBookTypeListActivity.kt new file mode 100644 index 0000000..2720057 --- /dev/null +++ b/app/src/main/java/com/novel/read/activity/NovelBookTypeListActivity.kt @@ -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 = 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) + } +} diff --git a/app/src/main/java/com/novel/read/activity/NovelMainActivity.java b/app/src/main/java/com/novel/read/activity/NovelMainActivity.java deleted file mode 100644 index 9486c0c..0000000 --- a/app/src/main/java/com/novel/read/activity/NovelMainActivity.java +++ /dev/null @@ -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 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); - } -} diff --git a/app/src/main/java/com/novel/read/activity/NovelMainActivity.kt b/app/src/main/java/com/novel/read/activity/NovelMainActivity.kt new file mode 100644 index 0000000..e269a6b --- /dev/null +++ b/app/src/main/java/com/novel/read/activity/NovelMainActivity.kt @@ -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) + } + } +} diff --git a/app/src/main/java/com/novel/read/activity/NovelRankListActivity.java b/app/src/main/java/com/novel/read/activity/NovelRankListActivity.java deleted file mode 100644 index 0539ed3..0000000 --- a/app/src/main/java/com/novel/read/activity/NovelRankListActivity.java +++ /dev/null @@ -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 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 { - - @Override - public void onResponse(@NonNull Call call, @NonNull Response 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 call, @NonNull Throwable t) { - - } - } -} diff --git a/app/src/main/java/com/novel/read/activity/NovelRankListActivity.kt b/app/src/main/java/com/novel/read/activity/NovelRankListActivity.kt new file mode 100644 index 0000000..1c68b92 --- /dev/null +++ b/app/src/main/java/com/novel/read/activity/NovelRankListActivity.kt @@ -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 = 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 { + + override fun onResponse(call: Call, response: Response) { + 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, t: Throwable) { + + } + } +} diff --git a/app/src/main/java/com/novel/read/activity/NovelReadActivity.java b/app/src/main/java/com/novel/read/activity/NovelReadActivity.java deleted file mode 100644 index a9f4b54..0000000 --- a/app/src/main/java/com/novel/read/activity/NovelReadActivity.java +++ /dev/null @@ -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 mChapters = new ArrayList<>(); - private TxtChapter mCurrentChapter; //当前章节 - private int currentChapter = 0; - private MarkAdapter mMarkAdapter; - private List 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 requestChapters) { - AccountManager.getInstance().getBookArticleDetail(mBookId, requestChapters); - mHandler.sendEmptyMessage(WHAT_CATEGORY); - } - - @Override - public void onCategoryFinish(List 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 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 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 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); - } -} diff --git a/app/src/main/java/com/novel/read/activity/NovelReadActivity.kt b/app/src/main/java/com/novel/read/activity/NovelReadActivity.kt new file mode 100644 index 0000000..7aa96fc --- /dev/null +++ b/app/src/main/java/com/novel/read/activity/NovelReadActivity.kt @@ -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() + private var mCurrentChapter: TxtChapter? = null //当前章节 + private var currentChapter = 0 + private var mMarkAdapter: MarkAdapter? = null + private val mMarks = ArrayList() + 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) { + AccountManager.getInstance().getBookArticleDetail(mBookId, requestChapters) + mHandler.sendEmptyMessage(WHAT_CATEGORY) + } + + override fun onCategoryFinish(chapters: List) { + 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() + 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, 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 + } +} diff --git a/app/src/main/java/com/novel/read/activity/NovelRecommendBookListActivity.java b/app/src/main/java/com/novel/read/activity/NovelRecommendBookListActivity.java deleted file mode 100644 index 51173db..0000000 --- a/app/src/main/java/com/novel/read/activity/NovelRecommendBookListActivity.java +++ /dev/null @@ -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 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; - } - } - }); - } -} diff --git a/app/src/main/java/com/novel/read/activity/NovelRecommendBookListActivity.kt b/app/src/main/java/com/novel/read/activity/NovelRecommendBookListActivity.kt new file mode 100644 index 0000000..ea8d0a8 --- /dev/null +++ b/app/src/main/java/com/novel/read/activity/NovelRecommendBookListActivity.kt @@ -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() + 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) + } + } + }) + + } +} diff --git a/app/src/main/java/com/novel/read/activity/NovelSearchActivity.java b/app/src/main/java/com/novel/read/activity/NovelSearchActivity.java deleted file mode 100644 index 9b0f7e8..0000000 --- a/app/src/main/java/com/novel/read/activity/NovelSearchActivity.java +++ /dev/null @@ -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 mHotList = new ArrayList<>(); - private HotAdapter mHotAdapter; - - private List mHisList = new ArrayList<>(); - private HistoryAdapter mHisAdapter; - - private List 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); - } -} diff --git a/app/src/main/java/com/novel/read/activity/NovelSearchActivity.kt b/app/src/main/java/com/novel/read/activity/NovelSearchActivity.kt new file mode 100644 index 0000000..0cf6c85 --- /dev/null +++ b/app/src/main/java/com/novel/read/activity/NovelSearchActivity.kt @@ -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() + private var mHotAdapter: HotAdapter? = null + + private var mHisList: MutableList = ArrayList() + private var mHisAdapter: HistoryAdapter? = null + + private val mSearchList = ArrayList() + 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) + } +} diff --git a/app/src/main/java/com/novel/read/activity/NovelSettingActivity.java b/app/src/main/java/com/novel/read/activity/NovelSettingActivity.java deleted file mode 100644 index 9d1beb5..0000000 --- a/app/src/main/java/com/novel/read/activity/NovelSettingActivity.java +++ /dev/null @@ -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); - } -} diff --git a/app/src/main/java/com/novel/read/activity/NovelSettingActivity.kt b/app/src/main/java/com/novel/read/activity/NovelSettingActivity.kt new file mode 100644 index 0000000..a700bd7 --- /dev/null +++ b/app/src/main/java/com/novel/read/activity/NovelSettingActivity.kt @@ -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) + } +} diff --git a/app/src/main/java/com/novel/read/activity/NovelSplashActivity.java b/app/src/main/java/com/novel/read/activity/NovelSplashActivity.java deleted file mode 100644 index a988df8..0000000 --- a/app/src/main/java/com/novel/read/activity/NovelSplashActivity.java +++ /dev/null @@ -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); - } -} diff --git a/app/src/main/java/com/novel/read/activity/NovelSplashActivity.kt b/app/src/main/java/com/novel/read/activity/NovelSplashActivity.kt new file mode 100644 index 0000000..ee7f81f --- /dev/null +++ b/app/src/main/java/com/novel/read/activity/NovelSplashActivity.kt @@ -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, + 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 + } +} diff --git a/app/src/main/java/com/novel/read/adapter/BookAdapter.java b/app/src/main/java/com/novel/read/adapter/BookAdapter.java index f256edd..7a2222a 100644 --- a/app/src/main/java/com/novel/read/adapter/BookAdapter.java +++ b/app/src/main/java/com/novel/read/adapter/BookAdapter.java @@ -26,7 +26,7 @@ public class BookAdapter extends RecyclerView.Adapter { private Context mContext; private final int VALUE_ITEM = 100; //正常item private final int EMPTY_ITEM = 101; //空白item - protected OnItemClickListener mClickListener; + private OnItemClickListener mClickListener; private boolean mEdit; public BookAdapter(List mList) { diff --git a/app/src/main/java/com/novel/read/adapter/PageStyleAdapter.java b/app/src/main/java/com/novel/read/adapter/PageStyleAdapter.java index decd716..ab8a87f 100644 --- a/app/src/main/java/com/novel/read/adapter/PageStyleAdapter.java +++ b/app/src/main/java/com/novel/read/adapter/PageStyleAdapter.java @@ -11,7 +11,6 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.mango.mangolib.event.EventManager; import com.novel.read.R; -import com.novel.read.event.SetAdsBgEvent; import com.novel.read.widget.page.PageLoader; import com.novel.read.widget.page.PageStyle; @@ -49,7 +48,6 @@ public class PageStyleAdapter extends RecyclerView.Adapter { private TextView mTvChapter; @@ -37,7 +34,7 @@ public class CategoryHolder extends ViewHolderImpl { mTvChapter.setSelected(false); mTvChapter.setTextColor(ContextCompat.getColor(getContext(),R.color.colorTitle)); mTvChapter.setCompoundDrawablesWithIntrinsicBounds(drawable,null,null,null); - mTvChapter.setText(StringUtils.convertCC(value.getTitle(),getContext())); + mTvChapter.setText(StringUtils.convertCC(value.getTitle())); } diff --git a/app/src/main/java/com/novel/read/base/BaseService.java b/app/src/main/java/com/novel/read/base/BaseService.java deleted file mode 100644 index 4b31b82..0000000 --- a/app/src/main/java/com/novel/read/base/BaseService.java +++ /dev/null @@ -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(); - } - } -} diff --git a/app/src/main/java/com/novel/read/base/BaseService.kt b/app/src/main/java/com/novel/read/base/BaseService.kt new file mode 100644 index 0000000..1a20fc6 --- /dev/null +++ b/app/src/main/java/com/novel/read/base/BaseService.kt @@ -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() + } + } +} diff --git a/app/src/main/java/com/novel/read/base/MyApp.java b/app/src/main/java/com/novel/read/base/MyApp.java deleted file mode 100644 index 25572c4..0000000 --- a/app/src/main/java/com/novel/read/base/MyApp.java +++ /dev/null @@ -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()); - } - - -} diff --git a/app/src/main/java/com/novel/read/base/MyApp.kt b/app/src/main/java/com/novel/read/base/MyApp.kt new file mode 100644 index 0000000..e241716 --- /dev/null +++ b/app/src/main/java/com/novel/read/base/MyApp.kt @@ -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 + } + + +} diff --git a/app/src/main/java/com/novel/read/base/NovelBaseActivity.java b/app/src/main/java/com/novel/read/base/NovelBaseActivity.java deleted file mode 100644 index 0f12268..0000000 --- a/app/src/main/java/com/novel/read/base/NovelBaseActivity.java +++ /dev/null @@ -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)); - } -} diff --git a/app/src/main/java/com/novel/read/base/NovelBaseActivity.kt b/app/src/main/java/com/novel/read/base/NovelBaseActivity.kt new file mode 100644 index 0000000..9e4059b --- /dev/null +++ b/app/src/main/java/com/novel/read/base/NovelBaseActivity.kt @@ -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)) + } +} diff --git a/app/src/main/java/com/novel/read/base/NovelBaseFragment.java b/app/src/main/java/com/novel/read/base/NovelBaseFragment.java deleted file mode 100644 index b84a768..0000000 --- a/app/src/main/java/com/novel/read/base/NovelBaseFragment.java +++ /dev/null @@ -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(); - } -} diff --git a/app/src/main/java/com/novel/read/base/NovelBaseFragment.kt b/app/src/main/java/com/novel/read/base/NovelBaseFragment.kt new file mode 100644 index 0000000..a2c3dbb --- /dev/null +++ b/app/src/main/java/com/novel/read/base/NovelBaseFragment.kt @@ -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) + } + + +} diff --git a/app/src/main/java/com/novel/read/constants/Constant.java b/app/src/main/java/com/novel/read/constants/Constant.java deleted file mode 100644 index 323a438..0000000 --- a/app/src/main/java/com/novel/read/constants/Constant.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Copyright 2016 JustWayward Team - *

- * 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 - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * 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"; - } -} diff --git a/app/src/main/java/com/novel/read/constants/Constant.kt b/app/src/main/java/com/novel/read/constants/Constant.kt new file mode 100644 index 0000000..d137f4d --- /dev/null +++ b/app/src/main/java/com/novel/read/constants/Constant.kt @@ -0,0 +1,121 @@ +package com.novel.read.constants + +import android.graphics.Color + +import com.novel.read.utlis.FileUtils + +import java.io.File + +// ┏┓   ┏┓ +//┏┛┻━━━┛┻┓ +//┃       ┃ +//┃   ━   ┃ +//┃ ┳┛ ┗┳ ┃ +//┃       ┃ +//┃   ┻   ┃ +//┃       ┃ +//┗━┓   ┏━┛ +// ┃   ┃ 神兽保佑 +// ┃   ┃ 代码无BUG! +// ┃   ┗━━━┓ +// ┃       ┣┓ +// ┃       ┏┛ +// ┗┓┓┏━┳┓┏┛ +// ┃┫┫ ┃┫┫ +// ┗┻┛ ┗┻┛ +/** + * Created by zlj on 2019/7/27. + * desc: 常量 + */ +object Constant { + + const val NIGHT = "NIGHT" + const val Language = "Language" + const val BookSort = "BookSort" + const val Uid = "Uid" + const val Sex = "Sex" + const val Type = "Type" + const val DateType = "DateType" + const val BookGuide = "BookGuide" //图书引导是否提示过 + + const val FORMAT_BOOK_DATE = "yyyy-MM-dd HH:mm:ss" + const val FORMAT_TIME = "HH:mm" + const val COMMENT_SIZE = 10 + + const val FeedBackEmail = "390057892@qq.com" + + /** + * 百度语音合成 + */ + const val appId = "16826023" + const val appKey = "vEuU5gIWGwq5hivdTAaKz0P9" + const val secretKey = "FcWRYUIrOPyE7dy51qfYZmg8Y1ZyP1c4 " + + //BookCachePath (因为getCachePath引用了Context,所以必须是静态变量,不能够是静态常量) + @kotlin.jvm.JvmField + var BOOK_CACHE_PATH: String = (FileUtils.getCachePath() + File.separator + + "book_cache" + File.separator) + + @kotlin.jvm.JvmField + val tagColors = intArrayOf( + 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") + ) + + //榜单类型 + interface ListType { + companion object { + const val Human = "1" + const val EditRecommend = "2" + const val HotSearch = "3" + } + } + + interface GenderType { + companion object { + const val Man = "1" + const val Woman = "2" + } + } + + interface DateTyp { + companion object { + const val General = "3" + const val Month = "2" + const val Week = "1" + } + } + + interface Bundle { + companion object { + const val CategoryId = "category_id" + const val mTitle = "mTitle" + const val BookId = "BookId" + } + } + + interface HasImage { + companion object { + const val has = 1 + } + } + + interface RequestCode { + companion object { + const val REQUEST_READ = 1 + } + } + + interface ResultCode { + companion object { + const val RESULT_IS_COLLECTED = "result_is_collected" + } + } +} diff --git a/app/src/main/java/com/novel/read/event/AddBookSignEvent.java b/app/src/main/java/com/novel/read/event/AddBookSignEvent.java deleted file mode 100644 index 942ce66..0000000 --- a/app/src/main/java/com/novel/read/event/AddBookSignEvent.java +++ /dev/null @@ -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 { - public AddBookSignEvent(ErrorResponse result) { - super(result); - } - - public AddBookSignEvent() { - } -} diff --git a/app/src/main/java/com/novel/read/event/AddBookSignEvent.kt b/app/src/main/java/com/novel/read/event/AddBookSignEvent.kt new file mode 100644 index 0000000..4566d2a --- /dev/null +++ b/app/src/main/java/com/novel/read/event/AddBookSignEvent.kt @@ -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 { + constructor(result: ErrorResponse) : super(result) {} + + constructor() {} +} diff --git a/app/src/main/java/com/novel/read/event/DeleteBookSignEvent.java b/app/src/main/java/com/novel/read/event/DeleteBookSignEvent.java deleted file mode 100644 index 7448864..0000000 --- a/app/src/main/java/com/novel/read/event/DeleteBookSignEvent.java +++ /dev/null @@ -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 { - public DeleteBookSignEvent(ErrorResponse result) { - super(result); - } - - public DeleteBookSignEvent() { - } -} diff --git a/app/src/main/java/com/novel/read/event/DeleteBookSignEvent.kt b/app/src/main/java/com/novel/read/event/DeleteBookSignEvent.kt new file mode 100644 index 0000000..fc49e8e --- /dev/null +++ b/app/src/main/java/com/novel/read/event/DeleteBookSignEvent.kt @@ -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(result) diff --git a/app/src/main/java/com/novel/read/event/DeleteResponseEvent.java b/app/src/main/java/com/novel/read/event/DeleteResponseEvent.java deleted file mode 100644 index 0eb2d36..0000000 --- a/app/src/main/java/com/novel/read/event/DeleteResponseEvent.java +++ /dev/null @@ -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; - } -} diff --git a/app/src/main/java/com/novel/read/event/DeleteResponseEvent.kt b/app/src/main/java/com/novel/read/event/DeleteResponseEvent.kt new file mode 100644 index 0000000..87a7287 --- /dev/null +++ b/app/src/main/java/com/novel/read/event/DeleteResponseEvent.kt @@ -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() diff --git a/app/src/main/java/com/novel/read/event/DeleteTaskEvent.java b/app/src/main/java/com/novel/read/event/DeleteTaskEvent.java deleted file mode 100644 index 84ef84e..0000000 --- a/app/src/main/java/com/novel/read/event/DeleteTaskEvent.java +++ /dev/null @@ -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; - } -} diff --git a/app/src/main/java/com/novel/read/event/DeleteTaskEvent.kt b/app/src/main/java/com/novel/read/event/DeleteTaskEvent.kt new file mode 100644 index 0000000..4474419 --- /dev/null +++ b/app/src/main/java/com/novel/read/event/DeleteTaskEvent.kt @@ -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() diff --git a/app/src/main/java/com/novel/read/event/ErrorChapterEvent.java b/app/src/main/java/com/novel/read/event/ErrorChapterEvent.java deleted file mode 100644 index b91538d..0000000 --- a/app/src/main/java/com/novel/read/event/ErrorChapterEvent.java +++ /dev/null @@ -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() { - } -} diff --git a/app/src/main/java/com/novel/read/event/ErrorChapterEvent.kt b/app/src/main/java/com/novel/read/event/ErrorChapterEvent.kt new file mode 100644 index 0000000..b65bead --- /dev/null +++ b/app/src/main/java/com/novel/read/event/ErrorChapterEvent.kt @@ -0,0 +1,9 @@ +package com.novel.read.event + +import com.mango.mangolib.event.BaseEvent + +class ErrorChapterEvent : BaseEvent { + constructor(result: Any) : super(result) + + constructor() +} diff --git a/app/src/main/java/com/novel/read/event/FinishChapterEvent.java b/app/src/main/java/com/novel/read/event/FinishChapterEvent.java deleted file mode 100644 index 54ff9b0..0000000 --- a/app/src/main/java/com/novel/read/event/FinishChapterEvent.java +++ /dev/null @@ -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() { - } -} diff --git a/app/src/main/java/com/novel/read/event/FinishChapterEvent.kt b/app/src/main/java/com/novel/read/event/FinishChapterEvent.kt new file mode 100644 index 0000000..d2d7a6c --- /dev/null +++ b/app/src/main/java/com/novel/read/event/FinishChapterEvent.kt @@ -0,0 +1,9 @@ +package com.novel.read.event + +import com.mango.mangolib.event.BaseEvent + +class FinishChapterEvent : BaseEvent { + constructor(result: Any) : super(result) + + constructor() +} diff --git a/app/src/main/java/com/novel/read/event/GetCategoryTypeEvent.java b/app/src/main/java/com/novel/read/event/GetCategoryTypeEvent.java deleted file mode 100644 index b9b6078..0000000 --- a/app/src/main/java/com/novel/read/event/GetCategoryTypeEvent.java +++ /dev/null @@ -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 { - - public GetCategoryTypeEvent(CategoryTypeResp result) { - super(result); - } - - public GetCategoryTypeEvent() { - } -} diff --git a/app/src/main/java/com/novel/read/event/GetCategoryTypeEvent.kt b/app/src/main/java/com/novel/read/event/GetCategoryTypeEvent.kt new file mode 100644 index 0000000..88c8e64 --- /dev/null +++ b/app/src/main/java/com/novel/read/event/GetCategoryTypeEvent.kt @@ -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 { + + constructor(result: CategoryTypeResp) : super(result) {} + + constructor() {} +} diff --git a/app/src/main/java/com/novel/read/event/HideBottomBarEvent.java b/app/src/main/java/com/novel/read/event/HideBottomBarEvent.java deleted file mode 100644 index c3ce62a..0000000 --- a/app/src/main/java/com/novel/read/event/HideBottomBarEvent.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.novel.read.event; - -import com.mango.mangolib.event.BaseEvent; - -public class HideBottomBarEvent extends BaseEvent { - public HideBottomBarEvent(Boolean result) { - super(result); - } - - public HideBottomBarEvent() { - } -} diff --git a/app/src/main/java/com/novel/read/event/HideBottomBarEvent.kt b/app/src/main/java/com/novel/read/event/HideBottomBarEvent.kt new file mode 100644 index 0000000..a9f7469 --- /dev/null +++ b/app/src/main/java/com/novel/read/event/HideBottomBarEvent.kt @@ -0,0 +1,5 @@ +package com.novel.read.event + +import com.mango.mangolib.event.BaseEvent + +class HideBottomBarEvent(result: Boolean?) : BaseEvent(result!!) diff --git a/app/src/main/java/com/novel/read/event/HotSearchEvent.java b/app/src/main/java/com/novel/read/event/HotSearchEvent.java deleted file mode 100644 index 5ab71d0..0000000 --- a/app/src/main/java/com/novel/read/event/HotSearchEvent.java +++ /dev/null @@ -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 { - - public HotSearchEvent(HotSearchResp result) { - super(result); - } - - public HotSearchEvent() { - } -} diff --git a/app/src/main/java/com/novel/read/event/HotSearchEvent.kt b/app/src/main/java/com/novel/read/event/HotSearchEvent.kt new file mode 100644 index 0000000..e152f31 --- /dev/null +++ b/app/src/main/java/com/novel/read/event/HotSearchEvent.kt @@ -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(result) diff --git a/app/src/main/java/com/novel/read/event/HumanEvent.kt b/app/src/main/java/com/novel/read/event/HumanEvent.kt index 43025b1..e7f196f 100644 --- a/app/src/main/java/com/novel/read/event/HumanEvent.kt +++ b/app/src/main/java/com/novel/read/event/HumanEvent.kt @@ -8,9 +8,6 @@ import com.novel.read.model.protocol.RecommendListResp * create by 赵利君 on 2019/6/18 * describe: */ -class HumanEvent : BaseEvent { +class HumanEvent(result: RecommendListResp) : BaseEvent(result) { - constructor(result: RecommendListResp) : super(result) {} - - constructor() {} } diff --git a/app/src/main/java/com/novel/read/event/RankByUpdateEvent.java b/app/src/main/java/com/novel/read/event/RankByUpdateEvent.java deleted file mode 100644 index b538d36..0000000 --- a/app/src/main/java/com/novel/read/event/RankByUpdateEvent.java +++ /dev/null @@ -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 { - - public RankByUpdateEvent(RankByUpadateResp result) { - super(result); - } - - public RankByUpdateEvent() { - } -} diff --git a/app/src/main/java/com/novel/read/event/RankByUpdateEvent.kt b/app/src/main/java/com/novel/read/event/RankByUpdateEvent.kt new file mode 100644 index 0000000..14c2d62 --- /dev/null +++ b/app/src/main/java/com/novel/read/event/RankByUpdateEvent.kt @@ -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 { + + constructor(result: RankByUpadateResp) : super(result) {} + + constructor() {} +} diff --git a/app/src/main/java/com/novel/read/event/RxBus.java b/app/src/main/java/com/novel/read/event/RxBus.java index 215b78c..1cd13e3 100644 --- a/app/src/main/java/com/novel/read/event/RxBus.java +++ b/app/src/main/java/com/novel/read/event/RxBus.java @@ -3,11 +3,6 @@ package com.novel.read.event; import io.reactivex.Observable; import io.reactivex.subjects.PublishSubject; -/** - * Created by newbiechen on 17-4-18. - * 原理:PublishSubject本身作为观察者和被观察者。 - */ - public class RxBus { private static volatile RxBus sInstance; private final PublishSubject mEventBus = PublishSubject.create(); diff --git a/app/src/main/java/com/novel/read/event/SetAdsBgEvent.java b/app/src/main/java/com/novel/read/event/SetAdsBgEvent.java deleted file mode 100644 index 05da283..0000000 --- a/app/src/main/java/com/novel/read/event/SetAdsBgEvent.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.novel.read.event; - -import com.mango.mangolib.event.BaseEvent; - -public class SetAdsBgEvent extends BaseEvent { - - -} diff --git a/app/src/main/java/com/novel/read/event/SwitchFragmentEvent.java b/app/src/main/java/com/novel/read/event/SwitchFragmentEvent.java deleted file mode 100644 index 5ad2791..0000000 --- a/app/src/main/java/com/novel/read/event/SwitchFragmentEvent.java +++ /dev/null @@ -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() { - } -} diff --git a/app/src/main/java/com/novel/read/event/SwitchFragmentEvent.kt b/app/src/main/java/com/novel/read/event/SwitchFragmentEvent.kt new file mode 100644 index 0000000..296ab2e --- /dev/null +++ b/app/src/main/java/com/novel/read/event/SwitchFragmentEvent.kt @@ -0,0 +1,10 @@ +package com.novel.read.event + +import com.mango.mangolib.event.BaseEvent + +class SwitchFragmentEvent : BaseEvent { + + constructor(result: Any) : super(result) {} + + constructor() {} +} diff --git a/app/src/main/java/com/novel/read/event/UpdateBookEvent.java b/app/src/main/java/com/novel/read/event/UpdateBookEvent.java deleted file mode 100644 index a1cf2ea..0000000 --- a/app/src/main/java/com/novel/read/event/UpdateBookEvent.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.novel.read.event; - -import com.mango.mangolib.event.BaseEvent; - -public class UpdateBookEvent extends BaseEvent { - - public UpdateBookEvent(String result) { - super(result); - } - - public UpdateBookEvent() { - } -} diff --git a/app/src/main/java/com/novel/read/event/UpdateBookEvent.kt b/app/src/main/java/com/novel/read/event/UpdateBookEvent.kt new file mode 100644 index 0000000..8f4a974 --- /dev/null +++ b/app/src/main/java/com/novel/read/event/UpdateBookEvent.kt @@ -0,0 +1,10 @@ +package com.novel.read.event + +import com.mango.mangolib.event.BaseEvent + +class UpdateBookEvent : BaseEvent { + + constructor(result: String) : super(result) {} + + constructor() {} +} diff --git a/app/src/main/java/com/novel/read/fragment/BookFragment.java b/app/src/main/java/com/novel/read/fragment/BookFragment.java deleted file mode 100644 index b670764..0000000 --- a/app/src/main/java/com/novel/read/fragment/BookFragment.java +++ /dev/null @@ -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 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 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 collBookBeans) { //检测书籍更新 - if (collBookBeans == null || collBookBeans.isEmpty()) return; - List collBooks = new ArrayList<>(collBookBeans); - List> observables = new ArrayList<>(collBooks.size()); - Iterator 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 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>() { - @Override - public void onSubscribe(Disposable d) { -// addDisposable(d); - } - - @Override - public void onSuccess(List 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); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/novel/read/fragment/BookFragment.kt b/app/src/main/java/com/novel/read/fragment/BookFragment.kt new file mode 100644 index 0000000..d214b4d --- /dev/null +++ b/app/src/main/java/com/novel/read/fragment/BookFragment.kt @@ -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() + 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?) { //检测书籍更新 + if (collBookBeans == null || collBookBeans.isEmpty()) return + val collBooks = ArrayList(collBookBeans) + val observables = ArrayList>(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>(observables) { objects -> + val newCollBooks = ArrayList(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> { + RxUtils.toSimpleSingle( + it + ) + }.subscribe(object : SingleObserver> { + override fun onSubscribe(d: Disposable) { + } + + override fun onSuccess(value: List) { + //跟原先比较 + 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 + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/novel/read/fragment/BookListFragment.java b/app/src/main/java/com/novel/read/fragment/BookListFragment.java deleted file mode 100644 index a94d6bd..0000000 --- a/app/src/main/java/com/novel/read/fragment/BookListFragment.java +++ /dev/null @@ -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 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 { - - @Override - public void onResponse(@NonNull Call call, @NonNull Response 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 call, @NonNull Throwable t) { - - } - } -} diff --git a/app/src/main/java/com/novel/read/fragment/BookListFragment.kt b/app/src/main/java/com/novel/read/fragment/BookListFragment.kt new file mode 100644 index 0000000..02e1055 --- /dev/null +++ b/app/src/main/java/com/novel/read/fragment/BookListFragment.kt @@ -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 = 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 { + + override fun onResponse(call: Call, response: Response) { + 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, 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 + } + } +} diff --git a/app/src/main/java/com/novel/read/fragment/ManFragment.java b/app/src/main/java/com/novel/read/fragment/ManFragment.java deleted file mode 100644 index ab44831..0000000 --- a/app/src/main/java/com/novel/read/fragment/ManFragment.java +++ /dev/null @@ -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 mHumanList = new ArrayList<>(); - private EditRecommendAdapter mEditAdapter; - private List mEditList = new ArrayList<>(); - private RankAdapter mRankAdapter; - private List 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 { - - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful() && response.body() != null) { - mHumanList.clear(); - mHumanList.addAll(response.body().getList()); - mHumanAdapter.notifyDataSetChanged(); - - } else { - refreshLayout.showError(); - } - } - - @Override - public void onFailure(Call call, Throwable t) { - - } - } - - private class EditCallBack implements Callback { - - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful() && response.body() != null) { - mEditList.clear(); - mEditList.addAll(response.body().getList()); - mEditAdapter.notifyDataSetChanged(); - - } else { - refreshLayout.showError(); - } - } - - @Override - public void onFailure(Call call, Throwable t) { - - } - } - - private class HotSearchCallBack implements Callback { - - @Override - public void onResponse(@NonNull Call call, @NonNull Response 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 call, Throwable t) { - - } - } - - - @Override - public void onDestroy() { - super.onDestroy(); - EventManager.Companion.getInstance().unregisterSubscriber(this); - } -} diff --git a/app/src/main/java/com/novel/read/fragment/ManFragment.kt b/app/src/main/java/com/novel/read/fragment/ManFragment.kt new file mode 100644 index 0000000..e8bff7b --- /dev/null +++ b/app/src/main/java/com/novel/read/fragment/ManFragment.kt @@ -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() + private var mEditAdapter: EditRecommendAdapter? = null + private val mEditList = ArrayList() + private var mRankAdapter: RankAdapter? = null + private val mRankList = ArrayList() + + 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 { + + override fun onResponse( + call: Call, + response: Response + ) { + if (response.isSuccessful && response.body() != null) { + mHumanList.clear() + mHumanList.addAll(response.body()!!.list) + mHumanAdapter!!.notifyDataSetChanged() + } else { + swipe.showError() + } + } + + override fun onFailure(call: Call, t: Throwable) { + + } + } + + private inner class EditCallBack : Callback { + + override fun onResponse( + call: Call, + response: Response + ) { + if (response.isSuccessful && response.body() != null) { + mEditList.clear() + mEditList.addAll(response.body()!!.list) + mEditAdapter!!.notifyDataSetChanged() + + } else { + swipe.showError() + } + } + + override fun onFailure(call: Call, t: Throwable) { + + } + } + + private inner class HotSearchCallBack : Callback { + + override fun onResponse( + call: Call, + response: Response + ) { + 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, 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 + } + } +} diff --git a/app/src/main/java/com/novel/read/fragment/MoreFragment.java b/app/src/main/java/com/novel/read/fragment/MoreFragment.java deleted file mode 100644 index 9e4b7d8..0000000 --- a/app/src/main/java/com/novel/read/fragment/MoreFragment.java +++ /dev/null @@ -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(); - } -} diff --git a/app/src/main/java/com/novel/read/fragment/MoreFragment.kt b/app/src/main/java/com/novel/read/fragment/MoreFragment.kt new file mode 100644 index 0000000..5d5bee3 --- /dev/null +++ b/app/src/main/java/com/novel/read/fragment/MoreFragment.kt @@ -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) + } +} diff --git a/app/src/main/java/com/novel/read/fragment/RecommendFragment.java b/app/src/main/java/com/novel/read/fragment/RecommendFragment.java deleted file mode 100644 index 2559052..0000000 --- a/app/src/main/java/com/novel/read/fragment/RecommendFragment.java +++ /dev/null @@ -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 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); - } -} diff --git a/app/src/main/java/com/novel/read/fragment/RecommendFragment.kt b/app/src/main/java/com/novel/read/fragment/RecommendFragment.kt new file mode 100644 index 0000000..337a8a5 --- /dev/null +++ b/app/src/main/java/com/novel/read/fragment/RecommendFragment.kt @@ -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 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 + } + } +} diff --git a/app/src/main/java/com/novel/read/fragment/StackFragment.java b/app/src/main/java/com/novel/read/fragment/StackFragment.java deleted file mode 100644 index e54ae04..0000000 --- a/app/src/main/java/com/novel/read/fragment/StackFragment.java +++ /dev/null @@ -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 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); - } -} diff --git a/app/src/main/java/com/novel/read/fragment/StackFragment.kt b/app/src/main/java/com/novel/read/fragment/StackFragment.kt new file mode 100644 index 0000000..c645327 --- /dev/null +++ b/app/src/main/java/com/novel/read/fragment/StackFragment.kt @@ -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? = 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 + } + } +} diff --git a/app/src/main/java/com/novel/read/fragment/WomanFragment.java b/app/src/main/java/com/novel/read/fragment/WomanFragment.java deleted file mode 100644 index e8ba909..0000000 --- a/app/src/main/java/com/novel/read/fragment/WomanFragment.java +++ /dev/null @@ -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 mHumanList = new ArrayList<>(); - private EditRecommendAdapter mEditAdapter; - private List mEditList = new ArrayList<>(); - private RankAdapter mRankAdapter; - private List 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 { - - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()&& response.body() != null){ - mHumanList.clear(); - mHumanList.addAll(response.body().getList()); - mHumanAdapter.notifyDataSetChanged(); - - }else { - refreshLayout.showError(); - } - } - - @Override - public void onFailure(Call call, Throwable t) { - - } - } - - private class EditCallBack implements Callback { - - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()&& response.body() != null){ - mEditList.clear(); - mEditList.addAll(response.body().getList()); - mEditAdapter.notifyDataSetChanged(); - - }else { - refreshLayout.showError(); - } - } - - @Override - public void onFailure(Call call, Throwable t) { - - } - } - - private class HotSearchCallBack implements Callback { - - @Override - public void onResponse(@NonNull Call call, @NonNull Response 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 call, Throwable t) { - - } - } - - @Override - public void onDestroy() { - super.onDestroy(); - EventManager.Companion.getInstance().unregisterSubscriber(this); - } -} diff --git a/app/src/main/java/com/novel/read/fragment/WomanFragment.kt b/app/src/main/java/com/novel/read/fragment/WomanFragment.kt new file mode 100644 index 0000000..c722eee --- /dev/null +++ b/app/src/main/java/com/novel/read/fragment/WomanFragment.kt @@ -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() + private var mEditAdapter: EditRecommendAdapter? = null + private val mEditList = ArrayList() + private var mRankAdapter: RankAdapter? = null + private val mRankList = ArrayList() + + 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 { + + override fun onResponse( + call: Call, + response: Response + ) { + if (response.isSuccessful && response.body() != null) { + mHumanList.clear() + mHumanList.addAll(response.body()!!.list) + mHumanAdapter!!.notifyDataSetChanged() + + } else { + swipe.showError() + } + } + + override fun onFailure(call: Call, t: Throwable) { + + } + } + + private inner class EditCallBack : Callback { + + override fun onResponse( + call: Call, + response: Response + ) { + if (response.isSuccessful && response.body() != null) { + mEditList.clear() + mEditList.addAll(response.body()!!.list) + mEditAdapter!!.notifyDataSetChanged() + + } else { + swipe.showError() + } + } + + override fun onFailure(call: Call, t: Throwable) { + + } + } + + private inner class HotSearchCallBack : Callback { + + override fun onResponse( + call: Call, + response: Response + ) { + 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, 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 + } + } +} diff --git a/app/src/main/java/com/novel/read/http/AccountManager.java b/app/src/main/java/com/novel/read/http/AccountManager.java index 32d7b56..cb12edd 100644 --- a/app/src/main/java/com/novel/read/http/AccountManager.java +++ b/app/src/main/java/com/novel/read/http/AccountManager.java @@ -8,7 +8,6 @@ import com.mango.mangolib.event.EventManager; import com.mango.mangolib.http.ErrorResponse; import com.mango.mangolib.http.MyRequestType; import com.mango.mangolib.http.ServiceCallback; -import com.novel.read.constants.Constant; import com.novel.read.event.AddBookSignEvent; import com.novel.read.event.BookArticleEvent; import com.novel.read.event.DeleteBookSignEvent; @@ -58,7 +57,7 @@ import retrofit2.Call; import retrofit2.Callback; /** - * Created by JillFung on 2017/2/14. + * Created by zlj on 2017/2/14. */ public class AccountManager { @@ -79,69 +78,68 @@ public class AccountManager { } - public void getRecommendBook(String bookId,String limit) { + public void getRecommendBook(String bookId, String limit) { HashMap map = new HashMap<>(); map.put("book_id", bookId); - Call call = accountService.getRecommendBook(getUrlString(Urls.getRecommend,map)); + Call call = accountService.getRecommendBook(getUrlString(Urls.getRecommend, map)); call.enqueue(new ServiceCallback<>(GetRecommendBookEvent.class)); } public void getBookDetail(String bookId) { HashMap map = new HashMap<>(); map.put("book_id", bookId); - Call call = accountService.getBookDetail(getUrlString(Urls.getBookDetail,map)); + Call call = accountService.getBookDetail(getUrlString(Urls.getBookDetail, map)); call.enqueue(new ServiceCallback<>(GetBookDetailEvent.class)); } - public Single getBookDetails(String bookId){ //rxjava 获取多书籍详情 合并请求调用 + public Single getBookDetails(String bookId) { //rxjava 获取多书籍详情 合并请求调用 HashMap map = new HashMap<>(); map.put("book_id", bookId); - return accountService.getBookDetails(getUrlString(Urls.getBookDetail,map)); + return accountService.getBookDetails(getUrlString(Urls.getBookDetail, map)); } public void getCategoryType() { HashMap map = new HashMap<>(); - Call call = accountService.getCategoryType(getUrlString(Urls.getCategoryType,map)); + Call call = accountService.getCategoryType(getUrlString(Urls.getCategoryType, map)); call.enqueue(new ServiceCallback<>(GetCategoryTypeEvent.class)); } public void getHotSearch() { HashMap map = new HashMap<>(); - Call call = accountService.getHotSearch(getUrlString(Urls.getHotSearch,map)); + Call call = accountService.getHotSearch(getUrlString(Urls.getHotSearch, map)); call.enqueue(new ServiceCallback<>(HotSearchEvent.class)); } - - public void getBookArticle(String bookId,String hasContent,String page,String limit) { + public void getBookArticle(String bookId, String hasContent, String page, String limit) { HashMap map = new HashMap<>(); map.put("book_id", bookId); map.put("has_content", hasContent); map.put("page", page); map.put("limit", limit); - Call call = accountService.getBookArticle(getUrlString(Urls.getBookArticle,map)); + Call call = accountService.getBookArticle(getUrlString(Urls.getBookArticle, map)); call.enqueue(new ServiceCallback<>(BookArticleEvent.class)); } - public void getSearchBookList(String category_id,String key,int page) { + public void getSearchBookList(String category_id, String key, int page) { HashMap map = new HashMap<>(); if (!TextUtils.isEmpty(category_id)) { map.put("category_id", category_id); - }else { + } else { map.put("category_id", "0"); } - if (!TextUtils.isEmpty(key)){ + if (!TextUtils.isEmpty(key)) { map.put("key", key); } map.put("page", String.valueOf(page)); - Call call = accountService.getSearchList(getUrlString(Urls.getBookList,map)); + Call call = accountService.getSearchList(getUrlString(Urls.getBookList, map)); call.enqueue(new ServiceCallback<>(SearchListEvent.class)); } public void getRecommendList(String listType, Callback callback) { HashMap map = new HashMap<>(); map.put("type", listType); - Call call = accountService.getRecommendList(getUrlString(Urls.getRecommendList,map)); + Call call = accountService.getRecommendList(getUrlString(Urls.getRecommendList, map)); call.enqueue(callback); } @@ -151,14 +149,14 @@ public class AccountManager { if (!TextUtils.isEmpty(String.valueOf(page))) { map.put("page", String.valueOf(page)); } - if (limit!=0){ + if (limit != 0) { map.put("limit", String.valueOf(limit)); } - Call call = accountService.getRankByUpdate(getUrlString(Urls.getRankByUpdate,map)); + Call call = accountService.getRankByUpdate(getUrlString(Urls.getRankByUpdate, map)); call.enqueue(callback); } - public void getRankList(String type, String sex, String dateType, String page, Callback callback){ + public void getRankList(String type, String sex, String dateType, String page, Callback callback) { HashMap map = new HashMap<>(); map.put("type", type); map.put("gender", sex); @@ -168,7 +166,7 @@ public class AccountManager { call.enqueue(callback); } - public void checkVersion(int versionCode){ + public void checkVersion(int versionCode) { HashMap map = new HashMap<>(); map.put("version", String.valueOf(versionCode)); // map.put("shell", Constant.shell); @@ -176,7 +174,7 @@ public class AccountManager { call.enqueue(new ServiceCallback<>(VersionEvent.class)); } - public void addSign(String bookId,String articleId,String content){ + public void addSign(String bookId, String articleId, String content) { HashMap map = new HashMap<>(); map.put("book_id", bookId); map.put("article_id", articleId); @@ -185,23 +183,23 @@ public class AccountManager { call.enqueue(new ServiceCallback<>(AddBookSignEvent.class)); } - public void deleteSign(String signIds){ + public void deleteSign(String signIds) { HashMap map = new HashMap<>(); map.put("sign_ids", signIds); Call call = accountService.deleteSign(Urls.deleteSign, mapToBody(map)); call.enqueue(new ServiceCallback<>(DeleteBookSignEvent.class)); } - public void getSignList(String bookId){ + public void getSignList(String bookId) { HashMap map = new HashMap<>(); map.put("book_id", bookId); Call call = accountService.getSignList(getUrlString(Urls.getBookSign, map)); call.enqueue(new ServiceCallback<>(GetBookSignEvent.class)); } - public void login(Context mContext){ + public void login(Context mContext) { HashMap map = new HashMap<>(); - Log.e("getUniquePsuedoID", "login: "+ PhoneUtils.getUniquePsuedoID()); + Log.e("getUniquePsuedoID", "login: " + PhoneUtils.getUniquePsuedoID()); map.put("code", PhoneUtils.getUniquePsuedoID()); Call call = accountService.login(Urls.login, mapToBody(map)); call.enqueue(new ServiceCallback<>(LoginEvent.class)); @@ -209,7 +207,7 @@ public class AccountManager { private Subscription mChapterSub; - public void getBookArticleDetail(String bookId,List bookChapters){ + public void getBookArticleDetail(String bookId, List bookChapters) { int size = bookChapters.size(); //取消上次的任务,防止多次加载 if (mChapterSub != null) { @@ -231,46 +229,46 @@ public class AccountManager { .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { - String title = titles.poll(); - - @Override - public void onSubscribe(Subscription s) { - s.request(Integer.MAX_VALUE); - mChapterSub = s; - } - - @Override - public void onNext(ChapterInfoBean chapterInfoBean) { - //存储数据 - BookRepository.getInstance().saveChapterInfo( - bookId, title, chapterInfoBean.getBody() - ); - EventManager.Companion.getInstance().postEvent(new FinishChapterEvent()); - //将获取到的数据进行存储 - title = titles.poll(); - } - - @Override - public void onError(Throwable t) { - //只有第一个加载失败才会调用errorChapter - if (bookChapters.get(0).getTitle().equals(title)) { - EventManager.Companion.getInstance().postEvent(new ErrorChapterEvent()); - } - LogUtils.e(t); - } - - @Override - public void onComplete() { - } - } + String title = titles.poll(); + + @Override + public void onSubscribe(Subscription s) { + s.request(Integer.MAX_VALUE); + mChapterSub = s; + } + + @Override + public void onNext(ChapterInfoBean chapterInfoBean) { + //存储数据 + BookRepository.getInstance().saveChapterInfo( + bookId, title, chapterInfoBean.getBody() + ); + EventManager.Companion.getInstance().postEvent(new FinishChapterEvent()); + //将获取到的数据进行存储 + title = titles.poll(); + } + + @Override + public void onError(Throwable t) { + //只有第一个加载失败才会调用errorChapter + if (bookChapters.get(0).getTitle().equals(title)) { + EventManager.Companion.getInstance().postEvent(new ErrorChapterEvent()); + } + LogUtils.e(t); + } + + @Override + public void onComplete() { + } + } ); } /** * 注意这里用的是同步请求 */ - public Single getChapterInfo(String id){ - HashMap map = new HashMap<>(); + public Single getChapterInfo(String id) { + HashMap map = new HashMap<>(); map.put("article_id", id); return accountService.getBookArticleDetail(getUrlString(Urls.getDetail, map)) .map(bean -> bean.getArticle().get(0)); @@ -308,7 +306,7 @@ public class AccountManager { /** * 减少请求info类的数量,直接用map替代实体类,返回body */ - private RequestBody mapToBody(HashMap map){ + private RequestBody mapToBody(HashMap map) { return RequestBody.create(MediaType.parse("application/json; charset=utf-8"), ServiceGenerator.formatResponse(map)); } diff --git a/app/src/main/java/com/novel/read/http/CommonHeadersInterceptor.java b/app/src/main/java/com/novel/read/http/CommonHeadersInterceptor.java index 86174e0..4602b06 100644 --- a/app/src/main/java/com/novel/read/http/CommonHeadersInterceptor.java +++ b/app/src/main/java/com/novel/read/http/CommonHeadersInterceptor.java @@ -12,7 +12,7 @@ import okhttp3.Request; import okhttp3.Response; /** - * Created by alex on 2019/3/1. + * Created by zlj on 2019/3/1. */ public class CommonHeadersInterceptor implements Interceptor { diff --git a/app/src/main/java/com/novel/read/http/ServiceGenerator.java b/app/src/main/java/com/novel/read/http/ServiceGenerator.java index 5196022..b78ede0 100644 --- a/app/src/main/java/com/novel/read/http/ServiceGenerator.java +++ b/app/src/main/java/com/novel/read/http/ServiceGenerator.java @@ -30,7 +30,7 @@ public class ServiceGenerator { .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create(gson)); - private static OkHttpClient getOkHttp(){ + private static OkHttpClient getOkHttp() { return new OkHttpClient() .newBuilder() .addInterceptor(new CommonHeadersInterceptor()) diff --git a/app/src/main/java/com/novel/read/http/Urls.kt b/app/src/main/java/com/novel/read/http/Urls.kt index 8055044..37e326c 100644 --- a/app/src/main/java/com/novel/read/http/Urls.kt +++ b/app/src/main/java/com/novel/read/http/Urls.kt @@ -1,7 +1,7 @@ package com.novel.read.http /** - * create by 赵利君 on 2019/10/14 + * create by zlj on 2019/10/14 * describe: */ diff --git a/app/src/main/java/com/novel/read/model/db/CollBookBean.java b/app/src/main/java/com/novel/read/model/db/CollBookBean.java index 9ccf2e1..2a7e54c 100644 --- a/app/src/main/java/com/novel/read/model/db/CollBookBean.java +++ b/app/src/main/java/com/novel/read/model/db/CollBookBean.java @@ -74,7 +74,7 @@ public class CollBookBean extends LitePalSupport implements Serializable { } public String getTitle() { - return title == null ? "" : StringUtils.convertCC(title, MyApp.getContext()); + return title == null ? "" : StringUtils.convertCC(title); } public void setTitle(String title) { @@ -82,7 +82,7 @@ public class CollBookBean extends LitePalSupport implements Serializable { } public String getAuthor() { - return author == null ? "" :StringUtils.convertCC(author, MyApp.getContext()); + return author == null ? "" :StringUtils.convertCC(author); } public void setAuthor(String author) { @@ -90,7 +90,7 @@ public class CollBookBean extends LitePalSupport implements Serializable { } public String getShortIntro() { - return shortIntro == null ? "" :StringUtils.convertCC(shortIntro, MyApp.getContext()); + return shortIntro == null ? "" :StringUtils.convertCC(shortIntro); } public void setShortIntro(String shortIntro) { @@ -154,7 +154,7 @@ public class CollBookBean extends LitePalSupport implements Serializable { } public String getLastChapter() { - return lastChapter == null ? "" : StringUtils.convertCC(lastChapter, MyApp.getContext()); + return lastChapter == null ? "" : StringUtils.convertCC(lastChapter); } public void setLastChapter(String lastChapter) { diff --git a/app/src/main/java/com/novel/read/model/db/dbManage/BookManager.java b/app/src/main/java/com/novel/read/model/db/dbManage/BookManager.java index f97233d..85d2ccc 100644 --- a/app/src/main/java/com/novel/read/model/db/dbManage/BookManager.java +++ b/app/src/main/java/com/novel/read/model/db/dbManage/BookManager.java @@ -8,12 +8,6 @@ import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Map; -/** - * Created by newbiechen on 17-5-20. - * 处理书籍的工具类,配合PageFactory使用 - * 已弃用, - */ - public class BookManager { private static final String TAG = "BookManager"; private String chapterName; diff --git a/app/src/main/java/com/novel/read/model/db/dbManage/BookRepository.java b/app/src/main/java/com/novel/read/model/db/dbManage/BookRepository.java index 172c99d..3095563 100644 --- a/app/src/main/java/com/novel/read/model/db/dbManage/BookRepository.java +++ b/app/src/main/java/com/novel/read/model/db/dbManage/BookRepository.java @@ -318,7 +318,7 @@ public class BookRepository { //删除书籍 public void deleteBook(String bookId) { - FileUtils.deleteFile(Constant.BOOK_CACHE_PATH + bookId); + FileUtils.deleteFile(Constant.INSTANCE.BOOK_CACHE_PATH + bookId); } public void deleteBookRecord(String id) { diff --git a/app/src/main/java/com/novel/read/model/protocol/CategoryTypeResp.java b/app/src/main/java/com/novel/read/model/protocol/CategoryTypeResp.java index 8390e0e..abd3a9e 100644 --- a/app/src/main/java/com/novel/read/model/protocol/CategoryTypeResp.java +++ b/app/src/main/java/com/novel/read/model/protocol/CategoryTypeResp.java @@ -39,7 +39,7 @@ public class CategoryTypeResp implements Serializable { } public String getTitle() { - return StringUtils.convertCC(title == null ? "" : title, MyApp.getContext()); + return StringUtils.convertCC(title == null ? "" : title); } public void setTitle(String title) { diff --git a/app/src/main/java/com/novel/read/model/protocol/RankByUpadateResp.java b/app/src/main/java/com/novel/read/model/protocol/RankByUpadateResp.java index 106fd77..e60cd48 100644 --- a/app/src/main/java/com/novel/read/model/protocol/RankByUpadateResp.java +++ b/app/src/main/java/com/novel/read/model/protocol/RankByUpadateResp.java @@ -57,7 +57,7 @@ public class RankByUpadateResp implements Serializable { } public String getTitle() { - return title == null ? "" : StringUtils.convertCC(title, MyApp.getContext()); + return title == null ? "" : StringUtils.convertCC(title); } public void setTitle(String title) { @@ -73,7 +73,7 @@ public class RankByUpadateResp implements Serializable { } public String getDescription() { - return description == null ? "" : StringUtils.convertCC(StringUtils.delete160(description), MyApp.getContext()); + return description == null ? "" : StringUtils.convertCC(StringUtils.delete160(description)); } public void setDescription(String description) { @@ -97,7 +97,7 @@ public class RankByUpadateResp implements Serializable { } public String getAuthor() { - return author == null ? "" :StringUtils.convertCC(author, MyApp.getContext()); + return author == null ? "" :StringUtils.convertCC(author); } public void setAuthor(String author) { diff --git a/app/src/main/java/com/novel/read/model/protocol/RecommendBookResp.java b/app/src/main/java/com/novel/read/model/protocol/RecommendBookResp.java index 51477c3..7a7fdb3 100644 --- a/app/src/main/java/com/novel/read/model/protocol/RecommendBookResp.java +++ b/app/src/main/java/com/novel/read/model/protocol/RecommendBookResp.java @@ -54,7 +54,7 @@ public class RecommendBookResp implements Serializable { } public String getTitle() { - return title == null ? "" : StringUtils.convertCC(title, MyApp.getContext()); + return title == null ? "" : StringUtils.convertCC(title); } public void setTitle(String title) { @@ -70,7 +70,7 @@ public class RecommendBookResp implements Serializable { } public String getDescription() { - return description == null ? "" : StringUtils.convertCC(StringUtils.delete160(description), MyApp.getContext()); + return description == null ? "" : StringUtils.convertCC(StringUtils.delete160(description)); } public void setDescription(String description) { @@ -94,7 +94,7 @@ public class RecommendBookResp implements Serializable { } public String getAuthor() { - return author == null ? "" : StringUtils.convertCC(author, MyApp.getContext()) ; + return author == null ? "" : StringUtils.convertCC(author) ; } public void setAuthor(String author) { diff --git a/app/src/main/java/com/novel/read/model/protocol/RecommendListResp.java b/app/src/main/java/com/novel/read/model/protocol/RecommendListResp.java index 24012ad..9d1629d 100644 --- a/app/src/main/java/com/novel/read/model/protocol/RecommendListResp.java +++ b/app/src/main/java/com/novel/read/model/protocol/RecommendListResp.java @@ -117,7 +117,7 @@ public class RecommendListResp implements Serializable { } public String getBook_title() { - return book_title == null ? "" : StringUtils.convertCC(book_title, MyApp.getContext()); + return book_title == null ? "" : StringUtils.convertCC(book_title); } public void setBook_title(String book_title) { @@ -133,7 +133,7 @@ public class RecommendListResp implements Serializable { } public String getAuthor() { - return author == null ? "" : StringUtils.convertCC(author, MyApp.getContext()); + return author == null ? "" : StringUtils.convertCC(author); } public void setAuthor(String author) { @@ -141,7 +141,7 @@ public class RecommendListResp implements Serializable { } public String getDescription() { - return description == null ? "" : StringUtils.convertCC(StringUtils.delete160(description), MyApp.getContext()); + return description == null ? "" : StringUtils.convertCC(StringUtils.delete160(description)); } public void setDescription(String description) { diff --git a/app/src/main/java/com/novel/read/model/protocol/SearchResp.java b/app/src/main/java/com/novel/read/model/protocol/SearchResp.java index 3e9c676..810ba9e 100644 --- a/app/src/main/java/com/novel/read/model/protocol/SearchResp.java +++ b/app/src/main/java/com/novel/read/model/protocol/SearchResp.java @@ -69,7 +69,7 @@ public class SearchResp implements Serializable { } public String getTitle() { - return title == null ? "" : StringUtils.convertCC(title, MyApp.getContext()); + return title == null ? "" : StringUtils.convertCC(title); } public void setTitle(String title) { @@ -93,7 +93,7 @@ public class SearchResp implements Serializable { } public String getDescription() { - return description == null ? "" : StringUtils.convertCC(StringUtils.delete160(description), MyApp.getContext()); + return description == null ? "" : StringUtils.convertCC(StringUtils.delete160(description)); } public void setDescription(String description) { @@ -117,7 +117,7 @@ public class SearchResp implements Serializable { } public String getAuthor() { - return author == null ? "" : StringUtils.convertCC(author, MyApp.getContext()); + return author == null ? "" : StringUtils.convertCC(author); } public void setAuthor(String author) { diff --git a/app/src/main/java/com/novel/read/service/DownloadService.java b/app/src/main/java/com/novel/read/service/DownloadService.java index 4eeef65..18c6d10 100644 --- a/app/src/main/java/com/novel/read/service/DownloadService.java +++ b/app/src/main/java/com/novel/read/service/DownloadService.java @@ -112,7 +112,7 @@ public class DownloadService extends BaseService { //判断是否该数据存在加载列表中 boolean isDelete = true; for (DownloadTaskBean bean : mDownloadTaskQueue) { - if (bean.getBookId().equals(event.collBook.getId())) { + if (bean.getBookId().equals(event.getCollBook().getId())) { isDelete = false; break; } @@ -123,13 +123,13 @@ public class DownloadService extends BaseService { Iterator taskIt = mDownloadTaskList.iterator(); while (taskIt.hasNext()) { DownloadTaskBean task = taskIt.next(); - if (task.getBookId().equals(event.collBook.getId())) { + if (task.getBookId().equals(event.getCollBook().getId())) { taskIt.remove(); } } } //返回状态 - RxBus.getInstance().post(new DeleteResponseEvent(isDelete, event.collBook)); + RxBus.getInstance().post(new DeleteResponseEvent(isDelete, event.getCollBook())); } ); addDisposable(deleteDisp); diff --git a/app/src/main/java/com/novel/read/utlis/DateUtli.java b/app/src/main/java/com/novel/read/utlis/DateUtli.java index f1893b1..d67ed99 100644 --- a/app/src/main/java/com/novel/read/utlis/DateUtli.java +++ b/app/src/main/java/com/novel/read/utlis/DateUtli.java @@ -138,13 +138,4 @@ public class DateUtli { */ private static String[] dayNames = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"}; - - public static boolean checkInstallTime() { - long installTime = SpUtil.getLongValue(Constant.InstallTime); - long currentTime = System.currentTimeMillis(); - //如果当前时间比安装时间早7天 并且 安装包开启次数大于7 - return currentTime - installTime > 7 * 24 * 3600 * 1000 && SpUtil.getIntValue(Constant.InstallCount, 0) > 7; - - } - } diff --git a/app/src/main/java/com/novel/read/utlis/FileUtils.java b/app/src/main/java/com/novel/read/utlis/FileUtils.java index 263e9f3..6ae81d8 100644 --- a/app/src/main/java/com/novel/read/utlis/FileUtils.java +++ b/app/src/main/java/com/novel/read/utlis/FileUtils.java @@ -61,12 +61,12 @@ public class FileUtils { //获取Cache文件夹 public static String getCachePath(){ if (isSdCardExist()){ - return MyApp.getContext() + return MyApp.Companion.getContext() .getExternalCacheDir() .getAbsolutePath(); } else{ - return MyApp.getContext() + return MyApp.Companion.getContext() .getCacheDir() .getAbsolutePath(); } diff --git a/app/src/main/java/com/novel/read/utlis/LogUtils.java b/app/src/main/java/com/novel/read/utlis/LogUtils.java index a5d5760..d1abff4 100644 --- a/app/src/main/java/com/novel/read/utlis/LogUtils.java +++ b/app/src/main/java/com/novel/read/utlis/LogUtils.java @@ -31,7 +31,7 @@ public class LogUtils { private static String LOG_FILE_NAME;// 日志文件保存名称 public static void init(Context context) { // 在Application中初始化 - LOG_FILE_PATH = Environment.getExternalStorageDirectory().getPath() + File.separator + MyApp.getContext().getPackageName(); + LOG_FILE_PATH = Environment.getExternalStorageDirectory().getPath() + File.separator + MyApp.Companion.getContext().getPackageName(); LOG_FILE_NAME = "Log"; } diff --git a/app/src/main/java/com/novel/read/utlis/NetworkUtils.java b/app/src/main/java/com/novel/read/utlis/NetworkUtils.java index a032c1d..1b95e3b 100644 --- a/app/src/main/java/com/novel/read/utlis/NetworkUtils.java +++ b/app/src/main/java/com/novel/read/utlis/NetworkUtils.java @@ -18,7 +18,7 @@ public class NetworkUtils { * @return NetworkInfo */ public static NetworkInfo getNetworkInfo(){ - ConnectivityManager cm = (ConnectivityManager) MyApp.getContext().getSystemService(Context.CONNECTIVITY_SERVICE); + ConnectivityManager cm = (ConnectivityManager) MyApp.Companion.getContext().getSystemService(Context.CONNECTIVITY_SERVICE); return cm.getActiveNetworkInfo(); } diff --git a/app/src/main/java/com/novel/read/utlis/ScreenUtils.java b/app/src/main/java/com/novel/read/utlis/ScreenUtils.java index bfaf3a1..e67c0f7 100644 --- a/app/src/main/java/com/novel/read/utlis/ScreenUtils.java +++ b/app/src/main/java/com/novel/read/utlis/ScreenUtils.java @@ -68,7 +68,7 @@ public class ScreenUtils { * @return */ public static int getStatusBarHeight(){ - Resources resources = MyApp.getContext().getResources(); + Resources resources = MyApp.Companion.getContext().getResources(); int resourceId = resources.getIdentifier("status_bar_height","dimen","android"); return resources.getDimensionPixelSize(resourceId); } @@ -79,7 +79,7 @@ public class ScreenUtils { */ public static int getNavigationBarHeight() { int navigationBarHeight = 0; - Resources rs = MyApp.getContext().getResources(); + Resources rs = MyApp.Companion.getContext().getResources(); int id = rs.getIdentifier("navigation_bar_height", "dimen", "android"); if (id > 0 && hasNavigationBar()) { navigationBarHeight = rs.getDimensionPixelSize(id); @@ -93,7 +93,7 @@ public class ScreenUtils { */ private static boolean hasNavigationBar() { boolean hasNavigationBar = false; - Resources rs = MyApp.getContext().getResources(); + Resources rs = MyApp.Companion.getContext().getResources(); int id = rs.getIdentifier("config_showNavigationBar", "bool", "android"); if (id > 0) { hasNavigationBar = rs.getBoolean(id); @@ -114,7 +114,7 @@ public class ScreenUtils { public static DisplayMetrics getDisplayMetrics(){ DisplayMetrics metrics = MyApp - .getContext() + .Companion.getContext() .getResources() .getDisplayMetrics(); return metrics; diff --git a/app/src/main/java/com/novel/read/utlis/StringUtils.java b/app/src/main/java/com/novel/read/utlis/StringUtils.java index 59b87c3..ef3adce 100644 --- a/app/src/main/java/com/novel/read/utlis/StringUtils.java +++ b/app/src/main/java/com/novel/read/utlis/StringUtils.java @@ -55,7 +55,7 @@ public class StringUtils { } //繁簡轉換 - public static String convertCC(String input, Context context) { + public static String convertCC(String input) { int convertType = SpUtil.getIntValue(SHARED_READ_CONVERT_TYPE, 1); if (input.length() == 0) diff --git a/app/src/main/java/com/novel/read/widget/HeadLayout.java b/app/src/main/java/com/novel/read/widget/HeadLayout.java deleted file mode 100644 index 2fb90e0..0000000 --- a/app/src/main/java/com/novel/read/widget/HeadLayout.java +++ /dev/null @@ -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); - } - - -} diff --git a/app/src/main/java/com/novel/read/widget/HeadLayout.kt b/app/src/main/java/com/novel/read/widget/HeadLayout.kt new file mode 100644 index 0000000..c99cc35 --- /dev/null +++ b/app/src/main/java/com/novel/read/widget/HeadLayout.kt @@ -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) + } + + +} diff --git a/app/src/main/java/com/novel/read/widget/VpTabLayout.java b/app/src/main/java/com/novel/read/widget/VpTabLayout.java deleted file mode 100644 index 3006eaf..0000000 --- a/app/src/main/java/com/novel/read/widget/VpTabLayout.java +++ /dev/null @@ -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); - } -} diff --git a/app/src/main/java/com/novel/read/widget/VpTabLayout.kt b/app/src/main/java/com/novel/read/widget/VpTabLayout.kt new file mode 100644 index 0000000..84c04fc --- /dev/null +++ b/app/src/main/java/com/novel/read/widget/VpTabLayout.kt @@ -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) + } +} diff --git a/app/src/main/java/com/novel/read/widget/dialog/AppraiseDialog.java b/app/src/main/java/com/novel/read/widget/dialog/AppraiseDialog.java deleted file mode 100644 index d817e15..0000000 --- a/app/src/main/java/com/novel/read/widget/dialog/AppraiseDialog.java +++ /dev/null @@ -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); - } - -} diff --git a/app/src/main/java/com/novel/read/widget/dialog/AppraiseDialog.kt b/app/src/main/java/com/novel/read/widget/dialog/AppraiseDialog.kt new file mode 100644 index 0000000..1b6735f --- /dev/null +++ b/app/src/main/java/com/novel/read/widget/dialog/AppraiseDialog.kt @@ -0,0 +1,39 @@ +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 com.novel.read.R +import kotlinx.android.synthetic.main.dialog_go_appraise.* + +class AppraiseDialog(context: Context) : Dialog(context, R.style.dialog) { + private val view: View = LayoutInflater.from(context).inflate(R.layout.dialog_go_appraise, null) + + init { + view.setHasTransientState(true) + setContentView( + view, LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.MATCH_PARENT + ) + ) + setCancelable(false) + initView() + + } + + private fun initView() { + val mTvCancel = findViewById(R.id.tv_cancel) + + mTvCancel.setOnClickListener { dismiss() } + } + + fun appraiseDialog(receiveClickListener: View.OnClickListener) { + tv_appraise.setOnClickListener(receiveClickListener) + } + +} diff --git a/app/src/main/java/com/novel/read/widget/dialog/ReadSettingDialog.java b/app/src/main/java/com/novel/read/widget/dialog/ReadSettingDialog.java deleted file mode 100644 index d535297..0000000 --- a/app/src/main/java/com/novel/read/widget/dialog/ReadSettingDialog.java +++ /dev/null @@ -1,185 +0,0 @@ -package com.novel.read.widget.dialog; - -import android.app.Activity; -import android.app.Dialog; -import android.graphics.drawable.Drawable; -import android.os.Bundle; -import android.view.Gravity; -import android.view.View; -import android.view.Window; -import android.view.WindowManager; -import android.widget.ImageView; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.novel.read.R; -import com.novel.read.adapter.PageStyleAdapter; -import com.novel.read.widget.page.PageLoader; -import com.novel.read.widget.page.PageMode; -import com.novel.read.widget.page.PageStyle; -import com.novel.read.widget.page.ReadSettingManager; - -import java.util.Arrays; - -import butterknife.BindView; -import butterknife.ButterKnife; - -public class ReadSettingDialog extends Dialog { - - private static final String TAG = "ReadSettingDialog"; - - @BindView(R.id.tv_simple) - TextView mTvSimple; - @BindView(R.id.tv_trans) - TextView mTvTrans; - - @BindView(R.id.read_setting_tv_font_minus) - ImageView mTvFontMinus; - - @BindView(R.id.read_setting_tv_font_plus) - ImageView mTvFontPlus; - - @BindView(R.id.read_setting_rv_bg) - RecyclerView mRvBg; - - /************************************/ - private PageStyleAdapter mPageStyleAdapter; - private ReadSettingManager mSettingManager; - private PageLoader mPageLoader; - private Activity mActivity; - - private PageMode mPageMode; - private PageStyle mPageStyle; - - private int mBrightness; - private int mTextSize; - - private boolean isBrightnessAuto; - private boolean isTextDefault; - - private int convertType; - - public ReadSettingDialog(@NonNull Activity activity, PageLoader mPageLoader) { - super(activity, R.style.ReadSettingDialog); - mActivity = activity; - this.mPageLoader = mPageLoader; - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.layout_setting); - ButterKnife.bind(this); - setUpWindow(); - initData(); - initWidget(); - initClick(); - } - - //设置Dialog显示的位置 - private void setUpWindow() { - Window window = getWindow(); - WindowManager.LayoutParams lp = window.getAttributes(); - lp.width = WindowManager.LayoutParams.MATCH_PARENT; - lp.height = WindowManager.LayoutParams.WRAP_CONTENT; - lp.gravity = Gravity.BOTTOM; - window.setAttributes(lp); - } - - private void initData() { - mSettingManager = ReadSettingManager.getInstance(); - - isBrightnessAuto = mSettingManager.isBrightnessAuto(); - mBrightness = mSettingManager.getBrightness(); - mTextSize = mSettingManager.getTextSize(); - isTextDefault = mSettingManager.isDefaultTextSize(); - mPageMode = mSettingManager.getPageMode(); - mPageStyle = mSettingManager.getPageStyle(); - convertType = mSettingManager.getConvertType(); - if (convertType == 0) { - mTvSimple.setSelected(true); - mTvTrans.setSelected(false); - } else { - mTvSimple.setSelected(false); - mTvTrans.setSelected(true); - } - } - - private void initWidget() { - //RecyclerView - setUpAdapter(); - } - - private void setUpAdapter() { - Drawable[] drawables = { - getDrawable(R.color.nb_read_bg_1) - , getDrawable(R.color.nb_read_bg_2) - , getDrawable(R.color.nb_read_bg_4) - , getDrawable(R.color.nb_read_bg_5)}; - - mPageStyleAdapter = new PageStyleAdapter(Arrays.asList(drawables), mPageLoader); - mRvBg.setLayoutManager(new GridLayoutManager(getContext(), 5)); - mRvBg.setAdapter(mPageStyleAdapter); - - mPageStyleAdapter.setPageStyleChecked(mPageStyle); - - } - - - private Drawable getDrawable(int drawRes) { - return ContextCompat.getDrawable(getContext(), drawRes); - } - - private void initClick() { - - //字体大小调节 - mTvFontMinus.setOnClickListener( - (v) -> { - int fontSize = mSettingManager.getTextSize() - 1; - if (fontSize < 0) return; - mPageLoader.setTextSize(fontSize); - } - ); - - mTvFontPlus.setOnClickListener( - (v) -> { - int fontSize = mSettingManager.getTextSize() + 1; - mPageLoader.setTextSize(fontSize); - } - ); - - mTvSimple.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (convertType == 0) { - return; - } - mTvSimple.setSelected(true); - mTvTrans.setSelected(false); - mSettingManager.setConvertType(0); - convertType = 0; - mPageLoader.setTextSize(mSettingManager.getTextSize()); - } - }); - - mTvTrans.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (convertType == 1) { - return; - } - mTvSimple.setSelected(false); - mTvTrans.setSelected(true); - mSettingManager.setConvertType(1); - convertType = 1; - mPageLoader.setTextSize(mSettingManager.getTextSize()); - } - }); - - } - -} diff --git a/app/src/main/java/com/novel/read/widget/dialog/ReadSettingDialog.kt b/app/src/main/java/com/novel/read/widget/dialog/ReadSettingDialog.kt new file mode 100644 index 0000000..4b95d59 --- /dev/null +++ b/app/src/main/java/com/novel/read/widget/dialog/ReadSettingDialog.kt @@ -0,0 +1,142 @@ +package com.novel.read.widget.dialog + +import android.app.Activity +import android.app.Dialog +import android.graphics.drawable.Drawable +import android.view.Gravity +import android.view.View +import android.view.WindowManager +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.GridLayoutManager +import com.novel.read.R +import com.novel.read.adapter.PageStyleAdapter +import com.novel.read.widget.page.PageLoader +import com.novel.read.widget.page.PageMode +import com.novel.read.widget.page.PageStyle +import com.novel.read.widget.page.ReadSettingManager +import kotlinx.android.synthetic.main.layout_setting.* + +class ReadSettingDialog(mActivity: Activity, private var mPageLoader: PageLoader) : + Dialog(mActivity, R.style.ReadSettingDialog) { + + private var mPageStyleAdapter: PageStyleAdapter? = null + private var mSettingManager: ReadSettingManager? = null + + private var mPageMode: PageMode? = null + private var mPageStyle: PageStyle? = null + + private var mBrightness: Int = 0 + private var mTextSize: Int = 0 + + private var isBrightnessAuto: Boolean = false + private var isTextDefault: Boolean = false + + private var convertType: Int = 0 + + init { + setContentView(R.layout.layout_setting) + setUpWindow() + initData() + initWidget() + initClick() + } + + //设置Dialog显示的位置 + private fun setUpWindow() { + val window = window + val lp = window!!.attributes + lp.width = WindowManager.LayoutParams.MATCH_PARENT + lp.height = WindowManager.LayoutParams.WRAP_CONTENT + lp.gravity = Gravity.BOTTOM + window.attributes = lp + } + + private fun initData() { + mSettingManager = ReadSettingManager.getInstance() + + isBrightnessAuto = mSettingManager!!.isBrightnessAuto + mBrightness = mSettingManager!!.brightness + mTextSize = mSettingManager!!.textSize + isTextDefault = mSettingManager!!.isDefaultTextSize + mPageMode = mSettingManager!!.pageMode + mPageStyle = mSettingManager!!.pageStyle + convertType = mSettingManager!!.convertType + if (convertType == 0) { + tv_simple.isSelected = true + tv_trans.isSelected = false + } else { + tv_simple.isSelected = false + tv_trans.isSelected = true + } + } + + private fun initWidget() { + setUpAdapter() + } + + private fun setUpAdapter() { + val drawables = arrayOf( + getDrawable(R.color.nb_read_bg_1), + getDrawable(R.color.nb_read_bg_2), + getDrawable(R.color.nb_read_bg_4), + getDrawable(R.color.nb_read_bg_5) + ) + + mPageStyleAdapter = PageStyleAdapter(listOf(*drawables), mPageLoader) + read_setting_rv_bg.layoutManager = GridLayoutManager(context, 5) + read_setting_rv_bg.adapter = mPageStyleAdapter + + mPageStyleAdapter!!.setPageStyleChecked(mPageStyle!!) + + } + + + private fun getDrawable(drawRes: Int): Drawable? { + return ContextCompat.getDrawable(context, drawRes) + } + + private fun initClick() { + + //字体大小调节 + read_setting_tv_font_minus.setOnClickListener { v -> + val fontSize = mSettingManager!!.textSize - 1 + if (fontSize < 0) { + return@setOnClickListener + } + mPageLoader.setTextSize(fontSize) + } + + read_setting_tv_font_plus.setOnClickListener { v -> + val fontSize = mSettingManager!!.textSize + 1 + mPageLoader.setTextSize(fontSize) + } + + tv_simple.setOnClickListener(View.OnClickListener { + if (convertType == 0) { + return@OnClickListener + } + tv_simple.isSelected = true + tv_trans.isSelected = false + mSettingManager!!.convertType = 0 + convertType = 0 + mPageLoader.setTextSize(mSettingManager!!.textSize) + }) + + tv_trans.setOnClickListener(View.OnClickListener { + if (convertType == 1) { + return@OnClickListener + } + tv_simple.isSelected = false + tv_trans.isSelected = true + mSettingManager!!.convertType = 1 + convertType = 1 + mPageLoader.setTextSize(mSettingManager!!.textSize) + }) + + } + + companion object { + private val TAG = "ReadSettingDialog" + } + +} diff --git a/app/src/main/java/com/novel/read/widget/page/LocalPageLoader.java b/app/src/main/java/com/novel/read/widget/page/LocalPageLoader.java index c1ca03f..fd20f77 100644 --- a/app/src/main/java/com/novel/read/widget/page/LocalPageLoader.java +++ b/app/src/main/java/com/novel/read/widget/page/LocalPageLoader.java @@ -432,7 +432,7 @@ public class LocalPageLoader extends PageLoader { //从文件中获取数据 byte[] content = getChapterContent(chapter); String test = new String(content); - test = StringUtils.convertCC(test, mContext); + test = StringUtils.convertCC(test); content = test.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(content); return new BufferedReader(new InputStreamReader(bais, mCharset.getName())); diff --git a/app/src/main/java/com/novel/read/widget/page/PageLoader.java b/app/src/main/java/com/novel/read/widget/page/PageLoader.java index 5906796..aeb49de 100644 --- a/app/src/main/java/com/novel/read/widget/page/PageLoader.java +++ b/app/src/main/java/com/novel/read/widget/page/PageLoader.java @@ -1300,12 +1300,12 @@ public abstract class PageLoader { int titleLinesCount = 0; boolean showTitle = true; // 是否展示标题 String paragraph = chapter.getTitle();//默认展示标题 - String title = StringUtils.convertCC(chapter.getTitle(), mContext); + String title = StringUtils.convertCC(chapter.getTitle()); String half; try { while (showTitle || (paragraph = br.readLine()) != null) { half = paragraph; - paragraph = StringUtils.convertCC(paragraph, mContext); + paragraph = StringUtils.convertCC(paragraph); // 重置段落 if (!showTitle) { paragraph = paragraph.replaceAll("\\s", ""); diff --git a/app/src/main/java/com/novel/read/widget/page/ReadSettingManager.java b/app/src/main/java/com/novel/read/widget/page/ReadSettingManager.java index 848ed15..24dd240 100644 --- a/app/src/main/java/com/novel/read/widget/page/ReadSettingManager.java +++ b/app/src/main/java/com/novel/read/widget/page/ReadSettingManager.java @@ -4,11 +4,6 @@ package com.novel.read.widget.page; import com.novel.read.utlis.ScreenUtils; import com.novel.read.utlis.SpUtil; -/** - * Created by newbiechen on 17-5-17. - * 阅读器的配置管理 - */ - public class ReadSettingManager { /*************实在想不出什么好记的命名方式。。******************/ public static final int READ_BG_DEFAULT = 0; diff --git a/app/src/main/res/layout/activity_rank_list.xml b/app/src/main/res/layout/activity_rank_list.xml index 4e9359e..6f19620 100644 --- a/app/src/main/res/layout/activity_rank_list.xml +++ b/app/src/main/res/layout/activity_rank_list.xml @@ -1,5 +1,5 @@ - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_book_list.xml b/app/src/main/res/layout/fragment_book_list.xml index 68b12ea..a689f91 100644 --- a/app/src/main/res/layout/fragment_book_list.xml +++ b/app/src/main/res/layout/fragment_book_list.xml @@ -1,12 +1,12 @@ - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 15aba56..ec77a65 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -92,7 +92,7 @@ @android:color/transparent false - Re + @style/anim_slide_left_in_right_out diff --git a/common_lib/build.gradle b/common_lib/build.gradle index f3f582a..ba5997e 100644 --- a/common_lib/build.gradle +++ b/common_lib/build.gradle @@ -38,19 +38,17 @@ dependencies { api rootProject.ext.dependencies["gson"] api rootProject.ext.dependencies["glide"] + api rootProject.ext.dependencies["litepal"] + api files('libs/ZHConverter.jar') api 'com.google.android:flexbox:0.3.1' - api 'org.litepal.android:java:3.0.0' + // RxJava api 'io.reactivex.rxjava2:rxandroid:2.0.1' api 'io.reactivex.rxjava2:rxjava:2.0.1' api 'org.reactivestreams:reactive-streams:1.0.0' - api 'com.tencent.bugly:crashreport:3.0.0' - api 'com.tencent.bugly:nativecrashreport:3.7.1' - api files('libs/ZHConverter.jar') - api 'com.google.zxing:core:3.3.0' //密码输入 diff --git a/config.gradle b/config.gradle index c3e8acc..e07daf3 100644 --- a/config.gradle +++ b/config.gradle @@ -2,7 +2,7 @@ ext { android = [ compileSdkVersion : 28, buildToolsVersion : '28.0.3', - minSdkVersion : 19, + minSdkVersion : 17, targetSdkVersion : 28, versionCode : 1, versionName : "1.0.0",