Code dedup.

This commit is contained in:
Johannes Mockenhaupt 2018-03-23 23:02:18 +01:00
parent 3700ad9813
commit 8a7776fd74
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
2 changed files with 20 additions and 58 deletions

View file

@ -63,11 +63,7 @@ public class NSUpload {
bundle.putString("action", "dbAdd");
bundle.putString("collection", "treatments");
bundle.putString("data", data.toString());
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString());
broadcastCareportalEvent(context, data, bundle);
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
@ -99,11 +95,7 @@ public class NSUpload {
bundle.putString("action", "dbAdd");
bundle.putString("collection", "treatments");
bundle.putString("data", data.toString());
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString());
broadcastCareportalEvent(context, data, bundle);
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
@ -125,11 +117,7 @@ public class NSUpload {
bundle.putString("action", "dbAdd");
bundle.putString("collection", "treatments");
bundle.putString("data", data.toString());
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString());
broadcastCareportalEvent(context, data, bundle);
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
@ -153,11 +141,7 @@ public class NSUpload {
bundle.putString("action", "dbAdd");
bundle.putString("collection", "treatments");
bundle.putString("data", data.toString());
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString());
broadcastCareportalEvent(context, data, bundle);
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
@ -181,16 +165,20 @@ public class NSUpload {
bundle.putString("action", "dbAdd");
bundle.putString("collection", "treatments");
bundle.putString("data", data.toString());
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString());
broadcastCareportalEvent(context, data, bundle);
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
}
private static void broadcastCareportalEvent(Context context, JSONObject data, Bundle bundle) {
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString());
}
private static String getNextAvailableSecond(long time) {
long second = time - time % 1000;
if (second == lastUsedSecond) second += 1000;
@ -257,11 +245,7 @@ public class NSUpload {
bundle.putString("action", "dbAdd");
bundle.putString("collection", "devicestatus");
bundle.putString("data", deviceStatus.mongoRecord().toString());
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, deviceStatus.mongoRecord().toString());
broadcastCareportalEvent(context, deviceStatus.mongoRecord(), bundle);
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
@ -335,11 +319,7 @@ public class NSUpload {
bundle.putString("collection", "treatments");
bundle.putString("data", data.toString());
bundle.putString("_id", profileSwitch._id);
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString());
broadcastCareportalEvent(context, data, bundle);
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
@ -365,11 +345,7 @@ public class NSUpload {
bundle.putString("action", "dbAdd");
bundle.putString("collection", "treatments");
bundle.putString("data", data.toString());
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString());
broadcastCareportalEvent(context, data, bundle);
} catch (Exception e) {
log.error("Unhandled exception", e);
}
@ -425,11 +401,7 @@ public class NSUpload {
log.error("Unhandled exception", e);
}
bundle.putString("data", data.toString());
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString());
broadcastCareportalEvent(context, data, bundle);
}
public static void uploadBg(BgReading reading) {
@ -449,11 +421,7 @@ public class NSUpload {
log.error("Unhandled exception", e);
}
bundle.putString("data", data.toString());
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString());
broadcastCareportalEvent(context, data, bundle);
}
public static void uploadAppStart() {
@ -471,11 +439,7 @@ public class NSUpload {
log.error("Unhandled exception", e);
}
bundle.putString("data", data.toString());
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString());
broadcastCareportalEvent(context, data, bundle);
}
}

View file

@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -11,7 +9,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"