增加了配置信息为单例模式

This commit is contained in:
董宏宇
2021-02-04 11:20:08 +08:00
parent aaf294e1e9
commit 5ec2e4fe8e
7 changed files with 80 additions and 3 deletions

View File

@@ -18,6 +18,12 @@
</intent-filter>
</activity>
<activity
android:name=".ConfigInfoActivity"
android:label="配置信息">
</activity>
<activity
android:name=".PassPortActivity"
android:label="鉴权测试">

View File

@@ -0,0 +1,26 @@
package com.mogo.cloud;
import android.os.Bundle;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
import com.mogo.utils.network.utils.GsonUtil;
/**
* 查看配置信息
*/
public class ConfigInfoActivity extends AppCompatActivity {
private TextView tvConfigInfo;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.actitity_config_info);
tvConfigInfo = findViewById(R.id.tvConfigInfo);
tvConfigInfo.setText(GsonUtil.jsonFromObject(MoGoAiCloudClientConfig.getInstance()));
}
}

View File

@@ -15,6 +15,7 @@ import com.mogo.cloud.passport.MoGoAiCloudClient;
public class MainActivity extends AppCompatActivity {
private Button btnJumpPassPort;
private Button btnJumpConfigInfo;
private Button btnJumpNetWorkPort;
private Button btnJumpRealTime;
private Button btnJumpRoadCondition;
@@ -57,6 +58,12 @@ public class MainActivity extends AppCompatActivity {
startActivity(intent);
});
btnJumpConfigInfo = findViewById(R.id.btnJumpConfigInfo);
btnJumpConfigInfo.setOnClickListener(v -> {
Intent intent = new Intent(MainActivity.this, ConfigInfoActivity.class);
startActivity(intent);
});
MoGoAiCloudClient.getInstance().addTokenCallbacks(new IMoGoTokenCallback() {
@Override
public void onTokenGot(String token, String sn) {

View File

@@ -35,7 +35,7 @@ public class MoGoApplication extends MultiDexApplication {
* BYDbydauto
*/
// 配置云服务API
MoGoAiCloudClientConfig clientConfig = new MoGoAiCloudClientConfig();
MoGoAiCloudClientConfig clientConfig = MoGoAiCloudClientConfig.getInstance();
// 设置网络环境HTTP_DNS_ENV_QA、HTTP_DNS_ENV_RELEASE、HTTP_DNS_ENV_DEV
clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_QA);
// 设置是否是第三APP登录
@@ -59,8 +59,7 @@ public class MoGoApplication extends MultiDexApplication {
});
// 初始化SDK可以设置状态回调来监听
MoGoAiCloudClient.getInstance().init(
this, clientConfig);
MoGoAiCloudClient.getInstance().init(this, clientConfig);
}
}

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvConfigInfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:lineHeight="30dp"
android:textColor="#000000"
android:textSize="20dp"
tools:text="测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -48,6 +48,12 @@
android:layout_height="match_parent"
android:text="刷新令牌" />
<Button
android:id="@+id/btnJumpConfigInfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="查看配置信息" />
<Button
android:id="@+id/btnJumpNetWorkPort"
android:layout_width="match_parent"

View File

@@ -12,6 +12,23 @@ import com.mogo.utils.logger.Logger;
public class MoGoAiCloudClientConfig {
private static final String TAG = "MoGoAiCloudClientConfig";
private static MoGoAiCloudClientConfig mMoGoAiCloudClientConfig;
private MoGoAiCloudClientConfig() {
}
public static MoGoAiCloudClientConfig getInstance() {
if (mMoGoAiCloudClientConfig == null) {
synchronized (MoGoAiCloudClientConfig.class) {
if (mMoGoAiCloudClientConfig == null) {
mMoGoAiCloudClientConfig = new MoGoAiCloudClientConfig();
}
}
}
return mMoGoAiCloudClientConfig;
}
/**
* 网络模式
*/