Skip to content

Commit

Permalink
优化预览页,优化相关逻辑等.....
Browse files Browse the repository at this point in the history
  • Loading branch information
laishujie committed Jun 28, 2018
1 parent 0c75e79 commit c94d262
Show file tree
Hide file tree
Showing 23 changed files with 497 additions and 322 deletions.
51 changes: 44 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ android {
}
getSigningProperties()

compileSdkVersion 26
compileSdkVersion rootProject.ext.android.compileSdkVersion

defaultConfig {
applicationId "com.lai.mtc"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//只保留了中文和英文的语言资源
resConfigs "zh", "en"
Expand Down Expand Up @@ -95,7 +97,42 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation "com.android.support:design:$support"
androidTestImplementation rootProject.ext.dependencies.runner
androidTestImplementation rootProject.ext.dependencies.espresso

api rootProject.ext.dependencies.appcompat_v7
api rootProject.ext.dependencies.design
api rootProject.ext.dependencies.cardview
api rootProject.ext.dependencies.rxjava
api rootProject.ext.dependencies.rxandroid
api rootProject.ext.dependencies.retrofit
api rootProject.ext.dependencies.retrofit_converter_gson
api rootProject.ext.dependencies.retrofit_adapter_rxjava2
api rootProject.ext.dependencies.interceptor
api rootProject.ext.dependencies.rxlifecycle2
api rootProject.ext.dependencies.butterknife
annotationProcessor rootProject.ext.dependencies.butterknife_annotationProcessor

api rootProject.ext.dependencies.dagger
annotationProcessor rootProject.ext.dependencies.dagger_annotationProcessor
provided rootProject.ext.dependencies.dagger_provided
api rootProject.ext.dependencies.dagger_support
annotationProcessor rootProject.ext.dependencies.dagger_android_annotationProcessor

api rootProject.ext.dependencies.buttonStyle
api rootProject.ext.dependencies.BaseRecyclerViewAdapterHelper
api rootProject.ext.dependencies.lottie
api rootProject.ext.dependencies.glide
annotationProcessor rootProject.ext.dependencies.glide_annotationProcessor
api(rootProject.ext.dependencies.integration) {
transitive = false
}

implementation(rootProject.ext.dependencies.glide_recyclerview) {
// Excludes the support library because it's already included by Glide.
transitive = false
}
/*implementation "com.android.support:design:$support"
implementation "com.android.support:appcompat-v7:$support"
implementation "com.android.support:cardview-v7:$support"
testCompile 'junit:junit:4.12'
Expand Down Expand Up @@ -131,5 +168,5 @@ dependencies {
annotationProcessor "com.github.bumptech.glide:compiler:$glide"
implementation("com.github.bumptech.glide:okhttp3-integration:$glide") {
transitive = false
}
}*/
}
10 changes: 9 additions & 1 deletion app/objectbox-models/default.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"entities": [
{
"id": "1:8699208959836505960",
"lastPropertyId": "5:3948644640204751108",
"lastPropertyId": "7:3513099458287364368",
"name": "MyCollection",
"properties": [
{
Expand All @@ -27,6 +27,14 @@
{
"id": "5:3948644640204751108",
"name": "name"
},
{
"id": "6:1459824881156873142",
"name": "status"
},
{
"id": "7:3513099458287364368",
"name": "author"
}
],
"relations": []
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/lai/mtc/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,18 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_module) {
mMenuItem = item;
if ("多列".equals(item.getTitle())) {
if ("多列".equals(item.getTitle().toString())) {
((ComicsMainFragment) currentFragment).changeMode(ComicsPresenter.SINGLE_MODE, new Consumer<Boolean>() {
@Override
public void accept(Boolean aBoolean) throws Exception {
public void accept(Boolean aBoolean) {
mMenuItem.setIcon(getResources().getDrawable(R.drawable.ic_line_weight_black_24dp));
mMenuItem.setTitle("单列");
}
});
} else {
((ComicsMainFragment) currentFragment).changeMode(ComicsPresenter.MANY_MODE, new Consumer<Boolean>() {
@Override
public void accept(Boolean aBoolean) throws Exception {
public void accept(Boolean aBoolean) {
mMenuItem.setTitle("多列");
mMenuItem.setIcon(getResources().getDrawable(R.drawable.ic_dashboard_black_24dp));
}
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/com/lai/mtc/TestMainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lai.mtc;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

Expand All @@ -9,6 +10,7 @@
import com.lai.mtc.mvp.base.impl.BaseMvpActivity;
import com.lai.mtc.mvp.contract.ComicsPreviewContract;
import com.lai.mtc.mvp.presenter.ComicsPreviewPresenter;
import com.lai.mtc.mvp.utlis.ScreenUtils;
import com.lai.mtc.mvp.utlis.glide.GlideCacheUtil;
import com.lai.mtc.mvp.utlis.glide.ImageUtils;

Expand All @@ -25,7 +27,9 @@ public void init(Bundle savedInstanceState) {
findViewById(R.id.btn_1).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mPresenter.testList(TestMainActivity.this);
int[] imageWidthHeight = ScreenUtils.getImageWidthHeight(url);
Log.w("1111","ima");
//mPresenter.testList(TestMainActivity.this);
}
});
findViewById(R.id.btn_2).setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -53,7 +57,6 @@ public View getTitleBar() {
return null;
}

@Override
public void showPreview(ComicPreView comicPreView) {

}
Expand All @@ -63,6 +66,11 @@ public void showInfo(ComicListDetail comicListDetail) {

}

@Override
public void showPreview(ComicPreView comicPreView, boolean isRefresh) {

}

//@Inject
// Retrofit mComicApi;

Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/com/lai/mtc/bean/ComicListDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public List<ChaptersBean> getChapters() {

public void setChapters(List<ChaptersBean> chapters) {
this.chapters = chapters;
this.ascendingOrderChapters = chapters;
}

public List<MirrorsBean> getMirrors() {
Expand All @@ -167,6 +168,17 @@ public void setMirrors(List<MirrorsBean> mirrors) {
private java.util.List<String> tag_list;
private java.util.List<ChaptersBean> chapters;

public List<ChaptersBean> getAscendingOrderChapters() {
return ascendingOrderChapters;
}

public void setAscendingOrderChapters(List<ChaptersBean> ascendingOrderChapters) {
this.ascendingOrderChapters = ascendingOrderChapters;
}

//升序
private java.util.List<ChaptersBean> ascendingOrderChapters;

public List<ChaptersBean> getShowChapters() {
return mShowChapters;
}
Expand Down Expand Up @@ -237,7 +249,7 @@ public void setTrack_url(String track_url) {

}

public static class MirrorsBean implements IPopMenu,Serializable {
public static class MirrorsBean implements IPopMenu, Serializable {
private int id;
private String source;

Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/lai/mtc/comm/Parameter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.lai.mtc.comm;

//常见参数
public class Parameter {

//配置
public static final String SP_CONFIG = "config";
//预览模式
public static final String SP_PREVIEW_MODE = "module";
//集数分页标准
public static final int PAGING_STANDARD = 52;
//提前加载多少页
public static final int MAX_PRELOAD = 4;
}
74 changes: 0 additions & 74 deletions app/src/main/java/com/lai/mtc/comm/widget/MyPagerSnapHelper.java

This file was deleted.

4 changes: 2 additions & 2 deletions app/src/main/java/com/lai/mtc/di/module/NetModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ public Response intercept(Chain chain) throws IOException {

@Provides
@Singleton
OkHttpClient provideOkHttpClient(HttpLoggingInterceptor httpLoggingInterceptor,CommonInterceptor commonInterceptor,CacheInterceptor cacheInterceptor) {
OkHttpClient provideOkHttpClient(HttpLoggingInterceptor httpLoggingInterceptor, CommonInterceptor commonInterceptor, CacheInterceptor cacheInterceptor) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.cache(new Cache(new File(Environment.getExternalStorageDirectory().getPath(), "HttpCache"), 1024 * 1024 * 10)).
builder.cache(new Cache(new File(MTC.getApp().getFilesDir(), "HttpCache"), 1024 * 1024 * 10)).
addInterceptor(httpLoggingInterceptor)
.addInterceptor(commonInterceptor)
.addNetworkInterceptor(cacheInterceptor).retryOnConnectionFailure(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
public class ComicsPreviewContract {
//对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息
public interface View extends IView {
void showPreview(ComicPreView comicPreView);
void showPreview(ComicPreView comicPreView, boolean isRefresh);
}

//Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,如是否使用缓存
public interface Model extends IModel {
void requestPreview(int id, int cid, Context context);
void requestPreview(int id, int cid, Context context, boolean isRefresh);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
* @author Lai
* @time 2017/12/11 17:04
* @describe 漫画详情业务桥梁P
*
* @see SimplePresenter
* @see SimplePresenter
*/
public class ComicsListDetailPresenter extends BasePresenter<ComicsListDetailContract.View> implements ComicsListDetailContract.Model {

Expand All @@ -47,27 +46,26 @@ public void onDestroy() {
}

@Override
public void getComicById(final int id) {
public void getComicById(int id) {
mRootView.showLoading();
Observable.timer(1, TimeUnit.SECONDS).compose(mRootView.<Long>bindToLifecycle()).subscribe(new Consumer<Long>() {
@Override
public void accept(Long aLong) throws Exception {
mComicApi.getComicById(id).subscribeOn(Schedulers.io()).observeOn(Schedulers.computation())
.compose(mRootView.<ComicListDetail>bindToLifecycle()).map(new Function<ComicListDetail, ComicListDetail>() {
@Override
public ComicListDetail apply(ComicListDetail comicListDetail) throws Exception {
if (comicListDetail != null && !ListUtils.isEmpty(comicListDetail.getChapters())) {
List<ComicListDetail.ChaptersBean> mirrors = comicListDetail.getChapters();
if (mirrors.size() > 52) {
comicListDetail.setShowChapters(new ArrayList<>(mirrors.subList(0, 52)));
comicListDetail.setLastChapters(new ArrayList<>(mirrors.subList(52, mirrors.size())));
}
}
return comicListDetail;
}
}).compose(mRootView.<ComicListDetail>bindToLifecycle())
.onErrorResumeNext(new HttpResultFunction<ComicListDetail>())
.observeOn(AndroidSchedulers.mainThread()).subscribe(new HttpRxObserver<ComicListDetail>(new HttpRxObserver.IResult<ComicListDetail>() {
mComicApi.getComicById(id)
.compose(RxUtlis.<ComicListDetail>toMain())
.compose(mRootView.<ComicListDetail>bindToLifecycle())
/* .doOnNext(new Consumer<ComicListDetail>() {
@Override
public void accept(ComicListDetail comicListDetail) {
if (comicListDetail != null && !ListUtils.isEmpty(comicListDetail.getChapters())) {
List<ComicListDetail.ChaptersBean> mirrors = comicListDetail.getChapters();
if (mirrors.size() > 52) {
comicListDetail.setShowChapters(new ArrayList<>(mirrors.subList(0, 52)));
comicListDetail.setLastChapters(new ArrayList<>(mirrors.subList(52, mirrors.size())));
}
}
}
})*/
.onErrorResumeNext(new HttpResultFunction<ComicListDetail>())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new HttpRxObserver<>(new HttpRxObserver.IResult<ComicListDetail>() {
@Override
public void onSuccess(ComicListDetail comicListDetail) {
mRootView.showDetail(comicListDetail);
Expand All @@ -79,16 +77,14 @@ public void onError(ApiException e) {
mRootView.handleError(e);
}
}));
}
});
}

@Override
public void reverse(final ComicListDetail comicListDetail) {
mRootView.showLoading();
Observable.create(new ObservableOnSubscribe<ComicListDetail>() {
@Override
public void subscribe(ObservableEmitter<ComicListDetail> e) throws Exception {
public void subscribe(ObservableEmitter<ComicListDetail> e) {
if (comicListDetail != null && !ListUtils.isEmpty(comicListDetail.getChapters())) {
Collections.reverse(comicListDetail.getChapters());
List<ComicListDetail.ChaptersBean> mirrors = comicListDetail.getChapters();
Expand All @@ -101,7 +97,7 @@ public void subscribe(ObservableEmitter<ComicListDetail> e) throws Exception {
}
}).compose(RxUtlis.<ComicListDetail>toMain())
.onErrorResumeNext(new HttpResultFunction<ComicListDetail>())
.subscribe(new HttpRxObserver<ComicListDetail>(new HttpRxObserver.IResult<ComicListDetail>() {
.subscribe(new HttpRxObserver<>(new HttpRxObserver.IResult<ComicListDetail>() {
@Override
public void onSuccess(ComicListDetail comicListDetail) {
mRootView.hideLoading();
Expand Down
Loading

0 comments on commit c94d262

Please sign in to comment.