Search in sources :

Example 1 with AnkiChinaSyncer

use of com.ichi2.libanki.sync.AnkiChinaSyncer in project AnkiChinaAndroid by ankichinateam.

the class AnkiActivity method syncChina.

// private final OKHttpUtil.MyCallBack checkRestServerSpaceListener = new OKHttpUtil.MyCallBack() {
// @Override
// public void onFailure(Call call, IOException e) {
// 
// }
// 
// 
// @Override
// public void onResponse(Call call, String token, Object arg1, Response response) throws IOException {
// //            Timber.i("http get result:%s,body:%s", response.toString() ,response.body()==null?"":response.body().string());
// if (response.isSuccessful()) {
// try {
// org.json.JSONObject result = (new org.json.JSONObject(response.body().string())).getJSONObject("data");
// Timber.i("fetch server space result:%s ", result.toString());
// long total = result.getLong("origin_size");
// long used = result.getLong("origin_used_size");
// String totalStr = result.getString("size");
// String usedStr = result.getString("used_size");
// String hint = String.format("%s/%s", usedStr, totalStr);
// long rest = total - used;
// Timber.i("fetch server space result:%d,%d,%d", total, used, rest);
// saveServerRestSpace(rest);
// if (rest <= 0) {
// showNoSpaceDialog();
// return;
// }
// //获取剩余空间
// runOnUiThread(() ->syncChina(token) );
// } catch (org.json.JSONException e) {
// e.printStackTrace();
// }
// }
// }
// };
protected void syncChina(String token) {
    if (getServerRestSpace() <= 0) {
        showNoSpaceDialog();
        return;
    }
    AnkiChinaSyncer syncer = new AnkiChinaSyncer(AnkiActivity.this, token, new AnkiChinaSyncer.OnSyncCallback() {

        @Override
        public void onError(int code, String message) {
            onSyncChinaError(code, message);
        }

        @Override
        public void onCompletedAll() {
            onSyncCompletedAll();
        }

        @Override
        public void onCompletedData() {
            onSyncCompletedData();
        }
    });
    syncer.sync();
    onSyncChinaStart();
}
Also used : AnkiChinaSyncer(com.ichi2.libanki.sync.AnkiChinaSyncer)

Aggregations

AnkiChinaSyncer (com.ichi2.libanki.sync.AnkiChinaSyncer)1