Permalink
Browse files

[Mobile,Wear,Widget] General analytics and safety check improvements.

  • Loading branch information...
thecosmicfrog committed Apr 19, 2017
1 parent 865338f commit ca76d1206a5323d89baa245d951bb41244ccb4a2
@@ -48,6 +48,7 @@
import org.thecosmicfrog.luasataglance.object.NotifyTimesMap;
import org.thecosmicfrog.luasataglance.object.StopForecast;
import org.thecosmicfrog.luasataglance.object.StopNameIdMap;
import org.thecosmicfrog.luasataglance.util.Analytics;
import org.thecosmicfrog.luasataglance.util.Constant;
import org.thecosmicfrog.luasataglance.util.Preferences;
import org.thecosmicfrog.luasataglance.util.Settings;
@@ -755,7 +756,7 @@ public void autoReloadStopForecast(int delayTimeMillis) {
@Override
public void run() {
/* Check Fragment is attached to Activity to avoid NullPointerExceptions. */
if (isAdded()){
if (isAdded()) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
@@ -814,6 +815,12 @@ public void success(ApiTimes apiTimes, Response response) {
/* Stop the refresh animations. */
setIsLoading(false);
swipeRefreshLayout.setRefreshing(false);
} else {
Analytics.nullApitimes(
getContext(),
"null",
"null_apitimes_mobile"
);
}
}
}
@@ -827,26 +834,26 @@ public void failure(RetrofitError retrofitError) {
* the client request or the server's response itself.
*/
if (retrofitError.getMessage() != null) {
Log.e(LOG_TAG, retrofitError.getMessage());
Log.e(LOG_TAG, "Message: " + retrofitError.getMessage());
}
if (retrofitError.getResponse() != null) {
if (retrofitError.getResponse().getUrl() != null) {
Log.e(LOG_TAG, retrofitError.getResponse().getUrl());
Log.e(LOG_TAG, "Response: " + retrofitError.getResponse().getUrl());
}
Log.e(LOG_TAG, Integer.toString(retrofitError.getResponse().getStatus()));
Log.e(LOG_TAG, "Status: " + Integer.toString(retrofitError.getResponse().getStatus()));
if (retrofitError.getResponse().getHeaders() != null) {
Log.e(LOG_TAG, retrofitError.getResponse().getHeaders().toString());
Log.e(LOG_TAG, "Headers: " + retrofitError.getResponse().getHeaders().toString());
}
if (retrofitError.getResponse().getBody() != null) {
Log.e(LOG_TAG, retrofitError.getResponse().getBody().toString());
Log.e(LOG_TAG, "Body: " + retrofitError.getResponse().getBody().toString());
}
if (retrofitError.getResponse().getReason() != null) {
Log.e(LOG_TAG, retrofitError.getResponse().getReason());
Log.e(LOG_TAG, "Reason: " + retrofitError.getResponse().getReason());
}
}
@@ -855,8 +862,14 @@ public void failure(RetrofitError retrofitError) {
* going on by getting the "kind" of error.
*/
if (retrofitError.getKind() != null) {
Log.e(LOG_TAG, retrofitError.getKind().toString());
Log.e(LOG_TAG, "Kind: " + retrofitError.getKind().toString());
}
Analytics.httpError(
getContext(),
"http_error",
"http_error_general_mobile"
);
}
};
@@ -36,6 +36,7 @@
import org.thecosmicfrog.luasataglance.object.StopForecast;
import org.thecosmicfrog.luasataglance.object.StopNameIdMap;
import org.thecosmicfrog.luasataglance.object.Tram;
import org.thecosmicfrog.luasataglance.util.Analytics;
import org.thecosmicfrog.luasataglance.util.Constant;
import org.thecosmicfrog.luasataglance.util.Serializer;
@@ -138,15 +139,24 @@ private void fetchStopForecast(String stopName) {
Callback<ApiTimes> callback = new Callback<ApiTimes>() {
@Override
public void success(ApiTimes apiTimes, Response response) {
/* Then create a stop forecast with this data. */
final StopForecast stopForecast = createStopForecast(apiTimes);
new Thread(new Runnable() {
@Override
public void run() {
replyStopForecast(Constant.PATH_STOPFORECAST_FETCH_WEAR, stopForecast);
}
}).start();
/* If the server returned times. */
if (apiTimes != null) {
/* Then create a stop forecast with this data. */
final StopForecast stopForecast = createStopForecast(apiTimes);
new Thread(new Runnable() {
@Override
public void run() {
replyStopForecast(Constant.PATH_STOPFORECAST_FETCH_WEAR, stopForecast);
}
}).start();
} else {
Analytics.nullApitimes(
getApplicationContext(),
"null",
"null_apitimes_wear"
);
}
}
@Override
@@ -186,6 +196,12 @@ public void failure(RetrofitError retrofitError) {
*/
if (retrofitError.getKind() != null)
Log.e(LOG_TAG, retrofitError.getKind().toString());
Analytics.httpError(
getApplicationContext(),
"http_error",
"http_error_general_wear"
);
}
};
@@ -39,6 +39,7 @@
import org.thecosmicfrog.luasataglance.object.StopForecast;
import org.thecosmicfrog.luasataglance.object.StopNameIdMap;
import org.thecosmicfrog.luasataglance.object.Tram;
import org.thecosmicfrog.luasataglance.util.Analytics;
import org.thecosmicfrog.luasataglance.util.Constant;
import java.io.BufferedInputStream;
@@ -227,13 +228,22 @@ private void loadStopForecast(final Context context,final AppWidgetManager appWi
Callback<ApiTimes> callback = new Callback<ApiTimes>() {
@Override
public void success(ApiTimes apiTimes, Response response) {
/* Then create a stop forecast with this data. */
StopForecast stopForecast = createStopForecast(apiTimes);
/* Update the stop forecast. */
updateStopForecast(context, views, stopForecast);
appWidgetManager.partiallyUpdateAppWidget(widgetId, views);
/* If the server returned times. */
if (apiTimes != null) {
/* Then create a stop forecast with this data. */
StopForecast stopForecast = createStopForecast(apiTimes);
/* Update the stop forecast. */
updateStopForecast(context, views, stopForecast);
appWidgetManager.partiallyUpdateAppWidget(widgetId, views);
} else {
Analytics.nullApitimes(
getApplicationContext(),
"null",
"null_apitimes_widget"
);
}
/* Stop the refresh animations. */
setIsLoading(appWidgetManager, widgetId, views, false);
@@ -277,6 +287,12 @@ public void failure(RetrofitError retrofitError) {
*/
if (retrofitError.getKind() != null)
Log.e(LOG_TAG, retrofitError.getKind().toString());
Analytics.httpError(
getApplicationContext(),
"http_error",
"http_error_general_widget"
);
}
};
@@ -23,28 +23,82 @@
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import com.google.firebase.analytics.FirebaseAnalytics;
import org.thecosmicfrog.luasataglance.activity.LineFragment;
public final class Analytics {
private static final String EVENT_HTTP_ERROR = "http_error";
private static final String EVENT_NULL_APITIMES = "null_apitimes";
private static final String LOG_TAG = Analytics.class.getSimpleName();
private static FirebaseAnalytics firebaseAnalytics;
public static void httpError(Context context, String contentType, String itemId) {
try {
firebaseAnalytics = FirebaseAnalytics.getInstance(context);
} catch (Exception e) {
Log.e(LOG_TAG, "Error gathering analytics for " + itemId + ".");
Log.e(LOG_TAG, Log.getStackTraceString(e));
}
if (firebaseAnalytics != null) {
Bundle params = new Bundle();
params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, contentType);
params.putString(FirebaseAnalytics.Param.ITEM_ID, itemId);
firebaseAnalytics.logEvent(EVENT_HTTP_ERROR, params);
}
}
public static void nullApitimes(Context context, String contentType, String itemId) {
try {
firebaseAnalytics = FirebaseAnalytics.getInstance(context);
} catch (Exception e) {
Log.e(LOG_TAG, "Error gathering analytics for " + itemId + ".");
Log.e(LOG_TAG, Log.getStackTraceString(e));
}
if (firebaseAnalytics != null) {
Bundle params = new Bundle();
params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, contentType);
params.putString(FirebaseAnalytics.Param.ITEM_ID, itemId);
firebaseAnalytics.logEvent(EVENT_NULL_APITIMES, params);
}
}
public static void selectContent(Context context, String contentType, String itemId) {
firebaseAnalytics = FirebaseAnalytics.getInstance(context);
try {
firebaseAnalytics = FirebaseAnalytics.getInstance(context);
} catch (Exception e) {
Log.e(LOG_TAG, "Error gathering analytics for " + itemId + ".");
Log.e(LOG_TAG, Log.getStackTraceString(e));
}
Bundle params = new Bundle();
params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, contentType);
params.putString(FirebaseAnalytics.Param.ITEM_ID, itemId);
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, params);
if (firebaseAnalytics != null) {
Bundle params = new Bundle();
params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, contentType);
params.putString(FirebaseAnalytics.Param.ITEM_ID, itemId);
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, params);
}
}
public static void tutorialBegin(Context context, String contentType, String itemId) {
firebaseAnalytics = FirebaseAnalytics.getInstance(context);
try {
firebaseAnalytics = FirebaseAnalytics.getInstance(context);
} catch (Exception e) {
Log.e(LOG_TAG, "Error gathering analytics for " + itemId + ".");
Log.e(LOG_TAG, Log.getStackTraceString(e));
}
Bundle params = new Bundle();
params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, contentType);
params.putString(FirebaseAnalytics.Param.ITEM_ID, itemId);
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.TUTORIAL_BEGIN, params);
if (firebaseAnalytics != null) {
Bundle params = new Bundle();
params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, contentType);
params.putString(FirebaseAnalytics.Param.ITEM_ID, itemId);
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.TUTORIAL_BEGIN, params);
}
}
}

0 comments on commit ca76d12

Please sign in to comment.