Skip to content

Commit

Permalink
添加详细页面
Browse files Browse the repository at this point in the history
  • Loading branch information
HanteIsHante committed Apr 27, 2017
1 parent ff5a0b5 commit 229293f
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.hante.thirdopen.R;
import com.example.hante.thirdopen.base.BaseActivity;
import com.example.hante.thirdopen.mvp.entry.freebook.FreeBookInfo;
import com.example.hante.thirdopen.mvp.model.FreeBookModel;

import butterknife.BindView;
Expand All @@ -18,40 +21,83 @@
* Created By HanTe
*/

public class BookInfoActivity extends BaseActivity {
public class BookInfoActivity extends BaseActivity implements PageInterface {


@BindView(R.id.toolbar)
Toolbar toolbar;
Toolbar mToolbar;
@BindView(R.id.book_image)
ImageView bookImage;
ImageView mBookImage;
@BindView(R.id.book_name)
TextView bookName;
TextView mBookName;
@BindView(R.id.book_auth)
TextView bookAuth;
TextView mBookAuth;
@BindView(R.id.booktype)
TextView bookype;
TextView mBookType;
@BindView(R.id.book_progress)
TextView bookProgress;
TextView mBookProgress;
@BindView(R.id.download)
TextView download;
TextView mDownLoad;
@BindView(R.id.book_desc)
TextView bookDesc;
TextView mBookDesc;
@BindView(R.id.book_length)
TextView mBookLength;

@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.book_info);
ButterKnife.bind(this);
initUI();
int id = getIntent().getIntExtra("id", 0);
if (id != 0){
FreeBookModel.getFreeBookInfo(id);
if(id != 0) {
FreeBookModel.getFreeBookInfo(id, this);
}
}

private void initUI () {
setSupportActionBar(mToolbar);
if(getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
}
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View v) {
finish();
}
});
}

public static void setId (Activity activity, int id) {
Intent intent = new Intent(activity, BookInfoActivity.class);
intent.putExtra("id", id);
activity.startActivity(intent);
}

@Override
public void SendData (Object o) {
FreeBookInfo freeBookInfo = (FreeBookInfo) o;
FreeBookInfo.DataBean data = freeBookInfo.getData();
String bookImageUrl = data.getBookImageUrl();
String bookAuthor = data.getBookAuthor();
String bookIntroduction = data.getBookIntroduction();
String bookProgress = data.getBookProgress();
String bookName = data.getBookName();
String bookUpdateTime = data.getBookUpdateTime();
String bookLength = data.getBookLength();
String bookDownload = data.getBookDownload();
String bookType = data.getBookType();
Glide.with(this).load(bookImageUrl)
.error(getResources().getDrawable(R.mipmap.nocover))// 加载失败时显示图片
.placeholder(getResources().getDrawable(R.mipmap.nocover))// 加载过长中显示的图片
.into(mBookImage);
mBookName.setText(bookName);
mBookAuth.setText(bookAuthor);
mBookType.setText(bookType);
mBookProgress.setText(bookProgress);
mBookDesc.setText(bookIntroduction);
mDownLoad.setText(bookUpdateTime);
mBookLength.setText(bookLength);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.hante.thirdopen.activity;

/**
* Created By HanTe
*/

public interface PageInterface {

void SendData (Object o);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.hante.thirdopen.mvp.model;

import com.example.hante.thirdopen.activity.PageInterface;
import com.example.hante.thirdopen.contract.Contract;
import com.example.hante.thirdopen.mvp.BasePresenter;
import com.example.hante.thirdopen.mvp.entry.freebook.FreeBook;
Expand All @@ -18,14 +19,15 @@
* 获取数据
*/

public class FreeBookModel extends Network{
public class FreeBookModel extends Network {
private FreeBook mFreeBook;
private static final NetInterface netInterface =
getRetrofit(Contract.FreeBook_Base_Url).create(NetInterface.class);
private Disposable mDisposable;
private static FreeBookInfo mFreeBookInfo;

public void loadBookData (boolean fresh, final BasePresenter basePresenter){
if (fresh){
public void loadBookData (boolean fresh, final BasePresenter basePresenter) {
if(fresh) {
netInterface.getHomeInfo()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
Expand All @@ -34,10 +36,12 @@ public void loadBookData (boolean fresh, final BasePresenter basePresenter){
public void onSubscribe (Disposable d) {
mDisposable = d;
}

@Override
public void onNext (FreeBook freeBook) {
mFreeBook = freeBook;
}

@Override
public void onError (Throwable e) {
basePresenter.onFail(e.toString());
Expand All @@ -52,7 +56,8 @@ public void onComplete () {
}
}

public static void getFreeBookInfo (int id) {
public static void getFreeBookInfo (int id, PageInterface pageInterface) {
final PageInterface mPageInterface = pageInterface;
netInterface.getBookInfo(id).subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<FreeBookInfo>() {
Expand All @@ -64,6 +69,7 @@ public void onSubscribe (Disposable d) {
@Override
public void onNext (FreeBookInfo freeBookInfo) {
LogUtils.a(freeBookInfo.toString());
mFreeBookInfo = freeBookInfo;

}

Expand All @@ -74,9 +80,11 @@ public void onError (Throwable e) {

@Override
public void onComplete () {
mPageInterface.SendData(mFreeBookInfo);
}
});
}

/**
* 取消网络请求
*/
Expand Down
45 changes: 31 additions & 14 deletions app/src/main/res/layout/book_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintRight_toRightOf="parent"
tools:ignore="MissingConstraints,RtlHardcoded"
tools:layout_editor_absoluteY="0dp"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent"/>

<ImageView
Expand All @@ -29,7 +28,8 @@
app:layout_constraintLeft_toLeftOf="parent"
tools:ignore="ContentDescription,MissingConstraints,RtlHardcoded"
android:layout_marginTop="10dp"
app:layout_constraintTop_toBottomOf="@+id/toolbar"/>
app:layout_constraintTop_toBottomOf="@+id/toolbar"
android:layout_marginStart="16dp"/>

<TextView
android:id="@+id/book_name"
Expand All @@ -40,14 +40,14 @@
android:layout_marginTop="2dp"
app:layout_constraintLeft_toRightOf="@+id/book_image"
android:layout_marginLeft="11dp"
tools:ignore="HardcodedText,RtlHardcoded"/>
tools:ignore="HardcodedText,RtlHardcoded"
android:layout_marginStart="11dp"/>

<TextView
android:id="@+id/book_auth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="@+id/book_name"
android:layout_marginTop="15dp"
app:layout_constraintTop_toBottomOf="@+id/book_name"
Expand All @@ -58,7 +58,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="@+id/book_auth"
app:layout_constraintBottom_toBottomOf="@+id/book_image"
android:layout_marginBottom="8dp"
Expand All @@ -68,7 +67,6 @@
android:id="@+id/book_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:text="TextView"
app:layout_constraintLeft_toLeftOf="@+id/book_image"
android:layout_marginTop="20dp"
Expand All @@ -79,23 +77,42 @@
android:id="@+id/download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:text="TextView"
app:layout_constraintLeft_toLeftOf="@+id/booktype"
app:layout_constraintTop_toTopOf="@+id/book_progress"
tools:ignore="HardcodedText,RtlHardcoded"/>

<TextView
android:id="@+id/book_desc"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:text="TextView"
app:layout_constraintLeft_toLeftOf="parent"
tools:ignore="HardcodedText,RtlHardcoded"
android:layout_marginStart="10dp"
android:layout_marginRight="12dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginTop="10dp"
android:ellipsize="end"
android:maxLines="10"
app:layout_constraintTop_toBottomOf="@+id/book_progress"
tools:ignore="HardcodedText,RtlHardcoded"/>
app:layout_constraintVertical_bias="0.072"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="@+id/book_progress"
app:layout_constraintHorizontal_bias="0.033"/>

<TextView
android:id="@+id/book_length"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="TextView"
app:layout_constraintTop_toBottomOf="@+id/book_auth"
tools:ignore="HardcodedText,RtlHardcoded"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="@+id/book_auth"
/>


</android.support.constraint.ConstraintLayout>

0 comments on commit 229293f

Please sign in to comment.