增加 更新

idata
wanghao 7 months ago
parent ef9ad2c0a1
commit 55ed1c5cfb

@ -59,4 +59,14 @@ dependencies {
// https://mvnrepository.com/artifact/com.contrarywind/Android-PickerView
// implementation 'com.contrarywind:Android-PickerView:4.1.9'
implementation 'org.litepal.android:java:3.0.0'
implementation 'com.github.xuexiangjys:XUpdate:2.1.4'
implementation 'com.github.xuexiangjys.XUpdateAPI:xupdate-easy:1.0.1'
//
//
// implementation 'com.lzy.net:okhttputils:1.6.0' //使
// implementation 'com.lzy.net:okhttpserver:0.1.7' //
}

@ -5,7 +5,13 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" /> <!-- //震动权限 -->
<uses-permission android:name="android.permission.VIBRATE" /> <!-- //外部存储器权限 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<application
android:name=".base.MyApplication"
android:allowBackup="true"

@ -18,24 +18,31 @@ import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.uhf.api.cls.Reader;
import com.xuexiang.xupdate.XUpdate;
import com.xuexiang.xupdate.easy.EasyUpdate;
import java.util.List;
public class MainActivity extends BaseActivity {
private LoginVm loginVm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityMainBinding binding= DataBindingUtil.setContentView(this,R.layout.activity_main);
loginVm=new LoginVm();
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
loginVm = new LoginVm();
boolean isRemember = SharedPreferencesUtils.getboolean("isRemember", false);
if (isRemember){
loginVm.setName(SharedPreferencesUtils.getstring("user",""));
loginVm.setPass(SharedPreferencesUtils.getstring("pass",""));
if (isRemember) {
loginVm.setName(SharedPreferencesUtils.getstring("user", ""));
loginVm.setPass(SharedPreferencesUtils.getstring("pass", ""));
loginVm.setRemember(isRemember);
}
binding.setUser(loginVm);
EasyUpdate.checkUpdate(this,url + "/getVersion");
// XUpdate.newBuild(this)
// .updateUrl(url + "/getVersion")
// .promptIgnoreDownloadError(true)
// .update();
}
@Override
@ -43,39 +50,39 @@ public class MainActivity extends BaseActivity {
}
public void login_click(View view){
String pass = loginVm.getPass();
String name = loginVm.getName();
if (pass==null|| name==null||pass.isEmpty()||name.isEmpty()) return;
dialog.show();
OkGo.<String> get(url+"/login/finduser").tag(this)
.params("name", name)
.params("pass", pass)
.execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
dialog.dismiss();
String body = response.body();
if (body.equals("isEmpty")){
Toast.makeText(MainActivity.this, "暂无权限", Toast.LENGTH_SHORT).show();
} else if (body.equals("Error")) {
Toast.makeText(MainActivity.this, "用户名密码错误", Toast.LENGTH_SHORT).show();
}else {
boolean remember = loginVm.isRemember();
if (remember){
SharedPreferencesUtils.putboolean("isRemember",remember);
SharedPreferencesUtils.putstring("user",name);
SharedPreferencesUtils.putstring("pass",pass);
Intent intent=new Intent(MainActivity.this, HomePageActivity.class);
intent.putExtra("json",body);
intent.putExtra("user",name);
startActivity(intent);
finish();
}
}
}
});
}
public void login_click(View view) {
String pass = loginVm.getPass();
String name = loginVm.getName();
if (pass == null || name == null || pass.isEmpty() || name.isEmpty()) return;
dialog.show();
OkGo.<String>get(url + "/login/finduser").tag(this)
.params("name", name)
.params("pass", pass)
.execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
dialog.dismiss();
String body = response.body();
if (body.equals("isEmpty")) {
Toast.makeText(MainActivity.this, "暂无权限", Toast.LENGTH_SHORT).show();
} else if (body.equals("Error")) {
Toast.makeText(MainActivity.this, "用户名密码错误", Toast.LENGTH_SHORT).show();
} else {
boolean remember = loginVm.isRemember();
if (remember) {
SharedPreferencesUtils.putboolean("isRemember", remember);
SharedPreferencesUtils.putstring("user", name);
SharedPreferencesUtils.putstring("pass", pass);
Intent intent = new Intent(MainActivity.this, HomePageActivity.class);
intent.putExtra("json", body);
intent.putExtra("user", name);
startActivity(intent);
finish();
}
}
}
});
}
}

@ -1,5 +1,7 @@
package com.example.beijing_daxing.base;
import static com.xuexiang.xupdate.entity.UpdateError.ERROR.CHECK_NO_NEW_VERSION;
import android.app.Application;
import android.util.Log;
@ -13,6 +15,13 @@ import com.lzy.okgo.cookie.CookieJarImpl;
import com.lzy.okgo.cookie.store.MemoryCookieStore;
import com.lzy.okgo.https.HttpsUtils;
import com.lzy.okgo.interceptor.HttpLoggingInterceptor;
import com.xuexiang.xupdate.XUpdate;
import com.xuexiang.xupdate.easy.service.OkHttpUpdateHttpServiceImpl;
import com.xuexiang.xupdate.entity.UpdateError;
import com.xuexiang.xupdate.listener.OnUpdateFailureListener;
import com.xuexiang.xupdate.proxy.IUpdateHttpService;
import com.xuexiang.xupdate.utils.UpdateUtils;
import org.litepal.LitePal;
@ -39,6 +48,17 @@ public class MyApplication extends Application {
SharedPreferencesUtils.init(getApplicationContext(), "myapp");
okGoBase();
getUhfLongerManager();
XUpdate.get()
.debug(true)
.isWifiOnly(false) //默认设置只在wifi下检查版本更新
.isGet(true) //默认设置使用get请求检查版本
.isAutoMode(false) //默认设置非自动模式,可根据具体使用配置
// .param("versionCode", UpdateUtils.getVersionCode(this)) //设置默认公共请求参数
// .param("appKey", getPackageName())
.supportSilentInstall(false) //设置是否支持静默安装默认是true
.setIUpdateHttpService(new OkHttpUpdateHttpServiceImpl()) //这个必须设置!实现网络请求功能。
.init(this);
}
public static UHFRManager getUhfLongerManager() {

@ -34,6 +34,7 @@
android:layout_gravity="center"/>
<!-- </FrameLayout>-->
<TextView
android:layout_width="match_parent"
android:layout_height="45dp"

Loading…
Cancel
Save