Skip to content

Commit

Permalink
图片浏览页面添加收藏和取消收藏功能
Browse files Browse the repository at this point in the history
  • Loading branch information
maning committed Dec 29, 2017
1 parent 6a670a7 commit 3e26f19
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void run() {
}

private void initRecycleView(List<GankEntity> welFareList) {

((MainActivity) getActivity()).setPicList(welFareList);

if (recyclePicAdapter == null) {
Expand All @@ -86,7 +86,7 @@ private void initRecycleView(List<GankEntity> welFareList) {
recyclePicAdapter.setOnItemClickLitener(new RecyclePicAdapter.OnItemClickLitener() {
@Override
public void onItemClick(View view, int position) {
welFarePresenter.itemClick(view,position);
welFarePresenter.itemClick(view, position);
}
});
//获取头条随机
Expand Down Expand Up @@ -154,5 +154,12 @@ public void onDestroyView() {
ButterKnife.unbind(this);
}


@Override
public void onResume() {
super.onResume();
//刷新页面
if (recyclePicAdapter != null) {
recyclePicAdapter.notifyDataSetChanged();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -18,15 +20,17 @@ public class MNImageBrowser {

/**
* 打开浏览页面
*
* @param context 上下文
* @param view 点击的当前View
* @param position 默认打开第几个
* @param imageList 数据源ArrayList<String>
*/
public static void showImageBrowser(Context context, View view, int position, ArrayList<String> imageList) {
public static void showImageBrowser(Context context, View view, int position, ArrayList<String> imageList, ArrayList<GankEntity> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -69,11 +69,14 @@ public class MNImageBrowserActivity extends AppCompatActivity {
private int clickPosition; //需要保存的图片

private ArrayList<String> imageUrlList = new ArrayList<>();
private ArrayList<GankEntity> welFareLists;
private int currentPosition;

private MStatusDialog mStatusDialog;
private MProgressDialog mProgressDialog;

private ArrayList<String> mListDialogDatas = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
setWindowFullScreen();
Expand Down Expand Up @@ -112,6 +115,7 @@ private void setWindowFullScreen() {

private void initIntent() {
imageUrlList = getIntent().getStringArrayListExtra(IntentKey_ImageList);
welFareLists = (ArrayList<GankEntity>) getIntent().getSerializableExtra(IntentKey_GankEntityList);
currentPosition = getIntent().getIntExtra(IntentKey_CurrentPosition, 1);
}

Expand All @@ -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()));
}

Expand Down Expand Up @@ -259,13 +264,23 @@ public void run() {
}).start();
}

private ArrayList<String> 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) {
Expand All @@ -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));
}
}
}
}
}
});
Expand Down Expand Up @@ -349,28 +387,6 @@ public boolean onResourceReady(Drawable resource, Object model, Target<Drawable>
})
.into(imageView);

// Glide
// .with(context)
// .load(url)
// .thumbnail(0.2f)
// .listener(new RequestListener<String, GlideDrawable>() {
// @Override
// public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
// progressWheel.setVisibility(View.GONE);
// iv_fail.setVisibility(View.VISIBLE);
// return false;
// }
//
// @Override
// public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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<GankEntity>) welFareLists, position, view);
}

}
13 changes: 7 additions & 6 deletions app/src/main/java/com/maning/gankmm/utils/IntentUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +18,7 @@
import com.socks.library.KLog;

import java.util.ArrayList;
import java.util.List;

/**
* Created by maning on 16/3/3.
Expand All @@ -35,12 +37,11 @@ public class IntentUtils {
public static final String PushMessage = "PushMessage";

public static void startToImageShow(Context context, ArrayList<String> 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<String> mDatas, ArrayList<GankEntity> gankEntityList, int position, View view) {
MNImageBrowser.showImageBrowser(context, view, position, mDatas, gankEntityList);
}

public static void startToWebActivity(Context context, String titleFlag, String title, String url) {
Expand Down

0 comments on commit 3e26f19

Please sign in to comment.