Skip to content

Commit

Permalink
kotlin编写闲读页面
Browse files Browse the repository at this point in the history
  • Loading branch information
wosojadfjgo committed Sep 1, 2019
1 parent 1c053c7 commit 4c4beeb
Show file tree
Hide file tree
Showing 31 changed files with 974 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ConfigConstants {
//module2模块路由路径
public static final String PATH_MODULE2_PROVIDER = "/module2/main/service";
public static final String PATH_GANK = "/module2/gank";
public static final String PATH_LEISURE_READ = "/module2/leisureRead";
public static final String PATH_WELFARE = "/module2/welfare";
public static final String PATH_ABOUT = "/module2/about";
public static final String PATH_ENCOURAGE = "/module2/encourage";
Expand Down
Binary file added base/src/main/res/drawable-xhdpi/ic_close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion base/src/main/res/layout/layout_spinner_dropdown_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
android:padding="@dimen/dp_10"
android:singleLine="true"
android:textColor="@color/text_color"
android:textSize="@dimen/sp_14">
android:textSize="@dimen/sp_16">

</TextView>
3 changes: 1 addition & 2 deletions main/src/main/java/com/heyongrui/main/HomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ protected void initView(Bundle savedInstanceState) {
addOnClickListeners(view -> {
int id = view.getId();
if (id == R.id.tv_home) {
// ARouter.getInstance().build(ConfigConstants.PATH_USER).withBoolean(ConfigConstants.IS_NEED_INTERCEPT, true).navigation();
ARouter.getInstance().build(ConfigConstants.PATH_H5).withString("h5Url", "https://ys.juan8014.cn/yin/").navigation();
ARouter.getInstance().build(ConfigConstants.PATH_USER).withBoolean(ConfigConstants.IS_NEED_INTERCEPT, true).navigation();
}
}, R.id.tv_home);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ private void initRecyclerView(RecyclerView recyclerView) {
case 4://探索
break;
case 5://音乐
ARouter.getInstance().build(ConfigConstants.PATH_H5).withString("h5Url", "https://ys.juan8014.cn/yin/").navigation();
break;
case 6://开眼
ARouter.getInstance().build(ConfigConstants.PATH_KAIYAN_LIST).withInt("type", 1).navigation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ protected void initView(Bundle savedInstanceState) {
int id = view.getId();
if (id == R.id.iv_back) {
backLogic();
} else if (id == R.id.iv_close) {
mActivity.finish();
}
}, R.id.iv_back);
}, R.id.iv_back, R.id.iv_close);
}

@Override
Expand Down
17 changes: 15 additions & 2 deletions module/src/main/res/layout/fragment_x5webview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,24 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/iv_close"
android:layout_width="@dimen/dp_30"
android:layout_height="@dimen/dp_30"
android:layout_marginStart="@dimen/dp_10"
android:layout_marginLeft="@dimen/dp_10"
android:padding="3dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_close"
android:tint="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/iv_back"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_50"
android:layout_marginEnd="@dimen/dp_50"
android:ellipsize="end"
android:focusable="true"
android:focusableInTouchMode="true"
Expand All @@ -45,6 +57,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.5"
tools:text="@string/app_name" />

</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down
3 changes: 3 additions & 0 deletions module2/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
<activity
android:name=".gank.view.GankActivity"
android:theme="@style/BaseAppTheme" />
<activity
android:name=".gank.view.LeisureReadActivity"
android:theme="@style/BaseAppTheme" />
</application>
</manifest>
3 changes: 3 additions & 0 deletions module2/src/main/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<activity
android:name=".gank.view.GankActivity"
android:theme="@style/BaseAppTheme" />
<activity
android:name=".gank.view.LeisureReadActivity"
android:theme="@style/BaseAppTheme" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ private void initBalls() {
case 6://拓展资源
ARouter.getInstance().build(ConfigConstants.PATH_GANK).withString("category", "拓展资源").navigation();
break;
case 8://瞎推荐
ARouter.getInstance().build(ConfigConstants.PATH_LEISURE_READ).navigation();
break;
case 9://关于
ARouter.getInstance().build(ConfigConstants.PATH_ABOUT).navigation();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.heyongrui.base.utils.UiUtil;
import com.heyongrui.module2.R;
import com.heyongrui.module2.data.dto.GankDto;
import com.heyongrui.module2.data.dto.LeisureReadDto;

import java.util.List;

Expand All @@ -40,6 +41,7 @@ public Module2SectionAdapter(int sectionHeadResId, List<Module2SectionEntity> da
super(sectionHeadResId, data);
addItemType(Module2SectionEntity.WELFARE, R.layout.recycle_item_welfare);
addItemType(Module2SectionEntity.GANK, R.layout.recycle_item_android);
addItemType(Module2SectionEntity.LEISURE_READ, R.layout.recycle_item_leisure_read);
}

@Override
Expand All @@ -55,9 +57,9 @@ protected void convert(BaseViewHolder helper, Module2SectionEntity item) {
case Module2SectionEntity.WELFARE: {
ConstraintLayout content = helper.getView(R.id.content);
ImageView coverIv = helper.getView(R.id.iv);
GankDto.GankBean gankBean = item.getGankBean();
if (gankBean == null) return;
String url = gankBean.getUrl();
GankDto gankDto = item.getGankDto();
if (gankDto == null) return;
String url = gankDto.getUrl();
RequestOptions options = new RequestOptions()
.placeholder(R.drawable.placeholder)
.error(R.drawable.placeholder_fail)
Expand All @@ -82,18 +84,49 @@ public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? sup
TextView tvDate = helper.getView(R.id.tv_date);

String title = "", type = "", date = "";
GankDto.GankBean gankBean = item.getGankBean();
if (null != gankBean) {
title = gankBean.getDesc();
type = gankBean.getType();
String publishedAt = gankBean.getPublishedAt();
GankDto gankDto = item.getGankDto();
if (null != gankDto) {
title = gankDto.getDesc();
type = gankDto.getType();
String publishedAt = gankDto.getPublishedAt();
date = TimeUtil.getDateString(publishedAt, TimeUtil.ISO8601, TimeUtil.DAY_ONE);
}
tvTitle.setText(TextUtils.isEmpty(title) ? "" : title);
tvType.setText(TextUtils.isEmpty(type) ? "" : type);
tvDate.setText(TextUtils.isEmpty(date) ? "" : date);
}
break;
case Module2SectionEntity.LEISURE_READ: {
UiUtil.setOnclickFeedBack(mContext, ContextCompat.getColor(mContext, R.color.background), ContextCompat.getColor(mContext, R.color.gray), helper.itemView);
ConstraintLayout content = helper.getView(R.id.content);
ImageView ivCover = helper.getView(R.id.iv_cover);
TextView tvTitle = helper.getView(R.id.tv_title);

String cover = "", title = "";
LeisureReadDto leisureReadDto = item.getLeisureReadDto();
if (null != leisureReadDto) {
cover = leisureReadDto.getCover();
title = leisureReadDto.getTitle();
}

RequestOptions options = new RequestOptions()
.placeholder(R.drawable.placeholder)
.error(R.drawable.placeholder_fail)
.diskCacheStrategy(DiskCacheStrategy.NONE);
GlideApp.with(mContext).asBitmap().load(cover).apply(options).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
float ratio = (float) resource.getWidth() / resource.getHeight();
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(content);
constraintSet.setDimensionRatio(ivCover.getId(), ratio + "");
constraintSet.applyTo(content);
ivCover.setImageBitmap(resource);
}
});
tvTitle.setText(TextUtils.isEmpty(title) ? "" : title);
}
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.chad.library.adapter.base.entity.SectionMultiEntity;
import com.heyongrui.module2.data.dto.GankDto;
import com.heyongrui.module2.data.dto.LeisureReadDto;

import java.util.List;

Expand All @@ -11,15 +12,17 @@
* 2019/6/25 18:13
*/
public class Module2SectionEntity extends SectionMultiEntity implements MultiItemEntity {

public static final int WELFARE = 100;
public static final int GANK = 101;
public static final int LEISURE_READ = 102;

private int itemType;
private int spanSize;

private Object object;
private GankDto.GankBean gankBean;
private GankDto gankDto;
private LeisureReadDto leisureReadDto;

public Module2SectionEntity(boolean isHeader, String header, boolean isShow) {
super(isHeader, header);
Expand All @@ -40,8 +43,10 @@ public Module2SectionEntity(int itemType, int spanSize, Object object) {
// if (o instanceof BannerDto) {
// this.bannerDtoList = (List<BannerDto>) object;
// }
} else if (object instanceof GankDto.GankBean) {
this.gankBean = (GankDto.GankBean) object;
} else if (object instanceof GankDto) {
this.gankDto = (GankDto) object;
} else if (object instanceof LeisureReadDto) {
this.leisureReadDto = (LeisureReadDto) object;
}
}
}
Expand Down Expand Up @@ -71,11 +76,19 @@ public void setObject(Object object) {
this.object = object;
}

public GankDto.GankBean getGankBean() {
return gankBean;
public GankDto getGankDto() {
return gankDto;
}

public void setGankDto(GankDto gankDto) {
this.gankDto = gankDto;
}

public LeisureReadDto getLeisureReadDto() {
return leisureReadDto;
}

public void setGankBean(GankDto.GankBean gankBean) {
this.gankBean = gankBean;
public void setLeisureReadDto(LeisureReadDto leisureReadDto) {
this.leisureReadDto = leisureReadDto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.heyongrui.base.dagger.AppComponent;
import com.heyongrui.base.dagger.PerActivity;
import com.heyongrui.module2.gank.presenter.GankPresenter;
import com.heyongrui.module2.gank.presenter.LeisureReadPresenter;

import dagger.Component;

Expand All @@ -24,4 +25,6 @@ public interface Module2Component {
Fragment getFragment();

void inject(GankPresenter gankPresenter);

void inject(LeisureReadPresenter leisureReadPresenter);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.heyongrui.module2.data.api;

import com.heyongrui.module2.data.dto.GankDto;
import com.heyongrui.module2.data.dto.GankResponse;
import com.heyongrui.module2.data.dto.LeisureReadCategoryDto;
import com.heyongrui.module2.data.dto.LeisureReadDto;
import com.heyongrui.module2.data.dto.LeisureReadSubCategoryDto;

import java.util.List;

import io.reactivex.Observable;
import retrofit2.http.GET;
Expand All @@ -13,10 +19,34 @@
public interface GankApi {

/**
* 获取分类数据
*
* @param category 数据类型: 福利 | Android | iOS | 休息视频 | 拓展资源 | 前端 | all
* @param per_page 请求个数: 数字,大于0
* @param page 第几页:数字,大于0
*/
@GET("data/{category}/{per_page}/{page}")
Observable<GankDto> getGankCategory(@Path("category") String category, @Path("per_page") int per_page, @Path("page") int page);
Observable<GankResponse<List<GankDto>>> getGankCategory(@Path("category") String category, @Path("per_page") int per_page, @Path("page") int page);

/**
* 获取闲读主分类
*/
@GET("/api/xiandu/categories")
Observable<GankResponse<List<LeisureReadCategoryDto>>> getLeisureReadCategory();

/**
* 获取闲读子分类
*/
@GET("/api/xiandu/category/{subCategory}")
Observable<GankResponse<List<LeisureReadSubCategoryDto>>> getLeisureReadSubCategory(@Path("subCategory") String subCategory);

/**
* 获取闲读数据
*
* @param id 后面可接受参数为子分类返回的id
* @param perPage 每页的个数
* @param page 第几页,从1开始
*/
@GET("/api/xiandu/data/id/{id}/count/{perPage}/page/{page}")
Observable<GankResponse<List<LeisureReadDto>>> getLeisureRead(@Path("id") String id, @Path("perPage") int perPage, @Path("page") int page);
}
Loading

0 comments on commit 4c4beeb

Please sign in to comment.