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

View file

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