Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Adjust book detail UI and update activity horizontal margin
Browse files Browse the repository at this point in the history
  • Loading branch information
zchu committed Sep 20, 2017
1 parent 56b14ce commit d843435
Show file tree
Hide file tree
Showing 26 changed files with 493 additions and 113 deletions.
9 changes: 9 additions & 0 deletions app/src/main/java/com/youshibi/app/AppManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ public Activity beforeActivity() {
return activity;
}

public Activity beforeActivity(Activity activity) {
Activity beforeActivity = null;
int indexOf = mActivityStack.indexOf(activity);
if (indexOf >= 1) {
beforeActivity = mActivityStack.get(indexOf - 1);
}
return beforeActivity;
}


/**
* 结束当前Activity(堆栈中最后一个压入的)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/youshibi/app/AppRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public static void showSearchResultActivity(Context context, String keyword) {
CountEventHelper.countBookSearch(context, keyword);
}

public static void showBookCatalogActivity(Context context, String bookId, int sectionCount) {
context.startActivity(BookCatalogActivity.newIntent(context, bookId, sectionCount));
public static void showBookCatalogActivity(Context context, Book book, int sectionCount) {
context.startActivity(BookCatalogActivity.newIntent(context, book, sectionCount));
}

}
2 changes: 1 addition & 1 deletion app/src/main/java/com/youshibi/app/base/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void onSlideClosed() {

public Drawable getWindowBackground() {
if (windowBackground == null) {
Activity beforeActivity = AppManager.getInstance().beforeActivity();
Activity beforeActivity = AppManager.getInstance().beforeActivity(this);
if (beforeActivity != null) {
Object tag = beforeActivity.getWindow().getDecorView().getTag();

Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/youshibi/app/data/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import com.youshibi.app.AppContext;
import com.youshibi.app.BuildConfig;
import com.youshibi.app.data.bean.Book;
import com.youshibi.app.data.bean.BookDetail;
import com.youshibi.app.data.bean.BookSectionContent;
import com.youshibi.app.data.bean.BookSectionItem;
import com.youshibi.app.data.bean.BookType;
import com.youshibi.app.data.bean.Channel;
import com.youshibi.app.data.bean.DataList;
import com.youshibi.app.data.bean.AppRelease;
import com.youshibi.app.data.bean.LatestChapter;
import com.youshibi.app.data.net.RequestClient;
import com.youshibi.app.rx.HttpResultFunc;
import com.zchu.rxcache.CacheTarget;
Expand Down Expand Up @@ -299,4 +301,24 @@ public Observable<AppRelease> getLatestReleases() {
.map(new HttpResultFunc<AppRelease>());
}


/**
* 获取书籍详情
*/
public Observable<BookDetail> getBookDetail(String bookId) {
return RequestClient
.getServerAPI()
.getBookDetail(bookId)
.map(new HttpResultFunc<BookDetail>());
}

/**
* 获取最新章节
*/
public Observable<LatestChapter> getLatestChapter(List<String> bookIds) {
return RequestClient
.getServerAPI()
.getLatestChapter(bookIds)
.map(new HttpResultFunc<LatestChapter>());
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/youshibi/app/data/bean/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class Book implements Serializable, Parcelable {
@SerializedName("recommend_num")
private long recommendNum;

@SerializedName("create_date_time")
@SerializedName("create_time")
private String createDateTime;


Expand Down
46 changes: 46 additions & 0 deletions app/src/main/java/com/youshibi/app/data/bean/BookDetail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.youshibi.app.data.bean;

import com.google.gson.annotations.SerializedName;

/**
* author : zchu
* date : 2017/9/20
* desc :
*/

public class BookDetail {

private Book book;

@SerializedName("chapter_count")
private int chapterCount;

@SerializedName("last_chapter")
private LatestChapter latestChapter;

public Book getBook() {
return book;
}

public void setBook(Book book) {
this.book = book;
}

public int getChapterCount() {
return chapterCount;
}

public void setChapterCount(int chapterCount) {
this.chapterCount = chapterCount;
}

public LatestChapter getLatestChapter() {
return latestChapter;
}

public void setLatestChapter(LatestChapter latestChapter) {
this.latestChapter = latestChapter;
}


}
63 changes: 63 additions & 0 deletions app/src/main/java/com/youshibi/app/data/bean/LatestChapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.youshibi.app.data.bean;

import com.google.gson.annotations.SerializedName;

/**
* author : zchu
* date : 2017/9/20
* desc :
*/

public class LatestChapter {

/**
* chapter_id : d6771dd9-05da-4aa6-9344-0017ee8623cf
* chapter_index : 3127
* chapter_name : 第3119章 岂不是又纠缠不清了?
* create_time : 2017-04-02T10:51:45.367
*/

@SerializedName("chapter_id")
private String chapterId;

@SerializedName("chapter_index")
private int chapterIndex;

@SerializedName("chapter_name")
private String chapterName;

@SerializedName("create_time")
private String createTime;

public String getChapterId() {
return chapterId;
}

public void setChapterId(String chapterId) {
this.chapterId = chapterId;
}

public int getChapterIndex() {
return chapterIndex;
}

public void setChapterIndex(int chapterIndex) {
this.chapterIndex = chapterIndex;
}

public String getChapterName() {
return chapterName;
}

public void setChapterName(String chapterName) {
this.chapterName = chapterName;
}

public String getCreateTime() {
return createTime;
}

public void setCreateTime(String createTime) {
this.createTime = createTime;
}
}
20 changes: 18 additions & 2 deletions app/src/main/java/com/youshibi/app/data/net/ServerAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

import com.youshibi.app.data.bean.AppRelease;
import com.youshibi.app.data.bean.Book;
import com.youshibi.app.data.bean.BookDetail;
import com.youshibi.app.data.bean.BookSectionContent;
import com.youshibi.app.data.bean.BookSectionItem;
import com.youshibi.app.data.bean.BookType;
import com.youshibi.app.data.bean.Channel;
import com.youshibi.app.data.bean.DataList;
import com.youshibi.app.data.bean.HttpResult;
import com.youshibi.app.data.bean.LatestChapter;

import java.util.HashMap;
import java.util.List;

import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.QueryMap;
import rx.Observable;
Expand All @@ -30,6 +34,18 @@ public interface ServerAPI {
@GET("/v1/books")
Observable<HttpResult<DataList<Book>>> getBookList(@QueryMap HashMap<String, Object> map);

/**
* 获取小说详情
*/
@GET("/v1/books/{bookId}")
Observable<HttpResult<BookDetail>> getBookDetail(@Path("bookId") String bookId);

/**
* 书籍最新章节信息
*/
@POST("v1/books/latest-chapter")
Observable<HttpResult<LatestChapter>> getLatestChapter(@Body List<String> bookIds);

/**
* 搜索小说
*/
Expand Down Expand Up @@ -69,14 +85,14 @@ Observable<HttpResult<BookSectionContent>> getBookSectionContent(@Path("bookId")
*/
@GET("/v1/channels/books/{channelId}")
Observable<HttpResult<DataList<Book>>> getChannelBooks(@Path("channelId") long channelId,
@QueryMap HashMap<String, Object> map);
@QueryMap HashMap<String, Object> map);

/**
* 获取频道内容-书籍列表
*/
@GET("/v1/channels/book-ranking/{channelId}")
Observable<HttpResult<DataList<Book>>> getChannelBookRanking(@Path("channelId") long channelId,
@QueryMap HashMap<String, Object> map);
@QueryMap HashMap<String, Object> map);

/**
* 获取最新的app版本信息
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
Expand All @@ -18,12 +19,14 @@
import com.afollestad.materialdialogs.MaterialDialog;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.youshibi.app.R;
import com.youshibi.app.data.bean.Book;
import com.youshibi.app.mvp.MvpLoaderActivity;
import com.youshibi.app.ui.help.CommonAdapter;
import com.youshibi.app.ui.help.CommonViewHolder;
import com.youshibi.app.ui.help.RecyclerViewItemDecoration;
import com.youshibi.app.ui.help.ToolbarHelper;
import com.youshibi.app.util.DensityUtil;
import com.youshibi.app.util.ToastUtil;

import java.util.List;

Expand All @@ -34,7 +37,7 @@
*/

public class BookCatalogActivity extends MvpLoaderActivity<BookCatalogContract.Presenter> implements BookCatalogContract.View {
private static final String K_EXTRA_BOOK_ID = "book_id";
private static final String K_EXTRA_BOOK = "book";
private static final String K_EXTRA_SECTION_COUNT = "section_count";
private TextView tvSectionCount;
private TextView tvSectionSelection;
Expand All @@ -45,9 +48,9 @@ public class BookCatalogActivity extends MvpLoaderActivity<BookCatalogContract.P
private int sectionDataIndex;


public static Intent newIntent(Context context, String bookId, int sectionCount) {
public static Intent newIntent(Context context, Book book, int sectionCount) {
Intent intent = new Intent(context, BookCatalogActivity.class);
intent.putExtra(K_EXTRA_BOOK_ID, bookId);
intent.putExtra(K_EXTRA_BOOK, (Parcelable) book);
intent.putExtra(K_EXTRA_SECTION_COUNT, sectionCount);
return intent;
}
Expand All @@ -58,8 +61,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
setContentView(R.layout.activity_book_catalog);
ToolbarHelper.initToolbar(this, R.id.toolbar, true, "目录");
initView();
if(savedInstanceState!=null){
sectionDataIndex=savedInstanceState.getInt("sectionDataIndex");
if (savedInstanceState != null) {
sectionDataIndex = savedInstanceState.getInt("sectionDataIndex");
}
tvSectionCount.setText("共" + getIntent().getIntExtra(K_EXTRA_SECTION_COUNT, 50) + "章");
llSectionSelection.setOnClickListener(new View.OnClickListener() {
Expand All @@ -75,7 +78,7 @@ public void onClick(View view) {
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("sectionDataIndex",sectionDataIndex);
outState.putInt("sectionDataIndex", sectionDataIndex);
}

private void showSectionSelectionDialog() {
Expand All @@ -90,6 +93,8 @@ private void showSectionSelectionDialog() {
dialog = new MaterialDialog.Builder(this)
.customView(recyclerView, true)
.build();
} else {
sectionAdapter.notifyDataSetChanged();
}
dialog.show();

Expand All @@ -103,7 +108,7 @@ public void onBindPresenter(BookCatalogContract.Presenter presenter) {
@NonNull
@Override
public BookCatalogContract.Presenter createPresenter() {
return new BookCatalogPresenter(getIntent().getStringExtra(K_EXTRA_BOOK_ID),
return new BookCatalogPresenter((Book) getIntent().getParcelableExtra(K_EXTRA_BOOK),
getIntent().getIntExtra(K_EXTRA_SECTION_COUNT, 50));
}

Expand All @@ -120,7 +125,7 @@ public void showLoading() {

@Override
public void showError(String errorMsg) {

ToastUtil.showToast(errorMsg);
}

@Override
Expand All @@ -146,7 +151,13 @@ private BaseQuickAdapter createSectionAdapter(List<String> sectionData) {

@Override
protected void convert(CommonViewHolder helper, String item) {
((TextView) helper.itemView).setText(item);
TextView textView = ((TextView) helper.itemView);
textView.setText(item);
if (sectionDataIndex == helper.getLayoutPosition()) {
textView.setTextColor(ContextCompat.getColor(mContext, R.color.colorAccent));
} else {
textView.setTextColor(ContextCompat.getColor(mContext, R.color.textSecondary));
}
}

protected CommonViewHolder onCreateDefViewHolder(ViewGroup parent, int viewType) {
Expand All @@ -162,9 +173,9 @@ protected CommonViewHolder onCreateDefViewHolder(ViewGroup parent, int viewType)
@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
getPresenter().loadData(position + 1);
sectionDataIndex=position;
sectionDataIndex = position;
tvSectionSelection.setText((String) sectionAdapter.getData().get(position));
((LinearLayoutManager)recyclerView.getLayoutManager()).scrollToPositionWithOffset(0,0);
((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(0, 0);
if (dialog != null) {
dialog.dismiss();
}
Expand Down
Loading

0 comments on commit d843435

Please sign in to comment.