Skip to content

Commit

Permalink
Gank页面完善
Browse files Browse the repository at this point in the history
  • Loading branch information
wosojadfjgo committed Sep 1, 2019
1 parent 420aabb commit 1c053c7
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 84 deletions.
18 changes: 18 additions & 0 deletions base/src/main/java/com/heyongrui/base/utils/TimeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

public class TimeUtil {
public final static String ISO8601 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
public final static String SEC = "yyyy-MM-dd HH:mm:ss";
public final static String MIN = "yyyy-MM-dd HH:mm";
public final static String MIN_TWO = "MM-dd HH:mm";
Expand Down Expand Up @@ -46,6 +47,23 @@ public static String getDateString(Date date, String targetDateType) {
return datestring;
}

/**
* 将原始格式的时间转化为新时间的格式
*/
public static String getDateString(String originalTime, String originalFormat, String targetFormat) {
if (TextUtils.isEmpty(originalTime) || TextUtils.isEmpty(originalFormat) || TextUtils.isEmpty(targetFormat))
return "";
String targetTime = "";
try {
SimpleDateFormat sdfSource = new SimpleDateFormat(originalFormat);//原始的日期格式
SimpleDateFormat sdfTarget = new SimpleDateFormat(targetFormat);//新日期格式
targetTime = sdfTarget.format(sdfSource.parse(originalTime));
} catch (Exception e) {
e.printStackTrace();
}
return targetTime;
}

/**
* 将日期字符串转成指定格式的日期
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public void checkUpdate(@NonNull String updateCheckUrl, @NonNull String authorit
boolean is_force_update = jsonObject.getBoolean("ignore_able");
showUpdateDialog(mActivity, "V " + update_ver_name + "\n" + update_content, update_url,
is_force_update, authority, appName);
} else {
ToastUtils.showShort(R.string.latest_tip);
}
} catch (JSONException e) {
e.printStackTrace();
Expand Down
1 change: 1 addition & 0 deletions base/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<string name="update_url">https://raw.githubusercontent.com/HeYongRui/YouJu/master/app/version_update.json</string>
<string name="update_title">更新提示</string>
<string name="update_error">更新失败</string>
<string name="latest_tip">已是最新版本</string>
<string name="update">更新</string>
<string name="downloading">下载中...</string>
<string name="doing_download">正在下载</string>
Expand Down
11 changes: 10 additions & 1 deletion module2/src/main/java/com/heyongrui/module2/Module2Fragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,16 @@ private void initBalls() {
ARouter.getInstance().build(ConfigConstants.PATH_WELFARE).navigation();
break;
case 2://Android
ARouter.getInstance().build(ConfigConstants.PATH_GANK).withInt("type", 1).navigation();
ARouter.getInstance().build(ConfigConstants.PATH_GANK).withString("category", "Android").navigation();
break;
case 3://IOS
ARouter.getInstance().build(ConfigConstants.PATH_GANK).withString("category", "iOS").navigation();
break;
case 5://前端
ARouter.getInstance().build(ConfigConstants.PATH_GANK).withString("category", "前端").navigation();
break;
case 6://拓展资源
ARouter.getInstance().build(ConfigConstants.PATH_GANK).withString("category", "拓展资源").navigation();
break;
case 9://关于
ARouter.getInstance().build(ConfigConstants.PATH_ABOUT).navigation();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.heyongrui.module2.adapter;

import android.graphics.Bitmap;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.core.content.ContextCompat;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
Expand All @@ -15,8 +18,10 @@
import com.chad.library.adapter.base.BaseSectionMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.heyongrui.base.glide.GlideApp;
import com.heyongrui.base.utils.TimeUtil;
import com.heyongrui.base.utils.UiUtil;
import com.heyongrui.module2.R;
import com.heyongrui.module2.data.dto.WelfareDto;
import com.heyongrui.module2.data.dto.GankDto;

import java.util.List;

Expand All @@ -34,6 +39,7 @@ public Module2SectionAdapter(List<Module2SectionEntity> data) {
public Module2SectionAdapter(int sectionHeadResId, List<Module2SectionEntity> data) {
super(sectionHeadResId, data);
addItemType(Module2SectionEntity.WELFARE, R.layout.recycle_item_welfare);
addItemType(Module2SectionEntity.GANK, R.layout.recycle_item_android);
}

@Override
Expand All @@ -49,9 +55,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);
WelfareDto.WelfareBean welfareBean = item.getWelfareBean();
if (welfareBean == null) return;
String url = welfareBean.getUrl();
GankDto.GankBean gankBean = item.getGankBean();
if (gankBean == null) return;
String url = gankBean.getUrl();
RequestOptions options = new RequestOptions()
.placeholder(R.drawable.placeholder)
.error(R.drawable.placeholder_fail)
Expand All @@ -69,6 +75,25 @@ public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? sup
});
}
break;
case Module2SectionEntity.GANK: {
UiUtil.setOnclickFeedBack(mContext, ContextCompat.getColor(mContext, R.color.background), ContextCompat.getColor(mContext, R.color.gray), helper.itemView);
TextView tvTitle = helper.getView(R.id.tv_title);
TextView tvType = helper.getView(R.id.tv_type);
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();
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.chad.library.adapter.base.entity.SectionMultiEntity;
import com.heyongrui.module2.data.dto.WelfareDto;
import com.heyongrui.module2.data.dto.GankDto;

import java.util.List;

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

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

private int itemType;
private int spanSize;

private Object object;
private WelfareDto.WelfareBean welfareBean;
private GankDto.GankBean gankBean;

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

public WelfareDto.WelfareBean getWelfareBean() {
return welfareBean;
public GankDto.GankBean getGankBean() {
return gankBean;
}

public void setWelfareBean(WelfareDto.WelfareBean welfareBean) {
this.welfareBean = welfareBean;
public void setGankBean(GankDto.GankBean gankBean) {
this.gankBean = gankBean;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.heyongrui.module2.data.api;

import com.heyongrui.module2.data.dto.WelfareDto;
import com.heyongrui.module2.data.dto.GankDto;

import io.reactivex.Observable;
import retrofit2.http.GET;
Expand All @@ -12,6 +12,11 @@

public interface GankApi {

/**
* @param category 数据类型: 福利 | Android | iOS | 休息视频 | 拓展资源 | 前端 | all
* @param per_page 请求个数: 数字,大于0
* @param page 第几页:数字,大于0
*/
@GET("data/{category}/{per_page}/{page}")
Observable<WelfareDto> getGankCategory(@Path("category") String category, @Path("per_page") int per_page, @Path("page") int page);
Observable<GankDto> getGankCategory(@Path("category") String category, @Path("per_page") int per_page, @Path("page") int page);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* Created by Mr.He on 2019/3/10.
*/

public class WelfareDto {
public class GankDto {

private boolean error;
private List<WelfareBean> results;
private List<GankBean> results;

public boolean isError() {
return error;
Expand All @@ -19,15 +19,15 @@ public void setError(boolean error) {
this.error = error;
}

public List<WelfareBean> getResults() {
public List<GankBean> getResults() {
return results;
}

public void setResults(List<WelfareBean> results) {
public void setResults(List<GankBean> results) {
this.results = results;
}

public static class WelfareBean {
public static class GankBean {

private String _id;
private String createdAt;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.heyongrui.module2.data.service;

import com.heyongrui.module2.data.api.GankApi;
import com.heyongrui.module2.data.dto.WelfareDto;
import com.heyongrui.module2.data.dto.GankDto;
import com.heyongrui.network.configure.RxHelper;
import com.heyongrui.network.service.ApiService;

Expand All @@ -19,15 +19,14 @@ public GankService() {

}

public Observable<WelfareDto> getWelfare(int perPage, int page) {
/**
* @param category 数据类型: 福利 | Android | iOS | 休息视频 | 拓展资源 | 前端 | all
* @param perPage 请求个数: 数字,大于0
* @param page 第几页:数字,大于0
*/
public Observable<GankDto> getGankCategory(String category, int perPage, int page) {
return ApiService.createApi(GankApi.class, BASE_URL_GANK)
.getGankCategory("福利", perPage, page)
.compose(RxHelper.rxSchedulerHelper());
}

public Observable<WelfareDto> getAndroid(int perPage, int page) {
return ApiService.createApi(GankApi.class, BASE_URL_GANK)
.getGankCategory("Android", perPage, page)
.getGankCategory(category, perPage, page)
.compose(RxHelper.rxSchedulerHelper());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ import com.chad.library.adapter.base.BaseQuickAdapter
import com.heyongrui.base.base.BasePresenter
import com.heyongrui.base.base.BaseView
import com.heyongrui.module2.adapter.Module2SectionAdapter
import com.heyongrui.module2.data.dto.WelfareDto
import com.heyongrui.module2.data.dto.GankDto
import com.scwang.smartrefresh.header.StoreHouseHeader
import com.scwang.smartrefresh.layout.SmartRefreshLayout
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener

interface GankContract {
interface View : BaseView<Any> {
fun getAndroidSuccess(welfareDto: WelfareDto)
fun getGankCategorySuccess(gankDto: GankDto)

fun getAndroidFail(errorCode: Int, errorMsg: String)
fun getGankCategoryFail(errorCode: Int, errorMsg: String)
}

abstract class Presenter : BasePresenter<View>() {
abstract fun initSwipeRefresh(smartRefreshLayout: SmartRefreshLayout, storeHouseHeader: StoreHouseHeader, onRefreshLoadMoreListener: OnRefreshLoadMoreListener)

abstract fun initRecyclerView(recyclerView: RecyclerView, listener: BaseQuickAdapter.OnItemClickListener): Module2SectionAdapter

abstract fun getAndroid(perPage: Int, page: Int)
abstract fun getGankCategory(category: String, perPage: Int, page: Int)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import com.heyongrui.base.base.BasePresenter;
import com.heyongrui.base.base.BaseView;
import com.heyongrui.base.widget.imagewatcher.ImageWatcherHelper;
import com.heyongrui.module2.data.dto.WelfareDto;
import com.heyongrui.module2.data.dto.GankDto;

public interface WelfareContract {
interface View extends BaseView {
void getWelfareSuccess(WelfareDto welfareDto);
void getWelfareSuccess(GankDto gankDto);

void getWelfareFail(int errorCode, String errorMsg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.heyongrui.module2.adapter.Module2SectionAdapter
import com.heyongrui.module2.adapter.Module2SectionEntity
import com.heyongrui.module2.dagger.DaggerModule2Component
import com.heyongrui.module2.dagger.Module2Module
import com.heyongrui.module2.data.dto.WelfareDto
import com.heyongrui.module2.data.dto.GankDto
import com.heyongrui.module2.data.service.GankService
import com.heyongrui.module2.gank.contract.GankContract
import com.heyongrui.network.configure.ResponseDisposable
Expand Down Expand Up @@ -46,27 +46,27 @@ class GankPresenter : GankContract.Presenter() {
val moduleSectionAdapter = Module2SectionAdapter(data)
recyclerView.layoutManager = LinearLayoutManager(mContext)
moduleSectionAdapter.bindToRecyclerView(recyclerView)
val dp10 = ConvertUtils.dp2px(10f)
recyclerView.addItemDecoration(RecycleViewItemDecoration(mContext, dp10))
val dp1 = ConvertUtils.dp2px(1f)
recyclerView.addItemDecoration(RecycleViewItemDecoration(mContext, dp1))
moduleSectionAdapter.setSpanSizeLookup({ gridLayoutManager, position -> data[position].getSpanSize() })
if (null != listener) {
moduleSectionAdapter.setOnItemClickListener(listener)
}
return moduleSectionAdapter
}

override fun getAndroid(perPage: Int, page: Int) {
mRxManager.add(mGankService.getAndroid(perPage, page).subscribeWith(
object : ResponseDisposable<WelfareDto>(mContext, true) {
override fun onSuccess(welfareDto: WelfareDto) {
override fun getGankCategory(category: String, perPage: Int, page: Int) {
mRxManager.add(mGankService.getGankCategory(category, perPage, page).subscribeWith(
object : ResponseDisposable<GankDto>(mContext, true) {
override fun onSuccess(gankDto: GankDto) {
if (mView != null) {
mView.getAndroidSuccess(welfareDto)
mView.getGankCategorySuccess(gankDto)
}
}

override fun onFailure(errorCode: Int, errorMsg: String) {
if (mView != null) {
mView.getAndroidFail(errorCode, errorMsg)
mView.getGankCategoryFail(errorCode, errorMsg)
}
}
}))
Expand Down
Loading

0 comments on commit 1c053c7

Please sign in to comment.