|
|
@@ -1,9 +1,12 @@
|
|
|
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.util.Log;
|
|
|
+import android.view.TextureView;
|
|
|
|
|
|
import com.kfzs.duanduan.utils.ApkUtils;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
@@ -41,7 +44,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 +61,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 +89,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 +112,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 +135,25 @@ 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);
|
|
|
+ String tmp = sp.getString("channel_name", "");
|
|
|
+ Log.e("ChannelContent", "invitation_code : " + channel_name);
|
|
|
+ return tmp;
|
|
|
+ }
|
|
|
+
|
|
|
public Map<String, String> getChanelInfo(String... key) {
|
|
|
if (!hasChannelFile || properties == null || properties.isEmpty()) {
|
|
|
new ExceptionInInitializerError("has your initChannelContent() ?").printStackTrace();
|