Commit f3a7046d authored by 赵鹏翔's avatar 赵鹏翔

配置渠道管理类,处理渠道配置所需api

parent b004a9e3
......@@ -2,13 +2,13 @@
{
"ChannelId": -1,
"ChannelName": "通用",
"ChannelNameDesc": "common",
"ChannelNameEn": "common",
"ChannelAccountArray": []
},
{
"ChannelId": 1,
"ChannelName": "匡威",
"ChannelNameDesc": "converse",
"ChannelNameEn": "converse",
"ChannelAccountArray": ["6011","6013","6014","6017","6021"]
}
]
\ No newline at end of file
package com.miya.fastcashier.bean;
import com.fastcashier.lib_common.base.BaseBean;
import java.util.List;
/**
* 类描述:渠道配置信息
* 创建人:zpxiang
* 创建时间:
* 修改人:
* 修改时间:
*/
public class ChannelInfoBean extends BaseBean {
/**
* ChannelId : 1
* ChannelName : 匡威
* ChannelNameDesc : converse
* ChannelAccountArray : ["6011","6013","6014","6017","6021"]
*/
private String ChannelId;
private String ChannelName;
private String ChannelNameEn;
private List<String> ChannelAccountArray;
public void setChannelId(String channelId) {
ChannelId = channelId;
}
public String getChannelId() {
return ChannelId;
}
public String getChannelName() {
return ChannelName;
}
public void setChannelName(String channelName) {
ChannelName = channelName;
}
public String getChannelNameEn() {
return ChannelNameEn;
}
public void setChannelNameEn(String channelNameEn) {
ChannelNameEn = channelNameEn;
}
public List<String> getChannelAccountArray() {
return ChannelAccountArray;
}
public void setChannelAccountArray(List<String> channelAccountArray) {
ChannelAccountArray = channelAccountArray;
}
}
package com.miya.fastcashier.bean
import java.io.Serializable
import com.fastcashier.lib_common.base.BaseBean
/**
* 作者:Leon
* 时间:2017/3/21 14:50
*/
class LFileParamEntity : Serializable {
class LFileParamBean : BaseBean() {
var title: String? = null
@get:Deprecated("")
......
......@@ -3,7 +3,7 @@ package com.miya.fastcashier.bean
/**
* Data validation state of the login form.
*/
data class LoginFormState(
data class LoginFormStateBean(
val usernameError: Int? = null,
val passwordError: Int? = null,
val isDataValid: Boolean = false
......
......@@ -23,7 +23,7 @@ import com.fastcashier.lib_common.net.CommonCallback;
import com.fastcashier.lib_common.util.LogFileUtils;
import com.miya.fastcashier.R;
import com.miya.fastcashier.util.manage.log.LFileFilter;
import com.miya.fastcashier.bean.LFileParamEntity;
import com.miya.fastcashier.bean.LFileParamBean;
import com.miya.fastcashier.net.MiyaApiRequest;
import com.miya.fastcashier.net.MiyaApi;
import com.miya.fastcashier.ui.adapter.PathAdapter;
......@@ -55,7 +55,7 @@ public class LFilePickerActivity extends BaseActivity {
private String mPath;
private PathAdapter mPathAdapter;
private Toolbar mToolbar;
private LFileParamEntity mParamEntity;
private LFileParamBean mParamEntity;
private boolean mIsAllSelected = false;
private Menu mMenu;
private Toast successToast;
......@@ -67,7 +67,7 @@ public class LFilePickerActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
mParamEntity = (LFileParamEntity) getIntent().getExtras().getSerializable("param");
mParamEntity = (LFileParamBean) getIntent().getExtras().getSerializable("param");
setTheme(mParamEntity.getTheme());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lfile_picker);
......
......@@ -4,11 +4,17 @@ 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;
/**
......@@ -21,14 +27,15 @@ import java.util.Map;
*/
public class ChannelManageKit {
private static Map<String, String> channelMap;
private static final long CHANNEL_OFFICIAL_ID = -1;
private static final String CHANNEL_OFFICIAL_NAME = "通用";
private static Map<String, ChannelInfoBean> channelMap;
private static final String CHANNEL_OFFICIAL_ACCOUNT = "-1";
private static final String CHANNEL_OFFICIAL_CHANNELNAME = "通用";
/**
* 初始化本地渠道数据
*/
public static void initChannelRes(Context context) {
clearChannelResData();
if (null == context) {
initDefaultChannelRes();
return;
......@@ -39,12 +46,32 @@ public class ChannelManageKit {
initDefaultChannelRes();
return;
}
// GsonUtils.fromJson(assetsJson);
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();
return;
}
for (int j = 0; j < channelAccountArray.size(); i++) {
String account = channelAccountArray.get(j);
channelMap.put(account,channelInfoBean);
}
}
}
}
private static void initDefaultChannelRes() {
channelMap = new HashMap<>();
ChannelInfoBean commonChannel = new ChannelInfoBean();
commonChannel.setChannelId("-1");
commonChannel.setChannelName(CHANNEL_OFFICIAL_CHANNELNAME);
commonChannel.setChannelNameEn(CHANNEL_OFFICIAL_CHANNELNAME);
channelMap.put(CHANNEL_OFFICIAL_ACCOUNT,commonChannel);
}
/**
......@@ -55,30 +82,29 @@ public class ChannelManageKit {
initChannelRes(context);
}
String channelName = channelMap.get(AccountService.INSTANCE.getUserName());
if (TextUtils.isEmpty(channelName)) {
return CHANNEL_OFFICIAL_NAME;
boolean containsKey = channelMap.containsKey(AccountService.INSTANCE.getUserName());
if (!containsKey) {
return CHANNEL_OFFICIAL_CHANNELNAME;
}
return channelName;
return channelMap.get(AccountService.INSTANCE.getUserName()).getChannelName();
}
/**
* 获取App渠道编号
*/
public static long getAppChannelId(Context context) {
public static String getAppChannelId(Context context) {
if (context == null) {
return CHANNEL_OFFICIAL_ID;
return CHANNEL_OFFICIAL_ACCOUNT;
}
if (channelMap == null || channelMap.isEmpty()) {
initChannelRes(context);
}
String channelCode = channelMap.get(getAppChannelName(context));
if (TextUtils.isEmpty(channelCode)) {
return CHANNEL_OFFICIAL_ID;
if (!channelMap.containsKey(AccountService.INSTANCE.getUserName())) {
return CHANNEL_OFFICIAL_ACCOUNT;
}
return Long.parseLong(channelCode);
return channelMap.get(AccountService.INSTANCE.getUserName()).getChannelId();
}
public static void clearChannelResData() {
......@@ -92,10 +118,6 @@ public class ChannelManageKit {
/**
* 读取json文件
*
* @param context
* @param fileName
* @return
*/
private static String getAssetsJson(Context context, String fileName) {
StringBuilder stringBuilder = new StringBuilder();
......
......@@ -6,7 +6,7 @@ import android.content.Intent
import android.os.Bundle
import androidx.annotation.StyleRes
import com.miya.fastcashier.R
import com.miya.fastcashier.bean.LFileParamEntity
import com.miya.fastcashier.bean.LFileParamBean
import com.miya.fastcashier.ui.LFilePickerActivity
/**
......@@ -277,7 +277,7 @@ class LFilePickerManageKit {
private val bundle: Bundle
private get() {
val paramEntity = LFileParamEntity()
val paramEntity = LFileParamBean()
paramEntity.title = mTitle
paramEntity.theme = theme
paramEntity.titleColor = mTitleColor
......
......@@ -7,7 +7,7 @@ import androidx.lifecycle.viewModelScope
import com.fastcashier.lib_common.function.account.SelfCashierAccountInfo
import com.fastcashier.lib_common.net.CommonCallback
import com.miya.fastcashier.R
import com.miya.fastcashier.bean.LoginFormState
import com.miya.fastcashier.bean.LoginFormStateBean
import com.miya.fastcashier.net.param.LoginParams
import com.miya.fastcashier.net.MiyaApiRequest
import kotlinx.coroutines.Dispatchers
......@@ -16,8 +16,8 @@ import kotlinx.coroutines.launch
class LoginViewModel : ViewModel() {
val loginLiveData: MutableLiveData<Result<SelfCashierAccountInfo>> = MutableLiveData()
val _loginForm = MutableLiveData<LoginFormState>()
val loginFormState: LiveData<LoginFormState> = _loginForm
val _loginForm = MutableLiveData<LoginFormStateBean>()
val loginFormState: LiveData<LoginFormStateBean> = _loginForm
fun login(userName: String, passWord: String) {
......@@ -43,11 +43,11 @@ class LoginViewModel : ViewModel() {
fun loginDataChanged(username: String, password: String) {
if (!isUserNameValid(username)) {
_loginForm.value = LoginFormState(usernameError = R.string.username_not_empty)
_loginForm.value = LoginFormStateBean(usernameError = R.string.username_not_empty)
} else if (!isPasswordValid(password)) {
_loginForm.value = LoginFormState(passwordError = R.string.password_not_empty)
_loginForm.value = LoginFormStateBean(passwordError = R.string.password_not_empty)
} else {
_loginForm.value = LoginFormState(isDataValid = true)
_loginForm.value = LoginFormStateBean(isDataValid = true)
}
}
......
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