|
@@ -41,28 +41,51 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
|
|
|
private Handler handler;
|
|
|
|
|
|
+ private boolean isDebug = false;
|
|
|
+
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.activity_main);
|
|
|
sp = getSharedPreferences("config", Context.MODE_PRIVATE);
|
|
|
+ //初始化试图
|
|
|
+ this.initView();
|
|
|
+ //初始化app参数
|
|
|
+ this.initApp();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void initView(){
|
|
|
etUrl = findViewById(R.id.et_url);
|
|
|
btnNext = findViewById(R.id.bt_next);
|
|
|
btnNext.setOnClickListener(this);
|
|
|
findViewById(R.id.bt_qrc).setOnClickListener(this);
|
|
|
etUrl.setText(sp.getString("url","http://ccvadmin.info666.com/ljshxyqy/"));
|
|
|
handler = new Handler(this);
|
|
|
- this.initApp();
|
|
|
+ if(isDebug){
|
|
|
+ findViewById(R.id.ll_welcome).setVisibility(View.GONE);
|
|
|
+ findViewById(R.id.et_url).setVisibility(View.VISIBLE);
|
|
|
+ findViewById(R.id.ll_mt).setVisibility(View.VISIBLE);
|
|
|
+ findViewById(R.id.bt_next).setVisibility(View.VISIBLE);
|
|
|
+ findViewById(R.id.bt_qrc).setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void initApp(){
|
|
|
new Thread(()->{
|
|
|
- String result = HttpUtil.get("http://api.info666.com/api/api/v1/appConfig/getAppConfig");
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- JSONArray jsonArray = jsonObject.getJSONArray("data");
|
|
|
Message message = new Message();
|
|
|
- message.obj = jsonArray.getJSONObject(0).toJSONString();
|
|
|
- handler.sendMessage(message);
|
|
|
+ try {
|
|
|
+ String result = HttpUtil.get("http://api.info666.com/api/api/v1/appConfig/getAppConfig",10 * 1000);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("data");
|
|
|
+ message.what = 200;
|
|
|
+ message.obj = jsonArray.getJSONObject(0).toJSONString();
|
|
|
+ }catch (Exception e){
|
|
|
+ message.what = 500;
|
|
|
+ }finally {
|
|
|
+ handler.sendMessage(message);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}).start();
|
|
|
}
|
|
|
|
|
@@ -74,18 +97,25 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
if(null == url || url.length() == 0){
|
|
|
return;
|
|
|
}
|
|
|
- SharedPreferences.Editor editor = sp.edit();
|
|
|
- editor.putString("url",url);
|
|
|
- editor.commit();
|
|
|
- Intent intent = new Intent(this, InfraredRemoteActivity.class);
|
|
|
- startActivity(intent);
|
|
|
- MainActivity.this.finish();
|
|
|
+ this.goInfraredRemote(url);
|
|
|
} else if(v.getId() == R.id.bt_qrc){
|
|
|
Intent intent = new Intent(this, MyCaptureActivity.class);
|
|
|
startActivityForResult(intent,Activity.RESULT_FIRST_USER);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 打开红外页面
|
|
|
+ */
|
|
|
+ public void goInfraredRemote(String appUrl){
|
|
|
+ SharedPreferences.Editor editor = sp.edit();
|
|
|
+ editor.putString("url",appUrl);
|
|
|
+ editor.commit();
|
|
|
+ Intent intent = new Intent(this, InfraredRemoteActivity.class);
|
|
|
+ startActivity(intent);
|
|
|
+ MainActivity.this.finish();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
@@ -97,15 +127,30 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
|
|
|
@Override
|
|
|
public boolean handleMessage(@NonNull Message msg) {
|
|
|
- Log.d("handleMessage",msg.obj.toString());
|
|
|
+ Log.d("handleMessage",msg.obj + "");
|
|
|
try {
|
|
|
+ if(msg.what == 500){
|
|
|
+ new AlertDialog.Builder(this)
|
|
|
+ .setTitle(String.format("提示"))
|
|
|
+ .setMessage("网络连接异常,请重试")
|
|
|
+ .setPositiveButton("确定", (dialog, which) -> {
|
|
|
+ MainActivity.this.finish();
|
|
|
+ })
|
|
|
+ .setCancelable(false)
|
|
|
+ .create()
|
|
|
+ .show();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
JSONObject appData = JSON.parseObject(msg.obj.toString());
|
|
|
appData = JSON.parseObject(appData.getString("data"));
|
|
|
int appVersion = appData.getInteger("appVersion");
|
|
|
String downLoadUrl = appData.getString("downLoadUrl");
|
|
|
+ String appUrl = appData.getString("appUrl");
|
|
|
int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
|
|
|
if(appVersion > versionCode){
|
|
|
- this.updateApp(downLoadUrl);
|
|
|
+ this.updateApp(downLoadUrl,appUrl);
|
|
|
+ }else{
|
|
|
+ this.goInfraredRemote(appUrl);
|
|
|
}
|
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
|
throw new RuntimeException(e);
|
|
@@ -113,7 +158,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- public void updateApp(String downLoadUrl){
|
|
|
+ public void updateApp(final String downLoadUrl,final String appUrl){
|
|
|
new AlertDialog.Builder(this)
|
|
|
.setTitle(String.format("提示"))
|
|
|
.setMessage("有新版本需要更新")
|
|
@@ -122,8 +167,13 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
Intent it = new Intent(Intent.ACTION_VIEW,uri);
|
|
|
MainActivity.this.startActivity(it);
|
|
|
dialog.dismiss();
|
|
|
+ MainActivity.this.finish();
|
|
|
+ })
|
|
|
+ .setNegativeButton("暂不升级", (dialog, which) -> {
|
|
|
+ this.goInfraredRemote(appUrl);
|
|
|
+ dialog.dismiss();
|
|
|
})
|
|
|
- .setNegativeButton("暂不升级", (dialog, which) -> dialog.dismiss())
|
|
|
+ .setCancelable(false)
|
|
|
.create()
|
|
|
.show();
|
|
|
}
|