Skip to content

Commit

Permalink
首页视频列表支持本地保存,MTRVA升级,提供原生Adapter封装
Browse files Browse the repository at this point in the history
  • Loading branch information
crazysunj committed Jul 11, 2018
1 parent db82a91 commit a2c08f8
Show file tree
Hide file tree
Showing 20 changed files with 491 additions and 277 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* MTRVA轻松处理RecyclerViewAdapter的数据,实现多列表效果更佳
* 大量自定义控件,如Camera、Matrix、贝塞尔曲线、高斯模糊、Behavior、事件拦截、沉浸式、QQ侧滑菜单等等运用
* 大量动画,如lottie、补间动画、3D动画、属性动画(ObjectAnimator、ValueAnimator、View.animate和PropertyValuesHolder)和转场动画(自定义Transition)运用
* 视频列表
* 视频列表滑动支持小窗口播放,本地保存
* 支持图片预览、编辑(如裁剪、压缩)和保存本地
* 支持下载机制,通知栏回显(兼容8.0),下载完成可打开
* 支持扫码,扫码支持访问链接和下载,界面仿微信,支持本地图片扫码
Expand All @@ -60,7 +60,6 @@
* 加上引导页
* Navigation支持多fragment(AS3.2启动)
* 添加微信精选,稀土掘金模块
* 视频列表支持小窗口播放,本地保存
* 添加音乐模块
* 添加分享
* 添加ConstraintLayout进阶用法
Expand Down
4 changes: 1 addition & 3 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ ext {
butterknife : "8.4.0",
glide : "4.7.1",
glideTransformations : "3.3.0",
MTRVA : "2.1.0",
BRVAH : "2.9.28",
MTRVA : "2.2.0",
arrowVersion : "1.0.0",
javaxAnnotationVersion: "1.0",
javaxInjectVersion : "1",
Expand Down Expand Up @@ -74,7 +73,6 @@ ext {
butterknife : "com.jakewharton:butterknife:${dependVersion.butterknife}",
butterknifeCompiler : "com.jakewharton:butterknife-compiler:${dependVersion.butterknife}",
MTRVA : "com.crazysunj:multitypeadapter:${dependVersion.MTRVA}",
BRVAH : "com.github.CymChad:BaseRecyclerViewAdapterHelper:${dependVersion.BRVAH}",
annotation : "org.glassfish:javax.annotation:10.0-b28",
multidex : "com.android.support:multidex:1.0.1",
pickerdialog : "com.crazysunj:android-pickerdialog:${dependVersion.pickerdialog}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import com.crazysunj.domain.repository.download.DownloadRepository;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

Expand All @@ -36,6 +34,9 @@
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import okio.BufferedSink;
import okio.Okio;
import okio.Source;
import retrofit2.Response;

/**
Expand Down Expand Up @@ -68,28 +69,24 @@ private File convertFile(File saveFileDir, Response<ResponseBody> response) {
if (responseBody == null) {
return null;
}
InputStream is = null;
byte[] buffer = new byte[1024];
int len;
FileOutputStream fos = null;
File saveFile = new File(saveFileDir, getFileName(response));
BufferedSink bufferedSink = null;
Source source = null;
try {
is = responseBody.byteStream();
fos = new FileOutputStream(saveFile);
while ((len = is.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
fos.flush();
File saveFile = new File(saveFileDir, getFileName(response));
bufferedSink = Okio.buffer(Okio.sink(saveFile));
source = Okio.source(responseBody.byteStream());
bufferedSink.writeAll(source);
bufferedSink.flush();
return saveFile;
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (is != null) {
is.close();
if (bufferedSink != null) {
bufferedSink.close();
}
if (fos != null) {
fos.close();
if (source != null) {
source.close();
}
} catch (IOException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class GaoxiaoItemEntity extends MultiTypeIdEntity {
private String thumbnail;
private long duration;
private String videoUrl;
private boolean isPlaying;

public static GaoxiaoItemEntity get(GaoxiaoEntity.DataEntity entity) {
final String videouri = entity.getVideouri();
Expand All @@ -67,14 +66,6 @@ public GaoxiaoItemEntity(String id, String avatar, String name, CharSequence tit
this.videoUrl = videoUrl;
}

public boolean isPlaying() {
return isPlaying;
}

public void setPlaying(boolean playing) {
isPlaying = playing;
}

public String getAvatar() {
return avatar;
}
Expand Down
1 change: 0 additions & 1 deletion presentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ dependencies {
implementation libs.multidex
implementation libs.butterknife
implementation libs.MTRVA //recyclerview数据处理
implementation libs.BRVAH
implementation libs.statusbarutil //状态栏
implementation libs.pickerdialog //选择对话框
implementation libs.circleimageview //圆形imageview
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/**
* Copyright 2017 Sun Jian
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.crazysunj.crazydaily.base;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.crazysunj.multitypeadapter.entity.MultiTypeEntity;
import com.crazysunj.multitypeadapter.helper.RecyclerViewAdapterHelper;

import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
* author: sunjian
* created on: 2017/8/3 下午5:18
* description:https://github.com/crazysunj/CrazyDaily
*/
public abstract class BaseHelperAdapter<T extends MultiTypeEntity, VH extends BaseViewHolder, H extends RecyclerViewAdapterHelper<T>> extends RecyclerView.Adapter<VH> {

protected Context mContext;
protected LayoutInflater mLayoutInflater;
protected H mHelper;

public BaseHelperAdapter(H helper) {
helper.bindAdapter(this);
mHelper = helper;
}

@Override
public int getItemViewType(int position) {
return mHelper.getItemViewType(position);
}

@Override
public void onBindViewHolder(@NonNull VH holder, int position) {
convert(holder, mHelper.getData().get(position));
}

protected abstract void convert(VH holder, T item);

@NonNull
@Override
public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return createBaseViewHolder(parent, mHelper.getLayoutId(viewType));
}

@Override
public int getItemCount() {
return mHelper.getData().size();
}

protected VH createBaseViewHolder(ViewGroup parent, int layoutResId) {
if (mContext == null) {
mContext = parent.getContext();
}
if (mLayoutInflater == null) {
mLayoutInflater = LayoutInflater.from(mContext);
}
return createBaseViewHolder(mLayoutInflater.inflate(layoutResId, parent, false));
}

@SuppressWarnings("unchecked")
protected VH createBaseViewHolder(View view) {
Class temp = getClass();
Class z = null;
while (z == null && null != temp) {
z = getInstancedGenericKClass(temp);
temp = temp.getSuperclass();
}
VH vh = createGenericKInstance(z, view);
return null != vh ? vh : (VH) new BaseViewHolder(view);
}

@SuppressWarnings("unchecked")
private VH createGenericKInstance(Class z, View view) {
try {
Constructor constructor;
String buffer = Modifier.toString(z.getModifiers());
String className = z.getName();
if (className.contains("$") && !buffer.contains("static")) {
constructor = z.getDeclaredConstructor(getClass(), View.class);
return (VH) constructor.newInstance(this, view);
} else {
constructor = z.getDeclaredConstructor(View.class);
return (VH) constructor.newInstance(view);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

private Class getInstancedGenericKClass(Class z) {
Type type = z.getGenericSuperclass();
if (type instanceof ParameterizedType) {
Type[] types = ((ParameterizedType) type).getActualTypeArguments();
for (Type temp : types) {
if (temp instanceof Class) {
Class tempClass = (Class) temp;
if (BaseViewHolder.class.isAssignableFrom(tempClass)) {
return tempClass;
}
}
}
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Copyright 2017 Sun Jian
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.crazysunj.crazydaily.base;

import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

/**
* author: sunjian
* created on: 2017/8/3 下午5:18
* description:https://github.com/crazysunj/CrazyDaily
*/
public class BaseViewHolder extends RecyclerView.ViewHolder {

private SparseArray<View> mViews;

public BaseViewHolder(View view) {
super(view);
if (mViews == null) {
mViews = new SparseArray<>();
}
}

@SuppressWarnings("unchecked")
public <T extends View> T getView(int viewId) {
View view = mViews.get(viewId);
if (view == null) {
view = itemView.findViewById(viewId);
mViews.put(viewId, view);
}
return (T) view;
}

@SuppressWarnings("unchecked")
public <T extends View> T getView(int viewId, Class<T> clazz) {
View view = mViews.get(viewId);
if (view == null) {
view = itemView.findViewById(viewId);
mViews.put(viewId, view);
}
return (T) view;
}

public void setText(int viewId, CharSequence text) {
getTextView(viewId).setText(text);
}

public void setImageResource(int viewId, int resId) {
getImageView(viewId).setImageResource(resId);
}

public void setVisible(int viewId, boolean visible) {
getView(viewId).setVisibility(visible ? View.VISIBLE : View.GONE);
}

public TextView getTextView(int viewId) {
return getView(viewId, TextView.class);
}

public ImageView getImageView(int viewId) {
return getView(viewId, ImageView.class);
}

}
Loading

0 comments on commit a2c08f8

Please sign in to comment.