From a2c08f89312edf7ef2790d48bbf3cbceb9db0237 Mon Sep 17 00:00:00 2001 From: crazysunj Date: Wed, 11 Jul 2018 17:24:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E8=A7=86=E9=A2=91=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=94=AF=E6=8C=81=E6=9C=AC=E5=9C=B0=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=EF=BC=8CMTRVA=E5=8D=87=E7=BA=A7=EF=BC=8C=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E5=8E=9F=E7=94=9FAdapter=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +- config.gradle | 4 +- .../download/DownloadDataRepository.java | 31 ++- .../entity/gaoxiao/GaoxiaoItemEntity.java | 9 - presentation/build.gradle | 1 - .../crazydaily/base/BaseAdapter.java | 55 ----- .../crazydaily/base/BaseHelperAdapter.java | 128 ++++++++++ .../crazydaily/base/BaseViewHolder.java | 80 ++++++ .../ui/adapter/ContactsAdapter.java | 67 ++--- .../crazydaily/ui/adapter/HomeAdapter.java | 230 +++++++++++------- .../adapter/helper/ContactAdapterHelper.java | 3 +- .../ui/adapter/helper/HomeAdapterHelper.java | 5 +- .../crazydaily/ui/home/HomeActivity.java | 47 ++-- .../ui/shimmer/ShimmerViewHolder.java | 2 +- .../video/NeihanVideoPlayerController.java | 32 ++- .../layout/common/layout/header_common.xml | 2 +- .../contact/layout/activity_contact.xml | 2 +- .../res/layout/neihan/layout/item_neihan.xml | 7 +- .../layout/neihan_video_player_controller.xml | 58 ++--- presentation/src/main/res/values/dimens.xml | 2 + 20 files changed, 491 insertions(+), 277 deletions(-) delete mode 100644 presentation/src/main/java/com/crazysunj/crazydaily/base/BaseAdapter.java create mode 100644 presentation/src/main/java/com/crazysunj/crazydaily/base/BaseHelperAdapter.java create mode 100755 presentation/src/main/java/com/crazysunj/crazydaily/base/BaseViewHolder.java diff --git a/README.md b/README.md index 0c4fe5a..ab4f946 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ * MTRVA轻松处理RecyclerViewAdapter的数据,实现多列表效果更佳 * 大量自定义控件,如Camera、Matrix、贝塞尔曲线、高斯模糊、Behavior、事件拦截、沉浸式、QQ侧滑菜单等等运用 * 大量动画,如lottie、补间动画、3D动画、属性动画(ObjectAnimator、ValueAnimator、View.animate和PropertyValuesHolder)和转场动画(自定义Transition)运用 -* 视频列表 +* 视频列表滑动支持小窗口播放,本地保存 * 支持图片预览、编辑(如裁剪、压缩)和保存本地 * 支持下载机制,通知栏回显(兼容8.0),下载完成可打开 * 支持扫码,扫码支持访问链接和下载,界面仿微信,支持本地图片扫码 @@ -60,7 +60,6 @@ * 加上引导页 * Navigation支持多fragment(AS3.2启动) * 添加微信精选,稀土掘金模块 -* 视频列表支持小窗口播放,本地保存 * 添加音乐模块 * 添加分享 * 添加ConstraintLayout进阶用法 diff --git a/config.gradle b/config.gradle index 2dea3e6..1fd6bbc 100755 --- a/config.gradle +++ b/config.gradle @@ -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", @@ -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}", diff --git a/data/src/main/java/com/crazysunj/data/repository/download/DownloadDataRepository.java b/data/src/main/java/com/crazysunj/data/repository/download/DownloadDataRepository.java index ebd26b7..18f2b66 100644 --- a/data/src/main/java/com/crazysunj/data/repository/download/DownloadDataRepository.java +++ b/data/src/main/java/com/crazysunj/data/repository/download/DownloadDataRepository.java @@ -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; @@ -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; /** @@ -68,28 +69,24 @@ private File convertFile(File saveFileDir, Response 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(); diff --git a/domain/src/main/java/com/crazysunj/domain/entity/gaoxiao/GaoxiaoItemEntity.java b/domain/src/main/java/com/crazysunj/domain/entity/gaoxiao/GaoxiaoItemEntity.java index 24c4850..5b0e87b 100644 --- a/domain/src/main/java/com/crazysunj/domain/entity/gaoxiao/GaoxiaoItemEntity.java +++ b/domain/src/main/java/com/crazysunj/domain/entity/gaoxiao/GaoxiaoItemEntity.java @@ -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(); @@ -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; } diff --git a/presentation/build.gradle b/presentation/build.gradle index 52a51ed..68b8fa0 100644 --- a/presentation/build.gradle +++ b/presentation/build.gradle @@ -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 diff --git a/presentation/src/main/java/com/crazysunj/crazydaily/base/BaseAdapter.java b/presentation/src/main/java/com/crazysunj/crazydaily/base/BaseAdapter.java deleted file mode 100644 index 7fce470..0000000 --- a/presentation/src/main/java/com/crazysunj/crazydaily/base/BaseAdapter.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright 2017 Sun Jian - *

- * 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 - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * 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.view.ViewGroup; - -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.BaseViewHolder; -import com.crazysunj.multitypeadapter.entity.MultiTypeEntity; -import com.crazysunj.multitypeadapter.helper.RecyclerViewAdapterHelper; - -/** - * author: sunjian - * created on: 2017/8/3 下午5:18 - * description:https://github.com/crazysunj/CrazyDaily - */ - -public abstract class BaseAdapter> extends BaseQuickAdapter { - - protected H mHelper; - - public BaseAdapter(H helper) { - super(helper.getData()); - mHelper = helper; - mHelper.bindAdapter(this); - } - - @Override - protected K onCreateDefViewHolder(ViewGroup parent, int viewType) { - return createBaseViewHolder(parent, mHelper.getLayoutId(viewType)); - } - - @Override - protected int getDefItemViewType(int position) { - return mHelper.getItemViewType(position); - } - - public H getHelper() { - return mHelper; - } - -} diff --git a/presentation/src/main/java/com/crazysunj/crazydaily/base/BaseHelperAdapter.java b/presentation/src/main/java/com/crazysunj/crazydaily/base/BaseHelperAdapter.java new file mode 100644 index 0000000..755500c --- /dev/null +++ b/presentation/src/main/java/com/crazysunj/crazydaily/base/BaseHelperAdapter.java @@ -0,0 +1,128 @@ +/** + * Copyright 2017 Sun Jian + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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> extends RecyclerView.Adapter { + + 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; + } +} diff --git a/presentation/src/main/java/com/crazysunj/crazydaily/base/BaseViewHolder.java b/presentation/src/main/java/com/crazysunj/crazydaily/base/BaseViewHolder.java new file mode 100755 index 0000000..dcbd1df --- /dev/null +++ b/presentation/src/main/java/com/crazysunj/crazydaily/base/BaseViewHolder.java @@ -0,0 +1,80 @@ +/** + * Copyright 2017 Sun Jian + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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 mViews; + + public BaseViewHolder(View view) { + super(view); + if (mViews == null) { + mViews = new SparseArray<>(); + } + } + + @SuppressWarnings("unchecked") + public 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 getView(int viewId, Class 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); + } + +} diff --git a/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/ContactsAdapter.java b/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/ContactsAdapter.java index bf36ac5..0dfad67 100644 --- a/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/ContactsAdapter.java +++ b/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/ContactsAdapter.java @@ -25,7 +25,7 @@ import android.view.View; import com.crazysunj.crazydaily.R; -import com.crazysunj.crazydaily.base.BaseAdapter; +import com.crazysunj.crazydaily.base.BaseHelperAdapter; import com.crazysunj.crazydaily.entity.ContactLoadingEntity; import com.crazysunj.crazydaily.extension.Extension; import com.crazysunj.crazydaily.extension.ItemTouchHelperExtension; @@ -48,7 +48,7 @@ * created on: 2018/4/16 下午6:39 * description:https://github.com/crazysunj/CrazyDaily */ -public class ContactsAdapter extends BaseAdapter { +public class ContactsAdapter extends BaseHelperAdapter { private ItemTouchHelperExtension mItemTouchHelper; @@ -82,34 +82,34 @@ public void showLoading() { } @Override - public void onViewAttachedToWindow(ContactViewHolder helper) { - helper.startAnim(); + public void onViewAttachedToWindow(@NonNull ContactViewHolder holder) { + holder.startAnim(); } @Override - public void onViewDetachedFromWindow(@NonNull ContactViewHolder helper) { - helper.stopAnim(); + public void onViewDetachedFromWindow(@NonNull ContactViewHolder holder) { + holder.stopAnim(); } @Override - protected void convert(ContactViewHolder helper, MultiTypeIndexEntity item) { + protected void convert(ContactViewHolder holder, MultiTypeIndexEntity item) { switch (item.getItemType()) { case Contact.TYPE: - renderContact(helper, (Contact) item); + renderContact(holder, (Contact) item); break; case ContactHeader.TYPE: - renderContactHeader(helper, (ContactHeader) item); + renderContactHeader(holder, (ContactHeader) item); break; default: break; } } - private void renderContactHeader(ContactViewHolder helper, ContactHeader item) { - helper.setText(R.id.index, item.getStringId()); - View icon = helper.getView(R.id.header_icon); + private void renderContactHeader(ContactViewHolder holder, ContactHeader item) { + holder.setText(R.id.index, item.getStringId()); + View icon = holder.getView(R.id.header_icon); final boolean flod = item.isFlod(); - helper.setVisible(R.id.bottom_line, !flod); + holder.setVisible(R.id.bottom_line, !flod); if (flod) { icon.animate().cancel(); icon.setRotation(-90); @@ -117,11 +117,12 @@ private void renderContactHeader(ContactViewHolder helper, ContactHeader item) { icon.animate().cancel(); icon.setRotation(0); } - helper.itemView.setOnClickListener(v -> switchStatus(item, icon)); + holder.itemView.setOnClickListener(v -> switchStatus(item, icon)); } private void switchStatus(ContactHeader item, View icon) { - final int index = mData.indexOf(item); + final List data = mHelper.getData(); + final int index = data.indexOf(item); final String flag = item.getIndex(); if (item.isFlod()) { icon.animate().rotation(90).setDuration(500).start(); @@ -130,7 +131,7 @@ private void switchStatus(ContactHeader item, View icon) { icon.animate().rotation(-90).setDuration(500).start(); List childs; int count = 0; - for (MultiTypeIndexEntity entity : mData) { + for (MultiTypeIndexEntity entity : data) { if (entity.getIndex().equals(flag)) { count++; } @@ -147,20 +148,20 @@ private void switchStatus(ContactHeader item, View icon) { mHelper.setData(index, item); } - private void renderContact(ContactViewHolder helper, Contact contact) { - CircleImageView icon = helper.getView(R.id.ic_head); + private void renderContact(ContactViewHolder holder, Contact contact) { + CircleImageView icon = holder.getView(R.id.ic_head); ImageLoader.load(mContext, contact.getAvatar(), R.mipmap.ic_huaji, icon); - helper.setText(R.id.tx_name, contact.getName()); - helper.setText(R.id.tx_location, contact.getLocation()); - helper.getView(R.id.content).setOnClickListener(v -> enterContactDetail(v.getContext(), helper, contact)); - helper.getView(R.id.msg).setOnClickListener(v -> enterSms(v.getContext(), contact.getPhone())); - helper.getView(R.id.call).setOnClickListener(v -> enterPhone(v.getContext(), contact.getPhone())); - helper.getView(R.id.delete).setOnClickListener(v -> deleteContact(helper)); - helper.setVisible(R.id.bottom_line, !contact.isLast()); + holder.setText(R.id.tx_name, contact.getName()); + holder.setText(R.id.tx_location, contact.getLocation()); + holder.getView(R.id.content).setOnClickListener(v -> enterContactDetail(v.getContext(), holder, contact)); + holder.getView(R.id.msg).setOnClickListener(v -> enterSms(v.getContext(), contact.getPhone())); + holder.getView(R.id.call).setOnClickListener(v -> enterPhone(v.getContext(), contact.getPhone())); + holder.getView(R.id.delete).setOnClickListener(v -> deleteContact(holder)); + holder.setVisible(R.id.bottom_line, !contact.isLast()); } @SuppressWarnings("unchecked") - private void enterContactDetail(Context context, ContactViewHolder helper, Contact contact) { + private void enterContactDetail(Context context, ContactViewHolder holder, Contact contact) { if (mItemTouchHelper.isOpened()) { mItemTouchHelper.closeOpened(); return; @@ -176,18 +177,18 @@ private void enterContactDetail(Context context, ContactViewHolder helper, Conta ContactDetailActivity.start(activity, bitmap, contact, - Pair.create(helper.getView(R.id.tx_name), activity.getString(R.string.transition_name)), - Pair.create(helper.getView(R.id.ic_head), activity.getString(R.string.transition_head)), - Pair.create(helper.getView(R.id.ic_location), activity.getString(R.string.transition_location_icon)), - Pair.create(helper.getView(R.id.tx_location), activity.getString(R.string.transition_location))); + Pair.create(holder.getView(R.id.tx_name), activity.getString(R.string.transition_name)), + Pair.create(holder.getView(R.id.ic_head), activity.getString(R.string.transition_head)), + Pair.create(holder.getView(R.id.ic_location), activity.getString(R.string.transition_location_icon)), + Pair.create(holder.getView(R.id.tx_location), activity.getString(R.string.transition_location))); } - private void deleteContact(ContactViewHolder helper) { - int position = helper.getLayoutPosition() - getHeaderLayoutCount(); + private void deleteContact(ContactViewHolder holder) { + final int position = holder.getLayoutPosition(); Contact removeData = (Contact) mHelper.removeData(position); if (removeData.isLast()) { int prePosition = position - 1; - MultiTypeIndexEntity entity = mData.get(prePosition); + MultiTypeIndexEntity entity = mHelper.getItem(prePosition); if (entity instanceof ContactHeader) { mHelper.removeData(prePosition); } else { diff --git a/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/HomeAdapter.java b/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/HomeAdapter.java index 09ea314..075b52f 100644 --- a/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/HomeAdapter.java +++ b/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/HomeAdapter.java @@ -19,12 +19,14 @@ import android.support.annotation.NonNull; import android.support.v7.widget.AppCompatImageView; import android.text.format.DateFormat; +import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; import android.widget.TextView; -import com.chad.library.adapter.base.BaseViewHolder; import com.crazysunj.crazydaily.R; -import com.crazysunj.crazydaily.base.BaseAdapter; +import com.crazysunj.crazydaily.base.BaseHelperAdapter; +import com.crazysunj.crazydaily.base.BaseViewHolder; import com.crazysunj.crazydaily.di.module.EntityModule; import com.crazysunj.crazydaily.entity.ExpandCollapseFooterEntity; import com.crazysunj.crazydaily.moudle.image.ImageLoader; @@ -61,7 +63,7 @@ * description: https://github.com/crazysunj/CrazyDaily */ -public class HomeAdapter extends BaseAdapter { +public class HomeAdapter extends BaseHelperAdapter { //固定不变的或者直接在Adapter中修改数据源的(如footer)可以用这种方法 @Named(EntityModule.NAME_ZHIHU) @@ -88,6 +90,7 @@ public class HomeAdapter extends BaseAdapter { + if (mDownloadCallback != null) { + mDownloadCallback.onDownload(url); + } + }); controller.setTitle(""); controller.setLenght(item.getDuration()); videoPlayer.setUp(item.getVideoUrl(), null); @@ -147,73 +178,98 @@ private void renderGaoxiao(BaseViewHolder helper, GaoxiaoItemEntity item) { ImageLoader.load(mContext, item.getThumbnail(), R.drawable.img_default, controller.imageView()); } + private int getPosition(BaseViewHolder holder) { + return holder.getAdapterPosition(); + } + @Override - public void onViewAttachedToWindow(BaseViewHolder holder) { - super.onViewAttachedToWindow(holder); - final int position = holder.getAdapterPosition() - getHeaderLayoutCount(); + public void onViewRecycled(@NonNull BaseViewHolder holder) { + super.onViewRecycled(holder); + final int position = getPosition(holder); if (position < 0) { return; } - final int itemViewType = holder.getItemViewType(); - if (itemViewType == GaoxiaoItemEntity.TYPE_GAOXIAO && mTinyWindowPosition == position) { - mVideoPlayer.exitTinyWindow(); + final MultiTypeIdEntity item = mHelper.getItem(position); + if (item.getItemType() == GaoxiaoItemEntity.TYPE_GAOXIAO) { ViewGroup wrapView = (ViewGroup) holder.itemView; - wrapView.addView(mVideoPlayer); - mVideoPlayer = null; - mTinyWindowPosition = -1; + View lastView = wrapView.getChildAt(wrapView.getChildCount() - 1); + if (!(lastView instanceof NiceVideoPlayer)) { + NiceVideoPlayer videoPlayer = new NiceVideoPlayer(mContext); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mContext.getResources().getDimensionPixelSize(R.dimen.space_240)); + ((ViewGroup) holder.itemView).addView(videoPlayer, params); + } } } @Override - public void onViewDetachedFromWindow(@NonNull BaseViewHolder holder) { - super.onViewDetachedFromWindow(holder); - final int position = holder.getAdapterPosition() - getHeaderLayoutCount(); + public void onViewAttachedToWindow(@NonNull BaseViewHolder holder) { + super.onViewAttachedToWindow(holder); + final int position = getPosition(holder); if (position < 0) { return; } - MultiTypeIdEntity item = mData.get(position); + final MultiTypeIdEntity item = mHelper.getItem(position); if (item.getItemType() == GaoxiaoItemEntity.TYPE_GAOXIAO) { GaoxiaoItemEntity gaoxiaoItem = (GaoxiaoItemEntity) item; - NiceVideoPlayer niceVideoPlayer = holder.getView(R.id.item_neihan_video); - if (niceVideoPlayer.isPlaying()) { -// ThreadManager.single().execute(niceVideoPlayer::release); + if (gaoxiaoItem.getStringId().equals(mRemoveVideoItemId)) { ViewGroup wrapView = (ViewGroup) holder.itemView; - wrapView.removeView(niceVideoPlayer); - mVideoPlayer = niceVideoPlayer; - mTinyWindowPosition = position; - mVideoPlayer.enterTinyWindow(); + View lastView = wrapView.getChildAt(wrapView.getChildCount() - 1); + if (lastView instanceof NiceVideoPlayer) { + wrapView.removeView(lastView); + } + mVideoPlayer.exitTinyWindow(); + wrapView.addView(mVideoPlayer); + mVideoPlayer = null; + mRemoveVideoItemId = null; } } } - private int mTinyWindowPosition = -1; + @Override + public void onViewDetachedFromWindow(@NonNull BaseViewHolder holder) { + super.onViewDetachedFromWindow(holder); + final int position = getPosition(holder); + if (position < 0) { + return; + } + final MultiTypeIdEntity item = mHelper.getItem(position); + if (item.getItemType() == GaoxiaoItemEntity.TYPE_GAOXIAO) { + ViewGroup wrapView = (ViewGroup) holder.itemView; + NiceVideoPlayer videoPlayer = (NiceVideoPlayer) wrapView.getChildAt(wrapView.getChildCount() - 1); + if (videoPlayer.isPlaying()) { + wrapView.removeView(videoPlayer); + mVideoPlayer = videoPlayer; + // 视频封装库关于小窗口位置是写死的,可通过反射重新设置 + // 再不济可以自己封装视频UI,现在基本都是基于ijkplayer + mVideoPlayer.enterTinyWindow(); + GaoxiaoItemEntity gaoxiaoItem = (GaoxiaoItemEntity) item; + mRemoveVideoItemId = gaoxiaoItem.getStringId(); + } + } + } public void notifyGaoxiaoList(List data) { + mRemoveVideoItemId = null; final int level = HomeAdapterHelper.LEVEL_GAOXIAO; -// if (mVideoPlayer == null) { -// mVideoPlayer = new NiceVideoPlayer(mContext); -// LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mContext.getResources().getDimensionPixelSize(R.dimen.space_240)); -// mVideoPlayer.setLayoutParams(params); -// } mHelper.notifyMoudleDataAndHeaderAndFooterChanged(data, mGaoxiaoHeaderEntity, mGaoxiaoFooterEntity, level); } // *********************** 内涵段子 *********************** - private void renderNeihan(BaseViewHolder helper, NeihanItemEntity item) { - CircleImageView avatar = helper.getView(R.id.item_neihan_avatar); - ImageLoader.load(mContext, item.getAvatar(), R.mipmap.ic_huaji, avatar); - helper.setText(R.id.item_neihan_name, item.getName()); - helper.setText(R.id.item_neihan_title, item.getTitle()); - NiceVideoPlayer videoPlayer = helper.getView(R.id.item_neihan_video); - NeihanVideoPlayerController controller = new NeihanVideoPlayerController(mContext); - controller.setTitle(""); - controller.setLenght(item.getDuration()); - controller.setClarity(item.getClarityList(), 0); - videoPlayer.setController(controller); - ImageLoader.load(mContext, item.getThumbnail(), R.drawable.img_default, controller.imageView()); - - } +// private void renderNeihan(BaseViewHolder helper, NeihanItemEntity item) { +// CircleImageView avatar = helper.getView(R.id.item_neihan_avatar); +// ImageLoader.load(mContext, item.getAvatar(), R.mipmap.ic_huaji, avatar); +// helper.setText(R.id.item_neihan_name, item.getName()); +// helper.setText(R.id.item_neihan_title, item.getTitle()); +// NiceVideoPlayer videoPlayer = helper.getView(R.id.item_neihan_video); +// NeihanVideoPlayerController controller = new NeihanVideoPlayerController(mContext); +// controller.setTitle(""); +// controller.setLenght(item.getDuration()); +// controller.setClarity(item.getClarityList(), 0); +// videoPlayer.setController(controller); +// ImageLoader.load(mContext, item.getThumbnail(), R.drawable.img_default, controller.imageView()); +// +// } public void notifyNeihanList(List data) { @@ -223,15 +279,15 @@ public void notifyNeihanList(List data) { // *********************** Weather *********************** - private void renderWeather(BaseViewHolder helper, WeatherRemoteEntity.WeatherEntity item) { + private void renderWeather(BaseViewHolder holder, WeatherRemoteEntity.WeatherEntity item) { WeatherRemoteEntity.WeatherEntity.NowEntity nowEntity = item.getNow(); - helper.setText(R.id.item_weather_temperature, String.format("%s ℃", nowEntity.getTemperature())); + holder.setText(R.id.item_weather_temperature, String.format("%s ℃", nowEntity.getTemperature())); final String cityName = item.getCity_name(); - helper.setText(R.id.item_weather_location, cityName); - helper.setText(R.id.item_weather_text, nowEntity.getText()); - helper.setText(R.id.item_weather_time, DateFormat.format("HH:mm", new Date())); - helper.setImageResource(R.id.item_weather_icon, WeatherUtil.getWeatherIcon(nowEntity.getCode())); - helper.itemView.setOnClickListener(v -> { + holder.setText(R.id.item_weather_location, cityName); + holder.setText(R.id.item_weather_text, nowEntity.getText()); + holder.setText(R.id.item_weather_time, DateFormat.format("HH:mm", new Date())); + holder.setImageResource(R.id.item_weather_icon, WeatherUtil.getWeatherIcon(nowEntity.getCode())); + holder.itemView.setOnClickListener(v -> { if (mOnHeaderClickListener != null) { mOnHeaderClickListener.onHeaderClick(mHelper.getLevel(item.getItemType()), cityName); } @@ -245,17 +301,17 @@ public void notifyWeatherList(List data) { // *********************** Gankio *********************** - private void renderGankio(BaseViewHolder helper, GankioEntity.ResultsEntity item) { - helper.setText(R.id.item_gank_io_title, item.getDesc()); - helper.setText(R.id.item_gank_io_author, String.format("作者:%s", FileUtil.getText(item.getWho(), "神秘大佬"))); - helper.setText(R.id.item_gank_io_date, String.format("发布时间:%s", DateUtil.getLocalTime(item.getPublishedAt()))); - helper.itemView.setOnClickListener(v -> BrowserActivity.start(mContext, item.getUrl())); + private void renderGankio(BaseViewHolder holder, GankioEntity.ResultsEntity item) { + holder.setText(R.id.item_gank_io_title, item.getDesc()); + holder.setText(R.id.item_gank_io_author, String.format("作者:%s", FileUtil.getText(item.getWho(), "神秘大佬"))); + holder.setText(R.id.item_gank_io_date, String.format("发布时间:%s", DateUtil.getLocalTime(item.getPublishedAt()))); + holder.itemView.setOnClickListener(v -> BrowserActivity.start(mContext, item.getUrl())); } - private void renderGankioHeader(BaseViewHolder helper, CommonHeaderEntity item) { + private void renderGankioHeader(BaseViewHolder holder, CommonHeaderEntity item) { final int level = mHelper.getLevel(item.getItemType()); - helper.setText(R.id.header_title, item.getTitle()); - TextView optionsView = helper.getView(R.id.header_options); + holder.setText(R.id.header_title, item.getTitle()); + TextView optionsView = holder.getView(R.id.header_options); final String options = item.getOptions(); optionsView.setText(options); optionsView.setTextColor(HomeAdapterHelper.getColor(level)); @@ -277,10 +333,10 @@ public void notifyGankioList(List data) { // ***********************知乎 *********************** - private void renderHeader(BaseViewHolder helper, CommonHeaderEntity item) { + private void renderHeader(BaseViewHolder holder, CommonHeaderEntity item) { final int level = mHelper.getLevel(item.getItemType()); - helper.setText(R.id.header_title, item.getTitle()); - TextView optionsView = helper.getView(R.id.header_options); + holder.setText(R.id.header_title, item.getTitle()); + TextView optionsView = holder.getView(R.id.header_options); final String options = item.getOptions(); optionsView.setText(options); optionsView.setTextColor(HomeAdapterHelper.getColor(level)); @@ -291,11 +347,11 @@ private void renderHeader(BaseViewHolder helper, CommonHeaderEntity item) { }); } - private void renderZhihuNews(BaseViewHolder helper, ZhihuNewsEntity.StoriesEntity item) { - final AppCompatImageView icon = helper.getView(R.id.item_zhihu_news_icon); + private void renderZhihuNews(BaseViewHolder holder, ZhihuNewsEntity.StoriesEntity item) { + final AppCompatImageView icon = holder.getView(R.id.item_zhihu_news_icon); ImageLoader.load(mContext, getUrl(item.getImages()), icon); - helper.setText(R.id.item_zhihu_news_title, item.getTitle()); - helper.itemView.setOnClickListener(v -> ZhihuNewsDetailActivity.start((Activity) v.getContext(), item.getId(), icon)); + holder.setText(R.id.item_zhihu_news_title, item.getTitle()); + holder.itemView.setOnClickListener(v -> ZhihuNewsDetailActivity.start((Activity) v.getContext(), item.getId(), icon)); } public void notifyZhihuNewsList(List data) { @@ -313,19 +369,19 @@ private String getUrl(List images) { } //*********************** 公共Footer *********************** - private void renderExpandCollapseFooter(BaseViewHolder helper, ExpandCollapseFooterEntity item) { + private void renderExpandCollapseFooter(BaseViewHolder holder, ExpandCollapseFooterEntity item) { String stringId = item.getStringId(); - helper.setText(R.id.footer_title, stringId); - helper.setImageResource(R.id.footer_icon, item.getIconResId()); - helper.itemView.setOnClickListener(v -> { + holder.setText(R.id.footer_title, stringId); + holder.setImageResource(R.id.footer_icon, item.getIconResId()); + holder.itemView.setOnClickListener(v -> { item.switchStatus(); mHelper.foldType(mHelper.getLevel(item.getItemType()), item.isFlod()); - mHelper.setData(mData.indexOf(item), item); + mHelper.notifyDataChanged(item); }); } - private void renderFooter(BaseViewHolder helper, CommonFooterEntity item) { - helper.setText(R.id.footer_title, item.getTitle()); + private void renderFooter(BaseViewHolder holder, CommonFooterEntity item) { + holder.setText(R.id.footer_title, item.getTitle()); } diff --git a/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/helper/ContactAdapterHelper.java b/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/helper/ContactAdapterHelper.java index 33decb6..ed4095d 100644 --- a/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/helper/ContactAdapterHelper.java +++ b/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/helper/ContactAdapterHelper.java @@ -16,7 +16,6 @@ package com.crazysunj.crazydaily.ui.adapter.helper; import com.crazysunj.crazydaily.R; -import com.crazysunj.crazydaily.base.BaseAdapter; import com.crazysunj.domain.entity.contact.Contact; import com.crazysunj.domain.entity.contact.ContactHeader; import com.crazysunj.domain.entity.contact.MultiTypeIndexEntity; @@ -29,7 +28,7 @@ * created on: 2018/4/17 下午3:54 * description:https://github.com/crazysunj/CrazyDaily */ -public class ContactAdapterHelper extends AsynAdapterHelper { +public class ContactAdapterHelper extends AsynAdapterHelper { public static final int CONTACT_LEVEL = 0; diff --git a/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/helper/HomeAdapterHelper.java b/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/helper/HomeAdapterHelper.java index 3da97ea..be2df76 100644 --- a/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/helper/HomeAdapterHelper.java +++ b/presentation/src/main/java/com/crazysunj/crazydaily/ui/adapter/helper/HomeAdapterHelper.java @@ -19,13 +19,12 @@ import android.support.v7.util.DiffUtil; import com.crazysunj.crazydaily.R; -import com.crazysunj.crazydaily.base.BaseAdapter; import com.crazysunj.crazydaily.ui.adapter.helper.callback.StringDiffCallBack; +import com.crazysunj.domain.entity.base.MultiTypeIdEntity; import com.crazysunj.domain.entity.gankio.GankioEntity; import com.crazysunj.domain.entity.gaoxiao.GaoxiaoItemEntity; import com.crazysunj.domain.entity.weather.WeatherRemoteEntity; import com.crazysunj.domain.entity.zhihu.ZhihuNewsEntity; -import com.crazysunj.domain.entity.base.MultiTypeIdEntity; import com.crazysunj.multitypeadapter.helper.AsynAdapterHelper; import java.util.List; @@ -38,7 +37,7 @@ * description: https://github.com/crazysunj/CrazyDaily */ -public class HomeAdapterHelper extends AsynAdapterHelper { +public class HomeAdapterHelper extends AsynAdapterHelper { public static final int MIN_ZHIHU = 2; public static final int MIN_GANK_IO = 3; diff --git a/presentation/src/main/java/com/crazysunj/crazydaily/ui/home/HomeActivity.java b/presentation/src/main/java/com/crazysunj/crazydaily/ui/home/HomeActivity.java index d26997d..e98d05e 100644 --- a/presentation/src/main/java/com/crazysunj/crazydaily/ui/home/HomeActivity.java +++ b/presentation/src/main/java/com/crazysunj/crazydaily/ui/home/HomeActivity.java @@ -53,13 +53,15 @@ import com.crazysunj.crazydaily.moudle.image.ImageLoader; import com.crazysunj.crazydaily.moudle.permission.PermissionCamera; import com.crazysunj.crazydaily.moudle.permission.PermissionHelper; +import com.crazysunj.crazydaily.moudle.permission.PermissionStorage; import com.crazysunj.crazydaily.presenter.HomePresenter; import com.crazysunj.crazydaily.presenter.contract.HomeContract; -import com.crazysunj.crazydaily.ui.me.MeActivity; +import com.crazysunj.crazydaily.service.DownloadService; import com.crazysunj.crazydaily.ui.adapter.HomeAdapter; import com.crazysunj.crazydaily.ui.adapter.helper.HomeAdapterHelper; import com.crazysunj.crazydaily.ui.browser.BrowserActivity; import com.crazysunj.crazydaily.ui.contact.ContactActivity; +import com.crazysunj.crazydaily.ui.me.MeActivity; import com.crazysunj.crazydaily.ui.photo.PhotoActivity; import com.crazysunj.crazydaily.ui.scan.ScannerActivity; import com.crazysunj.crazydaily.util.SnackbarUtil; @@ -80,7 +82,6 @@ import com.google.zxing.integration.android.IntentResult; import com.sunjian.android_pickview_lib.BaseOptionsPickerDialog; import com.sunjian.android_pickview_lib.PhoneOptionsPickerDialog; -import com.xiao.nicevideoplayer.NiceVideoPlayer; import com.xiao.nicevideoplayer.NiceVideoPlayerManager; import java.util.ArrayList; @@ -102,7 +103,7 @@ * description: https://github.com/crazysunj/CrazyDaily */ @RuntimePermissions -public class HomeActivity extends BaseActivity implements HomeContract.View, PermissionCamera { +public class HomeActivity extends BaseActivity implements HomeContract.View, PermissionCamera, PermissionStorage { @BindView(R.id.refresh) SwipeRefreshLayout mRefresh; @@ -200,13 +201,13 @@ protected void initView() { protected void initListener() { mRefresh.setOnRefreshListener(this::onRefresh); mAdapter.setOnHeaderClickListener(this::handleHeaderOptions); -// mHomeList.addOnChildAttachStateChangeListener(new HomeRecyclerViewStateChangeListener()); mAppbar.addOnOffsetChangedListener(this::handleAppbarOffsetChangedListener); mToolbar.setNavigationOnClickListener(v -> HomeActivityPermissionsDispatcher.openQRCodeWithPermissionCheck(this)); mBottomNavigation.setOnNavigationItemSelectedListener(this::handleNavigationItemClick); mCubeAnchor.setOnClickListener(v -> clickCubeAnchor()); mCubeFirst.setOnClickListener(v -> clickCubeFirst()); mCubeSecond.setOnClickListener(v -> clickCubeSecond()); + mAdapter.setDownloadCallback(url -> HomeActivityPermissionsDispatcher.downloadWithPermissionCheck(this, url)); } @Override @@ -319,6 +320,7 @@ public void onBackPressed() { private void onRefresh() { mPresenter.endBanner(); + NiceVideoPlayerManager.instance().releaseNiceVideoPlayer(); initData(); } @@ -487,6 +489,7 @@ private void handleHeaderOptions(int level, String options) { SnackbarUtil.show(this, "已经最新了,别点了!"); break; case HomeAdapterHelper.LEVEL_GAOXIAO: + NiceVideoPlayerManager.instance().releaseNiceVideoPlayer(); mPresenter.getGaoxiaoList(++gaoxiaoIndex); break; default: @@ -540,26 +543,26 @@ public void showNeverAskForCamera() { PermissionHelper.cameraNeverAskAgain(this); } - private class HomeRecyclerViewStateChangeListener implements RecyclerView.OnChildAttachStateChangeListener { + @NeedsPermission({Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}) + void download(String url) { + DownloadService.start(this, url); + } - @Override - public void onChildViewAttachedToWindow(View view) { + @OnShowRationale({Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}) + @Override + public void showRationaleForStorage(PermissionRequest request) { - } + } + + @OnPermissionDenied({Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}) + @Override + public void showDeniedForStorage() { + + } + + @OnNeverAskAgain({Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}) + @Override + public void showNeverAskForStorage() { - @Override - public void onChildViewDetachedFromWindow(View view) { - final int position = mHomeList.getChildAdapterPosition(view) - mAdapter.getHeaderLayoutCount(); - if (position < 0) { - return; - } - final int itemViewType = mAdapter.getHelper().getItemViewType(position); - if (itemViewType == GaoxiaoItemEntity.TYPE_GAOXIAO) { - NiceVideoPlayer niceVideoPlayer = view.findViewById(R.id.item_neihan_video); - if (niceVideoPlayer.isPlaying()) { - ThreadManager.single().execute(niceVideoPlayer::release); - } - } - } } } diff --git a/presentation/src/main/java/com/crazysunj/crazydaily/ui/shimmer/ShimmerViewHolder.java b/presentation/src/main/java/com/crazysunj/crazydaily/ui/shimmer/ShimmerViewHolder.java index 3f30864..1725051 100755 --- a/presentation/src/main/java/com/crazysunj/crazydaily/ui/shimmer/ShimmerViewHolder.java +++ b/presentation/src/main/java/com/crazysunj/crazydaily/ui/shimmer/ShimmerViewHolder.java @@ -2,7 +2,7 @@ import android.view.View; -import com.chad.library.adapter.base.BaseViewHolder; +import com.crazysunj.crazydaily.base.BaseViewHolder; import com.facebook.shimmer.ShimmerFrameLayout; public class ShimmerViewHolder extends BaseViewHolder { diff --git a/presentation/src/main/java/com/crazysunj/crazydaily/view/video/NeihanVideoPlayerController.java b/presentation/src/main/java/com/crazysunj/crazydaily/view/video/NeihanVideoPlayerController.java index 68a414b..edfbe13 100755 --- a/presentation/src/main/java/com/crazysunj/crazydaily/view/video/NeihanVideoPlayerController.java +++ b/presentation/src/main/java/com/crazysunj/crazydaily/view/video/NeihanVideoPlayerController.java @@ -39,6 +39,7 @@ import com.xiao.nicevideoplayer.NiceVideoPlayer; import com.xiao.nicevideoplayer.NiceVideoPlayerController; +import java.lang.reflect.Field; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -95,7 +96,7 @@ public class NeihanVideoPlayerController private LinearLayout mCompleted; private TextView mReplay; - private TextView mShare; + private TextView mSave; private boolean topBottomVisible; private CountDownTimer mDismissTopBottomCountDownTimer; @@ -153,7 +154,7 @@ private void init() { mCompleted = (LinearLayout) findViewById(R.id.completed); mReplay = (TextView) findViewById(R.id.replay); - mShare = (TextView) findViewById(R.id.share); + mSave = (TextView) findViewById(R.id.save); mCenterStart.setOnClickListener(this); mBack.setOnClickListener(this); @@ -162,7 +163,7 @@ private void init() { mClarity.setOnClickListener(this); mRetry.setOnClickListener(this); mReplay.setOnClickListener(this); - mShare.setOnClickListener(this); + mSave.setOnClickListener(this); mSeek.setOnSeekBarChangeListener(this); this.setOnClickListener(this); } @@ -370,6 +371,16 @@ protected void reset() { mCompleted.setVisibility(View.GONE); } + private DownloadCallback mDownloadCallback; + + public void setDownloadCallback(DownloadCallback callback) { + mDownloadCallback = callback; + } + + public interface DownloadCallback { + void onDownload(String url); + } + /** * 尽量不要在onClick中直接处理控件的隐藏、显示及各种UI逻辑。 * UI相关的逻辑都尽量到{@link #onPlayStateChanged}和{@link #onPlayModeChanged}中处理. @@ -405,8 +416,19 @@ public void onClick(View v) { mNiceVideoPlayer.restart(); } else if (v == mReplay) { mRetry.performClick(); - } else if (v == mShare) { - Toast.makeText(mContext, "不要方,以后会做分享", Toast.LENGTH_SHORT).show(); + } else if (v == mSave) { + try { + Class videoPlayerClass = NiceVideoPlayer.class; + Field urlField = videoPlayerClass.getDeclaredField("mUrl"); + urlField.setAccessible(true); + final String url = (String) urlField.get(mNiceVideoPlayer); + if (mDownloadCallback != null) { + mDownloadCallback.onDownload(url); + } + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show(); + } } else if (v == this) { if (mNiceVideoPlayer.isPlaying() || mNiceVideoPlayer.isPaused() diff --git a/presentation/src/main/res/layout/common/layout/header_common.xml b/presentation/src/main/res/layout/common/layout/header_common.xml index ebcbbb1..9397a11 100644 --- a/presentation/src/main/res/layout/common/layout/header_common.xml +++ b/presentation/src/main/res/layout/common/layout/header_common.xml @@ -13,7 +13,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="@dimen/space_40" - android:padding="@dimen/dp_10"> + android:padding="@dimen/space_10"> + app:sidebar_text_size="@dimen/text_14" /> diff --git a/presentation/src/main/res/layout/neihan/layout/item_neihan.xml b/presentation/src/main/res/layout/neihan/layout/item_neihan.xml index b73cd88..406fa00 100644 --- a/presentation/src/main/res/layout/neihan/layout/item_neihan.xml +++ b/presentation/src/main/res/layout/neihan/layout/item_neihan.xml @@ -44,12 +44,7 @@ android:paddingEnd="@dimen/space_15" android:paddingStart="@dimen/space_15" android:paddingTop="@dimen/space_6" - android:textSize="@dimen/sp_16" + android:textSize="@dimen/text_16" tools:text="我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天我的天" /> - - \ No newline at end of file diff --git a/presentation/src/main/res/layout/neihan/layout/neihan_video_player_controller.xml b/presentation/src/main/res/layout/neihan/layout/neihan_video_player_controller.xml index e664072..6dfd20e 100644 --- a/presentation/src/main/res/layout/neihan/layout/neihan_video_player_controller.xml +++ b/presentation/src/main/res/layout/neihan/layout/neihan_video_player_controller.xml @@ -9,7 +9,7 @@ android:layout_height="match_parent" android:background="@drawable/img_default" android:scaleType="fitXY" - android:visibility="visible"/> + android:visibility="visible" /> + android:layout_height="16dp" /> + android:textSize="13sp" /> + android:textSize="28sp" /> + android:progressDrawable="@drawable/pb_change" /> + android:src="@drawable/ic_palyer_brightness" /> + android:progressDrawable="@drawable/pb_change" /> @@ -105,7 +105,7 @@ + android:src="@drawable/ic_palyer_volume" /> + android:progressDrawable="@drawable/pb_change" /> @@ -137,19 +137,19 @@ android:padding="8dp" android:text="重新播放" android:textColor="@android:color/white" - android:textSize="13sp"/> + android:textSize="13sp" /> + android:textSize="13sp" /> + android:textSize="13sp" /> + android:textSize="13sp" /> + android:visibility="visible" /> + android:textSize="14sp" /> + android:src="@drawable/battery_100" /> + android:textSize="10sp" /> @@ -248,7 +248,7 @@ android:id="@+id/restart_or_pause" android:layout_width="24dp" android:layout_height="24dp" - android:src="@drawable/ic_player_start"/> + android:src="@drawable/ic_player_start" /> + android:textSize="12sp" /> + android:textSize="14sp" /> + android:textSize="12sp" /> + android:thumb="@drawable/seek_thumb" /> + android:visibility="gone" /> + android:src="@drawable/ic_player_enlarge" /> + android:textSize="12sp" /> + android:visibility="visible" /> \ No newline at end of file diff --git a/presentation/src/main/res/values/dimens.xml b/presentation/src/main/res/values/dimens.xml index 811aedf..ec51151 100644 --- a/presentation/src/main/res/values/dimens.xml +++ b/presentation/src/main/res/values/dimens.xml @@ -37,4 +37,6 @@ 5dp 46dp 360dp + 14sp + 16sp \ No newline at end of file