Commit 6cc0d15a authored by 赵鹏翔's avatar 赵鹏翔

修改渠道配置

parent 5b4ed42e
......@@ -55,7 +55,7 @@ android {
variant.outputs.all { output ->
outputFileName = new File(output.outputFile.parent,
"${getAppChannel()}" + "_v" +
"Miya_FastCashier_v" +
variant.versionName + "_" +
variant.versionCode + "_" +
variant.buildType.name + "_" +
......@@ -90,7 +90,3 @@ static String buildTime() {
String dates = date.format("yyyyMMddHHmm", TimeZone.getTimeZone("Asia/Shanghai"))
return dates
}
\ No newline at end of file
String getAppChannel() {
return project.CHANNEL
}
\ No newline at end of file
......@@ -157,15 +157,21 @@ class LoginActivity : AppCompatActivity() {
private fun login() {
binding.vLoading.visibility = View.VISIBLE
val userName = binding.etUsername.text.toString()
if (ChannelManageKit.containsAccount(this, userName)) {
loginViewModel.login(
userName,
binding.etPassword.text.toString()
)
} else {
binding.vLoading.visibility = View.GONE
CenterToasty.error(this, "账号有误,请检查后重试").show()
}
//暂不加账号过滤
// if (ChannelManageKit.containsAccount(this, userName)) {
// loginViewModel.login(
// userName,
// binding.etPassword.text.toString()
// )
// } else {
// binding.vLoading.visibility = View.GONE
// CenterToasty.error(this, "账号有误,请检查后重试").show()
// }
}
/**
......
package com.miya.fastcashier.util.manage;
import android.content.Context;
import android.content.res.AssetManager;
import android.text.TextUtils;
import com.blankj.utilcode.util.GsonUtils;
import com.fastcashier.lib_common.function.account.AccountService;
import com.google.gson.reflect.TypeToken;
import com.miya.fastcashier.bean.ChannelInfoBean;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 类说明:渠道管理类(用于处理品牌全局设置,以及换肤所需渠道配置)
* 详细描述:目前通过本地资源文件加载 todo 后期能改成接口返回渠道最好
* 创建人:zpxiang
* 创建时间:
* 修改人:
* 修改时间:
*/
public class ChannelManageKit {
private static Map<String, ChannelInfoBean> channelMap;//key为账号,value为所属的品牌信息
private static final String CHANNEL_OFFICIAL_ACCOUNT = "-1";
private static final String CHANNEL_OFFICIAL_CHANNELNAME = "通用";
private static final String CHANNEL_OFFICIAL_CHANNELNAME_EN = "common";
/**
* 初始化本地渠道数据
*/
public static void initChannelRes(Context context) {
clearChannelResData();
if (null == context) {
initDefaultChannelRes();
return;
}
String assetsJson = getAssetsJson(context, "channel.json");
if (TextUtils.isEmpty(assetsJson)) {
initDefaultChannelRes();
return;
}
ArrayList<ChannelInfoBean> channelInfoList = GsonUtils.fromJson(assetsJson, new TypeToken<List<ChannelInfoBean>>() {
}.getType());
channelMap = new HashMap<>();
if (!channelInfoList.isEmpty()) {
for (int i = 0; i < channelInfoList.size(); i++) {
ChannelInfoBean channelInfoBean = channelInfoList.get(i);
List<String> channelAccountArray = channelInfoBean.getChannelAccountArray();
if (channelAccountArray.isEmpty()) {
initDefaultChannelRes();
continue;
}
for (int j = 0; j < channelAccountArray.size(); j++) {
String account = channelAccountArray.get(j);
channelMap.put(account, channelInfoBean);
}
}
}
}
private static void initDefaultChannelRes() {
if (channelMap == null){
channelMap = new HashMap<>();
}
ChannelInfoBean commonChannel = new ChannelInfoBean();
commonChannel.setChannelId("-1");
commonChannel.setChannelName(CHANNEL_OFFICIAL_CHANNELNAME);
commonChannel.setChannelNameEn(CHANNEL_OFFICIAL_CHANNELNAME_EN);
channelMap.put(CHANNEL_OFFICIAL_ACCOUNT, commonChannel);
}
/**
* 判断本地是否包含本品牌账户,此处暂时用来处理区别大屏和手持账号
*/
public static boolean containsAccount(Context context, String account) {
if (channelMap == null || channelMap.isEmpty()) {
initChannelRes(context);
}
return channelMap.containsKey(account);
}
/**
* 获取渠道名称
*/
public static String getAppChannelName(Context context) {
if (channelMap == null || channelMap.isEmpty()) {
initChannelRes(context);
}
boolean containsKey = channelMap.containsKey(AccountService.INSTANCE.getUserName());
if (!containsKey) {
return CHANNEL_OFFICIAL_CHANNELNAME;
}
return channelMap.get(AccountService.INSTANCE.getUserName()).getChannelName();
}
/**
* 获取App渠道编号
*/
public static String getAppChannelId(Context context) {
if (context == null) {
return CHANNEL_OFFICIAL_ACCOUNT;
}
if (channelMap == null || channelMap.isEmpty()) {
initChannelRes(context);
}
if (!channelMap.containsKey(AccountService.INSTANCE.getUserName())) {
return CHANNEL_OFFICIAL_ACCOUNT;
}
return channelMap.get(AccountService.INSTANCE.getUserName()).getChannelId();
}
public static void clearChannelResData() {
if (null == channelMap) {
return;
}
channelMap.clear();
channelMap = null;
}
/**
* 读取json文件
*/
private static String getAssetsJson(Context context, String fileName) {
StringBuilder stringBuilder = new StringBuilder();
AssetManager assetManager = context.getAssets();
try {
BufferedReader bf = new BufferedReader(new InputStreamReader(assetManager.open(fileName), "UTF-8"));
String line;
while ((line = bf.readLine()) != null) {
stringBuilder.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
return stringBuilder.toString();
}
}
package com.miya.fastcashier.util.manage
import android.content.Context
import android.text.TextUtils
import com.blankj.utilcode.util.GsonUtils
import com.fastcashier.lib_common.function.account.AccountService.getUserName
import com.google.gson.reflect.TypeToken
import com.miya.fastcashier.bean.ChannelInfoBean
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.util.*
import kotlin.collections.HashMap
/**
* 类说明:渠道管理类(用于处理品牌全局设置,以及换肤所需渠道配置)
* 详细描述:目前通过本地资源文件加载 todo 后期能改成接口返回渠道最好
* 创建人:zpxiang
* 创建时间:
* 修改人:
* 修改时间:
*/
object ChannelManageKit {
private var channelMap: HashMap<String, ChannelInfoBean>? = null//key为账号,value为所属的品牌信息
private const val CHANNEL_OFFICIAL_ACCOUNT = "-1"
private const val CHANNEL_OFFICIAL_CHANNELNAME = "通用"
private const val CHANNEL_OFFICIAL_CHANNELNAME_EN = "common"
/**
* 初始化本地渠道数据
*/
fun initChannelRes(context: Context?) {
clearChannelResData()
if (null == context) {
initDefaultChannelRes()
return
}
val assetsJson = getAssetsJson(context, "channel.json")
if (TextUtils.isEmpty(assetsJson)) {
initDefaultChannelRes()
return
}
val channelInfoList = GsonUtils.fromJson<ArrayList<ChannelInfoBean>>(
assetsJson,
object : TypeToken<List<ChannelInfoBean?>?>() {}.type
)
channelMap = HashMap()
if (!channelInfoList.isEmpty()) {
for (i in channelInfoList.indices) {
val channelInfoBean = channelInfoList[i]
val channelAccountArray = channelInfoBean.channelAccountArray
if (channelAccountArray.isEmpty()) {
initDefaultChannelRes()
continue
}
for (j in channelAccountArray.indices) {
val account = channelAccountArray[j]
channelMap!![account] = channelInfoBean
}
}
}
}
private fun initDefaultChannelRes() {
if (channelMap == null) {
channelMap = HashMap()
}
val commonChannel = ChannelInfoBean()
commonChannel.channelId = "-1"
commonChannel.channelName = CHANNEL_OFFICIAL_CHANNELNAME
commonChannel.channelNameEn = CHANNEL_OFFICIAL_CHANNELNAME_EN
channelMap!![CHANNEL_OFFICIAL_ACCOUNT] = commonChannel
}
/**
* 判断本地是否包含本品牌账户,此处暂时用来处理区别大屏和手持账号
*/
fun containsAccount(context: Context?, account: String): Boolean {
if (channelMap == null || channelMap!!.isEmpty()) {
initChannelRes(context)
}
return channelMap!!.containsKey(account)
}
/**
* 获取渠道名称
*/
fun getAppChannelName(context: Context?): String {
if (channelMap == null || channelMap!!.isEmpty()) {
initChannelRes(context)
}
val containsKey = channelMap!!.containsKey(getUserName())
return if (!containsKey) {
CHANNEL_OFFICIAL_CHANNELNAME
} else channelMap!![getUserName()]!!.channelName
}
/**
* 获取App渠道编号
*/
fun getAppChannelId(context: Context?): String {
if (context == null) {
return CHANNEL_OFFICIAL_ACCOUNT
}
if (channelMap == null || channelMap!!.isEmpty()) {
initChannelRes(context)
}
return if (!channelMap!!.containsKey(getUserName())) {
CHANNEL_OFFICIAL_ACCOUNT
} else channelMap!![getUserName()]!!.channelId
}
fun clearChannelResData() {
if (null == channelMap) {
return
}
channelMap!!.clear()
channelMap = null
}
/**
* 读取json文件
*/
private fun getAssetsJson(context: Context, fileName: String): String {
val stringBuilder = StringBuilder()
val assetManager = context.assets
try {
val bf = BufferedReader(InputStreamReader(assetManager.open(fileName), "UTF-8"))
var line: String?
while (bf.readLine().also { line = it } != null) {
stringBuilder.append(line)
}
} catch (e: IOException) {
e.printStackTrace()
}
return stringBuilder.toString()
}
}
\ No newline at end of file
......@@ -22,6 +22,6 @@ android.jetifier.blacklist=miya-print
android.useDeprecatedNdk=true
#区别品牌
CHANNEL=converse
#CHANNEL=converse
#区别环境 true:是测试环境,仅供内部人员测试使用;false:非测试包,供外部人员、渠道推广、应用商店等使用
ISTEST=false
\ No newline at end of file
......@@ -14,7 +14,6 @@ android {
multiDexEnabled true
consumerProguardFiles "consumer-rules.pro"
buildConfigField 'String', "CHANNEL", "\"$CHANNEL\""
buildConfigField "Boolean", "ISTEST", ISTEST.toString()
buildConfigField "String", "appType", "\"mpos\""
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment