diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 9f5a09b..1b91fa8 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/modules.xml b/.idea/modules.xml index 669fcc4..c9f6d5e 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,8 +2,8 @@ - - + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 11c1e21..b397ea2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -60,12 +60,12 @@ android { versionCode version versionName versionN testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' - javaCompileOptions { - annotationProcessorOptions { - includeCompileClasspath = true - } - } } + + buildFeatures { + viewBinding true + } + buildTypes { release { minifyEnabled false @@ -99,7 +99,6 @@ android { } productFlavors { } - } @@ -124,10 +123,6 @@ dependencies { implementation "org.jetbrains.anko:anko-sdk27:$anko_version" implementation "org.jetbrains.anko:anko-sdk27-listeners:$anko_version" - implementation 'com.jakewharton:butterknife:10.0.0' - - annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0' - //Glide implementation 'com.github.bumptech.glide:glide:4.9.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0' diff --git a/app/libs/sun.misc.BASE64Decoder.jar b/app/libs/sun.misc.BASE64Decoder.jar deleted file mode 100644 index 9811c13..0000000 Binary files a/app/libs/sun.misc.BASE64Decoder.jar and /dev/null differ diff --git a/app/src/main/java/xyz/fycz/myreader/base/BaseActivity.java b/app/src/main/java/xyz/fycz/myreader/base/BaseActivity.java index 945aef0..ae61b25 100644 --- a/app/src/main/java/xyz/fycz/myreader/base/BaseActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/base/BaseActivity.java @@ -5,17 +5,17 @@ import android.content.Intent; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.os.Bundle; - import android.view.Menu; import android.view.MenuItem; -import androidx.annotation.LayoutRes; + import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; -import butterknife.ButterKnife; -import butterknife.Unbinder; + +import java.lang.reflect.Method; +import java.util.ArrayList; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; @@ -26,9 +26,6 @@ import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.util.StatusBarUtil; -import java.lang.reflect.Method; -import java.util.ArrayList; - /** * @author fengyue * @date 2020/8/12 20:02 @@ -37,17 +34,15 @@ public abstract class BaseActivity extends AppCompatActivity { private static final int INVALID_VAL = -1; protected CompositeDisposable mDisposable; - //ButterKnife - protected Toolbar mToolbar; - private Unbinder unbinder; + protected Toolbar mToolbar; private int curNightMode; /****************************abstract area*************************************/ - - @LayoutRes - protected abstract int getContentId(); - + /** + * 绑定视图 + */ + protected abstract void bindView(); /************************init area************************************/ protected void addDisposable(Disposable d){ if (mDisposable == null){ @@ -56,6 +51,7 @@ public abstract class BaseActivity extends AppCompatActivity { mDisposable.add(d); } + /** * 配置Toolbar * @param toolbar @@ -108,8 +104,7 @@ public abstract class BaseActivity extends AppCompatActivity { super.onCreate(savedInstanceState); initTheme(); ActivityManage.addActivity(this); - setContentView(getContentId()); - unbinder = ButterKnife.bind(this); + bindView(); initData(savedInstanceState); initToolbar(); initWidget(); @@ -138,7 +133,6 @@ public abstract class BaseActivity extends AppCompatActivity { protected void onDestroy() { super.onDestroy(); ActivityManage.removeActivity(this); - unbinder.unbind(); if (mDisposable != null){ mDisposable.dispose(); } diff --git a/app/src/main/java/xyz/fycz/myreader/base/BaseFragment.java b/app/src/main/java/xyz/fycz/myreader/base/BaseFragment.java index 39ee26b..0b3a0de 100644 --- a/app/src/main/java/xyz/fycz/myreader/base/BaseFragment.java +++ b/app/src/main/java/xyz/fycz/myreader/base/BaseFragment.java @@ -1,15 +1,13 @@ package xyz.fycz.myreader.base; import android.os.Bundle; - import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import androidx.annotation.LayoutRes; + import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; -import butterknife.ButterKnife; -import butterknife.Unbinder; + import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; @@ -23,11 +21,11 @@ public abstract class BaseFragment extends Fragment { protected CompositeDisposable mDisposable; private View root = null; - protected Unbinder unbinder; - - @LayoutRes - protected abstract int getContentId(); + /** + * 绑定视图 + */ + protected abstract View bindView(LayoutInflater inflater, ViewGroup container); /*******************************init area*********************************/ protected void addDisposable(Disposable d){ if (mDisposable == null){ @@ -62,8 +60,7 @@ public abstract class BaseFragment extends Fragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - int resId = getContentId(); - root = inflater.inflate(resId,container,false); + root = bindView(inflater, container); return root; } @@ -71,7 +68,6 @@ public abstract class BaseFragment extends Fragment { public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); initData(savedInstanceState); - unbinder = ButterKnife.bind(this,root); initWidget(savedInstanceState); initClick(); processLogic(); @@ -81,8 +77,6 @@ public abstract class BaseFragment extends Fragment { public void onDetach() { super.onDetach(); - unbinder.unbind(); - if (mDisposable != null){ mDisposable.clear(); } diff --git a/app/src/main/java/xyz/fycz/myreader/base/BaseTabActivity.java b/app/src/main/java/xyz/fycz/myreader/base/BaseTabActivity.java index 585a8a1..113113e 100644 --- a/app/src/main/java/xyz/fycz/myreader/base/BaseTabActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/base/BaseTabActivity.java @@ -5,12 +5,13 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; import androidx.viewpager.widget.ViewPager; -import butterknife.BindView; + import com.google.android.material.tabs.TabLayout; -import xyz.fycz.myreader.R; import java.util.List; +import xyz.fycz.myreader.R; + /** * @author fengyue * @date 2020/8/12 20:02 @@ -18,10 +19,9 @@ import java.util.List; public abstract class BaseTabActivity extends BaseActivity { /**************View***************/ - @BindView(R.id.tab_tl_indicator) protected TabLayout mTlIndicator; - @BindView(R.id.tab_vp) protected ViewPager mVp; + /************Params*******************/ private List mFragmentList; private List mTitleList; @@ -30,7 +30,14 @@ public abstract class BaseTabActivity extends BaseActivity { protected abstract List createTabFragments(); protected abstract List createTabTitles(); + @Override + protected void bindView() { + mTlIndicator = findViewById(R.id.tab_tl_indicator); + mVp = findViewById(R.id.tab_vp); + } + /*****************rewrite method***************************/ + @Override protected void initWidget() { super.initWidget(); @@ -61,6 +68,7 @@ public abstract class BaseTabActivity extends BaseActivity { throw new IllegalArgumentException("fragment and title size must equal"); } + /******************inner class*****************/ class TabFragmentPageAdapter extends FragmentPagerAdapter { diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java index 1edcb15..53f25f8 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java @@ -5,14 +5,14 @@ import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.net.Uri; -import android.widget.TextView; + import androidx.appcompat.widget.Toolbar; -import androidx.cardview.widget.CardView; -import butterknife.BindView; + import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.common.URLCONST; +import xyz.fycz.myreader.databinding.ActivityAboutBinding; import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.util.ShareUtils; import xyz.fycz.myreader.util.SharedPreUtils; @@ -23,26 +23,12 @@ import xyz.fycz.myreader.util.ToastUtils; * @date 2020/9/18 22:21 */ public class AboutActivity extends BaseActivity { - @BindView(R.id.tv_version_name) - TextView tvVersionName; - @BindView(R.id.vm_author) - CardView vmAuthor; - @BindView(R.id.vw_share) - CardView vmShare; - @BindView(R.id.vw_update) - CardView vmUpdate; - @BindView(R.id.vw_update_log) - CardView vmUpdateLog; - @BindView(R.id.vw_qq) - CardView vmQQ; - @BindView(R.id.vw_git) - CardView vmGit; - @BindView(R.id.vw_disclaimer) - CardView vmDisclaimer; + private ActivityAboutBinding binding; @Override - protected int getContentId() { - return R.layout.activity_about; + protected void bindView() { + binding = ActivityAboutBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -56,14 +42,14 @@ public class AboutActivity extends BaseActivity { @Override protected void initWidget() { super.initWidget(); - tvVersionName.setText("风月读书v" + MyApplication.getStrVersionName()); + binding.il.tvVersionName.setText("风月读书v" + MyApplication.getStrVersionName()); } @Override protected void initClick() { super.initClick(); ClipboardManager mClipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); - vmAuthor.setOnClickListener(v -> { + binding.il.vmAuthor.setOnClickListener(v -> { //数据 ClipData mClipData = ClipData.newPlainText("Label", "fy@fycz.xyz"); //把数据设置到剪切板上 @@ -71,11 +57,11 @@ public class AboutActivity extends BaseActivity { mClipboardManager.setPrimaryClip(mClipData); ToastUtils.showSuccess("邮箱复制成功!"); }); - vmShare.setOnClickListener(v -> ShareUtils.share(this, getString(R.string.share_text) + + binding.il.vwShare.setOnClickListener(v -> ShareUtils.share(this, getString(R.string.share_text) + SharedPreUtils.getInstance().getString(getString(R.string.downloadLink), URLCONST.LAN_ZOUS_URL))); - vmUpdate.setOnClickListener(v -> MyApplication.checkVersionByServer(this, true, null)); - vmUpdateLog.setOnClickListener(v -> DialogCreator.createAssetTipDialog(this, "更新日志", "updatelog.fy")); - vmQQ.setOnClickListener(v -> { + binding.il.vwUpdate.setOnClickListener(v -> MyApplication.checkVersionByServer(this, true, null)); + binding.il.vwUpdateLog.setOnClickListener(v -> DialogCreator.createAssetTipDialog(this, "更新日志", "updatelog.fy")); + binding.il.vwQq.setOnClickListener(v -> { if (!MyApplication.joinQQGroup(this,"8PIOnHFuH6A38hgxvD_Rp2Bu-Ke1ToBn")){ //数据 ClipData mClipData = ClipData.newPlainText("Label", "1085028304"); @@ -85,8 +71,8 @@ public class AboutActivity extends BaseActivity { ToastUtils.showError("未安装手Q或安装的版本不支持!\n已复制QQ群号,您可自行前往QQ添加!"); } }); - vmGit.setOnClickListener(v -> openIntent(Intent.ACTION_VIEW, getString(R.string.this_github_url))); - vmDisclaimer.setOnClickListener(v -> DialogCreator.createAssetTipDialog(this, "免责声明", "disclaimer.fy")); + binding.il.vwGit.setOnClickListener(v -> openIntent(Intent.ACTION_VIEW, getString(R.string.this_github_url))); + binding.il.vwDisclaimer.setOnClickListener(v -> DialogCreator.createAssetTipDialog(this, "免责声明", "disclaimer.fy")); } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java index a3634af..00718ff 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java @@ -6,30 +6,21 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Message; -import android.text.Layout; -import android.text.StaticLayout; import android.text.TextPaint; import android.text.TextUtils; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.widget.*; import androidx.appcompat.widget.Toolbar; import androidx.core.content.FileProvider; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import butterknife.BindView; -import butterknife.OnClick; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestBuilder; @@ -37,6 +28,12 @@ import com.bumptech.glide.request.RequestOptions; import com.google.zxing.EncodeHintType; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; +import java.io.File; +import java.io.FileOutputStream; +import java.util.ArrayList; +import java.util.List; + + import cn.bingoogolapple.qrcode.zxing.QRCodeEncoder; import io.reactivex.Single; import io.reactivex.SingleOnSubscribe; @@ -47,78 +44,43 @@ import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.observer.MySingleObserver; +import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.URLCONST; +import xyz.fycz.myreader.databinding.ActivityBookDetailBinding; import xyz.fycz.myreader.entity.SharedBook; +import xyz.fycz.myreader.enums.BookSource; +import xyz.fycz.myreader.greendao.entity.Book; +import xyz.fycz.myreader.greendao.entity.Chapter; +import xyz.fycz.myreader.greendao.service.BookService; +import xyz.fycz.myreader.greendao.service.ChapterService; +import xyz.fycz.myreader.ui.adapter.DetailCatalogAdapter; import xyz.fycz.myreader.ui.dialog.BookGroupDialog; +import xyz.fycz.myreader.ui.dialog.DialogCreator; +import xyz.fycz.myreader.ui.dialog.SourceExchangeDialog; import xyz.fycz.myreader.util.IOUtils; import xyz.fycz.myreader.util.SharedPreUtils; +import xyz.fycz.myreader.util.StringHelper; +import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.utils.BitmapUtil; +import xyz.fycz.myreader.util.utils.BlurTransformation; import xyz.fycz.myreader.util.utils.FileUtils; import xyz.fycz.myreader.util.utils.GsonExtensionsKt; +import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.util.utils.RxUtils; -import xyz.fycz.myreader.util.utils.ScreenUtils; import xyz.fycz.myreader.util.utils.StringUtils; +import xyz.fycz.myreader.webapi.CommonApi; import xyz.fycz.myreader.webapi.callback.ResultCallback; -import xyz.fycz.myreader.common.APPCONST; -import xyz.fycz.myreader.ui.dialog.SourceExchangeDialog; -import xyz.fycz.myreader.util.ToastUtils; -import xyz.fycz.myreader.util.utils.BlurTransformation; +import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil; import xyz.fycz.myreader.webapi.crawler.base.BookInfoCrawler; import xyz.fycz.myreader.webapi.crawler.base.ReadCrawler; -import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil; -import xyz.fycz.myreader.ui.dialog.DialogCreator; -import xyz.fycz.myreader.enums.BookSource; -import xyz.fycz.myreader.greendao.entity.Book; -import xyz.fycz.myreader.greendao.entity.Chapter; -import xyz.fycz.myreader.greendao.service.BookService; -import xyz.fycz.myreader.greendao.service.ChapterService; -import xyz.fycz.myreader.ui.adapter.DetailCatalogAdapter; -import xyz.fycz.myreader.util.StringHelper; -import xyz.fycz.myreader.util.utils.NetworkUtils; -import xyz.fycz.myreader.webapi.CommonApi; -import xyz.fycz.myreader.widget.CoverImageView; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; /** * @author fengyue * @date 2020/8/17 11:39 */ public class BookDetailedActivity extends BaseActivity { - @BindView(R.id.book_detail_iv_cover) - CoverImageView mIvCover; - /* @BindView(R.id.book_detail_iv_blur_cover) - ImageView mIvBlurCover;*/ - @BindView(R.id.book_detail_tv_author) - TextView mTvAuthor; - @BindView(R.id.book_detail_tv_type) - TextView mTvType; - @BindView(R.id.book_detail_source) - TextView mTvSource; - @BindView(R.id.book_detail_tv_add) - TextView bookDetailTvAdd; - @BindView(R.id.book_detail_tv_open) - TextView bookDetailTvOpen; - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.book_detail_tv_desc) - TextView mTvDesc; - @BindView(R.id.tv_disclaimer) - TextView mTvDisclaimer; - @BindView(R.id.fl_add_bookcase) - FrameLayout flAddBookcase; - @BindView(R.id.fl_open_book) - FrameLayout flOpenBook; - @BindView(R.id.book_detail_rv_catalog) - RecyclerView bookDetailRvCatalog; - @BindView(R.id.pb_loading) - ProgressBar pbLoading; + private ActivityBookDetailBinding binding; private Book mBook; private ArrayList aBooks; @@ -151,11 +113,11 @@ public class BookDetailedActivity extends BaseActivity { createChangeSourceDia(); break; case 3: - pbLoading.setVisibility(View.GONE); + binding.pbLoading.setVisibility(View.GONE); DialogCreator.createTipDialog(BookDetailedActivity.this, "未搜索到该书籍,书源加载失败!"); break; case 4: - pbLoading.setVisibility(View.GONE); + binding.pbLoading.setVisibility(View.GONE); initOtherInfo(); break; } @@ -163,8 +125,9 @@ public class BookDetailedActivity extends BaseActivity { }; @Override - protected int getContentId() { - return R.layout.activity_book_detail; + protected void bindView() { + binding = ActivityBookDetailBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -201,8 +164,8 @@ public class BookDetailedActivity extends BaseActivity { //catalog mCatalogAdapter = new DetailCatalogAdapter(); - bookDetailRvCatalog.setLayoutManager(new LinearLayoutManager(this)); - bookDetailRvCatalog.setAdapter(mCatalogAdapter); + binding.ic.bookDetailRvCatalog.setLayoutManager(new LinearLayoutManager(this)); + binding.ic.bookDetailRvCatalog.setAdapter(mCatalogAdapter); initChapters(false); @@ -212,10 +175,10 @@ public class BookDetailedActivity extends BaseActivity { goReadActivity(); }); - mTvDisclaimer.setOnClickListener(v -> DialogCreator.createAssetTipDialog(this, "免责声明", "disclaimer.fy")); + binding.ic.tvDisclaimer.setOnClickListener(v -> DialogCreator.createAssetTipDialog(this, "免责声明", "disclaimer.fy")); if (isCollected) { - bookDetailTvAdd.setText("移除书籍"); - bookDetailTvOpen.setText("继续阅读"); + binding.ib.bookDetailTvAdd.setText("移除书籍"); + binding.ib.bookDetailTvOpen.setText("继续阅读"); } //Dialog @@ -241,7 +204,9 @@ public class BookDetailedActivity extends BaseActivity { @Override protected void initClick() { super.initClick(); - flAddBookcase.setOnClickListener(view -> { + binding.ic.bookDetailTvDesc.setOnClickListener(v -> showMoreDesc()); + binding.ic.bookDetailTvCatalogMore.setOnClickListener(v -> goToMoreChapter()); + binding.ib.flAddBookcase.setOnClickListener(view -> { if (!isCollected) { mBook.setNoReadNum(mChapters.size()); mBook.setChapterTotalNum(0); @@ -253,7 +218,7 @@ public class BookDetailedActivity extends BaseActivity { mChapterService.addChapters(mChapters); isCollected = true; ToastUtils.showSuccess("成功加入书架"); - bookDetailTvAdd.setText("移除书籍"); + binding.ib.bookDetailTvAdd.setText("移除书籍"); } else { mBookService.deleteBookById(mBook.getId()); isCollected = false; @@ -261,11 +226,11 @@ public class BookDetailedActivity extends BaseActivity { mBook.setHistoryChapterId("未开始阅读"); mBook.setLastReadPosition(0); ToastUtils.showSuccess("成功移除书籍"); - bookDetailTvAdd.setText("加入书架"); - bookDetailTvOpen.setText("开始阅读"); + binding.ib.bookDetailTvAdd.setText("加入书架"); + binding.ib.bookDetailTvOpen.setText("开始阅读"); } }); - flOpenBook.setOnClickListener(view -> goReadActivity()); + binding.ib.flOpenBook.setOnClickListener(view -> goReadActivity()); //换源对话框 mSourceDialog.setOnSourceChangeListener((bean, pos) -> { @@ -298,6 +263,25 @@ public class BookDetailedActivity extends BaseActivity { }); } + /** + * 展开简介 + */ + protected void showMoreDesc() { + if (binding.ic.bookDetailTvDesc.getMaxLines() == 5) + binding.ic.bookDetailTvDesc.setMaxLines(15); + else + binding.ic.bookDetailTvDesc.setMaxLines(5); + } + + /** + * 章节列表 + */ + public void goToMoreChapter() { + Intent intent = new Intent(this, CatalogActivity.class); + intent.putExtra(APPCONST.BOOK, mBook); + startActivityForResult(intent, APPCONST.REQUEST_CHAPTER_PAGE); + } + @Override protected void processLogic() { super.processLogic(); @@ -322,23 +306,23 @@ public class BookDetailedActivity extends BaseActivity { * 初始化书籍信息 */ private void initBookInfo() { - mTvAuthor.setText(mBook.getAuthor()); + binding.ih.bookDetailTvAuthor.setText(mBook.getAuthor()); if (StringHelper.isEmpty(mBook.getImgUrl())) { mBook.setImgUrl(""); } assert mBook.getNewestChapterTitle() != null; - mTvDesc.setText(""); + binding.ic.bookDetailTvDesc.setText(""); if (mBook.getType() != null) { - mTvType.setText(mBook.getType()); + binding.ih.bookDetailTvType.setText(mBook.getType()); } else { - mTvType.setText(""); + binding.ih.bookDetailTvType.setText(""); } if (!"null".equals(mBook.getSource())) { - mTvSource.setText("书源:" + BookSource.fromString(mBook.getSource()).text); + binding.ih.bookDetailSource.setText("书源:" + BookSource.fromString(mBook.getSource()).text); } ReadCrawler rc = ReadCrawlerUtil.getReadCrawler(mBook.getSource()); if (rc instanceof BookInfoCrawler && StringHelper.isEmpty(mBook.getImgUrl())) { - pbLoading.setVisibility(View.VISIBLE); + binding.pbLoading.setVisibility(View.VISIBLE); BookInfoCrawler bic = (BookInfoCrawler) rc; CommonApi.getBookInfo(mBook, bic, new ResultCallback() { @Override @@ -362,10 +346,10 @@ public class BookDetailedActivity extends BaseActivity { * 初始化其他书籍信息 */ private void initOtherInfo() { - mTvDesc.setText("\t\t\t\t" + mBook.getDesc()); - mTvType.setText(mBook.getType()); + binding.ic.bookDetailTvDesc.setText("\t\t\t\t" + mBook.getDesc()); + binding.ih.bookDetailTvType.setText(mBook.getType()); if (!MyApplication.isDestroy(this)) { - mIvCover.load(mBook.getImgUrl(), mBook.getName(), mBook.getAuthor()); + binding.ih.bookDetailIvCover.load(mBook.getImgUrl(), mBook.getName(), mBook.getAuthor()); /*Glide.with(this) .load(mBook.getImgUrl()) .transition(DrawableTransitionOptions.withCrossFade(1500)) @@ -598,26 +582,6 @@ public class BookDetailedActivity extends BaseActivity { return super.onOptionsItemSelected(item); } - /** - * 展开简介 - */ - @OnClick(R.id.book_detail_tv_desc) - protected void showMoreDesc() { - if (mTvDesc.getMaxLines() == 5) - mTvDesc.setMaxLines(15); - else - mTvDesc.setMaxLines(5); - } - - /** - * 章节列表 - */ - @OnClick(R.id.book_detail_tv_catalog_more) - public void goToMoreChapter() { - Intent intent = new Intent(this, CatalogActivity.class); - intent.putExtra(APPCONST.BOOK, mBook); - startActivityForResult(intent, APPCONST.REQUEST_CHAPTER_PAGE); - } /** * 阅读/章节界面反馈结果处理 @@ -639,8 +603,8 @@ public class BookDetailedActivity extends BaseActivity { int lastReadPosition = data.getIntExtra(APPCONST.RESULT_LAST_READ_POSITION, 0); int historyChapterPos = data.getIntExtra(APPCONST.RESULT_HISTORY_CHAPTER, 0); if (isCollected) { - bookDetailTvAdd.setText("移除书籍"); - bookDetailTvOpen.setText("继续阅读"); + binding.ib.bookDetailTvAdd.setText("移除书籍"); + binding.ib.bookDetailTvOpen.setText("继续阅读"); this.isCollected = true; if (mChapters != null && mChapters.size() != 0) { mBook.setHistoryChapterId(mChapters.get(historyChapterPos).getTitle()); @@ -720,9 +684,9 @@ public class BookDetailedActivity extends BaseActivity { int marginTop = 24; - mIvCover.setDrawingCacheEnabled(true); - Bitmap img = Bitmap.createBitmap(mIvCover.getDrawingCache()).copy(Bitmap.Config.ARGB_8888, true); - mIvCover.setDrawingCacheEnabled(false); + binding.ih.bookDetailIvCover.setDrawingCacheEnabled(true); + Bitmap img = Bitmap.createBitmap(binding.ih.bookDetailIvCover.getDrawingCache()).copy(Bitmap.Config.ARGB_8888, true); + binding.ih.bookDetailIvCover.setDrawingCacheEnabled(false); img = BitmapUtil.getBitmap(img, 152, 209); Canvas cv = new Canvas(back); diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookstoreActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookstoreActivity.java index dd9df2f..6d08fbb 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookstoreActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookstoreActivity.java @@ -8,23 +8,19 @@ import android.os.Message; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.widget.ProgressBar; import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; - -import com.scwang.smartrefresh.layout.SmartRefreshLayout; +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.base.BaseActivity; -import xyz.fycz.myreader.webapi.callback.ResultCallback; import xyz.fycz.myreader.common.APPCONST; -import xyz.fycz.myreader.ui.dialog.DialogCreator; -import xyz.fycz.myreader.ui.dialog.SourceExchangeDialog; +import xyz.fycz.myreader.databinding.ActiityBookstoreBinding; import xyz.fycz.myreader.entity.bookstore.BookType; import xyz.fycz.myreader.entity.bookstore.QDBook; import xyz.fycz.myreader.entity.bookstore.RankBook; @@ -33,33 +29,21 @@ import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.service.BookService; import xyz.fycz.myreader.ui.adapter.BookStoreBookAdapter; import xyz.fycz.myreader.ui.adapter.BookStoreBookTypeAdapter; +import xyz.fycz.myreader.ui.dialog.DialogCreator; +import xyz.fycz.myreader.ui.dialog.SourceExchangeDialog; import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.webapi.BookStoreApi; +import xyz.fycz.myreader.webapi.callback.ResultCallback; import xyz.fycz.myreader.webapi.crawler.base.FindCrawler; import xyz.fycz.myreader.webapi.crawler.find.QiDianMobileRank; -import xyz.fycz.myreader.widget.RefreshLayout; - -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; /** * @author fengyue * @date 2020/9/13 21:11 */ public class BookstoreActivity extends BaseActivity { - @BindView(R.id.refresh_layout) - RefreshLayout mRlRefresh; - @BindView(R.id.rv_type_list) - RecyclerView rvTypeList; - @BindView(R.id.rv_book_list) - RecyclerView rvBookList; - @BindView(R.id.srl_book_list) - SmartRefreshLayout srlBookList; - @BindView(R.id.pb_loading) - ProgressBar pbLoading; + private ActiityBookstoreBinding binding; private FindCrawler findCrawler; private LinearLayoutManager mLinearLayoutManager; @@ -83,25 +67,25 @@ public class BookstoreActivity extends BaseActivity { switch (msg.what) { case 1: initTypeList(); - mRlRefresh.showFinish(); + binding.refreshLayout.showFinish(); break; case 2: List bookList = (List) msg.obj; initBookList(bookList); - srlBookList.setEnableRefresh(true); - srlBookList.setEnableLoadMore(true); - pbLoading.setVisibility(View.GONE); + binding.srlBookList.setEnableRefresh(true); + binding.srlBookList.setEnableLoadMore(true); + binding.pbLoading.setVisibility(View.GONE); break; case 3: - pbLoading.setVisibility(View.VISIBLE); + binding.pbLoading.setVisibility(View.VISIBLE); break; case 4: - pbLoading.setVisibility(View.GONE); - srlBookList.finishRefresh(false); - srlBookList.finishLoadMore(false); + binding.pbLoading.setVisibility(View.GONE); + binding.srlBookList.finishRefresh(false); + binding.srlBookList.finishLoadMore(false); break; case 5: - mRlRefresh.showError(); + binding.refreshLayout.showError(); break; case 6: DialogCreator.createTipDialog(BookstoreActivity.this, @@ -112,8 +96,9 @@ public class BookstoreActivity extends BaseActivity { }; @Override - protected int getContentId() { - return R.layout.actiity_bookstore; + protected void bindView() { + binding = ActiityBookstoreBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -139,24 +124,24 @@ public class BookstoreActivity extends BaseActivity { @Override protected void initWidget() { super.initWidget(); - srlBookList.setEnableRefresh(false); - srlBookList.setEnableLoadMore(false); + binding.srlBookList.setEnableRefresh(false); + binding.srlBookList.setEnableLoadMore(false); //小说列表下拉加载更多事件 - srlBookList.setOnLoadMoreListener(refreshLayout -> { + binding.srlBookList.setOnLoadMoreListener(refreshLayout -> { page++; getBooksData(); }); //小说列表上拉刷新事件 - srlBookList.setOnRefreshListener(refreshLayout -> { + binding.srlBookList.setOnRefreshListener(refreshLayout -> { page = 1; getBooksData(); }); mBookStoreBookAdapter = new BookStoreBookAdapter(findCrawler.hasImg(), this); - rvBookList.setLayoutManager(new LinearLayoutManager(this)); - rvBookList.setAdapter(mBookStoreBookAdapter); - mRlRefresh.setOnReloadingListener(this::getData); + binding.rvBookList.setLayoutManager(new LinearLayoutManager(this)); + binding.rvBookList.setAdapter(mBookStoreBookAdapter); + binding.refreshLayout.setOnReloadingListener(this::getData); } @Override @@ -236,7 +221,7 @@ public class BookstoreActivity extends BaseActivity { @Override public void onError(Exception e) { if (MyApplication.isDestroy(BookstoreActivity.this)) return; - mRlRefresh.showError(); + binding.refreshLayout.showError(); e.printStackTrace(); } }); @@ -277,7 +262,7 @@ public class BookstoreActivity extends BaseActivity { */ private void getBooksData() { if (findCrawler.getTypePage(curType, page)) { - srlBookList.finishLoadMoreWithNoMoreData(); + binding.srlBookList.finishLoadMoreWithNoMoreData(); return; } @@ -346,9 +331,9 @@ public class BookstoreActivity extends BaseActivity { //设置布局管理器 mLinearLayoutManager = new LinearLayoutManager(this); mLinearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); - rvTypeList.setLayoutManager(mLinearLayoutManager); + binding.rvTypeList.setLayoutManager(mLinearLayoutManager); mBookStoreBookTypeAdapter = new BookStoreBookTypeAdapter(this, mBookTypes); - rvTypeList.setAdapter(mBookStoreBookTypeAdapter); + binding.rvTypeList.setAdapter(mBookStoreBookTypeAdapter); //点击事件 mBookStoreBookTypeAdapter.setOnItemClickListener((pos, view) -> { @@ -357,7 +342,7 @@ public class BookstoreActivity extends BaseActivity { } page = 1; curType = mBookTypes.get(pos); - srlBookList.resetNoMoreData(); + binding.srlBookList.resetNoMoreData(); getBooksData(); }); @@ -373,7 +358,7 @@ public class BookstoreActivity extends BaseActivity { mBookStoreBookAdapter.refreshItems(bookList); this.bookList.clear(); this.bookList.addAll(bookList); - rvBookList.scrollToPosition(0); + binding.rvBookList.scrollToPosition(0); } else { this.bookList.addAll(bookList); this.bookList = new ArrayList<>(new LinkedHashSet<>(this.bookList));//去重 @@ -381,9 +366,9 @@ public class BookstoreActivity extends BaseActivity { } //刷新动作完成 - srlBookList.finishRefresh(); + binding.srlBookList.finishRefresh(); //加载更多完成 - srlBookList.finishLoadMore(); + binding.srlBookList.finishLoadMore(); } @@ -432,7 +417,7 @@ public class BookstoreActivity extends BaseActivity { mHandler.sendEmptyMessage(6); return true; case R.id.action_refresh: - mRlRefresh.showLoading(); + binding.refreshLayout.showLoading(); getData(); return true; } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/CatalogActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/CatalogActivity.java index ebe0428..c6aa433 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/CatalogActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/CatalogActivity.java @@ -4,14 +4,14 @@ import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; + import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.Toolbar; -import androidx.viewpager.widget.ViewPager; -import butterknife.BindView; -import com.google.android.material.tabs.TabLayout; + import xyz.fycz.myreader.R; import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.common.APPCONST; +import xyz.fycz.myreader.databinding.ActivityCatalogBinding; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.ui.adapter.TabFragmentPageAdapter; import xyz.fycz.myreader.ui.fragment.BookMarkFragment; @@ -23,12 +23,7 @@ import xyz.fycz.myreader.ui.fragment.CatalogFragment; public class CatalogActivity extends BaseActivity { - @BindView(R.id.catalog_tab) - TabLayout catalogTab; - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.catalog_vp) - ViewPager viewPager; + private ActivityCatalogBinding binding; private SearchView searchView; private Book mBook; @@ -41,6 +36,12 @@ public class CatalogActivity extends BaseActivity { return mBook; } + @Override + protected void bindView() { + binding = ActivityCatalogBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + } + /*********************Initialization****************************/ @@ -50,10 +51,6 @@ public class CatalogActivity extends BaseActivity { mBook = (Book) getIntent().getSerializableExtra(APPCONST.BOOK); } - @Override - protected int getContentId() { - return R.layout.activity_catalog; - } @Override protected void setUpToolbar(Toolbar toolbar) { @@ -67,9 +64,9 @@ public class CatalogActivity extends BaseActivity { @Override protected void initWidget() { super.initWidget(); - viewPager.setAdapter(tabAdapter); - viewPager.setOffscreenPageLimit(2); - catalogTab.setupWithViewPager(viewPager); + binding.catalogVp.setAdapter(tabAdapter); + binding.catalogVp.setOffscreenPageLimit(2); + binding.catalogTab.setupWithViewPager(binding.catalogVp); } @@ -90,7 +87,7 @@ public class CatalogActivity extends BaseActivity { @Override public boolean onQueryTextChange(String newText) { - switch (viewPager.getCurrentItem()){ + switch (binding.catalogVp.getCurrentItem()){ case 0: ((CatalogFragment) tabAdapter.getItem(0)).getmCatalogPresent().startSearch(newText); break; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/FeedbackActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/FeedbackActivity.java index 589f4d8..9d7a246 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/FeedbackActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/FeedbackActivity.java @@ -1,7 +1,6 @@ package xyz.fycz.myreader.ui.activity; import android.annotation.SuppressLint; -import android.app.Dialog; import android.webkit.WebChromeClient; import android.webkit.WebResourceError; import android.webkit.WebResourceRequest; @@ -11,26 +10,24 @@ import android.webkit.WebViewClient; import androidx.appcompat.widget.Toolbar; -import butterknife.BindView; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.base.BaseActivity; +import xyz.fycz.myreader.databinding.ActivityFeedbackBinding; import xyz.fycz.myreader.ui.dialog.DialogCreator; -import xyz.fycz.myreader.widget.RefreshLayout; /** * @author fengyue * @date 2020/12/24 20:48 */ public class FeedbackActivity extends BaseActivity { - @BindView(R.id.refresh_layout) - RefreshLayout mRlRefresh; - @BindView(R.id.wv_feedback) - WebView wvFeedback; + + private ActivityFeedbackBinding binding; @Override - protected int getContentId() { - return R.layout.activity_feedback; + protected void bindView() { + binding =ActivityFeedbackBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -45,12 +42,12 @@ public class FeedbackActivity extends BaseActivity { protected void initWidget() { super.initWidget(); //声明WebSettings子类 - WebSettings webSettings = wvFeedback.getSettings(); + WebSettings webSettings = binding.wvFeedback.getSettings(); //如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript webSettings.setJavaScriptEnabled(true); - wvFeedback.loadUrl("https://www.wjx.cn/jq/102348283.aspx"); - wvFeedback.setWebViewClient(new WebViewClient(){ + binding.wvFeedback.loadUrl("https://www.wjx.cn/jq/102348283.aspx"); + binding.wvFeedback.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (!url.endsWith("102348283.aspx")){ @@ -70,14 +67,14 @@ public class FeedbackActivity extends BaseActivity { public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { super.onReceivedError(view, request, error); if (!MyApplication.isDestroy(FeedbackActivity.this)) - mRlRefresh.showError(); + binding.refreshLayout.showError(); } }); - wvFeedback.setWebChromeClient(new WebChromeClient(){ + binding.wvFeedback.setWebChromeClient(new WebChromeClient(){ @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100 && !MyApplication.isDestroy(FeedbackActivity.this)){ - mRlRefresh.showFinish(); + binding.refreshLayout.showFinish(); } }}); } @@ -85,8 +82,8 @@ public class FeedbackActivity extends BaseActivity { @Override protected void initClick() { super.initClick(); - mRlRefresh.setOnReloadingListener(() -> { - wvFeedback.loadUrl("https://www.wjx.cn/jq/102348283.aspx"); + binding.refreshLayout.setOnReloadingListener(() -> { + binding.wvFeedback.loadUrl("https://www.wjx.cn/jq/102348283.aspx"); }); } } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/FileSystemActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/FileSystemActivity.java index 9a0ab9e..e56d569 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/FileSystemActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/FileSystemActivity.java @@ -1,30 +1,28 @@ package xyz.fycz.myreader.ui.activity; -import android.widget.Button; -import android.widget.CheckBox; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import androidx.viewpager.widget.ViewPager; -import butterknife.BindView; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import xyz.fycz.myreader.R; import xyz.fycz.myreader.base.BaseTabActivity; -import xyz.fycz.myreader.ui.dialog.DialogCreator; +import xyz.fycz.myreader.databinding.ActivityFileSystemBinding; import xyz.fycz.myreader.enums.BookSource; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.service.BookService; +import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.fragment.BaseFileFragment; import xyz.fycz.myreader.ui.fragment.FileCategoryFragment; import xyz.fycz.myreader.ui.fragment.LocalBookFragment; import xyz.fycz.myreader.util.ToastUtils; -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - - /** * @author fengyue * @date 2020/8/12 20:02 @@ -33,12 +31,7 @@ import java.util.List; public class FileSystemActivity extends BaseTabActivity { private static final String TAG = "FileSystemActivity"; - @BindView(R.id.file_system_cb_selected_all) - CheckBox mCbSelectAll; - @BindView(R.id.file_system_btn_delete) - Button mBtnDelete; - @BindView(R.id.file_system_btn_add_book) - Button mBtnAddBook; + private ActivityFileSystemBinding binding; private LocalBookFragment mLocalFragment; private FileCategoryFragment mCategoryFragment; @@ -61,6 +54,13 @@ public class FileSystemActivity extends BaseTabActivity { } }; + @Override + protected void bindView() { + binding = ActivityFileSystemBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + super.bindView(); + } + @Override protected List createTabFragments() { mLocalFragment = new LocalBookFragment(); @@ -73,11 +73,6 @@ public class FileSystemActivity extends BaseTabActivity { return Arrays.asList("智能导入","手机目录"); } - @Override - protected int getContentId() { - return R.layout.activity_file_system; - } - @Override protected void setUpToolbar(Toolbar toolbar) { super.setUpToolbar(toolbar); @@ -88,10 +83,10 @@ public class FileSystemActivity extends BaseTabActivity { @Override protected void initClick() { super.initClick(); - mCbSelectAll.setOnClickListener( + binding.fileSystemCbSelectedAll.setOnClickListener( (view) -> { //设置全选状态 - boolean isChecked = mCbSelectAll.isChecked(); + boolean isChecked = binding.fileSystemCbSelectedAll.isChecked(); mCurFragment.setCheckedAll(isChecked); //改变菜单状态 changeMenuStatus(); @@ -124,7 +119,7 @@ public class FileSystemActivity extends BaseTabActivity { } }); - mBtnAddBook.setOnClickListener( + binding.fileSystemBtnAddBook.setOnClickListener( (v) -> { //获取选中的文件 List files = mCurFragment.getCheckedFiles(); @@ -144,7 +139,7 @@ public class FileSystemActivity extends BaseTabActivity { } ); - mBtnDelete.setOnClickListener( + binding.fileSystemBtnDelete.setOnClickListener( (v) -> { //弹出,确定删除文件吗。 DialogCreator.createCommonDialog(this, "删除文件", "确定删除文件吗?", @@ -213,18 +208,18 @@ public class FileSystemActivity extends BaseTabActivity { //点击、删除状态的设置 if (mCurFragment.getCheckedCount() == 0){ - mBtnAddBook.setText(getString(R.string.file_add_shelf)); + binding.fileSystemBtnAddBook.setText(getString(R.string.file_add_shelf)); //设置某些按钮的是否可点击 setMenuClickable(false); - if (mCbSelectAll.isChecked()){ + if (binding.fileSystemCbSelectedAll.isChecked()){ mCurFragment.setChecked(false); - mCbSelectAll.setChecked(mCurFragment.isCheckedAll()); + binding.fileSystemCbSelectedAll.setChecked(mCurFragment.isCheckedAll()); } } else { - mBtnAddBook.setText(getString(R.string.file_add_shelves, mCurFragment.getCheckedCount())); + binding.fileSystemBtnAddBook.setText(getString(R.string.file_add_shelves, mCurFragment.getCheckedCount())); setMenuClickable(true); //全选状态的设置 @@ -233,21 +228,21 @@ public class FileSystemActivity extends BaseTabActivity { if (mCurFragment.getCheckedCount() == mCurFragment.getCheckableCount()){ //设置为全选 mCurFragment.setChecked(true); - mCbSelectAll.setChecked(mCurFragment.isCheckedAll()); + binding.fileSystemCbSelectedAll.setChecked(mCurFragment.isCheckedAll()); } //如果曾今是全选则替换 else if (mCurFragment.isCheckedAll()){ mCurFragment.setChecked(false); - mCbSelectAll.setChecked(mCurFragment.isCheckedAll()); + binding.fileSystemCbSelectedAll.setChecked(mCurFragment.isCheckedAll()); } } //重置全选的文字 if (mCurFragment.isCheckedAll()){ - mCbSelectAll.setText("取消"); + binding.fileSystemCbSelectedAll.setText("取消"); } else { - mCbSelectAll.setText("全选"); + binding.fileSystemCbSelectedAll.setText("全选"); } } @@ -255,12 +250,12 @@ public class FileSystemActivity extends BaseTabActivity { private void setMenuClickable(boolean isClickable){ //设置是否可删除 - mBtnDelete.setEnabled(isClickable); - mBtnDelete.setClickable(isClickable); + binding.fileSystemBtnDelete.setEnabled(isClickable); + binding.fileSystemBtnDelete.setClickable(isClickable); //设置是否可添加书籍 - mBtnAddBook.setEnabled(isClickable); - mBtnAddBook.setClickable(isClickable); + binding.fileSystemBtnAddBook.setEnabled(isClickable); + binding.fileSystemBtnAddBook.setClickable(isClickable); } /** @@ -272,12 +267,12 @@ public class FileSystemActivity extends BaseTabActivity { //设置是否能够全选 if (count > 0){ - mCbSelectAll.setClickable(true); - mCbSelectAll.setEnabled(true); + binding.fileSystemCbSelectedAll.setClickable(true); + binding.fileSystemCbSelectedAll.setEnabled(true); } else { - mCbSelectAll.setClickable(false); - mCbSelectAll.setEnabled(false); + binding.fileSystemCbSelectedAll.setClickable(false); + binding.fileSystemCbSelectedAll.setEnabled(false); } } } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/FontsActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/FontsActivity.java index 5977a77..b6ccddf 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/FontsActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/FontsActivity.java @@ -8,26 +8,26 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.View; -import android.widget.ListView; -import android.widget.ProgressBar; + import androidx.appcompat.widget.Toolbar; -import butterknife.BindView; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; + import xyz.fycz.myreader.R; import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.common.APPCONST; +import xyz.fycz.myreader.databinding.ActivityFontsBinding; import xyz.fycz.myreader.enums.Font; import xyz.fycz.myreader.ui.adapter.FontsAdapter; import xyz.fycz.myreader.util.IOUtils; import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.utils.FileUtils; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; - import static xyz.fycz.myreader.util.UriFileUtil.getPath; /** @@ -35,10 +35,7 @@ import static xyz.fycz.myreader.util.UriFileUtil.getPath; * @date 2020/9/19 12:04 */ public class FontsActivity extends BaseActivity { - @BindView(R.id.lv_fonts) - ListView lvFonts; - @BindView(R.id.pb_loading) - ProgressBar pbLoading; + private ActivityFontsBinding binding; private ArrayList mFonts; private FontsAdapter mFontsAdapter; @@ -54,9 +51,11 @@ public class FontsActivity extends BaseActivity { } } }; + @Override - protected int getContentId() { - return R.layout.activity_fonts; + protected void bindView() { + binding = ActivityFontsBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -76,8 +75,8 @@ public class FontsActivity extends BaseActivity { protected void initWidget() { super.initWidget(); mFontsAdapter = new FontsAdapter(this, R.layout.listview_font_item, mFonts, this); - lvFonts.setAdapter(mFontsAdapter); - pbLoading.setVisibility(View.GONE); + binding.lvFonts.setAdapter(mFontsAdapter); + binding.pbLoading.setVisibility(View.GONE); } private void initFonts() { diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/LoginActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/LoginActivity.java index 1544bd8..69f429b 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/LoginActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/LoginActivity.java @@ -13,45 +13,32 @@ import android.text.TextWatcher; import android.view.MotionEvent; import android.view.View; import android.view.inputmethod.InputMethodManager; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.TextView; + import androidx.appcompat.widget.Toolbar; -import butterknife.BindView; -import com.google.android.material.textfield.TextInputLayout; + +import java.util.HashMap; +import java.util.Map; + import xyz.fycz.myreader.R; -import xyz.fycz.myreader.model.backup.UserService; import xyz.fycz.myreader.base.BaseActivity; -import xyz.fycz.myreader.webapi.callback.ResultCallback; import xyz.fycz.myreader.common.APPCONST; +import xyz.fycz.myreader.databinding.ActivityLoginBinding; +import xyz.fycz.myreader.model.backup.UserService; import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.util.CodeUtil; import xyz.fycz.myreader.util.CyptoUtils; import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.util.utils.StringUtils; - -import java.util.HashMap; -import java.util.Map; +import xyz.fycz.myreader.webapi.callback.ResultCallback; /** * @author fengyue * @date 2020/9/18 22:27 */ public class LoginActivity extends BaseActivity implements TextWatcher { - @BindView(R.id.et_user) - TextInputLayout user; - @BindView(R.id.et_password) - TextInputLayout password; - @BindView(R.id.bt_login) - Button loginBtn; - @BindView(R.id.tv_register) - TextView tvRegister; - @BindView(R.id.et_captcha) - TextInputLayout etCaptcha; - @BindView(R.id.iv_captcha) - ImageView ivCaptcha; + private ActivityLoginBinding binding; private String code; @SuppressLint("HandlerLeak") @@ -61,7 +48,7 @@ public class LoginActivity extends BaseActivity implements TextWatcher { public void handleMessage(Message msg) { switch (msg.what) { case 1: - loginBtn.setEnabled(true); + binding.btLogin.setEnabled(true); break; case 2: createCaptcha(); @@ -70,9 +57,11 @@ public class LoginActivity extends BaseActivity implements TextWatcher { } }; + @Override - protected int getContentId() { - return R.layout.activity_login; + protected void bindView() { + binding = ActivityLoginBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -92,22 +81,22 @@ public class LoginActivity extends BaseActivity implements TextWatcher { super.initWidget(); mHandler.sendMessage(mHandler.obtainMessage(2)); String username = UserService.readUsername(); - user.getEditText().setText(username); - user.getEditText().requestFocus(username.length()); + binding.etUser.getEditText().setText(username); + binding.etUser.getEditText().requestFocus(username.length()); //监听内容改变 -> 控制按钮的点击状态 - user.getEditText().addTextChangedListener(this); - password.getEditText().addTextChangedListener(this); - etCaptcha.getEditText().addTextChangedListener(this); + binding.etUser.getEditText().addTextChangedListener(this); + binding.etPassword.getEditText().addTextChangedListener(this); + binding.etCaptcha.getEditText().addTextChangedListener(this); } @Override protected void initClick() { super.initClick(); - ivCaptcha.setOnClickListener(v -> mHandler.sendMessage(mHandler.obtainMessage(2))); + binding.ivCaptcha.setOnClickListener(v -> mHandler.sendMessage(mHandler.obtainMessage(2))); - loginBtn.setOnClickListener(v -> { + binding.btLogin.setOnClickListener(v -> { mHandler.sendMessage(mHandler.obtainMessage(2)); - if (!code.toLowerCase().equals(etCaptcha.getEditText().getText().toString().toLowerCase())){ + if (!code.toLowerCase().equals(binding.etCaptcha.getEditText().getText().toString().toLowerCase())){ DialogCreator.createTipDialog(this, "验证码错误!"); return; } @@ -116,9 +105,9 @@ public class LoginActivity extends BaseActivity implements TextWatcher { return; } ProgressDialog dialog = DialogCreator.createProgressDialog(this, null, "正在登陆..."); - loginBtn.setEnabled(false); - final String loginName = user.getEditText().getText().toString().trim(); - String loginPwd = password.getEditText().getText().toString(); + binding.btLogin.setEnabled(false); + final String loginName = binding.etUser.getEditText().getText().toString().trim(); + String loginPwd = binding.etPassword.getEditText().getText().toString(); final Map userLoginInfo = new HashMap<>(); userLoginInfo.put("loginName", loginName); userLoginInfo.put("loginPwd", CyptoUtils.encode(APPCONST.KEY, loginPwd)); @@ -157,7 +146,7 @@ public class LoginActivity extends BaseActivity implements TextWatcher { }); - tvRegister.setOnClickListener(v -> { + binding.tvRegister.setOnClickListener(v -> { Intent intent = new Intent(LoginActivity.this, RegisterActivity.class); startActivity(intent); }); @@ -166,7 +155,7 @@ public class LoginActivity extends BaseActivity implements TextWatcher { public void createCaptcha() { code = CodeUtil.getInstance().createCode(); Bitmap codeBitmap = CodeUtil.getInstance().createBitmap(code); - ivCaptcha.setImageBitmap(codeBitmap); + binding.ivCaptcha.setImageBitmap(codeBitmap); } @@ -188,7 +177,7 @@ public class LoginActivity extends BaseActivity implements TextWatcher { (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); //2.隐藏键盘 - inputManager.hideSoftInputFromWindow(user.getWindowToken(),0); + inputManager.hideSoftInputFromWindow(binding.etUser.getWindowToken(),0); //3.取消焦点 View focusView = getCurrentFocus(); @@ -218,14 +207,14 @@ public class LoginActivity extends BaseActivity implements TextWatcher { //禁止输入中文 StringUtils.isNotChinese(s); //判断两个输入框是否有内容 - if (user.getEditText().getText().toString().length() > 0 && - password.getEditText().getText().toString().length() > 0 && - etCaptcha.getEditText().getText().toString().length() > 0){ + if (binding.etUser.getEditText().getText().toString().length() > 0 && + binding.etPassword.getEditText().getText().toString().length() > 0 && + binding.etCaptcha.getEditText().getText().toString().length() > 0){ //按钮可以点击 - loginBtn.setEnabled(true); + binding.btLogin.setEnabled(true); }else{ //按钮不能点击 - loginBtn.setEnabled(false); + binding.btLogin.setEnabled(false); } } } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/MainActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/MainActivity.java index 3bb5fdd..13d8756 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/MainActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/MainActivity.java @@ -6,54 +6,44 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.provider.Settings; -import android.text.InputType; import android.util.Log; import android.view.Menu; import android.view.MenuItem; -import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.ActionMenuView; -import androidx.appcompat.widget.AppCompatTextView; import androidx.appcompat.widget.Toolbar; import androidx.core.content.FileProvider; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentPagerAdapter; import androidx.viewpager.widget.ViewPager; -import butterknife.BindView; - -import com.google.android.material.bottomnavigation.BottomNavigationView; +import java.io.File; +import java.util.ArrayList; +import java.util.List; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.common.APPCONST; +import xyz.fycz.myreader.databinding.ActivityMainBinding; import xyz.fycz.myreader.entity.SharedBook; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.BookGroup; import xyz.fycz.myreader.greendao.service.BookGroupService; import xyz.fycz.myreader.ui.dialog.DialogCreator; -import xyz.fycz.myreader.ui.dialog.FingerprintDialog; import xyz.fycz.myreader.ui.dialog.MyAlertDialog; import xyz.fycz.myreader.ui.fragment.BookcaseFragment; import xyz.fycz.myreader.ui.fragment.FindFragment; import xyz.fycz.myreader.ui.fragment.MineFragment; -import xyz.fycz.myreader.util.CyptoUtils; import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.ToastUtils; -import xyz.fycz.myreader.util.utils.FingerprintUtils; import xyz.fycz.myreader.util.utils.GsonExtensionsKt; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - import static androidx.fragment.app.FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT; /** @@ -62,10 +52,8 @@ import static androidx.fragment.app.FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CU */ public class MainActivity extends BaseActivity { public static final String TAG = MainActivity.class.getSimpleName(); - @BindView(R.id.bottom_navigation_view) - BottomNavigationView bottomNavigation; - @BindView(R.id.view_pager_main) - ViewPager viewPagerMain; + + private ActivityMainBinding binding; private List mFragments = new ArrayList<>(); private String[] titles; @@ -77,8 +65,9 @@ public class MainActivity extends BaseActivity { private MineFragment mMineFragment; @Override - protected int getContentId() { - return R.layout.activity_main; + protected void bindView() { + binding = ActivityMainBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -120,8 +109,8 @@ public class MainActivity extends BaseActivity { @Override protected void initWidget() { super.initWidget(); - viewPagerMain.setOffscreenPageLimit(2); - viewPagerMain.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager(), BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { + binding.viewPagerMain.setOffscreenPageLimit(2); + binding.viewPagerMain.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager(), BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { @Override public int getCount() { return mFragments.size(); @@ -141,7 +130,7 @@ public class MainActivity extends BaseActivity { super.initClick(); mToolbar.setOnLongClickListener(v -> { - if (viewPagerMain.getCurrentItem() == 0 && !BookGroupService.getInstance().curGroupIsPrivate()){ + if (binding.viewPagerMain.getCurrentItem() == 0 && !BookGroupService.getInstance().curGroupIsPrivate()){ goPrivateBookcase(); return true; } @@ -149,25 +138,25 @@ public class MainActivity extends BaseActivity { }); //BottomNavigationView 点击事件监听 - bottomNavigation.setOnNavigationItemSelectedListener(menuItem -> { + binding.bottomNavigationView.setOnNavigationItemSelectedListener(menuItem -> { int menuId = menuItem.getItemId(); // 跳转指定页面:Fragment switch (menuId) { case R.id.menu_bookshelf: - viewPagerMain.setCurrentItem(0); + binding.viewPagerMain.setCurrentItem(0); break; case R.id.menu_find_book: - viewPagerMain.setCurrentItem(1); + binding.viewPagerMain.setCurrentItem(1); break; case R.id.menu_my_config: - viewPagerMain.setCurrentItem(2); + binding.viewPagerMain.setCurrentItem(2); break; } return false; }); // ViewPager 滑动事件监听 - viewPagerMain.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + binding.viewPagerMain.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int i, float v, int i1) { @@ -176,7 +165,7 @@ public class MainActivity extends BaseActivity { @Override public void onPageSelected(int i) { //将滑动到的页面对应的 menu 设置为选中状态 - bottomNavigation.getMenu().getItem(i).setChecked(true); + binding.bottomNavigationView.getMenu().getItem(i).setChecked(true); getSupportActionBar().setTitle(titles[i]); if (i == 0) { getSupportActionBar().setSubtitle(groupName); @@ -230,7 +219,7 @@ public class MainActivity extends BaseActivity { } public ViewPager getViewPagerMain() { - return viewPagerMain; + return binding.viewPagerMain; } /********************************Event***************************************/ @@ -248,7 +237,7 @@ public class MainActivity extends BaseActivity { @Override public boolean onPrepareOptionsMenu(Menu menu) { - if (viewPagerMain.getCurrentItem() == 0) { + if (binding.viewPagerMain.getCurrentItem() == 0) { if (mBookcaseFragment.getmBookcasePresenter() != null && mBookcaseFragment.getmBookcasePresenter().ismEditState()) { menu.findItem(R.id.action_finish).setVisible(true); @@ -275,31 +264,27 @@ public class MainActivity extends BaseActivity { if (mBookcaseFragment.isRecreate()) { reLoadFragment(); } - switch (item.getItemId()) { - case R.id.action_search: - Intent searchBookIntent = new Intent(this, SearchBookActivity.class); - startActivity(searchBookIntent); - return true; - case R.id.action_finish: - mBookcaseFragment.getmBookcasePresenter().cancelEdit(); - invalidateOptionsMenu(); - return true; - case R.id.action_change_group: - case R.id.action_group_man: - if (!mBookcaseFragment.getmBookcasePresenter().hasOnGroupChangeListener()) { - mBookcaseFragment.getmBookcasePresenter().addOnGroupChangeListener(() -> { - groupName = SharedPreUtils.getInstance().getString(getString(R.string.curBookGroupName), "所有书籍"); - getSupportActionBar().setSubtitle(groupName); - }); - } - break; - case R.id.action_edit: - invalidateOptionsMenu(); - break; - case R.id.action_qr_scan: - Intent intent = new Intent(this, QRCodeScanActivity.class); - startActivityForResult(intent, APPCONST.REQUEST_QR_SCAN); - break; + int itemId = item.getItemId(); + if (itemId == R.id.action_search) { + Intent searchBookIntent = new Intent(this, SearchBookActivity.class); + startActivity(searchBookIntent); + return true; + } else if (itemId == R.id.action_finish) { + mBookcaseFragment.getmBookcasePresenter().cancelEdit(); + invalidateOptionsMenu(); + return true; + } else if (itemId == R.id.action_change_group || itemId == R.id.action_group_man) { + if (!mBookcaseFragment.getmBookcasePresenter().hasOnGroupChangeListener()) { + mBookcaseFragment.getmBookcasePresenter().addOnGroupChangeListener(() -> { + groupName = SharedPreUtils.getInstance().getString(getString(R.string.curBookGroupName), "所有书籍"); + getSupportActionBar().setSubtitle(groupName); + }); + } + } else if (itemId == R.id.action_edit) { + invalidateOptionsMenu(); + } else if (itemId == R.id.action_qr_scan) { + Intent intent = new Intent(this, QRCodeScanActivity.class); + startActivityForResult(intent, APPCONST.REQUEST_QR_SCAN); } return mBookcaseFragment.getmBookcasePresenter().onOptionsItemSelected(item); } @@ -329,7 +314,7 @@ public class MainActivity extends BaseActivity { }else { groupName = bookGroup.getName(); } - if (viewPagerMain.getCurrentItem() == 0){ + if (binding.viewPagerMain.getCurrentItem() == 0){ getSupportActionBar().setSubtitle(groupName); } // MyApplication.checkVersionByServer(this); diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/MoreSettingActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/MoreSettingActivity.java index e4c4ffa..3833264 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/MoreSettingActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/MoreSettingActivity.java @@ -3,50 +3,46 @@ package xyz.fycz.myreader.ui.activity; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import android.text.InputType; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.widget.*; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.NumberPicker; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.SwitchCompat; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.FragmentTransaction; -import butterknife.BindView; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; + import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseFragment; import xyz.fycz.myreader.common.APPCONST; -import xyz.fycz.myreader.greendao.service.BookGroupService; -import xyz.fycz.myreader.ui.dialog.DialogCreator; -import xyz.fycz.myreader.ui.dialog.FingerprintDialog; -import xyz.fycz.myreader.ui.dialog.MultiChoiceDialog; -import xyz.fycz.myreader.ui.dialog.MyAlertDialog; +import xyz.fycz.myreader.databinding.ActivityMoreSettingBinding; import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.enums.BookSource; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.service.BookService; +import xyz.fycz.myreader.ui.dialog.DialogCreator; +import xyz.fycz.myreader.ui.dialog.MultiChoiceDialog; +import xyz.fycz.myreader.ui.dialog.MyAlertDialog; import xyz.fycz.myreader.ui.fragment.PrivateBooksFragment; import xyz.fycz.myreader.ui.fragment.WebDavFragment; -import xyz.fycz.myreader.util.CyptoUtils; -import xyz.fycz.myreader.util.utils.FileUtils; import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.ToastUtils; -import xyz.fycz.myreader.util.utils.FingerprintUtils; +import xyz.fycz.myreader.util.utils.FileUtils; import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil; -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; - import static xyz.fycz.myreader.common.APPCONST.BOOK_CACHE_PATH; /** @@ -55,80 +51,8 @@ import static xyz.fycz.myreader.common.APPCONST.BOOK_CACHE_PATH; */ public class MoreSettingActivity extends BaseActivity { - @BindView(R.id.sv_content) - ScrollView svContent; - @BindView(R.id.ll_webdav) - LinearLayout mLlWebdav; - @BindView(R.id.rl_volume) - RelativeLayout mRlVolume; - @BindView(R.id.sc_volume) - SwitchCompat mScVolume; - @BindView(R.id.rl_always_next) - RelativeLayout mRlAlwaysNext; - @BindView(R.id.sc_always_next) - SwitchCompat mScAlwaysNext; - @BindView(R.id.rl_show_status) - RelativeLayout mRlShowStatus; - @BindView(R.id.sc_show_status) - SwitchCompat mScShowStatus; - @BindView(R.id.rl_long_press) - RelativeLayout mRlLongPress; - @BindView(R.id.sc_long_press) - SwitchCompat mScLongPress; - @BindView(R.id.rl_content_replace) - RelativeLayout mRlContentReplace; - @BindView(R.id.rl_read_aloud_volume_turn_page) - RelativeLayout mRlReadAloudVolumeTurnPage; - @BindView(R.id.sc_read_aloud_volume_turn_page) - SwitchCompat mScReadAloudVolumeTurnPage; - @BindView(R.id.rl_no_menu_title) - RelativeLayout mRlNoMenuTitle; - @BindView(R.id.sc_no_menu_title) - SwitchCompat mScNoMenuTitle; - @BindView(R.id.rl_reset_screen) - RelativeLayout mRlResetScreen; - @BindView(R.id.sc_reset_screen) - Spinner mScResetScreen; - @BindView(R.id.rl_auto_refresh) - RelativeLayout mRlAutoRefresh; - @BindView(R.id.sc_auto_refresh) - SwitchCompat mScAutoRefresh; - @BindView(R.id.ll_book_sort) - LinearLayout mLlBookSort; - @BindView(R.id.tv_book_sort) - TextView mTvBookSort; - @BindView(R.id.rl_private_bookcase) - RelativeLayout mRlPrivateBookcase; - @BindView(R.id.ll_close_refresh) - LinearLayout mLlCloseRefresh; - @BindView(R.id.ll_disable_source) - LinearLayout mLlDisableSource; - @BindView(R.id.ll_thread_num) - LinearLayout mLlThreadNum; - @BindView(R.id.tv_thread_num) - TextView mTvThreadNum; - @BindView(R.id.iv_match_chapter_tip) - ImageView mIvMatchChapterTip; - @BindView(R.id.rl_match_chapter) - RelativeLayout mRlMatchChapter; - @BindView(R.id.sc_match_chapter) - SwitchCompat mScMatchChapter; - @BindView(R.id.rl_match_chapter_suitability) - RelativeLayout mRlMatchChapterSuitability; - @BindView(R.id.sc_match_chapter_suitability) - Spinner mScMatchChapterSuitability; - @BindView(R.id.rl_cathe_gap) - RelativeLayout mRlCatheGap; - @BindView(R.id.sc_cathe_gap) - Spinner mScCatheGap; - @BindView(R.id.rl_delete_cathe) - RelativeLayout mRlDeleteCathe; - @BindView(R.id.ll_download_all) - LinearLayout mLlDownloadAll; - /*@BindView(R.id.rl_bookstore) - RelativeLayout mRlBookstore; - @BindView(R.id.sc_bookstore) - SwitchCompat mScBookstore;*/ + + private ActivityMoreSettingBinding binding; private boolean needRefresh; private boolean upMenu; @@ -165,8 +89,9 @@ public class MoreSettingActivity extends BaseActivity { private BaseFragment curFragment; @Override - protected int getContentId() { - return R.layout.activity_more_setting; + protected void bindView() { + binding = ActivityMoreSettingBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -213,16 +138,16 @@ public class MoreSettingActivity extends BaseActivity { super.initWidget(); initSwitchStatus(); if (sortStyle == 1) { - mTvBookSort.setText(getString(R.string.time_sort)); + binding.tvBookSort.setText(getString(R.string.time_sort)); } else if (sortStyle == 2) { - mTvBookSort.setText(getString(R.string.book_name_sort)); + binding.tvBookSort.setText(getString(R.string.book_name_sort)); } if (isMatchChapter) { - mRlMatchChapterSuitability.setVisibility(View.VISIBLE); + binding.rlMatchChapterSuitability.setVisibility(View.VISIBLE); } else { - mRlMatchChapterSuitability.setVisibility(View.GONE); + binding.rlMatchChapterSuitability.setVisibility(View.GONE); } - mTvThreadNum.setText(getString(R.string.cur_thread_num, threadNum)); + binding.tvThreadNum.setText(getString(R.string.cur_thread_num, threadNum)); } @Override @@ -254,21 +179,21 @@ public class MoreSettingActivity extends BaseActivity { } private void initSwitchStatus() { - mScVolume.setChecked(isVolumeTurnPage); - mScAlwaysNext.setChecked(alwaysNext); - mScMatchChapter.setChecked(isMatchChapter); - mScAutoRefresh.setChecked(autoRefresh); - mScShowStatus.setChecked(isShowStatusBar); - mScLongPress.setChecked(isLongPress); - mScNoMenuTitle.setChecked(noMenuTitle); - mScReadAloudVolumeTurnPage.setChecked(readAloudVolumeTurnPage); + binding.scVolume.setChecked(isVolumeTurnPage); + binding.scAlwaysNext.setChecked(alwaysNext); + binding.scMatchChapter.setChecked(isMatchChapter); + binding.scAutoRefresh.setChecked(autoRefresh); + binding.scShowStatus.setChecked(isShowStatusBar); + binding.scLongPress.setChecked(isLongPress); + binding.scNoMenuTitle.setChecked(noMenuTitle); + binding.scReadAloudVolumeTurnPage.setChecked(readAloudVolumeTurnPage); } @Override protected void initClick() { super.initClick(); - mLlWebdav.setOnClickListener(v -> { - svContent.setVisibility(View.GONE); + binding.llWebdav.setOnClickListener(v -> { + binding.svContent.setVisibility(View.GONE); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); if (mWebDavFragment == null) { mWebDavFragment = new WebDavFragment(); @@ -281,31 +206,31 @@ public class MoreSettingActivity extends BaseActivity { setUpToolbar(); }); - mRlVolume.setOnClickListener( + binding.rlVolume.setOnClickListener( (v) -> { if (isVolumeTurnPage) { isVolumeTurnPage = false; } else { isVolumeTurnPage = true; } - mScVolume.setChecked(isVolumeTurnPage); + binding.scVolume.setChecked(isVolumeTurnPage); mSetting.setVolumeTurnPage(isVolumeTurnPage); SysManager.saveSetting(mSetting); } ); - mRlAlwaysNext.setOnClickListener( + binding.rlAlwaysNext.setOnClickListener( (v) -> { if (alwaysNext) { alwaysNext = false; } else { alwaysNext = true; } - mScAlwaysNext.setChecked(alwaysNext); + binding.scAlwaysNext.setChecked(alwaysNext); mSetting.setAlwaysNext(alwaysNext); SysManager.saveSetting(mSetting); } ); - mRlShowStatus.setOnClickListener( + binding.rlShowStatus.setOnClickListener( (v) -> { needRefresh = true; if (isShowStatusBar) { @@ -313,12 +238,12 @@ public class MoreSettingActivity extends BaseActivity { } else { isShowStatusBar = true; } - mScShowStatus.setChecked(isShowStatusBar); + binding.scShowStatus.setChecked(isShowStatusBar); mSetting.setShowStatusBar(isShowStatusBar); SysManager.saveSetting(mSetting); } ); - mRlLongPress.setOnClickListener( + binding.rlLongPress.setOnClickListener( (v) -> { needRefresh = false; if (isLongPress) { @@ -326,25 +251,25 @@ public class MoreSettingActivity extends BaseActivity { } else { isLongPress = true; } - mScLongPress.setChecked(isLongPress); + binding.scLongPress.setChecked(isLongPress); mSetting.setCanSelectText(isLongPress); SysManager.saveSetting(mSetting); } ); - mRlContentReplace.setOnClickListener(v -> startActivity(new Intent(this, RuleActivity.class))); - mRlReadAloudVolumeTurnPage.setOnClickListener( + binding.rlContentReplace.setOnClickListener(v -> startActivity(new Intent(this, RuleActivity.class))); + binding.rlReadAloudVolumeTurnPage.setOnClickListener( (v) -> { if (readAloudVolumeTurnPage) { readAloudVolumeTurnPage = false; } else { readAloudVolumeTurnPage = true; } - mScReadAloudVolumeTurnPage.setChecked(readAloudVolumeTurnPage); + binding.scReadAloudVolumeTurnPage.setChecked(readAloudVolumeTurnPage); mSetting.setReadAloudVolumeTurnPage(readAloudVolumeTurnPage); SysManager.saveSetting(mSetting); } ); - mRlNoMenuTitle.setOnClickListener( + binding.rlNoMenuTitle.setOnClickListener( (v) -> { upMenu = true; if (noMenuTitle) { @@ -352,13 +277,13 @@ public class MoreSettingActivity extends BaseActivity { } else { noMenuTitle = true; } - mScNoMenuTitle.setChecked(noMenuTitle); + binding.scNoMenuTitle.setChecked(noMenuTitle); mSetting.setNoMenuChTitle(noMenuTitle); SysManager.saveSetting(mSetting); } ); - mLlBookSort.setOnClickListener(v -> { + binding.llBookSort.setOnClickListener(v -> { MyAlertDialog.build(this) .setTitle(getString(R.string.book_sort)) .setSingleChoiceItems(R.array.book_sort, sortStyle, (dialog, which) -> { @@ -366,40 +291,40 @@ public class MoreSettingActivity extends BaseActivity { mSetting.setSortStyle(sortStyle); SysManager.saveSetting(mSetting); if (sortStyle == 0) { - mTvBookSort.setText(getString(R.string.manual_sort)); + binding.tvBookSort.setText(getString(R.string.manual_sort)); if (!SharedPreUtils.getInstance().getBoolean("manualSortTip")) { DialogCreator.createTipDialog(this, "可在书架编辑状态下长按移动书籍进行排序!"); SharedPreUtils.getInstance().putBoolean("manualSortTip", true); } } else if (sortStyle == 1) { - mTvBookSort.setText(getString(R.string.time_sort)); + binding.tvBookSort.setText(getString(R.string.time_sort)); } else if (sortStyle == 2) { - mTvBookSort.setText(getString(R.string.book_name_sort)); + binding.tvBookSort.setText(getString(R.string.book_name_sort)); } dialog.dismiss(); }).setNegativeButton("取消", null).show(); }); - mRlPrivateBookcase.setOnClickListener(v -> { + binding.rlPrivateBookcase.setOnClickListener(v -> { MyAlertDialog.showPrivateVerifyDia(this, needGoTo -> { showPrivateBooksFragment(); }); }); - mRlAutoRefresh.setOnClickListener( + binding.rlAutoRefresh.setOnClickListener( (v) -> { if (autoRefresh) { autoRefresh = false; } else { autoRefresh = true; } - mScAutoRefresh.setChecked(autoRefresh); + binding.scAutoRefresh.setChecked(autoRefresh); mSetting.setRefreshWhenStart(autoRefresh); SysManager.saveSetting(mSetting); } ); - mLlCloseRefresh.setOnClickListener(v -> { + binding.llCloseRefresh.setOnClickListener(v -> { MyApplication.runOnUiThread(() -> { if (mCloseRefreshDia != null) { mCloseRefreshDia.show(); @@ -444,7 +369,7 @@ public class MoreSettingActivity extends BaseActivity { }); }); - mLlDisableSource.setOnClickListener(v -> { + binding.llDisableSource.setOnClickListener(v -> { if (mDisableSourceDia != null) { mDisableSourceDia.show(); return; @@ -490,7 +415,7 @@ public class MoreSettingActivity extends BaseActivity { }); }); - mLlThreadNum.setOnClickListener(v -> { + binding.llThreadNum.setOnClickListener(v -> { View view = LayoutInflater.from(this).inflate(R.layout.dialog_number_picker, null); NumberPicker threadPick = view.findViewById(R.id.number_picker); threadPick.setMaxValue(1024); @@ -505,28 +430,28 @@ public class MoreSettingActivity extends BaseActivity { .setPositiveButton("确定", (dialog, which) -> { threadNum = threadPick.getValue(); SharedPreUtils.getInstance().putInt(getString(R.string.threadNum), threadNum); - mTvThreadNum.setText(getString(R.string.cur_thread_num, threadNum)); + binding.tvThreadNum.setText(getString(R.string.cur_thread_num, threadNum)); }).setNegativeButton("取消", null) .show(); }); - mRlMatchChapter.setOnClickListener( + binding.rlMatchChapter.setOnClickListener( (v) -> { if (isMatchChapter) { isMatchChapter = false; - mRlMatchChapterSuitability.setVisibility(View.GONE); + binding.rlMatchChapterSuitability.setVisibility(View.GONE); } else { isMatchChapter = true; - mRlMatchChapterSuitability.setVisibility(View.VISIBLE); + binding.rlMatchChapterSuitability.setVisibility(View.VISIBLE); } - mScMatchChapter.setChecked(isMatchChapter); + binding.scMatchChapter.setChecked(isMatchChapter); mSetting.setMatchChapter(isMatchChapter); SysManager.saveSetting(mSetting); } ); - mLlDownloadAll.setOnClickListener(v -> { + binding.llDownloadAll.setOnClickListener(v -> { MyApplication.runOnUiThread(() -> { if (mDownloadAllDia != null) { mDownloadAllDia.show(); @@ -573,13 +498,13 @@ public class MoreSettingActivity extends BaseActivity { }); }); - mIvMatchChapterTip.setOnClickListener(v -> DialogCreator.createTipDialog(this, "智能匹配", getString(R.string.match_chapter_tip))); + binding.ivMatchChapterTip.setOnClickListener(v -> DialogCreator.createTipDialog(this, "智能匹配", getString(R.string.match_chapter_tip))); - mRlMatchChapterSuitability.setOnClickListener(v -> mScMatchChapterSuitability.performClick()); - mRlResetScreen.setOnClickListener(v -> mScResetScreen.performClick()); - mRlCatheGap.setOnClickListener(v -> mScCatheGap.performClick()); + binding.rlMatchChapterSuitability.setOnClickListener(v -> binding.scMatchChapterSuitability.performClick()); + binding.rlResetScreen.setOnClickListener(v -> binding.scResetScreen.performClick()); + binding.rlCatheGap.setOnClickListener(v -> binding.scCatheGap.performClick()); - mRlDeleteCathe.setOnClickListener(v -> { + binding.rlDeleteCathe.setOnClickListener(v -> { MyApplication.runOnUiThread(() -> { File catheFile = getCacheDir(); String catheFileSize = FileUtils.getFileSize(FileUtils.getDirSize(catheFile)); @@ -630,7 +555,7 @@ public class MoreSettingActivity extends BaseActivity { setResult(AppCompatActivity.RESULT_OK, result); super.finish(); } else { - svContent.setVisibility(View.VISIBLE); + binding.svContent.setVisibility(View.VISIBLE); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.hide(curFragment); ft.commit(); @@ -645,7 +570,7 @@ public class MoreSettingActivity extends BaseActivity { ArrayAdapter resetScreenAdapter = ArrayAdapter.createFromResource(this, R.array.reset_screen_time, android.R.layout.simple_spinner_item); resetScreenAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - mScResetScreen.setAdapter(resetScreenAdapter); + binding.scResetScreen.setAdapter(resetScreenAdapter); int resetScreenSelection = 0; switch (resetScreenTime) { @@ -662,8 +587,8 @@ public class MoreSettingActivity extends BaseActivity { resetScreenSelection = 3; break; } - mScResetScreen.setSelection(resetScreenSelection); - mScResetScreen.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + binding.scResetScreen.setSelection(resetScreenSelection); + binding.scResetScreen.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { switch (position) { @@ -693,7 +618,7 @@ public class MoreSettingActivity extends BaseActivity { ArrayAdapter matchSuiAdapter = ArrayAdapter.createFromResource(this, R.array.match_chapter_suitability, android.R.layout.simple_spinner_item); matchSuiAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - mScMatchChapterSuitability.setAdapter(matchSuiAdapter); + binding.scMatchChapterSuitability.setAdapter(matchSuiAdapter); if (matchChapterSuitability == 0.0) { matchChapterSuitability = 0.7f; @@ -702,9 +627,9 @@ public class MoreSettingActivity extends BaseActivity { } int matchSuiSelection = (int) (matchChapterSuitability * 10 - 5); - mScMatchChapterSuitability.setSelection(matchSuiSelection); + binding.scMatchChapterSuitability.setSelection(matchSuiSelection); - mScMatchChapterSuitability.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + binding.scMatchChapterSuitability.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { matchChapterSuitability = (position + 5) * 1f / 10f; @@ -721,7 +646,7 @@ public class MoreSettingActivity extends BaseActivity { ArrayAdapter catheGapAdapter = ArrayAdapter.createFromResource(this, R.array.cathe_chapter_gap, android.R.layout.simple_spinner_item); catheGapAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - mScCatheGap.setAdapter(catheGapAdapter); + binding.scCatheGap.setAdapter(catheGapAdapter); if (catheCap == 0) { catheCap = 150; @@ -730,9 +655,9 @@ public class MoreSettingActivity extends BaseActivity { } int catheGapSelection = catheCap / 50 - 1; - mScCatheGap.setSelection(catheGapSelection); + binding.scCatheGap.setSelection(catheGapSelection); - mScCatheGap.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + binding.scCatheGap.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { catheCap = (position + 1) * 50; @@ -769,7 +694,7 @@ public class MoreSettingActivity extends BaseActivity { } private void showPrivateBooksFragment(){ - svContent.setVisibility(View.GONE); + binding.svContent.setVisibility(View.GONE); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); if (mPrivateBooksFragment == null) { mPrivateBooksFragment = new PrivateBooksFragment(); diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/QRCodeScanActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/QRCodeScanActivity.java index baf986b..04a996a 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/QRCodeScanActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/QRCodeScanActivity.java @@ -10,27 +10,18 @@ import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; -import android.widget.LinearLayout; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; import androidx.core.app.ActivityCompat; -import com.google.android.material.floatingactionbutton.FloatingActionButton; - -import java.util.Objects; - -import butterknife.BindView; import cn.bingoogolapple.qrcode.core.QRCodeView; -import cn.bingoogolapple.qrcode.zxing.ZXingView; import io.reactivex.Single; import io.reactivex.SingleOnSubscribe; import xyz.fycz.myreader.R; import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.observer.MySingleObserver; +import xyz.fycz.myreader.databinding.ActivityQrcodeCaptureBinding; import xyz.fycz.myreader.util.PermissionsChecker; import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.ToastUtils; @@ -45,16 +36,8 @@ import static xyz.fycz.myreader.util.UriFileUtil.getPath; public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Delegate { - @BindView(R.id.zxingview) - ZXingView zxingview; - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.ll_flashlight) - LinearLayout llFlashLight; - @BindView(R.id.fab_flashlight) - FloatingActionButton fabFlashlight; - @BindView(R.id.tv_flashlight) - TextView tvFlashlight; + + private ActivityQrcodeCaptureBinding binding; private final int REQUEST_QR_IMAGE = 202; private static final String CAMERA = "android.permission.CAMERA"; @@ -64,11 +47,11 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg private String picPath; @Override - protected int getContentId() { - return R.layout.activity_qrcode_capture; + protected void bindView() { + binding = ActivityQrcodeCaptureBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } - @Override protected void setUpToolbar(Toolbar toolbar) { super.setUpToolbar(toolbar); @@ -81,16 +64,16 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg */ @Override protected void initData(Bundle savedInstanceState) { - zxingview.setDelegate(this); - fabFlashlight.setOnClickListener(view -> { + binding.zxingview.setDelegate(this); + binding.fabFlashlight.setOnClickListener(view -> { if (flashlightIsOpen) { flashlightIsOpen = false; - zxingview.closeFlashlight(); - tvFlashlight.setText(getString(R.string.light_contact)); + binding.zxingview.closeFlashlight(); + binding.tvFlashlight.setText(getString(R.string.light_contact)); } else { flashlightIsOpen = true; - zxingview.openFlashlight(); - tvFlashlight.setText(getString(R.string.close_contact)); + binding.zxingview.openFlashlight(); + binding.tvFlashlight.setText(getString(R.string.close_contact)); } }); } @@ -107,13 +90,13 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg @Override protected void onStop() { - zxingview.stopCamera(); // 关闭摄像头预览,并且隐藏扫描框 + binding.zxingview.stopCamera(); // 关闭摄像头预览,并且隐藏扫描框 super.onStop(); } @Override protected void onDestroy() { - zxingview.onDestroy(); // 销毁二维码扫描控件 + binding.zxingview.onDestroy(); // 销毁二维码扫描控件 super.onDestroy(); } @@ -142,10 +125,10 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg @Override public void onCameraAmbientBrightnessChanged(boolean isDark) { if (isDark){ - llFlashLight.setVisibility(View.VISIBLE); + binding.llFlashlight.setVisibility(View.VISIBLE); }else { if (!flashlightIsOpen) { - llFlashLight.setVisibility(View.GONE); + binding.llFlashlight.setVisibility(View.GONE); } } } @@ -156,8 +139,8 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg } private void startScan() { - zxingview.setVisibility(View.VISIBLE); - zxingview.startSpotAndShowRect(); // 显示扫描框,并开始识别 + binding.zxingview.setVisibility(View.VISIBLE); + binding.zxingview.startSpotAndShowRect(); // 显示扫描框,并开始识别 } private void requestPermission() { @@ -212,7 +195,7 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - zxingview.startSpotAndShowRect(); // 显示扫描框,并开始识别 + binding.zxingview.startSpotAndShowRect(); // 显示扫描框,并开始识别 if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_QR_IMAGE) { picPath = getPath(this, data.getData()); @@ -238,7 +221,7 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg .subscribe(new MySingleObserver() { @Override public void onSuccess(Bitmap bitmap) { - zxingview.decodeQRCode(bitmap); + binding.zxingview.decodeQRCode(bitmap); } }); } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java index 7addb3e..f4cb2ab 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java @@ -28,12 +28,7 @@ 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.ProgressBar; -import android.widget.RelativeLayout; import android.widget.SeekBar; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -41,8 +36,6 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.gyf.immersionbar.ImmersionBar; import com.jaredrummler.android.colorpicker.ColorPickerDialogListener; @@ -51,8 +44,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; -import butterknife.BindView; -import butterknife.OnClick; import xyz.fycz.myreader.ActivityManage; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.MyApplication; @@ -60,6 +51,7 @@ import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.URLCONST; +import xyz.fycz.myreader.databinding.ActivityReadBinding; import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.enums.BookSource; import xyz.fycz.myreader.enums.Font; @@ -120,58 +112,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe private static final String TAG = ReadActivity.class.getSimpleName(); /*****************************View***********************************/ - @BindView(R.id.rl_content) - RelativeLayout rlContent; - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.read_abl_top_menu) - AppBarLayout readAblTopMenu; - @BindView(R.id.ll_chapter_view) - LinearLayout chapterView; - @BindView(R.id.tv_chapter_title_top) - TextView chapterTitle; - @BindView(R.id.tv_chapter_url) - TextView chapterUrl; - @BindView(R.id.read_pv_content) - PageView pageView; - @BindView(R.id.pb_loading) - ProgressBar pbLoading; - @BindView(R.id.cursor_left) - ImageView cursorLeft; - @BindView(R.id.cursor_right) - ImageView cursorRight; - @BindView(R.id.read_tv_page_tip) - TextView readTvPageTip; - @BindView(R.id.read_tv_pre_chapter) - TextView readTvPreChapter; - @BindView(R.id.read_sb_chapter_progress) - SeekBar readSbChapterProgress; - @BindView(R.id.read_tv_next_chapter) - TextView readTvNextChapter; - @BindView(R.id.read_tv_category) - TextView readTvCategory; - @BindView(R.id.btn_night_mode) - FloatingActionButton readBtnNightMode; - @BindView(R.id.read_tv_brightness_eye) - TextView readTvBrightnessEye; - @BindView(R.id.read_tv_setting) - TextView readTvSetting; - @BindView(R.id.read_ll_bottom_menu) - LinearLayout readLlBottomMenu; - @BindView(R.id.read_tv_listen_book) - TextView readTvListenBook; - @BindView(R.id.read_setting_menu) - ReadSettingMenu readSettingMenu; - @BindView(R.id.read_customize_menu) - CustomizeComMenu customizeComMenu; - @BindView(R.id.read_auto_page_menu) - AutoPageMenu autoPageMenu; - @BindView(R.id.read_customize_layout_menu) - CustomizeLayoutMenu customizeLayoutMenu; - @BindView(R.id.read_brightness_eye_menu) - BrightnessEyeMenu brightnessEyeMenu; - @BindView(R.id.vwNavigationBar) - View vwNavigationBar; + private ActivityReadBinding binding; /***************************variable*****************************/ private Book mBook; @@ -270,7 +211,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe e.getMessage()); e.printStackTrace(); } - pbLoading.setVisibility(View.GONE); + binding.pbLoading.setVisibility(View.GONE); break; case 3: break; @@ -299,7 +240,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe mPageLoader.chapterError(); break; case 8: - pbLoading.setVisibility(View.GONE); + binding.pbLoading.setVisibility(View.GONE); break; case 9: ToastUtils.showInfo("正在后台缓存书籍,具体进度可查看通知栏!"); @@ -314,12 +255,14 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe }; - /**************************override***********************************/ @Override - protected int getContentId() { - return R.layout.activity_read; + protected void bindView() { + binding = ActivityReadBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } + /**************************override***********************************/ + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -379,7 +322,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe mReadCrawler = ReadCrawlerUtil.getReadCrawler(mBook.getSource()); - mPageLoader = pageView.getPageLoader(mBook, mReadCrawler, mSetting); + mPageLoader = binding.readPvContent.getPageLoader(mBook, mReadCrawler, mSetting); //Dialog mSourceDialog = new SourceExchangeDialog(this, mBook); } @@ -389,13 +332,13 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe super.initWidget(); ImmersionBar.with(this).fullScreen(true).init(); //隐藏StatusBar - pageView.post( + binding.readPvContent.post( this::hideSystemBar ); if (!mSetting.isBrightFollowSystem()) { BrightUtil.setBrightness(this, mSetting.getBrightProgress()); } - pbLoading.setVisibility(View.VISIBLE); + binding.pbLoading.setVisibility(View.VISIBLE); initEyeView(); initSettingListener(); initTopMenu(); @@ -408,7 +351,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe @Override protected void initClick() { super.initClick(); - pageView.setTouchListener(new PageView.TouchListener() { + binding.readPvContent.setTouchListener(new PageView.TouchListener() { @Override public boolean onTouch() { screenOffTimerStart(); @@ -441,14 +384,14 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe @Override public void onTouchClearCursor() { - cursorLeft.setVisibility(View.INVISIBLE); - cursorRight.setVisibility(View.INVISIBLE); + binding.cursorLeft.setVisibility(View.INVISIBLE); + binding.cursorRight.setVisibility(View.INVISIBLE); longPressMenu.hidePopupListWindow(); } @Override public void onLongPress() { - if (!pageView.isRunning()) { + if (!binding.readPvContent.isRunning()) { selectTextCursorShow(); showAction(); } @@ -518,11 +461,11 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe } ); - readSbChapterProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + binding.readSbChapterProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { - readTvPageTip.setText((progress + 1) + "/" + (seekBar.getMax() + 1)); + binding.readTvPageTip.setText((progress + 1) + "/" + (seekBar.getMax() + 1)); } } @@ -568,7 +511,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe startActivity(intent); }); - readTvListenBook.setOnClickListener(v -> { + binding.readTvListenBook.setOnClickListener(v -> { if (mSetting.getPageMode() == PageMode.SCROLL) { ToastUtils.showWarring("朗读暂不支持滚动翻页模式!"); return; @@ -585,12 +528,54 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe mAudioPlayerDialog.show(); }); initReadLongPressPop(); - cursorLeft.setOnTouchListener(this); - cursorRight.setOnTouchListener(this); - rlContent.setOnTouchListener(this); + binding.cursorLeft.setOnTouchListener(this); + binding.cursorRight.setOnTouchListener(this); + binding.rlContent.setOnTouchListener(this); } - + protected void initBottomMenuClick() { + //设置 + binding.readTvSetting.setOnClickListener(v -> { + toggleMenu(false); + binding.readSettingMenu.startAnimation(mBottomInAnim); + binding.readSettingMenu.setVisibility(VISIBLE); + }); + //上一章 + binding.readTvPreChapter.setOnClickListener(v -> mPageLoader.skipPreChapter()); + //下一章 + binding.readTvNextChapter.setOnClickListener(v -> mPageLoader.skipNextChapter()); + //护眼 + binding.readTvBrightnessEye.setOnClickListener(v -> { + hideReadMenu(); + binding.readBrightnessEyeMenu.initWidget(); + binding.readBrightnessEyeMenu.setVisibility(VISIBLE); + binding.readBrightnessEyeMenu.startAnimation(mBottomInAnim); + }); + //目录 + binding.readTvCategory.setOnClickListener(v -> { + //切换菜单 + toggleMenu(true); + //跳转 + mHandler.postDelayed(() -> { + Intent intent = new Intent(this, CatalogActivity.class); + intent.putExtra(APPCONST.BOOK, mBook); + this.startActivityForResult(intent, APPCONST.REQUEST_CHAPTER_PAGE); + }, mBottomOutAnim.getDuration()); + }); + //跳转链接 + binding.llChapterView.setOnClickListener(v -> { + if (mChapters != null && mChapters.size() != 0) { + Chapter curChapter = mChapters.get(mPageLoader.getChapterPos()); + String url = curChapter.getUrl(); + if (!"本地书籍".equals(mBook.getType()) && !StringHelper.isEmpty(url)) { + Intent intent = new Intent(Intent.ACTION_VIEW); + Uri uri = Uri.parse(url); + intent.setData(uri); + startActivity(intent); + } + } + }); + } @Override protected void processLogic() { super.processLogic(); @@ -620,13 +605,13 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe @Override public boolean onKeyDown(int keyCode, KeyEvent event) { boolean isVolumeTurnPage = SysManager.getSetting().isVolumeTurnPage(); - if (readAblTopMenu.getVisibility() != View.VISIBLE && - customizeLayoutMenu.getVisibility() != View.VISIBLE && - autoPageMenu.getVisibility() != View.VISIBLE && - customizeComMenu.getVisibility() != View.VISIBLE && - readSettingMenu.getVisibility() != View.VISIBLE && - brightnessEyeMenu.getVisibility() != View.VISIBLE) { - if (pageView.getSelectMode() != PageView.SelectMode.Normal) { + if (binding.readAblTopMenu.getVisibility() != View.VISIBLE && + binding.readCustomizeLayoutMenu.getVisibility() != View.VISIBLE && + binding.readAutoPageMenu.getVisibility() != View.VISIBLE && + binding.readCustomizeMenu.getVisibility() != View.VISIBLE && + binding.readSettingMenu.getVisibility() != View.VISIBLE && + binding.readBrightnessEyeMenu.getVisibility() != View.VISIBLE) { + if (binding.readPvContent.getSelectMode() != PageView.SelectMode.Normal) { clearSelect(); } switch (keyCode) { @@ -747,52 +732,46 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.action_change_source: - mSourceDialog.show(); - break; - case R.id.action_reload: - isPrev = false; - if (!"本地书籍".equals(mBook.getType())) { - mChapterService.deleteChapterCacheFile(mChapters.get(mPageLoader.getChapterPos())); - } - mPageLoader.refreshChapter(mChapters.get(mPageLoader.getChapterPos())); - break; - case R.id.action_add_bookmark: - if (mChapters == null || mChapters.size() == 0) { - if ("本地书籍".equals(mBook.getType())) { - ToastUtils.showWarring("请等待章节拆分完成后再添加书签"); - } else { - ToastUtils.showError("章节目录为空,添加书签失败!"); - } - return true; + int itemId = item.getItemId(); + if (itemId == R.id.action_change_source) { + mSourceDialog.show(); + } else if (itemId == R.id.action_reload) { + isPrev = false; + if (!"本地书籍".equals(mBook.getType())) { + mChapterService.deleteChapterCacheFile(mChapters.get(mPageLoader.getChapterPos())); + } + mPageLoader.refreshChapter(mChapters.get(mPageLoader.getChapterPos())); + } else if (itemId == R.id.action_add_bookmark) { + if (mChapters == null || mChapters.size() == 0) { + if ("本地书籍".equals(mBook.getType())) { + ToastUtils.showWarring("请等待章节拆分完成后再添加书签"); + } else { + ToastUtils.showError("章节目录为空,添加书签失败!"); } - Chapter curChapter = mChapters.get(mPageLoader.getChapterPos()); - BookMark bookMark = new BookMark(); - bookMark.setBookId(mBook.getId()); - bookMark.setTitle(curChapter.getTitle()); - bookMark.setBookMarkChapterNum(mPageLoader.getChapterPos()); - bookMark.setBookMarkReadPosition(mPageLoader.getPagePos()); - mBookMarkService.addOrUpdateBookMark(bookMark); - DialogCreator.createTipDialog(this, "《" + mBook.getName() + - "》:" + bookMark.getTitle() + "[" + (bookMark.getBookMarkReadPosition() + 1) + - "]\n书签添加成功,书签列表可在目录界面查看!"); return true; - case R.id.action_replace_content: - Intent ruleIntent = new Intent(this, RuleActivity.class); - startActivityForResult(ruleIntent, APPCONST.REQUEST_REFRESH_READ_UI); - break; - case R.id.action_copy_content: - new CopyContentDialog(this, mPageLoader.getContent()).show(); - break; - case R.id.action_open_link: - Uri uri = Uri.parse(mBook.getChapterUrl()); - Intent intent = new Intent(Intent.ACTION_VIEW, uri); - startActivity(intent); - break; - case R.id.action_download: - download(); - break; + } + Chapter curChapter = mChapters.get(mPageLoader.getChapterPos()); + BookMark bookMark = new BookMark(); + bookMark.setBookId(mBook.getId()); + bookMark.setTitle(curChapter.getTitle()); + bookMark.setBookMarkChapterNum(mPageLoader.getChapterPos()); + bookMark.setBookMarkReadPosition(mPageLoader.getPagePos()); + mBookMarkService.addOrUpdateBookMark(bookMark); + DialogCreator.createTipDialog(this, "《" + mBook.getName() + + "》:" + bookMark.getTitle() + "[" + (bookMark.getBookMarkReadPosition() + 1) + + "]\n书签添加成功,书签列表可在目录界面查看!"); + return true; + } else if (itemId == R.id.action_replace_content) { + Intent ruleIntent = new Intent(this, RuleActivity.class); + startActivityForResult(ruleIntent, APPCONST.REQUEST_REFRESH_READ_UI); + } else if (itemId == R.id.action_copy_content) { + new CopyContentDialog(this, mPageLoader.getContent()).show(); + } else if (itemId == R.id.action_open_link) { + Uri uri = Uri.parse(mBook.getChapterUrl()); + Intent intent = new Intent(Intent.ACTION_VIEW, uri); + startActivity(intent); + } else if (itemId == R.id.action_download) { + download(); } return super.onOptionsItemSelected(item); } @@ -844,11 +823,11 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe break; case APPCONST.REQUEST_SELECT_BG: String bgPath = getPath(this, data.getData()); - customizeLayoutMenu.setCustomBg(bgPath); + binding.readCustomizeLayoutMenu.setCustomBg(bgPath); break; case APPCONST.REQUEST_IMPORT_LAYOUT: String zipPath = getPath(this, data.getData()); - customizeLayoutMenu.zip2Layout(zipPath); + binding.readCustomizeLayoutMenu.zip2Layout(zipPath); break; } } @@ -875,7 +854,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe break; } SysManager.saveSetting(mSetting); - customizeLayoutMenu.upColor(); + binding.readCustomizeLayoutMenu.upColor(); } /** @@ -906,11 +885,11 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe if (mChapters != null && mChapters.size() != 0) { Chapter curChapter = mChapters.get(mPageLoader.getChapterPos()); String url = curChapter.getUrl(); - chapterTitle.setText(curChapter.getTitle()); - chapterUrl.setText(StringHelper.isEmpty(url) ? curChapter.getId() : url); - readSbChapterProgress.setProgress(mPageLoader.getPagePos()); - readSbChapterProgress.setMax(mPageLoader.getAllPagePos() - 1); - readTvPageTip.setText((readSbChapterProgress.getProgress() + 1) + "/" + (readSbChapterProgress.getMax() + 1)); + binding.tvChapterTitleTop.setText(curChapter.getTitle()); + binding.tvChapterUrl.setText(StringHelper.isEmpty(url) ? curChapter.getId() : url); + binding.readSbChapterProgress.setProgress(mPageLoader.getPagePos()); + binding.readSbChapterProgress.setMax(mPageLoader.getAllPagePos() - 1); + binding.readTvPageTip.setText(String.format("%s/%s", binding.readSbChapterProgress.getProgress() + 1 ,binding.readSbChapterProgress.getMax() + 1)); } } /************************书籍相关******************************/ @@ -1138,7 +1117,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe ToastUtils.showWarring("该章节无内容!"); return; } - pbLoading.setVisibility(View.VISIBLE); + binding.pbLoading.setVisibility(View.VISIBLE); getChapterContent(mChapters.get(chapterPos), new ResultCallback() { @Override public void onFinish(Object o, int code) { @@ -1237,13 +1216,13 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe */ private void initTopMenu() { int statusBarHeight = ImmersionBar.getStatusBarHeight(this); - readAblTopMenu.setPadding(0, statusBarHeight, 0, 0); + binding.readAblTopMenu.setPadding(0, statusBarHeight, 0, 0); if (mSetting.isNoMenuChTitle()) { - chapterView.setVisibility(GONE); - toolbar.getLayoutParams().height = 60 + ImmersionBar.getStatusBarHeight(this); + binding.llChapterView.setVisibility(GONE); + binding.toolbar.getLayoutParams().height = ScreenUtils.dpToPx(60) + ImmersionBar.getStatusBarHeight(this); } else { - chapterView.setVisibility(VISIBLE); - toolbar.getLayoutParams().height = 45 + ImmersionBar.getStatusBarHeight(this); + binding.llChapterView.setVisibility(VISIBLE); + binding.toolbar.getLayoutParams().height = ScreenUtils.dpToPx(45) + ImmersionBar.getStatusBarHeight(this); } } @@ -1254,23 +1233,23 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe //判断是否全屏 //if (mSetting.getHideStatusBar()) { if (!mSetting.isDayStyle()) { - readBtnNightMode.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_sun)); + binding.btnNightMode.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_sun)); } - readBtnNightMode.setOnClickListener(v -> changeNightAndDaySetting(mSetting.isDayStyle())); + binding.btnNightMode.setOnClickListener(v -> changeNightAndDaySetting(mSetting.isDayStyle())); if (true) { //还需要设置mBottomMenu的底部高度 if (ImmersionBar.hasNavigationBar(this)) { int height = ImmersionBar.getNavigationBarHeight(this); - vwNavigationBar.getLayoutParams().height = height; - readSettingMenu.setNavigationBarHeight(height); - customizeComMenu.setNavigationBarHeight(height); - customizeLayoutMenu.setNavigationBarHeight(height); - autoPageMenu.setNavigationBarHeight(height); - brightnessEyeMenu.setNavigationBarHeight(height); + binding.vwNavigationBar.getLayoutParams().height = height; + binding.readSettingMenu.setNavigationBarHeight(height); + binding.readCustomizeMenu.setNavigationBarHeight(height); + binding.readCustomizeLayoutMenu.setNavigationBarHeight(height); + binding.readAutoPageMenu.setNavigationBarHeight(height); + binding.readBrightnessEyeMenu.setNavigationBarHeight(height); } } else { //设置mBottomMenu的底部距离 - vwNavigationBar.getLayoutParams().height = 0; + binding.vwNavigationBar.getLayoutParams().height = 0; } } @@ -1282,33 +1261,33 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe private boolean hideReadMenu() { hideSystemBar(); boolean flag = false; - if (readAblTopMenu.getVisibility() == VISIBLE) { + if (binding.readAblTopMenu.getVisibility() == VISIBLE) { toggleMenu(true); flag = true; } - if (readSettingMenu.getVisibility() == View.VISIBLE) { - readSettingMenu.setVisibility(GONE); - readSettingMenu.startAnimation(mBottomOutAnim); + if (binding.readSettingMenu.getVisibility() == View.VISIBLE) { + binding.readSettingMenu.setVisibility(GONE); + binding.readSettingMenu.startAnimation(mBottomOutAnim); flag = true; } - if (customizeComMenu.getVisibility() == VISIBLE) { - customizeComMenu.setVisibility(GONE); - customizeComMenu.startAnimation(mBottomOutAnim); + if (binding.readCustomizeMenu.getVisibility() == VISIBLE) { + binding.readCustomizeMenu.setVisibility(GONE); + binding.readCustomizeMenu.startAnimation(mBottomOutAnim); flag = true; } - if (customizeLayoutMenu.getVisibility() == VISIBLE) { - customizeLayoutMenu.setVisibility(GONE); - customizeLayoutMenu.startAnimation(mBottomOutAnim); + if (binding.readCustomizeLayoutMenu.getVisibility() == VISIBLE) { + binding.readCustomizeLayoutMenu.setVisibility(GONE); + binding.readCustomizeLayoutMenu.startAnimation(mBottomOutAnim); flag = true; } - if (autoPageMenu.getVisibility() == VISIBLE) { - autoPageMenu.setVisibility(GONE); - autoPageMenu.startAnimation(mBottomOutAnim); + if (binding.readAutoPageMenu.getVisibility() == VISIBLE) { + binding.readAutoPageMenu.setVisibility(GONE); + binding.readAutoPageMenu.startAnimation(mBottomOutAnim); flag = true; } - if (brightnessEyeMenu.getVisibility() == VISIBLE) { - brightnessEyeMenu.setVisibility(GONE); - brightnessEyeMenu.startAnimation(mBottomOutAnim); + if ( binding.readBrightnessEyeMenu.getVisibility() == VISIBLE) { + binding.readBrightnessEyeMenu.setVisibility(GONE); + binding.readBrightnessEyeMenu.startAnimation(mBottomOutAnim); flag = true; } return flag; @@ -1324,12 +1303,12 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe public void toggleMenu(boolean hideStatusBar, boolean home) { initMenuAnim(); - if (readAblTopMenu.getVisibility() == View.VISIBLE) { + if (binding.readAblTopMenu.getVisibility() == View.VISIBLE) { //关闭 - readAblTopMenu.startAnimation(mTopOutAnim); - readLlBottomMenu.startAnimation(mBottomOutAnim); - readAblTopMenu.setVisibility(GONE); - readLlBottomMenu.setVisibility(GONE); + binding.readAblTopMenu.startAnimation(mTopOutAnim); + binding.readLlBottomMenu.startAnimation(mBottomOutAnim); + binding.readAblTopMenu.setVisibility(GONE); + binding.readLlBottomMenu.setVisibility(GONE); if (hideStatusBar) { hideSystemBar(); } @@ -1342,14 +1321,14 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe } } if (autoPage) { - autoPageMenu.setVisibility(VISIBLE); - autoPageMenu.startAnimation(mBottomInAnim); + binding.readAutoPageMenu.setVisibility(VISIBLE); + binding.readAutoPageMenu.startAnimation(mBottomInAnim); return; } - readAblTopMenu.setVisibility(View.VISIBLE); - readLlBottomMenu.setVisibility(View.VISIBLE); - readAblTopMenu.startAnimation(mTopInAnim); - readLlBottomMenu.startAnimation(mBottomInAnim); + binding.readAblTopMenu.setVisibility(View.VISIBLE); + binding.readLlBottomMenu.setVisibility(View.VISIBLE); + binding.readAblTopMenu.startAnimation(mTopInAnim); + binding.readLlBottomMenu.startAnimation(mBottomInAnim); showSystemBar(); } @@ -1370,7 +1349,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe private void hideSystemBar() { //隐藏 - if (readAblTopMenu.getVisibility() != VISIBLE || (mAudioPlayerDialog != null && !mAudioPlayerDialog.isShowing())) { + if (binding.readAblTopMenu.getVisibility() != VISIBLE || (mAudioPlayerDialog != null && !mAudioPlayerDialog.isShowing())) { if (!mSetting.isShowStatusBar()) { SystemBarUtils.hideStableStatusBar(this); } @@ -1384,8 +1363,8 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe * 初始化详细设置 */ private void initSettingListener() { - readSettingMenu.setOnClickListener(null); - readSettingMenu.setListener(this, new ReadSettingMenu.Callback() { + binding.readSettingMenu.setOnClickListener(null); + binding.readSettingMenu.setListener(this, new ReadSettingMenu.Callback() { @Override public void onRefreshUI() { mHandler.sendEmptyMessage(5); @@ -1436,14 +1415,14 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe }, mBottomOutAnim.getDuration()); } }); - customizeComMenu.setOnClickListener(null); - customizeComMenu.setListener(new CustomizeComMenu.Callback() { + binding.readCustomizeMenu.setOnClickListener(null); + binding.readCustomizeMenu.setListener(new CustomizeComMenu.Callback() { @Override public void onTextPChange() { mPageLoader.setTextSize(); mSetting.setComposition(0); SysManager.saveSetting(mSetting); - readSettingMenu.initComposition(); + binding.readSettingMenu.initComposition(); } @Override @@ -1451,7 +1430,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe mPageLoader.upMargin(); mSetting.setComposition(0); SysManager.saveSetting(mSetting); - readSettingMenu.initComposition(); + binding.readSettingMenu.initComposition(); } @Override @@ -1465,18 +1444,16 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe mPageLoader.upMargin(); mSetting.setComposition(1); SysManager.saveSetting(mSetting); - readSettingMenu.initComposition(); + binding.readSettingMenu.initComposition(); ToastUtils.showInfo("已重置各间距为默认值"); } }); - autoPageMenu.setOnClickListener(null); - autoPageMenu.setListener(new AutoPageMenu.Callback() { + binding.readAutoPageMenu.setOnClickListener(null); + binding.readAutoPageMenu.setListener(new AutoPageMenu.Callback() { @Override public void onSpeedChange() { - if (pageView != null) { - pageView.autoPageOnSpeedChange(); - autoPage(); - } + binding.readPvContent.autoPageOnSpeedChange(); + autoPage(); } @Override @@ -1486,8 +1463,8 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe hideReadMenu(); } }); - customizeLayoutMenu.setOnClickListener(null); - customizeLayoutMenu.setListener(this, new CustomizeLayoutMenu.Callback() { + binding.readCustomizeLayoutMenu.setOnClickListener(null); + binding.readCustomizeLayoutMenu.setListener(this, new CustomizeLayoutMenu.Callback() { @Override public void upBg() { mPageLoader.refreshUi(); @@ -1495,12 +1472,12 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe @Override public void upStyle() { - readSettingMenu.initStyleImage(); + binding.readSettingMenu.initStyleImage(); } }); - brightnessEyeMenu.setOnClickListener(null); - brightnessEyeMenu.setListener(this, new BrightnessEyeMenu.Callback() { + binding.readBrightnessEyeMenu.setOnClickListener(null); + binding.readBrightnessEyeMenu.setListener(this, new BrightnessEyeMenu.Callback() { @Override public void onProtectEyeChange() { if (mSetting.isProtectEye()) { @@ -1567,58 +1544,6 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe } } - @OnClick({R.id.read_tv_setting, R.id.read_tv_pre_chapter - , R.id.read_tv_next_chapter, R.id.read_tv_brightness_eye}) - protected void onClick(View view) { - switch (view.getId()) { - case R.id.read_tv_setting: //设置 - toggleMenu(false); - readSettingMenu.startAnimation(mBottomInAnim); - readSettingMenu.setVisibility(VISIBLE); - break; - case R.id.read_tv_pre_chapter: //前一章 - mPageLoader.skipPreChapter(); - break; - case R.id.read_tv_next_chapter: //后一章 - mPageLoader.skipNextChapter(); - break; - case R.id.read_tv_brightness_eye: - hideReadMenu(); - brightnessEyeMenu.initWidget(); - brightnessEyeMenu.setVisibility(VISIBLE); - brightnessEyeMenu.startAnimation(mBottomInAnim); - break; - } - } - - /** - * 跳转到目录 - */ - @OnClick(R.id.read_tv_category) - protected void goToCatalog() { - //切换菜单 - toggleMenu(true); - //跳转 - mHandler.postDelayed(() -> { - Intent intent = new Intent(this, CatalogActivity.class); - intent.putExtra(APPCONST.BOOK, mBook); - this.startActivityForResult(intent, APPCONST.REQUEST_CHAPTER_PAGE); - }, mBottomOutAnim.getDuration()); - } - - @OnClick(R.id.ll_chapter_view) - protected void gotoUrl() { - if (mChapters != null && mChapters.size() != 0) { - Chapter curChapter = mChapters.get(mPageLoader.getChapterPos()); - String url = curChapter.getUrl(); - if (!"本地书籍".equals(mBook.getType()) && !StringHelper.isEmpty(url)) { - Intent intent = new Intent(Intent.ACTION_VIEW); - Uri uri = Uri.parse(url); - intent.setData(uri); - startActivity(intent); - } - } - } protected void download() { if (!isCollected) { @@ -1629,17 +1554,17 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe } public void showCustomizeMenu() { - customizeComMenu.initWidget(); - customizeComMenu.setVisibility(VISIBLE); - customizeComMenu.startAnimation(mBottomInAnim); + binding.readCustomizeMenu.initWidget(); + binding.readCustomizeMenu.setVisibility(VISIBLE); + binding.readCustomizeMenu.startAnimation(mBottomInAnim); } public void showCustomizeLayoutMenu() { hideReadMenu(); - customizeLayoutMenu.upColor(); - customizeLayoutMenu.setVisibility(VISIBLE); - customizeLayoutMenu.startAnimation(mBottomInAnim); + binding.readCustomizeLayoutMenu.upColor(); + binding.readCustomizeLayoutMenu.setVisibility(VISIBLE); + binding.readCustomizeLayoutMenu.startAnimation(mBottomInAnim); } /****************息屏相关*****************/ @@ -1939,26 +1864,26 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe v.postInvalidate(); //移动过程中要画线 - pageView.setSelectMode(PageView.SelectMode.SelectMoveForward); + binding.readPvContent.setSelectMode(PageView.SelectMode.SelectMoveForward); - int hh = cursorLeft.getHeight(); - int ww = cursorLeft.getWidth(); + int hh = binding.cursorLeft.getHeight(); + int ww = binding.cursorLeft.getWidth(); if (v.getId() == R.id.cursor_left) { - pageView.setFirstSelectTxtChar(pageView.getCurrentTxtChar(lastX + ww, lastY - hh)); - if (pageView.getFirstSelectTxtChar() != null) { - cursorLeft.setX(pageView.getFirstSelectTxtChar().getTopLeftPosition().x - ww); - cursorLeft.setY(pageView.getFirstSelectTxtChar().getBottomLeftPosition().y); + binding.readPvContent.setFirstSelectTxtChar(binding.readPvContent.getCurrentTxtChar(lastX + ww, lastY - hh)); + if (binding.readPvContent.getFirstSelectTxtChar() != null) { + binding.cursorLeft.setX(binding.readPvContent.getFirstSelectTxtChar().getTopLeftPosition().x - ww); + binding.cursorLeft.setY(binding.readPvContent.getFirstSelectTxtChar().getBottomLeftPosition().y); } } else { - pageView.setLastSelectTxtChar(pageView.getCurrentTxtChar(lastX - ww, lastY - hh)); - if (pageView.getLastSelectTxtChar() != null) { - cursorRight.setX(pageView.getLastSelectTxtChar().getBottomRightPosition().x); - cursorRight.setY(pageView.getLastSelectTxtChar().getBottomRightPosition().y); + binding.readPvContent.setLastSelectTxtChar(binding.readPvContent.getCurrentTxtChar(lastX - ww, lastY - hh)); + if (binding.readPvContent.getLastSelectTxtChar() != null) { + binding.cursorRight.setX(binding.readPvContent.getLastSelectTxtChar().getBottomRightPosition().x); + binding.cursorRight.setY(binding.readPvContent.getLastSelectTxtChar().getBottomRightPosition().y); } } - pageView.invalidate(); + binding.readPvContent.invalidate(); break; case MotionEvent.ACTION_UP: @@ -1977,19 +1902,19 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe */ public void showAction() { float x, y; - if (cursorLeft.getX() - cursorRight.getX() > 0){ - x = cursorRight.getX() + (cursorLeft.getX() - cursorRight.getX()) / 2 + ScreenUtils.dpToPx(12); + if (binding.cursorLeft.getX() - binding.cursorRight.getX() > 0){ + x = binding.cursorRight.getX() + (binding.cursorLeft.getX() - binding.cursorRight.getX()) / 2 + ScreenUtils.dpToPx(12); }else { - x = cursorLeft.getX() + (cursorRight.getX() - cursorLeft.getX()) / 2 + ScreenUtils.dpToPx(12); + x = binding.cursorLeft.getX() + (binding.cursorRight.getX() - binding.cursorLeft.getX()) / 2 + ScreenUtils.dpToPx(12); } - if ((cursorLeft.getY() - ScreenUtils.spToPx(mSetting.getReadWordSize()) - ScreenUtils.dpToPx(60)) < 0) { + if ((binding.cursorLeft.getY() - ScreenUtils.spToPx(mSetting.getReadWordSize()) - ScreenUtils.dpToPx(60)) < 0) { longPressMenu.setShowBottom(true); - y = cursorLeft.getY() + cursorLeft.getHeight() * 3 / 5; + y = binding.cursorLeft.getY() + binding.cursorLeft.getHeight() * 3 / 5; } else { longPressMenu.setShowBottom(false); - y = cursorLeft.getY() - ScreenUtils.spToPx(mSetting.getReadWordSize()) - ScreenUtils.dpToPx(5); + y = binding.cursorLeft.getY() - ScreenUtils.spToPx(mSetting.getReadWordSize()) - ScreenUtils.dpToPx(5); } - longPressMenu.showPopupListWindow(rlContent, 0, x, y, + longPressMenu.showPopupListWindow(binding.rlContent, 0, x, y, longPressMenuItems, longPressMenuListener); } @@ -1997,12 +1922,12 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe * 显示 */ private void selectTextCursorShow() { - if (pageView.getFirstSelectTxtChar() == null || pageView.getLastSelectTxtChar() == null) + if (binding.readPvContent.getFirstSelectTxtChar() == null || binding.readPvContent.getLastSelectTxtChar() == null) return; //show Cursor on current position cursorShow(); //set current word selected - pageView.invalidate(); + binding.readPvContent.invalidate(); // hideSnackBar(); } @@ -2011,15 +1936,15 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe * 显示选择 */ private void cursorShow() { - cursorLeft.setVisibility(View.VISIBLE); - cursorRight.setVisibility(View.VISIBLE); - int hh = cursorLeft.getHeight(); - int ww = cursorLeft.getWidth(); - if (pageView.getFirstSelectTxtChar() != null) { - cursorLeft.setX(pageView.getFirstSelectTxtChar().getTopLeftPosition().x - ww); - cursorLeft.setY(pageView.getFirstSelectTxtChar().getBottomLeftPosition().y); - cursorRight.setX(pageView.getFirstSelectTxtChar().getBottomRightPosition().x); - cursorRight.setY(pageView.getFirstSelectTxtChar().getBottomRightPosition().y); + binding.cursorLeft.setVisibility(View.VISIBLE); + binding.cursorRight.setVisibility(View.VISIBLE); + int hh = binding.cursorLeft.getHeight(); + int ww = binding.cursorLeft.getWidth(); + if (binding.readPvContent.getFirstSelectTxtChar() != null) { + binding.cursorLeft.setX(binding.readPvContent.getFirstSelectTxtChar().getTopLeftPosition().x - ww); + binding.cursorLeft.setY(binding.readPvContent.getFirstSelectTxtChar().getBottomLeftPosition().y); + binding.cursorRight.setX(binding.readPvContent.getFirstSelectTxtChar().getBottomRightPosition().x); + binding.cursorRight.setY(binding.readPvContent.getFirstSelectTxtChar().getBottomRightPosition().y); } } @@ -2052,7 +1977,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe switch (position) { case 0: ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clipData = ClipData.newPlainText(null, pageView.getSelectStr()); + ClipData clipData = ClipData.newPlainText(null, binding.readPvContent.getSelectStr()); if (clipboard != null) { clipboard.setPrimaryClip(clipData); ToastUtils.showInfo("所选内容已经复制到剪贴板"); @@ -2063,7 +1988,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe ReplaceRuleBean oldRuleBean = new ReplaceRuleBean(); oldRuleBean.setReplaceSummary(""); oldRuleBean.setEnable(true); - oldRuleBean.setRegex(pageView.getSelectStr().trim()); + oldRuleBean.setRegex(binding.readPvContent.getSelectStr().trim()); oldRuleBean.setIsRegex(false); oldRuleBean.setReplacement(""); oldRuleBean.setSerialNumber(0); @@ -2077,12 +2002,12 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe replaceDialog.show(getSupportFragmentManager(), "replaceRule"); break; case 2: - selectString = pageView.getSelectStr(); + selectString = binding.readPvContent.getSelectStr(); speak(ReadActivity.this, selectString); clearSelect(); break; case 3: - selectString = StringUtils.deleteWhitespace(pageView.getSelectStr()); + selectString = StringUtils.deleteWhitespace(binding.readPvContent.getSelectStr()); MyAlertDialog.build(ReadActivity.this) .setTitle(R.string.search) .setItems(R.array.search_way, (dialog, which) -> { @@ -2113,7 +2038,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe clearSelect(); break; case 4: - selectString = pageView.getSelectStr(); + selectString = binding.readPvContent.getSelectStr(); ShareUtils.share(ReadActivity.this, selectString); clearSelect(); break; @@ -2126,10 +2051,10 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe * 清除选择 */ private void clearSelect() { - cursorLeft.setVisibility(View.INVISIBLE); - cursorRight.setVisibility(View.INVISIBLE); + binding.cursorLeft.setVisibility(View.INVISIBLE); + binding.cursorRight.setVisibility(View.INVISIBLE); longPressMenu.hidePopupListWindow(); - pageView.clearSelect(); + binding.readPvContent.clearSelect(); } private TextToSpeech textToSpeech; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/RegisterActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/RegisterActivity.java index 0e3f265..2e0747e 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/RegisterActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/RegisterActivity.java @@ -9,48 +9,30 @@ import android.text.Editable; import android.text.TextWatcher; import android.text.method.LinkMovementMethod; import android.view.View; -import android.widget.Button; -import android.widget.CheckBox; -import android.widget.ImageView; -import android.widget.TextView; + import androidx.appcompat.widget.Toolbar; -import butterknife.BindView; -import com.google.android.material.textfield.TextInputLayout; + +import java.util.HashMap; +import java.util.Map; + import xyz.fycz.myreader.R; -import xyz.fycz.myreader.model.backup.UserService; import xyz.fycz.myreader.base.BaseActivity; -import xyz.fycz.myreader.webapi.callback.ResultCallback; +import xyz.fycz.myreader.databinding.ActivityRegisterBinding; +import xyz.fycz.myreader.model.backup.UserService; import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.util.CodeUtil; import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.utils.StringUtils; - -import java.util.HashMap; -import java.util.Map; +import xyz.fycz.myreader.webapi.callback.ResultCallback; /** * @author fengyue * @date 2020/9/18 22:37 */ public class RegisterActivity extends BaseActivity { - @BindView(R.id.et_username) - TextInputLayout etUsername; - @BindView(R.id.et_password) - TextInputLayout etPassword; - @BindView(R.id.et_rp_password) - TextInputLayout etRpPassword; - @BindView(R.id.et_captcha) - TextInputLayout etCaptcha; - @BindView(R.id.iv_captcha) - ImageView ivCaptcha; - @BindView(R.id.bt_register) - Button btRegister; - @BindView(R.id.tv_register_tip) - TextView tvRegisterTip; - @BindView(R.id.cb_agreement) - CheckBox cbAgreement; - @BindView(R.id.tv_agreement) - TextView tvAgreement; + + private ActivityRegisterBinding binding; + private String code; private String username = ""; private String password = ""; @@ -70,16 +52,16 @@ public class RegisterActivity extends BaseActivity { showTip((String) msg.obj); break; case 3: - tvRegisterTip.setVisibility(View.GONE); + binding.tvRegisterTip.setVisibility(View.GONE); break; } } }; - @Override - protected int getContentId() { - return R.layout.activity_register; + protected void bindView() { + binding = ActivityRegisterBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -93,8 +75,8 @@ public class RegisterActivity extends BaseActivity { protected void initWidget() { super.initWidget(); mHandler.sendMessage(mHandler.obtainMessage(1)); - etUsername.requestFocus(); - etUsername.getEditText().addTextChangedListener(new TextWatcher() { + binding.etUsername.requestFocus(); + binding.etUsername.getEditText().addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -124,7 +106,7 @@ public class RegisterActivity extends BaseActivity { } }); - etPassword.getEditText().addTextChangedListener(new TextWatcher() { + binding.etPassword.getEditText().addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -149,7 +131,7 @@ public class RegisterActivity extends BaseActivity { } }); - etRpPassword.getEditText().addTextChangedListener(new TextWatcher() { + binding.etRpPassword.getEditText().addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -172,7 +154,7 @@ public class RegisterActivity extends BaseActivity { } }); - etCaptcha.getEditText().addTextChangedListener(new TextWatcher() { + binding.etCaptcha.getEditText().addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -195,16 +177,16 @@ public class RegisterActivity extends BaseActivity { } }); - tvAgreement.setMovementMethod(LinkMovementMethod.getInstance()); + binding.tvAgreement.setMovementMethod(LinkMovementMethod.getInstance()); } @Override protected void initClick() { super.initClick(); - ivCaptcha.setOnClickListener(v -> mHandler.sendMessage(mHandler.obtainMessage(1))); + binding.ivCaptcha.setOnClickListener(v -> mHandler.sendMessage(mHandler.obtainMessage(1))); - btRegister.setOnClickListener(v -> { + binding.btRegister.setOnClickListener(v -> { if (!username.matches("^[A-Za-z][A-Za-z0-9]{5,13}$")){ DialogCreator.createTipDialog(this, "用户名格式错误", "用户名必须在6-14位之间\n用户名只能以字母开头\n用户名只能由数字、字母、下划线、减号组成"); @@ -216,7 +198,7 @@ public class RegisterActivity extends BaseActivity { "两次输入的密码不一致"); }else if(!inputCode.trim().toLowerCase().equals(code.toLowerCase())){ DialogCreator.createTipDialog(this, "验证码错误"); - }else if(!cbAgreement.isChecked()){ + }else if(!binding.cbAgreement.isChecked()){ DialogCreator.createTipDialog(this, "请勾选同意《用户服务协议》"); }else { ProgressDialog dialog = DialogCreator.createProgressDialog(this, null, "正在注册..."); @@ -252,19 +234,19 @@ public class RegisterActivity extends BaseActivity { public void createCaptcha() { code = CodeUtil.getInstance().createCode(); Bitmap codeBitmap = CodeUtil.getInstance().createBitmap(code); - ivCaptcha.setImageBitmap(codeBitmap); + binding.ivCaptcha.setImageBitmap(codeBitmap); } public void showTip(String tip) { - tvRegisterTip.setVisibility(View.VISIBLE); - tvRegisterTip.setText(tip); + binding.tvRegisterTip.setVisibility(View.VISIBLE); + binding.tvRegisterTip.setText(tip); } public void checkNotNone(){ if ("".equals(username) || "".equals(password) || "".equals(rpPassword) || "".equals(inputCode)){ - btRegister.setEnabled(false); + binding.btRegister.setEnabled(false); }else { - btRegister.setEnabled(true); + binding.btRegister.setEnabled(true); } } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/RuleActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/RuleActivity.java index 9bb890c..b07b9cb 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/RuleActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/RuleActivity.java @@ -11,12 +11,10 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; import java.util.List; -import butterknife.BindView; import io.reactivex.Observable; import io.reactivex.annotations.NonNull; import xyz.fycz.myreader.R; @@ -24,6 +22,7 @@ import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.observer.MyObserver; import xyz.fycz.myreader.base.observer.MySingleObserver; import xyz.fycz.myreader.common.APPCONST; +import xyz.fycz.myreader.databinding.ActivityRuleBinding; import xyz.fycz.myreader.greendao.entity.ReplaceRuleBean; import xyz.fycz.myreader.model.ReplaceRuleManager; import xyz.fycz.myreader.ui.adapter.ReplaceRuleAdapter; @@ -45,15 +44,16 @@ import static xyz.fycz.myreader.util.UriFileUtil.getPath; * @date 2021/1/19 10:02 */ public class RuleActivity extends BaseActivity { - @BindView(R.id.rv_rule_list) - RecyclerView rvRuleList; + + private ActivityRuleBinding binding; private List mReplaceRules; private ReplaceRuleAdapter mAdapter; @Override - protected int getContentId() { - return R.layout.activity_rule; + protected void bindView() { + binding = ActivityRuleBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -95,10 +95,10 @@ public class RuleActivity extends BaseActivity { mAdapter.notifyItemRangeChanged(which, mReplaceRules.size() - which); setUpBarTitle(); }); - rvRuleList.setLayoutManager(new LinearLayoutManager(this)); - rvRuleList.setAdapter(mAdapter); + binding.rvRuleList.setLayoutManager(new LinearLayoutManager(this)); + binding.rvRuleList.setAdapter(mAdapter); //设置分割线 - rvRuleList.addItemDecoration(new DividerItemDecoration(this)); + binding.rvRuleList.addItemDecoration(new DividerItemDecoration(this)); mAdapter.refreshItems(mReplaceRules); } @@ -106,7 +106,7 @@ public class RuleActivity extends BaseActivity { @Override protected void initClick() { super.initClick(); - rvRuleList.setOnTouchListener((v, event) -> { + binding.rvRuleList.setOnTouchListener((v, event) -> { if (event.getAction() == MotionEvent.ACTION_UP) { SwipeMenuLayout viewCache = SwipeMenuLayout.getViewCache(); if (null != viewCache) { diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchBookActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchBookActivity.java index 629ff60..e74dc8f 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchBookActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchBookActivity.java @@ -15,97 +15,52 @@ import android.view.MenuItem; import android.view.View; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; -import android.widget.*; import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.widget.AppCompatRadioButton; import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; - -import com.google.android.material.floatingactionbutton.FloatingActionButton; -import com.scwang.smartrefresh.layout.SmartRefreshLayout; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; -import me.gujun.android.taggroup.TagGroup; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.base.BaseActivity; -import xyz.fycz.myreader.entity.Setting; -import xyz.fycz.myreader.enums.BookSource; -import xyz.fycz.myreader.ui.dialog.DialogCreator; -import xyz.fycz.myreader.ui.dialog.MultiChoiceDialog; -import xyz.fycz.myreader.util.SharedPreUtils; -import xyz.fycz.myreader.util.utils.StringUtils; -import xyz.fycz.myreader.webapi.callback.ResultCallback; import xyz.fycz.myreader.common.APPCONST; -import xyz.fycz.myreader.model.SearchEngine; +import xyz.fycz.myreader.databinding.ActivitySearchBookBinding; import xyz.fycz.myreader.entity.SearchBookBean; +import xyz.fycz.myreader.entity.Setting; +import xyz.fycz.myreader.enums.BookSource; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.SearchHistory; import xyz.fycz.myreader.greendao.service.SearchHistoryService; +import xyz.fycz.myreader.model.SearchEngine; import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap; import xyz.fycz.myreader.ui.adapter.SearchBookAdapter; import xyz.fycz.myreader.ui.adapter.SearchHistoryAdapter; +import xyz.fycz.myreader.ui.dialog.DialogCreator; +import xyz.fycz.myreader.ui.dialog.MultiChoiceDialog; +import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.webapi.CommonApi; -import xyz.fycz.myreader.webapi.crawler.base.ReadCrawler; +import xyz.fycz.myreader.webapi.callback.ResultCallback; import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil; -import xyz.fycz.myreader.widget.RefreshProgressBar; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; +import xyz.fycz.myreader.webapi.crawler.base.ReadCrawler; /** * @author fengyue * @date 2020/9/18 21:58 */ public class SearchBookActivity extends BaseActivity { - @BindView(R.id.et_search_key) - EditText etSearchKey; - @BindView(R.id.tv_search_conform) - TextView tvSearchConform; - @BindView(R.id.ll_refresh_suggest_books) - LinearLayout llRefreshSuggestBooks; - @BindView(R.id.rv_search_books_list) - RecyclerView rvSearchBooksList; - @BindView(R.id.ll_suggest_books_view) - LinearLayout llSuggestBooksView; - @BindView(R.id.rpb) - RefreshProgressBar rpb; - @BindView(R.id.lv_history_list) - ListView lvHistoryList; - @BindView(R.id.ll_clear_history) - LinearLayout llClearHistory; - @BindView(R.id.ll_history_view) - LinearLayout llHistoryView; - @BindView(R.id.tg_suggest_book) - TagGroup tgSuggestBook; - @BindView(R.id.renew_image) - ImageView renewByImage; - @BindView(R.id.renew_text) - TextView renewByText; - @BindView(R.id.srl_search_book_list) - SmartRefreshLayout srlSearchBookList; - @BindView(R.id.fabSearchStop) - FloatingActionButton fabSearchStop; - @BindView(R.id.rg_search_filter) - RadioGroup rbSearchFilter; - @BindView(R.id.rb_all_search) - AppCompatRadioButton rbAllSearch; - @BindView(R.id.rb_fuzzy_search) - AppCompatRadioButton rbFuzzySearch; - @BindView(R.id.rb_precise_search) - AppCompatRadioButton rbPreciseSearch; + private ActivitySearchBookBinding binding; private SearchBookAdapter mSearchBookAdapter; private String searchKey;//搜索关键字 @@ -146,15 +101,13 @@ public class SearchBookActivity extends BaseActivity { search(); break; case 2: - if (srlSearchBookList != null) { - srlSearchBookList.finishRefresh(); - } + binding.srlSearchBookList.finishRefresh(); /*if (curThreadCount == 0 && !isStopSearch) { rpb.setIsAutoLoading(false); }*/ break; case 3: - fabSearchStop.setVisibility(View.GONE); + binding.fabSearchStop.setVisibility(View.GONE); break; } } @@ -162,8 +115,9 @@ public class SearchBookActivity extends BaseActivity { @Override - protected int getContentId() { - return R.layout.activity_search_book; + protected void bindView() { + binding = ActivitySearchBookBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -184,10 +138,8 @@ public class SearchBookActivity extends BaseActivity { searchEngine.setOnSearchListener(new SearchEngine.OnSearchListener() { @Override public void loadMoreFinish(Boolean isAll) { - if (rpb != null) { - rpb.setIsAutoLoading(false); - } - fabSearchStop.setVisibility(View.GONE); + binding.rpb.setIsAutoLoading(false); + binding.fabSearchStop.setVisibility(View.GONE); } @Override @@ -214,9 +166,9 @@ public class SearchBookActivity extends BaseActivity { @Override protected void initWidget() { super.initWidget(); - etSearchKey.requestFocus();//get the focus + binding.etSearchKey.requestFocus();//get the focus //enter事件 - etSearchKey.setOnEditorActionListener((textView, i, keyEvent) -> { + binding.etSearchKey.setOnEditorActionListener((textView, i, keyEvent) -> { if (i == EditorInfo.IME_ACTION_UNSPECIFIED) { mHandler.sendMessage(mHandler.obtainMessage(1)); return (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER); @@ -226,20 +178,20 @@ public class SearchBookActivity extends BaseActivity { switch (mSetting.getSearchFilter()) { case 0: - rbAllSearch.setChecked(true); + binding.rbAllSearch.setChecked(true); break; case 1: default: - rbFuzzySearch.setChecked(true); + binding.rbFuzzySearch.setChecked(true); break; case 2: - rbPreciseSearch.setChecked(true); + binding.rbPreciseSearch.setChecked(true); break; } - rbSearchFilter.setOnCheckedChangeListener((group, checkedId) -> { + binding.rgSearchFilter.setOnCheckedChangeListener((group, checkedId) -> { int searchFilter; - switch (checkedId){ + switch (checkedId) { case R.id.rb_all_search: default: searchFilter = 0; @@ -256,7 +208,7 @@ public class SearchBookActivity extends BaseActivity { }); //搜索框改变事件 - etSearchKey.addTextChangedListener(new TextWatcher() { + binding.etSearchKey.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { @@ -279,10 +231,10 @@ public class SearchBookActivity extends BaseActivity { }); - rvSearchBooksList.setLayoutManager(new LinearLayoutManager(this)); + binding.rvSearchBooksList.setLayoutManager(new LinearLayoutManager(this)); //上拉刷新 - srlSearchBookList.setOnRefreshListener(refreshLayout -> { + binding.srlSearchBookList.setOnRefreshListener(refreshLayout -> { stopSearch(); mHandler.sendMessage(mHandler.obtainMessage(1)); }); @@ -295,31 +247,31 @@ public class SearchBookActivity extends BaseActivity { super.initClick(); //换一批点击事件 - renewByImage.setOnClickListener(new RenewSuggestionBook()); + binding.renewImage.setOnClickListener(new RenewSuggestionBook()); //换一批点击事件 - renewByText.setOnClickListener(new RenewSuggestionBook()); + binding.renewText.setOnClickListener(new RenewSuggestionBook()); //搜索按钮点击事件 - tvSearchConform.setOnClickListener(view -> mHandler.sendMessage(mHandler.obtainMessage(1))); + binding.tvSearchConform.setOnClickListener(view -> mHandler.sendMessage(mHandler.obtainMessage(1))); //suggestion搜索事件 - tgSuggestBook.setOnTagClickListener(tag -> { - etSearchKey.setText(tag); - etSearchKey.setSelection(tag.length()); + binding.tgSuggestBook.setOnTagClickListener(tag -> { + binding.etSearchKey.setText(tag); + binding.etSearchKey.setSelection(tag.length()); mHandler.sendMessage(mHandler.obtainMessage(1)); }); //历史记录搜索事件 - lvHistoryList.setOnItemClickListener((parent, view, position, id) -> { - etSearchKey.setText(mSearchHistories.get(position).getContent()); - etSearchKey.setSelection(mSearchHistories.get(position).getContent().length()); + binding.lvHistoryList.setOnItemClickListener((parent, view, position, id) -> { + binding.etSearchKey.setText(mSearchHistories.get(position).getContent()); + binding.etSearchKey.setSelection(mSearchHistories.get(position).getContent().length()); mHandler.sendMessage(mHandler.obtainMessage(1)); }); //清空历史记录 - llClearHistory.setOnClickListener(v -> { + binding.llClearHistory.setOnClickListener(v -> { mSearchHistoryService.clearHistory(); initHistoryList(); }); //清除单个历史记录 - lvHistoryList.setOnItemLongClickListener((parent, view, position, id) -> { + binding.lvHistoryList.setOnItemLongClickListener((parent, view, position, id) -> { if (mSearchHistories.get(position) != null) { mSearchHistoryService.deleteHistory(mSearchHistories.get(position)); initHistoryList(); @@ -327,7 +279,7 @@ public class SearchBookActivity extends BaseActivity { return true; }); - fabSearchStop.setOnClickListener(v -> { + binding.fabSearchStop.setOnClickListener(v -> { stopSearch(); }); } @@ -341,13 +293,13 @@ public class SearchBookActivity extends BaseActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == R.id.action_disable_source){ + if (item.getItemId() == R.id.action_disable_source) { showDisableSourceDia(); } return super.onOptionsItemSelected(item); } - private void showDisableSourceDia(){ + private void showDisableSourceDia() { if (mDisableSourceDia != null) { mDisableSourceDia.show(); return; @@ -397,17 +349,17 @@ public class SearchBookActivity extends BaseActivity { * 初始化建议书目 */ private void initSuggestionBook() { - tgSuggestBook.setTags(suggestion); + binding.tgSuggestBook.setTags(suggestion); } private class RenewSuggestionBook implements View.OnClickListener { @Override public void onClick(View v) { - String[] s = tgSuggestBook.getTags(); + String[] s = binding.tgSuggestBook.getTags(); if (Arrays.equals(s, suggestion)) { - tgSuggestBook.setTags(suggestion2); + binding.tgSuggestBook.setTags(suggestion2); } else { - tgSuggestBook.setTags(suggestion); + binding.tgSuggestBook.setTags(suggestion); } } } @@ -418,11 +370,11 @@ public class SearchBookActivity extends BaseActivity { private void initHistoryList() { mSearchHistories = mSearchHistoryService.findAllSearchHistory(); if (mSearchHistories == null || mSearchHistories.size() == 0) { - llHistoryView.setVisibility(View.GONE); + binding.llHistoryView.setVisibility(View.GONE); } else { mSearchHistoryAdapter = new SearchHistoryAdapter(this, R.layout.listview_search_history_item, mSearchHistories); - lvHistoryList.setAdapter(mSearchHistoryAdapter); - llHistoryView.setVisibility(View.VISIBLE); + binding.lvHistoryList.setAdapter(mSearchHistoryAdapter); + binding.llHistoryView.setVisibility(View.VISIBLE); } } @@ -431,9 +383,9 @@ public class SearchBookActivity extends BaseActivity { */ private void initSearchList() { //initmBooksBean(); - rvSearchBooksList.setVisibility(View.VISIBLE); - llSuggestBooksView.setVisibility(View.GONE); - llSuggestBooksView.setVisibility(View.GONE); + binding.rvSearchBooksList.setVisibility(View.VISIBLE); + binding.llSuggestBooksView.setVisibility(View.GONE); + binding.llSuggestBooksView.setVisibility(View.GONE); } @@ -448,7 +400,7 @@ public class SearchBookActivity extends BaseActivity { allThreadCount = readCrawlers.size(); if (allThreadCount == 0) { ToastUtils.showWarring("当前书源已全部禁用,无法搜索!"); - rpb.setIsAutoLoading(false); + binding.rpb.setIsAutoLoading(false); return; } curThreadCount = allThreadCount; @@ -463,39 +415,39 @@ public class SearchBookActivity extends BaseActivity { * 搜索 */ private void search() { - rpb.setIsAutoLoading(true); - fabSearchStop.setVisibility(View.VISIBLE); + binding.rpb.setIsAutoLoading(true); + binding.fabSearchStop.setVisibility(View.VISIBLE); if (StringHelper.isEmpty(searchKey)) { isStopSearch = true; stopSearch(); - rpb.setIsAutoLoading(false); - rvSearchBooksList.setVisibility(View.GONE); - llSuggestBooksView.setVisibility(View.VISIBLE); + binding.rpb.setIsAutoLoading(false); + binding.rvSearchBooksList.setVisibility(View.GONE); + binding.llSuggestBooksView.setVisibility(View.VISIBLE); initHistoryList(); - rvSearchBooksList.setAdapter(null); - srlSearchBookList.setEnableRefresh(false); + binding.rvSearchBooksList.setAdapter(null); + binding.srlSearchBookList.setEnableRefresh(false); } else { isStopSearch = false; mSearchBookAdapter = new SearchBookAdapter(mBooks, searchEngine); - rvSearchBooksList.setAdapter(mSearchBookAdapter); + binding.rvSearchBooksList.setAdapter(mSearchBookAdapter); //进入书籍详情页 mSearchBookAdapter.setOnItemClickListener((view, pos) -> { Intent intent = new Intent(this, BookDetailedActivity.class); intent.putExtra(APPCONST.SEARCH_BOOK_BEAN, new ArrayList<>(mBooks.getValues(mSearchBookAdapter.getItem(pos)))); startActivity(intent); }); - srlSearchBookList.setEnableRefresh(true); - rvSearchBooksList.setVisibility(View.VISIBLE); - llSuggestBooksView.setVisibility(View.GONE); - llHistoryView.setVisibility(View.GONE); + binding.srlSearchBookList.setEnableRefresh(true); + binding.rvSearchBooksList.setVisibility(View.VISIBLE); + binding.llSuggestBooksView.setVisibility(View.GONE); + binding.llHistoryView.setVisibility(View.GONE); getData(); mSearchHistoryService.addOrUpadteHistory(searchKey); //收起软键盘 InputMethodManager imm = (InputMethodManager) MyApplication.getmContext().getSystemService(Context.INPUT_METHOD_SERVICE); assert imm != null; - imm.hideSoftInputFromWindow(etSearchKey.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); + imm.hideSoftInputFromWindow(binding.etSearchKey.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } @@ -509,7 +461,7 @@ public class SearchBookActivity extends BaseActivity { if (StringHelper.isEmpty(searchKey)) { super.onBackPressed(); } else { - etSearchKey.setText(""); + binding.etSearchKey.setText(""); } } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java index 7d82f43..af9beee 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java @@ -5,37 +5,30 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; +import android.util.Log; + import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.AppCompatImageView; import androidx.core.app.ActivityCompat; -import android.util.Log; -import android.view.Window; -import android.view.WindowManager; - -import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.signature.ObjectKey; import com.gyf.immersionbar.ImmersionBar; -import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import butterknife.BindView; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.common.APPCONST; +import xyz.fycz.myreader.databinding.ActivitySplashBinding; import xyz.fycz.myreader.greendao.service.BookGroupService; import xyz.fycz.myreader.ui.dialog.MyAlertDialog; import xyz.fycz.myreader.util.DateHelper; import xyz.fycz.myreader.util.IOUtils; import xyz.fycz.myreader.util.PermissionsChecker; import xyz.fycz.myreader.util.SharedPreUtils; -import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.utils.ImageLoader; import xyz.fycz.myreader.util.utils.MD5Utils; @@ -52,8 +45,7 @@ public class SplashActivity extends BaseActivity { Manifest.permission.WRITE_EXTERNAL_STORAGE }; - @BindView(R.id.iv_splash) - AppCompatImageView ivSplash; + private ActivitySplashBinding binding; private PermissionsChecker mPermissionsChecker; private Thread myThread = new Thread() {//创建子线程 @@ -73,11 +65,11 @@ public class SplashActivity extends BaseActivity { @Override - protected int getContentId() { - return R.layout.activity_splash; + protected void bindView() { + binding = ActivitySplashBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -149,7 +141,7 @@ public class SplashActivity extends BaseActivity { .load(this, imgFile) .error(R.drawable.start) .signature(new ObjectKey(splashLoadDate)) - .into(ivSplash); + .into(binding.ivSplash); } } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/dialog/AudioPlayerDialog.java b/app/src/main/java/xyz/fycz/myreader/ui/dialog/AudioPlayerDialog.java index 328bfd4..e4c1413 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/dialog/AudioPlayerDialog.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/dialog/AudioPlayerDialog.java @@ -11,16 +11,13 @@ import android.view.Window; import android.view.WindowManager; import android.widget.NumberPicker; import android.widget.SeekBar; -import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.widget.AppCompatImageView; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; + import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.MyApplication; +import xyz.fycz.myreader.databinding.DialogAudioPlayerBinding; import xyz.fycz.myreader.model.audio.ReadAloudService; import xyz.fycz.myreader.ui.activity.ReadActivity; import xyz.fycz.myreader.util.SharedPreUtils; @@ -28,10 +25,11 @@ import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.utils.AudioMngHelper; import xyz.fycz.myreader.widget.page.PageLoader; -import static xyz.fycz.myreader.util.utils.StringUtils.getString; - public class AudioPlayerDialog extends Dialog{ private static final String TAG="AudioPlayerDialog"; + + private DialogAudioPlayerBinding binding; + private PageLoader mPageLoader; private ReadActivity mReadActivity; private boolean aloudNextPage; @@ -43,30 +41,6 @@ public class AudioPlayerDialog extends Dialog{ private int speechRate; private int timer; - @BindView(R.id.iv_reset_setting) - TextView tvResetSetting; - @BindView(R.id.sb_volume_progress) - SeekBar sbVolume; - @BindView(R.id.sb_pitch_progress) - SeekBar sbPitch; - @BindView(R.id.sb_speech_rate_progress) - SeekBar sbSpeechRate; - @BindView(R.id.iv_go_tts_setting) - AppCompatImageView ivGoTTSSetting; - @BindView(R.id.iv_read_last_paragraph) - AppCompatImageView ivReadLastParagraph; - @BindView(R.id.iv_read_play_stop) - AppCompatImageView ivReadPlayStop; - @BindView(R.id.iv_read_next_paragraph) - AppCompatImageView ivReadNextParagraph; - @BindView(R.id.iv_read_stop) - AppCompatImageView ivReadStop; - @BindView(R.id.iv_read_timer) - AppCompatImageView ivReadTimer; - @BindView(R.id.iv_read_home) - AppCompatImageView ivReadHome; - - public AudioPlayerDialog(@NonNull ReadActivity context, PageLoader mPageLoader) { super(context); mReadActivity = context; @@ -76,11 +50,12 @@ public class AudioPlayerDialog extends Dialog{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.diallog_audio_player); - ButterKnife.bind(this); + binding = DialogAudioPlayerBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); setUpWindow(); initData(); initWidget(); + initCLick(); readAloud(); } @@ -88,7 +63,7 @@ public class AudioPlayerDialog extends Dialog{ protected void onStart() { super.onStart(); volume = AudioMngHelper.getInstance().get100CurrentVolume(); - sbVolume.setProgress(volume); + binding.sbVolumeProgress.setProgress(volume); if (!ReadAloudService.running){ readAloud(); } @@ -115,18 +90,18 @@ public class AudioPlayerDialog extends Dialog{ } private void initWidget() { - sbVolume.setProgress(volume); - sbPitch.setProgress(pitch); - sbSpeechRate.setProgress(speechRate); + binding.sbVolumeProgress.setProgress(volume); + binding.sbPitchProgress.setProgress(pitch); + binding.sbSpeechRateProgress.setProgress(speechRate); SeekBarChangeListener seekBarChangeListener = new SeekBarChangeListener(); - sbVolume.setOnSeekBarChangeListener(seekBarChangeListener); - sbPitch.setOnSeekBarChangeListener(seekBarChangeListener); - sbSpeechRate.setOnSeekBarChangeListener(seekBarChangeListener); - tvResetSetting.setOnClickListener(v ->{ + binding.sbVolumeProgress.setOnSeekBarChangeListener(seekBarChangeListener); + binding.sbPitchProgress.setOnSeekBarChangeListener(seekBarChangeListener); + binding.sbSpeechRateProgress.setOnSeekBarChangeListener(seekBarChangeListener); + binding.ivResetSetting.setOnClickListener(v ->{ pitch = 10; speechRate = 10; - sbPitch.setProgress(pitch); - sbSpeechRate.setProgress(speechRate); + binding.sbPitchProgress.setProgress(pitch); + binding.sbSpeechRateProgress.setProgress(speechRate); SharedPreUtils.getInstance().putInt("readPitch", pitch); SharedPreUtils.getInstance().putInt("speechRate", speechRate); if (ReadAloudService.running) { @@ -136,6 +111,65 @@ public class AudioPlayerDialog extends Dialog{ }); } + private void initCLick() { + binding.ivReadPlayStop.setOnClickListener(this::onClick); + binding.ivReadLastParagraph.setOnClickListener(this::onClick); + binding.ivReadNextParagraph.setOnClickListener(this::onClick); + binding.ivGoTtsSetting.setOnClickListener(this::onClick); + binding.ivReadStop.setOnClickListener(this::onClick); + binding.ivReadTimer.setOnClickListener(this::onClick); + binding.ivReadHome.setOnClickListener(this::onClick); + } + + public void onClick(View view){ + int id = view.getId(); + if (id == R.id.iv_go_tts_setting) { + ReadAloudService.toTTSSetting(mReadActivity); + } else if (id == R.id.iv_read_play_stop) { + if (ReadAloudService.running) { + if (aloudStatus == ReadAloudService.Status.PLAY) { + ReadAloudService.pause(mReadActivity); + } else { + ReadAloudService.resume(mReadActivity); + } + } else { + readAloud(); + } + } else if (id == R.id.iv_read_last_paragraph) { + ReadAloudService.lastP(mReadActivity); + } else if (id == R.id.iv_read_next_paragraph) { + ReadAloudService.nextP(mReadActivity); + } else if (id == R.id.iv_read_timer) { + View timer = LayoutInflater.from(getContext()).inflate(R.layout.dialog_hour_minute_picker, null, false); + NumberPicker hourPicker = timer.findViewById(R.id.hour_picker); + int hour = this.timer / 60; + int minute = this.timer % 60; + hourPicker.setMaxValue(5); + hourPicker.setMinValue(0); + hourPicker.setValue(hour); + NumberPicker minutePicker = timer.findViewById(R.id.minute_picker); + minutePicker.setMaxValue(59); + minutePicker.setMinValue(0); + minutePicker.setValue(minute); + MyAlertDialog.build(mReadActivity) + .setTitle("定时停止") + .setView(timer) + .setPositiveButton("确定", (dialog, which) -> { + this.timer = hourPicker.getValue() * 60 + minutePicker.getValue(); + SharedPreUtils.getInstance().putInt("timer", this.timer); + ReadAloudService.setTimer(mReadActivity, this.timer); + ToastUtils.showInfo("朗读将在" + hourPicker.getValue() + "时" + minutePicker.getValue() + "分钟后停止!"); + }).setNegativeButton("取消", null) + .show(); + } else if (id == R.id.iv_read_stop) { + ReadAloudService.stop(mReadActivity); + dismiss(); + } else if (id == R.id.iv_read_home) { + dismiss(); + mReadActivity.toggleMenu(true, true); + } + } + private class SeekBarChangeListener implements SeekBar.OnSeekBarChangeListener{ @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { @@ -150,24 +184,21 @@ public class AudioPlayerDialog extends Dialog{ @Override public void onStopTrackingTouch(SeekBar seekBar) { int progress = seekBar.getProgress(); - switch (seekBar.getId()){ - case R.id.sb_volume_progress: - AudioMngHelper.getInstance().setVoice100(progress); - break; - case R.id.sb_pitch_progress: - SharedPreUtils.getInstance().putInt("readPitch", progress); - if (ReadAloudService.running) { - ReadAloudService.pause(mReadActivity); - ReadAloudService.resume(mReadActivity); - } - break; - case R.id.sb_speech_rate_progress: - SharedPreUtils.getInstance().putInt("speechRate", progress); - if (ReadAloudService.running) { - ReadAloudService.pause(mReadActivity); - ReadAloudService.resume(mReadActivity); - } - break; + int id = seekBar.getId(); + if (id == R.id.sb_volume_progress) { + AudioMngHelper.getInstance().setVoice100(progress); + } else if (id == R.id.sb_pitch_progress) { + SharedPreUtils.getInstance().putInt("readPitch", progress); + if (ReadAloudService.running) { + ReadAloudService.pause(mReadActivity); + ReadAloudService.resume(mReadActivity); + } + } else if (id == R.id.sb_speech_rate_progress) { + SharedPreUtils.getInstance().putInt("speechRate", progress); + if (ReadAloudService.running) { + ReadAloudService.pause(mReadActivity); + ReadAloudService.resume(mReadActivity); + } } } } @@ -187,66 +218,6 @@ public class AudioPlayerDialog extends Dialog{ window.getDecorView().setBackgroundColor(getContext().getResources().getColor(R.color.read_menu_bg)); } - @OnClick({R.id.iv_read_play_stop, R.id.iv_read_last_paragraph, - R.id.iv_read_next_paragraph, R.id.iv_go_tts_setting, - R.id.iv_read_stop, R.id.iv_read_timer, R.id.iv_read_home}) - public void onClick(View view){ - //Log.d("onClick", String.valueOf(view.getId())); - switch (view.getId()){ - case R.id.iv_go_tts_setting: - ReadAloudService.toTTSSetting(mReadActivity); - break; - case R.id.iv_read_play_stop: - if (ReadAloudService.running) { - if (aloudStatus == ReadAloudService.Status.PLAY) { - ReadAloudService.pause(mReadActivity); - } else { - ReadAloudService.resume(mReadActivity); - } - }else { - readAloud(); - } - break; - case R.id.iv_read_last_paragraph: - ReadAloudService.lastP(mReadActivity); - break; - case R.id.iv_read_next_paragraph: - ReadAloudService.nextP(mReadActivity); - break; - case R.id.iv_read_timer: - View timer = LayoutInflater.from(getContext()).inflate(R.layout.dialog_hour_minute_picker, null, false); - NumberPicker hourPicker = timer.findViewById(R.id.hour_picker); - int hour = this.timer / 60; - int minute = this.timer % 60; - hourPicker.setMaxValue(5); - hourPicker.setMinValue(0); - hourPicker.setValue(hour); - NumberPicker minutePicker = timer.findViewById(R.id.minute_picker); - minutePicker.setMaxValue(59); - minutePicker.setMinValue(0); - minutePicker.setValue(minute); - MyAlertDialog.build(mReadActivity) - .setTitle("定时停止") - .setView(timer) - .setPositiveButton("确定", (dialog, which) -> { - this.timer = hourPicker.getValue() * 60 + minutePicker.getValue(); - SharedPreUtils.getInstance().putInt("timer", this.timer); - ReadAloudService.setTimer(mReadActivity, this.timer); - ToastUtils.showInfo("朗读将在" + hourPicker.getValue() + "时" + minutePicker.getValue() + "分钟后停止!"); - }).setNegativeButton("取消", null) - .show(); - break; - case R.id.iv_read_stop: - ReadAloudService.stop(mReadActivity); - dismiss(); - break; - case R.id.iv_read_home: - dismiss(); - mReadActivity.toggleMenu(true, true); - break; - } - } - public void readAloud() { mPageLoader.resetReadAloudParagraph(); @@ -261,7 +232,7 @@ public class AudioPlayerDialog extends Dialog{ public boolean addOrSubVolume(boolean isAdd){ volume = isAdd ? AudioMngHelper.getInstance().addVoice100() : AudioMngHelper.getInstance().subVoice100(); - sbVolume.setProgress(volume); + binding.sbVolumeProgress.setProgress(volume); return true; } @@ -305,13 +276,13 @@ public class AudioPlayerDialog extends Dialog{ } break; case PLAY: - ivReadPlayStop.setImageResource(R.drawable.ic_stop); + binding.ivReadPlayStop.setImageResource(R.drawable.ic_stop); break; case PAUSE: - ivReadPlayStop.setImageResource(R.drawable.ic_play); + binding.ivReadPlayStop.setImageResource(R.drawable.ic_play); break; default: - ivReadPlayStop.setImageResource(R.drawable.ic_play); + binding.ivReadPlayStop.setImageResource(R.drawable.ic_play); mPageLoader.skipToPage(mPageLoader.getPagePos()); } } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/dialog/CopyContentDialog.java b/app/src/main/java/xyz/fycz/myreader/ui/dialog/CopyContentDialog.java index d1f0299..1cdfda5 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/dialog/CopyContentDialog.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/dialog/CopyContentDialog.java @@ -6,11 +6,10 @@ import android.os.Bundle; import android.view.Gravity; import android.view.Window; import android.view.WindowManager; -import android.widget.TextView; + import androidx.annotation.NonNull; -import butterknife.BindView; -import butterknife.ButterKnife; -import xyz.fycz.myreader.R; + +import xyz.fycz.myreader.databinding.DialogCopyContentBinding; /** * Created by Zhouas666 on 2019-04-14 @@ -23,8 +22,7 @@ public class CopyContentDialog extends Dialog { private static final String TAG = "CopyContentDialog"; - @BindView(R.id.dialog_tv_content) - TextView dialogTvContent; + private DialogCopyContentBinding binding; private String content; @@ -39,12 +37,12 @@ public class CopyContentDialog extends Dialog { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.dialog_copy_content); - ButterKnife.bind(this); + binding = DialogCopyContentBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); setUpWindow(); - dialogTvContent.setText(content); + binding.dialogTvContent.setText(content); } /** diff --git a/app/src/main/java/xyz/fycz/myreader/ui/dialog/SourceExchangeDialog.java b/app/src/main/java/xyz/fycz/myreader/ui/dialog/SourceExchangeDialog.java index 07594a4..8b6ca8a 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/dialog/SourceExchangeDialog.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/dialog/SourceExchangeDialog.java @@ -7,16 +7,15 @@ import android.view.Gravity; import android.view.View; import android.view.Window; import android.view.WindowManager; -import android.widget.TextView; + import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.widget.AppCompatImageView; -import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import butterknife.ButterKnife; -import xyz.fycz.myreader.R; + +import java.util.ArrayList; +import java.util.List; + +import xyz.fycz.myreader.databinding.DialogBookSourceBinding; import xyz.fycz.myreader.entity.SearchBookBean; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.model.SearchEngine; @@ -25,10 +24,6 @@ import xyz.fycz.myreader.ui.adapter.SourceExchangeAdapter; import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil; import xyz.fycz.myreader.widget.RefreshProgressBar; - -import java.util.ArrayList; -import java.util.List; - /** * 换源dialog */ @@ -36,18 +31,8 @@ import java.util.List; public class SourceExchangeDialog extends Dialog { private static final String TAG = "SourceExchangeDialog"; - /*@BindView(R.id.dialog_tv_title) - TextView dialogTvTitle;*/ - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.iv_refresh_search) - AppCompatImageView ivRefreshSearch; - @BindView(R.id.iv_stop_search) - AppCompatImageView ivStopSearch; - @BindView(R.id.rpb) - RefreshProgressBar rpb; - @BindView(R.id.dialog_rv_content) - RecyclerView dialogRvContent; + + private DialogBookSourceBinding binding; private SearchEngine searchEngine; private SourceExchangeAdapter mAdapter; @@ -90,8 +75,8 @@ public class SourceExchangeDialog extends Dialog { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.dialog_book_source); - ButterKnife.bind(this); + binding = DialogBookSourceBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); setUpWindow(); initData(); initClick(); @@ -103,8 +88,8 @@ public class SourceExchangeDialog extends Dialog { //执行业务逻辑 if (aBooks.size() == 0) { searchEngine.search(mShelfBook.getName(), mShelfBook.getAuthor()); - ivStopSearch.setVisibility(View.VISIBLE); - rpb.setIsAutoLoading(true); + binding.ivStopSearch.setVisibility(View.VISIBLE); + binding.rpb.setIsAutoLoading(true); }else { if (mAdapter.getItemCount() == 0) { mAdapter.addItems(aBooks); @@ -128,8 +113,8 @@ public class SourceExchangeDialog extends Dialog { * 初始化数据 */ private void initData() { - toolbar.setTitle(mShelfBook.getName()); - toolbar.setSubtitle(mShelfBook.getAuthor()); + binding.it.toolbar.setTitle(mShelfBook.getName()); + binding.it.toolbar.setSubtitle(mShelfBook.getAuthor()); //dialogTvTitle.setText(mShelfBook.getName() + "(" + mShelfBook.getAuthor() + ")"); if (aBooks == null) { @@ -137,8 +122,8 @@ public class SourceExchangeDialog extends Dialog { } mAdapter = new SourceExchangeAdapter(); - dialogRvContent.setLayoutManager(new LinearLayoutManager(mActivity)); - dialogRvContent.setAdapter(mAdapter); + binding.dialogRvContent.setLayoutManager(new LinearLayoutManager(mActivity)); + binding.dialogRvContent.setAdapter(mAdapter); searchEngine = new SearchEngine(); searchEngine.initSearchEngine(ReadCrawlerUtil.getReadCrawlers()); @@ -149,8 +134,8 @@ public class SourceExchangeDialog extends Dialog { @Override public void loadMoreFinish(Boolean isAll) { synchronized (RefreshProgressBar.class) { - rpb.setIsAutoLoading(false); - ivStopSearch.setVisibility(View.GONE); + binding.rpb.setIsAutoLoading(false); + binding.ivStopSearch.setVisibility(View.GONE); } } @@ -199,10 +184,10 @@ public class SourceExchangeDialog extends Dialog { dismiss(); }); - ivStopSearch.setOnClickListener(v -> searchEngine.stopSearch()); - ivRefreshSearch.setOnClickListener(v -> { + binding.ivStopSearch.setOnClickListener(v -> searchEngine.stopSearch()); + binding.ivRefreshSearch.setOnClickListener(v -> { searchEngine.stopSearch(); - ivStopSearch.setVisibility(View.VISIBLE); + binding.ivStopSearch.setVisibility(View.VISIBLE); mAdapter.clear(); aBooks.clear(); mAdapter.notifyDataSetChanged(); diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/BookMarkFragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/BookMarkFragment.java index 666c911..c34fa88 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/BookMarkFragment.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/fragment/BookMarkFragment.java @@ -5,22 +5,19 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ListView; + import androidx.fragment.app.Fragment; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; -import xyz.fycz.myreader.R; + +import xyz.fycz.myreader.databinding.FragmentBookmarkBinding; import xyz.fycz.myreader.ui.presenter.BookMarkPresenter; /** * A simple {@link Fragment} subclass. */ public class BookMarkFragment extends Fragment { - @BindView(R.id.lv_bookmark_list) - ListView lvBookmarkList; + private FragmentBookmarkBinding binding; private BookMarkPresenter mBookMarkPresenter; - Unbinder unbinder; public BookMarkFragment() { @@ -31,21 +28,19 @@ public class BookMarkFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View view = inflater.inflate(R.layout.fragment_bookmark, container, false); - unbinder = ButterKnife.bind(this, view); + binding = FragmentBookmarkBinding.inflate(inflater, container, false); mBookMarkPresenter = new BookMarkPresenter(this); mBookMarkPresenter.start(); - return view; + return binding.getRoot(); } @Override public void onDestroyView() { super.onDestroyView(); - unbinder.unbind(); } public ListView getLvBookmarkList() { - return lvBookmarkList; + return binding.lvBookmarkList; } public BookMarkPresenter getmBookMarkPresenter() { diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/BookStoreFragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/BookStoreFragment.java deleted file mode 100644 index 6797dd3..0000000 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/BookStoreFragment.java +++ /dev/null @@ -1,84 +0,0 @@ -package xyz.fycz.myreader.ui.fragment; - - -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ProgressBar; -import androidx.fragment.app.Fragment; -import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; -import com.scwang.smartrefresh.layout.SmartRefreshLayout; -import xyz.fycz.myreader.R; -import xyz.fycz.myreader.ui.presenter.BookStorePresenter; -import xyz.fycz.myreader.widget.RefreshLayout; - -/** - * A simple {@link Fragment} subclass. - */ -public class BookStoreFragment extends Fragment { - @BindView(R.id.refresh_layout) - RefreshLayout mRlRefresh; - @BindView(R.id.rv_type_list) - RecyclerView rvTypeList; - @BindView(R.id.rv_book_list) - RecyclerView rvBookList; - @BindView(R.id.srl_book_list) - SmartRefreshLayout srlBookList; - @BindView(R.id.pb_loading) - ProgressBar pbLoading; - - Unbinder unbinder; - private BookStorePresenter mBookStorePresenter; - private boolean isFirstInit; - - public BookStoreFragment() { - // Required empty public constructor - } - - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - // Inflate the layout for this fragment - View view = inflater.inflate(R.layout.fragment_book_store, container, false); - unbinder = ButterKnife.bind(this, view); - /*mBookStorePresenter = new BookStorePresenter(this); - mBookStorePresenter.start();*/ - isFirstInit = true; - return view; - - } - - - public void lazyLoad() { - if (isFirstInit) { - mBookStorePresenter = new BookStorePresenter(this); - mBookStorePresenter.start(); - isFirstInit = false; - } - } - - public RecyclerView getRvTypeList() { - return rvTypeList; - } - - public RecyclerView getRvBookList() { - return rvBookList; - } - - public SmartRefreshLayout getSrlBookList() { - return srlBookList; - } - - public ProgressBar getPbLoading() { - return pbLoading; - } - - public RefreshLayout getmRlRefresh() { - return mRlRefresh; - } -} diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/BookcaseFragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/BookcaseFragment.java index 320cad3..dca7061 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/BookcaseFragment.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/fragment/BookcaseFragment.java @@ -6,46 +6,27 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.*; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.LinearLayout; +import android.widget.ProgressBar; +import android.widget.RelativeLayout; +import android.widget.TextView; import androidx.fragment.app.Fragment; + import com.scwang.smartrefresh.layout.SmartRefreshLayout; -import xyz.fycz.myreader.R; -import xyz.fycz.myreader.widget.custom.DragSortGridView; -import butterknife.ButterKnife; -import butterknife.BindView; -import butterknife.Unbinder; +import xyz.fycz.myreader.databinding.FragmentBookcaseBinding; import xyz.fycz.myreader.ui.presenter.BookcasePresenter; +import xyz.fycz.myreader.widget.custom.DragSortGridView; /** * A simple {@link Fragment} subclass. */ public class BookcaseFragment extends Fragment { - @BindView(R.id.srl_content) - SmartRefreshLayout srlContent; - @BindView(R.id.ll_no_data_tips) - LinearLayout llNoDataTips; - @BindView(R.id.gv_book) - DragSortGridView gvBook; - @BindView(R.id.rl_download_tip) - RelativeLayout rlDownloadTip; - @BindView(R.id.tv_download_tip) - TextView tvDownloadTip; - @BindView(R.id.tv_stop_download) - TextView tvStopDownload; - @BindView(R.id.pb_download) - ProgressBar pbDownload; - @BindView(R.id.rl_book_edit) - RelativeLayout rlBookEdit; - @BindView(R.id.book_selected_all) - CheckBox mCbSelectAll; - @BindView(R.id.book_btn_delete) - Button mBtnDelete; - @BindView(R.id.book_add_group) - Button mBtnAddGroup; - - Unbinder unbinder; + + private FragmentBookcaseBinding binding; private BookcasePresenter mBookcasePresenter; @@ -58,17 +39,15 @@ public class BookcaseFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View view = inflater.inflate(R.layout.fragment_bookcase, container, false); - unbinder = ButterKnife.bind(this, view); + binding = FragmentBookcaseBinding.inflate(inflater, container, false); mBookcasePresenter = new BookcasePresenter(this); mBookcasePresenter.start(); - return view; + return binding.getRoot(); } @Override public void onDestroyView() { super.onDestroyView(); - unbinder.unbind(); mBookcasePresenter.destroy(); } @@ -83,31 +62,31 @@ public class BookcaseFragment extends Fragment { } public LinearLayout getLlNoDataTips() { - return llNoDataTips; + return binding.llNoDataTips; } public DragSortGridView getGvBook() { - return gvBook; + return binding.gvBook; } public SmartRefreshLayout getSrlContent() { - return srlContent; + return binding.srlContent; } public RelativeLayout getRlDownloadTip() { - return rlDownloadTip; + return binding.rlDownloadTip; } public TextView getTvDownloadTip() { - return tvDownloadTip; + return binding.tvDownloadTip; } public TextView getTvStopDownload() { - return tvStopDownload; + return binding.tvStopDownload; } public ProgressBar getPbDownload() { - return pbDownload; + return binding.pbDownload; } public BookcasePresenter getmBookcasePresenter() { @@ -115,22 +94,22 @@ public class BookcaseFragment extends Fragment { } public boolean isRecreate() { - return unbinder == null; + return binding == null; } public RelativeLayout getRlBookEdit() { - return rlBookEdit; + return binding.rlBookEdit; } public CheckBox getmCbSelectAll() { - return mCbSelectAll; + return binding.bookSelectedAll; } public Button getmBtnDelete() { - return mBtnDelete; + return binding.bookBtnDelete; } public Button getmBtnAddGroup() { - return mBtnAddGroup; + return binding.bookAddGroup; } } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/CatalogFragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/CatalogFragment.java index 8c4e3db..6987665 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/CatalogFragment.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/fragment/CatalogFragment.java @@ -7,28 +7,20 @@ import android.view.ViewGroup; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.RelativeLayout; + import androidx.fragment.app.Fragment; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; + import com.google.android.material.floatingactionbutton.FloatingActionButton; -import xyz.fycz.myreader.R; + +import xyz.fycz.myreader.databinding.FragmentCatalogBinding; import xyz.fycz.myreader.ui.presenter.CatalogPresenter; /** * A simple {@link Fragment} subclass. */ public class CatalogFragment extends Fragment { - @BindView(R.id.rl_catalog) - RelativeLayout rlCatalog; - @BindView(R.id.lv_chapter_list) - ListView lvChapterList; - @BindView(R.id.change_sort) - FloatingActionButton fcChangeSort; - @BindView(R.id.pb_loading) - ProgressBar pbLoading; - Unbinder unbinder; + private FragmentCatalogBinding binding; private CatalogPresenter mCatalogPresent; @@ -40,29 +32,27 @@ public class CatalogFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View view = inflater.inflate(R.layout.fragment_catalog, container, false); - unbinder = ButterKnife.bind(this, view); + binding = FragmentCatalogBinding.inflate(inflater, container, false); mCatalogPresent = new CatalogPresenter(this); mCatalogPresent.start(); - return view; + return binding.getRoot(); } @Override public void onDestroyView() { super.onDestroyView(); - unbinder.unbind(); } public RelativeLayout getRlCatalog() { - return rlCatalog; + return binding.rlCatalog; } public ListView getLvChapterList() { - return lvChapterList; + return binding.lvChapterList; } public FloatingActionButton getFcChangeSort() { - return fcChangeSort; + return binding.changeSort; } public CatalogPresenter getmCatalogPresent() { @@ -70,6 +60,6 @@ public class CatalogFragment extends Fragment { } public ProgressBar getPbLoading() { - return pbLoading; + return binding.pbLoading; } } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/FileCategoryFragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/FileCategoryFragment.java index 5d4aeec..60c3a27 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/FileCategoryFragment.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/fragment/FileCategoryFragment.java @@ -2,23 +2,30 @@ package xyz.fycz.myreader.ui.fragment; import android.os.Bundle; import android.os.Environment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; -import android.widget.TextView; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; + +import java.io.File; +import java.io.FileFilter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Set; + import xyz.fycz.myreader.R; +import xyz.fycz.myreader.databinding.FragmentFileCategoryBinding; import xyz.fycz.myreader.greendao.service.BookService; import xyz.fycz.myreader.ui.adapter.FileSystemAdapter; import xyz.fycz.myreader.util.FileStack; import xyz.fycz.myreader.util.utils.FileUtils; import xyz.fycz.myreader.widget.DividerItemDecoration; - -import java.io.File; -import java.io.FileFilter; -import java.util.*; - /** * @author fengyue * @date 2020/8/12 20:02 @@ -26,17 +33,15 @@ import java.util.*; public class FileCategoryFragment extends BaseFileFragment { private static final String TAG = "FileCategoryFragment"; - @BindView(R.id.file_category_tv_path) - TextView mTvPath; - @BindView(R.id.file_category_tv_back_last) - TextView mTvBackLast; - @BindView(R.id.file_category_rv_content) - RecyclerView mRvContent; + + private FragmentFileCategoryBinding binding; private FileStack mFileStack; + @Override - protected int getContentId() { - return R.layout.fragment_file_category; + protected View bindView(LayoutInflater inflater, ViewGroup container) { + binding = FragmentFileCategoryBinding.inflate(inflater, container, false); + return binding.getRoot(); } @Override @@ -48,9 +53,9 @@ public class FileCategoryFragment extends BaseFileFragment { private void setUpAdapter(){ mAdapter = new FileSystemAdapter(); - mRvContent.setLayoutManager(new LinearLayoutManager(getContext())); - mRvContent.addItemDecoration(new DividerItemDecoration(getContext())); - mRvContent.setAdapter(mAdapter); + binding.fileCategoryRvContent.setLayoutManager(new LinearLayoutManager(getContext())); + binding.fileCategoryRvContent.addItemDecoration(new DividerItemDecoration(getContext())); + binding.fileCategoryRvContent.setAdapter(mAdapter); } @Override @@ -62,9 +67,9 @@ public class FileCategoryFragment extends BaseFileFragment { if (file.isDirectory()){ //保存当前信息。 FileStack.FileSnapshot snapshot = new FileStack.FileSnapshot(); - snapshot.filePath = mTvPath.getText().toString(); + snapshot.filePath = binding.fileCategoryTvPath.getText().toString(); snapshot.files = new ArrayList<>(mAdapter.getItems()); - snapshot.scrollOffset = mRvContent.computeVerticalScrollOffset(); + snapshot.scrollOffset = binding.fileCategoryRvContent.computeVerticalScrollOffset(); mFileStack.push(snapshot); //切换下一个文件 toggleFileTree(file); @@ -86,16 +91,16 @@ public class FileCategoryFragment extends BaseFileFragment { } ); - mTvBackLast.setOnClickListener(v -> backLast()); + binding.fileCategoryTvBackLast.setOnClickListener(v -> backLast()); } public boolean backLast(){ FileStack.FileSnapshot snapshot = mFileStack.pop(); - int oldScrollOffset = mRvContent.computeHorizontalScrollOffset(); + int oldScrollOffset = binding.fileCategoryRvContent.computeHorizontalScrollOffset(); if (snapshot == null) return false; - mTvPath.setText(snapshot.filePath); + binding.fileCategoryTvPath.setText(snapshot.filePath); mAdapter.refreshItems(snapshot.files); - mRvContent.scrollBy(0,snapshot.scrollOffset - oldScrollOffset); + binding.fileCategoryRvContent.scrollBy(0,snapshot.scrollOffset - oldScrollOffset); //反馈 if (mListener != null){ mListener.onCategoryChanged(); @@ -112,7 +117,7 @@ public class FileCategoryFragment extends BaseFileFragment { private void toggleFileTree(File file){ //路径名 - mTvPath.setText(getString(R.string.file_path,file.getPath())); + binding.fileCategoryTvPath.setText(getString(R.string.file_path,file.getPath())); //获取数据 File[] files = file.listFiles(new SimpleFileFilter()); //转换成List diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/FindFragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/FindFragment.java index 431d43f..a32886a 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/FindFragment.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/fragment/FindFragment.java @@ -1,18 +1,20 @@ package xyz.fycz.myreader.ui.fragment; import android.content.Intent; -import android.widget.RelativeLayout; -import butterknife.BindView; -import xyz.fycz.myreader.R; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + import xyz.fycz.myreader.base.BaseFragment; import xyz.fycz.myreader.common.APPCONST; +import xyz.fycz.myreader.databinding.FragmentFindBinding; import xyz.fycz.myreader.ui.activity.BookstoreActivity; import xyz.fycz.myreader.webapi.crawler.base.FindCrawler; +import xyz.fycz.myreader.webapi.crawler.find.QiDianMobileRank; import xyz.fycz.myreader.webapi.crawler.find.XS7Rank; import xyz.fycz.myreader.webapi.crawler.read.Ben100ReadCrawler; import xyz.fycz.myreader.webapi.crawler.read.MiaoBiReadCrawler; import xyz.fycz.myreader.webapi.crawler.read.QB5ReadCrawler; -import xyz.fycz.myreader.webapi.crawler.find.QiDianMobileRank; import xyz.fycz.myreader.webapi.crawler.read.XS7ReadCrawler; /** @@ -20,42 +22,27 @@ import xyz.fycz.myreader.webapi.crawler.read.XS7ReadCrawler; * @date 2020/9/13 21:07 */ public class FindFragment extends BaseFragment { - @BindView(R.id.find_rl_qidian_top) - RelativeLayout mRlQiDianTop; - @BindView(R.id.find_rl_qidian_ns_top) - RelativeLayout mRlQiDianNSTop; - @BindView(R.id.find_rl_xs7_top) - RelativeLayout mRlXS7Top; - @BindView(R.id.find_rl_qidian_sort) - RelativeLayout mRlQiDianSort; - @BindView(R.id.find_rl_qidian_ns_sort) - RelativeLayout mRlQiDianNSSort; - @BindView(R.id.find_rl_qb5_store) - RelativeLayout mRlQB5Store; - @BindView(R.id.find_rl_ben100_store) - RelativeLayout mRlBen100Store; - @BindView(R.id.find_rl_miaoqu_store) - RelativeLayout mRlMiaoQuStore; - @BindView(R.id.find_rl_xs7_store) - RelativeLayout mRlXS7Store; + + private FragmentFindBinding binding; @Override - protected int getContentId() { - return R.layout.fragment_find; + protected View bindView(LayoutInflater inflater, ViewGroup container) { + binding = FragmentFindBinding.inflate(inflater, container, false); + return binding.getRoot(); } @Override protected void initClick() { super.initClick(); - mRlQiDianTop.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(false))); - mRlQiDianNSTop.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(true))); - mRlXS7Top.setOnClickListener(v -> comeToBookstore(new XS7Rank())); - mRlQiDianSort.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(false, true))); - mRlQiDianNSSort.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(true, true))); - mRlQB5Store.setOnClickListener(v -> comeToBookstore(new QB5ReadCrawler())); - mRlBen100Store.setOnClickListener(v -> comeToBookstore(new Ben100ReadCrawler())); - mRlMiaoQuStore.setOnClickListener(v -> comeToBookstore(new MiaoBiReadCrawler())); - mRlXS7Store.setOnClickListener(v -> comeToBookstore(new XS7ReadCrawler())); + binding.findRlQidianTop.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(false))); + binding.findRlQidianNsTop.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(true))); + binding.findRlXs7Top.setOnClickListener(v -> comeToBookstore(new XS7Rank())); + binding.findRlQidianSort.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(false, true))); + binding.findRlQidianNsSort.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(true, true))); + binding.findRlQb5Store.setOnClickListener(v -> comeToBookstore(new QB5ReadCrawler())); + binding.findRlBen100Store.setOnClickListener(v -> comeToBookstore(new Ben100ReadCrawler())); + binding.findRlMiaoquStore.setOnClickListener(v -> comeToBookstore(new MiaoBiReadCrawler())); + binding.findRlXs7Store.setOnClickListener(v -> comeToBookstore(new XS7ReadCrawler())); } @@ -66,6 +53,6 @@ public class FindFragment extends BaseFragment { } public boolean isRecreate() { - return unbinder == null; + return binding == null; } } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/LocalBookFragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/LocalBookFragment.java index 26c0814..a9717bb 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/LocalBookFragment.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/fragment/LocalBookFragment.java @@ -2,17 +2,18 @@ package xyz.fycz.myreader.ui.fragment; import android.media.MediaScannerConnection; import android.os.Bundle; - import android.os.Environment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import xyz.fycz.myreader.R; + +import xyz.fycz.myreader.databinding.FragmentLocalBookBinding; import xyz.fycz.myreader.greendao.service.BookService; import xyz.fycz.myreader.ui.adapter.FileSystemAdapter; import xyz.fycz.myreader.util.media.MediaStoreHelper; import xyz.fycz.myreader.widget.DividerItemDecoration; -import xyz.fycz.myreader.widget.RefreshLayout; /** @@ -22,14 +23,12 @@ import xyz.fycz.myreader.widget.RefreshLayout; */ public class LocalBookFragment extends BaseFileFragment { - @BindView(R.id.refresh_layout) - RefreshLayout mRlRefresh; - @BindView(R.id.local_book_rv_content) - RecyclerView mRvContent; + private FragmentLocalBookBinding binding; @Override - protected int getContentId() { - return R.layout.fragment_local_book; + protected View bindView(LayoutInflater inflater, ViewGroup container) { + binding = FragmentLocalBookBinding.inflate(inflater, container, false); + return binding.getRoot(); } @Override @@ -40,9 +39,9 @@ public class LocalBookFragment extends BaseFileFragment { private void setUpAdapter() { mAdapter = new FileSystemAdapter(); - mRvContent.setLayoutManager(new LinearLayoutManager(getContext())); - mRvContent.addItemDecoration(new DividerItemDecoration(getContext())); - mRvContent.setAdapter(mAdapter); + binding.localBookRvContent.setLayoutManager(new LinearLayoutManager(getContext())); + binding.localBookRvContent.addItemDecoration(new DividerItemDecoration(getContext())); + binding.localBookRvContent.setAdapter(mAdapter); } @Override @@ -80,10 +79,10 @@ public class LocalBookFragment extends BaseFileFragment { MediaStoreHelper.getAllBookFile(getActivity(), (files) -> { if (files.isEmpty()) { - mRlRefresh.showEmpty(); + binding.refreshLayout.showEmpty(); } else { mAdapter.refreshItems(files); - mRlRefresh.showFinish(); + binding.refreshLayout.showFinish(); //反馈 if (mListener != null) { mListener.onCategoryChanged(); diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/MineFragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/MineFragment.java index 37dd0b0..68d23dc 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/MineFragment.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/fragment/MineFragment.java @@ -1,43 +1,46 @@ package xyz.fycz.myreader.ui.fragment; import android.annotation.SuppressLint; -import android.content.*; +import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; -import android.widget.RelativeLayout; -import android.widget.TextView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; -import butterknife.BindView; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; + import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.application.SysManager; -import xyz.fycz.myreader.model.backup.UserService; import xyz.fycz.myreader.base.BaseFragment; import xyz.fycz.myreader.common.APPCONST; -import xyz.fycz.myreader.model.storage.Backup; -import xyz.fycz.myreader.model.storage.Restore; -import xyz.fycz.myreader.ui.activity.FeedbackActivity; -import xyz.fycz.myreader.ui.dialog.DialogCreator; -import xyz.fycz.myreader.ui.dialog.MyAlertDialog; +import xyz.fycz.myreader.databinding.FragmentMineBinding; import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.service.BookService; +import xyz.fycz.myreader.model.backup.UserService; +import xyz.fycz.myreader.model.storage.Backup; +import xyz.fycz.myreader.model.storage.Restore; import xyz.fycz.myreader.ui.activity.AboutActivity; +import xyz.fycz.myreader.ui.activity.FeedbackActivity; import xyz.fycz.myreader.ui.activity.LoginActivity; import xyz.fycz.myreader.ui.activity.MoreSettingActivity; +import xyz.fycz.myreader.ui.dialog.DialogCreator; +import xyz.fycz.myreader.ui.dialog.MyAlertDialog; import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.webapi.callback.ResultCallback; -import java.io.File; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; - import static android.app.Activity.RESULT_OK; /** @@ -45,24 +48,8 @@ import static android.app.Activity.RESULT_OK; * @date 2020/9/13 13:20 */ public class MineFragment extends BaseFragment { - @BindView(R.id.mine_rl_user) - RelativeLayout mRlUser; - @BindView(R.id.tv_user) - TextView mTvUser; - @BindView(R.id.mine_rl_backup) - RelativeLayout mRlBackup; - @BindView(R.id.mine_rl_syn) - RelativeLayout mRlSyn; - @BindView(R.id.mine_rl_setting) - RelativeLayout mRlSetting; - @BindView(R.id.mine_rl_theme_mode) - RelativeLayout mRlThemeMode; - @BindView(R.id.tv_theme_mode_select) - TextView tvThemeModeSelect; - @BindView(R.id.mine_rl_feedback) - RelativeLayout mRlFeedback; - @BindView(R.id.mine_rl_about) - RelativeLayout mRlAbout; + + private FragmentMineBinding binding; private boolean isLogin; private Setting mSetting; @@ -77,7 +64,7 @@ public class MineFragment extends BaseFragment { public void handleMessage(@NonNull Message msg) { switch (msg.what) { case 1: - mTvUser.setText("登录/注册"); + binding.tvUser.setText("登录/注册"); break; case 2: backup(); @@ -93,8 +80,9 @@ public class MineFragment extends BaseFragment { } @Override - protected int getContentId() { - return R.layout.fragment_mine; + protected View bindView(LayoutInflater inflater, ViewGroup container) { + binding = FragmentMineBinding.inflate(inflater, container, false); + return binding.getRoot(); } @Override @@ -119,15 +107,15 @@ public class MineFragment extends BaseFragment { protected void initWidget(Bundle savedInstanceState) { super.initWidget(savedInstanceState); if (isLogin) { - mTvUser.setText(UserService.readUsername()); + binding.tvUser.setText(UserService.readUsername()); } - tvThemeModeSelect.setText(themeModeArr[themeMode]); + binding.tvThemeModeSelect.setText(themeModeArr[themeMode]); } @Override protected void initClick() { super.initClick(); - mRlUser.setOnClickListener(v -> { + binding.mineRlUser.setOnClickListener(v -> { if (isLogin) { DialogCreator.createCommonDialog(getActivity(), "退出登录", "确定要退出登录吗?" , true, (dialog, which) -> { @@ -147,7 +135,7 @@ public class MineFragment extends BaseFragment { getActivity().startActivityForResult(intent, APPCONST.REQUEST_LOGIN); } }); - mRlBackup.setOnClickListener(v -> { + binding.mineRlBackup.setOnClickListener(v -> { AlertDialog bookDialog = MyAlertDialog.build(getContext()) .setTitle(getContext().getResources().getString(R.string.menu_bookcase_backup)) .setItems(backupMenu, (dialog, which) -> { @@ -165,7 +153,7 @@ public class MineFragment extends BaseFragment { .create(); bookDialog.show(); }); - mRlSyn.setOnClickListener(v -> { + binding.mineRlSyn.setOnClickListener(v -> { if (!UserService.isLogin()) { ToastUtils.showWarring("请先登录!"); Intent loginIntent = new Intent(getActivity(), LoginActivity.class); @@ -205,11 +193,11 @@ public class MineFragment extends BaseFragment { .setPositiveButton(null, null) .show(); }); - mRlSetting.setOnClickListener(v -> { + binding.mineRlSetting.setOnClickListener(v -> { Intent settingIntent = new Intent(getActivity(), MoreSettingActivity.class); startActivity(settingIntent); }); - mRlThemeMode.setOnClickListener(v -> { + binding.mineRlThemeMode.setOnClickListener(v -> { if (themeModeDia != null) { themeModeDia.show(); return; @@ -239,7 +227,7 @@ public class MineFragment extends BaseFragment { break; } dialog.dismiss(); - tvThemeModeSelect.setText(themeModeArr[themeMode]); + binding.tvThemeModeSelect.setText(themeModeArr[themeMode]); MyApplication.getApplication().initNightTheme(); }) .setNegativeButton("取消", null) @@ -248,12 +236,12 @@ public class MineFragment extends BaseFragment { }); - mRlAbout.setOnClickListener(v -> { + binding.mineRlAbout.setOnClickListener(v -> { Intent aboutIntent = new Intent(getActivity(), AboutActivity.class); startActivity(aboutIntent); }); - mRlFeedback.setOnClickListener(v -> { + binding.mineRlFeedback.setOnClickListener(v -> { Intent intent = new Intent(getContext(), FeedbackActivity.class); getActivity().startActivity(intent); }); @@ -429,7 +417,7 @@ public class MineFragment extends BaseFragment { assert data != null; isLogin = data.getBooleanExtra("isLogin", false); if (isLogin) { - mTvUser.setText(UserService.readUsername()); + binding.tvUser.setText(UserService.readUsername()); } break; } @@ -437,6 +425,6 @@ public class MineFragment extends BaseFragment { } public boolean isRecreate() { - return unbinder == null; + return binding == null; } } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/PrivateBooksFragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/PrivateBooksFragment.java index c1cddcb..5b2336a 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/PrivateBooksFragment.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/fragment/PrivateBooksFragment.java @@ -3,20 +3,19 @@ package xyz.fycz.myreader.ui.fragment; import android.content.DialogInterface; import android.os.Bundle; import android.text.InputType; +import android.view.LayoutInflater; import android.view.View; -import android.widget.LinearLayout; -import android.widget.RelativeLayout; +import android.view.ViewGroup; import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.SwitchCompat; import java.util.List; -import butterknife.BindView; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.base.BaseFragment; import xyz.fycz.myreader.common.APPCONST; +import xyz.fycz.myreader.databinding.FragmentPrivateBookcaseBinding; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.service.BookGroupService; import xyz.fycz.myreader.greendao.service.BookService; @@ -34,27 +33,16 @@ import xyz.fycz.myreader.util.utils.FingerprintUtils; * @date 2021/1/9 13:53 */ public class PrivateBooksFragment extends BaseFragment { - @BindView(R.id.rl_private_bookcase) - RelativeLayout mRlPrivateBookcase; - @BindView(R.id.sc_private_bookcase) - SwitchCompat mScPrivateBookcase; - @BindView(R.id.ll_content) - LinearLayout mLlContent; - @BindView(R.id.ll_hide_books) - LinearLayout mLlHideBooks; - @BindView(R.id.rl_change_pwd) - RelativeLayout mRlChangePwd; - @BindView(R.id.rl_fingerprint) - RelativeLayout mRlFingerprint; - @BindView(R.id.sc_fingerprint) - SwitchCompat mScFingerprint; + + private FragmentPrivateBookcaseBinding binding; private boolean openPrivate; private boolean openFingerprint; @Override - protected int getContentId() { - return R.layout.fragment_private_bookcase; + protected View bindView(LayoutInflater inflater, ViewGroup container) { + binding = FragmentPrivateBookcaseBinding.inflate(inflater, container, false); + return binding.getRoot(); } @Override @@ -67,28 +55,28 @@ public class PrivateBooksFragment extends BaseFragment { @Override protected void initWidget(Bundle savedInstanceState) { super.initWidget(savedInstanceState); - mScPrivateBookcase.setChecked(openPrivate); - mScFingerprint.setChecked(openFingerprint); - if (openPrivate) mLlContent.setVisibility(View.VISIBLE); + binding.scPrivateBookcase.setChecked(openPrivate); + binding.scFingerprint.setChecked(openFingerprint); + if (openPrivate) binding.llContent.setVisibility(View.VISIBLE); } @Override protected void initClick() { super.initClick(); - mRlPrivateBookcase.setOnClickListener(v -> { + binding.rlPrivateBookcase.setOnClickListener(v -> { if (openPrivate) { DialogCreator.createCommonDialog(getContext(), "关闭私密书架", "确定要关闭私密书架吗?\n注意:这将会删除私密书架中的全部书籍!", true, (dialog, which) -> { BookGroupService.getInstance().deletePrivateGroup(); SharedPreUtils.getInstance().putString("privatePwd", ""); - mLlContent.setVisibility(View.GONE); + binding.llContent.setVisibility(View.GONE); openPrivate = !openPrivate; openFingerprint = false; SharedPreUtils.getInstance().putBoolean("openPrivate", openPrivate); SharedPreUtils.getInstance().putBoolean("openFingerprint", openFingerprint); - mScPrivateBookcase.setChecked(openPrivate); - mScFingerprint.setChecked(openFingerprint); + binding.scPrivateBookcase.setChecked(openPrivate); + binding.scFingerprint.setChecked(openFingerprint); }, null); } else { final String[] pwd = new String[1]; @@ -100,15 +88,15 @@ public class PrivateBooksFragment extends BaseFragment { BookGroupService.getInstance().createPrivateGroup(); SharedPreUtils.getInstance().putString("privatePwd", CyptoUtils.encode(APPCONST.KEY, pwd[0])); dialog.dismiss(); - mLlContent.setVisibility(View.VISIBLE); + binding.llContent.setVisibility(View.VISIBLE); openPrivate = !openPrivate; SharedPreUtils.getInstance().putBoolean("openPrivate", openPrivate); - mScPrivateBookcase.setChecked(openPrivate); + binding.scPrivateBookcase.setChecked(openPrivate); }); } }); - mLlHideBooks.setOnClickListener(v -> { + binding.llHideBooks.setOnClickListener(v -> { MyApplication.runOnUiThread(() -> { String privateGroupId = SharedPreUtils.getInstance().getString("privateGroupId"); List mBooks = BookService.getInstance().getAllBooks(); @@ -162,7 +150,7 @@ public class PrivateBooksFragment extends BaseFragment { }); }); - mRlChangePwd.setOnClickListener(v -> { + binding.rlChangePwd.setOnClickListener(v -> { final String[] pwd = new String[1]; MyAlertDialog.createInputDia(getContext(), getString(R.string.change_pwd), "", "", InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD, @@ -171,21 +159,21 @@ public class PrivateBooksFragment extends BaseFragment { (dialog, which) -> { SharedPreUtils.getInstance().putString("privatePwd", CyptoUtils.encode(APPCONST.KEY, pwd[0])); dialog.dismiss(); - mLlContent.setVisibility(View.VISIBLE); + binding.llContent.setVisibility(View.VISIBLE); }); }); - mRlFingerprint.setOnClickListener( + binding.rlFingerprint.setOnClickListener( (v) -> { if (openFingerprint) { openFingerprint = false; - mScFingerprint.setChecked(openFingerprint); + binding.scFingerprint.setChecked(openFingerprint); SharedPreUtils.getInstance().putBoolean("openFingerprint", openFingerprint); } else { if (!FingerprintUtils.supportFingerprint(getActivity())) return; FingerprintDialog fd = new FingerprintDialog((AppCompatActivity) getActivity(),false, needGoTo -> { openFingerprint = true; - mScFingerprint.setChecked(openFingerprint); + binding.scFingerprint.setChecked(openFingerprint); SharedPreUtils.getInstance().putBoolean("openFingerprint", openFingerprint); }); fd.setCancelable(false); @@ -208,12 +196,12 @@ public class PrivateBooksFragment extends BaseFragment { public void init(){ openPrivate = SharedPreUtils.getInstance().getBoolean("openPrivate"); openFingerprint = SharedPreUtils.getInstance().getBoolean("openFingerprint"); - mScPrivateBookcase.setChecked(openPrivate); - mScFingerprint.setChecked(openFingerprint); + binding.scPrivateBookcase.setChecked(openPrivate); + binding.scFingerprint.setChecked(openFingerprint); if (openPrivate) { - mLlContent.setVisibility(View.VISIBLE); + binding.llContent.setVisibility(View.VISIBLE); }else { - mLlContent.setVisibility(View.GONE); + binding.llContent.setVisibility(View.GONE); } } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/WebDavFragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/WebDavFragment.java index 91832fc..1f6ca43 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/WebDavFragment.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/fragment/WebDavFragment.java @@ -4,13 +4,11 @@ import android.os.Bundle; import android.text.InputType; import android.view.LayoutInflater; import android.view.View; -import android.widget.LinearLayout; +import android.view.ViewGroup; import android.widget.NumberPicker; -import android.widget.TextView; import java.util.ArrayList; -import butterknife.BindView; import io.reactivex.Single; import io.reactivex.SingleOnSubscribe; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -19,6 +17,7 @@ import xyz.fycz.myreader.R; import xyz.fycz.myreader.base.BaseFragment; import xyz.fycz.myreader.base.observer.MySingleObserver; import xyz.fycz.myreader.common.APPCONST; +import xyz.fycz.myreader.databinding.FragmentWebdavSettingBinding; import xyz.fycz.myreader.model.storage.BackupRestoreUi; import xyz.fycz.myreader.model.storage.WebDavHelp; import xyz.fycz.myreader.ui.dialog.MyAlertDialog; @@ -31,32 +30,18 @@ import xyz.fycz.myreader.util.ToastUtils; * @date 2021/1/9 12:08 */ public class WebDavFragment extends BaseFragment { - @BindView(R.id.webdav_setting_webdav_url) - LinearLayout llWebdavUrl; - @BindView(R.id.tv_webdav_url) - TextView tvWebdavUrl; - @BindView(R.id.webdav_setting_webdav_account) - LinearLayout llWebdavAccount; - @BindView(R.id.tv_webdav_account) - TextView tvWebdavAccount; - @BindView(R.id.webdav_setting_webdav_password) - LinearLayout llWebdavPassword; - @BindView(R.id.tv_webdav_password) - TextView tvWebdavPassword; - @BindView(R.id.webdav_setting_webdav_restore) - LinearLayout llWebdavRestore; - @BindView(R.id.ll_restore_num) - LinearLayout mLlRestoreNum; - @BindView(R.id.tv_restore_num) - TextView mTvRestoreNum; + + private FragmentWebdavSettingBinding binding; private String webdavUrl; private String webdavAccount; private String webdavPassword; private int restoreNum; + @Override - protected int getContentId() { - return R.layout.fragment_webdav_setting; + protected View bindView(LayoutInflater inflater, ViewGroup container) { + binding = FragmentWebdavSettingBinding.inflate(inflater, container, false); + return binding.getRoot(); } @Override @@ -71,56 +56,56 @@ public class WebDavFragment extends BaseFragment { @Override protected void initWidget(Bundle savedInstanceState) { super.initWidget(savedInstanceState); - tvWebdavUrl.setText(webdavUrl); - tvWebdavAccount.setText(StringHelper.isEmpty(webdavAccount) ? "请输入WebDav账号" : webdavAccount); - tvWebdavPassword.setText(StringHelper.isEmpty(webdavPassword) ? "请输入WebDav授权密码" : "************"); - mTvRestoreNum.setText(getString(R.string.cur_restore_list_num, restoreNum)); + binding.tvWebdavUrl.setText(webdavUrl); + binding.tvWebdavAccount.setText(StringHelper.isEmpty(webdavAccount) ? "请输入WebDav账号" : webdavAccount); + binding.tvWebdavPassword.setText(StringHelper.isEmpty(webdavPassword) ? "请输入WebDav授权密码" : "************"); + binding.tvRestoreNum.setText(getString(R.string.cur_restore_list_num, restoreNum)); } @Override protected void initClick() { super.initClick(); final String[] webdavTexts = new String[3]; - llWebdavUrl.setOnClickListener(v -> { + binding.webdavSettingWebdavUrl.setOnClickListener(v -> { MyAlertDialog.createInputDia(getContext(), getString(R.string.webdav_url), "", webdavUrl.equals(APPCONST.DEFAULT_WEB_DAV_URL) ? "" : webdavUrl, InputType.TYPE_CLASS_TEXT,true, 100, text -> webdavTexts[0] = text, (dialog, which) -> { webdavUrl = webdavTexts[0]; - tvWebdavUrl.setText(webdavUrl); + binding.tvWebdavUrl.setText(webdavUrl); SharedPreUtils.getInstance().putString("webdavUrl", webdavUrl); dialog.dismiss(); }, null, "恢复默认", (dialog, which) -> { webdavUrl = APPCONST.DEFAULT_WEB_DAV_URL; - tvWebdavUrl.setText(webdavUrl); + binding.tvWebdavUrl.setText(webdavUrl); SharedPreUtils.getInstance().putString("webdavUrl", webdavUrl); }); }); - llWebdavAccount.setOnClickListener(v -> { + binding.webdavSettingWebdavAccount.setOnClickListener(v -> { MyAlertDialog.createInputDia(getContext(), getString(R.string.webdav_account), "", webdavAccount, true, 100, text -> webdavTexts[1] = text, (dialog, which) -> { webdavAccount = webdavTexts[1]; - tvWebdavAccount.setText(webdavAccount); + binding.tvWebdavAccount.setText(webdavAccount); SharedPreUtils.getInstance().putString("webdavAccount", webdavAccount); dialog.dismiss(); }); }); - llWebdavPassword.setOnClickListener(v -> { + binding.webdavSettingWebdavPassword.setOnClickListener(v -> { MyAlertDialog.createInputDia(getContext(), getString(R.string.webdav_password), "", webdavPassword, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD, true, 100, text -> webdavTexts[2] = text, (dialog, which) -> { webdavPassword = webdavTexts[2]; - tvWebdavPassword.setText("************"); + binding.tvWebdavPassword.setText("************"); SharedPreUtils.getInstance().putString("webdavPassword", webdavPassword); dialog.dismiss(); }); }); - llWebdavRestore.setOnClickListener(v -> { + binding.webdavSettingWebdavRestore.setOnClickListener(v -> { Single.create((SingleOnSubscribe>) emitter -> { emitter.onSuccess(WebDavHelp.INSTANCE.getWebDavFileNames()); }).subscribeOn(Schedulers.io()) @@ -135,7 +120,7 @@ public class WebDavFragment extends BaseFragment { }); }); - mLlRestoreNum.setOnClickListener(v -> { + binding.llRestoreNum.setOnClickListener(v -> { View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_number_picker, null); NumberPicker threadPick = view.findViewById(R.id.number_picker); threadPick.setMaxValue(100); @@ -150,7 +135,7 @@ public class WebDavFragment extends BaseFragment { .setPositiveButton("确定", (dialog, which) -> { restoreNum = threadPick.getValue(); SharedPreUtils.getInstance().putInt("restoreNum", restoreNum); - mTvRestoreNum.setText(getString(R.string.cur_restore_list_num, restoreNum)); + binding.tvRestoreNum.setText(getString(R.string.cur_restore_list_num, restoreNum)); }).setNegativeButton("取消", null) .show(); }); diff --git a/app/src/main/java/xyz/fycz/myreader/ui/popmenu/AutoPageMenu.java b/app/src/main/java/xyz/fycz/myreader/ui/popmenu/AutoPageMenu.java index 12dea15..b67ebed 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/popmenu/AutoPageMenu.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/popmenu/AutoPageMenu.java @@ -3,30 +3,19 @@ package xyz.fycz.myreader.ui.popmenu; import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; -import android.view.View; import android.widget.FrameLayout; import android.widget.SeekBar; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import butterknife.BindView; -import butterknife.ButterKnife; -import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.SysManager; +import xyz.fycz.myreader.databinding.MenuAutoPageBinding; import xyz.fycz.myreader.entity.Setting; public class AutoPageMenu extends FrameLayout { - @BindView(R.id.tv_auto_scroll_speed) - TextView tvAutoPageSpeed; - @BindView(R.id.sb_auto_scroll_progress) - SeekBar sbAutoPageSpeed; - @BindView(R.id.tv_exit_auto_page) - TextView tvExitAutoPage; - @BindView(R.id.vwNavigationBar) - View vwNavigationBar; + private MenuAutoPageBinding binding; public AutoPageMenu(@NonNull Context context) { super(context); @@ -44,18 +33,17 @@ public class AutoPageMenu extends FrameLayout { } private void init(Context context) { - View view = LayoutInflater.from(context).inflate(R.layout.menu_auto_page, this); - ButterKnife.bind(this, view); + binding = MenuAutoPageBinding.inflate(LayoutInflater.from(context), this, true); } public void setListener(Callback callback) { Setting setting = SysManager.getSetting(); - sbAutoPageSpeed.setProgress(110 - setting.getAutoScrollSpeed()); - tvAutoPageSpeed.setText(String.format("翻页速度:%s %%", 110 - setting.getAutoScrollSpeed())); - sbAutoPageSpeed.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + binding.sbAutoScrollProgress.setProgress(110 - setting.getAutoScrollSpeed()); + binding.tvAutoScrollSpeed.setText(String.format("翻页速度:%s %%", 110 - setting.getAutoScrollSpeed())); + binding.sbAutoScrollProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - tvAutoPageSpeed.setText(String.format("翻页速度:%s %%", progress)); + binding.tvAutoScrollSpeed.setText(String.format("翻页速度:%s %%", progress)); } @Override @@ -72,11 +60,11 @@ public class AutoPageMenu extends FrameLayout { callback.onSpeedChange(); } }); - tvExitAutoPage.setOnClickListener(v -> callback.onExitClick()); + binding.tvExitAutoPage.setOnClickListener(v -> callback.onExitClick()); } public void setNavigationBarHeight(int height) { - vwNavigationBar.getLayoutParams().height = height; + binding.vwNavigationBar.getLayoutParams().height = height; } public interface Callback{ diff --git a/app/src/main/java/xyz/fycz/myreader/ui/popmenu/BrightnessEyeMenu.java b/app/src/main/java/xyz/fycz/myreader/ui/popmenu/BrightnessEyeMenu.java index 9350817..70d05ed 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/popmenu/BrightnessEyeMenu.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/popmenu/BrightnessEyeMenu.java @@ -4,38 +4,21 @@ import android.app.Activity; import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; -import android.view.View; import android.widget.FrameLayout; -import android.widget.LinearLayout; import android.widget.SeekBar; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; -import butterknife.BindView; -import butterknife.ButterKnife; -import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.SysManager; +import xyz.fycz.myreader.databinding.MenuBrightnessEyeBinding; import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.util.BrightUtil; -import xyz.fycz.myreader.widget.CircleCheckBox; public class BrightnessEyeMenu extends FrameLayout { - @BindView(R.id.ll_follow_sys) - LinearLayout llFollowSys; - @BindView(R.id.cb_follow_sys) - CircleCheckBox cbFollowSys; - @BindView(R.id.sb_brightness_progress) - SeekBar sbBrightness; - @BindView(R.id.ll_protect_eye) - LinearLayout llProtectEye; - @BindView(R.id.cb_protect_eye) - CircleCheckBox cbProtectEye; - @BindView(R.id.sb_protect_eye) - SeekBar sbProtectEye; - @BindView(R.id.vwNavigationBar) - View vwNavigationBar; + + private MenuBrightnessEyeBinding binding; private Callback callback; @@ -59,8 +42,7 @@ public class BrightnessEyeMenu extends FrameLayout { } private void init(Context context) { - View view = LayoutInflater.from(context).inflate(R.layout.menu_brightness_eye, this); - ButterKnife.bind(this, view); + binding = MenuBrightnessEyeBinding.inflate(LayoutInflater.from(context), this, true); } public void setListener(Activity activity, Callback callback) { @@ -70,22 +52,21 @@ public class BrightnessEyeMenu extends FrameLayout { } public void initWidget() { - sbBrightness.setProgress(setting.getBrightProgress()); - cbFollowSys.setChecked(setting.isBrightFollowSystem()); - - sbProtectEye.setProgress(setting.getBlueFilterPercent() - 10); - cbProtectEye.setChecked(setting.isProtectEye()); - sbProtectEye.setEnabled(cbProtectEye.isChecked()); + binding.sbBrightnessProgress.setProgress(setting.getBrightProgress()); + binding.cbFollowSys.setChecked(setting.isBrightFollowSystem()); + binding.sbProtectEye.setProgress(setting.getBlueFilterPercent() - 10); + binding.cbProtectEye.setChecked(setting.isProtectEye()); + binding.sbProtectEye.setEnabled(binding.cbProtectEye.isChecked()); } private void initListener() { //设置亮度 - sbBrightness.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + binding.sbBrightnessProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { BrightUtil.setBrightness((AppCompatActivity) context, progress); - cbFollowSys.setChecked(false); + binding.cbFollowSys.setChecked(false); setting.setBrightProgress(progress); setting.setBrightFollowSystem(false); SysManager.saveSetting(setting); @@ -103,9 +84,9 @@ public class BrightnessEyeMenu extends FrameLayout { } }); //亮度跟随系统 - cbFollowSys.setOnClickListener(v -> { - cbFollowSys.setChecked(!cbFollowSys.isChecked()); - if (cbFollowSys.isChecked()) { + binding.cbFollowSys.setOnClickListener(v -> { + binding.cbFollowSys.setChecked(!binding.cbFollowSys.isChecked()); + if (binding.cbFollowSys.isChecked()) { BrightUtil.followSystemBright((AppCompatActivity) context); setting.setBrightFollowSystem(true); } else { @@ -116,7 +97,7 @@ public class BrightnessEyeMenu extends FrameLayout { }); //设置蓝光过滤 - sbProtectEye.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + binding.sbProtectEye.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { @@ -137,17 +118,17 @@ public class BrightnessEyeMenu extends FrameLayout { } }); //是否开启护眼 - cbProtectEye.setOnClickListener(v -> { - cbProtectEye.setChecked(!cbProtectEye.isChecked()); - sbProtectEye.setEnabled(cbProtectEye.isChecked()); - setting.setProtectEye(cbProtectEye.isChecked()); + binding.cbProtectEye.setOnClickListener(v -> { + binding.cbProtectEye.setChecked(!binding.cbProtectEye.isChecked()); + binding.sbProtectEye.setEnabled(binding.cbProtectEye.isChecked()); + setting.setProtectEye(binding.cbProtectEye.isChecked()); SysManager.saveSetting(setting); callback.onProtectEyeChange(); }); } public void setNavigationBarHeight(int height) { - vwNavigationBar.getLayoutParams().height = height; + binding.vwNavigationBar.getLayoutParams().height = height; } public interface Callback { diff --git a/app/src/main/java/xyz/fycz/myreader/ui/popmenu/CustomizeComMenu.java b/app/src/main/java/xyz/fycz/myreader/ui/popmenu/CustomizeComMenu.java index f3236e2..abd0f3a 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/popmenu/CustomizeComMenu.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/popmenu/CustomizeComMenu.java @@ -1,93 +1,26 @@ package xyz.fycz.myreader.ui.popmenu; -import android.app.Activity; import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; -import android.view.View; import android.widget.FrameLayout; -import android.widget.ImageView; import android.widget.SeekBar; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import butterknife.BindView; -import butterknife.ButterKnife; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.SysManager; +import xyz.fycz.myreader.databinding.MenuCustomizeComBinding; import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.ui.dialog.DialogCreator; -import static xyz.fycz.myreader.widget.page.PageLoader.DEFAULT_MARGIN_HEIGHT; import static xyz.fycz.myreader.widget.page.PageLoader.DEFAULT_MARGIN_WIDTH; public class CustomizeComMenu extends FrameLayout { - @BindView(R.id.tv_line_spacing) - TextView tvLineSpacing; - @BindView(R.id.iv_line_minus) - ImageView ivLineMinus; - @BindView(R.id.sb_line_progress) - SeekBar sbLineProgress; - @BindView(R.id.iv_line_add) - ImageView ivLineAdd; - @BindView(R.id.tv_para_spacing) - TextView tvParaSpacing; - @BindView(R.id.iv_para_minus) - ImageView ivParaMinus; - @BindView(R.id.sb_para_progress) - SeekBar sbParaProgress; - @BindView(R.id.iv_para_add) - ImageView ivParaAdd; - @BindView(R.id.tv_text_spacing) - TextView tvTextSpacing; - @BindView(R.id.iv_text_minus) - ImageView ivTextMinus; - @BindView(R.id.sb_text_progress) - SeekBar sbTextProgress; - @BindView(R.id.iv_text_add) - ImageView ivTextAdd; - @BindView(R.id.tv_left_spacing) - TextView tvLeftSpacing; - @BindView(R.id.iv_left_minus) - ImageView ivLeftMinus; - @BindView(R.id.sb_left_progress) - SeekBar sbLeftProgress; - @BindView(R.id.iv_left_add) - ImageView ivLeftAdd; - @BindView(R.id.tv_right_spacing) - TextView tvRightSpacing; - @BindView(R.id.iv_right_minus) - ImageView ivRightMinus; - @BindView(R.id.sb_right_progress) - SeekBar sbRightProgress; - @BindView(R.id.iv_right_add) - ImageView ivRightAdd; - @BindView(R.id.tv_top_spacing) - TextView tvTopSpacing; - @BindView(R.id.iv_top_minus) - ImageView ivTopMinus; - @BindView(R.id.sb_top_progress) - SeekBar sbTopProgress; - @BindView(R.id.iv_top_add) - ImageView ivTopAdd; - @BindView(R.id.tv_bottom_spacing) - TextView tvBottomSpacing; - @BindView(R.id.iv_bottom_minus) - ImageView ivBottomMinus; - @BindView(R.id.sb_bottom_progress) - SeekBar sbBottomProgress; - @BindView(R.id.iv_bottom_add) - ImageView ivBottomAdd; - @BindView(R.id.tv_normal_com) - TextView tvNormalCom; - @BindView(R.id.tv_tight_com) - TextView tvTightCom; - @BindView(R.id.tv_reset) - TextView tvReset; - @BindView(R.id.vwNavigationBar) - View vwNavigationBar; + + private MenuCustomizeComBinding binding; private Callback callback; @@ -109,8 +42,7 @@ public class CustomizeComMenu extends FrameLayout { } private void init(Context context) { - View view = LayoutInflater.from(context).inflate(R.layout.menu_customize_com, this); - ButterKnife.bind(this, view); + binding = MenuCustomizeComBinding.inflate(LayoutInflater.from(context), this, true); } public void setListener(Callback callback) { @@ -120,7 +52,7 @@ public class CustomizeComMenu extends FrameLayout { } public void setNavigationBarHeight(int height) { - vwNavigationBar.getLayoutParams().height = height; + binding.vwNavigationBar.getLayoutParams().height = height; } /** @@ -143,7 +75,7 @@ public class CustomizeComMenu extends FrameLayout { } private void initListener() { - ivLineAdd.setOnClickListener(v -> { + binding.ivLineAdd.setOnClickListener(v -> { float tem = setting.getLineMultiplier() + 0.1f; if (tem >= -0.3f && tem <= 3.0f) { setting.setLineMultiplier(tem); @@ -151,7 +83,7 @@ public class CustomizeComMenu extends FrameLayout { callback.onTextPChange(); } }); - ivLineMinus.setOnClickListener(v -> { + binding.ivLineMinus.setOnClickListener(v -> { float tem = setting.getLineMultiplier() - 0.1f; if (tem >= -0.3f && tem <= 3.0f) { setting.setLineMultiplier(tem); @@ -159,7 +91,7 @@ public class CustomizeComMenu extends FrameLayout { callback.onTextPChange(); } }); - sbLineProgress.setOnSeekBarChangeListener(new OnSeekBarChange() { + binding.sbLineProgress.setOnSeekBarChangeListener(new OnSeekBarChange() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser){ @@ -169,7 +101,7 @@ public class CustomizeComMenu extends FrameLayout { } } }); - ivParaAdd.setOnClickListener(v -> { + binding.ivParaAdd.setOnClickListener(v -> { float tem = setting.getParagraphSize() + 0.1f; if (tem >= 0.0f && tem <= 3.0f) { setting.setParagraphSize(tem); @@ -177,7 +109,7 @@ public class CustomizeComMenu extends FrameLayout { callback.onTextPChange(); } }); - ivParaMinus.setOnClickListener(v -> { + binding.ivParaMinus.setOnClickListener(v -> { float tem = setting.getParagraphSize() - 0.1f; if (tem >= 0.0f && tem <=3.0f) { setting.setParagraphSize(tem); @@ -185,7 +117,7 @@ public class CustomizeComMenu extends FrameLayout { callback.onTextPChange(); } }); - sbParaProgress.setOnSeekBarChangeListener(new OnSeekBarChange() { + binding.sbParaProgress.setOnSeekBarChangeListener(new OnSeekBarChange() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser){ @@ -195,7 +127,7 @@ public class CustomizeComMenu extends FrameLayout { } } }); - ivTextAdd.setOnClickListener(v -> { + binding.ivTextAdd.setOnClickListener(v -> { float tem = setting.getTextLetterSpacing() + 0.01f; if (tem >= -0.20f && tem <= 0.50f) { setting.setTextLetterSpacing(tem); @@ -203,7 +135,7 @@ public class CustomizeComMenu extends FrameLayout { callback.onTextPChange(); } }); - ivTextMinus.setOnClickListener(v -> { + binding.ivTextMinus.setOnClickListener(v -> { float tem = setting.getTextLetterSpacing() - 0.01f; if (tem >= -0.20f && tem <= 0.50f) { setting.setTextLetterSpacing(tem); @@ -211,7 +143,7 @@ public class CustomizeComMenu extends FrameLayout { callback.onTextPChange(); } }); - sbTextProgress.setOnSeekBarChangeListener(new OnSeekBarChange() { + binding.sbTextProgress.setOnSeekBarChangeListener(new OnSeekBarChange() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser){ @@ -221,7 +153,7 @@ public class CustomizeComMenu extends FrameLayout { } } }); - ivLeftAdd.setOnClickListener(v -> { + binding.ivLeftAdd.setOnClickListener(v -> { int tem = setting.getPaddingLeft() + 1; if (tem >= 0 && tem <= 100) { setting.setPaddingLeft(tem); @@ -229,7 +161,7 @@ public class CustomizeComMenu extends FrameLayout { callback.onMarginChange(); } }); - ivLeftMinus.setOnClickListener(v -> { + binding.ivLeftMinus.setOnClickListener(v -> { int tem = setting.getPaddingLeft() - 1; if (tem >= 0 && tem <= 100) { setting.setPaddingLeft(tem); @@ -237,7 +169,7 @@ public class CustomizeComMenu extends FrameLayout { callback.onMarginChange(); } }); - ivRightAdd.setOnClickListener(v -> { + binding.ivRightAdd.setOnClickListener(v -> { int tem = setting.getPaddingRight() + 1; if (tem >= 0 && tem <= 100) { setting.setPaddingRight(tem); @@ -245,7 +177,7 @@ public class CustomizeComMenu extends FrameLayout { callback.onMarginChange(); } }); - ivRightMinus.setOnClickListener(v -> { + binding.ivRightMinus.setOnClickListener(v -> { int tem = setting.getPaddingRight() - 1; if (tem >= 0 && tem <= 100) { setting.setPaddingRight(tem); @@ -253,7 +185,7 @@ public class CustomizeComMenu extends FrameLayout { callback.onMarginChange(); } }); - ivTopAdd.setOnClickListener(v -> { + binding.ivTopAdd.setOnClickListener(v -> { int tem = setting.getPaddingTop() + 1; if (tem >= 0 && tem <= 100) { setting.setPaddingTop(tem); @@ -261,7 +193,7 @@ public class CustomizeComMenu extends FrameLayout { callback.onMarginChange(); } }); - ivTopMinus.setOnClickListener(v -> { + binding.ivTopMinus.setOnClickListener(v -> { int tem = setting.getPaddingTop() - 1; if (tem >= 0 && tem <= 100) { setting.setPaddingTop(tem); @@ -269,7 +201,7 @@ public class CustomizeComMenu extends FrameLayout { callback.onMarginChange(); } }); - ivBottomAdd.setOnClickListener(v -> { + binding.ivBottomAdd.setOnClickListener(v -> { int tem = setting.getPaddingBottom() + 1; if (tem >= 0 && tem <= 100) { setting.setPaddingBottom(tem); @@ -277,7 +209,7 @@ public class CustomizeComMenu extends FrameLayout { callback.onMarginChange(); } }); - ivBottomMinus.setOnClickListener(v -> { + binding.ivBottomMinus.setOnClickListener(v -> { int tem = setting.getPaddingBottom() - 1; if (tem >= 0 && tem <= 100) { setting.setPaddingBottom(tem); @@ -285,23 +217,23 @@ public class CustomizeComMenu extends FrameLayout { callback.onMarginChange(); } }); - sbLeftProgress.setOnSeekBarChangeListener(onPaddingChange); - sbRightProgress.setOnSeekBarChangeListener(onPaddingChange); - sbTopProgress.setOnSeekBarChangeListener(onPaddingChange); - sbBottomProgress.setOnSeekBarChangeListener(onPaddingChange); + binding.sbLeftProgress.setOnSeekBarChangeListener(onPaddingChange); + binding.sbRightProgress.setOnSeekBarChangeListener(onPaddingChange); + binding.sbTopProgress.setOnSeekBarChangeListener(onPaddingChange); + binding.sbBottomProgress.setOnSeekBarChangeListener(onPaddingChange); - tvNormalCom.setOnClickListener(v -> { + binding.tvNormalCom.setOnClickListener(v -> { setting.setTightCom(false); initSelect(); callback.onRefreshUI(); }); - tvTightCom.setOnClickListener(v -> { + binding.tvTightCom.setOnClickListener(v -> { setting.setTightCom(true); initSelect(); callback.onRefreshUI(); DialogCreator.createTipDialog(getContext(), getContext().getResources().getString(R.string.tight_com_tip)); }); - tvReset.setOnClickListener(v -> { + binding.tvReset.setOnClickListener(v -> { setting.setLineMultiplier(1); setting.setParagraphSize(0.9f); setting.setTextLetterSpacing(0); @@ -317,42 +249,42 @@ public class CustomizeComMenu extends FrameLayout { private void initLine(){ int line = (int) (setting.getLineMultiplier() * 10); - initProgress(tvLineSpacing, sbLineProgress, String.format("行间距(%s)", line), line + 3); + initProgress(binding.tvLineSpacing, binding.sbLineProgress, String.format("行间距(%s)", line), line + 3); } private void initPara(){ int para = (int) (setting.getParagraphSize() * 10); - initProgress(tvParaSpacing, sbParaProgress, String.format("段间距(%s)", para), para); + initProgress(binding.tvParaSpacing, binding.sbParaProgress, String.format("段间距(%s)", para), para); } private void initText(){ int text = (int) (setting.getTextLetterSpacing() * 100); - initProgress(tvTextSpacing, sbTextProgress, String.format("字间距(%s)", text), text + 20); + initProgress(binding.tvTextSpacing, binding.sbTextProgress, String.format("字间距(%s)", text), text + 20); } private void initLeft(){ int left = setting.getPaddingLeft(); - initProgress(tvLeftSpacing, sbLeftProgress, String.format("左边距(%s)", left), left); + initProgress(binding.tvLeftSpacing, binding.sbLeftProgress, String.format("左边距(%s)", left), left); } private void initRight(){ int right = setting.getPaddingRight(); - initProgress(tvRightSpacing, sbRightProgress, String.format("右边距(%s)", right), right); + initProgress(binding.tvRightSpacing, binding.sbRightProgress, String.format("右边距(%s)", right), right); } private void initTop(){ int top = setting.getPaddingTop(); - initProgress(tvTopSpacing, sbTopProgress, String.format("上边距(%s)", top), top); + initProgress(binding.tvTopSpacing, binding.sbTopProgress, String.format("上边距(%s)", top), top); } private void initBottom(){ int bottom = setting.getPaddingBottom(); - initProgress(tvBottomSpacing, sbBottomProgress, String.format("下边距(%s)", bottom), bottom); + initProgress(binding.tvBottomSpacing, binding.sbBottomProgress, String.format("下边距(%s)", bottom), bottom); } private void initSelect(){ - tvTightCom.setSelected(setting.isTightCom()); - tvNormalCom.setSelected(!setting.isTightCom()); + binding.tvTightCom.setSelected(setting.isTightCom()); + binding.tvNormalCom.setSelected(!setting.isTightCom()); } private void initProgress(TextView tvSpacing, SeekBar sbProgress, String text, int value){ diff --git a/app/src/main/java/xyz/fycz/myreader/ui/popmenu/CustomizeLayoutMenu.java b/app/src/main/java/xyz/fycz/myreader/ui/popmenu/CustomizeLayoutMenu.java index 6e1bb35..0aaa65e 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/popmenu/CustomizeLayoutMenu.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/popmenu/CustomizeLayoutMenu.java @@ -3,25 +3,19 @@ package xyz.fycz.myreader.ui.popmenu; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.res.AssetManager; -import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; -import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; -import android.graphics.drawable.Drawable; import android.util.AttributeSet; -import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.FrameLayout; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; @@ -29,19 +23,16 @@ import androidx.annotation.Nullable; import androidx.fragment.app.FragmentActivity; import com.jaredrummler.android.colorpicker.ColorPickerDialog; -import com.jaredrummler.android.colorpicker.ColorPickerDialogListener; -import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.common.APPCONST; +import xyz.fycz.myreader.databinding.MenuCumtomizeLayoutBinding; import xyz.fycz.myreader.entity.ReadStyle; import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.ui.dialog.DialogCreator; @@ -51,28 +42,10 @@ import xyz.fycz.myreader.util.ZipUtils; import xyz.fycz.myreader.util.utils.FileUtils; import xyz.fycz.myreader.util.utils.GsonExtensionsKt; import xyz.fycz.myreader.util.utils.MeUtils; -import xyz.fycz.myreader.widget.CircleCheckBox; -import xyz.fycz.myreader.widget.HorizontalListView; public class CustomizeLayoutMenu extends FrameLayout { - @BindView(R.id.iv_bg_color) - ImageView ivBgColor; - @BindView(R.id.iv_font_color) - ImageView ivFontColor; - @BindView(R.id.cb_share_layout) - CircleCheckBox cbShareLayout; - @BindView(R.id.bgImgList) - HorizontalListView bgImgList; - @BindView(R.id.tv_save_layout) - TextView tvSaveLayout; - @BindView(R.id.tv_import_layout) - TextView tvImportLayout; - @BindView(R.id.tv_export_layout) - TextView tvExportLayout; - @BindView(R.id.tv_reset_layout) - TextView tvResetLayout; - @BindView(R.id.vwNavigationBar) - View vwNavigationBar; + + private MenuCumtomizeLayoutBinding binding; private Callback callback; @@ -98,8 +71,7 @@ public class CustomizeLayoutMenu extends FrameLayout { } private void init(Context context) { - View view = LayoutInflater.from(context).inflate(R.layout.menu_cumtomize_layout, this); - ButterKnife.bind(this, view); + binding = MenuCumtomizeLayoutBinding.inflate(LayoutInflater.from(context), this, true); } public void setListener(Activity activity, Callback callback) { @@ -110,14 +82,14 @@ public class CustomizeLayoutMenu extends FrameLayout { } private void initWidget() { - ivBgColor.setImageDrawable(setting.getBgDrawable(setting.getCurReadStyleIndex(), context, 200, 120)); - ivFontColor.setImageDrawable(new ColorDrawable(setting.getTextColor())); - cbShareLayout.setChecked(setting.isSharedLayout()); + binding.ivBgColor.setImageDrawable(setting.getBgDrawable(setting.getCurReadStyleIndex(), context, 200, 120)); + binding.ivFontColor.setImageDrawable(new ColorDrawable(setting.getTextColor())); + binding.cbShareLayout.setChecked(setting.isSharedLayout()); //背景图列表 bgImgListAdapter = new BgImgListAdapter(context); bgImgListAdapter.initList(); - bgImgList.setAdapter(bgImgListAdapter); + binding.bgImgList.setAdapter(bgImgListAdapter); } public void upColor() { @@ -126,12 +98,12 @@ public class CustomizeLayoutMenu extends FrameLayout { ToastUtils.showInfo("当前正在编辑夜间模式"); curStyleIndex = 6; } - ivFontColor.setImageDrawable(new ColorDrawable(setting.getTextColor())); - ivBgColor.setImageDrawable(setting.getBgDrawable(curStyleIndex, context, 200, 120)); + binding.ivFontColor.setImageDrawable(new ColorDrawable(setting.getTextColor())); + binding.ivBgColor.setImageDrawable(setting.getBgDrawable(curStyleIndex, context, 200, 120)); } private void initListener() { - ivBgColor.setOnClickListener(v -> { + binding.ivBgColor.setOnClickListener(v -> { ColorPickerDialog.newBuilder() .setColor(setting.getBgColor()) .setShowAlphaSlider(false) @@ -140,14 +112,14 @@ public class CustomizeLayoutMenu extends FrameLayout { .show((FragmentActivity) context); }); //选择文字颜色 - ivFontColor.setOnClickListener(view -> + binding.ivFontColor.setOnClickListener(view -> ColorPickerDialog.newBuilder() .setColor(setting.getTextColor()) .setShowAlphaSlider(false) .setDialogType(ColorPickerDialog.TYPE_PRESETS) .setDialogId(APPCONST.SELECT_TEXT_COLOR) .show((FragmentActivity) context)); - cbShareLayout.setOnClickListener(v -> { + binding.cbShareLayout.setOnClickListener(v -> { if (!setting.isSharedLayout()) { DialogCreator.createCommonDialog(context, "提示", context.getString(R.string.share_layout_tip), @@ -155,16 +127,16 @@ public class CustomizeLayoutMenu extends FrameLayout { setting.setSharedLayout(true); setting.sharedLayout(); SysManager.saveSetting(setting); - cbShareLayout.setChecked(true); + binding.cbShareLayout.setChecked(true); }, null); } else { setting.setSharedLayout(false); setting.sharedLayout(); SysManager.saveSetting(setting); - cbShareLayout.setChecked(false); + binding.cbShareLayout.setChecked(false); } }); - bgImgList.setOnItemClickListener((adapterView, view, i, l) -> { + binding.bgImgList.setOnItemClickListener((adapterView, view, i, l) -> { if (i == 0) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); @@ -175,7 +147,7 @@ public class CustomizeLayoutMenu extends FrameLayout { setAssetsBg(bgPath); } }); - tvSaveLayout.setOnClickListener(v -> { + binding.tvSaveLayout.setOnClickListener(v -> { CharSequence[] items = new CharSequence[6]; for (int i = 0; i < items.length; i++) { if (i == 5) { @@ -194,9 +166,9 @@ public class CustomizeLayoutMenu extends FrameLayout { ToastUtils.showSuccess("布局保存成功"); }).show(); }); - tvImportLayout.setOnClickListener(v -> importLayout()); - tvExportLayout.setOnClickListener(v -> exportLayout()); - tvResetLayout.setOnClickListener(v -> { + binding.tvImportLayout.setOnClickListener(v -> importLayout()); + binding.tvExportLayout.setOnClickListener(v -> exportLayout()); + binding.tvResetLayout.setOnClickListener(v -> { DialogCreator.createCommonDialog(context, "重置布局", "重置布局将会恢复所有布局为默认状态,确定要重置吗?", true, (dialog, which) -> { @@ -211,7 +183,7 @@ public class CustomizeLayoutMenu extends FrameLayout { } public void setNavigationBarHeight(int height) { - vwNavigationBar.getLayoutParams().height = height; + binding.vwNavigationBar.getLayoutParams().height = height; } public void setAssetsBg(String path) { diff --git a/app/src/main/java/xyz/fycz/myreader/ui/popmenu/ReadSettingMenu.java b/app/src/main/java/xyz/fycz/myreader/ui/popmenu/ReadSettingMenu.java index a4492e6..17c7242 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/popmenu/ReadSettingMenu.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/popmenu/ReadSettingMenu.java @@ -6,74 +6,25 @@ import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.FrameLayout; -import android.widget.ImageView; -import android.widget.SeekBar; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; -import butterknife.BindView; -import butterknife.ButterKnife; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.SysManager; +import xyz.fycz.myreader.databinding.MenuReadSettingBinding; import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.enums.Language; import xyz.fycz.myreader.ui.activity.ReadActivity; import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.MyAlertDialog; -import xyz.fycz.myreader.util.BrightUtil; import xyz.fycz.myreader.util.ToastUtils; -import xyz.fycz.myreader.widget.custom.CircleImageView; import xyz.fycz.myreader.widget.page.PageMode; public class ReadSettingMenu extends FrameLayout { - @BindView(R.id.tv_reduce_text_size) - TextView tvReduceTextSize; - @BindView(R.id.tv_text_size) - TextView tvTextSize; - @BindView(R.id.tv_increase_text_size) - TextView tvIncreaseTextSize; - @BindView(R.id.tv_switch_st) - TextView tvSwitchST; - @BindView(R.id.tv_text_font) - TextView tvTextFont; - @BindView(R.id.iv_line_spacing4) - View ivLineSpacing4; - @BindView(R.id.iv_line_spacing3) - View ivLineSpacing3; - @BindView(R.id.iv_line_spacing2) - View ivLineSpacing2; - @BindView(R.id.tv_line_spacing1) - View tvLineSpacing1; - @BindView(R.id.tv_line_spacing0) - View tvLineSpacing0; - @BindView(R.id.tv_intent) - TextView tvIntent; - @BindView(R.id.iv_common_style) - CircleImageView ivCommonStyle; - @BindView(R.id.iv_leather_style) - CircleImageView ivLeatherStyle; - @BindView(R.id.iv_protect_eye_style) - CircleImageView ivProtectEyeStyle; - @BindView(R.id.iv_breen_style) - CircleImageView ivBreenStyle; - @BindView(R.id.iv_blue_deep_style) - CircleImageView ivBlueStyle; - @BindView(R.id.iv_custom_style) - ImageView ivCustomStyle; - @BindView(R.id.read_tv_auto_page) - TextView tvAutoPage; - @BindView(R.id.read_tv_page_mode) - TextView tvPageMode; - @BindView(R.id.read_tv_hv_screen) - TextView tvHVScreen; - @BindView(R.id.read_tv_more_setting) - TextView tvMoreSetting; - @BindView(R.id.vwNavigationBar) - View vwNavigationBar; + + private MenuReadSettingBinding binding; private View vLastLineSpacing = null; @@ -100,8 +51,7 @@ public class ReadSettingMenu extends FrameLayout { } private void init(Context context) { - View view = LayoutInflater.from(context).inflate(R.layout.menu_read_setting, this); - ButterKnife.bind(this, view); + binding = MenuReadSettingBinding.inflate(LayoutInflater.from(context), this, true); } public void setListener(Activity activity, Callback callback) { @@ -112,11 +62,11 @@ public class ReadSettingMenu extends FrameLayout { } public void setNavigationBarHeight(int height) { - vwNavigationBar.getLayoutParams().height = height; + binding.vwNavigationBar.getLayoutParams().height = height; } private void initWidget() { - tvTextSize.setText(String.valueOf(setting.getReadWordSize())); + binding.tvTextSize.setText(String.valueOf(setting.getReadWordSize())); initSwitchST(false); initComposition(); initStyleImage(); @@ -126,9 +76,9 @@ public class ReadSettingMenu extends FrameLayout { private void initListener() { //减小字体 - tvReduceTextSize.setOnClickListener(v -> { + binding.tvReduceTextSize.setOnClickListener(v -> { if (setting.getReadWordSize() > 10) { - tvTextSize.setText(String.valueOf(setting.getReadWordSize() - 1)); + binding.tvTextSize.setText(String.valueOf(setting.getReadWordSize() - 1)); setting.setReadWordSize(setting.getReadWordSize() - 1); SysManager.saveSetting(setting); if (callback != null) { @@ -137,9 +87,9 @@ public class ReadSettingMenu extends FrameLayout { } }); //增大字体 - tvIncreaseTextSize.setOnClickListener(v -> { + binding.tvIncreaseTextSize.setOnClickListener(v -> { if (setting.getReadWordSize() < 60) { - tvTextSize.setText(String.valueOf(setting.getReadWordSize() + 1)); + binding.tvTextSize.setText(String.valueOf(setting.getReadWordSize() + 1)); setting.setReadWordSize(setting.getReadWordSize() + 1); SysManager.saveSetting(setting); if (callback != null) { @@ -148,24 +98,24 @@ public class ReadSettingMenu extends FrameLayout { } }); //繁简切换 - tvSwitchST.setOnClickListener(v -> { + binding.tvSwitchSt.setOnClickListener(v -> { initSwitchST(true); callback.onRefreshUI(); }); //字体选择 - tvTextFont.setOnClickListener(v -> callback.onFontClick()); + binding.tvTextFont.setOnClickListener(v -> callback.onFontClick()); //行距单倍 - ivLineSpacing4.setOnClickListener(v -> setLineSpacing(0.6f, 0.4f, 4)); + binding.ivLineSpacing4.setOnClickListener(v -> setLineSpacing(0.6f, 0.4f, 4)); //行距双倍 - ivLineSpacing3.setOnClickListener(v -> setLineSpacing(1.2f, 1.1f, 3)); + binding.ivLineSpacing3.setOnClickListener(v -> setLineSpacing(1.2f, 1.1f, 3)); //行距三倍 - ivLineSpacing2.setOnClickListener(v -> setLineSpacing(1.8f, 1.8f, 2)); + binding.ivLineSpacing2.setOnClickListener(v -> setLineSpacing(1.8f, 1.8f, 2)); //行距默认 - tvLineSpacing1.setOnClickListener(v -> setLineSpacing(1.0f, 0.9f, 1)); + binding.tvLineSpacing1.setOnClickListener(v -> setLineSpacing(1.0f, 0.9f, 1)); //自定义行距 - tvLineSpacing0.setOnClickListener(v -> ((ReadActivity) context).showCustomizeMenu()); + binding.tvLineSpacing0.setOnClickListener(v -> ((ReadActivity) context).showCustomizeMenu()); //缩进 - tvIntent.setOnClickListener(v -> { + binding.tvIntent.setOnClickListener(v -> { AlertDialog dialog = new AlertDialog.Builder(context, R.style.alertDialogTheme) .setTitle("缩进") .setSingleChoiceItems(context.getResources().getStringArray(R.array.indent), @@ -180,12 +130,12 @@ public class ReadSettingMenu extends FrameLayout { dialog.show(); }); //样式选择 - ivCommonStyle.setOnClickListener(v -> selectedStyle(0)); - ivLeatherStyle.setOnClickListener(v -> selectedStyle(1)); - ivProtectEyeStyle.setOnClickListener(v -> selectedStyle(2)); - ivBreenStyle.setOnClickListener(v -> selectedStyle(3)); - ivBlueStyle.setOnClickListener(v -> selectedStyle(4)); - ivCustomStyle.setOnClickListener(v -> { + binding.ivCommonStyle.setOnClickListener(v -> selectedStyle(0)); + binding.ivLeatherStyle.setOnClickListener(v -> selectedStyle(1)); + binding.ivProtectEyeStyle.setOnClickListener(v -> selectedStyle(2)); + binding.ivBreenStyle.setOnClickListener(v -> selectedStyle(3)); + binding.ivBlueDeepStyle.setOnClickListener(v -> selectedStyle(4)); + binding.ivCustomStyle.setOnClickListener(v -> { setting.saveLayout(5); if (setting.isDayStyle()) { selectedStyle(5); @@ -193,9 +143,9 @@ public class ReadSettingMenu extends FrameLayout { ((ReadActivity) context).showCustomizeLayoutMenu(); }); //自动翻页 - tvAutoPage.setOnClickListener(v -> callback.onAutoPageClick()); + binding.readTvAutoPage.setOnClickListener(v -> callback.onAutoPageClick()); //翻页模式 - tvPageMode.setOnClickListener(v -> { + binding.readTvPageMode.setOnClickListener(v -> { //显示翻页模式视图 int checkedItem; switch (setting.getPageMode()) { @@ -249,21 +199,21 @@ public class ReadSettingMenu extends FrameLayout { }).show(); }); //横屏竖屏切换 - tvHVScreen.setOnClickListener(v -> { + binding.readTvHvScreen.setOnClickListener(v -> { setting.setHorizontalScreen(!setting.isHorizontalScreen()); initHVScreen(); SysManager.saveSetting(setting); callback.onHVChange(); }); //更多设置 - tvMoreSetting.setOnClickListener(v -> callback.onMoreSettingClick()); + binding.readTvMoreSetting.setOnClickListener(v -> callback.onMoreSettingClick()); } private void initSwitchST(boolean isChange) { switch (setting.getLanguage()){ case normal: - tvSwitchST.setSelected(false); - tvSwitchST.setText("繁"); + binding.tvSwitchSt.setSelected(false); + binding.tvSwitchSt.setText("繁"); if (isChange){ setting.setLanguage(Language.traditional); ToastUtils.showInfo("已设置文本为简转繁"); @@ -271,8 +221,8 @@ public class ReadSettingMenu extends FrameLayout { } break; case traditional: - tvSwitchST.setSelected(true); - tvSwitchST.setText("繁"); + binding.tvSwitchSt.setSelected(true); + binding.tvSwitchSt.setText("繁"); if (isChange){ setting.setLanguage(Language.simplified); DialogCreator.createTipDialog(context, context.getString(R.string.traditional_to_simplified_tip)); @@ -280,8 +230,8 @@ public class ReadSettingMenu extends FrameLayout { } break; case simplified: - tvSwitchST.setSelected(true); - tvSwitchST.setText("简"); + binding.tvSwitchSt.setSelected(true); + binding.tvSwitchSt.setText("简"); if (isChange){ setting.setLanguage(Language.normal); ToastUtils.showInfo("已取消简转繁/繁转简,当前为原始文本"); @@ -295,41 +245,41 @@ public class ReadSettingMenu extends FrameLayout { } public void initStyleImage() { - ivCommonStyle.setImageDrawable(setting.getBgDrawable(0, context, 50, 50)); - ivLeatherStyle.setImageDrawable(setting.getBgDrawable(1, context, 50, 50)); - ivProtectEyeStyle.setImageDrawable(setting.getBgDrawable(2, context, 50, 50)); - ivBreenStyle.setImageDrawable(setting.getBgDrawable(3, context, 50, 50)); - ivBlueStyle.setImageDrawable(setting.getBgDrawable(4, context, 50, 50)); + binding.ivCommonStyle.setImageDrawable(setting.getBgDrawable(0, context, 50, 50)); + binding.ivLeatherStyle.setImageDrawable(setting.getBgDrawable(1, context, 50, 50)); + binding.ivProtectEyeStyle.setImageDrawable(setting.getBgDrawable(2, context, 50, 50)); + binding.ivBreenStyle.setImageDrawable(setting.getBgDrawable(3, context, 50, 50)); + binding.ivBlueDeepStyle.setImageDrawable(setting.getBgDrawable(4, context, 50, 50)); } public void initStyle() { if (!setting.isDayStyle()){ return; } - ivCommonStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text)); - ivLeatherStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text)); - ivProtectEyeStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text)); - ivBreenStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text)); - ivBlueStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text)); - ivCustomStyle.setSelected(false); + binding.ivCommonStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text)); + binding.ivLeatherStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text)); + binding.ivProtectEyeStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text)); + binding.ivBreenStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text)); + binding.ivBlueDeepStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text)); + binding.ivCustomStyle.setSelected(false); switch (setting.getCurReadStyleIndex()) { case 0: - ivCommonStyle.setBorderColor(context.getResources().getColor(R.color.sys_dialog_setting_word_red)); + binding.ivCommonStyle.setBorderColor(context.getResources().getColor(R.color.sys_dialog_setting_word_red)); break; case 1: - ivLeatherStyle.setBorderColor(context.getResources().getColor(R.color.sys_dialog_setting_word_red)); + binding.ivLeatherStyle.setBorderColor(context.getResources().getColor(R.color.sys_dialog_setting_word_red)); break; case 2: - ivProtectEyeStyle.setBorderColor(context.getResources().getColor(R.color.sys_dialog_setting_word_red)); + binding.ivProtectEyeStyle.setBorderColor(context.getResources().getColor(R.color.sys_dialog_setting_word_red)); break; case 3: - ivBreenStyle.setBorderColor(context.getResources().getColor(R.color.sys_dialog_setting_word_red)); + binding.ivBreenStyle.setBorderColor(context.getResources().getColor(R.color.sys_dialog_setting_word_red)); break; case 4: - ivBlueStyle.setBorderColor(context.getResources().getColor(R.color.sys_dialog_setting_word_red)); + binding.ivBlueDeepStyle.setBorderColor(context.getResources().getColor(R.color.sys_dialog_setting_word_red)); break; case 5: - ivCustomStyle.setSelected(true); + binding.ivCustomStyle.setSelected(true); break; } } @@ -340,28 +290,28 @@ public class ReadSettingMenu extends FrameLayout { } switch (setting.getComposition()){ case 0: - tvLineSpacing0.setSelected(true); - vLastLineSpacing = tvLineSpacing0; + binding.tvLineSpacing0.setSelected(true); + vLastLineSpacing = binding.tvLineSpacing0; break; case 1: - tvLineSpacing1.setSelected(true); - vLastLineSpacing = tvLineSpacing1; + binding.tvLineSpacing1.setSelected(true); + vLastLineSpacing = binding.tvLineSpacing1; break; case 2: - ivLineSpacing2.setSelected(true); - vLastLineSpacing = ivLineSpacing2; + binding.ivLineSpacing2.setSelected(true); + vLastLineSpacing = binding.ivLineSpacing2; break; case 3: - ivLineSpacing3.setSelected(true); - vLastLineSpacing = ivLineSpacing3; + binding.ivLineSpacing3.setSelected(true); + vLastLineSpacing = binding.ivLineSpacing3; break; case 4: - ivLineSpacing4.setSelected(true); - vLastLineSpacing = ivLineSpacing4; + binding.ivLineSpacing4.setSelected(true); + vLastLineSpacing = binding.ivLineSpacing4; break; default: - tvLineSpacing1.setSelected(true); - vLastLineSpacing = tvLineSpacing1; + binding.tvLineSpacing1.setSelected(true); + vLastLineSpacing = binding.tvLineSpacing1; break; } } @@ -369,9 +319,9 @@ public class ReadSettingMenu extends FrameLayout { private void initHVScreen(){ if (setting.isHorizontalScreen()){ - tvHVScreen.setText("竖屏阅读"); + binding.readTvHvScreen.setText("竖屏阅读"); }else { - tvHVScreen.setText("横屏阅读"); + binding.readTvHvScreen.setText("横屏阅读"); } } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/presenter/BookStorePresenter.java b/app/src/main/java/xyz/fycz/myreader/ui/presenter/BookStorePresenter.java deleted file mode 100644 index ae8bc89..0000000 --- a/app/src/main/java/xyz/fycz/myreader/ui/presenter/BookStorePresenter.java +++ /dev/null @@ -1,269 +0,0 @@ -package xyz.fycz.myreader.ui.presenter; - -import android.annotation.SuppressLint; -import android.content.Intent; -import android.os.Handler; -import android.os.Message; -import android.view.View; -import androidx.recyclerview.widget.LinearLayoutManager; -import xyz.fycz.myreader.base.BasePresenter; -import xyz.fycz.myreader.webapi.callback.ResultCallback; -import xyz.fycz.myreader.common.APPCONST; -import xyz.fycz.myreader.ui.dialog.ChangeSourceDialog; -import xyz.fycz.myreader.ui.dialog.DialogCreator; -import xyz.fycz.myreader.entity.bookstore.BookType; -import xyz.fycz.myreader.entity.bookstore.RankBook; -import xyz.fycz.myreader.greendao.entity.Book; -import xyz.fycz.myreader.ui.activity.BookDetailedActivity; -import xyz.fycz.myreader.ui.activity.MainActivity; -import xyz.fycz.myreader.ui.adapter.BookStoreBookAdapter; -import xyz.fycz.myreader.ui.adapter.BookStoreBookTypeAdapter; -import xyz.fycz.myreader.ui.fragment.BookStoreFragment; -import xyz.fycz.myreader.util.ToastUtils; -import xyz.fycz.myreader.webapi.crawler.find.QiDianMobileRank; - - -import java.util.ArrayList; -import java.util.List; - - -public class BookStorePresenter implements BasePresenter { - - private BookStoreFragment mBookStoreFragment; - private MainActivity mMainActivity; - private LinearLayoutManager mLinearLayoutManager; - private BookStoreBookTypeAdapter mBookStoreBookTypeAdapter; - private List mBookTypes; - - private BookStoreBookAdapter mBookStoreBookAdapter; - private List bookList = new ArrayList<>(); - - private BookType curType; - private QiDianMobileRank findCrawler; - - private int page = 1; - - @SuppressLint("HandlerLeak") - private Handler mHandler = new Handler() { - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case 1: - initTypeList(); - mBookStoreFragment.getmRlRefresh().showFinish(); - break; - case 2: - List bookList = (List) msg.obj; - initBookList(bookList); - mBookStoreFragment.getSrlBookList().setEnableRefresh(true); - mBookStoreFragment.getSrlBookList().setEnableLoadMore(true); - mBookStoreFragment.getPbLoading().setVisibility(View.GONE); - break; - case 3: - mBookStoreFragment.getPbLoading().setVisibility(View.VISIBLE); - break; - case 4: - mBookStoreFragment.getPbLoading().setVisibility(View.GONE); - mBookStoreFragment.getSrlBookList().finishRefresh(false); - mBookStoreFragment.getSrlBookList().finishLoadMore(false); - break; - case 5: - mBookStoreFragment.getmRlRefresh().showError(); - break; - } - } - }; - - public BookStorePresenter(BookStoreFragment bookStoreFragment) { - mBookStoreFragment = bookStoreFragment; - mMainActivity = ((MainActivity) (mBookStoreFragment.getActivity())); - } - - @Override - public void start() { - mBookStoreFragment.getSrlBookList().setEnableRefresh(false); - mBookStoreFragment.getSrlBookList().setEnableLoadMore(false); - findCrawler = new QiDianMobileRank(true); - //小说列表下拉加载更多事件 - mBookStoreFragment.getSrlBookList().setOnLoadMoreListener(refreshLayout -> { - page++; - BookStorePresenter.this.getBooksData(); - }); - - //小说列表上拉刷新事件 - mBookStoreFragment.getSrlBookList().setOnRefreshListener(refreshLayout -> { - page = 1; - BookStorePresenter.this.getBooksData(); - }); - - - mBookStoreBookAdapter = new BookStoreBookAdapter(findCrawler.hasImg(), mMainActivity); - mBookStoreFragment.getRvBookList().setLayoutManager(new LinearLayoutManager(mMainActivity)); - mBookStoreFragment.getRvBookList().setAdapter(mBookStoreBookAdapter); - mBookStoreBookAdapter.setOnItemClickListener((view, pos) -> { - Book book = bookList.get(pos); - if (!findCrawler.needSearch()) { - Intent intent = new Intent(mMainActivity, BookDetailedActivity.class); - intent.putExtra(APPCONST.BOOK, book); - mMainActivity.startActivity(intent); - } else { - mHandler.sendMessage(mHandler.obtainMessage(3)); - ChangeSourceDialog csd = new ChangeSourceDialog(mMainActivity, bookList.get(pos)); - csd.initOneBook(new ResultCallback() { - @Override - public void onFinish(Object o, int code) { - Book searchBook = (Book) o; - book.setChapterUrl(searchBook.getChapterUrl()); - book.setSource(searchBook.getSource()); - Intent intent = new Intent(mMainActivity, BookDetailedActivity.class); - intent.putExtra(APPCONST.BOOK, book); - mMainActivity.startActivity(intent); - mHandler.sendMessage(mHandler.obtainMessage(4)); - } - - @Override - public void onError(Exception e) { - DialogCreator.createTipDialog(mMainActivity,"未搜索到该书籍,无法进入书籍详情!"); - } - }); - } - }); - - getData(); - - mBookStoreFragment.getmRlRefresh().setOnReloadingListener(this::getData); - - } - - - /** - * 获取页面数据 - */ - private void getData() { - /*BookStoreApi.getBookTypeList(findCrawler, new ResultCallback() { - @Override - public void onFinish(Object o, int code) { - mBookTypes = (ArrayList) o; - curType = mBookTypes.get(0); - mHandler.sendMessage(mHandler.obtainMessage(1)); - page = 1; - getBooksData(); - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - mHandler.sendEmptyMessage(5); - } - });*/ - mBookTypes = findCrawler.getBookTypes(); - curType = mBookTypes.get(0); - mHandler.sendMessage(mHandler.obtainMessage(1)); - page = 1; - getBooksData(); - - - - } - - /** - * 获取小数列表数据 - */ - private void getBooksData() { - if (findCrawler.getTypePage(curType, page)) { - mBookStoreFragment.getSrlBookList().finishLoadMoreWithNoMoreData(); - return; - } - mHandler.sendEmptyMessage(3); - /*BookStoreApi.getBookRankList(curType.getUrl(), findCrawler, new ResultCallback() { - @Override - public void onFinish(Object o, int code) { - mHandler.sendMessage(mHandler.obtainMessage(2, o)); - } - - @Override - public void onError(Exception e) { - mHandler.sendMessage(mHandler.obtainMessage(4)); - ToastUtils.showError("数据加载失败!\n" + e.getMessage()); - e.printStackTrace(); - } - });*/ - findCrawler.getRankBooks(curType, new ResultCallback() { - @Override - public void onFinish(Object o, int code) { - List books = new ArrayList<>(); - for (RankBook rb : (List) o){ - Book book = new Book(); - book.setName(rb.getbName()); - book.setAuthor(rb.getbAuth()); - book.setImgUrl(rb.getImg()); - String cat = rb.getCat(); - book.setType(cat.contains("小说") || cat.length() >= 4 ? cat : cat + "小说"); - book.setNewestChapterTitle(rb.getDesc()); - book.setDesc(rb.getDesc()); - book.setUpdateDate(rb.getCnt()); - books.add(book); - } - mHandler.sendMessage(mHandler.obtainMessage(2, books)); - } - - @Override - public void onError(Exception e) { - mHandler.sendMessage(mHandler.obtainMessage(4)); - ToastUtils.showError("数据加载失败!\n" + e.getMessage()); - e.printStackTrace(); - } - }); - } - - - /** - * 初始化类别列表 - */ - private void initTypeList() { - - //设置布局管理器 - mLinearLayoutManager = new LinearLayoutManager(mBookStoreFragment.getActivity()); - mLinearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); - mBookStoreFragment.getRvTypeList().setLayoutManager(mLinearLayoutManager); - mBookStoreBookTypeAdapter = new BookStoreBookTypeAdapter(mBookStoreFragment.getActivity(), mBookTypes); - mBookStoreFragment.getRvTypeList().setAdapter(mBookStoreBookTypeAdapter); - - //点击事件 - mBookStoreBookTypeAdapter.setOnItemClickListener((pos, view) -> { - if (curType.equals(mBookTypes.get(pos))) { - return; - } - page = 1; - curType = mBookTypes.get(pos); - mBookStoreFragment.getSrlBookList().resetNoMoreData(); - BookStorePresenter.this.getBooksData(); - }); - - - } - - - /** - * 初始化小说列表 - */ - private void initBookList(List bookList) { - if (page == 1) { - mBookStoreBookAdapter.refreshItems(bookList); - this.bookList.clear(); - this.bookList.addAll(bookList); - mBookStoreFragment.getRvBookList().scrollToPosition(0); - } else { - this.bookList.addAll(bookList); - mBookStoreBookAdapter.addItems(bookList); - } - - //刷新动作完成 - mBookStoreFragment.getSrlBookList().finishRefresh(); - //加载更多完成 - mBookStoreFragment.getSrlBookList().finishLoadMore(); - - } - - -} diff --git a/app/src/main/res/layout/actiity_bookstore.xml b/app/src/main/res/layout/actiity_bookstore.xml index 9ab4adf..3a40e67 100644 --- a/app/src/main/res/layout/actiity_bookstore.xml +++ b/app/src/main/res/layout/actiity_bookstore.xml @@ -2,7 +2,6 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" - tools:context="xyz.fycz.myreader.ui.fragment.BookStoreFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorBackground" diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index 89cc520..42f2e57 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -7,12 +7,15 @@ android:orientation="vertical" tools:context=".ui.activity.AboutActivity"> - + - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_book_detail.xml b/app/src/main/res/layout/activity_book_detail.xml index 6b7fd0e..9460106 100644 --- a/app/src/main/res/layout/activity_book_detail.xml +++ b/app/src/main/res/layout/activity_book_detail.xml @@ -36,7 +36,9 @@ android:layout_height="190dp" android:scaleType="centerCrop"/>--> - + - + @@ -68,7 +72,9 @@ android:layout_gravity="bottom" android:orientation="vertical"> - + - diff --git a/app/src/main/res/layout/diallog_audio_player.xml b/app/src/main/res/layout/dialog_audio_player.xml similarity index 100% rename from app/src/main/res/layout/diallog_audio_player.xml rename to app/src/main/res/layout/dialog_audio_player.xml diff --git a/app/src/main/res/layout/dialog_book_source.xml b/app/src/main/res/layout/dialog_book_source.xml index 7a28cfc..e77d565 100644 --- a/app/src/main/res/layout/dialog_book_source.xml +++ b/app/src/main/res/layout/dialog_book_source.xml @@ -17,7 +17,9 @@ - + - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/version_code.properties b/app/version_code.properties index 18be550..29fe55d 100644 --- a/app/version_code.properties +++ b/app/version_code.properties @@ -1,2 +1,2 @@ -#Tue Jan 19 18:54:31 CST 2021 +#Mon Jan 25 21:29:58 CST 2021 VERSION_CODE=180 diff --git a/build.gradle b/build.gradle index 9538917..8edf102 100644 --- a/build.gradle +++ b/build.gradle @@ -8,13 +8,13 @@ buildscript { jcenter() mavenCentral() google() - maven { url 'http://s3.amazonaws.com/fabric-artifacts/public' } + maven { url 'https://s3.amazonaws.com/fabric-artifacts/public' } maven { url 'https://plugins.gradle.org/m2/' } maven { url "https://maven.java.net/content/groups/public/" } } dependencies { - classpath 'com.android.tools.build:gradle:3.6.2' - classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2' + classpath 'com.android.tools.build:gradle:4.1.2' + classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0' classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f5747c6..4917cf2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip