Android Open Source - NYU-BusTracker-Android Version Downloader Helper






From Project

Back to project page NYU-BusTracker-Android.

License

The source code is released under:

Apache License

If you think the Android project NYU-BusTracker-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nyubustracker.helpers;
//from w  w w.  j a  v  a 2 s .  c o  m
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.nyubustracker.activities.MainActivity;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

public class VersionDownloaderHelper implements DownloaderHelper {
    private static final String TIME_VERSION_PREF = "stopVersions";
    public static final String VERSION_JSON_FILE = "versionJson";

    @Override
    public void parse(JSONObject jsonObject) throws JSONException, IOException {

        BusManager sharedManager = BusManager.getBusManager();
        BusManager.parseVersion(jsonObject);
        Downloader.cache(VERSION_JSON_FILE, jsonObject);
        for (String timeURL : sharedManager.getTimesToDownload()) {
            SharedPreferences preferences = Downloader.getContext().getSharedPreferences(TIME_VERSION_PREF, Context.MODE_PRIVATE);
            String stopID = timeURL.substring(timeURL.lastIndexOf("/") + 1, timeURL.indexOf(".json"));
            if (MainActivity.LOCAL_LOGV) Log.v(MainActivity.REFACTOR_LOG_TAG, "Time to download: " + stopID);
            int newestStopTimeVersion = sharedManager.getTimesVersions().get(stopID);
            if (preferences.getInt(stopID, 0) != newestStopTimeVersion) {
                MainActivity.downloadsOnTheWire++;
                if (MainActivity.LOCAL_LOGV) Log.v(MainActivity.REFACTOR_LOG_TAG, "*   Actually downloading it!");
                new Downloader(new TimeDownloaderHelper(), Downloader.getContext()).execute(timeURL);
                preferences.edit().putInt(stopID, newestStopTimeVersion).apply();
            }
            else if (MainActivity.LOCAL_LOGV) Log.v(MainActivity.REFACTOR_LOG_TAG, "*   Not actually downloading it, because we already have the current version.");
        }
    }
}




Java Source Code List

com.nyubustracker.NYUBusTrackerApplication.java
com.nyubustracker.activities.MainActivity.java
com.nyubustracker.adapters.StopAdapter.java
com.nyubustracker.adapters.TimeAdapter.java
com.nyubustracker.helpers.BusDownloaderHelper.java
com.nyubustracker.helpers.BusManager.java
com.nyubustracker.helpers.DownloaderHelper.java
com.nyubustracker.helpers.Downloader.java
com.nyubustracker.helpers.MultipleOrientationSlidingDrawer.java
com.nyubustracker.helpers.RouteDownloaderHelper.java
com.nyubustracker.helpers.SegmentDownloaderHelper.java
com.nyubustracker.helpers.StopDownloaderHelper.java
com.nyubustracker.helpers.TimeDownloaderHelper.java
com.nyubustracker.helpers.VersionDownloaderHelper.java
com.nyubustracker.models.Bus.java
com.nyubustracker.models.Route.java
com.nyubustracker.models.Stop.java
com.nyubustracker.models.Time.java