|
@@ -1,18 +1,37 @@
|
|
|
package com.info666.app.infraredRemote;
|
|
|
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
+import android.app.Activity;
|
|
|
+import android.app.AlertDialog;
|
|
|
import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.content.SharedPreferences;
|
|
|
+import android.content.pm.PackageManager;
|
|
|
+import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import android.util.Log;
|
|
|
import android.view.View;
|
|
|
import android.widget.Button;
|
|
|
import android.widget.EditText;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.info666.app.infraredRemote.activity.InfraredRemoteActivity;
|
|
|
+import com.info666.app.infraredRemote.activity.MyCaptureActivity;
|
|
|
+import com.king.zxing.CameraScan;
|
|
|
|
|
|
-public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
|
|
+
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+
|
|
|
+public class MainActivity extends AppCompatActivity implements View.OnClickListener, Handler.Callback {
|
|
|
|
|
|
private SharedPreferences sp;
|
|
|
|
|
@@ -20,6 +39,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
|
|
|
private Button btnNext;
|
|
|
|
|
|
+ private Handler handler;
|
|
|
+
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
@@ -28,7 +49,21 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
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();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }).start();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -44,7 +79,53 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
editor.commit();
|
|
|
Intent intent = new Intent(this, InfraredRemoteActivity.class);
|
|
|
startActivity(intent);
|
|
|
- super.finish();
|
|
|
+ MainActivity.this.finish();
|
|
|
+ } else if(v.getId() == R.id.bt_qrc){
|
|
|
+ Intent intent = new Intent(this, MyCaptureActivity.class);
|
|
|
+ startActivityForResult(intent,Activity.RESULT_FIRST_USER);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+ if (Activity.RESULT_OK == resultCode) {
|
|
|
+ String msg = data.getStringExtra(CameraScan.SCAN_RESULT);
|
|
|
+ Toast.makeText(this,msg, Toast.LENGTH_LONG).show();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean handleMessage(@NonNull Message msg) {
|
|
|
+ Log.d("handleMessage",msg.obj.toString());
|
|
|
+ try {
|
|
|
+ JSONObject appData = JSON.parseObject(msg.obj.toString());
|
|
|
+ appData = JSON.parseObject(appData.getString("data"));
|
|
|
+ int appVersion = appData.getInteger("appVersion");
|
|
|
+ String downLoadUrl = appData.getString("downLoadUrl");
|
|
|
+ int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
|
|
|
+ if(appVersion > versionCode){
|
|
|
+ this.updateApp(downLoadUrl);
|
|
|
+ }
|
|
|
+ } catch (PackageManager.NameNotFoundException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateApp(String downLoadUrl){
|
|
|
+ new AlertDialog.Builder(this)
|
|
|
+ .setTitle(String.format("提示"))
|
|
|
+ .setMessage("有新版本需要更新")
|
|
|
+ .setPositiveButton("升级", (dialog, which) -> {
|
|
|
+ Uri uri = Uri.parse(downLoadUrl);
|
|
|
+ Intent it = new Intent(Intent.ACTION_VIEW,uri);
|
|
|
+ MainActivity.this.startActivity(it);
|
|
|
+ dialog.dismiss();
|
|
|
+ })
|
|
|
+ .setNegativeButton("暂不升级", (dialog, which) -> dialog.dismiss())
|
|
|
+ .create()
|
|
|
+ .show();
|
|
|
+ }
|
|
|
+
|
|
|
}
|