Переглянути джерело

登录成功时数据初始化优化;
切换到个人中心时,强制更新用户信息;
二维码图片优化

zengjiebin 7 роки тому
батько
коміт
968b173e2a

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/presenter/LoginPresenter.java

@@ -96,7 +96,7 @@ public class LoginPresenter implements LoginContract.Presenter {
                 }
             }
             SpUtils.saveToken(SheepApp.getInstance(), loginEty.getToken());
-            DataUtil.getInstance().setUserEntity(loginEty.getUser());
+            DataUtil.getInstance().initUserEntity(loginEty.getUser());
             LogUtil.logI("token--------"+loginEty.getToken());
         }
         view.NetSuccess(1,"登录成功", EntityUtils.getUserCode(loginEty));

+ 8 - 3
app/src/main/java/com/sheep/gamegroup/util/DataUtil.java

@@ -46,17 +46,22 @@ public class DataUtil {
     private static ACache aCache = ACache.get(SheepApp.getInstance());
 
     private DataUtil() {
-        userEntity = getCacheResult(ApiKey.get_info, UserEntity.class);//先从缓存中初始化用户信息
-        token = SpUtils.getToken(SheepApp.getInstance());
+        UserEntity cacheUser = getCacheResult(ApiKey.get_info, UserEntity.class);//先从缓存中初始化用户信息
+        initUserEntity(cacheUser);
         if(!TextUtils.isEmpty(token)){//如果有token,启动后台进程并初始化正在运行的自动审核任务列表
             CommonUtil.getInstance().reloadAutoTaskList();
         }
-        uid = TextUtils.isEmpty(token) ? "" : token.split("@")[0];
         if (userEntity != null && !TextUtils.equals(userEntity.getId(), uid)) {//当前用户id与缓存的用户信息不符时,清除缓存
             clearData();
         }
         initScreenShotConfig();
     }
+    //初始化用户相关信息
+    public void initUserEntity(UserEntity userEntity){
+        this.userEntity = userEntity;
+        token = SpUtils.getToken(SheepApp.getInstance());
+        uid = TextUtils.isEmpty(token) ? "" : token.split("@")[0];
+    }
 
 
     public static DataUtil getInstance() {

+ 0 - 24
app/src/main/java/com/sheep/gamegroup/util/MyDbManager.java

@@ -1,7 +1,6 @@
 package com.sheep.gamegroup.util;
 
 import android.database.Cursor;
-import android.os.Handler;
 
 import com.sheep.gamegroup.model.entity.AppRecord;
 import com.sheep.gamegroup.model.entity.AppUsage;
@@ -9,7 +8,6 @@ import com.sheep.gamegroup.model.entity.LoginUser;
 import com.sheep.gamegroup.model.entity.NewbieTaskRecord;
 import com.sheep.gamegroup.model.entity.SearchAppRecord;
 import com.sheep.gamegroup.model.entity.SearchGameRecord;
-import com.sheep.gamegroup.model.entity.UserEntity;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 
 import org.xutils.DbManager;
@@ -42,28 +40,6 @@ public class MyDbManager {
     }
 
     /**
-     * 保存或更新表表
-     */
-    public void saveOrUpdateUser(final UserEntity user) throws DbException {
-        if (user != null) {
-            DataUtil.getInstance().setUserEntity(user);
-            deleteTable(UserEntity.class);//先清空表
-            new Handler().postDelayed(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        db.saveOrUpdate(user);
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    }
-                }
-            }, 500);
-
-        }
-
-    }
-
-    /**
      * 查找NewbieTaskRecord
      */
     public NewbieTaskRecord dbFindNewbieTaskRecord(String invitation_code) throws DbException {

+ 7 - 1
app/src/main/java/com/sheep/gamegroup/util/TestUtil.java

@@ -108,7 +108,13 @@ public class TestUtil {
                                     Object object = ListUtil.getItem(list, which);
                                     if(object instanceof LoginUser){
                                         SpUtils.saveToken(SheepApp.getInstance(), ((LoginUser) object).getToken());
-                                        CommonUtil.getInstance().updateUserInfo(null);
+                                        CommonUtil.getInstance().updateUserInfo(new Action1<UserEntity>() {
+                                            @Override
+                                            public void call(UserEntity userEntity) {
+                                                if(userEntity != null)
+                                                    DataUtil.getInstance().initUserEntity(userEntity);
+                                            }
+                                        });
                                         ActivityManager.getInstance().finishAllActivity();
                                         Intent intent = new Intent(SheepApp.getInstance(), ActMain.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

+ 1 - 0
app/src/main/java/com/sheep/gamegroup/util/UMConfigUtils.java

@@ -175,6 +175,7 @@ public class UMConfigUtils {
         ASK_MAKE_MONEY_INVITATION("邀请赚钱分享页面"),
         SHARE_SYS_SEND("通过系统分享文件"),
         SHARE_TO_QZONE("分享到QQ空间"),
+        TASK_SAVE_QR("二维码小程序 -> 保存二维码"),
         ;
         private String tag;
 

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/view/activity/ActBindMobileRegister.java

@@ -189,7 +189,7 @@ public class ActBindMobileRegister extends BaseActivity {
                         }
                         if (loginEty != null) {
                             SpUtils.saveToken(activity, loginEty.getToken());
-                            DataUtil.getInstance().setUserEntity(loginEty.getUser());
+                            DataUtil.getInstance().initUserEntity(loginEty.getUser());
                         }
                         if(TextUtils.isEmpty(SheepApp.getInstance().getGameCode())){
                             Jump2View.getInstance().goHomePageView(activity, EntityUtils.getUserCode(loginEty));

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/view/activity/LoginAct.java

@@ -363,7 +363,7 @@ public class LoginAct extends BaseUMActivity implements LoginContract.View {
                         }
                         if (loginEty != null) {
                             SpUtils.saveToken(activity, loginEty.getToken());
-                            DataUtil.getInstance().setUserEntity(loginEty.getUser());
+                            DataUtil.getInstance().initUserEntity(loginEty.getUser());
                         }
 
                         if(TextUtils.isEmpty(SheepApp.getInstance().getGameCode())){

+ 24 - 22
app/src/main/java/com/sheep/gamegroup/view/adapter/TaskdetailSonListviewAdp.java

@@ -2,9 +2,7 @@ package com.sheep.gamegroup.view.adapter;
 
 import android.app.Activity;
 import android.content.Context;
-import android.content.Intent;
-import android.net.Uri;
-import android.support.annotation.NonNull;
+import android.graphics.BitmapFactory;
 import android.support.constraint.ConstraintLayout;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
@@ -18,20 +16,19 @@ import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import com.bumptech.glide.Glide;
+import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
 import com.bumptech.glide.request.RequestOptions;
 import com.sheep.gamegroup.model.entity.ScreenshotsEntity;
 import com.sheep.gamegroup.model.entity.TaskChild;
 import com.sheep.gamegroup.model.entity.TaskDescEntity;
-import com.sheep.gamegroup.model.entity.TaskEty;
 import com.sheep.gamegroup.model.entity.TaskReleaseEty;
 import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.GlideImageLoader;
 import com.sheep.gamegroup.util.ListUtil;
 import com.sheep.gamegroup.util.MyListview;
-import com.sheep.gamegroup.util.ViewHolder;
-import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.jiuyan.samllsheep.R;
-import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+import com.sheep.jiuyan.samllsheep.utils.FileUtil;
 import com.sheep.jiuyan.samllsheep.utils.G;
 
 import java.io.File;
@@ -39,8 +36,9 @@ import java.util.ArrayList;
 import java.util.List;
 
 import me.iwf.photopicker.PhotoPreview;
+import rx.functions.Action1;
 
-import static com.sheep.gamegroup.util.UMConfigUtils.Event.QR_SAVE;
+import static com.sheep.gamegroup.util.UMConfigUtils.Event.TASK_SAVE_QR;
 
 /**
  * Created by ljy on 2018/6/14.
@@ -277,26 +275,30 @@ public class TaskdetailSonListviewAdp extends BaseAdapter {
         if(taskReleaseEty == null || taskReleaseEty.getTask() == null || !taskReleaseEty.getTask().isApplet()){
             ar_code_layout.setVisibility(View.GONE);
         }else {
-
             if(taskReleaseEty.isIs_running()){
-
-                GlideImageLoader.setGameImage((ImageView) qr_code_iv, taskReleaseEty.getTask().getQr_code());
+                GlideImageLoader.downLoadImage(taskReleaseEty.getTask().getTask_name(), taskReleaseEty.getTask().getQr_code(), new Action1<File>() {
+                    @Override
+                    public void call(File file) {
+                        BitmapFactory.Options options = FileUtil.getImageOptions(file);
+                        int width = context.getResources().getDimensionPixelSize(R.dimen.content_padding_150);
+                        Glide.with(SheepApp.getInstance())
+                                .load(file)
+                                .apply(new RequestOptions().override(width, width * options.outHeight / options.outWidth).transform(new RoundedCorners(context.getResources().getDimensionPixelSize(R.dimen.content_padding_8))))
+                                .into((ImageView) qr_code_iv);
+                    }
+                });
                 btn_task_item.setVisibility(View.VISIBLE);
                 qr_code_notice_tv.setVisibility(View.GONE);
                 btn_task_item.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View v) {
-                        QR_SAVE.onEvent();
-                        File file = ViewUtil.saveImage(qr_code_iv, ClassFileHelper.DIR, System.currentTimeMillis() + ".jpg");
-                        if (file != null) {
-                            Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
-                            Uri uri = Uri.fromFile(file);
-                            intent.setData(uri);
-                            context.sendBroadcast(intent); // 发送广播通知相册
-                        } else {
-                            ViewUtil.sysSaveImage(qr_code_iv, "小绵羊", "二维码展示");
-                        }
-                        G.showToast("已保存");
+                        TASK_SAVE_QR.onEvent();
+                        GlideImageLoader.downLoadImage(taskReleaseEty.getTask().getTask_name(), taskReleaseEty.getTask().getQr_code(), new Action1<File>() {
+                            @Override
+                            public void call(File file) {
+                                G.showToast("保存成功,图片路径:" + file.getAbsolutePath());
+                            }
+                        });
                     }
                 });
             }else {

+ 17 - 1
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtPersonalCenter.java

@@ -316,7 +316,7 @@ public class FgtPersonalCenter extends BaseFragment {
                 startActivity(new Intent(activity, ActMsg.class));
                 break;
             case R.id.iv_redpackage://邀请成功后有可领红包
-                ViewUtil.changeRedPackage(getActivity(), getView(), FgtPersonalCenter.this);
+                ViewUtil.changeRedPackage(activity, getView(), FgtPersonalCenter.this);
                 break;
             case R.id.icon_img_iv://图片
                 if (TestUtil.isTest()) {
@@ -387,6 +387,22 @@ public class FgtPersonalCenter extends BaseFragment {
         }
     }
 
+    private boolean isVisibleToUser = false;
+    @Override
+    public void setUserVisibleHint(boolean isVisibleToUser) {
+        super.setUserVisibleHint(isVisibleToUser);
+        if(isVisibleToUser) {
+            if (this.isVisibleToUser) {
+                try {
+                    initData();
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    G.showToast(e.getMessage());
+                }
+            }
+            this.isVisibleToUser = true;
+        }
+    }
 
     @Override
     public void onResume() {

+ 13 - 14
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtSmallSheep.java

@@ -318,7 +318,7 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
         if (!userEntity.getParent_code().equals("") || (userEntity.getCreate_time_line() < 2) || (userEntity.getPackage_cate() == 1)) {
 
         } else {
-            changeRedPackage(getActivity(), LayoutInflater.from(getContext()).inflate(R.layout.activity_main, null), this);
+            changeRedPackage(activity, LayoutInflater.from(activity.getApplicationContext()).inflate(R.layout.activity_main, null), this);
         }
 
     }
@@ -546,16 +546,15 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
      */
     @SuppressLint("InflateParams")
     private void initTitleCardLayout(final Context context) {
-        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
         titleCardLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.view_float_title_card, null);
         doIt = titleCardLayout.findViewById(R.id.do_it_text);
         willStart = titleCardLayout.findViewById(R.id.will_start_text);
         doItLine = titleCardLayout.findViewById(R.id.do_it_every_day_line);
         lines = titleCardLayout.findViewById(R.id.but_will_start);
-        int linex = (wm.getDefaultDisplay().getWidth() / 6) - (getViewWidth(doItLine) / 2);
-        lines.setX(linex);
+        int lineX = (G.WIDTH / 6) - (getViewWidth(doItLine) / 2);
+        lines.setX(lineX);
         ViewGroup.LayoutParams layoutParams = lines.getLayoutParams();
-        layoutParams.width = wm.getDefaultDisplay().getWidth() - (linex * 2);
+        layoutParams.width = G.WIDTH - (lineX * 2);
         doIt.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -574,7 +573,7 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
                 willStartClick();
             }
         });
-        ((ViewGroup) this.getActivity().getWindow().getDecorView()).addView(titleCardLayout);
+        ((ViewGroup) activity.getWindow().getDecorView()).addView(titleCardLayout);
         titleCardLayout.setVisibility(View.GONE);
     }
 
@@ -582,24 +581,24 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
      * 每日必做按钮事件回调
      */
     private void toDayClick() {
-        doIt.setTextColor(getContext().getResources().getColor(R.color.blue_34a6e7));
-        willStart.setTextColor(getContext().getResources().getColor(R.color.black_444444));
+        doIt.setTextColor(getResources().getColor(R.color.blue_34a6e7));
+        willStart.setTextColor(getResources().getColor(R.color.black_444444));
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
             TransitionManager.beginDelayedTransition(titleCardLayout, new ChangeBounds());
         }
-        lines.setGravity(Gravity.LEFT);
+        lines.setGravity(Gravity.START);
     }
 
     /**
      * 即将开始按钮事件回调
      */
     private void willStartClick() {
-        doIt.setTextColor(getContext().getResources().getColor(R.color.black_444444));
-        willStart.setTextColor(getContext().getResources().getColor(R.color.blue_34a6e7));
+        doIt.setTextColor(getResources().getColor(R.color.black_444444));
+        willStart.setTextColor(getResources().getColor(R.color.blue_34a6e7));
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
             TransitionManager.beginDelayedTransition(titleCardLayout, new ChangeBounds());
         }
-        lines.setGravity(Gravity.RIGHT);
+        lines.setGravity(Gravity.END);
     }
 
     /**
@@ -626,7 +625,7 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
         showPDialog();
         initView();
         initListener();
-        initTitleCardLayout(this.getContext());
+        initTitleCardLayout(activity.getApplicationContext());
         TestUtil.testChange(activity, test_change);
         TestUtil.testChangeUser(activity, test_change_user);
         GlideImageLoader.setImage(bg_newbie_task, "http://cdngame.kuaifazs.com/bg_newbie_task.png");
@@ -1058,7 +1057,7 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
                     public void call(RobTask robTask) {
                         if (robTask != null) {
                             SheepApp.getInstance().setOrder(robTask.getOrder());
-                            ViewUtil.newInstance().showRobDutyDialog(getActivity(), getView(), robTask);
+                            ViewUtil.newInstance().showRobDutyDialog(activity, getView(), robTask);
                         } else {
                             G.showToast("任务已被抢光!请实时关注任务发布!");
                         }

+ 16 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/utils/FileUtil.java

@@ -105,4 +105,20 @@ public class FileUtil {
             bos.flush();
         }
     }
+
+    /**
+     * 获取图片配置信息
+     * @param file
+     * @return
+     */
+    public static BitmapFactory.Options getImageOptions(File file) {
+        BitmapFactory.Options options = new BitmapFactory.Options();
+        /**
+         * 最关键在此,把options.inJustDecodeBounds = true;
+         * 这里再decodeFile(),返回的bitmap为空,但此时调用options.outHeight时,已经包含了图片的高了
+         */
+        options.inJustDecodeBounds = true;
+        BitmapFactory.decodeFile(file.getAbsolutePath(), options); // 此时返回的bitmap为null
+        return options;
+    }
 }

+ 3 - 3
app/src/main/res/layout/taskdetail_mylistview_item.xml

@@ -144,11 +144,11 @@
 
             <ImageView
                 android:id="@+id/qr_code_iv"
-                android:layout_width="@dimen/view_size_80"
-                android:layout_height="@dimen/view_size_80"
+                android:layout_width="150dp"
+                android:layout_height="wrap_content"
                 android:layout_marginTop="@dimen/content_padding_18"
                 android:src="@mipmap/qr_code_taskdetail_zhanwei"
-                app:layout_constraintStart_toStartOf="@+id/qr_code_tv"
+                app:layout_constraintStart_toStartOf="parent"
                 app:layout_constraintTop_toBottomOf="@+id/qr_code_tv" />
 
             <TextView

+ 1 - 0
app/src/main/res/values/common.xml

@@ -63,6 +63,7 @@
     <dimen name="content_padding_96">96.5dp</dimen>
     <dimen name="content_padding_100">100dp</dimen>
     <dimen name="content_padding_120">120dp</dimen>
+    <dimen name="content_padding_150">150dp</dimen>
 
 
     <!--下面的tagid用于设置tag使用-->