use of com.a5corp.weather.internet.CheckConnection 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(context());
if (citys == null)
handler.postDelayed(new Runnable() {
@Override
public void run() {
fabProgressCircle.show();
}
}, 50);
new Thread() {
public void run() {
try {
if (lat == null && lon == null) {
json = wt.execute(citys != null ? citys : 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");
}
if (pd.isShowing())
pd.dismiss();
if (json == null) {
preferences.setCity(preferences.getLastCity());
handler.post(new Runnable() {
public void run() {
GlobalActivity.i = 1;
if (!preferences.getLaunched()) {
FirstStart();
} else {
if (citys == null)
fabProgressCircle.hide();
cc = new CheckConnection(context());
if (!cc.isNetworkAvailable()) {
showNoInternet();
} else {
if (pd.isShowing())
pd.dismiss();
showInputDialog();
}
}
}
});
} else {
handler.post(new Runnable() {
public void run() {
preferences.setLaunched();
renderWeather(json);
if (!preferences.getv3TargetShown())
showTargets();
if (pd.isShowing())
pd.dismiss();
if (citys == null) {
preferences.setLastCity(json.day.getName() + "," + json.day.getSys().getCountry());
((WeatherActivity) activity()).createShortcuts();
progress();
} else
preferences.setLastCity(preferences.getLastCity());
NotificationService.enqueueWork(context(), new Intent(context(), WeatherActivity.class));
}
});
}
}
}.start();
}
use of com.a5corp.weather.internet.CheckConnection in project Weather by Sparker0i.
the class FirstLaunchFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_first_launch, container, false);
preferences = new Prefs(getContext());
cityInput = rootView.findViewById(R.id.city_input);
textField = rootView.findViewById(R.id.materialTextField);
ImageView img = textField.findViewById(R.id.mtf_image);
img.setImageAlpha(R.drawable.logo);
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
permission = new Permissions(getContext());
requestPermissions(new String[] { android.Manifest.permission.ACCESS_COARSE_LOCATION }, Constants.READ_COARSE_LOCATION);
}
});
message = rootView.findViewById(R.id.intro_text);
if (GlobalActivity.i == 0) {
message.setText(getString(R.string.pick_city));
} else {
message.setText(getString(R.string.uh_oh));
}
Button goButton = rootView.findViewById(R.id.go_button);
goButton.setText(getString(android.R.string.ok));
goButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!new CheckConnection(getContext()).isNetworkAvailable()) {
Snackbar.make(rootView, getString(R.string.check_internet), Snackbar.LENGTH_SHORT).show();
} else if (cityInput.getText().length() > 0) {
launchActivity(0);
} else {
Snackbar.make(rootView, getString(R.string.enter_city_first), Snackbar.LENGTH_SHORT).show();
}
}
});
cityInput.setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
launchActivity(0);
return true;
}
return false;
}
});
return rootView;
}
use of com.a5corp.weather.internet.CheckConnection in project Weather by Sparker0i.
the class NotificationService method onHandleWork.
@Override
protected void onHandleWork(@NonNull Intent intent) {
CheckConnection checkNetwork = new CheckConnection(this);
if (!checkNetwork.isNetworkAvailable()) {
return;
}
Log.i("In", "Notification Service Alarm");
intent = NotificationService.newIntent(this);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
prefs = new Prefs(this);
long intervalMillis = Long.parseLong(prefs.getTime());
if (alarmManager != null)
if (new Prefs(this).getNotifs()) {
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), intervalMillis, pendingIntent);
} else {
alarmManager.cancel(pendingIntent);
pendingIntent.cancel();
}
String city = prefs.getCity();
String units = PreferenceManager.getDefaultSharedPreferences(this).getString(Constants.PREF_TEMPERATURE_UNITS, Constants.METRIC);
try {
WeatherInfo weather;
weather = new Request(this).getItems(city, units);
if (new Prefs(this).getNotifs())
weatherNotification(weather);
} catch (IOException e) {
Log.e(TAG, "Error get weather", e);
}
}
use of com.a5corp.weather.internet.CheckConnection in project Weather by Sparker0i.
the class WeatherFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0) {
cc = new CheckConnection(context());
if (!cc.isNetworkAvailable())
showNoInternet();
else {
pd.show();
updateWeatherData(preferences.getCity(), null, null);
}
}
}
Aggregations