Browse Source

Merge branch 'hb-notification-mods' of https://github.com/lukeswitz/haven into lukeswitz-hb-notification-mods

n8fr8 9 months ago
parent
commit
938504b0f3

+ 1 - 1
src/main/java/org/havenapp/main/PreferenceManager.java

@@ -363,7 +363,7 @@ public class PreferenceManager {
363 363
         prefsEditor.commit();
364 364
     }
365 365
 
366
-    public String getHearbeatPrefix() {
366
+    public String getHeartbeatPrefix() {
367 367
         return context.getString(R.string.hearbeat_monitor_initial_message_1);
368 368
     }
369 369
 

+ 5 - 16
src/main/java/org/havenapp/main/service/SignalSender.java

@@ -40,7 +40,7 @@ public class SignalSender {
40 40
         mUsername = username;
41 41
         mAlertCount = 0;
42 42
         preferences = new PreferenceManager(mContext);
43
-        prefix = preferences.getHearbeatPrefix();
43
+        prefix = preferences.getHeartbeatPrefix();
44 44
         suffix = preferences.getHeartbeatSuffix();
45 45
         messageString = preferences.getHeartbeatMonitorMessage();
46 46
         interval = preferences.getHeartbeatNotificationTimeMs() / 60000;
@@ -128,28 +128,18 @@ public class SignalSender {
128 128
                 // Log.d("HEARTBEAT MONITOR," seconds remaining: " + millisUntilFinished / 1000);
129 129
             }
130 130
             public void onFinish() {
131
-                try {
132
-                    beatingHeart();
133
-                } catch(Throwable e) {
134
-                    e.printStackTrace();
135
-                }
131
+                beatingHeart();
136 132
                 start();
137 133
             }
138 134
         }.start();
139 135
     }
140 136
 
141 137
     private void beatingHeart () {
138
+
142 139
         int unicodeBeat = 0x1F493;
143 140
         String emojiString = new String(Character.toChars(unicodeBeat));
144 141
         messageString = preferences.getHeartbeatMonitorMessage();
145 142
 
146
-        /**
147
-         * Use compiler for optimized concatenation.
148
-         * Send an explanatory message first, then the unicode symbol.
149
-         * Ensure above message sent before updating count.
150
-         * Check for a custom message, send that instead.
151
-         **/
152
-
153 143
         if (mAlertCount < 1 )
154 144
             messageString = prefix + " " + interval + " " + suffix + "\n" + mContext.getString(R.string.battery_level_msg_text) + ": " + Utils.getBatteryPercentage(mContext) + "%";
155 145
         else if (messageString != null)
@@ -163,19 +153,18 @@ public class SignalSender {
163 153
     private void initHbMessage (String message)
164 154
     {
165 155
         if (!TextUtils.isEmpty(mUsername)) {
156
+            mAlertCount ++;
166 157
             getInstance(mContext, mUsername.trim());
167 158
             ArrayList<String> recipient = new ArrayList<>();
168 159
             recipient.add(preferences.getSmsNumber());
169 160
             sendMessage(recipient, message,null);
170 161
         } else if (!TextUtils.isEmpty(preferences.getSmsNumber())) {
162
+            mAlertCount ++;
171 163
             SmsManager manager = SmsManager.getDefault();
172 164
             StringTokenizer st = new StringTokenizer(preferences.getSmsNumber(),",");
173 165
             while (st.hasMoreTokens())
174 166
                 manager.sendTextMessage(st.nextToken(), null, message, null, null);
175 167
         }
176
-
177
-        mAlertCount ++; //moved outside of the send functions for now
178
-        Log.d("HEARTBEAT MONITOR", "Sent: " + message);
179 168
     }
180 169
 
181 170
     public void sendMessage (final ArrayList<String> recipients, final String message, final String attachment)