From 3e26f19c7f4172a00f81054883ccf1820a008b40 Mon Sep 17 00:00:00 2001 From: maning Date: Fri, 29 Dec 2017 10:58:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=B5=8F=E8=A7=88=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=B7=BB=E5=8A=A0=E6=94=B6=E8=97=8F=E5=92=8C=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E6=94=B6=E8=97=8F=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gankmm/ui/fragment/WelFareFragment.java | 13 +++- .../ui/imagebrowser/MNImageBrowser.java | 6 +- .../imagebrowser/MNImageBrowserActivity.java | 70 ++++++++++++------- .../presenter/impl/WelFarePresenterImpl.java | 8 +-- .../com/maning/gankmm/utils/IntentUtils.java | 13 ++-- 5 files changed, 69 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/com/maning/gankmm/ui/fragment/WelFareFragment.java b/app/src/main/java/com/maning/gankmm/ui/fragment/WelFareFragment.java index fe158bd..5191aeb 100644 --- a/app/src/main/java/com/maning/gankmm/ui/fragment/WelFareFragment.java +++ b/app/src/main/java/com/maning/gankmm/ui/fragment/WelFareFragment.java @@ -76,7 +76,7 @@ public void run() { } private void initRecycleView(List welFareList) { - + ((MainActivity) getActivity()).setPicList(welFareList); if (recyclePicAdapter == null) { @@ -86,7 +86,7 @@ private void initRecycleView(List welFareList) { recyclePicAdapter.setOnItemClickLitener(new RecyclePicAdapter.OnItemClickLitener() { @Override public void onItemClick(View view, int position) { - welFarePresenter.itemClick(view,position); + welFarePresenter.itemClick(view, position); } }); //获取头条随机 @@ -154,5 +154,12 @@ public void onDestroyView() { ButterKnife.unbind(this); } - + @Override + public void onResume() { + super.onResume(); + //刷新页面 + if (recyclePicAdapter != null) { + recyclePicAdapter.notifyDataSetChanged(); + } + } } diff --git a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowser.java b/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowser.java index c446df7..62bbc2d 100644 --- a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowser.java +++ b/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowser.java @@ -8,7 +8,9 @@ import android.view.View; import com.maning.gankmm.R; +import com.maning.gankmm.bean.GankEntity; +import java.io.Serializable; import java.util.ArrayList; /** @@ -18,15 +20,17 @@ public class MNImageBrowser { /** * 打开浏览页面 + * * @param context 上下文 * @param view 点击的当前View * @param position 默认打开第几个 * @param imageList 数据源ArrayList */ - public static void showImageBrowser(Context context, View view, int position, ArrayList imageList) { + public static void showImageBrowser(Context context, View view, int position, ArrayList imageList, ArrayList gankEntityList) { Intent intent = new Intent(context, MNImageBrowserActivity.class); intent.putExtra(MNImageBrowserActivity.IntentKey_ImageList, imageList); intent.putExtra(MNImageBrowserActivity.IntentKey_CurrentPosition, position); + intent.putExtra(MNImageBrowserActivity.IntentKey_GankEntityList, gankEntityList); //android V4包的类,用于两个activity转场时的缩放效果实现 ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeScaleUpAnimation(view, view.getWidth() / 2, view.getHeight() / 2, 0, 0); diff --git a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowserActivity.java b/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowserActivity.java index 0254f76..1414361 100644 --- a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowserActivity.java +++ b/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowserActivity.java @@ -17,10 +17,7 @@ import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; @@ -32,7 +29,9 @@ import com.github.chrisbanes.photoview.PhotoView; import com.maning.gankmm.R; import com.maning.gankmm.app.MyApplication; +import com.maning.gankmm.bean.GankEntity; import com.maning.gankmm.constant.Constants; +import com.maning.gankmm.db.CollectDao; import com.maning.gankmm.listeners.OnItemClickListener; import com.maning.gankmm.ui.dialog.ListFragmentDialog; import com.maning.gankmm.ui.view.ProgressWheel; @@ -56,6 +55,7 @@ public class MNImageBrowserActivity extends AppCompatActivity { public final static String IntentKey_ImageList = "IntentKey_ImageList"; + public final static String IntentKey_GankEntityList = "IntentKey_GankEntityList"; public final static String IntentKey_CurrentPosition = "IntentKey_CurrentPosition"; private Context context; @@ -69,11 +69,14 @@ public class MNImageBrowserActivity extends AppCompatActivity { private int clickPosition; //需要保存的图片 private ArrayList imageUrlList = new ArrayList<>(); + private ArrayList welFareLists; private int currentPosition; private MStatusDialog mStatusDialog; private MProgressDialog mProgressDialog; + private ArrayList mListDialogDatas = new ArrayList<>(); + @Override protected void onCreate(Bundle savedInstanceState) { setWindowFullScreen(); @@ -112,6 +115,7 @@ private void setWindowFullScreen() { private void initIntent() { imageUrlList = getIntent().getStringArrayListExtra(IntentKey_ImageList); + welFareLists = (ArrayList) getIntent().getSerializableExtra(IntentKey_GankEntityList); currentPosition = getIntent().getIntExtra(IntentKey_CurrentPosition, 1); } @@ -138,6 +142,7 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse @Override public void onPageSelected(int position) { + currentPosition = position; tvNumShow.setText(String.valueOf((position + 1) + "/" + imageUrlList.size())); } @@ -259,13 +264,23 @@ public void run() { }).start(); } - private ArrayList mListDialogDatas = new ArrayList<>(); - public void showBottomSheet() { mListDialogDatas.clear(); mListDialogDatas.add("保存"); mListDialogDatas.add("分享"); mListDialogDatas.add("设置壁纸"); + + if (welFareLists != null && welFareLists.size() > 0) { + GankEntity gankEntity = welFareLists.get(currentPosition); + //查询是否存在收藏 + boolean isCollect = new CollectDao().queryOneCollectByID(gankEntity.get_id()); + if (isCollect) { + mListDialogDatas.add("取消收藏"); + } else { + mListDialogDatas.add("收藏"); + } + } + ListFragmentDialog.newInstance(this).showDailog(getSupportFragmentManager(), mListDialogDatas, new OnItemClickListener() { @Override public void onItemClick(View view, int position) { @@ -286,6 +301,29 @@ public void onItemClick(View view, int position) { IntentUtils.startAppShareText(context, "GankMM图片分享", "分享图片:" + imageUrlList.get(clickPosition)); } else if (position == 2) { setWallpaper(); + } else if (position == 3) { + if (welFareLists != null && welFareLists.size() > 0) { + GankEntity gankEntity = welFareLists.get(currentPosition); + //查询是否存在收藏 + boolean isCollect = new CollectDao().queryOneCollectByID(gankEntity.get_id()); + if (isCollect) { + //取消收藏 + boolean deleteResult = new CollectDao().deleteOneCollect(gankEntity.get_id()); + if (deleteResult) { + mStatusDialog.show("取消收藏成功", getResources().getDrawable(R.drawable.mn_icon_dialog_success)); + } else { + mStatusDialog.show("取消收藏失败", getResources().getDrawable(R.drawable.mn_icon_dialog_fail)); + } + } else { + //收藏 + boolean insertResult = new CollectDao().insertOneCollect(gankEntity); + if (insertResult) { + mStatusDialog.show("收藏成功", getResources().getDrawable(R.drawable.mn_icon_dialog_success)); + } else { + mStatusDialog.show("收藏失败", getResources().getDrawable(R.drawable.mn_icon_dialog_fail)); + } + } + } } } }); @@ -349,28 +387,6 @@ public boolean onResourceReady(Drawable resource, Object model, Target }) .into(imageView); -// Glide -// .with(context) -// .load(url) -// .thumbnail(0.2f) -// .listener(new RequestListener() { -// @Override -// public boolean onException(Exception e, String model, Target target, boolean isFirstResource) { -// progressWheel.setVisibility(View.GONE); -// iv_fail.setVisibility(View.VISIBLE); -// return false; -// } -// -// @Override -// public boolean onResourceReady(GlideDrawable resource, String model, Target target, boolean isFromMemoryCache, boolean isFirstResource) { -// progressWheel.setVisibility(View.GONE); -// rl_image_placeholder_bg.setVisibility(View.GONE); -// iv_fail.setVisibility(View.GONE); -// return false; -// } -// }) -// .into(imageView); - rl_browser_root.setOnClickListener(new View.OnClickListener() { @Override diff --git a/app/src/main/java/com/maning/gankmm/ui/presenter/impl/WelFarePresenterImpl.java b/app/src/main/java/com/maning/gankmm/ui/presenter/impl/WelFarePresenterImpl.java index d5e4800..c52a687 100644 --- a/app/src/main/java/com/maning/gankmm/ui/presenter/impl/WelFarePresenterImpl.java +++ b/app/src/main/java/com/maning/gankmm/ui/presenter/impl/WelFarePresenterImpl.java @@ -37,7 +37,7 @@ public WelFarePresenterImpl(Context context, IWelFareView iWelFareView) { private MyCallBack httpCallBack = new MyCallBack() { @Override public void onSuccessList(int what, List results) { - if(mView == null){ + if (mView == null) { return; } switch (what) { @@ -89,7 +89,7 @@ public void onSuccess(int what, Object result) { @Override public void onFail(int what, String result) { - if(mView == null){ + if (mView == null) { return; } mView.overRefresh(); @@ -114,7 +114,7 @@ public void getMoreDatas() { public void getRandomDatas() { //查看配置的干活类型:默认Android String headLineType = SharePreUtil.getStringData(context, Constants.SPSwitcherDataType, "Android"); - GankApi.getRandomDatas(headLineType,10, 0x003, httpCallBack); + GankApi.getRandomDatas(headLineType, 10, 0x003, httpCallBack); } @Override @@ -123,7 +123,7 @@ public void itemClick(View view, int position) { for (int i = 0; i < welFareLists.size(); i++) { imagesList.add(welFareLists.get(i).getUrl()); } - IntentUtils.startToImageShow(context, imagesList, position,view); + IntentUtils.startToImageShow(context, imagesList, (ArrayList) welFareLists, position, view); } } diff --git a/app/src/main/java/com/maning/gankmm/utils/IntentUtils.java b/app/src/main/java/com/maning/gankmm/utils/IntentUtils.java index 8ff7c30..b12a21b 100644 --- a/app/src/main/java/com/maning/gankmm/utils/IntentUtils.java +++ b/app/src/main/java/com/maning/gankmm/utils/IntentUtils.java @@ -6,6 +6,7 @@ import android.net.Uri; import android.view.View; +import com.maning.gankmm.bean.GankEntity; import com.maning.gankmm.ui.activity.AboutActivity; import com.maning.gankmm.ui.activity.GankActivity; import com.maning.gankmm.ui.activity.MoreActivity; @@ -17,6 +18,7 @@ import com.socks.library.KLog; import java.util.ArrayList; +import java.util.List; /** * Created by maning on 16/3/3. @@ -35,12 +37,11 @@ public class IntentUtils { public static final String PushMessage = "PushMessage"; public static void startToImageShow(Context context, ArrayList mDatas, int position, View view) { -// Intent intent = new Intent(context.getApplicationContext(), ImagesActivity.class); -// intent.putStringArrayListExtra(ImageArrayList, mDatas); -// intent.putExtra(ImagePositionForImageShow, position); -// context.startActivity(intent); - KLog.i("startToImageShow:" + view.getWidth() / 2 + "," + view.getHeight()); - MNImageBrowser.showImageBrowser(context, view, position, mDatas); + MNImageBrowser.showImageBrowser(context, view, position, mDatas, null); + } + + public static void startToImageShow(Context context, ArrayList mDatas, ArrayList gankEntityList, int position, View view) { + MNImageBrowser.showImageBrowser(context, view, position, mDatas, gankEntityList); } public static void startToWebActivity(Context context, String titleFlag, String title, String url) {