升级为viewBinding

pull/5/head
fengyuecanzhu 4 years ago
parent bbfe58c1db
commit a6dc3776a5
  1. BIN
      .idea/caches/build_file_checksums.ser
  2. 4
      .idea/modules.xml
  3. 13
      app/build.gradle
  4. BIN
      app/libs/sun.misc.BASE64Decoder.jar
  5. 28
      app/src/main/java/xyz/fycz/myreader/base/BaseActivity.java
  6. 20
      app/src/main/java/xyz/fycz/myreader/base/BaseFragment.java
  7. 16
      app/src/main/java/xyz/fycz/myreader/base/BaseTabActivity.java
  8. 44
      app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java
  9. 182
      app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java
  10. 87
      app/src/main/java/xyz/fycz/myreader/ui/activity/BookstoreActivity.java
  11. 31
      app/src/main/java/xyz/fycz/myreader/ui/activity/CatalogActivity.java
  12. 31
      app/src/main/java/xyz/fycz/myreader/ui/activity/FeedbackActivity.java
  13. 77
      app/src/main/java/xyz/fycz/myreader/ui/activity/FileSystemActivity.java
  14. 35
      app/src/main/java/xyz/fycz/myreader/ui/activity/FontsActivity.java
  15. 77
      app/src/main/java/xyz/fycz/myreader/ui/activity/LoginActivity.java
  16. 69
      app/src/main/java/xyz/fycz/myreader/ui/activity/MainActivity.java
  17. 231
      app/src/main/java/xyz/fycz/myreader/ui/activity/MoreSettingActivity.java
  18. 57
      app/src/main/java/xyz/fycz/myreader/ui/activity/QRCodeScanActivity.java
  19. 455
      app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java
  20. 76
      app/src/main/java/xyz/fycz/myreader/ui/activity/RegisterActivity.java
  21. 20
      app/src/main/java/xyz/fycz/myreader/ui/activity/RuleActivity.java
  22. 188
      app/src/main/java/xyz/fycz/myreader/ui/activity/SearchBookActivity.java
  23. 24
      app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java
  24. 199
      app/src/main/java/xyz/fycz/myreader/ui/dialog/AudioPlayerDialog.java
  25. 16
      app/src/main/java/xyz/fycz/myreader/ui/dialog/CopyContentDialog.java
  26. 57
      app/src/main/java/xyz/fycz/myreader/ui/dialog/SourceExchangeDialog.java
  27. 19
      app/src/main/java/xyz/fycz/myreader/ui/fragment/BookMarkFragment.java
  28. 84
      app/src/main/java/xyz/fycz/myreader/ui/fragment/BookStoreFragment.java
  29. 71
      app/src/main/java/xyz/fycz/myreader/ui/fragment/BookcaseFragment.java
  30. 32
      app/src/main/java/xyz/fycz/myreader/ui/fragment/CatalogFragment.java
  31. 57
      app/src/main/java/xyz/fycz/myreader/ui/fragment/FileCategoryFragment.java
  32. 55
      app/src/main/java/xyz/fycz/myreader/ui/fragment/FindFragment.java
  33. 31
      app/src/main/java/xyz/fycz/myreader/ui/fragment/LocalBookFragment.java
  34. 84
      app/src/main/java/xyz/fycz/myreader/ui/fragment/MineFragment.java
  35. 66
      app/src/main/java/xyz/fycz/myreader/ui/fragment/PrivateBooksFragment.java
  36. 59
      app/src/main/java/xyz/fycz/myreader/ui/fragment/WebDavFragment.java
  37. 30
      app/src/main/java/xyz/fycz/myreader/ui/popmenu/AutoPageMenu.java
  38. 59
      app/src/main/java/xyz/fycz/myreader/ui/popmenu/BrightnessEyeMenu.java
  39. 144
      app/src/main/java/xyz/fycz/myreader/ui/popmenu/CustomizeComMenu.java
  40. 70
      app/src/main/java/xyz/fycz/myreader/ui/popmenu/CustomizeLayoutMenu.java
  41. 180
      app/src/main/java/xyz/fycz/myreader/ui/popmenu/ReadSettingMenu.java
  42. 269
      app/src/main/java/xyz/fycz/myreader/ui/presenter/BookStorePresenter.java
  43. 1
      app/src/main/res/layout/actiity_bookstore.xml
  44. 7
      app/src/main/res/layout/activity_about.xml
  45. 12
      app/src/main/res/layout/activity_book_detail.xml
  46. 5
      app/src/main/res/layout/activity_file_system.xml
  47. 0
      app/src/main/res/layout/dialog_audio_player.xml
  48. 4
      app/src/main/res/layout/dialog_book_source.xml
  49. 58
      app/src/main/res/layout/fragment_book_store.xml
  50. 2
      app/version_code.properties
  51. 6
      build.gradle
  52. 2
      gradle/wrapper/gradle-wrapper.properties

@ -2,8 +2,8 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/.idea/modules/FYReader-master_-_内测.iml" filepath="$PROJECT_DIR$/.idea/modules/FYReader-master_-_内测.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/modules/FYReader-master.iml" filepath="$PROJECT_DIR$/.idea/modules/FYReader-master.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/app/FYReader-master_-_内测.app.iml" filepath="$PROJECT_DIR$/.idea/modules/app/FYReader-master_-_内测.app.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/modules/app/FYReader-master.app.iml" filepath="$PROJECT_DIR$/.idea/modules/app/FYReader-master.app.iml" />
</modules> </modules>
</component> </component>
</project> </project>

@ -60,12 +60,12 @@ android {
versionCode version versionCode version
versionName versionN versionName versionN
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath = true
}
} }
buildFeatures {
viewBinding true
} }
buildTypes { buildTypes {
release { release {
minifyEnabled false minifyEnabled false
@ -99,7 +99,6 @@ android {
} }
productFlavors { productFlavors {
} }
} }
@ -124,10 +123,6 @@ dependencies {
implementation "org.jetbrains.anko:anko-sdk27:$anko_version" implementation "org.jetbrains.anko:anko-sdk27:$anko_version"
implementation "org.jetbrains.anko:anko-sdk27-listeners:$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 //Glide
implementation 'com.github.bumptech.glide:glide:4.9.0' implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

@ -5,17 +5,17 @@ import android.content.Intent;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar; 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.CompositeDisposable;
import io.reactivex.disposables.Disposable; 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.entity.Setting;
import xyz.fycz.myreader.util.StatusBarUtil; import xyz.fycz.myreader.util.StatusBarUtil;
import java.lang.reflect.Method;
import java.util.ArrayList;
/** /**
* @author fengyue * @author fengyue
* @date 2020/8/12 20:02 * @date 2020/8/12 20:02
@ -37,17 +34,15 @@ public abstract class BaseActivity extends AppCompatActivity {
private static final int INVALID_VAL = -1; private static final int INVALID_VAL = -1;
protected CompositeDisposable mDisposable; protected CompositeDisposable mDisposable;
//ButterKnife
protected Toolbar mToolbar;
private Unbinder unbinder; protected Toolbar mToolbar;
private int curNightMode; private int curNightMode;
/****************************abstract area*************************************/ /****************************abstract area*************************************/
/**
@LayoutRes * 绑定视图
protected abstract int getContentId(); */
protected abstract void bindView();
/************************init area************************************/ /************************init area************************************/
protected void addDisposable(Disposable d){ protected void addDisposable(Disposable d){
if (mDisposable == null){ if (mDisposable == null){
@ -56,6 +51,7 @@ public abstract class BaseActivity extends AppCompatActivity {
mDisposable.add(d); mDisposable.add(d);
} }
/** /**
* 配置Toolbar * 配置Toolbar
* @param toolbar * @param toolbar
@ -108,8 +104,7 @@ public abstract class BaseActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
initTheme(); initTheme();
ActivityManage.addActivity(this); ActivityManage.addActivity(this);
setContentView(getContentId()); bindView();
unbinder = ButterKnife.bind(this);
initData(savedInstanceState); initData(savedInstanceState);
initToolbar(); initToolbar();
initWidget(); initWidget();
@ -138,7 +133,6 @@ public abstract class BaseActivity extends AppCompatActivity {
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
ActivityManage.removeActivity(this); ActivityManage.removeActivity(this);
unbinder.unbind();
if (mDisposable != null){ if (mDisposable != null){
mDisposable.dispose(); mDisposable.dispose();
} }

@ -1,15 +1,13 @@
package xyz.fycz.myreader.base; package xyz.fycz.myreader.base;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
@ -23,11 +21,11 @@ public abstract class BaseFragment extends Fragment {
protected CompositeDisposable mDisposable; protected CompositeDisposable mDisposable;
private View root = null; private View root = null;
protected Unbinder unbinder;
@LayoutRes
protected abstract int getContentId();
/**
* 绑定视图
*/
protected abstract View bindView(LayoutInflater inflater, ViewGroup container);
/*******************************init area*********************************/ /*******************************init area*********************************/
protected void addDisposable(Disposable d){ protected void addDisposable(Disposable d){
if (mDisposable == null){ if (mDisposable == null){
@ -62,8 +60,7 @@ public abstract class BaseFragment extends Fragment {
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
int resId = getContentId(); root = bindView(inflater, container);
root = inflater.inflate(resId,container,false);
return root; return root;
} }
@ -71,7 +68,6 @@ public abstract class BaseFragment extends Fragment {
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
initData(savedInstanceState); initData(savedInstanceState);
unbinder = ButterKnife.bind(this,root);
initWidget(savedInstanceState); initWidget(savedInstanceState);
initClick(); initClick();
processLogic(); processLogic();
@ -81,8 +77,6 @@ public abstract class BaseFragment extends Fragment {
public void onDetach() { public void onDetach() {
super.onDetach(); super.onDetach();
unbinder.unbind();
if (mDisposable != null){ if (mDisposable != null){
mDisposable.clear(); mDisposable.clear();
} }

@ -5,12 +5,13 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter; import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayout;
import xyz.fycz.myreader.R;
import java.util.List; import java.util.List;
import xyz.fycz.myreader.R;
/** /**
* @author fengyue * @author fengyue
* @date 2020/8/12 20:02 * @date 2020/8/12 20:02
@ -18,10 +19,9 @@ import java.util.List;
public abstract class BaseTabActivity extends BaseActivity { public abstract class BaseTabActivity extends BaseActivity {
/**************View***************/ /**************View***************/
@BindView(R.id.tab_tl_indicator)
protected TabLayout mTlIndicator; protected TabLayout mTlIndicator;
@BindView(R.id.tab_vp)
protected ViewPager mVp; protected ViewPager mVp;
/************Params*******************/ /************Params*******************/
private List<Fragment> mFragmentList; private List<Fragment> mFragmentList;
private List<String> mTitleList; private List<String> mTitleList;
@ -30,7 +30,14 @@ public abstract class BaseTabActivity extends BaseActivity {
protected abstract List<Fragment> createTabFragments(); protected abstract List<Fragment> createTabFragments();
protected abstract List<String> createTabTitles(); protected abstract List<String> createTabTitles();
@Override
protected void bindView() {
mTlIndicator = findViewById(R.id.tab_tl_indicator);
mVp = findViewById(R.id.tab_vp);
}
/*****************rewrite method***************************/ /*****************rewrite method***************************/
@Override @Override
protected void initWidget() { protected void initWidget() {
super.initWidget(); super.initWidget();
@ -61,6 +68,7 @@ public abstract class BaseTabActivity extends BaseActivity {
throw new IllegalArgumentException("fragment and title size must equal"); throw new IllegalArgumentException("fragment and title size must equal");
} }
/******************inner class*****************/ /******************inner class*****************/
class TabFragmentPageAdapter extends FragmentPagerAdapter { class TabFragmentPageAdapter extends FragmentPagerAdapter {

@ -5,14 +5,14 @@ import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.cardview.widget.CardView;
import butterknife.BindView;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.application.MyApplication;
import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.common.URLCONST; import xyz.fycz.myreader.common.URLCONST;
import xyz.fycz.myreader.databinding.ActivityAboutBinding;
import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.DialogCreator;
import xyz.fycz.myreader.util.ShareUtils; import xyz.fycz.myreader.util.ShareUtils;
import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.SharedPreUtils;
@ -23,26 +23,12 @@ import xyz.fycz.myreader.util.ToastUtils;
* @date 2020/9/18 22:21 * @date 2020/9/18 22:21
*/ */
public class AboutActivity extends BaseActivity { public class AboutActivity extends BaseActivity {
@BindView(R.id.tv_version_name) private ActivityAboutBinding binding;
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;
@Override @Override
protected int getContentId() { protected void bindView() {
return R.layout.activity_about; binding = ActivityAboutBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
} }
@Override @Override
@ -56,14 +42,14 @@ public class AboutActivity extends BaseActivity {
@Override @Override
protected void initWidget() { protected void initWidget() {
super.initWidget(); super.initWidget();
tvVersionName.setText("风月读书v" + MyApplication.getStrVersionName()); binding.il.tvVersionName.setText("风月读书v" + MyApplication.getStrVersionName());
} }
@Override @Override
protected void initClick() { protected void initClick() {
super.initClick(); super.initClick();
ClipboardManager mClipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager mClipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
vmAuthor.setOnClickListener(v -> { binding.il.vmAuthor.setOnClickListener(v -> {
//数据 //数据
ClipData mClipData = ClipData.newPlainText("Label", "fy@fycz.xyz"); ClipData mClipData = ClipData.newPlainText("Label", "fy@fycz.xyz");
//把数据设置到剪切板上 //把数据设置到剪切板上
@ -71,11 +57,11 @@ public class AboutActivity extends BaseActivity {
mClipboardManager.setPrimaryClip(mClipData); mClipboardManager.setPrimaryClip(mClipData);
ToastUtils.showSuccess("邮箱复制成功!"); 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))); SharedPreUtils.getInstance().getString(getString(R.string.downloadLink), URLCONST.LAN_ZOUS_URL)));
vmUpdate.setOnClickListener(v -> MyApplication.checkVersionByServer(this, true, null)); binding.il.vwUpdate.setOnClickListener(v -> MyApplication.checkVersionByServer(this, true, null));
vmUpdateLog.setOnClickListener(v -> DialogCreator.createAssetTipDialog(this, "更新日志", "updatelog.fy")); binding.il.vwUpdateLog.setOnClickListener(v -> DialogCreator.createAssetTipDialog(this, "更新日志", "updatelog.fy"));
vmQQ.setOnClickListener(v -> { binding.il.vwQq.setOnClickListener(v -> {
if (!MyApplication.joinQQGroup(this,"8PIOnHFuH6A38hgxvD_Rp2Bu-Ke1ToBn")){ if (!MyApplication.joinQQGroup(this,"8PIOnHFuH6A38hgxvD_Rp2Bu-Ke1ToBn")){
//数据 //数据
ClipData mClipData = ClipData.newPlainText("Label", "1085028304"); ClipData mClipData = ClipData.newPlainText("Label", "1085028304");
@ -85,8 +71,8 @@ public class AboutActivity extends BaseActivity {
ToastUtils.showError("未安装手Q或安装的版本不支持!\n已复制QQ群号,您可自行前往QQ添加!"); ToastUtils.showError("未安装手Q或安装的版本不支持!\n已复制QQ群号,您可自行前往QQ添加!");
} }
}); });
vmGit.setOnClickListener(v -> openIntent(Intent.ACTION_VIEW, getString(R.string.this_github_url))); binding.il.vwGit.setOnClickListener(v -> openIntent(Intent.ACTION_VIEW, getString(R.string.this_github_url)));
vmDisclaimer.setOnClickListener(v -> DialogCreator.createAssetTipDialog(this, "免责声明", "disclaimer.fy")); binding.il.vwDisclaimer.setOnClickListener(v -> DialogCreator.createAssetTipDialog(this, "免责声明", "disclaimer.fy"));
} }

@ -6,30 +6,21 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint; import android.text.TextPaint;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.*;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
import androidx.recyclerview.widget.LinearLayoutManager; 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.Glide;
import com.bumptech.glide.RequestBuilder; import com.bumptech.glide.RequestBuilder;
@ -37,6 +28,12 @@ import com.bumptech.glide.request.RequestOptions;
import com.google.zxing.EncodeHintType; import com.google.zxing.EncodeHintType;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; 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 cn.bingoogolapple.qrcode.zxing.QRCodeEncoder;
import io.reactivex.Single; import io.reactivex.Single;
import io.reactivex.SingleOnSubscribe; import io.reactivex.SingleOnSubscribe;
@ -47,78 +44,43 @@ import xyz.fycz.myreader.application.MyApplication;
import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.application.SysManager;
import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.base.observer.MySingleObserver; import xyz.fycz.myreader.base.observer.MySingleObserver;
import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.common.URLCONST; import xyz.fycz.myreader.common.URLCONST;
import xyz.fycz.myreader.databinding.ActivityBookDetailBinding;
import xyz.fycz.myreader.entity.SharedBook; 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.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.IOUtils;
import xyz.fycz.myreader.util.SharedPreUtils; 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.BitmapUtil;
import xyz.fycz.myreader.util.utils.BlurTransformation;
import xyz.fycz.myreader.util.utils.FileUtils; import xyz.fycz.myreader.util.utils.FileUtils;
import xyz.fycz.myreader.util.utils.GsonExtensionsKt; 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.RxUtils;
import xyz.fycz.myreader.util.utils.ScreenUtils;
import xyz.fycz.myreader.util.utils.StringUtils; import xyz.fycz.myreader.util.utils.StringUtils;
import xyz.fycz.myreader.webapi.CommonApi;
import xyz.fycz.myreader.webapi.callback.ResultCallback; import xyz.fycz.myreader.webapi.callback.ResultCallback;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil;
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.base.BookInfoCrawler; import xyz.fycz.myreader.webapi.crawler.base.BookInfoCrawler;
import xyz.fycz.myreader.webapi.crawler.base.ReadCrawler; 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 * @author fengyue
* @date 2020/8/17 11:39 * @date 2020/8/17 11:39
*/ */
public class BookDetailedActivity extends BaseActivity { 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 Book mBook;
private ArrayList<Book> aBooks; private ArrayList<Book> aBooks;
@ -151,11 +113,11 @@ public class BookDetailedActivity extends BaseActivity {
createChangeSourceDia(); createChangeSourceDia();
break; break;
case 3: case 3:
pbLoading.setVisibility(View.GONE); binding.pbLoading.setVisibility(View.GONE);
DialogCreator.createTipDialog(BookDetailedActivity.this, "未搜索到该书籍,书源加载失败!"); DialogCreator.createTipDialog(BookDetailedActivity.this, "未搜索到该书籍,书源加载失败!");
break; break;
case 4: case 4:
pbLoading.setVisibility(View.GONE); binding.pbLoading.setVisibility(View.GONE);
initOtherInfo(); initOtherInfo();
break; break;
} }
@ -163,8 +125,9 @@ public class BookDetailedActivity extends BaseActivity {
}; };
@Override @Override
protected int getContentId() { protected void bindView() {
return R.layout.activity_book_detail; binding = ActivityBookDetailBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
} }
@Override @Override
@ -201,8 +164,8 @@ public class BookDetailedActivity extends BaseActivity {
//catalog //catalog
mCatalogAdapter = new DetailCatalogAdapter(); mCatalogAdapter = new DetailCatalogAdapter();
bookDetailRvCatalog.setLayoutManager(new LinearLayoutManager(this)); binding.ic.bookDetailRvCatalog.setLayoutManager(new LinearLayoutManager(this));
bookDetailRvCatalog.setAdapter(mCatalogAdapter); binding.ic.bookDetailRvCatalog.setAdapter(mCatalogAdapter);
initChapters(false); initChapters(false);
@ -212,10 +175,10 @@ public class BookDetailedActivity extends BaseActivity {
goReadActivity(); goReadActivity();
}); });
mTvDisclaimer.setOnClickListener(v -> DialogCreator.createAssetTipDialog(this, "免责声明", "disclaimer.fy")); binding.ic.tvDisclaimer.setOnClickListener(v -> DialogCreator.createAssetTipDialog(this, "免责声明", "disclaimer.fy"));
if (isCollected) { if (isCollected) {
bookDetailTvAdd.setText("移除书籍"); binding.ib.bookDetailTvAdd.setText("移除书籍");
bookDetailTvOpen.setText("继续阅读"); binding.ib.bookDetailTvOpen.setText("继续阅读");
} }
//Dialog //Dialog
@ -241,7 +204,9 @@ public class BookDetailedActivity extends BaseActivity {
@Override @Override
protected void initClick() { protected void initClick() {
super.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) { if (!isCollected) {
mBook.setNoReadNum(mChapters.size()); mBook.setNoReadNum(mChapters.size());
mBook.setChapterTotalNum(0); mBook.setChapterTotalNum(0);
@ -253,7 +218,7 @@ public class BookDetailedActivity extends BaseActivity {
mChapterService.addChapters(mChapters); mChapterService.addChapters(mChapters);
isCollected = true; isCollected = true;
ToastUtils.showSuccess("成功加入书架"); ToastUtils.showSuccess("成功加入书架");
bookDetailTvAdd.setText("移除书籍"); binding.ib.bookDetailTvAdd.setText("移除书籍");
} else { } else {
mBookService.deleteBookById(mBook.getId()); mBookService.deleteBookById(mBook.getId());
isCollected = false; isCollected = false;
@ -261,11 +226,11 @@ public class BookDetailedActivity extends BaseActivity {
mBook.setHistoryChapterId("未开始阅读"); mBook.setHistoryChapterId("未开始阅读");
mBook.setLastReadPosition(0); mBook.setLastReadPosition(0);
ToastUtils.showSuccess("成功移除书籍"); ToastUtils.showSuccess("成功移除书籍");
bookDetailTvAdd.setText("加入书架"); binding.ib.bookDetailTvAdd.setText("加入书架");
bookDetailTvOpen.setText("开始阅读"); binding.ib.bookDetailTvOpen.setText("开始阅读");
} }
}); });
flOpenBook.setOnClickListener(view -> goReadActivity()); binding.ib.flOpenBook.setOnClickListener(view -> goReadActivity());
//换源对话框 //换源对话框
mSourceDialog.setOnSourceChangeListener((bean, pos) -> { 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 @Override
protected void processLogic() { protected void processLogic() {
super.processLogic(); super.processLogic();
@ -322,23 +306,23 @@ public class BookDetailedActivity extends BaseActivity {
* 初始化书籍信息 * 初始化书籍信息
*/ */
private void initBookInfo() { private void initBookInfo() {
mTvAuthor.setText(mBook.getAuthor()); binding.ih.bookDetailTvAuthor.setText(mBook.getAuthor());
if (StringHelper.isEmpty(mBook.getImgUrl())) { if (StringHelper.isEmpty(mBook.getImgUrl())) {
mBook.setImgUrl(""); mBook.setImgUrl("");
} }
assert mBook.getNewestChapterTitle() != null; assert mBook.getNewestChapterTitle() != null;
mTvDesc.setText(""); binding.ic.bookDetailTvDesc.setText("");
if (mBook.getType() != null) { if (mBook.getType() != null) {
mTvType.setText(mBook.getType()); binding.ih.bookDetailTvType.setText(mBook.getType());
} else { } else {
mTvType.setText(""); binding.ih.bookDetailTvType.setText("");
} }
if (!"null".equals(mBook.getSource())) { 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()); ReadCrawler rc = ReadCrawlerUtil.getReadCrawler(mBook.getSource());
if (rc instanceof BookInfoCrawler && StringHelper.isEmpty(mBook.getImgUrl())) { if (rc instanceof BookInfoCrawler && StringHelper.isEmpty(mBook.getImgUrl())) {
pbLoading.setVisibility(View.VISIBLE); binding.pbLoading.setVisibility(View.VISIBLE);
BookInfoCrawler bic = (BookInfoCrawler) rc; BookInfoCrawler bic = (BookInfoCrawler) rc;
CommonApi.getBookInfo(mBook, bic, new ResultCallback() { CommonApi.getBookInfo(mBook, bic, new ResultCallback() {
@Override @Override
@ -362,10 +346,10 @@ public class BookDetailedActivity extends BaseActivity {
* 初始化其他书籍信息 * 初始化其他书籍信息
*/ */
private void initOtherInfo() { private void initOtherInfo() {
mTvDesc.setText("\t\t\t\t" + mBook.getDesc()); binding.ic.bookDetailTvDesc.setText("\t\t\t\t" + mBook.getDesc());
mTvType.setText(mBook.getType()); binding.ih.bookDetailTvType.setText(mBook.getType());
if (!MyApplication.isDestroy(this)) { 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) /*Glide.with(this)
.load(mBook.getImgUrl()) .load(mBook.getImgUrl())
.transition(DrawableTransitionOptions.withCrossFade(1500)) .transition(DrawableTransitionOptions.withCrossFade(1500))
@ -598,26 +582,6 @@ public class BookDetailedActivity extends BaseActivity {
return super.onOptionsItemSelected(item); 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 lastReadPosition = data.getIntExtra(APPCONST.RESULT_LAST_READ_POSITION, 0);
int historyChapterPos = data.getIntExtra(APPCONST.RESULT_HISTORY_CHAPTER, 0); int historyChapterPos = data.getIntExtra(APPCONST.RESULT_HISTORY_CHAPTER, 0);
if (isCollected) { if (isCollected) {
bookDetailTvAdd.setText("移除书籍"); binding.ib.bookDetailTvAdd.setText("移除书籍");
bookDetailTvOpen.setText("继续阅读"); binding.ib.bookDetailTvOpen.setText("继续阅读");
this.isCollected = true; this.isCollected = true;
if (mChapters != null && mChapters.size() != 0) { if (mChapters != null && mChapters.size() != 0) {
mBook.setHistoryChapterId(mChapters.get(historyChapterPos).getTitle()); mBook.setHistoryChapterId(mChapters.get(historyChapterPos).getTitle());
@ -720,9 +684,9 @@ public class BookDetailedActivity extends BaseActivity {
int marginTop = 24; int marginTop = 24;
mIvCover.setDrawingCacheEnabled(true); binding.ih.bookDetailIvCover.setDrawingCacheEnabled(true);
Bitmap img = Bitmap.createBitmap(mIvCover.getDrawingCache()).copy(Bitmap.Config.ARGB_8888, true); Bitmap img = Bitmap.createBitmap(binding.ih.bookDetailIvCover.getDrawingCache()).copy(Bitmap.Config.ARGB_8888, true);
mIvCover.setDrawingCacheEnabled(false); binding.ih.bookDetailIvCover.setDrawingCacheEnabled(false);
img = BitmapUtil.getBitmap(img, 152, 209); img = BitmapUtil.getBitmap(img, 152, 209);
Canvas cv = new Canvas(back); Canvas cv = new Canvas(back);

@ -8,23 +8,19 @@ import android.os.Message;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ProgressBar;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView; import java.util.ArrayList;
import java.util.LinkedHashSet;
import com.scwang.smartrefresh.layout.SmartRefreshLayout; import java.util.List;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.application.MyApplication;
import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.webapi.callback.ResultCallback;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.databinding.ActiityBookstoreBinding;
import xyz.fycz.myreader.ui.dialog.SourceExchangeDialog;
import xyz.fycz.myreader.entity.bookstore.BookType; import xyz.fycz.myreader.entity.bookstore.BookType;
import xyz.fycz.myreader.entity.bookstore.QDBook; import xyz.fycz.myreader.entity.bookstore.QDBook;
import xyz.fycz.myreader.entity.bookstore.RankBook; 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.greendao.service.BookService;
import xyz.fycz.myreader.ui.adapter.BookStoreBookAdapter; import xyz.fycz.myreader.ui.adapter.BookStoreBookAdapter;
import xyz.fycz.myreader.ui.adapter.BookStoreBookTypeAdapter; 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.SharedPreUtils;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.webapi.BookStoreApi; 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.base.FindCrawler;
import xyz.fycz.myreader.webapi.crawler.find.QiDianMobileRank; 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 * @author fengyue
* @date 2020/9/13 21:11 * @date 2020/9/13 21:11
*/ */
public class BookstoreActivity extends BaseActivity { public class BookstoreActivity extends BaseActivity {
@BindView(R.id.refresh_layout) private ActiityBookstoreBinding binding;
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 FindCrawler findCrawler; private FindCrawler findCrawler;
private LinearLayoutManager mLinearLayoutManager; private LinearLayoutManager mLinearLayoutManager;
@ -83,25 +67,25 @@ public class BookstoreActivity extends BaseActivity {
switch (msg.what) { switch (msg.what) {
case 1: case 1:
initTypeList(); initTypeList();
mRlRefresh.showFinish(); binding.refreshLayout.showFinish();
break; break;
case 2: case 2:
List<Book> bookList = (List<Book>) msg.obj; List<Book> bookList = (List<Book>) msg.obj;
initBookList(bookList); initBookList(bookList);
srlBookList.setEnableRefresh(true); binding.srlBookList.setEnableRefresh(true);
srlBookList.setEnableLoadMore(true); binding.srlBookList.setEnableLoadMore(true);
pbLoading.setVisibility(View.GONE); binding.pbLoading.setVisibility(View.GONE);
break; break;
case 3: case 3:
pbLoading.setVisibility(View.VISIBLE); binding.pbLoading.setVisibility(View.VISIBLE);
break; break;
case 4: case 4:
pbLoading.setVisibility(View.GONE); binding.pbLoading.setVisibility(View.GONE);
srlBookList.finishRefresh(false); binding.srlBookList.finishRefresh(false);
srlBookList.finishLoadMore(false); binding.srlBookList.finishLoadMore(false);
break; break;
case 5: case 5:
mRlRefresh.showError(); binding.refreshLayout.showError();
break; break;
case 6: case 6:
DialogCreator.createTipDialog(BookstoreActivity.this, DialogCreator.createTipDialog(BookstoreActivity.this,
@ -112,8 +96,9 @@ public class BookstoreActivity extends BaseActivity {
}; };
@Override @Override
protected int getContentId() { protected void bindView() {
return R.layout.actiity_bookstore; binding = ActiityBookstoreBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
} }
@Override @Override
@ -139,24 +124,24 @@ public class BookstoreActivity extends BaseActivity {
@Override @Override
protected void initWidget() { protected void initWidget() {
super.initWidget(); super.initWidget();
srlBookList.setEnableRefresh(false); binding.srlBookList.setEnableRefresh(false);
srlBookList.setEnableLoadMore(false); binding.srlBookList.setEnableLoadMore(false);
//小说列表下拉加载更多事件 //小说列表下拉加载更多事件
srlBookList.setOnLoadMoreListener(refreshLayout -> { binding.srlBookList.setOnLoadMoreListener(refreshLayout -> {
page++; page++;
getBooksData(); getBooksData();
}); });
//小说列表上拉刷新事件 //小说列表上拉刷新事件
srlBookList.setOnRefreshListener(refreshLayout -> { binding.srlBookList.setOnRefreshListener(refreshLayout -> {
page = 1; page = 1;
getBooksData(); getBooksData();
}); });
mBookStoreBookAdapter = new BookStoreBookAdapter(findCrawler.hasImg(), this); mBookStoreBookAdapter = new BookStoreBookAdapter(findCrawler.hasImg(), this);
rvBookList.setLayoutManager(new LinearLayoutManager(this)); binding.rvBookList.setLayoutManager(new LinearLayoutManager(this));
rvBookList.setAdapter(mBookStoreBookAdapter); binding.rvBookList.setAdapter(mBookStoreBookAdapter);
mRlRefresh.setOnReloadingListener(this::getData); binding.refreshLayout.setOnReloadingListener(this::getData);
} }
@Override @Override
@ -236,7 +221,7 @@ public class BookstoreActivity extends BaseActivity {
@Override @Override
public void onError(Exception e) { public void onError(Exception e) {
if (MyApplication.isDestroy(BookstoreActivity.this)) return; if (MyApplication.isDestroy(BookstoreActivity.this)) return;
mRlRefresh.showError(); binding.refreshLayout.showError();
e.printStackTrace(); e.printStackTrace();
} }
}); });
@ -277,7 +262,7 @@ public class BookstoreActivity extends BaseActivity {
*/ */
private void getBooksData() { private void getBooksData() {
if (findCrawler.getTypePage(curType, page)) { if (findCrawler.getTypePage(curType, page)) {
srlBookList.finishLoadMoreWithNoMoreData(); binding.srlBookList.finishLoadMoreWithNoMoreData();
return; return;
} }
@ -346,9 +331,9 @@ public class BookstoreActivity extends BaseActivity {
//设置布局管理器 //设置布局管理器
mLinearLayoutManager = new LinearLayoutManager(this); mLinearLayoutManager = new LinearLayoutManager(this);
mLinearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); mLinearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
rvTypeList.setLayoutManager(mLinearLayoutManager); binding.rvTypeList.setLayoutManager(mLinearLayoutManager);
mBookStoreBookTypeAdapter = new BookStoreBookTypeAdapter(this, mBookTypes); mBookStoreBookTypeAdapter = new BookStoreBookTypeAdapter(this, mBookTypes);
rvTypeList.setAdapter(mBookStoreBookTypeAdapter); binding.rvTypeList.setAdapter(mBookStoreBookTypeAdapter);
//点击事件 //点击事件
mBookStoreBookTypeAdapter.setOnItemClickListener((pos, view) -> { mBookStoreBookTypeAdapter.setOnItemClickListener((pos, view) -> {
@ -357,7 +342,7 @@ public class BookstoreActivity extends BaseActivity {
} }
page = 1; page = 1;
curType = mBookTypes.get(pos); curType = mBookTypes.get(pos);
srlBookList.resetNoMoreData(); binding.srlBookList.resetNoMoreData();
getBooksData(); getBooksData();
}); });
@ -373,7 +358,7 @@ public class BookstoreActivity extends BaseActivity {
mBookStoreBookAdapter.refreshItems(bookList); mBookStoreBookAdapter.refreshItems(bookList);
this.bookList.clear(); this.bookList.clear();
this.bookList.addAll(bookList); this.bookList.addAll(bookList);
rvBookList.scrollToPosition(0); binding.rvBookList.scrollToPosition(0);
} else { } else {
this.bookList.addAll(bookList); this.bookList.addAll(bookList);
this.bookList = new ArrayList<>(new LinkedHashSet<>(this.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); mHandler.sendEmptyMessage(6);
return true; return true;
case R.id.action_refresh: case R.id.action_refresh:
mRlRefresh.showLoading(); binding.refreshLayout.showLoading();
getData(); getData();
return true; return true;
} }

@ -4,14 +4,14 @@ import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar; 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.R;
import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.databinding.ActivityCatalogBinding;
import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.ui.adapter.TabFragmentPageAdapter; import xyz.fycz.myreader.ui.adapter.TabFragmentPageAdapter;
import xyz.fycz.myreader.ui.fragment.BookMarkFragment; import xyz.fycz.myreader.ui.fragment.BookMarkFragment;
@ -23,12 +23,7 @@ import xyz.fycz.myreader.ui.fragment.CatalogFragment;
public class CatalogActivity extends BaseActivity { public class CatalogActivity extends BaseActivity {
@BindView(R.id.catalog_tab) private ActivityCatalogBinding binding;
TabLayout catalogTab;
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.catalog_vp)
ViewPager viewPager;
private SearchView searchView; private SearchView searchView;
private Book mBook; private Book mBook;
@ -41,6 +36,12 @@ public class CatalogActivity extends BaseActivity {
return mBook; return mBook;
} }
@Override
protected void bindView() {
binding = ActivityCatalogBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
}
/*********************Initialization****************************/ /*********************Initialization****************************/
@ -50,10 +51,6 @@ public class CatalogActivity extends BaseActivity {
mBook = (Book) getIntent().getSerializableExtra(APPCONST.BOOK); mBook = (Book) getIntent().getSerializableExtra(APPCONST.BOOK);
} }
@Override
protected int getContentId() {
return R.layout.activity_catalog;
}
@Override @Override
protected void setUpToolbar(Toolbar toolbar) { protected void setUpToolbar(Toolbar toolbar) {
@ -67,9 +64,9 @@ public class CatalogActivity extends BaseActivity {
@Override @Override
protected void initWidget() { protected void initWidget() {
super.initWidget(); super.initWidget();
viewPager.setAdapter(tabAdapter); binding.catalogVp.setAdapter(tabAdapter);
viewPager.setOffscreenPageLimit(2); binding.catalogVp.setOffscreenPageLimit(2);
catalogTab.setupWithViewPager(viewPager); binding.catalogTab.setupWithViewPager(binding.catalogVp);
} }
@ -90,7 +87,7 @@ public class CatalogActivity extends BaseActivity {
@Override @Override
public boolean onQueryTextChange(String newText) { public boolean onQueryTextChange(String newText) {
switch (viewPager.getCurrentItem()){ switch (binding.catalogVp.getCurrentItem()){
case 0: case 0:
((CatalogFragment) tabAdapter.getItem(0)).getmCatalogPresent().startSearch(newText); ((CatalogFragment) tabAdapter.getItem(0)).getmCatalogPresent().startSearch(newText);
break; break;

@ -1,7 +1,6 @@
package xyz.fycz.myreader.ui.activity; package xyz.fycz.myreader.ui.activity;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Dialog;
import android.webkit.WebChromeClient; import android.webkit.WebChromeClient;
import android.webkit.WebResourceError; import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest; import android.webkit.WebResourceRequest;
@ -11,26 +10,24 @@ import android.webkit.WebViewClient;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import butterknife.BindView;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.application.MyApplication;
import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.databinding.ActivityFeedbackBinding;
import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.DialogCreator;
import xyz.fycz.myreader.widget.RefreshLayout;
/** /**
* @author fengyue * @author fengyue
* @date 2020/12/24 20:48 * @date 2020/12/24 20:48
*/ */
public class FeedbackActivity extends BaseActivity { public class FeedbackActivity extends BaseActivity {
@BindView(R.id.refresh_layout)
RefreshLayout mRlRefresh; private ActivityFeedbackBinding binding;
@BindView(R.id.wv_feedback)
WebView wvFeedback;
@Override @Override
protected int getContentId() { protected void bindView() {
return R.layout.activity_feedback; binding =ActivityFeedbackBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
} }
@Override @Override
@ -45,12 +42,12 @@ public class FeedbackActivity extends BaseActivity {
protected void initWidget() { protected void initWidget() {
super.initWidget(); super.initWidget();
//声明WebSettings子类 //声明WebSettings子类
WebSettings webSettings = wvFeedback.getSettings(); WebSettings webSettings = binding.wvFeedback.getSettings();
//如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript //如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript
webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptEnabled(true);
wvFeedback.loadUrl("https://www.wjx.cn/jq/102348283.aspx"); binding.wvFeedback.loadUrl("https://www.wjx.cn/jq/102348283.aspx");
wvFeedback.setWebViewClient(new WebViewClient(){ binding.wvFeedback.setWebViewClient(new WebViewClient(){
@Override @Override
public boolean shouldOverrideUrlLoading(WebView view, String url) { public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!url.endsWith("102348283.aspx")){ if (!url.endsWith("102348283.aspx")){
@ -70,14 +67,14 @@ public class FeedbackActivity extends BaseActivity {
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error); super.onReceivedError(view, request, error);
if (!MyApplication.isDestroy(FeedbackActivity.this)) if (!MyApplication.isDestroy(FeedbackActivity.this))
mRlRefresh.showError(); binding.refreshLayout.showError();
} }
}); });
wvFeedback.setWebChromeClient(new WebChromeClient(){ binding.wvFeedback.setWebChromeClient(new WebChromeClient(){
@Override @Override
public void onProgressChanged(WebView view, int newProgress) { public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100 && !MyApplication.isDestroy(FeedbackActivity.this)){ if (newProgress == 100 && !MyApplication.isDestroy(FeedbackActivity.this)){
mRlRefresh.showFinish(); binding.refreshLayout.showFinish();
} }
}}); }});
} }
@ -85,8 +82,8 @@ public class FeedbackActivity extends BaseActivity {
@Override @Override
protected void initClick() { protected void initClick() {
super.initClick(); super.initClick();
mRlRefresh.setOnReloadingListener(() -> { binding.refreshLayout.setOnReloadingListener(() -> {
wvFeedback.loadUrl("https://www.wjx.cn/jq/102348283.aspx"); binding.wvFeedback.loadUrl("https://www.wjx.cn/jq/102348283.aspx");
}); });
} }
} }

@ -1,30 +1,28 @@
package xyz.fycz.myreader.ui.activity; package xyz.fycz.myreader.ui.activity;
import android.widget.Button;
import android.widget.CheckBox;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager; 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.R;
import xyz.fycz.myreader.base.BaseTabActivity; 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.enums.BookSource;
import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.greendao.service.BookService; 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.BaseFileFragment;
import xyz.fycz.myreader.ui.fragment.FileCategoryFragment; import xyz.fycz.myreader.ui.fragment.FileCategoryFragment;
import xyz.fycz.myreader.ui.fragment.LocalBookFragment; import xyz.fycz.myreader.ui.fragment.LocalBookFragment;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/** /**
* @author fengyue * @author fengyue
* @date 2020/8/12 20:02 * @date 2020/8/12 20:02
@ -33,12 +31,7 @@ import java.util.List;
public class FileSystemActivity extends BaseTabActivity { public class FileSystemActivity extends BaseTabActivity {
private static final String TAG = "FileSystemActivity"; private static final String TAG = "FileSystemActivity";
@BindView(R.id.file_system_cb_selected_all) private ActivityFileSystemBinding binding;
CheckBox mCbSelectAll;
@BindView(R.id.file_system_btn_delete)
Button mBtnDelete;
@BindView(R.id.file_system_btn_add_book)
Button mBtnAddBook;
private LocalBookFragment mLocalFragment; private LocalBookFragment mLocalFragment;
private FileCategoryFragment mCategoryFragment; 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 @Override
protected List<Fragment> createTabFragments() { protected List<Fragment> createTabFragments() {
mLocalFragment = new LocalBookFragment(); mLocalFragment = new LocalBookFragment();
@ -73,11 +73,6 @@ public class FileSystemActivity extends BaseTabActivity {
return Arrays.asList("智能导入","手机目录"); return Arrays.asList("智能导入","手机目录");
} }
@Override
protected int getContentId() {
return R.layout.activity_file_system;
}
@Override @Override
protected void setUpToolbar(Toolbar toolbar) { protected void setUpToolbar(Toolbar toolbar) {
super.setUpToolbar(toolbar); super.setUpToolbar(toolbar);
@ -88,10 +83,10 @@ public class FileSystemActivity extends BaseTabActivity {
@Override @Override
protected void initClick() { protected void initClick() {
super.initClick(); super.initClick();
mCbSelectAll.setOnClickListener( binding.fileSystemCbSelectedAll.setOnClickListener(
(view) -> { (view) -> {
//设置全选状态 //设置全选状态
boolean isChecked = mCbSelectAll.isChecked(); boolean isChecked = binding.fileSystemCbSelectedAll.isChecked();
mCurFragment.setCheckedAll(isChecked); mCurFragment.setCheckedAll(isChecked);
//改变菜单状态 //改变菜单状态
changeMenuStatus(); changeMenuStatus();
@ -124,7 +119,7 @@ public class FileSystemActivity extends BaseTabActivity {
} }
}); });
mBtnAddBook.setOnClickListener( binding.fileSystemBtnAddBook.setOnClickListener(
(v) -> { (v) -> {
//获取选中的文件 //获取选中的文件
List<File> files = mCurFragment.getCheckedFiles(); List<File> files = mCurFragment.getCheckedFiles();
@ -144,7 +139,7 @@ public class FileSystemActivity extends BaseTabActivity {
} }
); );
mBtnDelete.setOnClickListener( binding.fileSystemBtnDelete.setOnClickListener(
(v) -> { (v) -> {
//弹出,确定删除文件吗。 //弹出,确定删除文件吗。
DialogCreator.createCommonDialog(this, "删除文件", "确定删除文件吗?", DialogCreator.createCommonDialog(this, "删除文件", "确定删除文件吗?",
@ -213,18 +208,18 @@ public class FileSystemActivity extends BaseTabActivity {
//点击、删除状态的设置 //点击、删除状态的设置
if (mCurFragment.getCheckedCount() == 0){ if (mCurFragment.getCheckedCount() == 0){
mBtnAddBook.setText(getString(R.string.file_add_shelf)); binding.fileSystemBtnAddBook.setText(getString(R.string.file_add_shelf));
//设置某些按钮的是否可点击 //设置某些按钮的是否可点击
setMenuClickable(false); setMenuClickable(false);
if (mCbSelectAll.isChecked()){ if (binding.fileSystemCbSelectedAll.isChecked()){
mCurFragment.setChecked(false); mCurFragment.setChecked(false);
mCbSelectAll.setChecked(mCurFragment.isCheckedAll()); binding.fileSystemCbSelectedAll.setChecked(mCurFragment.isCheckedAll());
} }
} }
else { else {
mBtnAddBook.setText(getString(R.string.file_add_shelves, mCurFragment.getCheckedCount())); binding.fileSystemBtnAddBook.setText(getString(R.string.file_add_shelves, mCurFragment.getCheckedCount()));
setMenuClickable(true); setMenuClickable(true);
//全选状态的设置 //全选状态的设置
@ -233,21 +228,21 @@ public class FileSystemActivity extends BaseTabActivity {
if (mCurFragment.getCheckedCount() == mCurFragment.getCheckableCount()){ if (mCurFragment.getCheckedCount() == mCurFragment.getCheckableCount()){
//设置为全选 //设置为全选
mCurFragment.setChecked(true); mCurFragment.setChecked(true);
mCbSelectAll.setChecked(mCurFragment.isCheckedAll()); binding.fileSystemCbSelectedAll.setChecked(mCurFragment.isCheckedAll());
} }
//如果曾今是全选则替换 //如果曾今是全选则替换
else if (mCurFragment.isCheckedAll()){ else if (mCurFragment.isCheckedAll()){
mCurFragment.setChecked(false); mCurFragment.setChecked(false);
mCbSelectAll.setChecked(mCurFragment.isCheckedAll()); binding.fileSystemCbSelectedAll.setChecked(mCurFragment.isCheckedAll());
} }
} }
//重置全选的文字 //重置全选的文字
if (mCurFragment.isCheckedAll()){ if (mCurFragment.isCheckedAll()){
mCbSelectAll.setText("取消"); binding.fileSystemCbSelectedAll.setText("取消");
} }
else { else {
mCbSelectAll.setText("全选"); binding.fileSystemCbSelectedAll.setText("全选");
} }
} }
@ -255,12 +250,12 @@ public class FileSystemActivity extends BaseTabActivity {
private void setMenuClickable(boolean isClickable){ private void setMenuClickable(boolean isClickable){
//设置是否可删除 //设置是否可删除
mBtnDelete.setEnabled(isClickable); binding.fileSystemBtnDelete.setEnabled(isClickable);
mBtnDelete.setClickable(isClickable); binding.fileSystemBtnDelete.setClickable(isClickable);
//设置是否可添加书籍 //设置是否可添加书籍
mBtnAddBook.setEnabled(isClickable); binding.fileSystemBtnAddBook.setEnabled(isClickable);
mBtnAddBook.setClickable(isClickable); binding.fileSystemBtnAddBook.setClickable(isClickable);
} }
/** /**
@ -272,12 +267,12 @@ public class FileSystemActivity extends BaseTabActivity {
//设置是否能够全选 //设置是否能够全选
if (count > 0){ if (count > 0){
mCbSelectAll.setClickable(true); binding.fileSystemCbSelectedAll.setClickable(true);
mCbSelectAll.setEnabled(true); binding.fileSystemCbSelectedAll.setEnabled(true);
} }
else { else {
mCbSelectAll.setClickable(false); binding.fileSystemCbSelectedAll.setClickable(false);
mCbSelectAll.setEnabled(false); binding.fileSystemCbSelectedAll.setEnabled(false);
} }
} }
} }

@ -8,26 +8,26 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.view.View; import android.view.View;
import android.widget.ListView;
import android.widget.ProgressBar;
import androidx.appcompat.widget.Toolbar; 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.R;
import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.databinding.ActivityFontsBinding;
import xyz.fycz.myreader.enums.Font; import xyz.fycz.myreader.enums.Font;
import xyz.fycz.myreader.ui.adapter.FontsAdapter; import xyz.fycz.myreader.ui.adapter.FontsAdapter;
import xyz.fycz.myreader.util.IOUtils; import xyz.fycz.myreader.util.IOUtils;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.utils.FileUtils; 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; 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 * @date 2020/9/19 12:04
*/ */
public class FontsActivity extends BaseActivity { public class FontsActivity extends BaseActivity {
@BindView(R.id.lv_fonts) private ActivityFontsBinding binding;
ListView lvFonts;
@BindView(R.id.pb_loading)
ProgressBar pbLoading;
private ArrayList<Font> mFonts; private ArrayList<Font> mFonts;
private FontsAdapter mFontsAdapter; private FontsAdapter mFontsAdapter;
@ -54,9 +51,11 @@ public class FontsActivity extends BaseActivity {
} }
} }
}; };
@Override @Override
protected int getContentId() { protected void bindView() {
return R.layout.activity_fonts; binding = ActivityFontsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
} }
@Override @Override
@ -76,8 +75,8 @@ public class FontsActivity extends BaseActivity {
protected void initWidget() { protected void initWidget() {
super.initWidget(); super.initWidget();
mFontsAdapter = new FontsAdapter(this, R.layout.listview_font_item, mFonts, this); mFontsAdapter = new FontsAdapter(this, R.layout.listview_font_item, mFonts, this);
lvFonts.setAdapter(mFontsAdapter); binding.lvFonts.setAdapter(mFontsAdapter);
pbLoading.setVisibility(View.GONE); binding.pbLoading.setVisibility(View.GONE);
} }
private void initFonts() { private void initFonts() {

@ -13,45 +13,32 @@ import android.text.TextWatcher;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar; 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.R;
import xyz.fycz.myreader.model.backup.UserService;
import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.webapi.callback.ResultCallback;
import xyz.fycz.myreader.common.APPCONST; 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.ui.dialog.DialogCreator;
import xyz.fycz.myreader.util.CodeUtil; import xyz.fycz.myreader.util.CodeUtil;
import xyz.fycz.myreader.util.CyptoUtils; import xyz.fycz.myreader.util.CyptoUtils;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.util.utils.NetworkUtils;
import xyz.fycz.myreader.util.utils.StringUtils; import xyz.fycz.myreader.util.utils.StringUtils;
import xyz.fycz.myreader.webapi.callback.ResultCallback;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author fengyue * @author fengyue
* @date 2020/9/18 22:27 * @date 2020/9/18 22:27
*/ */
public class LoginActivity extends BaseActivity implements TextWatcher { 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; private String code;
@SuppressLint("HandlerLeak") @SuppressLint("HandlerLeak")
@ -61,7 +48,7 @@ public class LoginActivity extends BaseActivity implements TextWatcher {
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
switch (msg.what) { switch (msg.what) {
case 1: case 1:
loginBtn.setEnabled(true); binding.btLogin.setEnabled(true);
break; break;
case 2: case 2:
createCaptcha(); createCaptcha();
@ -70,9 +57,11 @@ public class LoginActivity extends BaseActivity implements TextWatcher {
} }
}; };
@Override @Override
protected int getContentId() { protected void bindView() {
return R.layout.activity_login; binding = ActivityLoginBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
} }
@Override @Override
@ -92,22 +81,22 @@ public class LoginActivity extends BaseActivity implements TextWatcher {
super.initWidget(); super.initWidget();
mHandler.sendMessage(mHandler.obtainMessage(2)); mHandler.sendMessage(mHandler.obtainMessage(2));
String username = UserService.readUsername(); String username = UserService.readUsername();
user.getEditText().setText(username); binding.etUser.getEditText().setText(username);
user.getEditText().requestFocus(username.length()); binding.etUser.getEditText().requestFocus(username.length());
//监听内容改变 -> 控制按钮的点击状态 //监听内容改变 -> 控制按钮的点击状态
user.getEditText().addTextChangedListener(this); binding.etUser.getEditText().addTextChangedListener(this);
password.getEditText().addTextChangedListener(this); binding.etPassword.getEditText().addTextChangedListener(this);
etCaptcha.getEditText().addTextChangedListener(this); binding.etCaptcha.getEditText().addTextChangedListener(this);
} }
@Override @Override
protected void initClick() { protected void initClick() {
super.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)); 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, "验证码错误!"); DialogCreator.createTipDialog(this, "验证码错误!");
return; return;
} }
@ -116,9 +105,9 @@ public class LoginActivity extends BaseActivity implements TextWatcher {
return; return;
} }
ProgressDialog dialog = DialogCreator.createProgressDialog(this, null, "正在登陆..."); ProgressDialog dialog = DialogCreator.createProgressDialog(this, null, "正在登陆...");
loginBtn.setEnabled(false); binding.btLogin.setEnabled(false);
final String loginName = user.getEditText().getText().toString().trim(); final String loginName = binding.etUser.getEditText().getText().toString().trim();
String loginPwd = password.getEditText().getText().toString(); String loginPwd = binding.etPassword.getEditText().getText().toString();
final Map<String, String> userLoginInfo = new HashMap<>(); final Map<String, String> userLoginInfo = new HashMap<>();
userLoginInfo.put("loginName", loginName); userLoginInfo.put("loginName", loginName);
userLoginInfo.put("loginPwd", CyptoUtils.encode(APPCONST.KEY, loginPwd)); 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); Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(intent); startActivity(intent);
}); });
@ -166,7 +155,7 @@ public class LoginActivity extends BaseActivity implements TextWatcher {
public void createCaptcha() { public void createCaptcha() {
code = CodeUtil.getInstance().createCode(); code = CodeUtil.getInstance().createCode();
Bitmap codeBitmap = CodeUtil.getInstance().createBitmap(code); 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); (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
//2.隐藏键盘 //2.隐藏键盘
inputManager.hideSoftInputFromWindow(user.getWindowToken(),0); inputManager.hideSoftInputFromWindow(binding.etUser.getWindowToken(),0);
//3.取消焦点 //3.取消焦点
View focusView = getCurrentFocus(); View focusView = getCurrentFocus();
@ -218,14 +207,14 @@ public class LoginActivity extends BaseActivity implements TextWatcher {
//禁止输入中文 //禁止输入中文
StringUtils.isNotChinese(s); StringUtils.isNotChinese(s);
//判断两个输入框是否有内容 //判断两个输入框是否有内容
if (user.getEditText().getText().toString().length() > 0 && if (binding.etUser.getEditText().getText().toString().length() > 0 &&
password.getEditText().getText().toString().length() > 0 && binding.etPassword.getEditText().getText().toString().length() > 0 &&
etCaptcha.getEditText().getText().toString().length() > 0){ binding.etCaptcha.getEditText().getText().toString().length() > 0){
//按钮可以点击 //按钮可以点击
loginBtn.setEnabled(true); binding.btLogin.setEnabled(true);
}else{ }else{
//按钮不能点击 //按钮不能点击
loginBtn.setEnabled(false); binding.btLogin.setEnabled(false);
} }
} }
} }

@ -6,54 +6,44 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
import android.text.InputType;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.ActionMenuView;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter; import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import butterknife.BindView; import java.io.File;
import java.util.ArrayList;
import com.google.android.material.bottomnavigation.BottomNavigationView; import java.util.List;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.application.MyApplication;
import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.application.SysManager;
import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.databinding.ActivityMainBinding;
import xyz.fycz.myreader.entity.SharedBook; import xyz.fycz.myreader.entity.SharedBook;
import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.greendao.entity.BookGroup; import xyz.fycz.myreader.greendao.entity.BookGroup;
import xyz.fycz.myreader.greendao.service.BookGroupService; import xyz.fycz.myreader.greendao.service.BookGroupService;
import xyz.fycz.myreader.ui.dialog.DialogCreator; 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.dialog.MyAlertDialog;
import xyz.fycz.myreader.ui.fragment.BookcaseFragment; import xyz.fycz.myreader.ui.fragment.BookcaseFragment;
import xyz.fycz.myreader.ui.fragment.FindFragment; import xyz.fycz.myreader.ui.fragment.FindFragment;
import xyz.fycz.myreader.ui.fragment.MineFragment; import xyz.fycz.myreader.ui.fragment.MineFragment;
import xyz.fycz.myreader.util.CyptoUtils;
import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.SharedPreUtils;
import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.StringHelper;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.utils.FingerprintUtils;
import xyz.fycz.myreader.util.utils.GsonExtensionsKt; 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; 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 class MainActivity extends BaseActivity {
public static final String TAG = MainActivity.class.getSimpleName(); public static final String TAG = MainActivity.class.getSimpleName();
@BindView(R.id.bottom_navigation_view)
BottomNavigationView bottomNavigation; private ActivityMainBinding binding;
@BindView(R.id.view_pager_main)
ViewPager viewPagerMain;
private List<Fragment> mFragments = new ArrayList<>(); private List<Fragment> mFragments = new ArrayList<>();
private String[] titles; private String[] titles;
@ -77,8 +65,9 @@ public class MainActivity extends BaseActivity {
private MineFragment mMineFragment; private MineFragment mMineFragment;
@Override @Override
protected int getContentId() { protected void bindView() {
return R.layout.activity_main; binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
} }
@Override @Override
@ -120,8 +109,8 @@ public class MainActivity extends BaseActivity {
@Override @Override
protected void initWidget() { protected void initWidget() {
super.initWidget(); super.initWidget();
viewPagerMain.setOffscreenPageLimit(2); binding.viewPagerMain.setOffscreenPageLimit(2);
viewPagerMain.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager(), BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { binding.viewPagerMain.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager(), BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
@Override @Override
public int getCount() { public int getCount() {
return mFragments.size(); return mFragments.size();
@ -141,7 +130,7 @@ public class MainActivity extends BaseActivity {
super.initClick(); super.initClick();
mToolbar.setOnLongClickListener(v -> { mToolbar.setOnLongClickListener(v -> {
if (viewPagerMain.getCurrentItem() == 0 && !BookGroupService.getInstance().curGroupIsPrivate()){ if (binding.viewPagerMain.getCurrentItem() == 0 && !BookGroupService.getInstance().curGroupIsPrivate()){
goPrivateBookcase(); goPrivateBookcase();
return true; return true;
} }
@ -149,25 +138,25 @@ public class MainActivity extends BaseActivity {
}); });
//BottomNavigationView 点击事件监听 //BottomNavigationView 点击事件监听
bottomNavigation.setOnNavigationItemSelectedListener(menuItem -> { binding.bottomNavigationView.setOnNavigationItemSelectedListener(menuItem -> {
int menuId = menuItem.getItemId(); int menuId = menuItem.getItemId();
// 跳转指定页面:Fragment // 跳转指定页面:Fragment
switch (menuId) { switch (menuId) {
case R.id.menu_bookshelf: case R.id.menu_bookshelf:
viewPagerMain.setCurrentItem(0); binding.viewPagerMain.setCurrentItem(0);
break; break;
case R.id.menu_find_book: case R.id.menu_find_book:
viewPagerMain.setCurrentItem(1); binding.viewPagerMain.setCurrentItem(1);
break; break;
case R.id.menu_my_config: case R.id.menu_my_config:
viewPagerMain.setCurrentItem(2); binding.viewPagerMain.setCurrentItem(2);
break; break;
} }
return false; return false;
}); });
// ViewPager 滑动事件监听 // ViewPager 滑动事件监听
viewPagerMain.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { binding.viewPagerMain.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override @Override
public void onPageScrolled(int i, float v, int i1) { public void onPageScrolled(int i, float v, int i1) {
@ -176,7 +165,7 @@ public class MainActivity extends BaseActivity {
@Override @Override
public void onPageSelected(int i) { public void onPageSelected(int i) {
//将滑动到的页面对应的 menu 设置为选中状态 //将滑动到的页面对应的 menu 设置为选中状态
bottomNavigation.getMenu().getItem(i).setChecked(true); binding.bottomNavigationView.getMenu().getItem(i).setChecked(true);
getSupportActionBar().setTitle(titles[i]); getSupportActionBar().setTitle(titles[i]);
if (i == 0) { if (i == 0) {
getSupportActionBar().setSubtitle(groupName); getSupportActionBar().setSubtitle(groupName);
@ -230,7 +219,7 @@ public class MainActivity extends BaseActivity {
} }
public ViewPager getViewPagerMain() { public ViewPager getViewPagerMain() {
return viewPagerMain; return binding.viewPagerMain;
} }
/********************************Event***************************************/ /********************************Event***************************************/
@ -248,7 +237,7 @@ public class MainActivity extends BaseActivity {
@Override @Override
public boolean onPrepareOptionsMenu(Menu menu) { public boolean onPrepareOptionsMenu(Menu menu) {
if (viewPagerMain.getCurrentItem() == 0) { if (binding.viewPagerMain.getCurrentItem() == 0) {
if (mBookcaseFragment.getmBookcasePresenter() != null && mBookcaseFragment.getmBookcasePresenter().ismEditState()) { if (mBookcaseFragment.getmBookcasePresenter() != null && mBookcaseFragment.getmBookcasePresenter().ismEditState()) {
menu.findItem(R.id.action_finish).setVisible(true); menu.findItem(R.id.action_finish).setVisible(true);
@ -275,31 +264,27 @@ public class MainActivity extends BaseActivity {
if (mBookcaseFragment.isRecreate()) { if (mBookcaseFragment.isRecreate()) {
reLoadFragment(); reLoadFragment();
} }
switch (item.getItemId()) { int itemId = item.getItemId();
case R.id.action_search: if (itemId == R.id.action_search) {
Intent searchBookIntent = new Intent(this, SearchBookActivity.class); Intent searchBookIntent = new Intent(this, SearchBookActivity.class);
startActivity(searchBookIntent); startActivity(searchBookIntent);
return true; return true;
case R.id.action_finish: } else if (itemId == R.id.action_finish) {
mBookcaseFragment.getmBookcasePresenter().cancelEdit(); mBookcaseFragment.getmBookcasePresenter().cancelEdit();
invalidateOptionsMenu(); invalidateOptionsMenu();
return true; return true;
case R.id.action_change_group: } else if (itemId == R.id.action_change_group || itemId == R.id.action_group_man) {
case R.id.action_group_man:
if (!mBookcaseFragment.getmBookcasePresenter().hasOnGroupChangeListener()) { if (!mBookcaseFragment.getmBookcasePresenter().hasOnGroupChangeListener()) {
mBookcaseFragment.getmBookcasePresenter().addOnGroupChangeListener(() -> { mBookcaseFragment.getmBookcasePresenter().addOnGroupChangeListener(() -> {
groupName = SharedPreUtils.getInstance().getString(getString(R.string.curBookGroupName), "所有书籍"); groupName = SharedPreUtils.getInstance().getString(getString(R.string.curBookGroupName), "所有书籍");
getSupportActionBar().setSubtitle(groupName); getSupportActionBar().setSubtitle(groupName);
}); });
} }
break; } else if (itemId == R.id.action_edit) {
case R.id.action_edit:
invalidateOptionsMenu(); invalidateOptionsMenu();
break; } else if (itemId == R.id.action_qr_scan) {
case R.id.action_qr_scan:
Intent intent = new Intent(this, QRCodeScanActivity.class); Intent intent = new Intent(this, QRCodeScanActivity.class);
startActivityForResult(intent, APPCONST.REQUEST_QR_SCAN); startActivityForResult(intent, APPCONST.REQUEST_QR_SCAN);
break;
} }
return mBookcaseFragment.getmBookcasePresenter().onOptionsItemSelected(item); return mBookcaseFragment.getmBookcasePresenter().onOptionsItemSelected(item);
} }
@ -329,7 +314,7 @@ public class MainActivity extends BaseActivity {
}else { }else {
groupName = bookGroup.getName(); groupName = bookGroup.getName();
} }
if (viewPagerMain.getCurrentItem() == 0){ if (binding.viewPagerMain.getCurrentItem() == 0){
getSupportActionBar().setSubtitle(groupName); getSupportActionBar().setSubtitle(groupName);
} }
// MyApplication.checkVersionByServer(this); // MyApplication.checkVersionByServer(this);

@ -3,50 +3,46 @@ package xyz.fycz.myreader.ui.activity;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputType;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; 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.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SwitchCompat;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.FragmentTransaction; 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.R;
import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.application.MyApplication;
import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.application.SysManager;
import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.base.BaseFragment; import xyz.fycz.myreader.base.BaseFragment;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.greendao.service.BookGroupService; import xyz.fycz.myreader.databinding.ActivityMoreSettingBinding;
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.entity.Setting; import xyz.fycz.myreader.entity.Setting;
import xyz.fycz.myreader.enums.BookSource; import xyz.fycz.myreader.enums.BookSource;
import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.greendao.service.BookService; 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.PrivateBooksFragment;
import xyz.fycz.myreader.ui.fragment.WebDavFragment; 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.SharedPreUtils;
import xyz.fycz.myreader.util.ToastUtils; 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 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; 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 { public class MoreSettingActivity extends BaseActivity {
@BindView(R.id.sv_content)
ScrollView svContent; private ActivityMoreSettingBinding binding;
@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 boolean needRefresh; private boolean needRefresh;
private boolean upMenu; private boolean upMenu;
@ -165,8 +89,9 @@ public class MoreSettingActivity extends BaseActivity {
private BaseFragment curFragment; private BaseFragment curFragment;
@Override @Override
protected int getContentId() { protected void bindView() {
return R.layout.activity_more_setting; binding = ActivityMoreSettingBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
} }
@Override @Override
@ -213,16 +138,16 @@ public class MoreSettingActivity extends BaseActivity {
super.initWidget(); super.initWidget();
initSwitchStatus(); initSwitchStatus();
if (sortStyle == 1) { if (sortStyle == 1) {
mTvBookSort.setText(getString(R.string.time_sort)); binding.tvBookSort.setText(getString(R.string.time_sort));
} else if (sortStyle == 2) { } else if (sortStyle == 2) {
mTvBookSort.setText(getString(R.string.book_name_sort)); binding.tvBookSort.setText(getString(R.string.book_name_sort));
} }
if (isMatchChapter) { if (isMatchChapter) {
mRlMatchChapterSuitability.setVisibility(View.VISIBLE); binding.rlMatchChapterSuitability.setVisibility(View.VISIBLE);
} else { } 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 @Override
@ -254,21 +179,21 @@ public class MoreSettingActivity extends BaseActivity {
} }
private void initSwitchStatus() { private void initSwitchStatus() {
mScVolume.setChecked(isVolumeTurnPage); binding.scVolume.setChecked(isVolumeTurnPage);
mScAlwaysNext.setChecked(alwaysNext); binding.scAlwaysNext.setChecked(alwaysNext);
mScMatchChapter.setChecked(isMatchChapter); binding.scMatchChapter.setChecked(isMatchChapter);
mScAutoRefresh.setChecked(autoRefresh); binding.scAutoRefresh.setChecked(autoRefresh);
mScShowStatus.setChecked(isShowStatusBar); binding.scShowStatus.setChecked(isShowStatusBar);
mScLongPress.setChecked(isLongPress); binding.scLongPress.setChecked(isLongPress);
mScNoMenuTitle.setChecked(noMenuTitle); binding.scNoMenuTitle.setChecked(noMenuTitle);
mScReadAloudVolumeTurnPage.setChecked(readAloudVolumeTurnPage); binding.scReadAloudVolumeTurnPage.setChecked(readAloudVolumeTurnPage);
} }
@Override @Override
protected void initClick() { protected void initClick() {
super.initClick(); super.initClick();
mLlWebdav.setOnClickListener(v -> { binding.llWebdav.setOnClickListener(v -> {
svContent.setVisibility(View.GONE); binding.svContent.setVisibility(View.GONE);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (mWebDavFragment == null) { if (mWebDavFragment == null) {
mWebDavFragment = new WebDavFragment(); mWebDavFragment = new WebDavFragment();
@ -281,31 +206,31 @@ public class MoreSettingActivity extends BaseActivity {
setUpToolbar(); setUpToolbar();
}); });
mRlVolume.setOnClickListener( binding.rlVolume.setOnClickListener(
(v) -> { (v) -> {
if (isVolumeTurnPage) { if (isVolumeTurnPage) {
isVolumeTurnPage = false; isVolumeTurnPage = false;
} else { } else {
isVolumeTurnPage = true; isVolumeTurnPage = true;
} }
mScVolume.setChecked(isVolumeTurnPage); binding.scVolume.setChecked(isVolumeTurnPage);
mSetting.setVolumeTurnPage(isVolumeTurnPage); mSetting.setVolumeTurnPage(isVolumeTurnPage);
SysManager.saveSetting(mSetting); SysManager.saveSetting(mSetting);
} }
); );
mRlAlwaysNext.setOnClickListener( binding.rlAlwaysNext.setOnClickListener(
(v) -> { (v) -> {
if (alwaysNext) { if (alwaysNext) {
alwaysNext = false; alwaysNext = false;
} else { } else {
alwaysNext = true; alwaysNext = true;
} }
mScAlwaysNext.setChecked(alwaysNext); binding.scAlwaysNext.setChecked(alwaysNext);
mSetting.setAlwaysNext(alwaysNext); mSetting.setAlwaysNext(alwaysNext);
SysManager.saveSetting(mSetting); SysManager.saveSetting(mSetting);
} }
); );
mRlShowStatus.setOnClickListener( binding.rlShowStatus.setOnClickListener(
(v) -> { (v) -> {
needRefresh = true; needRefresh = true;
if (isShowStatusBar) { if (isShowStatusBar) {
@ -313,12 +238,12 @@ public class MoreSettingActivity extends BaseActivity {
} else { } else {
isShowStatusBar = true; isShowStatusBar = true;
} }
mScShowStatus.setChecked(isShowStatusBar); binding.scShowStatus.setChecked(isShowStatusBar);
mSetting.setShowStatusBar(isShowStatusBar); mSetting.setShowStatusBar(isShowStatusBar);
SysManager.saveSetting(mSetting); SysManager.saveSetting(mSetting);
} }
); );
mRlLongPress.setOnClickListener( binding.rlLongPress.setOnClickListener(
(v) -> { (v) -> {
needRefresh = false; needRefresh = false;
if (isLongPress) { if (isLongPress) {
@ -326,25 +251,25 @@ public class MoreSettingActivity extends BaseActivity {
} else { } else {
isLongPress = true; isLongPress = true;
} }
mScLongPress.setChecked(isLongPress); binding.scLongPress.setChecked(isLongPress);
mSetting.setCanSelectText(isLongPress); mSetting.setCanSelectText(isLongPress);
SysManager.saveSetting(mSetting); SysManager.saveSetting(mSetting);
} }
); );
mRlContentReplace.setOnClickListener(v -> startActivity(new Intent(this, RuleActivity.class))); binding.rlContentReplace.setOnClickListener(v -> startActivity(new Intent(this, RuleActivity.class)));
mRlReadAloudVolumeTurnPage.setOnClickListener( binding.rlReadAloudVolumeTurnPage.setOnClickListener(
(v) -> { (v) -> {
if (readAloudVolumeTurnPage) { if (readAloudVolumeTurnPage) {
readAloudVolumeTurnPage = false; readAloudVolumeTurnPage = false;
} else { } else {
readAloudVolumeTurnPage = true; readAloudVolumeTurnPage = true;
} }
mScReadAloudVolumeTurnPage.setChecked(readAloudVolumeTurnPage); binding.scReadAloudVolumeTurnPage.setChecked(readAloudVolumeTurnPage);
mSetting.setReadAloudVolumeTurnPage(readAloudVolumeTurnPage); mSetting.setReadAloudVolumeTurnPage(readAloudVolumeTurnPage);
SysManager.saveSetting(mSetting); SysManager.saveSetting(mSetting);
} }
); );
mRlNoMenuTitle.setOnClickListener( binding.rlNoMenuTitle.setOnClickListener(
(v) -> { (v) -> {
upMenu = true; upMenu = true;
if (noMenuTitle) { if (noMenuTitle) {
@ -352,13 +277,13 @@ public class MoreSettingActivity extends BaseActivity {
} else { } else {
noMenuTitle = true; noMenuTitle = true;
} }
mScNoMenuTitle.setChecked(noMenuTitle); binding.scNoMenuTitle.setChecked(noMenuTitle);
mSetting.setNoMenuChTitle(noMenuTitle); mSetting.setNoMenuChTitle(noMenuTitle);
SysManager.saveSetting(mSetting); SysManager.saveSetting(mSetting);
} }
); );
mLlBookSort.setOnClickListener(v -> { binding.llBookSort.setOnClickListener(v -> {
MyAlertDialog.build(this) MyAlertDialog.build(this)
.setTitle(getString(R.string.book_sort)) .setTitle(getString(R.string.book_sort))
.setSingleChoiceItems(R.array.book_sort, sortStyle, (dialog, which) -> { .setSingleChoiceItems(R.array.book_sort, sortStyle, (dialog, which) -> {
@ -366,40 +291,40 @@ public class MoreSettingActivity extends BaseActivity {
mSetting.setSortStyle(sortStyle); mSetting.setSortStyle(sortStyle);
SysManager.saveSetting(mSetting); SysManager.saveSetting(mSetting);
if (sortStyle == 0) { if (sortStyle == 0) {
mTvBookSort.setText(getString(R.string.manual_sort)); binding.tvBookSort.setText(getString(R.string.manual_sort));
if (!SharedPreUtils.getInstance().getBoolean("manualSortTip")) { if (!SharedPreUtils.getInstance().getBoolean("manualSortTip")) {
DialogCreator.createTipDialog(this, "可在书架编辑状态下长按移动书籍进行排序!"); DialogCreator.createTipDialog(this, "可在书架编辑状态下长按移动书籍进行排序!");
SharedPreUtils.getInstance().putBoolean("manualSortTip", true); SharedPreUtils.getInstance().putBoolean("manualSortTip", true);
} }
} else if (sortStyle == 1) { } else if (sortStyle == 1) {
mTvBookSort.setText(getString(R.string.time_sort)); binding.tvBookSort.setText(getString(R.string.time_sort));
} else if (sortStyle == 2) { } else if (sortStyle == 2) {
mTvBookSort.setText(getString(R.string.book_name_sort)); binding.tvBookSort.setText(getString(R.string.book_name_sort));
} }
dialog.dismiss(); dialog.dismiss();
}).setNegativeButton("取消", null).show(); }).setNegativeButton("取消", null).show();
}); });
mRlPrivateBookcase.setOnClickListener(v -> { binding.rlPrivateBookcase.setOnClickListener(v -> {
MyAlertDialog.showPrivateVerifyDia(this, needGoTo -> { MyAlertDialog.showPrivateVerifyDia(this, needGoTo -> {
showPrivateBooksFragment(); showPrivateBooksFragment();
}); });
}); });
mRlAutoRefresh.setOnClickListener( binding.rlAutoRefresh.setOnClickListener(
(v) -> { (v) -> {
if (autoRefresh) { if (autoRefresh) {
autoRefresh = false; autoRefresh = false;
} else { } else {
autoRefresh = true; autoRefresh = true;
} }
mScAutoRefresh.setChecked(autoRefresh); binding.scAutoRefresh.setChecked(autoRefresh);
mSetting.setRefreshWhenStart(autoRefresh); mSetting.setRefreshWhenStart(autoRefresh);
SysManager.saveSetting(mSetting); SysManager.saveSetting(mSetting);
} }
); );
mLlCloseRefresh.setOnClickListener(v -> { binding.llCloseRefresh.setOnClickListener(v -> {
MyApplication.runOnUiThread(() -> { MyApplication.runOnUiThread(() -> {
if (mCloseRefreshDia != null) { if (mCloseRefreshDia != null) {
mCloseRefreshDia.show(); mCloseRefreshDia.show();
@ -444,7 +369,7 @@ public class MoreSettingActivity extends BaseActivity {
}); });
}); });
mLlDisableSource.setOnClickListener(v -> { binding.llDisableSource.setOnClickListener(v -> {
if (mDisableSourceDia != null) { if (mDisableSourceDia != null) {
mDisableSourceDia.show(); mDisableSourceDia.show();
return; 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); View view = LayoutInflater.from(this).inflate(R.layout.dialog_number_picker, null);
NumberPicker threadPick = view.findViewById(R.id.number_picker); NumberPicker threadPick = view.findViewById(R.id.number_picker);
threadPick.setMaxValue(1024); threadPick.setMaxValue(1024);
@ -505,28 +430,28 @@ public class MoreSettingActivity extends BaseActivity {
.setPositiveButton("确定", (dialog, which) -> { .setPositiveButton("确定", (dialog, which) -> {
threadNum = threadPick.getValue(); threadNum = threadPick.getValue();
SharedPreUtils.getInstance().putInt(getString(R.string.threadNum), threadNum); 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) }).setNegativeButton("取消", null)
.show(); .show();
}); });
mRlMatchChapter.setOnClickListener( binding.rlMatchChapter.setOnClickListener(
(v) -> { (v) -> {
if (isMatchChapter) { if (isMatchChapter) {
isMatchChapter = false; isMatchChapter = false;
mRlMatchChapterSuitability.setVisibility(View.GONE); binding.rlMatchChapterSuitability.setVisibility(View.GONE);
} else { } else {
isMatchChapter = true; isMatchChapter = true;
mRlMatchChapterSuitability.setVisibility(View.VISIBLE); binding.rlMatchChapterSuitability.setVisibility(View.VISIBLE);
} }
mScMatchChapter.setChecked(isMatchChapter); binding.scMatchChapter.setChecked(isMatchChapter);
mSetting.setMatchChapter(isMatchChapter); mSetting.setMatchChapter(isMatchChapter);
SysManager.saveSetting(mSetting); SysManager.saveSetting(mSetting);
} }
); );
mLlDownloadAll.setOnClickListener(v -> { binding.llDownloadAll.setOnClickListener(v -> {
MyApplication.runOnUiThread(() -> { MyApplication.runOnUiThread(() -> {
if (mDownloadAllDia != null) { if (mDownloadAllDia != null) {
mDownloadAllDia.show(); 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()); binding.rlMatchChapterSuitability.setOnClickListener(v -> binding.scMatchChapterSuitability.performClick());
mRlResetScreen.setOnClickListener(v -> mScResetScreen.performClick()); binding.rlResetScreen.setOnClickListener(v -> binding.scResetScreen.performClick());
mRlCatheGap.setOnClickListener(v -> mScCatheGap.performClick()); binding.rlCatheGap.setOnClickListener(v -> binding.scCatheGap.performClick());
mRlDeleteCathe.setOnClickListener(v -> { binding.rlDeleteCathe.setOnClickListener(v -> {
MyApplication.runOnUiThread(() -> { MyApplication.runOnUiThread(() -> {
File catheFile = getCacheDir(); File catheFile = getCacheDir();
String catheFileSize = FileUtils.getFileSize(FileUtils.getDirSize(catheFile)); String catheFileSize = FileUtils.getFileSize(FileUtils.getDirSize(catheFile));
@ -630,7 +555,7 @@ public class MoreSettingActivity extends BaseActivity {
setResult(AppCompatActivity.RESULT_OK, result); setResult(AppCompatActivity.RESULT_OK, result);
super.finish(); super.finish();
} else { } else {
svContent.setVisibility(View.VISIBLE); binding.svContent.setVisibility(View.VISIBLE);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.hide(curFragment); ft.hide(curFragment);
ft.commit(); ft.commit();
@ -645,7 +570,7 @@ public class MoreSettingActivity extends BaseActivity {
ArrayAdapter<CharSequence> resetScreenAdapter = ArrayAdapter.createFromResource(this, ArrayAdapter<CharSequence> resetScreenAdapter = ArrayAdapter.createFromResource(this,
R.array.reset_screen_time, android.R.layout.simple_spinner_item); R.array.reset_screen_time, android.R.layout.simple_spinner_item);
resetScreenAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); resetScreenAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mScResetScreen.setAdapter(resetScreenAdapter); binding.scResetScreen.setAdapter(resetScreenAdapter);
int resetScreenSelection = 0; int resetScreenSelection = 0;
switch (resetScreenTime) { switch (resetScreenTime) {
@ -662,8 +587,8 @@ public class MoreSettingActivity extends BaseActivity {
resetScreenSelection = 3; resetScreenSelection = 3;
break; break;
} }
mScResetScreen.setSelection(resetScreenSelection); binding.scResetScreen.setSelection(resetScreenSelection);
mScResetScreen.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { binding.scResetScreen.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (position) { switch (position) {
@ -693,7 +618,7 @@ public class MoreSettingActivity extends BaseActivity {
ArrayAdapter<CharSequence> matchSuiAdapter = ArrayAdapter.createFromResource(this, ArrayAdapter<CharSequence> matchSuiAdapter = ArrayAdapter.createFromResource(this,
R.array.match_chapter_suitability, android.R.layout.simple_spinner_item); R.array.match_chapter_suitability, android.R.layout.simple_spinner_item);
matchSuiAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); matchSuiAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mScMatchChapterSuitability.setAdapter(matchSuiAdapter); binding.scMatchChapterSuitability.setAdapter(matchSuiAdapter);
if (matchChapterSuitability == 0.0) { if (matchChapterSuitability == 0.0) {
matchChapterSuitability = 0.7f; matchChapterSuitability = 0.7f;
@ -702,9 +627,9 @@ public class MoreSettingActivity extends BaseActivity {
} }
int matchSuiSelection = (int) (matchChapterSuitability * 10 - 5); 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 @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
matchChapterSuitability = (position + 5) * 1f / 10f; matchChapterSuitability = (position + 5) * 1f / 10f;
@ -721,7 +646,7 @@ public class MoreSettingActivity extends BaseActivity {
ArrayAdapter<CharSequence> catheGapAdapter = ArrayAdapter.createFromResource(this, ArrayAdapter<CharSequence> catheGapAdapter = ArrayAdapter.createFromResource(this,
R.array.cathe_chapter_gap, android.R.layout.simple_spinner_item); R.array.cathe_chapter_gap, android.R.layout.simple_spinner_item);
catheGapAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); catheGapAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mScCatheGap.setAdapter(catheGapAdapter); binding.scCatheGap.setAdapter(catheGapAdapter);
if (catheCap == 0) { if (catheCap == 0) {
catheCap = 150; catheCap = 150;
@ -730,9 +655,9 @@ public class MoreSettingActivity extends BaseActivity {
} }
int catheGapSelection = catheCap / 50 - 1; int catheGapSelection = catheCap / 50 - 1;
mScCatheGap.setSelection(catheGapSelection); binding.scCatheGap.setSelection(catheGapSelection);
mScCatheGap.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { binding.scCatheGap.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
catheCap = (position + 1) * 50; catheCap = (position + 1) * 50;
@ -769,7 +694,7 @@ public class MoreSettingActivity extends BaseActivity {
} }
private void showPrivateBooksFragment(){ private void showPrivateBooksFragment(){
svContent.setVisibility(View.GONE); binding.svContent.setVisibility(View.GONE);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (mPrivateBooksFragment == null) { if (mPrivateBooksFragment == null) {
mPrivateBooksFragment = new PrivateBooksFragment(); mPrivateBooksFragment = new PrivateBooksFragment();

@ -10,27 +10,18 @@ import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; 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.annotation.NonNull;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat; 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.core.QRCodeView;
import cn.bingoogolapple.qrcode.zxing.ZXingView;
import io.reactivex.Single; import io.reactivex.Single;
import io.reactivex.SingleOnSubscribe; import io.reactivex.SingleOnSubscribe;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.base.observer.MySingleObserver; import xyz.fycz.myreader.base.observer.MySingleObserver;
import xyz.fycz.myreader.databinding.ActivityQrcodeCaptureBinding;
import xyz.fycz.myreader.util.PermissionsChecker; import xyz.fycz.myreader.util.PermissionsChecker;
import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.StringHelper;
import xyz.fycz.myreader.util.ToastUtils; 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 { public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Delegate {
@BindView(R.id.zxingview)
ZXingView zxingview; private ActivityQrcodeCaptureBinding binding;
@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 final int REQUEST_QR_IMAGE = 202; private final int REQUEST_QR_IMAGE = 202;
private static final String CAMERA = "android.permission.CAMERA"; private static final String CAMERA = "android.permission.CAMERA";
@ -64,11 +47,11 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg
private String picPath; private String picPath;
@Override @Override
protected int getContentId() { protected void bindView() {
return R.layout.activity_qrcode_capture; binding = ActivityQrcodeCaptureBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
} }
@Override @Override
protected void setUpToolbar(Toolbar toolbar) { protected void setUpToolbar(Toolbar toolbar) {
super.setUpToolbar(toolbar); super.setUpToolbar(toolbar);
@ -81,16 +64,16 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg
*/ */
@Override @Override
protected void initData(Bundle savedInstanceState) { protected void initData(Bundle savedInstanceState) {
zxingview.setDelegate(this); binding.zxingview.setDelegate(this);
fabFlashlight.setOnClickListener(view -> { binding.fabFlashlight.setOnClickListener(view -> {
if (flashlightIsOpen) { if (flashlightIsOpen) {
flashlightIsOpen = false; flashlightIsOpen = false;
zxingview.closeFlashlight(); binding.zxingview.closeFlashlight();
tvFlashlight.setText(getString(R.string.light_contact)); binding.tvFlashlight.setText(getString(R.string.light_contact));
} else { } else {
flashlightIsOpen = true; flashlightIsOpen = true;
zxingview.openFlashlight(); binding.zxingview.openFlashlight();
tvFlashlight.setText(getString(R.string.close_contact)); binding.tvFlashlight.setText(getString(R.string.close_contact));
} }
}); });
} }
@ -107,13 +90,13 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg
@Override @Override
protected void onStop() { protected void onStop() {
zxingview.stopCamera(); // 关闭摄像头预览,并且隐藏扫描框 binding.zxingview.stopCamera(); // 关闭摄像头预览,并且隐藏扫描框
super.onStop(); super.onStop();
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
zxingview.onDestroy(); // 销毁二维码扫描控件 binding.zxingview.onDestroy(); // 销毁二维码扫描控件
super.onDestroy(); super.onDestroy();
} }
@ -142,10 +125,10 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg
@Override @Override
public void onCameraAmbientBrightnessChanged(boolean isDark) { public void onCameraAmbientBrightnessChanged(boolean isDark) {
if (isDark){ if (isDark){
llFlashLight.setVisibility(View.VISIBLE); binding.llFlashlight.setVisibility(View.VISIBLE);
}else { }else {
if (!flashlightIsOpen) { 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() { private void startScan() {
zxingview.setVisibility(View.VISIBLE); binding.zxingview.setVisibility(View.VISIBLE);
zxingview.startSpotAndShowRect(); // 显示扫描框,并开始识别 binding.zxingview.startSpotAndShowRect(); // 显示扫描框,并开始识别
} }
private void requestPermission() { private void requestPermission() {
@ -212,7 +195,7 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
zxingview.startSpotAndShowRect(); // 显示扫描框,并开始识别 binding.zxingview.startSpotAndShowRect(); // 显示扫描框,并开始识别
if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_QR_IMAGE) { if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_QR_IMAGE) {
picPath = getPath(this, data.getData()); picPath = getPath(this, data.getData());
@ -238,7 +221,7 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg
.subscribe(new MySingleObserver<Bitmap>() { .subscribe(new MySingleObserver<Bitmap>() {
@Override @Override
public void onSuccess(Bitmap bitmap) { public void onSuccess(Bitmap bitmap) {
zxingview.decodeQRCode(bitmap); binding.zxingview.decodeQRCode(bitmap);
} }
}); });
} }

@ -28,12 +28,7 @@ import android.view.WindowManager;
import android.view.animation.Animation; import android.view.animation.Animation;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;
import android.widget.FrameLayout; 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.SeekBar;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -41,8 +36,6 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat; 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.gyf.immersionbar.ImmersionBar;
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener; import com.jaredrummler.android.colorpicker.ColorPickerDialogListener;
@ -51,8 +44,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import butterknife.BindView;
import butterknife.OnClick;
import xyz.fycz.myreader.ActivityManage; import xyz.fycz.myreader.ActivityManage;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.MyApplication; 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.base.BaseActivity;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.common.URLCONST; import xyz.fycz.myreader.common.URLCONST;
import xyz.fycz.myreader.databinding.ActivityReadBinding;
import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.entity.Setting;
import xyz.fycz.myreader.enums.BookSource; import xyz.fycz.myreader.enums.BookSource;
import xyz.fycz.myreader.enums.Font; 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(); private static final String TAG = ReadActivity.class.getSimpleName();
/*****************************View***********************************/ /*****************************View***********************************/
@BindView(R.id.rl_content) private ActivityReadBinding binding;
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;
/***************************variable*****************************/ /***************************variable*****************************/
private Book mBook; private Book mBook;
@ -270,7 +211,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
e.getMessage()); e.getMessage());
e.printStackTrace(); e.printStackTrace();
} }
pbLoading.setVisibility(View.GONE); binding.pbLoading.setVisibility(View.GONE);
break; break;
case 3: case 3:
break; break;
@ -299,7 +240,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
mPageLoader.chapterError(); mPageLoader.chapterError();
break; break;
case 8: case 8:
pbLoading.setVisibility(View.GONE); binding.pbLoading.setVisibility(View.GONE);
break; break;
case 9: case 9:
ToastUtils.showInfo("正在后台缓存书籍,具体进度可查看通知栏!"); ToastUtils.showInfo("正在后台缓存书籍,具体进度可查看通知栏!");
@ -314,12 +255,14 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
}; };
/**************************override***********************************/
@Override @Override
protected int getContentId() { protected void bindView() {
return R.layout.activity_read; binding = ActivityReadBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
} }
/**************************override***********************************/
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -379,7 +322,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
mReadCrawler = ReadCrawlerUtil.getReadCrawler(mBook.getSource()); mReadCrawler = ReadCrawlerUtil.getReadCrawler(mBook.getSource());
mPageLoader = pageView.getPageLoader(mBook, mReadCrawler, mSetting); mPageLoader = binding.readPvContent.getPageLoader(mBook, mReadCrawler, mSetting);
//Dialog //Dialog
mSourceDialog = new SourceExchangeDialog(this, mBook); mSourceDialog = new SourceExchangeDialog(this, mBook);
} }
@ -389,13 +332,13 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
super.initWidget(); super.initWidget();
ImmersionBar.with(this).fullScreen(true).init(); ImmersionBar.with(this).fullScreen(true).init();
//隐藏StatusBar //隐藏StatusBar
pageView.post( binding.readPvContent.post(
this::hideSystemBar this::hideSystemBar
); );
if (!mSetting.isBrightFollowSystem()) { if (!mSetting.isBrightFollowSystem()) {
BrightUtil.setBrightness(this, mSetting.getBrightProgress()); BrightUtil.setBrightness(this, mSetting.getBrightProgress());
} }
pbLoading.setVisibility(View.VISIBLE); binding.pbLoading.setVisibility(View.VISIBLE);
initEyeView(); initEyeView();
initSettingListener(); initSettingListener();
initTopMenu(); initTopMenu();
@ -408,7 +351,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
@Override @Override
protected void initClick() { protected void initClick() {
super.initClick(); super.initClick();
pageView.setTouchListener(new PageView.TouchListener() { binding.readPvContent.setTouchListener(new PageView.TouchListener() {
@Override @Override
public boolean onTouch() { public boolean onTouch() {
screenOffTimerStart(); screenOffTimerStart();
@ -441,14 +384,14 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
@Override @Override
public void onTouchClearCursor() { public void onTouchClearCursor() {
cursorLeft.setVisibility(View.INVISIBLE); binding.cursorLeft.setVisibility(View.INVISIBLE);
cursorRight.setVisibility(View.INVISIBLE); binding.cursorRight.setVisibility(View.INVISIBLE);
longPressMenu.hidePopupListWindow(); longPressMenu.hidePopupListWindow();
} }
@Override @Override
public void onLongPress() { public void onLongPress() {
if (!pageView.isRunning()) { if (!binding.readPvContent.isRunning()) {
selectTextCursorShow(); selectTextCursorShow();
showAction(); showAction();
} }
@ -518,11 +461,11 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
} }
); );
readSbChapterProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { binding.readSbChapterProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (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); startActivity(intent);
}); });
readTvListenBook.setOnClickListener(v -> { binding.readTvListenBook.setOnClickListener(v -> {
if (mSetting.getPageMode() == PageMode.SCROLL) { if (mSetting.getPageMode() == PageMode.SCROLL) {
ToastUtils.showWarring("朗读暂不支持滚动翻页模式!"); ToastUtils.showWarring("朗读暂不支持滚动翻页模式!");
return; return;
@ -585,12 +528,54 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
mAudioPlayerDialog.show(); mAudioPlayerDialog.show();
}); });
initReadLongPressPop(); initReadLongPressPop();
cursorLeft.setOnTouchListener(this); binding.cursorLeft.setOnTouchListener(this);
cursorRight.setOnTouchListener(this); binding.cursorRight.setOnTouchListener(this);
rlContent.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 @Override
protected void processLogic() { protected void processLogic() {
super.processLogic(); super.processLogic();
@ -620,13 +605,13 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
boolean isVolumeTurnPage = SysManager.getSetting().isVolumeTurnPage(); boolean isVolumeTurnPage = SysManager.getSetting().isVolumeTurnPage();
if (readAblTopMenu.getVisibility() != View.VISIBLE && if (binding.readAblTopMenu.getVisibility() != View.VISIBLE &&
customizeLayoutMenu.getVisibility() != View.VISIBLE && binding.readCustomizeLayoutMenu.getVisibility() != View.VISIBLE &&
autoPageMenu.getVisibility() != View.VISIBLE && binding.readAutoPageMenu.getVisibility() != View.VISIBLE &&
customizeComMenu.getVisibility() != View.VISIBLE && binding.readCustomizeMenu.getVisibility() != View.VISIBLE &&
readSettingMenu.getVisibility() != View.VISIBLE && binding.readSettingMenu.getVisibility() != View.VISIBLE &&
brightnessEyeMenu.getVisibility() != View.VISIBLE) { binding.readBrightnessEyeMenu.getVisibility() != View.VISIBLE) {
if (pageView.getSelectMode() != PageView.SelectMode.Normal) { if (binding.readPvContent.getSelectMode() != PageView.SelectMode.Normal) {
clearSelect(); clearSelect();
} }
switch (keyCode) { switch (keyCode) {
@ -747,18 +732,16 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { int itemId = item.getItemId();
case R.id.action_change_source: if (itemId == R.id.action_change_source) {
mSourceDialog.show(); mSourceDialog.show();
break; } else if (itemId == R.id.action_reload) {
case R.id.action_reload:
isPrev = false; isPrev = false;
if (!"本地书籍".equals(mBook.getType())) { if (!"本地书籍".equals(mBook.getType())) {
mChapterService.deleteChapterCacheFile(mChapters.get(mPageLoader.getChapterPos())); mChapterService.deleteChapterCacheFile(mChapters.get(mPageLoader.getChapterPos()));
} }
mPageLoader.refreshChapter(mChapters.get(mPageLoader.getChapterPos())); mPageLoader.refreshChapter(mChapters.get(mPageLoader.getChapterPos()));
break; } else if (itemId == R.id.action_add_bookmark) {
case R.id.action_add_bookmark:
if (mChapters == null || mChapters.size() == 0) { if (mChapters == null || mChapters.size() == 0) {
if ("本地书籍".equals(mBook.getType())) { if ("本地书籍".equals(mBook.getType())) {
ToastUtils.showWarring("请等待章节拆分完成后再添加书签"); ToastUtils.showWarring("请等待章节拆分完成后再添加书签");
@ -778,21 +761,17 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
"》:" + bookMark.getTitle() + "[" + (bookMark.getBookMarkReadPosition() + 1) + "》:" + bookMark.getTitle() + "[" + (bookMark.getBookMarkReadPosition() + 1) +
"]\n书签添加成功,书签列表可在目录界面查看!"); "]\n书签添加成功,书签列表可在目录界面查看!");
return true; return true;
case R.id.action_replace_content: } else if (itemId == R.id.action_replace_content) {
Intent ruleIntent = new Intent(this, RuleActivity.class); Intent ruleIntent = new Intent(this, RuleActivity.class);
startActivityForResult(ruleIntent, APPCONST.REQUEST_REFRESH_READ_UI); startActivityForResult(ruleIntent, APPCONST.REQUEST_REFRESH_READ_UI);
break; } else if (itemId == R.id.action_copy_content) {
case R.id.action_copy_content:
new CopyContentDialog(this, mPageLoader.getContent()).show(); new CopyContentDialog(this, mPageLoader.getContent()).show();
break; } else if (itemId == R.id.action_open_link) {
case R.id.action_open_link:
Uri uri = Uri.parse(mBook.getChapterUrl()); Uri uri = Uri.parse(mBook.getChapterUrl());
Intent intent = new Intent(Intent.ACTION_VIEW, uri); Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent); startActivity(intent);
break; } else if (itemId == R.id.action_download) {
case R.id.action_download:
download(); download();
break;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@ -844,11 +823,11 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
break; break;
case APPCONST.REQUEST_SELECT_BG: case APPCONST.REQUEST_SELECT_BG:
String bgPath = getPath(this, data.getData()); String bgPath = getPath(this, data.getData());
customizeLayoutMenu.setCustomBg(bgPath); binding.readCustomizeLayoutMenu.setCustomBg(bgPath);
break; break;
case APPCONST.REQUEST_IMPORT_LAYOUT: case APPCONST.REQUEST_IMPORT_LAYOUT:
String zipPath = getPath(this, data.getData()); String zipPath = getPath(this, data.getData());
customizeLayoutMenu.zip2Layout(zipPath); binding.readCustomizeLayoutMenu.zip2Layout(zipPath);
break; break;
} }
} }
@ -875,7 +854,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
break; break;
} }
SysManager.saveSetting(mSetting); 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) { if (mChapters != null && mChapters.size() != 0) {
Chapter curChapter = mChapters.get(mPageLoader.getChapterPos()); Chapter curChapter = mChapters.get(mPageLoader.getChapterPos());
String url = curChapter.getUrl(); String url = curChapter.getUrl();
chapterTitle.setText(curChapter.getTitle()); binding.tvChapterTitleTop.setText(curChapter.getTitle());
chapterUrl.setText(StringHelper.isEmpty(url) ? curChapter.getId() : url); binding.tvChapterUrl.setText(StringHelper.isEmpty(url) ? curChapter.getId() : url);
readSbChapterProgress.setProgress(mPageLoader.getPagePos()); binding.readSbChapterProgress.setProgress(mPageLoader.getPagePos());
readSbChapterProgress.setMax(mPageLoader.getAllPagePos() - 1); binding.readSbChapterProgress.setMax(mPageLoader.getAllPagePos() - 1);
readTvPageTip.setText((readSbChapterProgress.getProgress() + 1) + "/" + (readSbChapterProgress.getMax() + 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("该章节无内容!"); ToastUtils.showWarring("该章节无内容!");
return; return;
} }
pbLoading.setVisibility(View.VISIBLE); binding.pbLoading.setVisibility(View.VISIBLE);
getChapterContent(mChapters.get(chapterPos), new ResultCallback() { getChapterContent(mChapters.get(chapterPos), new ResultCallback() {
@Override @Override
public void onFinish(Object o, int code) { public void onFinish(Object o, int code) {
@ -1237,13 +1216,13 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
*/ */
private void initTopMenu() { private void initTopMenu() {
int statusBarHeight = ImmersionBar.getStatusBarHeight(this); int statusBarHeight = ImmersionBar.getStatusBarHeight(this);
readAblTopMenu.setPadding(0, statusBarHeight, 0, 0); binding.readAblTopMenu.setPadding(0, statusBarHeight, 0, 0);
if (mSetting.isNoMenuChTitle()) { if (mSetting.isNoMenuChTitle()) {
chapterView.setVisibility(GONE); binding.llChapterView.setVisibility(GONE);
toolbar.getLayoutParams().height = 60 + ImmersionBar.getStatusBarHeight(this); binding.toolbar.getLayoutParams().height = ScreenUtils.dpToPx(60) + ImmersionBar.getStatusBarHeight(this);
} else { } else {
chapterView.setVisibility(VISIBLE); binding.llChapterView.setVisibility(VISIBLE);
toolbar.getLayoutParams().height = 45 + ImmersionBar.getStatusBarHeight(this); 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.getHideStatusBar()) {
if (!mSetting.isDayStyle()) { 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) { if (true) {
//还需要设置mBottomMenu的底部高度 //还需要设置mBottomMenu的底部高度
if (ImmersionBar.hasNavigationBar(this)) { if (ImmersionBar.hasNavigationBar(this)) {
int height = ImmersionBar.getNavigationBarHeight(this); int height = ImmersionBar.getNavigationBarHeight(this);
vwNavigationBar.getLayoutParams().height = height; binding.vwNavigationBar.getLayoutParams().height = height;
readSettingMenu.setNavigationBarHeight(height); binding.readSettingMenu.setNavigationBarHeight(height);
customizeComMenu.setNavigationBarHeight(height); binding.readCustomizeMenu.setNavigationBarHeight(height);
customizeLayoutMenu.setNavigationBarHeight(height); binding.readCustomizeLayoutMenu.setNavigationBarHeight(height);
autoPageMenu.setNavigationBarHeight(height); binding.readAutoPageMenu.setNavigationBarHeight(height);
brightnessEyeMenu.setNavigationBarHeight(height); binding.readBrightnessEyeMenu.setNavigationBarHeight(height);
} }
} else { } else {
//设置mBottomMenu的底部距离 //设置mBottomMenu的底部距离
vwNavigationBar.getLayoutParams().height = 0; binding.vwNavigationBar.getLayoutParams().height = 0;
} }
} }
@ -1282,33 +1261,33 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
private boolean hideReadMenu() { private boolean hideReadMenu() {
hideSystemBar(); hideSystemBar();
boolean flag = false; boolean flag = false;
if (readAblTopMenu.getVisibility() == VISIBLE) { if (binding.readAblTopMenu.getVisibility() == VISIBLE) {
toggleMenu(true); toggleMenu(true);
flag = true; flag = true;
} }
if (readSettingMenu.getVisibility() == View.VISIBLE) { if (binding.readSettingMenu.getVisibility() == View.VISIBLE) {
readSettingMenu.setVisibility(GONE); binding.readSettingMenu.setVisibility(GONE);
readSettingMenu.startAnimation(mBottomOutAnim); binding.readSettingMenu.startAnimation(mBottomOutAnim);
flag = true; flag = true;
} }
if (customizeComMenu.getVisibility() == VISIBLE) { if (binding.readCustomizeMenu.getVisibility() == VISIBLE) {
customizeComMenu.setVisibility(GONE); binding.readCustomizeMenu.setVisibility(GONE);
customizeComMenu.startAnimation(mBottomOutAnim); binding.readCustomizeMenu.startAnimation(mBottomOutAnim);
flag = true; flag = true;
} }
if (customizeLayoutMenu.getVisibility() == VISIBLE) { if (binding.readCustomizeLayoutMenu.getVisibility() == VISIBLE) {
customizeLayoutMenu.setVisibility(GONE); binding.readCustomizeLayoutMenu.setVisibility(GONE);
customizeLayoutMenu.startAnimation(mBottomOutAnim); binding.readCustomizeLayoutMenu.startAnimation(mBottomOutAnim);
flag = true; flag = true;
} }
if (autoPageMenu.getVisibility() == VISIBLE) { if (binding.readAutoPageMenu.getVisibility() == VISIBLE) {
autoPageMenu.setVisibility(GONE); binding.readAutoPageMenu.setVisibility(GONE);
autoPageMenu.startAnimation(mBottomOutAnim); binding.readAutoPageMenu.startAnimation(mBottomOutAnim);
flag = true; flag = true;
} }
if (brightnessEyeMenu.getVisibility() == VISIBLE) { if ( binding.readBrightnessEyeMenu.getVisibility() == VISIBLE) {
brightnessEyeMenu.setVisibility(GONE); binding.readBrightnessEyeMenu.setVisibility(GONE);
brightnessEyeMenu.startAnimation(mBottomOutAnim); binding.readBrightnessEyeMenu.startAnimation(mBottomOutAnim);
flag = true; flag = true;
} }
return flag; return flag;
@ -1324,12 +1303,12 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
public void toggleMenu(boolean hideStatusBar, boolean home) { public void toggleMenu(boolean hideStatusBar, boolean home) {
initMenuAnim(); initMenuAnim();
if (readAblTopMenu.getVisibility() == View.VISIBLE) { if (binding.readAblTopMenu.getVisibility() == View.VISIBLE) {
//关闭 //关闭
readAblTopMenu.startAnimation(mTopOutAnim); binding.readAblTopMenu.startAnimation(mTopOutAnim);
readLlBottomMenu.startAnimation(mBottomOutAnim); binding.readLlBottomMenu.startAnimation(mBottomOutAnim);
readAblTopMenu.setVisibility(GONE); binding.readAblTopMenu.setVisibility(GONE);
readLlBottomMenu.setVisibility(GONE); binding.readLlBottomMenu.setVisibility(GONE);
if (hideStatusBar) { if (hideStatusBar) {
hideSystemBar(); hideSystemBar();
} }
@ -1342,14 +1321,14 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
} }
} }
if (autoPage) { if (autoPage) {
autoPageMenu.setVisibility(VISIBLE); binding.readAutoPageMenu.setVisibility(VISIBLE);
autoPageMenu.startAnimation(mBottomInAnim); binding.readAutoPageMenu.startAnimation(mBottomInAnim);
return; return;
} }
readAblTopMenu.setVisibility(View.VISIBLE); binding.readAblTopMenu.setVisibility(View.VISIBLE);
readLlBottomMenu.setVisibility(View.VISIBLE); binding.readLlBottomMenu.setVisibility(View.VISIBLE);
readAblTopMenu.startAnimation(mTopInAnim); binding.readAblTopMenu.startAnimation(mTopInAnim);
readLlBottomMenu.startAnimation(mBottomInAnim); binding.readLlBottomMenu.startAnimation(mBottomInAnim);
showSystemBar(); showSystemBar();
} }
@ -1370,7 +1349,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
private void hideSystemBar() { private void hideSystemBar() {
//隐藏 //隐藏
if (readAblTopMenu.getVisibility() != VISIBLE || (mAudioPlayerDialog != null && !mAudioPlayerDialog.isShowing())) { if (binding.readAblTopMenu.getVisibility() != VISIBLE || (mAudioPlayerDialog != null && !mAudioPlayerDialog.isShowing())) {
if (!mSetting.isShowStatusBar()) { if (!mSetting.isShowStatusBar()) {
SystemBarUtils.hideStableStatusBar(this); SystemBarUtils.hideStableStatusBar(this);
} }
@ -1384,8 +1363,8 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
* 初始化详细设置 * 初始化详细设置
*/ */
private void initSettingListener() { private void initSettingListener() {
readSettingMenu.setOnClickListener(null); binding.readSettingMenu.setOnClickListener(null);
readSettingMenu.setListener(this, new ReadSettingMenu.Callback() { binding.readSettingMenu.setListener(this, new ReadSettingMenu.Callback() {
@Override @Override
public void onRefreshUI() { public void onRefreshUI() {
mHandler.sendEmptyMessage(5); mHandler.sendEmptyMessage(5);
@ -1436,14 +1415,14 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
}, mBottomOutAnim.getDuration()); }, mBottomOutAnim.getDuration());
} }
}); });
customizeComMenu.setOnClickListener(null); binding.readCustomizeMenu.setOnClickListener(null);
customizeComMenu.setListener(new CustomizeComMenu.Callback() { binding.readCustomizeMenu.setListener(new CustomizeComMenu.Callback() {
@Override @Override
public void onTextPChange() { public void onTextPChange() {
mPageLoader.setTextSize(); mPageLoader.setTextSize();
mSetting.setComposition(0); mSetting.setComposition(0);
SysManager.saveSetting(mSetting); SysManager.saveSetting(mSetting);
readSettingMenu.initComposition(); binding.readSettingMenu.initComposition();
} }
@Override @Override
@ -1451,7 +1430,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
mPageLoader.upMargin(); mPageLoader.upMargin();
mSetting.setComposition(0); mSetting.setComposition(0);
SysManager.saveSetting(mSetting); SysManager.saveSetting(mSetting);
readSettingMenu.initComposition(); binding.readSettingMenu.initComposition();
} }
@Override @Override
@ -1465,19 +1444,17 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
mPageLoader.upMargin(); mPageLoader.upMargin();
mSetting.setComposition(1); mSetting.setComposition(1);
SysManager.saveSetting(mSetting); SysManager.saveSetting(mSetting);
readSettingMenu.initComposition(); binding.readSettingMenu.initComposition();
ToastUtils.showInfo("已重置各间距为默认值"); ToastUtils.showInfo("已重置各间距为默认值");
} }
}); });
autoPageMenu.setOnClickListener(null); binding.readAutoPageMenu.setOnClickListener(null);
autoPageMenu.setListener(new AutoPageMenu.Callback() { binding.readAutoPageMenu.setListener(new AutoPageMenu.Callback() {
@Override @Override
public void onSpeedChange() { public void onSpeedChange() {
if (pageView != null) { binding.readPvContent.autoPageOnSpeedChange();
pageView.autoPageOnSpeedChange();
autoPage(); autoPage();
} }
}
@Override @Override
public void onExitClick() { public void onExitClick() {
@ -1486,8 +1463,8 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
hideReadMenu(); hideReadMenu();
} }
}); });
customizeLayoutMenu.setOnClickListener(null); binding.readCustomizeLayoutMenu.setOnClickListener(null);
customizeLayoutMenu.setListener(this, new CustomizeLayoutMenu.Callback() { binding.readCustomizeLayoutMenu.setListener(this, new CustomizeLayoutMenu.Callback() {
@Override @Override
public void upBg() { public void upBg() {
mPageLoader.refreshUi(); mPageLoader.refreshUi();
@ -1495,12 +1472,12 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
@Override @Override
public void upStyle() { public void upStyle() {
readSettingMenu.initStyleImage(); binding.readSettingMenu.initStyleImage();
} }
}); });
brightnessEyeMenu.setOnClickListener(null); binding.readBrightnessEyeMenu.setOnClickListener(null);
brightnessEyeMenu.setListener(this, new BrightnessEyeMenu.Callback() { binding.readBrightnessEyeMenu.setListener(this, new BrightnessEyeMenu.Callback() {
@Override @Override
public void onProtectEyeChange() { public void onProtectEyeChange() {
if (mSetting.isProtectEye()) { 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() { protected void download() {
if (!isCollected) { if (!isCollected) {
@ -1629,17 +1554,17 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
} }
public void showCustomizeMenu() { public void showCustomizeMenu() {
customizeComMenu.initWidget(); binding.readCustomizeMenu.initWidget();
customizeComMenu.setVisibility(VISIBLE); binding.readCustomizeMenu.setVisibility(VISIBLE);
customizeComMenu.startAnimation(mBottomInAnim); binding.readCustomizeMenu.startAnimation(mBottomInAnim);
} }
public void showCustomizeLayoutMenu() { public void showCustomizeLayoutMenu() {
hideReadMenu(); hideReadMenu();
customizeLayoutMenu.upColor(); binding.readCustomizeLayoutMenu.upColor();
customizeLayoutMenu.setVisibility(VISIBLE); binding.readCustomizeLayoutMenu.setVisibility(VISIBLE);
customizeLayoutMenu.startAnimation(mBottomInAnim); binding.readCustomizeLayoutMenu.startAnimation(mBottomInAnim);
} }
/****************息屏相关*****************/ /****************息屏相关*****************/
@ -1939,26 +1864,26 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
v.postInvalidate(); v.postInvalidate();
//移动过程中要画线 //移动过程中要画线
pageView.setSelectMode(PageView.SelectMode.SelectMoveForward); binding.readPvContent.setSelectMode(PageView.SelectMode.SelectMoveForward);
int hh = cursorLeft.getHeight(); int hh = binding.cursorLeft.getHeight();
int ww = cursorLeft.getWidth(); int ww = binding.cursorLeft.getWidth();
if (v.getId() == R.id.cursor_left) { if (v.getId() == R.id.cursor_left) {
pageView.setFirstSelectTxtChar(pageView.getCurrentTxtChar(lastX + ww, lastY - hh)); binding.readPvContent.setFirstSelectTxtChar(binding.readPvContent.getCurrentTxtChar(lastX + ww, lastY - hh));
if (pageView.getFirstSelectTxtChar() != null) { if (binding.readPvContent.getFirstSelectTxtChar() != null) {
cursorLeft.setX(pageView.getFirstSelectTxtChar().getTopLeftPosition().x - ww); binding.cursorLeft.setX(binding.readPvContent.getFirstSelectTxtChar().getTopLeftPosition().x - ww);
cursorLeft.setY(pageView.getFirstSelectTxtChar().getBottomLeftPosition().y); binding.cursorLeft.setY(binding.readPvContent.getFirstSelectTxtChar().getBottomLeftPosition().y);
} }
} else { } else {
pageView.setLastSelectTxtChar(pageView.getCurrentTxtChar(lastX - ww, lastY - hh)); binding.readPvContent.setLastSelectTxtChar(binding.readPvContent.getCurrentTxtChar(lastX - ww, lastY - hh));
if (pageView.getLastSelectTxtChar() != null) { if (binding.readPvContent.getLastSelectTxtChar() != null) {
cursorRight.setX(pageView.getLastSelectTxtChar().getBottomRightPosition().x); binding.cursorRight.setX(binding.readPvContent.getLastSelectTxtChar().getBottomRightPosition().x);
cursorRight.setY(pageView.getLastSelectTxtChar().getBottomRightPosition().y); binding.cursorRight.setY(binding.readPvContent.getLastSelectTxtChar().getBottomRightPosition().y);
} }
} }
pageView.invalidate(); binding.readPvContent.invalidate();
break; break;
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
@ -1977,19 +1902,19 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
*/ */
public void showAction() { public void showAction() {
float x, y; float x, y;
if (cursorLeft.getX() - cursorRight.getX() > 0){ if (binding.cursorLeft.getX() - binding.cursorRight.getX() > 0){
x = cursorRight.getX() + (cursorLeft.getX() - cursorRight.getX()) / 2 + ScreenUtils.dpToPx(12); x = binding.cursorRight.getX() + (binding.cursorLeft.getX() - binding.cursorRight.getX()) / 2 + ScreenUtils.dpToPx(12);
}else { }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); longPressMenu.setShowBottom(true);
y = cursorLeft.getY() + cursorLeft.getHeight() * 3 / 5; y = binding.cursorLeft.getY() + binding.cursorLeft.getHeight() * 3 / 5;
} else { } else {
longPressMenu.setShowBottom(false); 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); longPressMenuItems, longPressMenuListener);
} }
@ -1997,12 +1922,12 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
* 显示 * 显示
*/ */
private void selectTextCursorShow() { private void selectTextCursorShow() {
if (pageView.getFirstSelectTxtChar() == null || pageView.getLastSelectTxtChar() == null) if (binding.readPvContent.getFirstSelectTxtChar() == null || binding.readPvContent.getLastSelectTxtChar() == null)
return; return;
//show Cursor on current position //show Cursor on current position
cursorShow(); cursorShow();
//set current word selected //set current word selected
pageView.invalidate(); binding.readPvContent.invalidate();
// hideSnackBar(); // hideSnackBar();
} }
@ -2011,15 +1936,15 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
* 显示选择 * 显示选择
*/ */
private void cursorShow() { private void cursorShow() {
cursorLeft.setVisibility(View.VISIBLE); binding.cursorLeft.setVisibility(View.VISIBLE);
cursorRight.setVisibility(View.VISIBLE); binding.cursorRight.setVisibility(View.VISIBLE);
int hh = cursorLeft.getHeight(); int hh = binding.cursorLeft.getHeight();
int ww = cursorLeft.getWidth(); int ww = binding.cursorLeft.getWidth();
if (pageView.getFirstSelectTxtChar() != null) { if (binding.readPvContent.getFirstSelectTxtChar() != null) {
cursorLeft.setX(pageView.getFirstSelectTxtChar().getTopLeftPosition().x - ww); binding.cursorLeft.setX(binding.readPvContent.getFirstSelectTxtChar().getTopLeftPosition().x - ww);
cursorLeft.setY(pageView.getFirstSelectTxtChar().getBottomLeftPosition().y); binding.cursorLeft.setY(binding.readPvContent.getFirstSelectTxtChar().getBottomLeftPosition().y);
cursorRight.setX(pageView.getFirstSelectTxtChar().getBottomRightPosition().x); binding.cursorRight.setX(binding.readPvContent.getFirstSelectTxtChar().getBottomRightPosition().x);
cursorRight.setY(pageView.getFirstSelectTxtChar().getBottomRightPosition().y); binding.cursorRight.setY(binding.readPvContent.getFirstSelectTxtChar().getBottomRightPosition().y);
} }
} }
@ -2052,7 +1977,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
switch (position) { switch (position) {
case 0: case 0:
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); 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) { if (clipboard != null) {
clipboard.setPrimaryClip(clipData); clipboard.setPrimaryClip(clipData);
ToastUtils.showInfo("所选内容已经复制到剪贴板"); ToastUtils.showInfo("所选内容已经复制到剪贴板");
@ -2063,7 +1988,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
ReplaceRuleBean oldRuleBean = new ReplaceRuleBean(); ReplaceRuleBean oldRuleBean = new ReplaceRuleBean();
oldRuleBean.setReplaceSummary(""); oldRuleBean.setReplaceSummary("");
oldRuleBean.setEnable(true); oldRuleBean.setEnable(true);
oldRuleBean.setRegex(pageView.getSelectStr().trim()); oldRuleBean.setRegex(binding.readPvContent.getSelectStr().trim());
oldRuleBean.setIsRegex(false); oldRuleBean.setIsRegex(false);
oldRuleBean.setReplacement(""); oldRuleBean.setReplacement("");
oldRuleBean.setSerialNumber(0); oldRuleBean.setSerialNumber(0);
@ -2077,12 +2002,12 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
replaceDialog.show(getSupportFragmentManager(), "replaceRule"); replaceDialog.show(getSupportFragmentManager(), "replaceRule");
break; break;
case 2: case 2:
selectString = pageView.getSelectStr(); selectString = binding.readPvContent.getSelectStr();
speak(ReadActivity.this, selectString); speak(ReadActivity.this, selectString);
clearSelect(); clearSelect();
break; break;
case 3: case 3:
selectString = StringUtils.deleteWhitespace(pageView.getSelectStr()); selectString = StringUtils.deleteWhitespace(binding.readPvContent.getSelectStr());
MyAlertDialog.build(ReadActivity.this) MyAlertDialog.build(ReadActivity.this)
.setTitle(R.string.search) .setTitle(R.string.search)
.setItems(R.array.search_way, (dialog, which) -> { .setItems(R.array.search_way, (dialog, which) -> {
@ -2113,7 +2038,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
clearSelect(); clearSelect();
break; break;
case 4: case 4:
selectString = pageView.getSelectStr(); selectString = binding.readPvContent.getSelectStr();
ShareUtils.share(ReadActivity.this, selectString); ShareUtils.share(ReadActivity.this, selectString);
clearSelect(); clearSelect();
break; break;
@ -2126,10 +2051,10 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
* 清除选择 * 清除选择
*/ */
private void clearSelect() { private void clearSelect() {
cursorLeft.setVisibility(View.INVISIBLE); binding.cursorLeft.setVisibility(View.INVISIBLE);
cursorRight.setVisibility(View.INVISIBLE); binding.cursorRight.setVisibility(View.INVISIBLE);
longPressMenu.hidePopupListWindow(); longPressMenu.hidePopupListWindow();
pageView.clearSelect(); binding.readPvContent.clearSelect();
} }
private TextToSpeech textToSpeech; private TextToSpeech textToSpeech;

@ -9,48 +9,30 @@ import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.view.View; 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 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.R;
import xyz.fycz.myreader.model.backup.UserService;
import xyz.fycz.myreader.base.BaseActivity; 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.ui.dialog.DialogCreator;
import xyz.fycz.myreader.util.CodeUtil; import xyz.fycz.myreader.util.CodeUtil;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.utils.StringUtils; import xyz.fycz.myreader.util.utils.StringUtils;
import xyz.fycz.myreader.webapi.callback.ResultCallback;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author fengyue * @author fengyue
* @date 2020/9/18 22:37 * @date 2020/9/18 22:37
*/ */
public class RegisterActivity extends BaseActivity { public class RegisterActivity extends BaseActivity {
@BindView(R.id.et_username)
TextInputLayout etUsername; private ActivityRegisterBinding binding;
@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 String code; private String code;
private String username = ""; private String username = "";
private String password = ""; private String password = "";
@ -70,16 +52,16 @@ public class RegisterActivity extends BaseActivity {
showTip((String) msg.obj); showTip((String) msg.obj);
break; break;
case 3: case 3:
tvRegisterTip.setVisibility(View.GONE); binding.tvRegisterTip.setVisibility(View.GONE);
break; break;
} }
} }
}; };
@Override @Override
protected int getContentId() { protected void bindView() {
return R.layout.activity_register; binding = ActivityRegisterBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
} }
@Override @Override
@ -93,8 +75,8 @@ public class RegisterActivity extends BaseActivity {
protected void initWidget() { protected void initWidget() {
super.initWidget(); super.initWidget();
mHandler.sendMessage(mHandler.obtainMessage(1)); mHandler.sendMessage(mHandler.obtainMessage(1));
etUsername.requestFocus(); binding.etUsername.requestFocus();
etUsername.getEditText().addTextChangedListener(new TextWatcher() { binding.etUsername.getEditText().addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { 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 @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { 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 @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { 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 @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { 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 @Override
protected void initClick() { protected void initClick() {
super.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}$")){ if (!username.matches("^[A-Za-z][A-Za-z0-9]{5,13}$")){
DialogCreator.createTipDialog(this, "用户名格式错误", DialogCreator.createTipDialog(this, "用户名格式错误",
"用户名必须在6-14位之间\n用户名只能以字母开头\n用户名只能由数字、字母、下划线、减号组成"); "用户名必须在6-14位之间\n用户名只能以字母开头\n用户名只能由数字、字母、下划线、减号组成");
@ -216,7 +198,7 @@ public class RegisterActivity extends BaseActivity {
"两次输入的密码不一致"); "两次输入的密码不一致");
}else if(!inputCode.trim().toLowerCase().equals(code.toLowerCase())){ }else if(!inputCode.trim().toLowerCase().equals(code.toLowerCase())){
DialogCreator.createTipDialog(this, "验证码错误"); DialogCreator.createTipDialog(this, "验证码错误");
}else if(!cbAgreement.isChecked()){ }else if(!binding.cbAgreement.isChecked()){
DialogCreator.createTipDialog(this, "请勾选同意《用户服务协议》"); DialogCreator.createTipDialog(this, "请勾选同意《用户服务协议》");
}else { }else {
ProgressDialog dialog = DialogCreator.createProgressDialog(this, null, "正在注册..."); ProgressDialog dialog = DialogCreator.createProgressDialog(this, null, "正在注册...");
@ -252,19 +234,19 @@ public class RegisterActivity extends BaseActivity {
public void createCaptcha() { public void createCaptcha() {
code = CodeUtil.getInstance().createCode(); code = CodeUtil.getInstance().createCode();
Bitmap codeBitmap = CodeUtil.getInstance().createBitmap(code); Bitmap codeBitmap = CodeUtil.getInstance().createBitmap(code);
ivCaptcha.setImageBitmap(codeBitmap); binding.ivCaptcha.setImageBitmap(codeBitmap);
} }
public void showTip(String tip) { public void showTip(String tip) {
tvRegisterTip.setVisibility(View.VISIBLE); binding.tvRegisterTip.setVisibility(View.VISIBLE);
tvRegisterTip.setText(tip); binding.tvRegisterTip.setText(tip);
} }
public void checkNotNone(){ public void checkNotNone(){
if ("".equals(username) || "".equals(password) || "".equals(rpPassword) || "".equals(inputCode)){ if ("".equals(username) || "".equals(password) || "".equals(rpPassword) || "".equals(inputCode)){
btRegister.setEnabled(false); binding.btRegister.setEnabled(false);
}else { }else {
btRegister.setEnabled(true); binding.btRegister.setEnabled(true);
} }
} }

@ -11,12 +11,10 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import butterknife.BindView;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.annotations.NonNull; import io.reactivex.annotations.NonNull;
import xyz.fycz.myreader.R; 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.MyObserver;
import xyz.fycz.myreader.base.observer.MySingleObserver; import xyz.fycz.myreader.base.observer.MySingleObserver;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.databinding.ActivityRuleBinding;
import xyz.fycz.myreader.greendao.entity.ReplaceRuleBean; import xyz.fycz.myreader.greendao.entity.ReplaceRuleBean;
import xyz.fycz.myreader.model.ReplaceRuleManager; import xyz.fycz.myreader.model.ReplaceRuleManager;
import xyz.fycz.myreader.ui.adapter.ReplaceRuleAdapter; 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 * @date 2021/1/19 10:02
*/ */
public class RuleActivity extends BaseActivity { public class RuleActivity extends BaseActivity {
@BindView(R.id.rv_rule_list)
RecyclerView rvRuleList; private ActivityRuleBinding binding;
private List<ReplaceRuleBean> mReplaceRules; private List<ReplaceRuleBean> mReplaceRules;
private ReplaceRuleAdapter mAdapter; private ReplaceRuleAdapter mAdapter;
@Override @Override
protected int getContentId() { protected void bindView() {
return R.layout.activity_rule; binding = ActivityRuleBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
} }
@Override @Override
@ -95,10 +95,10 @@ public class RuleActivity extends BaseActivity {
mAdapter.notifyItemRangeChanged(which, mReplaceRules.size() - which); mAdapter.notifyItemRangeChanged(which, mReplaceRules.size() - which);
setUpBarTitle(); setUpBarTitle();
}); });
rvRuleList.setLayoutManager(new LinearLayoutManager(this)); binding.rvRuleList.setLayoutManager(new LinearLayoutManager(this));
rvRuleList.setAdapter(mAdapter); binding.rvRuleList.setAdapter(mAdapter);
//设置分割线 //设置分割线
rvRuleList.addItemDecoration(new DividerItemDecoration(this)); binding.rvRuleList.addItemDecoration(new DividerItemDecoration(this));
mAdapter.refreshItems(mReplaceRules); mAdapter.refreshItems(mReplaceRules);
} }
@ -106,7 +106,7 @@ public class RuleActivity extends BaseActivity {
@Override @Override
protected void initClick() { protected void initClick() {
super.initClick(); super.initClick();
rvRuleList.setOnTouchListener((v, event) -> { binding.rvRuleList.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getAction() == MotionEvent.ACTION_UP) {
SwipeMenuLayout viewCache = SwipeMenuLayout.getViewCache(); SwipeMenuLayout viewCache = SwipeMenuLayout.getViewCache();
if (null != viewCache) { if (null != viewCache) {

@ -15,97 +15,52 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.*;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.AppCompatRadioButton;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import java.util.ArrayList;
import com.scwang.smartrefresh.layout.SmartRefreshLayout; 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.R;
import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.application.MyApplication;
import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.application.SysManager;
import xyz.fycz.myreader.base.BaseActivity; 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.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.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.Book;
import xyz.fycz.myreader.greendao.entity.SearchHistory; import xyz.fycz.myreader.greendao.entity.SearchHistory;
import xyz.fycz.myreader.greendao.service.SearchHistoryService; import xyz.fycz.myreader.greendao.service.SearchHistoryService;
import xyz.fycz.myreader.model.SearchEngine;
import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap; import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap;
import xyz.fycz.myreader.ui.adapter.SearchBookAdapter; import xyz.fycz.myreader.ui.adapter.SearchBookAdapter;
import xyz.fycz.myreader.ui.adapter.SearchHistoryAdapter; 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.StringHelper;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.webapi.CommonApi; 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.webapi.crawler.ReadCrawlerUtil;
import xyz.fycz.myreader.widget.RefreshProgressBar; import xyz.fycz.myreader.webapi.crawler.base.ReadCrawler;
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;
/** /**
* @author fengyue * @author fengyue
* @date 2020/9/18 21:58 * @date 2020/9/18 21:58
*/ */
public class SearchBookActivity extends BaseActivity { 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 SearchBookAdapter mSearchBookAdapter;
private String searchKey;//搜索关键字 private String searchKey;//搜索关键字
@ -146,15 +101,13 @@ public class SearchBookActivity extends BaseActivity {
search(); search();
break; break;
case 2: case 2:
if (srlSearchBookList != null) { binding.srlSearchBookList.finishRefresh();
srlSearchBookList.finishRefresh();
}
/*if (curThreadCount == 0 && !isStopSearch) { /*if (curThreadCount == 0 && !isStopSearch) {
rpb.setIsAutoLoading(false); rpb.setIsAutoLoading(false);
}*/ }*/
break; break;
case 3: case 3:
fabSearchStop.setVisibility(View.GONE); binding.fabSearchStop.setVisibility(View.GONE);
break; break;
} }
} }
@ -162,8 +115,9 @@ public class SearchBookActivity extends BaseActivity {
@Override @Override
protected int getContentId() { protected void bindView() {
return R.layout.activity_search_book; binding = ActivitySearchBookBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
} }
@Override @Override
@ -184,10 +138,8 @@ public class SearchBookActivity extends BaseActivity {
searchEngine.setOnSearchListener(new SearchEngine.OnSearchListener() { searchEngine.setOnSearchListener(new SearchEngine.OnSearchListener() {
@Override @Override
public void loadMoreFinish(Boolean isAll) { public void loadMoreFinish(Boolean isAll) {
if (rpb != null) { binding.rpb.setIsAutoLoading(false);
rpb.setIsAutoLoading(false); binding.fabSearchStop.setVisibility(View.GONE);
}
fabSearchStop.setVisibility(View.GONE);
} }
@Override @Override
@ -214,9 +166,9 @@ public class SearchBookActivity extends BaseActivity {
@Override @Override
protected void initWidget() { protected void initWidget() {
super.initWidget(); super.initWidget();
etSearchKey.requestFocus();//get the focus binding.etSearchKey.requestFocus();//get the focus
//enter事件 //enter事件
etSearchKey.setOnEditorActionListener((textView, i, keyEvent) -> { binding.etSearchKey.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_UNSPECIFIED) { if (i == EditorInfo.IME_ACTION_UNSPECIFIED) {
mHandler.sendMessage(mHandler.obtainMessage(1)); mHandler.sendMessage(mHandler.obtainMessage(1));
return (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER); return (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER);
@ -226,18 +178,18 @@ public class SearchBookActivity extends BaseActivity {
switch (mSetting.getSearchFilter()) { switch (mSetting.getSearchFilter()) {
case 0: case 0:
rbAllSearch.setChecked(true); binding.rbAllSearch.setChecked(true);
break; break;
case 1: case 1:
default: default:
rbFuzzySearch.setChecked(true); binding.rbFuzzySearch.setChecked(true);
break; break;
case 2: case 2:
rbPreciseSearch.setChecked(true); binding.rbPreciseSearch.setChecked(true);
break; break;
} }
rbSearchFilter.setOnCheckedChangeListener((group, checkedId) -> { binding.rgSearchFilter.setOnCheckedChangeListener((group, checkedId) -> {
int searchFilter; int searchFilter;
switch (checkedId) { switch (checkedId) {
case R.id.rb_all_search: case R.id.rb_all_search:
@ -256,7 +208,7 @@ public class SearchBookActivity extends BaseActivity {
}); });
//搜索框改变事件 //搜索框改变事件
etSearchKey.addTextChangedListener(new TextWatcher() { binding.etSearchKey.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { 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(); stopSearch();
mHandler.sendMessage(mHandler.obtainMessage(1)); mHandler.sendMessage(mHandler.obtainMessage(1));
}); });
@ -295,31 +247,31 @@ public class SearchBookActivity extends BaseActivity {
super.initClick(); 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搜索事件 //suggestion搜索事件
tgSuggestBook.setOnTagClickListener(tag -> { binding.tgSuggestBook.setOnTagClickListener(tag -> {
etSearchKey.setText(tag); binding.etSearchKey.setText(tag);
etSearchKey.setSelection(tag.length()); binding.etSearchKey.setSelection(tag.length());
mHandler.sendMessage(mHandler.obtainMessage(1)); mHandler.sendMessage(mHandler.obtainMessage(1));
}); });
//历史记录搜索事件 //历史记录搜索事件
lvHistoryList.setOnItemClickListener((parent, view, position, id) -> { binding.lvHistoryList.setOnItemClickListener((parent, view, position, id) -> {
etSearchKey.setText(mSearchHistories.get(position).getContent()); binding.etSearchKey.setText(mSearchHistories.get(position).getContent());
etSearchKey.setSelection(mSearchHistories.get(position).getContent().length()); binding.etSearchKey.setSelection(mSearchHistories.get(position).getContent().length());
mHandler.sendMessage(mHandler.obtainMessage(1)); mHandler.sendMessage(mHandler.obtainMessage(1));
}); });
//清空历史记录 //清空历史记录
llClearHistory.setOnClickListener(v -> { binding.llClearHistory.setOnClickListener(v -> {
mSearchHistoryService.clearHistory(); mSearchHistoryService.clearHistory();
initHistoryList(); initHistoryList();
}); });
//清除单个历史记录 //清除单个历史记录
lvHistoryList.setOnItemLongClickListener((parent, view, position, id) -> { binding.lvHistoryList.setOnItemLongClickListener((parent, view, position, id) -> {
if (mSearchHistories.get(position) != null) { if (mSearchHistories.get(position) != null) {
mSearchHistoryService.deleteHistory(mSearchHistories.get(position)); mSearchHistoryService.deleteHistory(mSearchHistories.get(position));
initHistoryList(); initHistoryList();
@ -327,7 +279,7 @@ public class SearchBookActivity extends BaseActivity {
return true; return true;
}); });
fabSearchStop.setOnClickListener(v -> { binding.fabSearchStop.setOnClickListener(v -> {
stopSearch(); stopSearch();
}); });
} }
@ -397,17 +349,17 @@ public class SearchBookActivity extends BaseActivity {
* 初始化建议书目 * 初始化建议书目
*/ */
private void initSuggestionBook() { private void initSuggestionBook() {
tgSuggestBook.setTags(suggestion); binding.tgSuggestBook.setTags(suggestion);
} }
private class RenewSuggestionBook implements View.OnClickListener { private class RenewSuggestionBook implements View.OnClickListener {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
String[] s = tgSuggestBook.getTags(); String[] s = binding.tgSuggestBook.getTags();
if (Arrays.equals(s, suggestion)) { if (Arrays.equals(s, suggestion)) {
tgSuggestBook.setTags(suggestion2); binding.tgSuggestBook.setTags(suggestion2);
} else { } else {
tgSuggestBook.setTags(suggestion); binding.tgSuggestBook.setTags(suggestion);
} }
} }
} }
@ -418,11 +370,11 @@ public class SearchBookActivity extends BaseActivity {
private void initHistoryList() { private void initHistoryList() {
mSearchHistories = mSearchHistoryService.findAllSearchHistory(); mSearchHistories = mSearchHistoryService.findAllSearchHistory();
if (mSearchHistories == null || mSearchHistories.size() == 0) { if (mSearchHistories == null || mSearchHistories.size() == 0) {
llHistoryView.setVisibility(View.GONE); binding.llHistoryView.setVisibility(View.GONE);
} else { } else {
mSearchHistoryAdapter = new SearchHistoryAdapter(this, R.layout.listview_search_history_item, mSearchHistories); mSearchHistoryAdapter = new SearchHistoryAdapter(this, R.layout.listview_search_history_item, mSearchHistories);
lvHistoryList.setAdapter(mSearchHistoryAdapter); binding.lvHistoryList.setAdapter(mSearchHistoryAdapter);
llHistoryView.setVisibility(View.VISIBLE); binding.llHistoryView.setVisibility(View.VISIBLE);
} }
} }
@ -431,9 +383,9 @@ public class SearchBookActivity extends BaseActivity {
*/ */
private void initSearchList() { private void initSearchList() {
//initmBooksBean(); //initmBooksBean();
rvSearchBooksList.setVisibility(View.VISIBLE); binding.rvSearchBooksList.setVisibility(View.VISIBLE);
llSuggestBooksView.setVisibility(View.GONE); binding.llSuggestBooksView.setVisibility(View.GONE);
llSuggestBooksView.setVisibility(View.GONE); binding.llSuggestBooksView.setVisibility(View.GONE);
} }
@ -448,7 +400,7 @@ public class SearchBookActivity extends BaseActivity {
allThreadCount = readCrawlers.size(); allThreadCount = readCrawlers.size();
if (allThreadCount == 0) { if (allThreadCount == 0) {
ToastUtils.showWarring("当前书源已全部禁用,无法搜索!"); ToastUtils.showWarring("当前书源已全部禁用,无法搜索!");
rpb.setIsAutoLoading(false); binding.rpb.setIsAutoLoading(false);
return; return;
} }
curThreadCount = allThreadCount; curThreadCount = allThreadCount;
@ -463,39 +415,39 @@ public class SearchBookActivity extends BaseActivity {
* 搜索 * 搜索
*/ */
private void search() { private void search() {
rpb.setIsAutoLoading(true); binding.rpb.setIsAutoLoading(true);
fabSearchStop.setVisibility(View.VISIBLE); binding.fabSearchStop.setVisibility(View.VISIBLE);
if (StringHelper.isEmpty(searchKey)) { if (StringHelper.isEmpty(searchKey)) {
isStopSearch = true; isStopSearch = true;
stopSearch(); stopSearch();
rpb.setIsAutoLoading(false); binding.rpb.setIsAutoLoading(false);
rvSearchBooksList.setVisibility(View.GONE); binding.rvSearchBooksList.setVisibility(View.GONE);
llSuggestBooksView.setVisibility(View.VISIBLE); binding.llSuggestBooksView.setVisibility(View.VISIBLE);
initHistoryList(); initHistoryList();
rvSearchBooksList.setAdapter(null); binding.rvSearchBooksList.setAdapter(null);
srlSearchBookList.setEnableRefresh(false); binding.srlSearchBookList.setEnableRefresh(false);
} else { } else {
isStopSearch = false; isStopSearch = false;
mSearchBookAdapter = new SearchBookAdapter(mBooks, searchEngine); mSearchBookAdapter = new SearchBookAdapter(mBooks, searchEngine);
rvSearchBooksList.setAdapter(mSearchBookAdapter); binding.rvSearchBooksList.setAdapter(mSearchBookAdapter);
//进入书籍详情页 //进入书籍详情页
mSearchBookAdapter.setOnItemClickListener((view, pos) -> { mSearchBookAdapter.setOnItemClickListener((view, pos) -> {
Intent intent = new Intent(this, BookDetailedActivity.class); Intent intent = new Intent(this, BookDetailedActivity.class);
intent.putExtra(APPCONST.SEARCH_BOOK_BEAN, new ArrayList<>(mBooks.getValues(mSearchBookAdapter.getItem(pos)))); intent.putExtra(APPCONST.SEARCH_BOOK_BEAN, new ArrayList<>(mBooks.getValues(mSearchBookAdapter.getItem(pos))));
startActivity(intent); startActivity(intent);
}); });
srlSearchBookList.setEnableRefresh(true); binding.srlSearchBookList.setEnableRefresh(true);
rvSearchBooksList.setVisibility(View.VISIBLE); binding.rvSearchBooksList.setVisibility(View.VISIBLE);
llSuggestBooksView.setVisibility(View.GONE); binding.llSuggestBooksView.setVisibility(View.GONE);
llHistoryView.setVisibility(View.GONE); binding.llHistoryView.setVisibility(View.GONE);
getData(); getData();
mSearchHistoryService.addOrUpadteHistory(searchKey); mSearchHistoryService.addOrUpadteHistory(searchKey);
//收起软键盘 //收起软键盘
InputMethodManager imm = (InputMethodManager) MyApplication.getmContext().getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) MyApplication.getmContext().getSystemService(Context.INPUT_METHOD_SERVICE);
assert imm != null; 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)) { if (StringHelper.isEmpty(searchKey)) {
super.onBackPressed(); super.onBackPressed();
} else { } else {
etSearchKey.setText(""); binding.etSearchKey.setText("");
} }
} }

@ -5,37 +5,30 @@ import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.app.ActivityCompat; 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.bumptech.glide.signature.ObjectKey;
import com.gyf.immersionbar.ImmersionBar; import com.gyf.immersionbar.ImmersionBar;
import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import butterknife.BindView;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.application.MyApplication;
import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.databinding.ActivitySplashBinding;
import xyz.fycz.myreader.greendao.service.BookGroupService; import xyz.fycz.myreader.greendao.service.BookGroupService;
import xyz.fycz.myreader.ui.dialog.MyAlertDialog; import xyz.fycz.myreader.ui.dialog.MyAlertDialog;
import xyz.fycz.myreader.util.DateHelper; import xyz.fycz.myreader.util.DateHelper;
import xyz.fycz.myreader.util.IOUtils; import xyz.fycz.myreader.util.IOUtils;
import xyz.fycz.myreader.util.PermissionsChecker; import xyz.fycz.myreader.util.PermissionsChecker;
import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.SharedPreUtils;
import xyz.fycz.myreader.util.StringHelper;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.utils.ImageLoader; import xyz.fycz.myreader.util.utils.ImageLoader;
import xyz.fycz.myreader.util.utils.MD5Utils; import xyz.fycz.myreader.util.utils.MD5Utils;
@ -52,8 +45,7 @@ public class SplashActivity extends BaseActivity {
Manifest.permission.WRITE_EXTERNAL_STORAGE Manifest.permission.WRITE_EXTERNAL_STORAGE
}; };
@BindView(R.id.iv_splash) private ActivitySplashBinding binding;
AppCompatImageView ivSplash;
private PermissionsChecker mPermissionsChecker; private PermissionsChecker mPermissionsChecker;
private Thread myThread = new Thread() {//创建子线程 private Thread myThread = new Thread() {//创建子线程
@ -73,11 +65,11 @@ public class SplashActivity extends BaseActivity {
@Override @Override
protected int getContentId() { protected void bindView() {
return R.layout.activity_splash; binding = ActivitySplashBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
} }
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -149,7 +141,7 @@ public class SplashActivity extends BaseActivity {
.load(this, imgFile) .load(this, imgFile)
.error(R.drawable.start) .error(R.drawable.start)
.signature(new ObjectKey(splashLoadDate)) .signature(new ObjectKey(splashLoadDate))
.into(ivSplash); .into(binding.ivSplash);
} }
} }

@ -11,16 +11,13 @@ import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.NumberPicker; import android.widget.NumberPicker;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView;
import androidx.annotation.NonNull; 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.R;
import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.application.MyApplication;
import xyz.fycz.myreader.databinding.DialogAudioPlayerBinding;
import xyz.fycz.myreader.model.audio.ReadAloudService; import xyz.fycz.myreader.model.audio.ReadAloudService;
import xyz.fycz.myreader.ui.activity.ReadActivity; import xyz.fycz.myreader.ui.activity.ReadActivity;
import xyz.fycz.myreader.util.SharedPreUtils; 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.util.utils.AudioMngHelper;
import xyz.fycz.myreader.widget.page.PageLoader; import xyz.fycz.myreader.widget.page.PageLoader;
import static xyz.fycz.myreader.util.utils.StringUtils.getString;
public class AudioPlayerDialog extends Dialog{ public class AudioPlayerDialog extends Dialog{
private static final String TAG="AudioPlayerDialog"; private static final String TAG="AudioPlayerDialog";
private DialogAudioPlayerBinding binding;
private PageLoader mPageLoader; private PageLoader mPageLoader;
private ReadActivity mReadActivity; private ReadActivity mReadActivity;
private boolean aloudNextPage; private boolean aloudNextPage;
@ -43,30 +41,6 @@ public class AudioPlayerDialog extends Dialog{
private int speechRate; private int speechRate;
private int timer; 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) { public AudioPlayerDialog(@NonNull ReadActivity context, PageLoader mPageLoader) {
super(context); super(context);
mReadActivity = context; mReadActivity = context;
@ -76,11 +50,12 @@ public class AudioPlayerDialog extends Dialog{
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.diallog_audio_player); binding = DialogAudioPlayerBinding.inflate(getLayoutInflater());
ButterKnife.bind(this); setContentView(binding.getRoot());
setUpWindow(); setUpWindow();
initData(); initData();
initWidget(); initWidget();
initCLick();
readAloud(); readAloud();
} }
@ -88,7 +63,7 @@ public class AudioPlayerDialog extends Dialog{
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
volume = AudioMngHelper.getInstance().get100CurrentVolume(); volume = AudioMngHelper.getInstance().get100CurrentVolume();
sbVolume.setProgress(volume); binding.sbVolumeProgress.setProgress(volume);
if (!ReadAloudService.running){ if (!ReadAloudService.running){
readAloud(); readAloud();
} }
@ -115,18 +90,18 @@ public class AudioPlayerDialog extends Dialog{
} }
private void initWidget() { private void initWidget() {
sbVolume.setProgress(volume); binding.sbVolumeProgress.setProgress(volume);
sbPitch.setProgress(pitch); binding.sbPitchProgress.setProgress(pitch);
sbSpeechRate.setProgress(speechRate); binding.sbSpeechRateProgress.setProgress(speechRate);
SeekBarChangeListener seekBarChangeListener = new SeekBarChangeListener(); SeekBarChangeListener seekBarChangeListener = new SeekBarChangeListener();
sbVolume.setOnSeekBarChangeListener(seekBarChangeListener); binding.sbVolumeProgress.setOnSeekBarChangeListener(seekBarChangeListener);
sbPitch.setOnSeekBarChangeListener(seekBarChangeListener); binding.sbPitchProgress.setOnSeekBarChangeListener(seekBarChangeListener);
sbSpeechRate.setOnSeekBarChangeListener(seekBarChangeListener); binding.sbSpeechRateProgress.setOnSeekBarChangeListener(seekBarChangeListener);
tvResetSetting.setOnClickListener(v ->{ binding.ivResetSetting.setOnClickListener(v ->{
pitch = 10; pitch = 10;
speechRate = 10; speechRate = 10;
sbPitch.setProgress(pitch); binding.sbPitchProgress.setProgress(pitch);
sbSpeechRate.setProgress(speechRate); binding.sbSpeechRateProgress.setProgress(speechRate);
SharedPreUtils.getInstance().putInt("readPitch", pitch); SharedPreUtils.getInstance().putInt("readPitch", pitch);
SharedPreUtils.getInstance().putInt("speechRate", speechRate); SharedPreUtils.getInstance().putInt("speechRate", speechRate);
if (ReadAloudService.running) { 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{ private class SeekBarChangeListener implements SeekBar.OnSeekBarChangeListener{
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
@ -150,24 +184,21 @@ public class AudioPlayerDialog extends Dialog{
@Override @Override
public void onStopTrackingTouch(SeekBar seekBar) { public void onStopTrackingTouch(SeekBar seekBar) {
int progress = seekBar.getProgress(); int progress = seekBar.getProgress();
switch (seekBar.getId()){ int id = seekBar.getId();
case R.id.sb_volume_progress: if (id == R.id.sb_volume_progress) {
AudioMngHelper.getInstance().setVoice100(progress); AudioMngHelper.getInstance().setVoice100(progress);
break; } else if (id == R.id.sb_pitch_progress) {
case R.id.sb_pitch_progress:
SharedPreUtils.getInstance().putInt("readPitch", progress); SharedPreUtils.getInstance().putInt("readPitch", progress);
if (ReadAloudService.running) { if (ReadAloudService.running) {
ReadAloudService.pause(mReadActivity); ReadAloudService.pause(mReadActivity);
ReadAloudService.resume(mReadActivity); ReadAloudService.resume(mReadActivity);
} }
break; } else if (id == R.id.sb_speech_rate_progress) {
case R.id.sb_speech_rate_progress:
SharedPreUtils.getInstance().putInt("speechRate", progress); SharedPreUtils.getInstance().putInt("speechRate", progress);
if (ReadAloudService.running) { if (ReadAloudService.running) {
ReadAloudService.pause(mReadActivity); ReadAloudService.pause(mReadActivity);
ReadAloudService.resume(mReadActivity); ReadAloudService.resume(mReadActivity);
} }
break;
} }
} }
} }
@ -187,66 +218,6 @@ public class AudioPlayerDialog extends Dialog{
window.getDecorView().setBackgroundColor(getContext().getResources().getColor(R.color.read_menu_bg)); 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() { public void readAloud() {
mPageLoader.resetReadAloudParagraph(); mPageLoader.resetReadAloudParagraph();
@ -261,7 +232,7 @@ public class AudioPlayerDialog extends Dialog{
public boolean addOrSubVolume(boolean isAdd){ public boolean addOrSubVolume(boolean isAdd){
volume = isAdd ? AudioMngHelper.getInstance().addVoice100() : AudioMngHelper.getInstance().subVoice100(); volume = isAdd ? AudioMngHelper.getInstance().addVoice100() : AudioMngHelper.getInstance().subVoice100();
sbVolume.setProgress(volume); binding.sbVolumeProgress.setProgress(volume);
return true; return true;
} }
@ -305,13 +276,13 @@ public class AudioPlayerDialog extends Dialog{
} }
break; break;
case PLAY: case PLAY:
ivReadPlayStop.setImageResource(R.drawable.ic_stop); binding.ivReadPlayStop.setImageResource(R.drawable.ic_stop);
break; break;
case PAUSE: case PAUSE:
ivReadPlayStop.setImageResource(R.drawable.ic_play); binding.ivReadPlayStop.setImageResource(R.drawable.ic_play);
break; break;
default: default:
ivReadPlayStop.setImageResource(R.drawable.ic_play); binding.ivReadPlayStop.setImageResource(R.drawable.ic_play);
mPageLoader.skipToPage(mPageLoader.getPagePos()); mPageLoader.skipToPage(mPageLoader.getPagePos());
} }
} }

@ -6,11 +6,10 @@ import android.os.Bundle;
import android.view.Gravity; import android.view.Gravity;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import butterknife.BindView;
import butterknife.ButterKnife; import xyz.fycz.myreader.databinding.DialogCopyContentBinding;
import xyz.fycz.myreader.R;
/** /**
* Created by Zhouas666 on 2019-04-14 * Created by Zhouas666 on 2019-04-14
@ -23,8 +22,7 @@ public class CopyContentDialog extends Dialog {
private static final String TAG = "CopyContentDialog"; private static final String TAG = "CopyContentDialog";
@BindView(R.id.dialog_tv_content) private DialogCopyContentBinding binding;
TextView dialogTvContent;
private String content; private String content;
@ -39,12 +37,12 @@ public class CopyContentDialog extends Dialog {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_copy_content); binding = DialogCopyContentBinding.inflate(getLayoutInflater());
ButterKnife.bind(this); setContentView(binding.getRoot());
setUpWindow(); setUpWindow();
dialogTvContent.setText(content); binding.dialogTvContent.setText(content);
} }
/** /**

@ -7,16 +7,15 @@ import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView; import java.util.ArrayList;
import butterknife.ButterKnife; import java.util.List;
import xyz.fycz.myreader.R;
import xyz.fycz.myreader.databinding.DialogBookSourceBinding;
import xyz.fycz.myreader.entity.SearchBookBean; import xyz.fycz.myreader.entity.SearchBookBean;
import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.model.SearchEngine; 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.webapi.crawler.ReadCrawlerUtil;
import xyz.fycz.myreader.widget.RefreshProgressBar; import xyz.fycz.myreader.widget.RefreshProgressBar;
import java.util.ArrayList;
import java.util.List;
/** /**
* 换源dialog * 换源dialog
*/ */
@ -36,18 +31,8 @@ import java.util.List;
public class SourceExchangeDialog extends Dialog { public class SourceExchangeDialog extends Dialog {
private static final String TAG = "SourceExchangeDialog"; private static final String TAG = "SourceExchangeDialog";
/*@BindView(R.id.dialog_tv_title)
TextView dialogTvTitle;*/ private DialogBookSourceBinding binding;
@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 SearchEngine searchEngine; private SearchEngine searchEngine;
private SourceExchangeAdapter mAdapter; private SourceExchangeAdapter mAdapter;
@ -90,8 +75,8 @@ public class SourceExchangeDialog extends Dialog {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_book_source); binding = DialogBookSourceBinding.inflate(getLayoutInflater());
ButterKnife.bind(this); setContentView(binding.getRoot());
setUpWindow(); setUpWindow();
initData(); initData();
initClick(); initClick();
@ -103,8 +88,8 @@ public class SourceExchangeDialog extends Dialog {
//执行业务逻辑 //执行业务逻辑
if (aBooks.size() == 0) { if (aBooks.size() == 0) {
searchEngine.search(mShelfBook.getName(), mShelfBook.getAuthor()); searchEngine.search(mShelfBook.getName(), mShelfBook.getAuthor());
ivStopSearch.setVisibility(View.VISIBLE); binding.ivStopSearch.setVisibility(View.VISIBLE);
rpb.setIsAutoLoading(true); binding.rpb.setIsAutoLoading(true);
}else { }else {
if (mAdapter.getItemCount() == 0) { if (mAdapter.getItemCount() == 0) {
mAdapter.addItems(aBooks); mAdapter.addItems(aBooks);
@ -128,8 +113,8 @@ public class SourceExchangeDialog extends Dialog {
* 初始化数据 * 初始化数据
*/ */
private void initData() { private void initData() {
toolbar.setTitle(mShelfBook.getName()); binding.it.toolbar.setTitle(mShelfBook.getName());
toolbar.setSubtitle(mShelfBook.getAuthor()); binding.it.toolbar.setSubtitle(mShelfBook.getAuthor());
//dialogTvTitle.setText(mShelfBook.getName() + "(" + mShelfBook.getAuthor() + ")"); //dialogTvTitle.setText(mShelfBook.getName() + "(" + mShelfBook.getAuthor() + ")");
if (aBooks == null) { if (aBooks == null) {
@ -137,8 +122,8 @@ public class SourceExchangeDialog extends Dialog {
} }
mAdapter = new SourceExchangeAdapter(); mAdapter = new SourceExchangeAdapter();
dialogRvContent.setLayoutManager(new LinearLayoutManager(mActivity)); binding.dialogRvContent.setLayoutManager(new LinearLayoutManager(mActivity));
dialogRvContent.setAdapter(mAdapter); binding.dialogRvContent.setAdapter(mAdapter);
searchEngine = new SearchEngine(); searchEngine = new SearchEngine();
searchEngine.initSearchEngine(ReadCrawlerUtil.getReadCrawlers()); searchEngine.initSearchEngine(ReadCrawlerUtil.getReadCrawlers());
@ -149,8 +134,8 @@ public class SourceExchangeDialog extends Dialog {
@Override @Override
public void loadMoreFinish(Boolean isAll) { public void loadMoreFinish(Boolean isAll) {
synchronized (RefreshProgressBar.class) { synchronized (RefreshProgressBar.class) {
rpb.setIsAutoLoading(false); binding.rpb.setIsAutoLoading(false);
ivStopSearch.setVisibility(View.GONE); binding.ivStopSearch.setVisibility(View.GONE);
} }
} }
@ -199,10 +184,10 @@ public class SourceExchangeDialog extends Dialog {
dismiss(); dismiss();
}); });
ivStopSearch.setOnClickListener(v -> searchEngine.stopSearch()); binding.ivStopSearch.setOnClickListener(v -> searchEngine.stopSearch());
ivRefreshSearch.setOnClickListener(v -> { binding.ivRefreshSearch.setOnClickListener(v -> {
searchEngine.stopSearch(); searchEngine.stopSearch();
ivStopSearch.setVisibility(View.VISIBLE); binding.ivStopSearch.setVisibility(View.VISIBLE);
mAdapter.clear(); mAdapter.clear();
aBooks.clear(); aBooks.clear();
mAdapter.notifyDataSetChanged(); mAdapter.notifyDataSetChanged();

@ -5,22 +5,19 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ListView; import android.widget.ListView;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import butterknife.BindView;
import butterknife.ButterKnife; import xyz.fycz.myreader.databinding.FragmentBookmarkBinding;
import butterknife.Unbinder;
import xyz.fycz.myreader.R;
import xyz.fycz.myreader.ui.presenter.BookMarkPresenter; import xyz.fycz.myreader.ui.presenter.BookMarkPresenter;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
*/ */
public class BookMarkFragment extends Fragment { public class BookMarkFragment extends Fragment {
@BindView(R.id.lv_bookmark_list)
ListView lvBookmarkList;
private FragmentBookmarkBinding binding;
private BookMarkPresenter mBookMarkPresenter; private BookMarkPresenter mBookMarkPresenter;
Unbinder unbinder;
public BookMarkFragment() { public BookMarkFragment() {
@ -31,21 +28,19 @@ public class BookMarkFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment // Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_bookmark, container, false); binding = FragmentBookmarkBinding.inflate(inflater, container, false);
unbinder = ButterKnife.bind(this, view);
mBookMarkPresenter = new BookMarkPresenter(this); mBookMarkPresenter = new BookMarkPresenter(this);
mBookMarkPresenter.start(); mBookMarkPresenter.start();
return view; return binding.getRoot();
} }
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
unbinder.unbind();
} }
public ListView getLvBookmarkList() { public ListView getLvBookmarkList() {
return lvBookmarkList; return binding.lvBookmarkList;
} }
public BookMarkPresenter getmBookMarkPresenter() { public BookMarkPresenter getmBookMarkPresenter() {

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

@ -6,46 +6,27 @@ import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; 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 androidx.fragment.app.Fragment;
import com.scwang.smartrefresh.layout.SmartRefreshLayout; import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import xyz.fycz.myreader.R;
import xyz.fycz.myreader.widget.custom.DragSortGridView;
import butterknife.ButterKnife; import xyz.fycz.myreader.databinding.FragmentBookcaseBinding;
import butterknife.BindView;
import butterknife.Unbinder;
import xyz.fycz.myreader.ui.presenter.BookcasePresenter; import xyz.fycz.myreader.ui.presenter.BookcasePresenter;
import xyz.fycz.myreader.widget.custom.DragSortGridView;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
*/ */
public class BookcaseFragment extends Fragment { public class BookcaseFragment extends Fragment {
@BindView(R.id.srl_content)
SmartRefreshLayout srlContent; private FragmentBookcaseBinding binding;
@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 BookcasePresenter mBookcasePresenter; private BookcasePresenter mBookcasePresenter;
@ -58,17 +39,15 @@ public class BookcaseFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment // Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_bookcase, container, false); binding = FragmentBookcaseBinding.inflate(inflater, container, false);
unbinder = ButterKnife.bind(this, view);
mBookcasePresenter = new BookcasePresenter(this); mBookcasePresenter = new BookcasePresenter(this);
mBookcasePresenter.start(); mBookcasePresenter.start();
return view; return binding.getRoot();
} }
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
unbinder.unbind();
mBookcasePresenter.destroy(); mBookcasePresenter.destroy();
} }
@ -83,31 +62,31 @@ public class BookcaseFragment extends Fragment {
} }
public LinearLayout getLlNoDataTips() { public LinearLayout getLlNoDataTips() {
return llNoDataTips; return binding.llNoDataTips;
} }
public DragSortGridView getGvBook() { public DragSortGridView getGvBook() {
return gvBook; return binding.gvBook;
} }
public SmartRefreshLayout getSrlContent() { public SmartRefreshLayout getSrlContent() {
return srlContent; return binding.srlContent;
} }
public RelativeLayout getRlDownloadTip() { public RelativeLayout getRlDownloadTip() {
return rlDownloadTip; return binding.rlDownloadTip;
} }
public TextView getTvDownloadTip() { public TextView getTvDownloadTip() {
return tvDownloadTip; return binding.tvDownloadTip;
} }
public TextView getTvStopDownload() { public TextView getTvStopDownload() {
return tvStopDownload; return binding.tvStopDownload;
} }
public ProgressBar getPbDownload() { public ProgressBar getPbDownload() {
return pbDownload; return binding.pbDownload;
} }
public BookcasePresenter getmBookcasePresenter() { public BookcasePresenter getmBookcasePresenter() {
@ -115,22 +94,22 @@ public class BookcaseFragment extends Fragment {
} }
public boolean isRecreate() { public boolean isRecreate() {
return unbinder == null; return binding == null;
} }
public RelativeLayout getRlBookEdit() { public RelativeLayout getRlBookEdit() {
return rlBookEdit; return binding.rlBookEdit;
} }
public CheckBox getmCbSelectAll() { public CheckBox getmCbSelectAll() {
return mCbSelectAll; return binding.bookSelectedAll;
} }
public Button getmBtnDelete() { public Button getmBtnDelete() {
return mBtnDelete; return binding.bookBtnDelete;
} }
public Button getmBtnAddGroup() { public Button getmBtnAddGroup() {
return mBtnAddGroup; return binding.bookAddGroup;
} }
} }

@ -7,28 +7,20 @@ import android.view.ViewGroup;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import com.google.android.material.floatingactionbutton.FloatingActionButton; 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; import xyz.fycz.myreader.ui.presenter.CatalogPresenter;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
*/ */
public class CatalogFragment extends Fragment { 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; private CatalogPresenter mCatalogPresent;
@ -40,29 +32,27 @@ public class CatalogFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment // Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_catalog, container, false); binding = FragmentCatalogBinding.inflate(inflater, container, false);
unbinder = ButterKnife.bind(this, view);
mCatalogPresent = new CatalogPresenter(this); mCatalogPresent = new CatalogPresenter(this);
mCatalogPresent.start(); mCatalogPresent.start();
return view; return binding.getRoot();
} }
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
unbinder.unbind();
} }
public RelativeLayout getRlCatalog() { public RelativeLayout getRlCatalog() {
return rlCatalog; return binding.rlCatalog;
} }
public ListView getLvChapterList() { public ListView getLvChapterList() {
return lvChapterList; return binding.lvChapterList;
} }
public FloatingActionButton getFcChangeSort() { public FloatingActionButton getFcChangeSort() {
return fcChangeSort; return binding.changeSort;
} }
public CatalogPresenter getmCatalogPresent() { public CatalogPresenter getmCatalogPresent() {
@ -70,6 +60,6 @@ public class CatalogFragment extends Fragment {
} }
public ProgressBar getPbLoading() { public ProgressBar getPbLoading() {
return pbLoading; return binding.pbLoading;
} }
} }

@ -2,23 +2,30 @@ package xyz.fycz.myreader.ui.fragment;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; 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.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.R;
import xyz.fycz.myreader.databinding.FragmentFileCategoryBinding;
import xyz.fycz.myreader.greendao.service.BookService; import xyz.fycz.myreader.greendao.service.BookService;
import xyz.fycz.myreader.ui.adapter.FileSystemAdapter; import xyz.fycz.myreader.ui.adapter.FileSystemAdapter;
import xyz.fycz.myreader.util.FileStack; import xyz.fycz.myreader.util.FileStack;
import xyz.fycz.myreader.util.utils.FileUtils; import xyz.fycz.myreader.util.utils.FileUtils;
import xyz.fycz.myreader.widget.DividerItemDecoration; import xyz.fycz.myreader.widget.DividerItemDecoration;
import java.io.File;
import java.io.FileFilter;
import java.util.*;
/** /**
* @author fengyue * @author fengyue
* @date 2020/8/12 20:02 * @date 2020/8/12 20:02
@ -26,17 +33,15 @@ import java.util.*;
public class FileCategoryFragment extends BaseFileFragment { public class FileCategoryFragment extends BaseFileFragment {
private static final String TAG = "FileCategoryFragment"; private static final String TAG = "FileCategoryFragment";
@BindView(R.id.file_category_tv_path)
TextView mTvPath; private FragmentFileCategoryBinding binding;
@BindView(R.id.file_category_tv_back_last)
TextView mTvBackLast;
@BindView(R.id.file_category_rv_content)
RecyclerView mRvContent;
private FileStack mFileStack; private FileStack mFileStack;
@Override @Override
protected int getContentId() { protected View bindView(LayoutInflater inflater, ViewGroup container) {
return R.layout.fragment_file_category; binding = FragmentFileCategoryBinding.inflate(inflater, container, false);
return binding.getRoot();
} }
@Override @Override
@ -48,9 +53,9 @@ public class FileCategoryFragment extends BaseFileFragment {
private void setUpAdapter(){ private void setUpAdapter(){
mAdapter = new FileSystemAdapter(); mAdapter = new FileSystemAdapter();
mRvContent.setLayoutManager(new LinearLayoutManager(getContext())); binding.fileCategoryRvContent.setLayoutManager(new LinearLayoutManager(getContext()));
mRvContent.addItemDecoration(new DividerItemDecoration(getContext())); binding.fileCategoryRvContent.addItemDecoration(new DividerItemDecoration(getContext()));
mRvContent.setAdapter(mAdapter); binding.fileCategoryRvContent.setAdapter(mAdapter);
} }
@Override @Override
@ -62,9 +67,9 @@ public class FileCategoryFragment extends BaseFileFragment {
if (file.isDirectory()){ if (file.isDirectory()){
//保存当前信息。 //保存当前信息。
FileStack.FileSnapshot snapshot = new FileStack.FileSnapshot(); FileStack.FileSnapshot snapshot = new FileStack.FileSnapshot();
snapshot.filePath = mTvPath.getText().toString(); snapshot.filePath = binding.fileCategoryTvPath.getText().toString();
snapshot.files = new ArrayList<>(mAdapter.getItems()); snapshot.files = new ArrayList<>(mAdapter.getItems());
snapshot.scrollOffset = mRvContent.computeVerticalScrollOffset(); snapshot.scrollOffset = binding.fileCategoryRvContent.computeVerticalScrollOffset();
mFileStack.push(snapshot); mFileStack.push(snapshot);
//切换下一个文件 //切换下一个文件
toggleFileTree(file); toggleFileTree(file);
@ -86,16 +91,16 @@ public class FileCategoryFragment extends BaseFileFragment {
} }
); );
mTvBackLast.setOnClickListener(v -> backLast()); binding.fileCategoryTvBackLast.setOnClickListener(v -> backLast());
} }
public boolean backLast(){ public boolean backLast(){
FileStack.FileSnapshot snapshot = mFileStack.pop(); FileStack.FileSnapshot snapshot = mFileStack.pop();
int oldScrollOffset = mRvContent.computeHorizontalScrollOffset(); int oldScrollOffset = binding.fileCategoryRvContent.computeHorizontalScrollOffset();
if (snapshot == null) return false; if (snapshot == null) return false;
mTvPath.setText(snapshot.filePath); binding.fileCategoryTvPath.setText(snapshot.filePath);
mAdapter.refreshItems(snapshot.files); mAdapter.refreshItems(snapshot.files);
mRvContent.scrollBy(0,snapshot.scrollOffset - oldScrollOffset); binding.fileCategoryRvContent.scrollBy(0,snapshot.scrollOffset - oldScrollOffset);
//反馈 //反馈
if (mListener != null){ if (mListener != null){
mListener.onCategoryChanged(); mListener.onCategoryChanged();
@ -112,7 +117,7 @@ public class FileCategoryFragment extends BaseFileFragment {
private void toggleFileTree(File file){ 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()); File[] files = file.listFiles(new SimpleFileFilter());
//转换成List //转换成List

@ -1,18 +1,20 @@
package xyz.fycz.myreader.ui.fragment; package xyz.fycz.myreader.ui.fragment;
import android.content.Intent; import android.content.Intent;
import android.widget.RelativeLayout; import android.view.LayoutInflater;
import butterknife.BindView; import android.view.View;
import xyz.fycz.myreader.R; import android.view.ViewGroup;
import xyz.fycz.myreader.base.BaseFragment; import xyz.fycz.myreader.base.BaseFragment;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.databinding.FragmentFindBinding;
import xyz.fycz.myreader.ui.activity.BookstoreActivity; import xyz.fycz.myreader.ui.activity.BookstoreActivity;
import xyz.fycz.myreader.webapi.crawler.base.FindCrawler; 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.find.XS7Rank;
import xyz.fycz.myreader.webapi.crawler.read.Ben100ReadCrawler; import xyz.fycz.myreader.webapi.crawler.read.Ben100ReadCrawler;
import xyz.fycz.myreader.webapi.crawler.read.MiaoBiReadCrawler; import xyz.fycz.myreader.webapi.crawler.read.MiaoBiReadCrawler;
import xyz.fycz.myreader.webapi.crawler.read.QB5ReadCrawler; import xyz.fycz.myreader.webapi.crawler.read.QB5ReadCrawler;
import xyz.fycz.myreader.webapi.crawler.find.QiDianMobileRank;
import xyz.fycz.myreader.webapi.crawler.read.XS7ReadCrawler; 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 * @date 2020/9/13 21:07
*/ */
public class FindFragment extends BaseFragment { public class FindFragment extends BaseFragment {
@BindView(R.id.find_rl_qidian_top)
RelativeLayout mRlQiDianTop; private FragmentFindBinding binding;
@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;
@Override @Override
protected int getContentId() { protected View bindView(LayoutInflater inflater, ViewGroup container) {
return R.layout.fragment_find; binding = FragmentFindBinding.inflate(inflater, container, false);
return binding.getRoot();
} }
@Override @Override
protected void initClick() { protected void initClick() {
super.initClick(); super.initClick();
mRlQiDianTop.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(false))); binding.findRlQidianTop.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(false)));
mRlQiDianNSTop.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(true))); binding.findRlQidianNsTop.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(true)));
mRlXS7Top.setOnClickListener(v -> comeToBookstore(new XS7Rank())); binding.findRlXs7Top.setOnClickListener(v -> comeToBookstore(new XS7Rank()));
mRlQiDianSort.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(false, true))); binding.findRlQidianSort.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(false, true)));
mRlQiDianNSSort.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(true, true))); binding.findRlQidianNsSort.setOnClickListener(v -> comeToBookstore(new QiDianMobileRank(true, true)));
mRlQB5Store.setOnClickListener(v -> comeToBookstore(new QB5ReadCrawler())); binding.findRlQb5Store.setOnClickListener(v -> comeToBookstore(new QB5ReadCrawler()));
mRlBen100Store.setOnClickListener(v -> comeToBookstore(new Ben100ReadCrawler())); binding.findRlBen100Store.setOnClickListener(v -> comeToBookstore(new Ben100ReadCrawler()));
mRlMiaoQuStore.setOnClickListener(v -> comeToBookstore(new MiaoBiReadCrawler())); binding.findRlMiaoquStore.setOnClickListener(v -> comeToBookstore(new MiaoBiReadCrawler()));
mRlXS7Store.setOnClickListener(v -> comeToBookstore(new XS7ReadCrawler())); binding.findRlXs7Store.setOnClickListener(v -> comeToBookstore(new XS7ReadCrawler()));
} }
@ -66,6 +53,6 @@ public class FindFragment extends BaseFragment {
} }
public boolean isRecreate() { public boolean isRecreate() {
return unbinder == null; return binding == null;
} }
} }

@ -2,17 +2,18 @@ package xyz.fycz.myreader.ui.fragment;
import android.media.MediaScannerConnection; import android.media.MediaScannerConnection;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; 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.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView; import xyz.fycz.myreader.databinding.FragmentLocalBookBinding;
import xyz.fycz.myreader.R;
import xyz.fycz.myreader.greendao.service.BookService; import xyz.fycz.myreader.greendao.service.BookService;
import xyz.fycz.myreader.ui.adapter.FileSystemAdapter; import xyz.fycz.myreader.ui.adapter.FileSystemAdapter;
import xyz.fycz.myreader.util.media.MediaStoreHelper; import xyz.fycz.myreader.util.media.MediaStoreHelper;
import xyz.fycz.myreader.widget.DividerItemDecoration; 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 { public class LocalBookFragment extends BaseFileFragment {
@BindView(R.id.refresh_layout) private FragmentLocalBookBinding binding;
RefreshLayout mRlRefresh;
@BindView(R.id.local_book_rv_content)
RecyclerView mRvContent;
@Override @Override
protected int getContentId() { protected View bindView(LayoutInflater inflater, ViewGroup container) {
return R.layout.fragment_local_book; binding = FragmentLocalBookBinding.inflate(inflater, container, false);
return binding.getRoot();
} }
@Override @Override
@ -40,9 +39,9 @@ public class LocalBookFragment extends BaseFileFragment {
private void setUpAdapter() { private void setUpAdapter() {
mAdapter = new FileSystemAdapter(); mAdapter = new FileSystemAdapter();
mRvContent.setLayoutManager(new LinearLayoutManager(getContext())); binding.localBookRvContent.setLayoutManager(new LinearLayoutManager(getContext()));
mRvContent.addItemDecoration(new DividerItemDecoration(getContext())); binding.localBookRvContent.addItemDecoration(new DividerItemDecoration(getContext()));
mRvContent.setAdapter(mAdapter); binding.localBookRvContent.setAdapter(mAdapter);
} }
@Override @Override
@ -80,10 +79,10 @@ public class LocalBookFragment extends BaseFileFragment {
MediaStoreHelper.getAllBookFile(getActivity(), MediaStoreHelper.getAllBookFile(getActivity(),
(files) -> { (files) -> {
if (files.isEmpty()) { if (files.isEmpty()) {
mRlRefresh.showEmpty(); binding.refreshLayout.showEmpty();
} else { } else {
mAdapter.refreshItems(files); mAdapter.refreshItems(files);
mRlRefresh.showFinish(); binding.refreshLayout.showFinish();
//反馈 //反馈
if (mListener != null) { if (mListener != null) {
mListener.onCategoryChanged(); mListener.onCategoryChanged();

@ -1,43 +1,46 @@
package xyz.fycz.myreader.ui.fragment; package xyz.fycz.myreader.ui.fragment;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.*; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.widget.RelativeLayout; import android.view.LayoutInflater;
import android.widget.TextView; import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; 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.R;
import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.application.MyApplication;
import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.application.SysManager;
import xyz.fycz.myreader.model.backup.UserService;
import xyz.fycz.myreader.base.BaseFragment; import xyz.fycz.myreader.base.BaseFragment;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.model.storage.Backup; import xyz.fycz.myreader.databinding.FragmentMineBinding;
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.entity.Setting; import xyz.fycz.myreader.entity.Setting;
import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.greendao.service.BookService; 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.AboutActivity;
import xyz.fycz.myreader.ui.activity.FeedbackActivity;
import xyz.fycz.myreader.ui.activity.LoginActivity; import xyz.fycz.myreader.ui.activity.LoginActivity;
import xyz.fycz.myreader.ui.activity.MoreSettingActivity; 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.SharedPreUtils;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.util.utils.NetworkUtils;
import xyz.fycz.myreader.webapi.callback.ResultCallback; 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; import static android.app.Activity.RESULT_OK;
/** /**
@ -45,24 +48,8 @@ import static android.app.Activity.RESULT_OK;
* @date 2020/9/13 13:20 * @date 2020/9/13 13:20
*/ */
public class MineFragment extends BaseFragment { public class MineFragment extends BaseFragment {
@BindView(R.id.mine_rl_user)
RelativeLayout mRlUser; private FragmentMineBinding binding;
@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 boolean isLogin; private boolean isLogin;
private Setting mSetting; private Setting mSetting;
@ -77,7 +64,7 @@ public class MineFragment extends BaseFragment {
public void handleMessage(@NonNull Message msg) { public void handleMessage(@NonNull Message msg) {
switch (msg.what) { switch (msg.what) {
case 1: case 1:
mTvUser.setText("登录/注册"); binding.tvUser.setText("登录/注册");
break; break;
case 2: case 2:
backup(); backup();
@ -93,8 +80,9 @@ public class MineFragment extends BaseFragment {
} }
@Override @Override
protected int getContentId() { protected View bindView(LayoutInflater inflater, ViewGroup container) {
return R.layout.fragment_mine; binding = FragmentMineBinding.inflate(inflater, container, false);
return binding.getRoot();
} }
@Override @Override
@ -119,15 +107,15 @@ public class MineFragment extends BaseFragment {
protected void initWidget(Bundle savedInstanceState) { protected void initWidget(Bundle savedInstanceState) {
super.initWidget(savedInstanceState); super.initWidget(savedInstanceState);
if (isLogin) { if (isLogin) {
mTvUser.setText(UserService.readUsername()); binding.tvUser.setText(UserService.readUsername());
} }
tvThemeModeSelect.setText(themeModeArr[themeMode]); binding.tvThemeModeSelect.setText(themeModeArr[themeMode]);
} }
@Override @Override
protected void initClick() { protected void initClick() {
super.initClick(); super.initClick();
mRlUser.setOnClickListener(v -> { binding.mineRlUser.setOnClickListener(v -> {
if (isLogin) { if (isLogin) {
DialogCreator.createCommonDialog(getActivity(), "退出登录", "确定要退出登录吗?" DialogCreator.createCommonDialog(getActivity(), "退出登录", "确定要退出登录吗?"
, true, (dialog, which) -> { , true, (dialog, which) -> {
@ -147,7 +135,7 @@ public class MineFragment extends BaseFragment {
getActivity().startActivityForResult(intent, APPCONST.REQUEST_LOGIN); getActivity().startActivityForResult(intent, APPCONST.REQUEST_LOGIN);
} }
}); });
mRlBackup.setOnClickListener(v -> { binding.mineRlBackup.setOnClickListener(v -> {
AlertDialog bookDialog = MyAlertDialog.build(getContext()) AlertDialog bookDialog = MyAlertDialog.build(getContext())
.setTitle(getContext().getResources().getString(R.string.menu_bookcase_backup)) .setTitle(getContext().getResources().getString(R.string.menu_bookcase_backup))
.setItems(backupMenu, (dialog, which) -> { .setItems(backupMenu, (dialog, which) -> {
@ -165,7 +153,7 @@ public class MineFragment extends BaseFragment {
.create(); .create();
bookDialog.show(); bookDialog.show();
}); });
mRlSyn.setOnClickListener(v -> { binding.mineRlSyn.setOnClickListener(v -> {
if (!UserService.isLogin()) { if (!UserService.isLogin()) {
ToastUtils.showWarring("请先登录!"); ToastUtils.showWarring("请先登录!");
Intent loginIntent = new Intent(getActivity(), LoginActivity.class); Intent loginIntent = new Intent(getActivity(), LoginActivity.class);
@ -205,11 +193,11 @@ public class MineFragment extends BaseFragment {
.setPositiveButton(null, null) .setPositiveButton(null, null)
.show(); .show();
}); });
mRlSetting.setOnClickListener(v -> { binding.mineRlSetting.setOnClickListener(v -> {
Intent settingIntent = new Intent(getActivity(), MoreSettingActivity.class); Intent settingIntent = new Intent(getActivity(), MoreSettingActivity.class);
startActivity(settingIntent); startActivity(settingIntent);
}); });
mRlThemeMode.setOnClickListener(v -> { binding.mineRlThemeMode.setOnClickListener(v -> {
if (themeModeDia != null) { if (themeModeDia != null) {
themeModeDia.show(); themeModeDia.show();
return; return;
@ -239,7 +227,7 @@ public class MineFragment extends BaseFragment {
break; break;
} }
dialog.dismiss(); dialog.dismiss();
tvThemeModeSelect.setText(themeModeArr[themeMode]); binding.tvThemeModeSelect.setText(themeModeArr[themeMode]);
MyApplication.getApplication().initNightTheme(); MyApplication.getApplication().initNightTheme();
}) })
.setNegativeButton("取消", null) .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); Intent aboutIntent = new Intent(getActivity(), AboutActivity.class);
startActivity(aboutIntent); startActivity(aboutIntent);
}); });
mRlFeedback.setOnClickListener(v -> { binding.mineRlFeedback.setOnClickListener(v -> {
Intent intent = new Intent(getContext(), FeedbackActivity.class); Intent intent = new Intent(getContext(), FeedbackActivity.class);
getActivity().startActivity(intent); getActivity().startActivity(intent);
}); });
@ -429,7 +417,7 @@ public class MineFragment extends BaseFragment {
assert data != null; assert data != null;
isLogin = data.getBooleanExtra("isLogin", false); isLogin = data.getBooleanExtra("isLogin", false);
if (isLogin) { if (isLogin) {
mTvUser.setText(UserService.readUsername()); binding.tvUser.setText(UserService.readUsername());
} }
break; break;
} }
@ -437,6 +425,6 @@ public class MineFragment extends BaseFragment {
} }
public boolean isRecreate() { public boolean isRecreate() {
return unbinder == null; return binding == null;
} }
} }

@ -3,20 +3,19 @@ package xyz.fycz.myreader.ui.fragment;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputType; import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.view.ViewGroup;
import android.widget.RelativeLayout;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SwitchCompat;
import java.util.List; import java.util.List;
import butterknife.BindView;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.MyApplication; import xyz.fycz.myreader.application.MyApplication;
import xyz.fycz.myreader.base.BaseFragment; import xyz.fycz.myreader.base.BaseFragment;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.databinding.FragmentPrivateBookcaseBinding;
import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.greendao.service.BookGroupService; import xyz.fycz.myreader.greendao.service.BookGroupService;
import xyz.fycz.myreader.greendao.service.BookService; import xyz.fycz.myreader.greendao.service.BookService;
@ -34,27 +33,16 @@ import xyz.fycz.myreader.util.utils.FingerprintUtils;
* @date 2021/1/9 13:53 * @date 2021/1/9 13:53
*/ */
public class PrivateBooksFragment extends BaseFragment { public class PrivateBooksFragment extends BaseFragment {
@BindView(R.id.rl_private_bookcase)
RelativeLayout mRlPrivateBookcase; private FragmentPrivateBookcaseBinding binding;
@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 boolean openPrivate; private boolean openPrivate;
private boolean openFingerprint; private boolean openFingerprint;
@Override @Override
protected int getContentId() { protected View bindView(LayoutInflater inflater, ViewGroup container) {
return R.layout.fragment_private_bookcase; binding = FragmentPrivateBookcaseBinding.inflate(inflater, container, false);
return binding.getRoot();
} }
@Override @Override
@ -67,28 +55,28 @@ public class PrivateBooksFragment extends BaseFragment {
@Override @Override
protected void initWidget(Bundle savedInstanceState) { protected void initWidget(Bundle savedInstanceState) {
super.initWidget(savedInstanceState); super.initWidget(savedInstanceState);
mScPrivateBookcase.setChecked(openPrivate); binding.scPrivateBookcase.setChecked(openPrivate);
mScFingerprint.setChecked(openFingerprint); binding.scFingerprint.setChecked(openFingerprint);
if (openPrivate) mLlContent.setVisibility(View.VISIBLE); if (openPrivate) binding.llContent.setVisibility(View.VISIBLE);
} }
@Override @Override
protected void initClick() { protected void initClick() {
super.initClick(); super.initClick();
mRlPrivateBookcase.setOnClickListener(v -> { binding.rlPrivateBookcase.setOnClickListener(v -> {
if (openPrivate) { if (openPrivate) {
DialogCreator.createCommonDialog(getContext(), "关闭私密书架", DialogCreator.createCommonDialog(getContext(), "关闭私密书架",
"确定要关闭私密书架吗?\n注意:这将会删除私密书架中的全部书籍!", "确定要关闭私密书架吗?\n注意:这将会删除私密书架中的全部书籍!",
true, (dialog, which) -> { true, (dialog, which) -> {
BookGroupService.getInstance().deletePrivateGroup(); BookGroupService.getInstance().deletePrivateGroup();
SharedPreUtils.getInstance().putString("privatePwd", ""); SharedPreUtils.getInstance().putString("privatePwd", "");
mLlContent.setVisibility(View.GONE); binding.llContent.setVisibility(View.GONE);
openPrivate = !openPrivate; openPrivate = !openPrivate;
openFingerprint = false; openFingerprint = false;
SharedPreUtils.getInstance().putBoolean("openPrivate", openPrivate); SharedPreUtils.getInstance().putBoolean("openPrivate", openPrivate);
SharedPreUtils.getInstance().putBoolean("openFingerprint", openFingerprint); SharedPreUtils.getInstance().putBoolean("openFingerprint", openFingerprint);
mScPrivateBookcase.setChecked(openPrivate); binding.scPrivateBookcase.setChecked(openPrivate);
mScFingerprint.setChecked(openFingerprint); binding.scFingerprint.setChecked(openFingerprint);
}, null); }, null);
} else { } else {
final String[] pwd = new String[1]; final String[] pwd = new String[1];
@ -100,15 +88,15 @@ public class PrivateBooksFragment extends BaseFragment {
BookGroupService.getInstance().createPrivateGroup(); BookGroupService.getInstance().createPrivateGroup();
SharedPreUtils.getInstance().putString("privatePwd", CyptoUtils.encode(APPCONST.KEY, pwd[0])); SharedPreUtils.getInstance().putString("privatePwd", CyptoUtils.encode(APPCONST.KEY, pwd[0]));
dialog.dismiss(); dialog.dismiss();
mLlContent.setVisibility(View.VISIBLE); binding.llContent.setVisibility(View.VISIBLE);
openPrivate = !openPrivate; openPrivate = !openPrivate;
SharedPreUtils.getInstance().putBoolean("openPrivate", openPrivate); SharedPreUtils.getInstance().putBoolean("openPrivate", openPrivate);
mScPrivateBookcase.setChecked(openPrivate); binding.scPrivateBookcase.setChecked(openPrivate);
}); });
} }
}); });
mLlHideBooks.setOnClickListener(v -> { binding.llHideBooks.setOnClickListener(v -> {
MyApplication.runOnUiThread(() -> { MyApplication.runOnUiThread(() -> {
String privateGroupId = SharedPreUtils.getInstance().getString("privateGroupId"); String privateGroupId = SharedPreUtils.getInstance().getString("privateGroupId");
List<Book> mBooks = BookService.getInstance().getAllBooks(); List<Book> 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]; final String[] pwd = new String[1];
MyAlertDialog.createInputDia(getContext(), getString(R.string.change_pwd), MyAlertDialog.createInputDia(getContext(), getString(R.string.change_pwd),
"", "", InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD, "", "", InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD,
@ -171,21 +159,21 @@ public class PrivateBooksFragment extends BaseFragment {
(dialog, which) -> { (dialog, which) -> {
SharedPreUtils.getInstance().putString("privatePwd", CyptoUtils.encode(APPCONST.KEY, pwd[0])); SharedPreUtils.getInstance().putString("privatePwd", CyptoUtils.encode(APPCONST.KEY, pwd[0]));
dialog.dismiss(); dialog.dismiss();
mLlContent.setVisibility(View.VISIBLE); binding.llContent.setVisibility(View.VISIBLE);
}); });
}); });
mRlFingerprint.setOnClickListener( binding.rlFingerprint.setOnClickListener(
(v) -> { (v) -> {
if (openFingerprint) { if (openFingerprint) {
openFingerprint = false; openFingerprint = false;
mScFingerprint.setChecked(openFingerprint); binding.scFingerprint.setChecked(openFingerprint);
SharedPreUtils.getInstance().putBoolean("openFingerprint", openFingerprint); SharedPreUtils.getInstance().putBoolean("openFingerprint", openFingerprint);
} else { } else {
if (!FingerprintUtils.supportFingerprint(getActivity())) return; if (!FingerprintUtils.supportFingerprint(getActivity())) return;
FingerprintDialog fd = new FingerprintDialog((AppCompatActivity) getActivity(),false, needGoTo -> { FingerprintDialog fd = new FingerprintDialog((AppCompatActivity) getActivity(),false, needGoTo -> {
openFingerprint = true; openFingerprint = true;
mScFingerprint.setChecked(openFingerprint); binding.scFingerprint.setChecked(openFingerprint);
SharedPreUtils.getInstance().putBoolean("openFingerprint", openFingerprint); SharedPreUtils.getInstance().putBoolean("openFingerprint", openFingerprint);
}); });
fd.setCancelable(false); fd.setCancelable(false);
@ -208,12 +196,12 @@ public class PrivateBooksFragment extends BaseFragment {
public void init(){ public void init(){
openPrivate = SharedPreUtils.getInstance().getBoolean("openPrivate"); openPrivate = SharedPreUtils.getInstance().getBoolean("openPrivate");
openFingerprint = SharedPreUtils.getInstance().getBoolean("openFingerprint"); openFingerprint = SharedPreUtils.getInstance().getBoolean("openFingerprint");
mScPrivateBookcase.setChecked(openPrivate); binding.scPrivateBookcase.setChecked(openPrivate);
mScFingerprint.setChecked(openFingerprint); binding.scFingerprint.setChecked(openFingerprint);
if (openPrivate) { if (openPrivate) {
mLlContent.setVisibility(View.VISIBLE); binding.llContent.setVisibility(View.VISIBLE);
}else { }else {
mLlContent.setVisibility(View.GONE); binding.llContent.setVisibility(View.GONE);
} }
} }

@ -4,13 +4,11 @@ import android.os.Bundle;
import android.text.InputType; import android.text.InputType;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.view.ViewGroup;
import android.widget.NumberPicker; import android.widget.NumberPicker;
import android.widget.TextView;
import java.util.ArrayList; import java.util.ArrayList;
import butterknife.BindView;
import io.reactivex.Single; import io.reactivex.Single;
import io.reactivex.SingleOnSubscribe; import io.reactivex.SingleOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers; 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.BaseFragment;
import xyz.fycz.myreader.base.observer.MySingleObserver; import xyz.fycz.myreader.base.observer.MySingleObserver;
import xyz.fycz.myreader.common.APPCONST; 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.BackupRestoreUi;
import xyz.fycz.myreader.model.storage.WebDavHelp; import xyz.fycz.myreader.model.storage.WebDavHelp;
import xyz.fycz.myreader.ui.dialog.MyAlertDialog; import xyz.fycz.myreader.ui.dialog.MyAlertDialog;
@ -31,32 +30,18 @@ import xyz.fycz.myreader.util.ToastUtils;
* @date 2021/1/9 12:08 * @date 2021/1/9 12:08
*/ */
public class WebDavFragment extends BaseFragment { public class WebDavFragment extends BaseFragment {
@BindView(R.id.webdav_setting_webdav_url)
LinearLayout llWebdavUrl; private FragmentWebdavSettingBinding binding;
@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 String webdavUrl; private String webdavUrl;
private String webdavAccount; private String webdavAccount;
private String webdavPassword; private String webdavPassword;
private int restoreNum; private int restoreNum;
@Override @Override
protected int getContentId() { protected View bindView(LayoutInflater inflater, ViewGroup container) {
return R.layout.fragment_webdav_setting; binding = FragmentWebdavSettingBinding.inflate(inflater, container, false);
return binding.getRoot();
} }
@Override @Override
@ -71,56 +56,56 @@ public class WebDavFragment extends BaseFragment {
@Override @Override
protected void initWidget(Bundle savedInstanceState) { protected void initWidget(Bundle savedInstanceState) {
super.initWidget(savedInstanceState); super.initWidget(savedInstanceState);
tvWebdavUrl.setText(webdavUrl); binding.tvWebdavUrl.setText(webdavUrl);
tvWebdavAccount.setText(StringHelper.isEmpty(webdavAccount) ? "请输入WebDav账号" : webdavAccount); binding.tvWebdavAccount.setText(StringHelper.isEmpty(webdavAccount) ? "请输入WebDav账号" : webdavAccount);
tvWebdavPassword.setText(StringHelper.isEmpty(webdavPassword) ? "请输入WebDav授权密码" : "************"); binding.tvWebdavPassword.setText(StringHelper.isEmpty(webdavPassword) ? "请输入WebDav授权密码" : "************");
mTvRestoreNum.setText(getString(R.string.cur_restore_list_num, restoreNum)); binding.tvRestoreNum.setText(getString(R.string.cur_restore_list_num, restoreNum));
} }
@Override @Override
protected void initClick() { protected void initClick() {
super.initClick(); super.initClick();
final String[] webdavTexts = new String[3]; final String[] webdavTexts = new String[3];
llWebdavUrl.setOnClickListener(v -> { binding.webdavSettingWebdavUrl.setOnClickListener(v -> {
MyAlertDialog.createInputDia(getContext(), getString(R.string.webdav_url), MyAlertDialog.createInputDia(getContext(), getString(R.string.webdav_url),
"", webdavUrl.equals(APPCONST.DEFAULT_WEB_DAV_URL) ? "", webdavUrl.equals(APPCONST.DEFAULT_WEB_DAV_URL) ?
"" : webdavUrl, InputType.TYPE_CLASS_TEXT,true, 100, "" : webdavUrl, InputType.TYPE_CLASS_TEXT,true, 100,
text -> webdavTexts[0] = text, text -> webdavTexts[0] = text,
(dialog, which) -> { (dialog, which) -> {
webdavUrl = webdavTexts[0]; webdavUrl = webdavTexts[0];
tvWebdavUrl.setText(webdavUrl); binding.tvWebdavUrl.setText(webdavUrl);
SharedPreUtils.getInstance().putString("webdavUrl", webdavUrl); SharedPreUtils.getInstance().putString("webdavUrl", webdavUrl);
dialog.dismiss(); dialog.dismiss();
}, null, "恢复默认", (dialog, which) -> { }, null, "恢复默认", (dialog, which) -> {
webdavUrl = APPCONST.DEFAULT_WEB_DAV_URL; webdavUrl = APPCONST.DEFAULT_WEB_DAV_URL;
tvWebdavUrl.setText(webdavUrl); binding.tvWebdavUrl.setText(webdavUrl);
SharedPreUtils.getInstance().putString("webdavUrl", webdavUrl); SharedPreUtils.getInstance().putString("webdavUrl", webdavUrl);
}); });
}); });
llWebdavAccount.setOnClickListener(v -> { binding.webdavSettingWebdavAccount.setOnClickListener(v -> {
MyAlertDialog.createInputDia(getContext(), getString(R.string.webdav_account), MyAlertDialog.createInputDia(getContext(), getString(R.string.webdav_account),
"", webdavAccount, true, 100, "", webdavAccount, true, 100,
text -> webdavTexts[1] = text, text -> webdavTexts[1] = text,
(dialog, which) -> { (dialog, which) -> {
webdavAccount = webdavTexts[1]; webdavAccount = webdavTexts[1];
tvWebdavAccount.setText(webdavAccount); binding.tvWebdavAccount.setText(webdavAccount);
SharedPreUtils.getInstance().putString("webdavAccount", webdavAccount); SharedPreUtils.getInstance().putString("webdavAccount", webdavAccount);
dialog.dismiss(); dialog.dismiss();
}); });
}); });
llWebdavPassword.setOnClickListener(v -> { binding.webdavSettingWebdavPassword.setOnClickListener(v -> {
MyAlertDialog.createInputDia(getContext(), getString(R.string.webdav_password), MyAlertDialog.createInputDia(getContext(), getString(R.string.webdav_password),
"", webdavPassword, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD, "", webdavPassword, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD,
true, 100, true, 100,
text -> webdavTexts[2] = text, text -> webdavTexts[2] = text,
(dialog, which) -> { (dialog, which) -> {
webdavPassword = webdavTexts[2]; webdavPassword = webdavTexts[2];
tvWebdavPassword.setText("************"); binding.tvWebdavPassword.setText("************");
SharedPreUtils.getInstance().putString("webdavPassword", webdavPassword); SharedPreUtils.getInstance().putString("webdavPassword", webdavPassword);
dialog.dismiss(); dialog.dismiss();
}); });
}); });
llWebdavRestore.setOnClickListener(v -> { binding.webdavSettingWebdavRestore.setOnClickListener(v -> {
Single.create((SingleOnSubscribe<ArrayList<String>>) emitter -> { Single.create((SingleOnSubscribe<ArrayList<String>>) emitter -> {
emitter.onSuccess(WebDavHelp.INSTANCE.getWebDavFileNames()); emitter.onSuccess(WebDavHelp.INSTANCE.getWebDavFileNames());
}).subscribeOn(Schedulers.io()) }).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); View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_number_picker, null);
NumberPicker threadPick = view.findViewById(R.id.number_picker); NumberPicker threadPick = view.findViewById(R.id.number_picker);
threadPick.setMaxValue(100); threadPick.setMaxValue(100);
@ -150,7 +135,7 @@ public class WebDavFragment extends BaseFragment {
.setPositiveButton("确定", (dialog, which) -> { .setPositiveButton("确定", (dialog, which) -> {
restoreNum = threadPick.getValue(); restoreNum = threadPick.getValue();
SharedPreUtils.getInstance().putInt("restoreNum", restoreNum); 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) }).setNegativeButton("取消", null)
.show(); .show();
}); });

@ -3,30 +3,19 @@ package xyz.fycz.myreader.ui.popmenu;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; 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.application.SysManager;
import xyz.fycz.myreader.databinding.MenuAutoPageBinding;
import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.entity.Setting;
public class AutoPageMenu extends FrameLayout { public class AutoPageMenu extends FrameLayout {
@BindView(R.id.tv_auto_scroll_speed) private MenuAutoPageBinding binding;
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;
public AutoPageMenu(@NonNull Context context) { public AutoPageMenu(@NonNull Context context) {
super(context); super(context);
@ -44,18 +33,17 @@ public class AutoPageMenu extends FrameLayout {
} }
private void init(Context context) { private void init(Context context) {
View view = LayoutInflater.from(context).inflate(R.layout.menu_auto_page, this); binding = MenuAutoPageBinding.inflate(LayoutInflater.from(context), this, true);
ButterKnife.bind(this, view);
} }
public void setListener(Callback callback) { public void setListener(Callback callback) {
Setting setting = SysManager.getSetting(); Setting setting = SysManager.getSetting();
sbAutoPageSpeed.setProgress(110 - setting.getAutoScrollSpeed()); binding.sbAutoScrollProgress.setProgress(110 - setting.getAutoScrollSpeed());
tvAutoPageSpeed.setText(String.format("翻页速度:%s %%", 110 - setting.getAutoScrollSpeed())); binding.tvAutoScrollSpeed.setText(String.format("翻页速度:%s %%", 110 - setting.getAutoScrollSpeed()));
sbAutoPageSpeed.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { binding.sbAutoScrollProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
tvAutoPageSpeed.setText(String.format("翻页速度:%s %%", progress)); binding.tvAutoScrollSpeed.setText(String.format("翻页速度:%s %%", progress));
} }
@Override @Override
@ -72,11 +60,11 @@ public class AutoPageMenu extends FrameLayout {
callback.onSpeedChange(); callback.onSpeedChange();
} }
}); });
tvExitAutoPage.setOnClickListener(v -> callback.onExitClick()); binding.tvExitAutoPage.setOnClickListener(v -> callback.onExitClick());
} }
public void setNavigationBarHeight(int height) { public void setNavigationBarHeight(int height) {
vwNavigationBar.getLayoutParams().height = height; binding.vwNavigationBar.getLayoutParams().height = height;
} }
public interface Callback{ public interface Callback{

@ -4,38 +4,21 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.SeekBar; import android.widget.SeekBar;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; 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.application.SysManager;
import xyz.fycz.myreader.databinding.MenuBrightnessEyeBinding;
import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.entity.Setting;
import xyz.fycz.myreader.util.BrightUtil; import xyz.fycz.myreader.util.BrightUtil;
import xyz.fycz.myreader.widget.CircleCheckBox;
public class BrightnessEyeMenu extends FrameLayout { public class BrightnessEyeMenu extends FrameLayout {
@BindView(R.id.ll_follow_sys)
LinearLayout llFollowSys; private MenuBrightnessEyeBinding binding;
@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 Callback callback; private Callback callback;
@ -59,8 +42,7 @@ public class BrightnessEyeMenu extends FrameLayout {
} }
private void init(Context context) { private void init(Context context) {
View view = LayoutInflater.from(context).inflate(R.layout.menu_brightness_eye, this); binding = MenuBrightnessEyeBinding.inflate(LayoutInflater.from(context), this, true);
ButterKnife.bind(this, view);
} }
public void setListener(Activity activity, Callback callback) { public void setListener(Activity activity, Callback callback) {
@ -70,22 +52,21 @@ public class BrightnessEyeMenu extends FrameLayout {
} }
public void initWidget() { public void initWidget() {
sbBrightness.setProgress(setting.getBrightProgress()); binding.sbBrightnessProgress.setProgress(setting.getBrightProgress());
cbFollowSys.setChecked(setting.isBrightFollowSystem()); binding.cbFollowSys.setChecked(setting.isBrightFollowSystem());
binding.sbProtectEye.setProgress(setting.getBlueFilterPercent() - 10);
sbProtectEye.setProgress(setting.getBlueFilterPercent() - 10); binding.cbProtectEye.setChecked(setting.isProtectEye());
cbProtectEye.setChecked(setting.isProtectEye()); binding.sbProtectEye.setEnabled(binding.cbProtectEye.isChecked());
sbProtectEye.setEnabled(cbProtectEye.isChecked());
} }
private void initListener() { private void initListener() {
//设置亮度 //设置亮度
sbBrightness.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { binding.sbBrightnessProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser) { if (fromUser) {
BrightUtil.setBrightness((AppCompatActivity) context, progress); BrightUtil.setBrightness((AppCompatActivity) context, progress);
cbFollowSys.setChecked(false); binding.cbFollowSys.setChecked(false);
setting.setBrightProgress(progress); setting.setBrightProgress(progress);
setting.setBrightFollowSystem(false); setting.setBrightFollowSystem(false);
SysManager.saveSetting(setting); SysManager.saveSetting(setting);
@ -103,9 +84,9 @@ public class BrightnessEyeMenu extends FrameLayout {
} }
}); });
//亮度跟随系统 //亮度跟随系统
cbFollowSys.setOnClickListener(v -> { binding.cbFollowSys.setOnClickListener(v -> {
cbFollowSys.setChecked(!cbFollowSys.isChecked()); binding.cbFollowSys.setChecked(!binding.cbFollowSys.isChecked());
if (cbFollowSys.isChecked()) { if (binding.cbFollowSys.isChecked()) {
BrightUtil.followSystemBright((AppCompatActivity) context); BrightUtil.followSystemBright((AppCompatActivity) context);
setting.setBrightFollowSystem(true); setting.setBrightFollowSystem(true);
} else { } else {
@ -116,7 +97,7 @@ public class BrightnessEyeMenu extends FrameLayout {
}); });
//设置蓝光过滤 //设置蓝光过滤
sbProtectEye.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { binding.sbProtectEye.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser) { if (fromUser) {
@ -137,17 +118,17 @@ public class BrightnessEyeMenu extends FrameLayout {
} }
}); });
//是否开启护眼 //是否开启护眼
cbProtectEye.setOnClickListener(v -> { binding.cbProtectEye.setOnClickListener(v -> {
cbProtectEye.setChecked(!cbProtectEye.isChecked()); binding.cbProtectEye.setChecked(!binding.cbProtectEye.isChecked());
sbProtectEye.setEnabled(cbProtectEye.isChecked()); binding.sbProtectEye.setEnabled(binding.cbProtectEye.isChecked());
setting.setProtectEye(cbProtectEye.isChecked()); setting.setProtectEye(binding.cbProtectEye.isChecked());
SysManager.saveSetting(setting); SysManager.saveSetting(setting);
callback.onProtectEyeChange(); callback.onProtectEyeChange();
}); });
} }
public void setNavigationBarHeight(int height) { public void setNavigationBarHeight(int height) {
vwNavigationBar.getLayoutParams().height = height; binding.vwNavigationBar.getLayoutParams().height = height;
} }
public interface Callback { public interface Callback {

@ -1,93 +1,26 @@
package xyz.fycz.myreader.ui.popmenu; package xyz.fycz.myreader.ui.popmenu;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.ButterKnife;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.application.SysManager;
import xyz.fycz.myreader.databinding.MenuCustomizeComBinding;
import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.entity.Setting;
import xyz.fycz.myreader.ui.dialog.DialogCreator; 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; import static xyz.fycz.myreader.widget.page.PageLoader.DEFAULT_MARGIN_WIDTH;
public class CustomizeComMenu extends FrameLayout { public class CustomizeComMenu extends FrameLayout {
@BindView(R.id.tv_line_spacing)
TextView tvLineSpacing; private MenuCustomizeComBinding binding;
@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 Callback callback; private Callback callback;
@ -109,8 +42,7 @@ public class CustomizeComMenu extends FrameLayout {
} }
private void init(Context context) { private void init(Context context) {
View view = LayoutInflater.from(context).inflate(R.layout.menu_customize_com, this); binding = MenuCustomizeComBinding.inflate(LayoutInflater.from(context), this, true);
ButterKnife.bind(this, view);
} }
public void setListener(Callback callback) { public void setListener(Callback callback) {
@ -120,7 +52,7 @@ public class CustomizeComMenu extends FrameLayout {
} }
public void setNavigationBarHeight(int height) { 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() { private void initListener() {
ivLineAdd.setOnClickListener(v -> { binding.ivLineAdd.setOnClickListener(v -> {
float tem = setting.getLineMultiplier() + 0.1f; float tem = setting.getLineMultiplier() + 0.1f;
if (tem >= -0.3f && tem <= 3.0f) { if (tem >= -0.3f && tem <= 3.0f) {
setting.setLineMultiplier(tem); setting.setLineMultiplier(tem);
@ -151,7 +83,7 @@ public class CustomizeComMenu extends FrameLayout {
callback.onTextPChange(); callback.onTextPChange();
} }
}); });
ivLineMinus.setOnClickListener(v -> { binding.ivLineMinus.setOnClickListener(v -> {
float tem = setting.getLineMultiplier() - 0.1f; float tem = setting.getLineMultiplier() - 0.1f;
if (tem >= -0.3f && tem <= 3.0f) { if (tem >= -0.3f && tem <= 3.0f) {
setting.setLineMultiplier(tem); setting.setLineMultiplier(tem);
@ -159,7 +91,7 @@ public class CustomizeComMenu extends FrameLayout {
callback.onTextPChange(); callback.onTextPChange();
} }
}); });
sbLineProgress.setOnSeekBarChangeListener(new OnSeekBarChange() { binding.sbLineProgress.setOnSeekBarChangeListener(new OnSeekBarChange() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (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; float tem = setting.getParagraphSize() + 0.1f;
if (tem >= 0.0f && tem <= 3.0f) { if (tem >= 0.0f && tem <= 3.0f) {
setting.setParagraphSize(tem); setting.setParagraphSize(tem);
@ -177,7 +109,7 @@ public class CustomizeComMenu extends FrameLayout {
callback.onTextPChange(); callback.onTextPChange();
} }
}); });
ivParaMinus.setOnClickListener(v -> { binding.ivParaMinus.setOnClickListener(v -> {
float tem = setting.getParagraphSize() - 0.1f; float tem = setting.getParagraphSize() - 0.1f;
if (tem >= 0.0f && tem <=3.0f) { if (tem >= 0.0f && tem <=3.0f) {
setting.setParagraphSize(tem); setting.setParagraphSize(tem);
@ -185,7 +117,7 @@ public class CustomizeComMenu extends FrameLayout {
callback.onTextPChange(); callback.onTextPChange();
} }
}); });
sbParaProgress.setOnSeekBarChangeListener(new OnSeekBarChange() { binding.sbParaProgress.setOnSeekBarChangeListener(new OnSeekBarChange() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (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; float tem = setting.getTextLetterSpacing() + 0.01f;
if (tem >= -0.20f && tem <= 0.50f) { if (tem >= -0.20f && tem <= 0.50f) {
setting.setTextLetterSpacing(tem); setting.setTextLetterSpacing(tem);
@ -203,7 +135,7 @@ public class CustomizeComMenu extends FrameLayout {
callback.onTextPChange(); callback.onTextPChange();
} }
}); });
ivTextMinus.setOnClickListener(v -> { binding.ivTextMinus.setOnClickListener(v -> {
float tem = setting.getTextLetterSpacing() - 0.01f; float tem = setting.getTextLetterSpacing() - 0.01f;
if (tem >= -0.20f && tem <= 0.50f) { if (tem >= -0.20f && tem <= 0.50f) {
setting.setTextLetterSpacing(tem); setting.setTextLetterSpacing(tem);
@ -211,7 +143,7 @@ public class CustomizeComMenu extends FrameLayout {
callback.onTextPChange(); callback.onTextPChange();
} }
}); });
sbTextProgress.setOnSeekBarChangeListener(new OnSeekBarChange() { binding.sbTextProgress.setOnSeekBarChangeListener(new OnSeekBarChange() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser){ if (fromUser){
@ -221,7 +153,7 @@ public class CustomizeComMenu extends FrameLayout {
} }
} }
}); });
ivLeftAdd.setOnClickListener(v -> { binding.ivLeftAdd.setOnClickListener(v -> {
int tem = setting.getPaddingLeft() + 1; int tem = setting.getPaddingLeft() + 1;
if (tem >= 0 && tem <= 100) { if (tem >= 0 && tem <= 100) {
setting.setPaddingLeft(tem); setting.setPaddingLeft(tem);
@ -229,7 +161,7 @@ public class CustomizeComMenu extends FrameLayout {
callback.onMarginChange(); callback.onMarginChange();
} }
}); });
ivLeftMinus.setOnClickListener(v -> { binding.ivLeftMinus.setOnClickListener(v -> {
int tem = setting.getPaddingLeft() - 1; int tem = setting.getPaddingLeft() - 1;
if (tem >= 0 && tem <= 100) { if (tem >= 0 && tem <= 100) {
setting.setPaddingLeft(tem); setting.setPaddingLeft(tem);
@ -237,7 +169,7 @@ public class CustomizeComMenu extends FrameLayout {
callback.onMarginChange(); callback.onMarginChange();
} }
}); });
ivRightAdd.setOnClickListener(v -> { binding.ivRightAdd.setOnClickListener(v -> {
int tem = setting.getPaddingRight() + 1; int tem = setting.getPaddingRight() + 1;
if (tem >= 0 && tem <= 100) { if (tem >= 0 && tem <= 100) {
setting.setPaddingRight(tem); setting.setPaddingRight(tem);
@ -245,7 +177,7 @@ public class CustomizeComMenu extends FrameLayout {
callback.onMarginChange(); callback.onMarginChange();
} }
}); });
ivRightMinus.setOnClickListener(v -> { binding.ivRightMinus.setOnClickListener(v -> {
int tem = setting.getPaddingRight() - 1; int tem = setting.getPaddingRight() - 1;
if (tem >= 0 && tem <= 100) { if (tem >= 0 && tem <= 100) {
setting.setPaddingRight(tem); setting.setPaddingRight(tem);
@ -253,7 +185,7 @@ public class CustomizeComMenu extends FrameLayout {
callback.onMarginChange(); callback.onMarginChange();
} }
}); });
ivTopAdd.setOnClickListener(v -> { binding.ivTopAdd.setOnClickListener(v -> {
int tem = setting.getPaddingTop() + 1; int tem = setting.getPaddingTop() + 1;
if (tem >= 0 && tem <= 100) { if (tem >= 0 && tem <= 100) {
setting.setPaddingTop(tem); setting.setPaddingTop(tem);
@ -261,7 +193,7 @@ public class CustomizeComMenu extends FrameLayout {
callback.onMarginChange(); callback.onMarginChange();
} }
}); });
ivTopMinus.setOnClickListener(v -> { binding.ivTopMinus.setOnClickListener(v -> {
int tem = setting.getPaddingTop() - 1; int tem = setting.getPaddingTop() - 1;
if (tem >= 0 && tem <= 100) { if (tem >= 0 && tem <= 100) {
setting.setPaddingTop(tem); setting.setPaddingTop(tem);
@ -269,7 +201,7 @@ public class CustomizeComMenu extends FrameLayout {
callback.onMarginChange(); callback.onMarginChange();
} }
}); });
ivBottomAdd.setOnClickListener(v -> { binding.ivBottomAdd.setOnClickListener(v -> {
int tem = setting.getPaddingBottom() + 1; int tem = setting.getPaddingBottom() + 1;
if (tem >= 0 && tem <= 100) { if (tem >= 0 && tem <= 100) {
setting.setPaddingBottom(tem); setting.setPaddingBottom(tem);
@ -277,7 +209,7 @@ public class CustomizeComMenu extends FrameLayout {
callback.onMarginChange(); callback.onMarginChange();
} }
}); });
ivBottomMinus.setOnClickListener(v -> { binding.ivBottomMinus.setOnClickListener(v -> {
int tem = setting.getPaddingBottom() - 1; int tem = setting.getPaddingBottom() - 1;
if (tem >= 0 && tem <= 100) { if (tem >= 0 && tem <= 100) {
setting.setPaddingBottom(tem); setting.setPaddingBottom(tem);
@ -285,23 +217,23 @@ public class CustomizeComMenu extends FrameLayout {
callback.onMarginChange(); callback.onMarginChange();
} }
}); });
sbLeftProgress.setOnSeekBarChangeListener(onPaddingChange); binding.sbLeftProgress.setOnSeekBarChangeListener(onPaddingChange);
sbRightProgress.setOnSeekBarChangeListener(onPaddingChange); binding.sbRightProgress.setOnSeekBarChangeListener(onPaddingChange);
sbTopProgress.setOnSeekBarChangeListener(onPaddingChange); binding.sbTopProgress.setOnSeekBarChangeListener(onPaddingChange);
sbBottomProgress.setOnSeekBarChangeListener(onPaddingChange); binding.sbBottomProgress.setOnSeekBarChangeListener(onPaddingChange);
tvNormalCom.setOnClickListener(v -> { binding.tvNormalCom.setOnClickListener(v -> {
setting.setTightCom(false); setting.setTightCom(false);
initSelect(); initSelect();
callback.onRefreshUI(); callback.onRefreshUI();
}); });
tvTightCom.setOnClickListener(v -> { binding.tvTightCom.setOnClickListener(v -> {
setting.setTightCom(true); setting.setTightCom(true);
initSelect(); initSelect();
callback.onRefreshUI(); callback.onRefreshUI();
DialogCreator.createTipDialog(getContext(), getContext().getResources().getString(R.string.tight_com_tip)); DialogCreator.createTipDialog(getContext(), getContext().getResources().getString(R.string.tight_com_tip));
}); });
tvReset.setOnClickListener(v -> { binding.tvReset.setOnClickListener(v -> {
setting.setLineMultiplier(1); setting.setLineMultiplier(1);
setting.setParagraphSize(0.9f); setting.setParagraphSize(0.9f);
setting.setTextLetterSpacing(0); setting.setTextLetterSpacing(0);
@ -317,42 +249,42 @@ public class CustomizeComMenu extends FrameLayout {
private void initLine(){ private void initLine(){
int line = (int) (setting.getLineMultiplier() * 10); 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(){ private void initPara(){
int para = (int) (setting.getParagraphSize() * 10); 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(){ private void initText(){
int text = (int) (setting.getTextLetterSpacing() * 100); 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(){ private void initLeft(){
int left = setting.getPaddingLeft(); 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(){ private void initRight(){
int right = setting.getPaddingRight(); 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(){ private void initTop(){
int top = setting.getPaddingTop(); 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(){ private void initBottom(){
int bottom = setting.getPaddingBottom(); 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(){ private void initSelect(){
tvTightCom.setSelected(setting.isTightCom()); binding.tvTightCom.setSelected(setting.isTightCom());
tvNormalCom.setSelected(!setting.isTightCom()); binding.tvNormalCom.setSelected(!setting.isTightCom());
} }
private void initProgress(TextView tvSpacing, SeekBar sbProgress, String text, int value){ private void initProgress(TextView tvSpacing, SeekBar sbProgress, String text, int value){

@ -3,25 +3,19 @@ package xyz.fycz.myreader.ui.popmenu;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -29,19 +23,16 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import com.jaredrummler.android.colorpicker.ColorPickerDialog; import com.jaredrummler.android.colorpicker.ColorPickerDialog;
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.application.SysManager;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.databinding.MenuCumtomizeLayoutBinding;
import xyz.fycz.myreader.entity.ReadStyle; import xyz.fycz.myreader.entity.ReadStyle;
import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.entity.Setting;
import xyz.fycz.myreader.ui.dialog.DialogCreator; 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.FileUtils;
import xyz.fycz.myreader.util.utils.GsonExtensionsKt; import xyz.fycz.myreader.util.utils.GsonExtensionsKt;
import xyz.fycz.myreader.util.utils.MeUtils; import xyz.fycz.myreader.util.utils.MeUtils;
import xyz.fycz.myreader.widget.CircleCheckBox;
import xyz.fycz.myreader.widget.HorizontalListView;
public class CustomizeLayoutMenu extends FrameLayout { public class CustomizeLayoutMenu extends FrameLayout {
@BindView(R.id.iv_bg_color)
ImageView ivBgColor; private MenuCumtomizeLayoutBinding binding;
@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 Callback callback; private Callback callback;
@ -98,8 +71,7 @@ public class CustomizeLayoutMenu extends FrameLayout {
} }
private void init(Context context) { private void init(Context context) {
View view = LayoutInflater.from(context).inflate(R.layout.menu_cumtomize_layout, this); binding = MenuCumtomizeLayoutBinding.inflate(LayoutInflater.from(context), this, true);
ButterKnife.bind(this, view);
} }
public void setListener(Activity activity, Callback callback) { public void setListener(Activity activity, Callback callback) {
@ -110,14 +82,14 @@ public class CustomizeLayoutMenu extends FrameLayout {
} }
private void initWidget() { private void initWidget() {
ivBgColor.setImageDrawable(setting.getBgDrawable(setting.getCurReadStyleIndex(), context, 200, 120)); binding.ivBgColor.setImageDrawable(setting.getBgDrawable(setting.getCurReadStyleIndex(), context, 200, 120));
ivFontColor.setImageDrawable(new ColorDrawable(setting.getTextColor())); binding.ivFontColor.setImageDrawable(new ColorDrawable(setting.getTextColor()));
cbShareLayout.setChecked(setting.isSharedLayout()); binding.cbShareLayout.setChecked(setting.isSharedLayout());
//背景图列表 //背景图列表
bgImgListAdapter = new BgImgListAdapter(context); bgImgListAdapter = new BgImgListAdapter(context);
bgImgListAdapter.initList(); bgImgListAdapter.initList();
bgImgList.setAdapter(bgImgListAdapter); binding.bgImgList.setAdapter(bgImgListAdapter);
} }
public void upColor() { public void upColor() {
@ -126,12 +98,12 @@ public class CustomizeLayoutMenu extends FrameLayout {
ToastUtils.showInfo("当前正在编辑夜间模式"); ToastUtils.showInfo("当前正在编辑夜间模式");
curStyleIndex = 6; curStyleIndex = 6;
} }
ivFontColor.setImageDrawable(new ColorDrawable(setting.getTextColor())); binding.ivFontColor.setImageDrawable(new ColorDrawable(setting.getTextColor()));
ivBgColor.setImageDrawable(setting.getBgDrawable(curStyleIndex, context, 200, 120)); binding.ivBgColor.setImageDrawable(setting.getBgDrawable(curStyleIndex, context, 200, 120));
} }
private void initListener() { private void initListener() {
ivBgColor.setOnClickListener(v -> { binding.ivBgColor.setOnClickListener(v -> {
ColorPickerDialog.newBuilder() ColorPickerDialog.newBuilder()
.setColor(setting.getBgColor()) .setColor(setting.getBgColor())
.setShowAlphaSlider(false) .setShowAlphaSlider(false)
@ -140,14 +112,14 @@ public class CustomizeLayoutMenu extends FrameLayout {
.show((FragmentActivity) context); .show((FragmentActivity) context);
}); });
//选择文字颜色 //选择文字颜色
ivFontColor.setOnClickListener(view -> binding.ivFontColor.setOnClickListener(view ->
ColorPickerDialog.newBuilder() ColorPickerDialog.newBuilder()
.setColor(setting.getTextColor()) .setColor(setting.getTextColor())
.setShowAlphaSlider(false) .setShowAlphaSlider(false)
.setDialogType(ColorPickerDialog.TYPE_PRESETS) .setDialogType(ColorPickerDialog.TYPE_PRESETS)
.setDialogId(APPCONST.SELECT_TEXT_COLOR) .setDialogId(APPCONST.SELECT_TEXT_COLOR)
.show((FragmentActivity) context)); .show((FragmentActivity) context));
cbShareLayout.setOnClickListener(v -> { binding.cbShareLayout.setOnClickListener(v -> {
if (!setting.isSharedLayout()) { if (!setting.isSharedLayout()) {
DialogCreator.createCommonDialog(context, "提示", DialogCreator.createCommonDialog(context, "提示",
context.getString(R.string.share_layout_tip), context.getString(R.string.share_layout_tip),
@ -155,16 +127,16 @@ public class CustomizeLayoutMenu extends FrameLayout {
setting.setSharedLayout(true); setting.setSharedLayout(true);
setting.sharedLayout(); setting.sharedLayout();
SysManager.saveSetting(setting); SysManager.saveSetting(setting);
cbShareLayout.setChecked(true); binding.cbShareLayout.setChecked(true);
}, null); }, null);
} else { } else {
setting.setSharedLayout(false); setting.setSharedLayout(false);
setting.sharedLayout(); setting.sharedLayout();
SysManager.saveSetting(setting); 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) { if (i == 0) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE); intent.addCategory(Intent.CATEGORY_OPENABLE);
@ -175,7 +147,7 @@ public class CustomizeLayoutMenu extends FrameLayout {
setAssetsBg(bgPath); setAssetsBg(bgPath);
} }
}); });
tvSaveLayout.setOnClickListener(v -> { binding.tvSaveLayout.setOnClickListener(v -> {
CharSequence[] items = new CharSequence[6]; CharSequence[] items = new CharSequence[6];
for (int i = 0; i < items.length; i++) { for (int i = 0; i < items.length; i++) {
if (i == 5) { if (i == 5) {
@ -194,9 +166,9 @@ public class CustomizeLayoutMenu extends FrameLayout {
ToastUtils.showSuccess("布局保存成功"); ToastUtils.showSuccess("布局保存成功");
}).show(); }).show();
}); });
tvImportLayout.setOnClickListener(v -> importLayout()); binding.tvImportLayout.setOnClickListener(v -> importLayout());
tvExportLayout.setOnClickListener(v -> exportLayout()); binding.tvExportLayout.setOnClickListener(v -> exportLayout());
tvResetLayout.setOnClickListener(v -> { binding.tvResetLayout.setOnClickListener(v -> {
DialogCreator.createCommonDialog(context, "重置布局", DialogCreator.createCommonDialog(context, "重置布局",
"重置布局将会恢复所有布局为默认状态,确定要重置吗?", "重置布局将会恢复所有布局为默认状态,确定要重置吗?",
true, (dialog, which) -> { true, (dialog, which) -> {
@ -211,7 +183,7 @@ public class CustomizeLayoutMenu extends FrameLayout {
} }
public void setNavigationBarHeight(int height) { public void setNavigationBarHeight(int height) {
vwNavigationBar.getLayoutParams().height = height; binding.vwNavigationBar.getLayoutParams().height = height;
} }
public void setAssetsBg(String path) { public void setAssetsBg(String path) {

@ -6,74 +6,25 @@ import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; 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.R;
import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.application.SysManager;
import xyz.fycz.myreader.databinding.MenuReadSettingBinding;
import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.entity.Setting;
import xyz.fycz.myreader.enums.Language; import xyz.fycz.myreader.enums.Language;
import xyz.fycz.myreader.ui.activity.ReadActivity; import xyz.fycz.myreader.ui.activity.ReadActivity;
import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.DialogCreator;
import xyz.fycz.myreader.ui.dialog.MyAlertDialog; import xyz.fycz.myreader.ui.dialog.MyAlertDialog;
import xyz.fycz.myreader.util.BrightUtil;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.widget.custom.CircleImageView;
import xyz.fycz.myreader.widget.page.PageMode; import xyz.fycz.myreader.widget.page.PageMode;
public class ReadSettingMenu extends FrameLayout { public class ReadSettingMenu extends FrameLayout {
@BindView(R.id.tv_reduce_text_size)
TextView tvReduceTextSize; private MenuReadSettingBinding binding;
@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 View vLastLineSpacing = null; private View vLastLineSpacing = null;
@ -100,8 +51,7 @@ public class ReadSettingMenu extends FrameLayout {
} }
private void init(Context context) { private void init(Context context) {
View view = LayoutInflater.from(context).inflate(R.layout.menu_read_setting, this); binding = MenuReadSettingBinding.inflate(LayoutInflater.from(context), this, true);
ButterKnife.bind(this, view);
} }
public void setListener(Activity activity, Callback callback) { public void setListener(Activity activity, Callback callback) {
@ -112,11 +62,11 @@ public class ReadSettingMenu extends FrameLayout {
} }
public void setNavigationBarHeight(int height) { public void setNavigationBarHeight(int height) {
vwNavigationBar.getLayoutParams().height = height; binding.vwNavigationBar.getLayoutParams().height = height;
} }
private void initWidget() { private void initWidget() {
tvTextSize.setText(String.valueOf(setting.getReadWordSize())); binding.tvTextSize.setText(String.valueOf(setting.getReadWordSize()));
initSwitchST(false); initSwitchST(false);
initComposition(); initComposition();
initStyleImage(); initStyleImage();
@ -126,9 +76,9 @@ public class ReadSettingMenu extends FrameLayout {
private void initListener() { private void initListener() {
//减小字体 //减小字体
tvReduceTextSize.setOnClickListener(v -> { binding.tvReduceTextSize.setOnClickListener(v -> {
if (setting.getReadWordSize() > 10) { if (setting.getReadWordSize() > 10) {
tvTextSize.setText(String.valueOf(setting.getReadWordSize() - 1)); binding.tvTextSize.setText(String.valueOf(setting.getReadWordSize() - 1));
setting.setReadWordSize(setting.getReadWordSize() - 1); setting.setReadWordSize(setting.getReadWordSize() - 1);
SysManager.saveSetting(setting); SysManager.saveSetting(setting);
if (callback != null) { if (callback != null) {
@ -137,9 +87,9 @@ public class ReadSettingMenu extends FrameLayout {
} }
}); });
//增大字体 //增大字体
tvIncreaseTextSize.setOnClickListener(v -> { binding.tvIncreaseTextSize.setOnClickListener(v -> {
if (setting.getReadWordSize() < 60) { if (setting.getReadWordSize() < 60) {
tvTextSize.setText(String.valueOf(setting.getReadWordSize() + 1)); binding.tvTextSize.setText(String.valueOf(setting.getReadWordSize() + 1));
setting.setReadWordSize(setting.getReadWordSize() + 1); setting.setReadWordSize(setting.getReadWordSize() + 1);
SysManager.saveSetting(setting); SysManager.saveSetting(setting);
if (callback != null) { if (callback != null) {
@ -148,24 +98,24 @@ public class ReadSettingMenu extends FrameLayout {
} }
}); });
//繁简切换 //繁简切换
tvSwitchST.setOnClickListener(v -> { binding.tvSwitchSt.setOnClickListener(v -> {
initSwitchST(true); initSwitchST(true);
callback.onRefreshUI(); 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) AlertDialog dialog = new AlertDialog.Builder(context, R.style.alertDialogTheme)
.setTitle("缩进") .setTitle("缩进")
.setSingleChoiceItems(context.getResources().getStringArray(R.array.indent), .setSingleChoiceItems(context.getResources().getStringArray(R.array.indent),
@ -180,12 +130,12 @@ public class ReadSettingMenu extends FrameLayout {
dialog.show(); dialog.show();
}); });
//样式选择 //样式选择
ivCommonStyle.setOnClickListener(v -> selectedStyle(0)); binding.ivCommonStyle.setOnClickListener(v -> selectedStyle(0));
ivLeatherStyle.setOnClickListener(v -> selectedStyle(1)); binding.ivLeatherStyle.setOnClickListener(v -> selectedStyle(1));
ivProtectEyeStyle.setOnClickListener(v -> selectedStyle(2)); binding.ivProtectEyeStyle.setOnClickListener(v -> selectedStyle(2));
ivBreenStyle.setOnClickListener(v -> selectedStyle(3)); binding.ivBreenStyle.setOnClickListener(v -> selectedStyle(3));
ivBlueStyle.setOnClickListener(v -> selectedStyle(4)); binding.ivBlueDeepStyle.setOnClickListener(v -> selectedStyle(4));
ivCustomStyle.setOnClickListener(v -> { binding.ivCustomStyle.setOnClickListener(v -> {
setting.saveLayout(5); setting.saveLayout(5);
if (setting.isDayStyle()) { if (setting.isDayStyle()) {
selectedStyle(5); selectedStyle(5);
@ -193,9 +143,9 @@ public class ReadSettingMenu extends FrameLayout {
((ReadActivity) context).showCustomizeLayoutMenu(); ((ReadActivity) context).showCustomizeLayoutMenu();
}); });
//自动翻页 //自动翻页
tvAutoPage.setOnClickListener(v -> callback.onAutoPageClick()); binding.readTvAutoPage.setOnClickListener(v -> callback.onAutoPageClick());
//翻页模式 //翻页模式
tvPageMode.setOnClickListener(v -> { binding.readTvPageMode.setOnClickListener(v -> {
//显示翻页模式视图 //显示翻页模式视图
int checkedItem; int checkedItem;
switch (setting.getPageMode()) { switch (setting.getPageMode()) {
@ -249,21 +199,21 @@ public class ReadSettingMenu extends FrameLayout {
}).show(); }).show();
}); });
//横屏竖屏切换 //横屏竖屏切换
tvHVScreen.setOnClickListener(v -> { binding.readTvHvScreen.setOnClickListener(v -> {
setting.setHorizontalScreen(!setting.isHorizontalScreen()); setting.setHorizontalScreen(!setting.isHorizontalScreen());
initHVScreen(); initHVScreen();
SysManager.saveSetting(setting); SysManager.saveSetting(setting);
callback.onHVChange(); callback.onHVChange();
}); });
//更多设置 //更多设置
tvMoreSetting.setOnClickListener(v -> callback.onMoreSettingClick()); binding.readTvMoreSetting.setOnClickListener(v -> callback.onMoreSettingClick());
} }
private void initSwitchST(boolean isChange) { private void initSwitchST(boolean isChange) {
switch (setting.getLanguage()){ switch (setting.getLanguage()){
case normal: case normal:
tvSwitchST.setSelected(false); binding.tvSwitchSt.setSelected(false);
tvSwitchST.setText("繁"); binding.tvSwitchSt.setText("繁");
if (isChange){ if (isChange){
setting.setLanguage(Language.traditional); setting.setLanguage(Language.traditional);
ToastUtils.showInfo("已设置文本为简转繁"); ToastUtils.showInfo("已设置文本为简转繁");
@ -271,8 +221,8 @@ public class ReadSettingMenu extends FrameLayout {
} }
break; break;
case traditional: case traditional:
tvSwitchST.setSelected(true); binding.tvSwitchSt.setSelected(true);
tvSwitchST.setText("繁"); binding.tvSwitchSt.setText("繁");
if (isChange){ if (isChange){
setting.setLanguage(Language.simplified); setting.setLanguage(Language.simplified);
DialogCreator.createTipDialog(context, context.getString(R.string.traditional_to_simplified_tip)); DialogCreator.createTipDialog(context, context.getString(R.string.traditional_to_simplified_tip));
@ -280,8 +230,8 @@ public class ReadSettingMenu extends FrameLayout {
} }
break; break;
case simplified: case simplified:
tvSwitchST.setSelected(true); binding.tvSwitchSt.setSelected(true);
tvSwitchST.setText("简"); binding.tvSwitchSt.setText("简");
if (isChange){ if (isChange){
setting.setLanguage(Language.normal); setting.setLanguage(Language.normal);
ToastUtils.showInfo("已取消简转繁/繁转简,当前为原始文本"); ToastUtils.showInfo("已取消简转繁/繁转简,当前为原始文本");
@ -295,41 +245,41 @@ public class ReadSettingMenu extends FrameLayout {
} }
public void initStyleImage() { public void initStyleImage() {
ivCommonStyle.setImageDrawable(setting.getBgDrawable(0, context, 50, 50)); binding.ivCommonStyle.setImageDrawable(setting.getBgDrawable(0, context, 50, 50));
ivLeatherStyle.setImageDrawable(setting.getBgDrawable(1, context, 50, 50)); binding.ivLeatherStyle.setImageDrawable(setting.getBgDrawable(1, context, 50, 50));
ivProtectEyeStyle.setImageDrawable(setting.getBgDrawable(2, context, 50, 50)); binding.ivProtectEyeStyle.setImageDrawable(setting.getBgDrawable(2, context, 50, 50));
ivBreenStyle.setImageDrawable(setting.getBgDrawable(3, context, 50, 50)); binding.ivBreenStyle.setImageDrawable(setting.getBgDrawable(3, context, 50, 50));
ivBlueStyle.setImageDrawable(setting.getBgDrawable(4, context, 50, 50)); binding.ivBlueDeepStyle.setImageDrawable(setting.getBgDrawable(4, context, 50, 50));
} }
public void initStyle() { public void initStyle() {
if (!setting.isDayStyle()){ if (!setting.isDayStyle()){
return; return;
} }
ivCommonStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text)); binding.ivCommonStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text));
ivLeatherStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text)); binding.ivLeatherStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text));
ivProtectEyeStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text)); binding.ivProtectEyeStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text));
ivBreenStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text)); binding.ivBreenStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text));
ivBlueStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text)); binding.ivBlueDeepStyle.setBorderColor(context.getResources().getColor(R.color.read_menu_text));
ivCustomStyle.setSelected(false); binding.ivCustomStyle.setSelected(false);
switch (setting.getCurReadStyleIndex()) { switch (setting.getCurReadStyleIndex()) {
case 0: 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; break;
case 1: 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; break;
case 2: 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; break;
case 3: 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; break;
case 4: 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; break;
case 5: case 5:
ivCustomStyle.setSelected(true); binding.ivCustomStyle.setSelected(true);
break; break;
} }
} }
@ -340,28 +290,28 @@ public class ReadSettingMenu extends FrameLayout {
} }
switch (setting.getComposition()){ switch (setting.getComposition()){
case 0: case 0:
tvLineSpacing0.setSelected(true); binding.tvLineSpacing0.setSelected(true);
vLastLineSpacing = tvLineSpacing0; vLastLineSpacing = binding.tvLineSpacing0;
break; break;
case 1: case 1:
tvLineSpacing1.setSelected(true); binding.tvLineSpacing1.setSelected(true);
vLastLineSpacing = tvLineSpacing1; vLastLineSpacing = binding.tvLineSpacing1;
break; break;
case 2: case 2:
ivLineSpacing2.setSelected(true); binding.ivLineSpacing2.setSelected(true);
vLastLineSpacing = ivLineSpacing2; vLastLineSpacing = binding.ivLineSpacing2;
break; break;
case 3: case 3:
ivLineSpacing3.setSelected(true); binding.ivLineSpacing3.setSelected(true);
vLastLineSpacing = ivLineSpacing3; vLastLineSpacing = binding.ivLineSpacing3;
break; break;
case 4: case 4:
ivLineSpacing4.setSelected(true); binding.ivLineSpacing4.setSelected(true);
vLastLineSpacing = ivLineSpacing4; vLastLineSpacing = binding.ivLineSpacing4;
break; break;
default: default:
tvLineSpacing1.setSelected(true); binding.tvLineSpacing1.setSelected(true);
vLastLineSpacing = tvLineSpacing1; vLastLineSpacing = binding.tvLineSpacing1;
break; break;
} }
} }
@ -369,9 +319,9 @@ public class ReadSettingMenu extends FrameLayout {
private void initHVScreen(){ private void initHVScreen(){
if (setting.isHorizontalScreen()){ if (setting.isHorizontalScreen()){
tvHVScreen.setText("竖屏阅读"); binding.readTvHvScreen.setText("竖屏阅读");
}else { }else {
tvHVScreen.setText("横屏阅读"); binding.readTvHvScreen.setText("横屏阅读");
} }
} }

@ -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<BookType> mBookTypes;
private BookStoreBookAdapter mBookStoreBookAdapter;
private List<Book> 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<Book> bookList = (List<Book>) 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<BookType>) 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<Book> books = new ArrayList<>();
for (RankBook rb : (List<RankBook>) 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<Book> 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();
}
}

@ -2,7 +2,6 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="xyz.fycz.myreader.ui.fragment.BookStoreFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/colorBackground" android:background="@color/colorBackground"

@ -7,12 +7,15 @@
android:orientation="vertical" android:orientation="vertical"
tools:context=".ui.activity.AboutActivity"> tools:context=".ui.activity.AboutActivity">
<include layout="@layout/toolbar"/> <include
layout="@layout/toolbar"/>
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<include layout="@layout/layout_about_content" /> <include
android:id="@+id/il"
layout="@layout/layout_about_content" />
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>

@ -36,7 +36,9 @@
android:layout_height="190dp" android:layout_height="190dp"
android:scaleType="centerCrop"/>--> android:scaleType="centerCrop"/>-->
<include layout="@layout/layout_book_detail_header"/> <include
android:id="@+id/ih"
layout="@layout/layout_book_detail_header"/>
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
@ -57,7 +59,9 @@
android:layout_marginBottom="56dp" android:layout_marginBottom="56dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"> app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include layout="@layout/layout_book_detail_content"/> <include
android:id="@+id/ic"
layout="@layout/layout_book_detail_content"/>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>
@ -68,7 +72,9 @@
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:orientation="vertical"> android:orientation="vertical">
<include layout="@layout/layout_book_detail_bottom"/> <include
android:id="@+id/ib"
layout="@layout/layout_book_detail_bottom"/>
<View <View
android:layout_width="match_parent" android:layout_width="match_parent"

@ -1,8 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">

@ -17,7 +17,9 @@
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<include layout="@layout/toolbar"/> <include
android:id="@+id/it"
layout="@layout/toolbar"/>
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_refresh_search" android:id="@+id/iv_refresh_search"
android:layout_width="wrap_content" android:layout_width="wrap_content"

@ -1,58 +0,0 @@
<xyz.fycz.myreader.widget.RefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="xyz.fycz.myreader.ui.fragment.BookStoreFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_type_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="10">
</androidx.recyclerview.widget.RecyclerView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3">
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/srl_book_list"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smartrefresh.header.MaterialHeader
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_book_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.scwang.smartrefresh.layout.footer.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srlTextLoading="@string/loading_tip"
app:srlTextFailed="@string/loading_tip"
app:srlTextPulling="下拉加载更多"
app:srlAccentColor="@color/textSecondary"/>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
<ProgressBar
android:id="@+id/pb_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"/>
</RelativeLayout>
</LinearLayout>
</xyz.fycz.myreader.widget.RefreshLayout>

@ -1,2 +1,2 @@
#Tue Jan 19 18:54:31 CST 2021 #Mon Jan 25 21:29:58 CST 2021
VERSION_CODE=180 VERSION_CODE=180

@ -8,13 +8,13 @@ buildscript {
jcenter() jcenter()
mavenCentral() mavenCentral()
google() 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://plugins.gradle.org/m2/' }
maven { url "https://maven.java.net/content/groups/public/" } maven { url "https://maven.java.net/content/groups/public/" }
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.6.2' classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2' classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0'
classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.1' classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists 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

Loading…
Cancel
Save