Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Invinciblelee committed May 25, 2019
1 parent b79fef6 commit 0d4b1c9
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 19 deletions.
16 changes: 16 additions & 0 deletions app/src/main/java/com/monke/monkeybook/bean/BookmarkBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
Expand Down Expand Up @@ -148,4 +150,18 @@ public void setPageIndex(Integer pageIndex) {
public String[] getFilters() {
return new String[]{chapterName, content};
}

@NonNull
@Override
public String toString() {
return "BookmarkBean{" +
"id=" + id +
", noteUrl='" + noteUrl + '\'' +
", bookName='" + bookName + '\'' +
", chapterName='" + chapterName + '\'' +
", chapterIndex=" + chapterIndex +
", pageIndex=" + pageIndex +
", content='" + content + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public DownloadBookBean(String name, String author, String tag, String noteUrl,
this.end = end;
}


protected DownloadBookBean(Parcel in) {
name = in.readString();
author = in.readString();
Expand Down Expand Up @@ -147,12 +148,12 @@ public int getSuccessCount() {
return successCount;
}

public int getWaitingCount(){
public int getWaitingCount() {
return this.downloadCount - this.successCount;
}

public synchronized void successCountAdd() {
if(this.successCount < this.downloadCount) {
if (this.successCount < this.downloadCount) {
this.successCount += 1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ public void onNext(BookShelfBean bookShelfBean) {

@Override
public void onError(Throwable e) {

}
});
}
Expand All @@ -304,7 +303,6 @@ public void onNext(BookShelfBean bookShelfBean) {

@Override
public void onError(Throwable e) {

}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ public int onStartCommand(Intent intent, int flags, int startId) {
}
break;
case removeDownloadAction:
int id = intent.getIntExtra("taskId", -1);
removeDownload(id);
if (intent.hasExtra("noteUrl")) {
removeDownload(intent.getStringExtra("noteUrl"));
} else {
removeDownload(intent.getIntExtra("taskId", -1));
}
break;
case cancelAction:
cancelDownload();
Expand Down Expand Up @@ -187,6 +190,20 @@ private void removeDownload(int id) {
}
}

private void removeDownload(String noteUrl) {
if (noteUrl == null) {
return;
}

for (int i = downloadTasks.size() - 1; i >= 0; i--) {
IDownloadTask downloadTask = downloadTasks.valueAt(i);
if (noteUrl.equals(downloadTask.getDownloadBook().getNoteUrl())) {
downloadTask.stopDownload();
break;
}
}
}

private void refreshDownloadList() {
ArrayList<DownloadBookBean> downloadBookBeans = new ArrayList<>();
for (int i = downloadTasks.size() - 1; i >= 0; i--) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import com.monke.monkeybook.service.ReadAloudService;
import com.monke.monkeybook.utils.StringUtils;
import com.monke.monkeybook.utils.SystemUtil;
import com.monke.monkeybook.utils.URLUtils;
import com.monke.monkeybook.view.fragment.ChapterDrawerFragment;
import com.monke.monkeybook.view.fragment.dialog.AlertDialog;
import com.monke.monkeybook.view.fragment.dialog.BookmarkDialog;
Expand All @@ -75,6 +76,7 @@
import com.monke.monkeybook.widget.page.PageView;
import com.monke.monkeybook.widget.theme.AppCompat;

import java.net.URL;
import java.util.List;

import butterknife.BindView;
Expand Down Expand Up @@ -480,7 +482,8 @@ private void showHideUrlViews() {
atvLayout.setVisibility(View.GONE);
} else {
int chapterIndex = mPresenter.getBookShelf().getDurChapter();
atvUrl.setText(mPresenter.getBookShelf().getChapter(chapterIndex).getDurChapterUrl());
atvUrl.setText(URLUtils.getAbsUrl(mPresenter.getBookShelf().getBookInfoBean().getChapterListUrl(),
mPresenter.getBookShelf().getChapter(chapterIndex).getDurChapterUrl()));
atvSourceName.setText(mPresenter.getBookShelf().getBookInfoBean().getOrigin());
if (TextUtils.isEmpty(atvUrl.getText())) {
atvDivider.setVisibility(View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
dismissAllowingStateLoss();
bookmarkBean.setContent(StringUtils.valueOf(tvContent.getText()));
if(bookmarkClick != null) {
bookmarkClick.openBookmark(bookmarkBean);
bookmarkClick.saveBookmark(bookmarkBean);
}
});

Expand All @@ -81,14 +81,14 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
dismissAllowingStateLoss();
bookmarkBean.setContent(StringUtils.valueOf(tvContent.getText()));
if(bookmarkClick != null) {
bookmarkClick.openBookmark(bookmarkBean);
bookmarkClick.saveBookmark(bookmarkBean);
}
});
View tvDel = findViewById(R.id.tv_del);
tvDel.setOnClickListener(v -> {
dismissAllowingStateLoss();
if(bookmarkClick != null) {
bookmarkClick.openBookmark(bookmarkBean);
bookmarkClick.delBookmark(bookmarkBean);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.monke.monkeybook.model.SearchBookModel;
import com.monke.monkeybook.utils.ListUtils;
import com.monke.monkeybook.utils.NetworkUtil;
import com.monke.monkeybook.utils.ScreenUtils;
import com.monke.monkeybook.utils.ToastUtils;
import com.monke.monkeybook.view.adapter.ChangeSourceAdapter;
import com.monke.monkeybook.widget.refreshview.RefreshRecyclerView;
Expand Down Expand Up @@ -135,7 +136,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
@Override
protected void onDialogAttachWindow(@NonNull Window window) {
window.setGravity(Gravity.CENTER);
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
int height = getResources().getDisplayMetrics().heightPixels - ScreenUtils.getStatusBarHeight();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, height);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
TextView tvDownload = findViewById(R.id.tv_download);

edtStart.setText(String.valueOf(start + 1));
edtEnd.setText(String.valueOf(total - 1));
edtEnd.setText(String.valueOf(total));

edtStart.addTextChangedListener(new TextWatcher() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import androidx.fragment.app.FragmentManager;

import com.monke.monkeybook.R;
import com.monke.monkeybook.utils.DensityUtil;
import com.monke.monkeybook.utils.MarkdownUtils;
import com.monke.monkeybook.utils.ScreenUtils;

import io.reactivex.schedulers.Schedulers;

Expand Down Expand Up @@ -58,6 +60,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
@Override
protected void onDialogAttachWindow(@NonNull Window window) {
window.setGravity(Gravity.CENTER);
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
int height = getResources().getDisplayMetrics().heightPixels - ScreenUtils.getStatusBarHeight();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, height);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public class MoreSettingPop extends PopupWindow {
View llswReadAloudKey;
@BindView(R.id.sw_read_aloud_key)
Switch swReadAloudKey;
@BindView(R.id.ll_sb_showTitle)
View llswShowTitle;
@BindView(R.id.sb_showTitle)
Switch swShowTitle;
@BindView(R.id.ll_sb_showBatteryNumber)
View llswShowBatteryNumber;
@BindView(R.id.sb_showBatteryNumber)
Expand Down Expand Up @@ -184,6 +188,13 @@ private void bindEvent() {
.create();
dialog.show();
});

llswShowTitle.setOnClickListener(view -> {
boolean isChecked = swShowTitle.isChecked();
swShowTitle.setChecked(!isChecked);
readBookControl.setShowTitle(!isChecked);
changeProListener.refresh();
});
}

private void initData() {
Expand All @@ -198,6 +209,7 @@ private void initData() {
sbImmersionBar.setChecked(readBookControl.getImmersionStatusBar());
swShowBatteryNumber.setChecked(readBookControl.getShowBatteryNumber());
swShowDividerLine.setChecked(readBookControl.getShowBottomLine());
swShowTitle.setChecked(readBookControl.getShowTitle());
upView();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.monke.monkeybook.bean.BookShelfBean;
import com.monke.monkeybook.bean.ChapterBean;
import com.monke.monkeybook.help.ChapterContentHelp;
import com.monke.monkeybook.help.ReadBookControl;
import com.monke.monkeybook.help.RxBusTag;
import com.monke.monkeybook.model.WebBookModel;
import com.monke.monkeybook.utils.IOUtils;
Expand Down Expand Up @@ -84,7 +85,7 @@ private TxtChapter loadChapter(ChapterBean chapter, BufferedReader br) {
int rHeight = mPageLoader.getVisibleHeight();
int titleLinesCount = 0;
try {
boolean showTitle = true; // 是否展示标题
boolean showTitle = ReadBookControl.getInstance().getShowTitle(); // 是否展示标题
String paragraph = chapter.getDurChapterName() + "\n"; //默认展示标题
if (collBook.isLocalBook()) {
br.readLine();
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/dialog_download_choice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@

<EditText
android:id="@+id/edt_start"
android:layout_width="50dp"
android:layout_width="56dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/bg_edit"
android:inputType="number"
android:lines="1"
android:maxLength="4"
android:maxLength="5"
android:paddingLeft="5dp"
android:paddingTop="4dp"
android:paddingRight="5dp"
Expand All @@ -75,13 +75,13 @@

<EditText
android:id="@+id/edt_end"
android:layout_width="50dp"
android:layout_width="56dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/bg_edit"
android:inputType="number"
android:lines="1"
android:maxLength="4"
android:maxLength="5"
android:paddingLeft="5dp"
android:paddingTop="4dp"
android:paddingRight="5dp"
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/res/layout/pop_more_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,33 @@
android:padding="15dp" />
</LinearLayout>

<LinearLayout
android:id="@+id/ll_sb_showTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="15dp"
android:paddingEnd="0dp"
android:text="@string/showTitle"
android:textColor="@color/colorTextDefault" />


<Switch
android:id="@+id/sb_showTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:padding="15dp" />
</LinearLayout>

<LinearLayout
android:id="@+id/ll_sb_showTimeBattery"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
<string name="refresh_default">书源同步</string>
<string name="no_last_chapter">无最新章节信息</string>
<string name="showTimeBattery">显示时间和电量</string>
<string name="showTitle">显示正文标题</string>
<string name="showBatteryNumber">显示电量数字</string>
<string name="showLine">显示分隔线</string>
<string name="darkStatusIcon">深色状态栏图标</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public abstract class BasePresenterImpl<T extends IView> implements IPresenter {
protected T mView;

@SuppressWarnings(value="unchecked")
@SuppressWarnings(value = "unchecked")
@Override
public void attachView(@NonNull IView iView) {
mView = (T) iView;
Expand Down

0 comments on commit 0d4b1c9

Please sign in to comment.