Skip to content

Commit

Permalink
A collection of over-due crash fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HannahMitt committed Nov 21, 2015
1 parent c3a95e1 commit d62d2e2
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 47 deletions.
13 changes: 12 additions & 1 deletion app/src/main/java/com/morristaedt/mirror/MirrorApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@

import android.app.Application;

import com.crashlytics.android.Crashlytics;
import com.morristaedt.mirror.configuration.ConfigurationSettings;

import io.fabric.sdk.android.Fabric;

/**
* Created by HannahMitt on 8/22/15.
*/
public class MirrorApplication extends Application {

// Usage removed, but leaving around for possible future use
@Override
public void onCreate() {
super.onCreate();
if (!ConfigurationSettings.isDebugBuild()) {
Fabric.with(this, new Crashlytics());
}
}
}
11 changes: 7 additions & 4 deletions app/src/main/java/com/morristaedt/mirror/SetUpActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.CheckBox;
Expand All @@ -18,8 +19,6 @@
import android.widget.Toast;

import com.morristaedt.mirror.configuration.ConfigurationSettings;
import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric;

public class SetUpActivity extends Activity {

Expand Down Expand Up @@ -51,7 +50,6 @@ public class SetUpActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics());
setContentView(R.layout.activity_configuration);

mConfigSettings = new ConfigurationSettings(this);
Expand Down Expand Up @@ -113,7 +111,12 @@ private void setUpLocationMonitoring() {
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
String provider = mLocationManager.getBestProvider(criteria, true);
mLocation = mLocationManager.getLastKnownLocation(provider);

try {
mLocation = mLocationManager.getLastKnownLocation(provider);
} catch (IllegalArgumentException e) {
Log.e("SetUpActivity", "Location manager could not use provider", e);
}

if (mLocation == null) {
mLocationView.setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import android.database.Cursor;
import android.os.AsyncTask;
import android.provider.CalendarContract;
import android.text.TextUtils;
import android.util.Log;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;

/**
* Created by alex on 12/09/15.
Expand All @@ -34,7 +34,7 @@ protected void onPostExecute(Void aVoid) {

@Override
protected Void doInBackground(Void... params) {
Cursor cursor = null;
Cursor cursor;
ContentResolver contentResolver = context.getContentResolver();
final String[] colsToQuery = new String[]{
CalendarContract.EventsEntity.TITLE,
Expand All @@ -49,7 +49,7 @@ protected Void doInBackground(Void... params) {

SimpleDateFormat endFormat = new SimpleDateFormat("hh:mm:ss dd/MM/yy");
Calendar endOfDay = Calendar.getInstance();
Date endofDayDate = null;
Date endofDayDate;
try {
endofDayDate = endFormat.parse("23:59:59 " + dateString);
endOfDay.setTime(endofDayDate);
Expand All @@ -62,21 +62,23 @@ protected Void doInBackground(Void... params) {
"( dtstart >" + start + ") and (dtend <" + endOfDay.getTimeInMillis() + ")",
null, "dtstart ASC");

if (cursor.getCount() > 0) {
cursor.moveToFirst();
title = cursor.getString(0);
Calendar startTime = Calendar.getInstance();
startTime.setTimeInMillis(cursor.getLong(1));
Calendar endTime = Calendar.getInstance();
endTime.setTimeInMillis(cursor.getLong(2));
DateFormat formatter = SimpleDateFormat.getTimeInstance(DateFormat.SHORT);
details = formatter.format(startTime.getTime()) + " - " + formatter.format(endTime.getTime());
if (!cursor.getString(3).equals("")) {
details += " ~ " + cursor.getString(3);
if (cursor != null) {
if (cursor.getCount() > 0) {
cursor.moveToFirst();
title = cursor.getString(0);
Calendar startTime = Calendar.getInstance();
startTime.setTimeInMillis(cursor.getLong(1));
Calendar endTime = Calendar.getInstance();
endTime.setTimeInMillis(cursor.getLong(2));
DateFormat formatter = SimpleDateFormat.getTimeInstance(DateFormat.SHORT);
details = formatter.format(startTime.getTime()) + " - " + formatter.format(endTime.getTime());
if (!TextUtils.isEmpty(cursor.getString(3))) {
details += " ~ " + cursor.getString(3);
}
}
}

cursor.close();
cursor.close();
}
return null;
}
}.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected ForecastResponse doInBackground(Void... params) {
try {
return service.getHourlyForecast(resources.getString(R.string.dark_sky_api_key), lat, lon, excludes, units);
} catch (RetrofitError error) {
Log.w("mirror", "Forecast error: " + error.getMessage());
Log.w("ForecastModule", "Forecast error: " + error.getMessage());
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ protected String doInBackground(Void... params) {
} catch (RSSReaderException e) {
Log.e("NewsModule", "Error parsing RSS");
return null;
} catch (Exception e) {
// not great to catch general exceptions, but this lib is being sketchy
Log.e("NewsModule", "Error parsing RSS");
return null;
}
}
}.execute();
Expand Down
30 changes: 15 additions & 15 deletions app/src/main/java/com/morristaedt/mirror/modules/XKCDModule.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.morristaedt.mirror.modules;

import android.os.AsyncTask;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;

Expand All @@ -9,7 +10,6 @@

import java.util.Calendar;

import retrofit.ErrorHandler;
import retrofit.RestAdapter;
import retrofit.RetrofitError;

Expand All @@ -34,27 +34,27 @@ public static void getXKCDForToday(final XKCDListener listener) {
protected XKCDResponse doInBackground(Void... params) {
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("http://xkcd.com")
.setErrorHandler(new ErrorHandler() {
@Override
public Throwable handleError(RetrofitError cause) {
Log.w("mirror", "XKCD error: " + cause);
return null;
}
})
.build();

XKCDRequest service = restAdapter.create(XKCDRequest.class);
return service.getLatestXKCD();
try {
return service.getLatestXKCD();
} catch (RetrofitError e) {
Log.w("XKCDModule", "Error loading xkcd", e);
return null;
}
}

@Override
protected void onPostExecute(XKCDResponse xkcdResponse) {
Calendar today = Calendar.getInstance();
if (!TextUtils.isEmpty(xkcdResponse.img) && xkcdResponse.day == today.get(Calendar.DAY_OF_MONTH) && xkcdResponse.month == (today.get(Calendar.MONTH) + 1) && xkcdResponse.year == today.get(Calendar.YEAR)) {
listener.onNewXKCDToday(xkcdResponse.img);
} else {
listener.onNewXKCDToday(null);
protected void onPostExecute(@Nullable XKCDResponse xkcdResponse) {
if (xkcdResponse != null) {
Calendar today = Calendar.getInstance();
if (!TextUtils.isEmpty(xkcdResponse.img) && xkcdResponse.day == today.get(Calendar.DAY_OF_MONTH) && xkcdResponse.month == (today.get(Calendar.MONTH) + 1) && xkcdResponse.year == today.get(Calendar.YEAR)) {
listener.onNewXKCDToday(xkcdResponse.img);
return;
}
}
listener.onNewXKCDToday(null);
}
}.execute();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.morristaedt.mirror.modules;

import android.os.AsyncTask;
import android.support.annotation.Nullable;
import android.util.Log;

import com.morristaedt.mirror.requests.YahooFinanceRequest;
import com.morristaedt.mirror.requests.YahooStockResponse;

import java.math.BigDecimal;

import retrofit.ErrorHandler;
import retrofit.RestAdapter;
import retrofit.RetrofitError;

Expand All @@ -34,25 +34,23 @@ public static void getStockForToday(final String stockName, final StockListener
protected YahooStockResponse doInBackground(Void... params) {
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("http://query.yahooapis.com/v1/public")
.setErrorHandler(new ErrorHandler() {
@Override
public Throwable handleError(RetrofitError cause) {
Log.w("mirror", "Yahoo Finance error: " + cause);
return cause;
}
})
.build();

YahooFinanceRequest service = restAdapter.create(YahooFinanceRequest.class);

String query = "select * from yahoo.finance.quotes where symbol in (\"" + stockName + "\")";
String env = "http://datatables.org/alltables.env";
String format = "json";
return service.getStockData(query, env, format);
try {
return service.getStockData(query, env, format);
} catch (RetrofitError error) {
Log.w("YahooFinanceModule", "YahooFinance error: " + error.getMessage());
return null;
}
}

@Override
protected void onPostExecute(YahooStockResponse stockResponse) {
protected void onPostExecute(@Nullable YahooStockResponse stockResponse) {
if (stockResponse != null && stockResponse.getQuoteResponse() != null) {
YahooStockResponse.YahooQuoteResponse quoteResponse = stockResponse.getQuoteResponse();
if (quoteResponse.getPercentageChange().abs().compareTo(BigDecimal.valueOf(0.03)) >= 0) {
Expand Down

0 comments on commit d62d2e2

Please sign in to comment.