Explorar o código

Merge remote-tracking branch 'origin/sheep_develop' into sheep_develop

zengjiebin %!s(int64=7) %!d(string=hai) anos
pai
achega
63aae84c9f

+ 2 - 0
app/src/main/java/com/sheep/gamegroup/module/login/fragments/SignUpFgt.java

@@ -14,6 +14,7 @@ import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.LoginEntity;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.module.login.controller.LoginController;
+import com.sheep.gamegroup.util.ChannelContent;
 import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.PreferenceUtils;
 import com.sheep.gamegroup.util.StringUtils;
@@ -83,6 +84,7 @@ public class SignUpFgt extends BaseFragment {
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("user_name", userNameBox.getText().toString().trim());
         jsonObject.put("password", passwordBox.getText().toString().trim());
+        jsonObject.put("invitation_code", ChannelContent.getInstance().getChannel_name());
         PreferenceUtils.setPrefString(SheepApp.getInstance(), UMConfigUtils.LOGIN_TYPE, UMConfigUtils.Source.SHEEP);
         SheepApp.getInstance().getNetComponent().getApiService().registerByUserName(jsonObject)
                 .subscribeOn(Schedulers.io())

+ 31 - 5
app/src/main/java/com/sheep/gamegroup/util/ChannelContent.java

@@ -1,9 +1,11 @@
 package com.sheep.gamegroup.util;
 
 import android.content.Context;
+import android.content.SharedPreferences;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageInfo;
 import android.text.TextUtils;
+import android.view.TextureView;
 
 import com.kfzs.duanduan.utils.ApkUtils;
 import com.sheep.jiuyan.samllsheep.SheepApp;
@@ -41,7 +43,7 @@ public class ChannelContent {
 
     private static final String META_INF_FILE_START = "META-INF/pl_channel_";
     private static final String CHANNEL_FILE_MARK = "pl_channel_";
-    private String channel_name="";
+    private String channel_name = "";
     private String gameId;
     private static ChannelContent instance;
     private Properties properties;
@@ -58,6 +60,15 @@ public class ChannelContent {
     }
 
     public boolean initChannelContent(Context context) {
+        channel_name = getChannelName(context);
+        if(TextUtils.isEmpty(channel_name)){
+            return loadContentFromApk(context);
+        }else {
+            return true;
+        }
+    }
+
+    private boolean loadContentFromApk(Context context){
         hasChannelFile = false;
         ApplicationInfo appInfo = context.getApplicationInfo();
         String sourceDir = appInfo.sourceDir;
@@ -77,6 +88,7 @@ public class ChannelContent {
                     }
                     String[] split = entryName.split(CHANNEL_FILE_MARK);
                     channel_name = split[split.length - 1];
+                    saveChannelName(context, channel_name);
                     hasChannelFile = true;
                     long size = entry.getSize();
                     if (size > 0) {
@@ -99,20 +111,21 @@ public class ChannelContent {
                 }
             }
         }
-        if(!hasChannelFile){//zip方式获取渠道
+        if (!hasChannelFile) {//zip方式获取渠道
             try {
                 PackageInfo packageInfo = ApkUtils.getPackageInfo(SheepApp.getInstance().getPackageName());
-                if(packageInfo != null && !TextUtils.isEmpty(packageInfo.applicationInfo.sourceDir)) {
+                if (packageInfo != null && !TextUtils.isEmpty(packageInfo.applicationInfo.sourceDir)) {
                     String comment = ZipChannelUtil.readQUA(new File(packageInfo.applicationInfo.sourceDir));
-                    if(!TextUtils.isEmpty(comment)){
+                    if (!TextUtils.isEmpty(comment)) {
                         hasChannelFile = true;
-                        if(comment.contains(";")){
+                        if (comment.contains(";")) {
                             String[] items = comment.split(";");
                             channel_name = items[0];
                             gameId = items[1];
                         } else {
                             channel_name = comment;
                         }
+                        saveChannelName(context, channel_name);
                     }
                 }
             } catch (IOException e) {
@@ -121,10 +134,23 @@ public class ChannelContent {
         }
         return hasChannelFile;
     }
+
     public String getChannel_name() {
         return channel_name;
     }
 
+    private void saveChannelName(Context context, String channelName) {
+        SharedPreferences sp = context.getSharedPreferences("channel_content", Context.MODE_PRIVATE);
+        SharedPreferences.Editor editor = sp.edit();
+        editor.putString("channel_name", channelName);
+        editor.commit();
+    }
+
+    private String getChannelName(Context context) {
+        SharedPreferences sp = context.getSharedPreferences("channel_content", Context.MODE_PRIVATE);
+        return sp.getString("channel_name", "");
+    }
+
     public Map<String, String> getChanelInfo(String... key) {
         if (!hasChannelFile || properties == null || properties.isEmpty()) {
             new ExceptionInInitializerError("has your initChannelContent() ?").printStackTrace();