Skip to content

Commit

Permalink
Removing unused code. Reorganizing packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
vbresan committed Jun 27, 2023
1 parent 8bc7632 commit 1afd653
Show file tree
Hide file tree
Showing 27 changed files with 371 additions and 779 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 31
compileSdkVersion 32
buildToolsVersion "31.0.0"

compileOptions {
Expand All @@ -12,9 +12,9 @@ android {
defaultConfig {
applicationId "biz.binarysolutions.weatherusa"
minSdkVersion 21
targetSdkVersion 31
versionCode 24
versionName "3.0.1"
targetSdkVersion 32
versionCode 25
versionName "4.0"

setProperty("archivesBaseName", "$applicationId-$versionName")
}
Expand All @@ -39,5 +39,5 @@ android {

dependencies {
implementation 'com.github.bumptech.glide:glide:4.15.1'
gplayImplementation 'com.google.android.gms:play-services-ads:21.5.0'
gplayImplementation 'com.google.android.gms:play-services-ads:22.1.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import android.widget.RadioButton;
import android.widget.RadioGroup;

import biz.binarysolutions.weatherusa.components.preferences.Preferences;
import biz.binarysolutions.weatherusa.preferences.Preferences;
import biz.binarysolutions.weatherusa.util.DefaultTextWatcher;

/**
Expand Down Expand Up @@ -67,7 +67,7 @@ public void afterTextChanged(Editable editable) {
boolean isGPS = radioButtonGPS.isChecked();
String zip = editText.getText().toString();

Preferences.save(LocationActivity.this, isGPS, zip);
Preferences.saveLocationPreferences(LocationActivity.this, isGPS, zip);
finish();
});
}
Expand Down
222 changes: 78 additions & 144 deletions app/src/main/java/biz/binarysolutions/weatherusa/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,30 @@

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Date;

import biz.binarysolutions.weatherusa.components.forecast.ForecastHandler;
import biz.binarysolutions.weatherusa.components.location.LocationHandler;
import biz.binarysolutions.weatherusa.components.location.LocationHandlerListener;
import biz.binarysolutions.weatherusa.components.preferences.Preferences;
import biz.binarysolutions.weatherusa.dialog.DialogBuilder;
import biz.binarysolutions.weatherusa.dialog.DialogCode;
import biz.binarysolutions.weatherusa.util.location.LocationFormatter;
import biz.binarysolutions.weatherusa.forecast.ForecastHandler;
import biz.binarysolutions.weatherusa.location.LocationHandler;
import biz.binarysolutions.weatherusa.preferences.Preferences;
import biz.binarysolutions.weatherusa.util.WeatherLocation;

/**
* TODO: app is rejected from Samsung Store. Check their report
* received on support email address. Fix it.
*
*/
public class MainActivity
extends Activity
implements LocationHandlerListener {
public class MainActivity extends Activity {

private static final int ZIP_LENGTH = 5;
public static final int ZIP_LENGTH = 5;

private LocationHandler locationHandler;
private ForecastHandler forecastHandler;
Expand All @@ -52,10 +40,22 @@ private void updateLocationView(Location location) {
return;
}

TextView view = (TextView) findViewById(R.id.TextViewLocation);
view.setText(LocationFormatter.format(location));
TextView view = findViewById(R.id.TextViewLocation);
if (view != null) {
view.setText(new WeatherLocation(location).toString());
}
}

setForecastButtonEnabled(true);
/**
* @param zip
*
*/
private void updateLocationView(String zip) {

TextView view = findViewById(R.id.TextViewLocation);
if (view != null) {
view.setText(zip);
}
}

/**
Expand All @@ -69,15 +69,24 @@ private void updateForecastRequestView(Date date) {
}

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
TextView view = (TextView) findViewById(R.id.TextViewForecastRequest);
TextView view = findViewById(R.id.TextViewForecastRequest);
view.setText(sdf.format(date));
}

/**
*
*/
private void displayLastKnownLocation() {
updateLocationView(locationHandler.getLastKnownLocation());

boolean isGPS = Preferences.isGPS(this);
String zip = Preferences.getZIP(this);

if (isGPS) {
updateLocationView(locationHandler.getLastKnownLocation());
} else if (zip.length() == ZIP_LENGTH) {
updateLocationView(zip);
}

}

/**
Expand All @@ -97,69 +106,27 @@ private void displayLastKnownForecast() {
private void updateForecast() {

setForecastButtonEnabled(false);
Location location = locationHandler.getLastKnownLocation();
forecastHandler.updateForecast(location);
}

/**
*
*/
public void zipCodeEntry() {

final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog_zipcode);
dialog.setTitle(R.string.EnterZIPCode);

final EditText editText = dialog.findViewById(R.id.EditTextZIP);
final Button button = dialog.findViewById(R.id.ButtonZIPContinue);

button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

String zip = editText.getText().toString();
if (zip.length() == ZIP_LENGTH) {

dialog.dismiss();
setLocationButtonEnabled(false);
locationHandler.setLocationUsingZIP(zip);
}
}
});

dialog.show();
}
boolean isGPS = Preferences.isGPS(this);
String zip = Preferences.getZIP(this);

if (isGPS) {
Location location = locationHandler.getLastKnownLocation();
forecastHandler.updateForecast(location);
} else if (zip.length() == ZIP_LENGTH) {
forecastHandler.updateForecast(zip);
}
}

/**
*
*/
private void determineLocationDialog() {

DialogInterface.OnClickListener goToSettingsListener =
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
goToLocationSources();
}
};

DialogInterface.OnClickListener enterZIPCodeListener =
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
zipCodeEntry();
}
};

new AlertDialog.Builder(this)
.setMessage(R.string.LocationChoice)
.setView(R.layout.dialog_zipcode)
.setPositiveButton(R.string.UseGPS, goToSettingsListener)
.setNegativeButton(R.string.EnterZIPCode, enterZIPCodeListener)
.show();
.setPositiveButton(android.R.string.ok, null)
.show();
}

/**
Expand All @@ -174,6 +141,25 @@ private void showDialogForecastUnavailable() {
.setPositiveButton(android.R.string.ok, null)
.show();
}

/**
*
*/
private void refreshLocation() {

boolean isGPS = Preferences.isGPS(this);
String zip = Preferences.getZIP(this);

if (isGPS) {
if (locationHandler.hasProvider()) {
locationHandler.requestLocationUpdate();
} else {
determineLocationDialog();
}
} else if (zip.length() != ZIP_LENGTH) {
updateLocation();
}
}

/**
*
Expand All @@ -182,18 +168,6 @@ private void updateLocation() {

Intent intent = new Intent(this, LocationActivity.class);
startActivity(intent);

//TODO: fix this
//TODO: on location change refresh forecast
//determineLocationDialog();

/*
if (locationHandler.hasProvider()) {
locationHandler.requestLocationUpdate();
} else {
determineLocationDialog();
}
*/
}

/**
Expand Down Expand Up @@ -254,75 +228,40 @@ private void setButtonListeners() {
);
}
}

/**
*
*/
private void setLocationHandler() {

locationHandler = new LocationHandler(
(LocationManager) getSystemService(Context.LOCATION_SERVICE),
this
);
}

/**
*
*/
private void setForecastHandler() {
forecastHandler = new ForecastHandler(this);
}

/**
*
*/
private void goToLocationSources() {
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

setLocationHandler();
setForecastHandler();

Preferences.load(getPreferences(MODE_PRIVATE), locationHandler);
locationHandler = new LocationHandler(this);
forecastHandler = new ForecastHandler(this);

displayLastKnownLocation();
displayLastKnownForecast();
setButtonListeners();

AdHandler.initialize(this);

//TODO: uncomment this
//updateLocation();
updateForecast();
}

@Override
public void onPause() {
//TODO: this is saving location only, refactor it!
Preferences.save(getPreferences(MODE_PRIVATE), locationHandler);
super.onPause();
}
protected void onResume() {
super.onResume();

@Override
protected Dialog onCreateDialog(int id) {

Dialog dialog = DialogBuilder.get(id, this);
if (dialog == null) {
dialog = super.onCreateDialog(id);
}

return dialog;
displayLastKnownLocation();
displayLastKnownForecast();

refreshLocation();
updateForecast();
}

@Override
/**
*
* @param location
*/
public void onLocationChanged(Location location) {

updateLocationView(location);
setLocationButtonEnabled(true);
updateForecast();
}

/**
Expand All @@ -341,9 +280,4 @@ public void onForecastUnavailable() {
setAlertVisible(true);
setForecastButtonEnabled(true);
}

@Override
public void onConnectionError() {
showDialog(DialogCode.WIRELESS_CONTROLS);
}
}

This file was deleted.

Loading

0 comments on commit 1afd653

Please sign in to comment.