Search in sources :

Example 1 with Version

use of com.mnnyang.gzuclassschedule.data.bean.Version in project GzuClassSchedule by mnnyang.

the class VersionUpdate method checkUpdate.

public void checkUpdate(final HttpCallback<Version> callback) {
    OkHttpUtils.get().url(Url.URL_CHECK_UPDATE_APP).build().execute(new StringCallback() {

        @Override
        public void onError(Call call, Exception e, int id) {
            e.printStackTrace();
            callback.onFail(e.getMessage());
        }

        @Override
        public void onResponse(String response, int id) {
            try {
                Gson gson = new Gson();
                Version version = gson.fromJson(response, Version.class);
                callback.onSuccess(version);
            } catch (Exception e) {
                e.printStackTrace();
                callback.onFail("parse error");
            }
        }
    });
}
Also used : Call(okhttp3.Call) Version(com.mnnyang.gzuclassschedule.data.bean.Version) StringCallback(com.zhy.http.okhttp.callback.StringCallback) Gson(com.google.gson.Gson) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 2 with Version

use of com.mnnyang.gzuclassschedule.data.bean.Version in project GzuClassSchedule by mnnyang.

the class AboutPresenter method checkUpdate.

@Override
public void checkUpdate() {
    mView.showNotice(app.mContext.getString(R.string.checking_for_updates));
    final VersionUpdate versionUpdate = new VersionUpdate();
    versionUpdate.checkUpdate(new HttpCallback<Version>() {

        @Override
        public void onSuccess(Version version) {
            if (version == null) {
                LogUtil.e(this, "version object is null");
                return;
            }
            int localVersion = versionUpdate.getLocalVersion(app.mContext);
            LogUtil.d(this, String.valueOf(version.getCode()));
            if (version.getVersion() > localVersion) {
                mView.showUpdateVersionInfo(version);
            } else {
                mView.showNotice(app.mContext.getString(R.string.already_the_latest_version));
            }
        }

        @Override
        public void onFail(String errMsg) {
            LogUtil.e(this, errMsg);
            ToastUtils.show(app.mContext.getString(R.string.access_err));
        }
    });
}
Also used : Version(com.mnnyang.gzuclassschedule.data.bean.Version) VersionUpdate(com.mnnyang.gzuclassschedule.utils.VersionUpdate)

Aggregations

Version (com.mnnyang.gzuclassschedule.data.bean.Version)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Gson (com.google.gson.Gson)1 VersionUpdate (com.mnnyang.gzuclassschedule.utils.VersionUpdate)1 StringCallback (com.zhy.http.okhttp.callback.StringCallback)1 Call (okhttp3.Call)1