Search in sources :

Example 1 with FetchWeather

use of com.a5corp.weather.internet.FetchWeather in project Weather by Sparker0i.

the class WeatherFragment method updateWeatherData.

private void updateWeatherData(final String city, final String lat, final String lon) {
    wt = new FetchWeather(getContext());
    new Thread() {

        public void run() {
            try {
                if (lat == null && lon == null) {
                    json = wt.execute(city).get();
                } else if (city == null) {
                    json = wt.execute(lat, lon).get();
                }
            } catch (InterruptedException iex) {
                Log.e("InterruptedException", "iex");
            } catch (ExecutionException eex) {
                Log.e("ExecutionException", "eex");
            }
            pd.dismiss();
            if (swipeView != null && swipeView.isRefreshing())
                swipeView.post(new Runnable() {

                    @Override
                    public void run() {
                        swipeView.setRefreshing(false);
                    }
                });
            if (json == null) {
                preferences.setCity(preferences.getLastCity());
                handler.post(new Runnable() {

                    public void run() {
                        Toast.makeText(getActivity(), getActivity().getString(R.string.place_not_found), Toast.LENGTH_LONG).show();
                        GlobalActivity.i = 1;
                        if (!preferences.getLaunched()) {
                            FirstStart();
                        } else {
                            cc = new CheckConnection(getContext());
                            if (!cc.isNetworkAvailable()) {
                                showNoInternet();
                            } else {
                                pd.dismiss();
                                showInputDialog();
                            }
                        }
                    }
                });
            } else {
                handler.post(new Runnable() {

                    public void run() {
                        preferences.setLaunched();
                        renderWeather(json);
                        Snackbar snackbar = Snackbar.make(rootView, "Loaded Weather Data", 500);
                        snackbar.show();
                        //function();
                        if (!preferences.getv3TargetShown())
                            showTargets();
                        pd.dismiss();
                        preferences.setLastCity(json.day.getName());
                        ((WeatherActivity) getActivity()).createShortcuts();
                    }
                });
            }
        }
    }.start();
}
Also used : FetchWeather(com.a5corp.weather.internet.FetchWeather) WeatherActivity(com.a5corp.weather.activity.WeatherActivity) ExecutionException(java.util.concurrent.ExecutionException) CheckConnection(com.a5corp.weather.internet.CheckConnection) Snackbar(android.support.design.widget.Snackbar)

Aggregations

Snackbar (android.support.design.widget.Snackbar)1 WeatherActivity (com.a5corp.weather.activity.WeatherActivity)1 CheckConnection (com.a5corp.weather.internet.CheckConnection)1 FetchWeather (com.a5corp.weather.internet.FetchWeather)1 ExecutionException (java.util.concurrent.ExecutionException)1