Search in sources :

Example 1 with Download

use of com.tonyodev.fetch2.Download in project kcanotify by antest1.

the class UpdateCheckActivity method getFetchListener.

private FetchListener getFetchListener(String url, String name, int version) {
    return new FetchListener() {

        @Override
        public void onDeleted(Download download) {
        }

        @Override
        public void onRemoved(Download download) {
        }

        @Override
        public void onResumed(Download download) {
        }

        @Override
        public void onPaused(Download download) {
        }

        @Override
        public void onProgress(Download download, long l, long l1) {
        }

        @Override
        public void onQueued(Download download, boolean b) {
        }

        @Override
        public void onCancelled(Download download) {
        }

        @Override
        public void onError(Download download) {
        }

        @Override
        public void onCompleted(@NotNull Download download) {
            File jsonFile = new File(download.getFile());
            new DataSaveTask(UpdateCheckActivity.this).execute(name, String.valueOf(version));
            if (name.equals("icon_info.json")) {
                Toast.makeText(getApplicationContext(), "Download Completed: " + name + "\nRetrieving Fairy Images..", Toast.LENGTH_LONG).show();
                final Handler handler1 = new Handler();
                handler1.postDelayed(() -> new KcaFairyDownloader().execute(), LOAD_DELAY);
            }
            int num_count = 0;
            for (int i = 0; i < resource_info.size(); i++) {
                JsonObject item = resource_info.get(i).getAsJsonObject();
                if (item.get("name").getAsString().equals(name)) {
                    int latest_res_v = item.get("version").getAsInt();
                    item.addProperty("version_str", getVersionString(version, latest_res_v));
                    item.addProperty("highlight", version < latest_res_v);
                    if (version < latest_res_v)
                        num_count += 1;
                }
            }
            resource_adapter.setListItem(resource_info);
            resource_adapter.notifyDataSetChanged();
            resource_downall.setVisibility(num_count > 0 ? View.VISIBLE : View.GONE);
            fetch.removeListener(this);
        }
    };
}
Also used : FetchListener(com.tonyodev.fetch2.FetchListener) Handler(android.os.Handler) JsonObject(com.google.gson.JsonObject) Download(com.tonyodev.fetch2.Download) NotNull(org.jetbrains.annotations.NotNull) File(java.io.File)

Aggregations

Handler (android.os.Handler)1 JsonObject (com.google.gson.JsonObject)1 Download (com.tonyodev.fetch2.Download)1 FetchListener (com.tonyodev.fetch2.FetchListener)1 File (java.io.File)1 NotNull (org.jetbrains.annotations.NotNull)1