|
|
@@ -1,28 +1,57 @@
|
|
|
package com.kfzs.duanduan.fragment;
|
|
|
|
|
|
+import android.app.Activity;
|
|
|
+import android.app.AlertDialog;
|
|
|
+import android.content.Intent;
|
|
|
+import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Environment;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
+import android.view.Window;
|
|
|
+import android.view.WindowManager;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.bumptech.glide.Glide;
|
|
|
+import com.bumptech.glide.request.FutureTarget;
|
|
|
+import com.bumptech.glide.request.RequestOptions;
|
|
|
+import com.bumptech.glide.request.target.Target;
|
|
|
import com.kfzs.duanduan.BaseCompatFragment;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.model.entity.FriendAndAwardEntity;
|
|
|
import com.sheep.gamegroup.model.entity.UserEntity;
|
|
|
import com.sheep.gamegroup.model.entity.WebviewEntity;
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
+import com.sheep.gamegroup.util.AppUtil;
|
|
|
+import com.sheep.gamegroup.util.FastJsonUtils;
|
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.MyDbManager;
|
|
|
+import com.sheep.gamegroup.util.StringUtils;
|
|
|
import com.sheep.gamegroup.util.UMConfigUtils;
|
|
|
+import com.sheep.gamegroup.view.activity.AskGetMoneyAct;
|
|
|
import com.sheep.gamegroup.view.activity.PersonalCenterAct;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
|
|
|
import org.xutils.ex.DbException;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
+
|
|
|
import butterknife.BindView;
|
|
|
import butterknife.ButterKnife;
|
|
|
import butterknife.OnClick;
|
|
|
import butterknife.Unbinder;
|
|
|
+import rx.android.schedulers.AndroidSchedulers;
|
|
|
+import rx.schedulers.Schedulers;
|
|
|
|
|
|
/**
|
|
|
* 个人中心
|
|
|
@@ -49,7 +78,7 @@ public class FgtPersonalCenter extends BaseCompatFragment {
|
|
|
}
|
|
|
|
|
|
private void initData() {
|
|
|
-
|
|
|
+ getShardData();
|
|
|
try {
|
|
|
userEntitys = MyDbManager.getInstance().dbFindUser();
|
|
|
} catch (DbException e) {
|
|
|
@@ -110,10 +139,169 @@ public class FgtPersonalCenter extends BaseCompatFragment {
|
|
|
getActivity());
|
|
|
break;
|
|
|
case R.id.recommend_friend_layout://推荐给好友
|
|
|
+ if(Ety!= null){
|
|
|
+ shardFriend(getActivity(),Ety.getShare_link());
|
|
|
+ }
|
|
|
break;
|
|
|
case R.id.tv_submit://注销
|
|
|
((PersonalCenterAct)getActivity()).loginOut();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分享对话框
|
|
|
+ * @param activity
|
|
|
+ * @param link
|
|
|
+ */
|
|
|
+ private void shardFriend(final Activity activity, final String link) {
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
|
+ View view = View.inflate(activity, R.layout.x_recommend_dialog, null);
|
|
|
+ builder.setView(view);
|
|
|
+
|
|
|
+ final AlertDialog dialog = builder.create();
|
|
|
+ ImageView iv = view.findViewById(R.id.iv_close);
|
|
|
+ TextView withdrawal = view.findViewById(R.id.withdrawal);
|
|
|
+ TextView tv_link = view.findViewById(R.id.tv_link);
|
|
|
+ TextView save_pic = view.findViewById(R.id.save_pic);
|
|
|
+ ImageView iv_qr = view.findViewById(R.id.iv_qr);
|
|
|
+ ImageView iv_qr_small = view.findViewById(R.id.iv_qr_small);
|
|
|
+
|
|
|
+ tv_link.setText(link);
|
|
|
+
|
|
|
+ Glide.with(activity)
|
|
|
+ .load(AppUtil.getQRLink(link, 800))
|
|
|
+ .apply(new RequestOptions().override(800, 800))
|
|
|
+ .into(iv_qr);
|
|
|
+ Glide.with(activity)
|
|
|
+ .load("http://cdngame.kuaifazs.com/icon.png")
|
|
|
+ .apply(new RequestOptions().override(G.WIDTH/5))
|
|
|
+ .into(iv_qr_small);
|
|
|
+ dialog.show();
|
|
|
+ Window window = dialog.getWindow();
|
|
|
+ if(window != null) {
|
|
|
+ android.view.WindowManager.LayoutParams p = window.getAttributes();
|
|
|
+ p.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
+// p.height = G.WIDTH;
|
|
|
+ p.width = G.WIDTH;
|
|
|
+ dialog.getWindow().setAttributes(p); //设置生效
|
|
|
+ }
|
|
|
+ iv.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ withdrawal.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ StringUtils.CopyText(activity,Ety.getShare_link());
|
|
|
+ showToast("复制链接成功");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ save_pic.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+
|
|
|
+ new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ String imagePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + new Date().toString() +".png";
|
|
|
+ String path = getImagePath(AppUtil.getQRLink(link, 800));
|
|
|
+ /**
|
|
|
+ * 拷贝到指定路径
|
|
|
+ */
|
|
|
+ copyFile(path, imagePath);
|
|
|
+ Intent intentBroadcast = new Intent(
|
|
|
+ Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
|
|
|
+ File file = new File(imagePath);
|
|
|
+ intentBroadcast.setData(Uri.fromFile(file));
|
|
|
+ activity.sendBroadcast(intentBroadcast);
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+ showToast("已保存");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ FriendAndAwardEntity Ety;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取分享数据
|
|
|
+ */
|
|
|
+ private void getShardData(){
|
|
|
+ SheepApp.get(getActivity()).getNetComponent().getApiService().FriendCountAndAward()
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ showToast(baseMessage.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ if(baseMessage!=null){
|
|
|
+ Ety = FastJsonUtils.toBean( JSONObject.toJSONString(baseMessage.getData()),FriendAndAwardEntity.class);
|
|
|
+ }else{
|
|
|
+ showToast("数据解析出错");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取Glide显示图片的缓存路径
|
|
|
+ * @param imgUrl
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getImagePath(String imgUrl) {
|
|
|
+ String path = null;
|
|
|
+ FutureTarget<File> future = Glide.with(this)
|
|
|
+ .load(imgUrl)
|
|
|
+ .downloadOnly(Target.SIZE_ORIGINAL,Target.SIZE_ORIGINAL);
|
|
|
+ try {
|
|
|
+ File cacheFile = future.get();
|
|
|
+ path = cacheFile.getAbsolutePath();
|
|
|
+ } catch (InterruptedException | ExecutionException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存图片
|
|
|
+ * @param oldPath
|
|
|
+ * @param newPath
|
|
|
+ */
|
|
|
+ public void copyFile(String oldPath, String newPath) {
|
|
|
+ try {
|
|
|
+ int bytesum = 0;
|
|
|
+ int byteread = 0;
|
|
|
+ File oldfile = new File(oldPath);
|
|
|
+ if (oldfile.exists()) { //文件存在时
|
|
|
+ InputStream inStream = new FileInputStream(oldPath); //读入原文件
|
|
|
+ FileOutputStream fs = new FileOutputStream(newPath);
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ while ( (byteread = inStream.read(buffer)) != -1) {
|
|
|
+ bytesum += byteread; //字节数 文件大小
|
|
|
+ fs.write(buffer, 0, byteread);
|
|
|
+ }
|
|
|
+ inStream.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|