Skip to content

Commit

Permalink
修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
git committed Oct 26, 2016
1 parent de9b869 commit 404dcc6
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 50 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/com/tongming/manga/mvp/api/ApiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,14 @@ public Observable<Result> queryCollection(int uid, String name) {
return apiService.queryCollection(uid, name);
}

public Observable<ResponseBody> downloadImage(String url) {
public Observable<ResponseBody> downloadImage(String url, String source) {
Observable<ResponseBody> observable = null;
if (source.equals(SOURCE_DMZJ)) {
observable = apiService.downloadImageByDMZJ(url);
} else if (source.equals(SOURCE_IKAN)) {
observable = apiService.downloadImageByIKAN(url);
} else {
observable = apiService.downloadImageByIKAN(url);
}
return observable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void onNext(List<String> list) {

private void downloadImage() {
ApiManager.getInstance()
.downloadImage(imgs.get(info.getPosition()))
.downloadImage(imgs.get(info.getPosition()), info.getComic_source())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<ResponseBody>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
public class PageModel implements IPageModel {

private onGetPageListener onGetPageListener;
private String source;

public PageModel(PageModel.onGetPageListener onGetPageListener) {
this.onGetPageListener = onGetPageListener;
}

@Override
public Subscription getPage(String source, String chapterUrl) {
this.source = source;
return ApiManager.getInstance().getComicPage(source, chapterUrl)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
Expand Down Expand Up @@ -72,7 +74,7 @@ public void onError(Throwable e) {
@Override
public void onNext(String s) {
if (!TextUtils.isEmpty(s)) {
HeaderGlide.downloadImage(mContext, s);
HeaderGlide.downloadImage(mContext, s, source);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ protected void initView() {
toolbar.setTitle(intent.getStringExtra("name"));
String cover = intent.getStringExtra("cover");
if (!TextUtils.isEmpty(cover)) {
HeaderGlide.loadImage(this, cover, ivCover);
HeaderGlide.loadBitmap(this, cover, ivBlur);
HeaderGlide.loadImage(this, cover, ivCover, intent.getStringExtra("source"));
HeaderGlide.loadBitmap(this, cover, ivBlur, intent.getStringExtra("source"));
isCover = true;
getWindow().getSharedElementEnterTransition().addListener(new Transition.TransitionListener() {
@Override
Expand Down Expand Up @@ -188,8 +188,8 @@ public void onGetData(ComicInfo info) {
}
String cover = comicInfo.getCover();
if (!isCover) {
HeaderGlide.loadImage(this, cover, ivCover);
HeaderGlide.loadBitmap(this, cover, ivBlur);
HeaderGlide.loadImage(this, cover, ivCover, info.getComic_source());
HeaderGlide.loadBitmap(this, cover, ivBlur, info.getComic_source());
}
tvComicName.setText(this.comicInfo.getComic_name());
tvComicAuthor.setText("作者: " + comicInfo.getComic_author());
Expand Down Expand Up @@ -317,6 +317,7 @@ public void onClick(View v) {

private int getHistoryPos(String historyUrl) {
for (int i = 0; i < chapterList.size(); i++) {
Logger.d(chapterList.get(i).getChapter_url());
if (chapterList.get(i).getChapter_url().equals(historyUrl)) {
return i;
}
Expand Down Expand Up @@ -411,8 +412,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
isRead = true;
Logger.d("添加阅读记录");
}
/*adapter = new ChapterAdapter(chapterList, getHistoryPos(historyUrl), this);
gvChapter.setAdapter(adapter);*/
adapter.setHistoryPos(getHistoryPos(historyUrl));
adapter.notifyDataSetChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.widget.ImageView;

import com.tongming.manga.R;
import com.tongming.manga.mvp.api.ApiManager;
import com.tongming.manga.mvp.base.BaseActivity;
import com.tongming.manga.util.HeaderGlide;

Expand All @@ -26,7 +27,7 @@ protected int getLayoutId() {
protected void initView() {
String url = "http://images.dmzj.com/img/chapterpic/20457/55239/14743796761525.jpg";

HeaderGlide.loadImage(this, url, ivTest);
HeaderGlide.loadImage(this, url, ivTest, ApiManager.SOURCE_DMZJ);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
//不返回true,不拦截此处的事件 :( 绕了好久,为什么要这么傻去拦截...
}
//加载上一话
//TODO 如果图片大于屏幕的高度,出现问题
if ((manager.findFirstVisibleItemPosition() == 0)
|| (!sp.getBoolean("isPortrait", true) && manager.findFirstVisibleItemPosition() == 0)) {
if (sp.getBoolean("isPortrait", true)) {
Expand Down Expand Up @@ -471,7 +470,7 @@ public void onSuccess(ComicPage page) {
public void onPageCompleted(List<String> imgList) {
if (this.imgList == null) {
this.imgList = imgList;
adapter = new PageAdapter(this.imgList, this);
adapter = new PageAdapter(this.imgList, this, source);
rvPage.setAdapter(adapter);
isFirstLoad = false;
Logger.d("第一次加载成功");
Expand Down Expand Up @@ -579,7 +578,7 @@ public void onConfigurationChanged(Configuration newConfig) {
sp.edit().putBoolean("isPortrait", true).apply();
}
if (adapter != null && imgList != null) {
adapter = new PageAdapter(imgList, this);
adapter = new PageAdapter(imgList, this, source);
rvPage.setAdapter(adapter);
rvPage.addItemDecoration(new SpaceItemDecoration(30));
manager.scrollToPosition(currentPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
ComicCard bean = comicList.get(position);
String cover = bean.getCover();
if (!TextUtils.isEmpty(cover)) {
HeaderGlide.loadImage(mContext, bean.getCover(), holder.cover);
HeaderGlide.loadImage(mContext, bean.getCover(), holder.cover, bean.getComic_source());
}
holder.comicName.setText(bean.getComic_name());
if ("".equals(bean.getNewest_chapter())) {
Expand All @@ -140,21 +140,21 @@ public View getView(int position, View convertView, ViewGroup parent) {
} else if (historyComics != null) {
HistoryComic comic = historyComics.get(position);
if (!TextUtils.isEmpty(comic.getCover())) {
HeaderGlide.loadImage(mContext, comic.getCover(), holder.cover);
HeaderGlide.loadImage(mContext, comic.getCover(), holder.cover, comic.getComic_source());
}
holder.comicName.setText(comic.getName());
holder.chapterName.setText(comic.getHistoryName());
} else if (collectedComics != null) {
CollectedComic comic = collectedComics.get(position);
if (!TextUtils.isEmpty(comic.getCover())) {
HeaderGlide.loadImage(mContext, comic.getCover(), holder.cover);
HeaderGlide.loadImage(mContext, comic.getCover(), holder.cover, comic.getComic_source());
}
holder.comicName.setText(comic.getName());
holder.chapterName.setText(comic.getAuthor());
} else {
DownloadComic comic = downloadComicList.get(position);
if (!TextUtils.isEmpty(comic.getCover())) {
HeaderGlide.loadImage(mContext, comic.getCover(), holder.cover);
HeaderGlide.loadImage(mContext, comic.getCover(), holder.cover, comic.getComic_source());
}
/*Glide.with(mContext)
.load(comic.getCover())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import com.bumptech.glide.load.model.LazyHeaders;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
import com.tongming.manga.R;
import com.tongming.manga.mvp.api.ApiManager;
import com.tongming.manga.util.CommonUtil;
import com.tongming.manga.util.HeaderGlide;

import java.util.List;

Expand All @@ -32,10 +34,16 @@ public class PageAdapter extends RecyclerView.Adapter<PageAdapter.PageHolder> {
private Context mContext;
private int height;
private int width;
private String SOURCE_URL;

public PageAdapter(List<String> picList, Context mContext) {
public PageAdapter(List<String> picList, Context mContext, String source) {
this.picList = picList;
this.mContext = mContext;
if (source.equals(ApiManager.SOURCE_DMZJ)) {
SOURCE_URL = HeaderGlide.URL_DMZJ;
} else if (source.equals(ApiManager.SOURCE_IKAN)) {
SOURCE_URL = HeaderGlide.URL_IKAN;
}
height = CommonUtil.getDeviceHeight((Activity) mContext);
width = CommonUtil.getDeviceWidth((Activity) mContext);
}
Expand All @@ -50,10 +58,9 @@ public PageAdapter.PageHolder onCreateViewHolder(ViewGroup parent, int viewType)
@Override
public void onBindViewHolder(final PageAdapter.PageHolder holder, final int position) {
scaleImageView(1.78f, holder);
// HeaderGlide.loadPage(mContext, picList.get(position), holder.ivPage);

GlideUrl glideUrl = new GlideUrl(picList.get(position), new LazyHeaders.Builder()
.addHeader("Referer", "http://m.dmzj.com/")
final GlideUrl glideUrl = new GlideUrl(picList.get(position), new LazyHeaders.Builder()
.addHeader("Referer", SOURCE_URL)
.build());
Glide.with(mContext)
.load(glideUrl)
Expand Down Expand Up @@ -92,7 +99,7 @@ class PageHolder extends RecyclerView.ViewHolder {
@BindView(R.id.iv_page)
ImageView ivPage;

public PageHolder(View itemView) {
PageHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void onBindViewHolder(RVComicAdapter.ViewHolder holder, int position) {
ComicCard bean = comicList.get(position);
String cover = bean.getCover();
if (!TextUtils.isEmpty(cover)) {
HeaderGlide.loadImage(mContext, bean.getCover(), holder.cover);
HeaderGlide.loadImage(mContext, bean.getCover(), holder.cover, bean.getComic_source());
}
holder.comicName.setText(bean.getComic_name());
if ("".equals(bean.getNewest_chapter())) {
Expand All @@ -94,23 +94,23 @@ public void onBindViewHolder(RVComicAdapter.ViewHolder holder, int position) {
case HISTORY_COMIC:
HistoryComic comic = historyComics.get(position);
if (!TextUtils.isEmpty(comic.getCover())) {
HeaderGlide.loadImage(mContext, comic.getCover(), holder.cover);
HeaderGlide.loadImage(mContext, comic.getCover(), holder.cover, comic.getComic_source());
}
holder.comicName.setText(comic.getName());
holder.chapterName.setText(comic.getHistoryName());
break;
case COLLECTION_COMIC:
CollectedComic collectedComic = collectedComics.get(position);
if (!TextUtils.isEmpty(collectedComic.getCover())) {
HeaderGlide.loadImage(mContext, collectedComic.getCover(), holder.cover);
HeaderGlide.loadImage(mContext, collectedComic.getCover(), holder.cover, collectedComic.getComic_source());
}
holder.comicName.setText(collectedComic.getName());
holder.chapterName.setText(collectedComic.getAuthor());
break;
case DOWNLOAD_COMIC:
DownloadComic downloadComic = downloadComicList.get(position);
if (!TextUtils.isEmpty(downloadComic.getCover())) {
HeaderGlide.loadImage(mContext, downloadComic.getCover(), holder.cover);
HeaderGlide.loadImage(mContext, downloadComic.getCover(), holder.cover, downloadComic.getComic_source());
}
holder.comicName.setText(downloadComic.getName());
holder.comicName.setTextSize(15);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void UpdateUI(Context context, int position, String data) {
.load(url)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);*/
HeaderGlide.loadImage(getContext(), data, imageView);
HeaderGlide.loadImage(getContext(), data, imageView, hot.getBanner().get(position).getComic_source());
}
};
}
Expand Down
30 changes: 7 additions & 23 deletions app/src/main/java/com/tongming/manga/util/HeaderGlide.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import com.bumptech.glide.request.target.SimpleTarget;
import com.tongming.manga.mvp.api.ApiManager;

import static com.tencent.bugly.crashreport.inner.InnerAPI.context;

/**
* Author: Tongming
* Date: 2016/9/20
Expand All @@ -25,9 +23,8 @@ public class HeaderGlide {
public static final String URL_IKAN = "http://m.ikanman.com/";
public static final String REFERER = "Referer";

private static String getReferer() {
private static String getReferer(String source) {
String referer_url = URL_DMZJ;
String source = context.getSharedPreferences("config", Context.MODE_PRIVATE).getString("source", ApiManager.SOURCE_DMZJ);
if (source.equals(ApiManager.SOURCE_DMZJ)) {
referer_url = URL_DMZJ;
} else if (source.equals(ApiManager.SOURCE_IKAN)) {
Expand All @@ -36,9 +33,9 @@ private static String getReferer() {
return referer_url;
}

public static void loadImage(Context context, String url, ImageView view) {
public static void loadImage(Context context, String url, ImageView view, String source) {
GlideUrl glideUrl = new GlideUrl(url, new LazyHeaders.Builder()
.addHeader(REFERER, getReferer())
.addHeader(REFERER, getReferer(source))
.build());
Glide.with(context)
.load(glideUrl)
Expand All @@ -48,9 +45,9 @@ public static void loadImage(Context context, String url, ImageView view) {
.into(view);
}

public static void loadBitmap(Context context, String url, final ImageView view) {
public static void loadBitmap(Context context, String url, final ImageView view, String source) {
GlideUrl glideUrl = new GlideUrl(url, new LazyHeaders.Builder()
.addHeader(REFERER, getReferer())
.addHeader(REFERER, getReferer(source))
.build());
Glide.with(context)
.load(glideUrl)
Expand All @@ -64,22 +61,9 @@ public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glid
});
}

public static void loadPage(Context context, String url, ImageView view) {
GlideUrl glideUrl = new GlideUrl(url, new LazyHeaders.Builder()
.addHeader(REFERER, getReferer())
.build());
Glide.with(context)
.load(glideUrl)
.dontAnimate()
// .placeholder(R.color.gray)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.fitCenter()
.into(view);
}

public static void downloadImage(Context context, String url) {
public static void downloadImage(Context context, String url, String source) {
GlideUrl glideUrl = new GlideUrl(url, new LazyHeaders.Builder()
.addHeader(REFERER, getReferer())
.addHeader(REFERER, getReferer(source))
.build());
Glide.with(context)
.load(glideUrl)
Expand Down

0 comments on commit 404dcc6

Please sign in to comment.