Skip to content

Commit b3adf2a

Browse files
authored
Merge pull request #160 from itsdrnoob/dev/2.3.1
Dev/2.3.1
2 parents 9a7f960 + f9c3614 commit b3adf2a

File tree

12 files changed

+300
-107
lines changed

12 files changed

+300
-107
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
All notable changes to Data Monitor will be documented in this file.
44

55

6+
## v2.3.1
7+
8+
Data Monitor v2.3.1 release <br>
9+
This is a hotfix release with certain changes and bug fixes.
10+
11+
- Fixed a crash caused by a NullPointerException while starting and stopping the DataMonitor service.
12+
- Fixed the invalid plan error when custom plan was not selected.
13+
- Fixed multiple issues with network speed notification.
14+
- Improved exception handling.
15+
- Fixed certain timezone issues when adding a data plan.
16+
- Other minor changes and improvements.
17+
18+
619
## v2.3.0
720

821
Data Monitor v2.3.0 release <br>

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
[![Version](https://shields.io/badge/version-v2.3.0-087AFF.svg)](https://github.com/itsdrnoob/DataMonitor/tree/dev/2.3.0)
1+
[![Version](https://shields.io/badge/version-v2.3.1-087AFF.svg)](https://github.com/itsdrnoob/DataMonitor/tree/dev/2.3.1)
22
[![Platform](https://shields.io/badge/platform-android-green.svg)](https://github.com/itsdrnoob/DataMonitor)
33
[![License](https://img.shields.io/badge/license-GPL3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html)
4-
[![Release](https://shields.io/badge/release-v2.3.0-blue.svg)](https://github.com/itsdrnoob/DataMonitor/releases)
4+
[![Release](https://shields.io/badge/release-v2.3.1-blue.svg)](https://github.com/itsdrnoob/DataMonitor/releases)
55
[![Chat](https://img.shields.io/badge/Telegram%20Chat-blue?logo=telegram)](https://t.me/datamonitor)
66
[![Downloads](https://img.shields.io/github/downloads/itsdrnoob/DataMonitor/total)](https://github.com/itsdrnoob/DataMonitor/releases)
77

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "com.drnoob.datamonitor"
1111
minSdkVersion 23
1212
targetSdkVersion 33
13-
versionCode 21
14-
versionName 'v2.3.0'
13+
versionCode 23
14+
versionName 'v2.3.1'
1515
resConfigs "en", "ar", "cs", "de", "es", "fr", "hi", "in", "it", "ko",
1616
"ml", "mr", "nb-rNO", "nl", "pl", "pt-rBR", "ro", "ru", "tr", "uk", "uz", "vi", "zh-rCN", "zh-rTW"
1717

app/src/main/java/com/drnoob/datamonitor/core/Values.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class Values {
3131
public static final String APP_DATA_USAGE_WARNING_CHANNEL_ID = "AppDataUsage.Warning";
3232
public static final String APP_DATA_USAGE_WARNING_CHANNEL_NAME = "App Data Usage Warning";
3333
public static final int NETWORK_SIGNAL_NOTIFICATION_ID = 0x010D;
34-
public static final String NETWORK_SIGNAL_CHANNEL_ID = "LiveNetwork.Notification";
34+
public static final String NETWORK_SIGNAL_CHANNEL_ID = "LiveNetwork.Notifications";
3535
public static final String NETWORK_SIGNAL_CHANNEL_NAME = "Network Speed Monitor";
3636
public static final String NETWORK_SIGNAL_NOTIFICATION_GROUP = "Network Speed Monitor";
3737
public static final int OTHER_NOTIFICATION_ID = 0x012C;
@@ -130,7 +130,7 @@ public class Values {
130130
public static final String SHOW_ADD_PLAN_BANNER = "show_add_plan_banner";
131131
public static final String LANGUAGE_SYSTEM_DEFAULT = "system";
132132
public static final String ALARM_PERMISSION_DENIED = "alarm_permission_denied";
133-
public static final String UPDATE_NOTIFICATION_CHANNEL = "update_notification_channel";
133+
public static final String UPDATE_NOTIFICATION_CHANNEL = "update_notification_channel.v2";
134134
public static final String SHOULD_SHOW_BATTERY_OPTIMISATION_ERROR = "show_battery_optimisation_error";
135135

136136
public static final String DARK_MODE_TOGGLE = "dark_mode_toggle";

app/src/main/java/com/drnoob/datamonitor/ui/activities/MainActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ private void createNotificationChannel() {
501501
AudioAttributes attributes = new AudioAttributes.Builder()
502502
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
503503
.build();
504-
networkSignalChannel.setSound(sound, attributes);
505-
// networkSignalChannel.setSound(null, null);
504+
// networkSignalChannel.setSound(sound, attributes);
505+
networkSignalChannel.setSound(Uri.EMPTY, null);
506506
networkSignalChannel.setShowBadge(false);
507507
networkSignalChannel.enableVibration(false);
508508
networkSignalChannel.enableLights(false);

app/src/main/java/com/drnoob/datamonitor/ui/fragments/AppDataUsageFragment.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,14 +626,14 @@ private static String getTotalDataUsage(Context context) throws ParseException,
626626
int type = getType();
627627
if (type == TYPE_MOBILE_DATA) {
628628
totalUsage = NetworkStatsHelper.formatData(
629-
NetworkStatsHelper.getDeviceMobileDataUsage(context, getSession(), date)[0],
630-
NetworkStatsHelper.getDeviceMobileDataUsage(context, getSession(), date)[1]
629+
NetworkStatsHelper.getTotalAppMobileDataUsage(context, getSession(), date)[0],
630+
NetworkStatsHelper.getTotalAppMobileDataUsage(context, getSession(), date)[1]
631631
)[2];
632632
}
633633
else if (type == TYPE_WIFI) {
634634
totalUsage = NetworkStatsHelper.formatData(
635-
NetworkStatsHelper.getDeviceWifiDataUsage(context, getSession())[0],
636-
NetworkStatsHelper.getDeviceWifiDataUsage(context, getSession())[1]
635+
NetworkStatsHelper.getTotalAppWifiDataUsage(context, getSession())[0],
636+
NetworkStatsHelper.getTotalAppWifiDataUsage(context, getSession())[1]
637637
)[2];
638638
}
639639
else {

app/src/main/java/com/drnoob/datamonitor/ui/fragments/DataPlanFragment.java

Lines changed: 75 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,14 @@
8484
import com.google.android.material.snackbar.Snackbar;
8585
import com.google.android.material.tabs.TabLayout;
8686

87+
import java.text.DateFormat;
8788
import java.text.ParseException;
8889
import java.text.SimpleDateFormat;
8990
import java.util.Calendar;
9091
import java.util.Date;
92+
import java.util.Locale;
9193
import java.util.Objects;
94+
import java.util.TimeZone;
9295

9396
public class DataPlanFragment extends Fragment {
9497
public static final String TAG = DataPlanFragment.class.getSimpleName();
@@ -101,6 +104,7 @@ public class DataPlanFragment extends Fragment {
101104
private Long planStartDateMillis, planEndDateMillis;
102105
private int startHour, startMinute, endHour, endMinute;
103106
private long startMillis, endMillis; // Absolute start and end time in millis
107+
private boolean is12HourView;
104108

105109
@Override
106110
public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -131,11 +135,16 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
131135
Calendar calendar = Calendar.getInstance();
132136
int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
133137

138+
Date date = new Date();
139+
String time = DateFormat.getTimeInstance(DateFormat.SHORT).format(date.getTime()).toLowerCase(Locale.ROOT);
140+
is12HourView = time.contains("am") || time.contains("pm") ||
141+
time.contains("a.m") || time.contains("p.m");
142+
134143
try {
135144
planStartDateMillis = PreferenceManager.getDefaultSharedPreferences(requireContext())
136-
.getLong(DATA_RESET_CUSTOM_DATE_START, MaterialDatePicker.todayInUtcMilliseconds());
145+
.getLong(DATA_RESET_CUSTOM_DATE_START, UTCToLocal(MaterialDatePicker.todayInUtcMilliseconds()));
137146
planEndDateMillis = PreferenceManager.getDefaultSharedPreferences(requireContext())
138-
.getLong(DATA_RESET_CUSTOM_DATE_END, MaterialDatePicker.todayInUtcMilliseconds());
147+
.getLong(DATA_RESET_CUSTOM_DATE_END, UTCToLocal(MaterialDatePicker.todayInUtcMilliseconds()));
139148
}
140149
catch (ClassCastException e) {
141150
int planStartIntValue = PreferenceManager.getDefaultSharedPreferences(requireContext())
@@ -165,16 +174,16 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
165174
String planStart = new SimpleDateFormat("dd/MM/yyyy").format(planStartDateMillis);
166175
String planEnd = new SimpleDateFormat("dd/MM/yyyy").format(planEndDateMillis);
167176
String startTime, endTime;
168-
startTime = getContext().getString(R.string.label_custom_start_time, getTime(startHour, startMinute));
169-
endTime = getContext().getString(R.string.label_custom_end_time, getTime(endHour, endMinute));
177+
startTime = getContext().getString(R.string.label_custom_start_time, getTime(startHour, startMinute, is12HourView));
178+
endTime = getContext().getString(R.string.label_custom_end_time, getTime(endHour, endMinute, is12HourView));
170179
String startDateToday = getContext().getString(R.string.label_custom_start_date, planStart);
171180
String endDateToday = getContext().getString(R.string.label_custom_end_date, planEnd);
172181

173182

174183
binding.customStartDate.setText(setBoldSpan(startDateToday, planStart));
175184
binding.customEndDate.setText(setBoldSpan(endDateToday, planEnd));
176-
binding.customStartTime.setText(setBoldSpan(startTime, getTime(startHour, startMinute)));
177-
binding.customEndTime.setText(setBoldSpan(endTime, getTime(endHour, endMinute)));
185+
binding.customStartTime.setText(setBoldSpan(startTime, getTime(startHour, startMinute, is12HourView)));
186+
binding.customEndTime.setText(setBoldSpan(endTime, getTime(endHour, endMinute, is12HourView)));
178187

179188
binding.customStartDate.setOnClickListener(new View.OnClickListener() {
180189
@Override
@@ -202,10 +211,14 @@ public void onClick(View v) {
202211
@Override
203212
public void onPositiveButtonClick(Object selection) {
204213
planStartDateMillis = Long.parseLong(selection.toString());
205-
Log.d(TAG, "onPositiveButtonClick: " + planStartDateMillis );
206-
Log.d(TAG, "onPositiveButtonClick: " + UTCToLocal(planStartDateMillis));
214+
Log.d(TAG, "onPositiveButtonClick: UTC: " + planStartDateMillis );
215+
Log.d(TAG, "onPositiveButtonClick: Local: " + UTCToLocal(planStartDateMillis));
207216
planStartDateMillis = UTCToLocal(planStartDateMillis);
208-
String date = new SimpleDateFormat("dd/MM/yyyy").format(planStartDateMillis);
217+
Log.d(TAG, "onPositiveButtonClick: UTC: " + localToUTC(planStartDateMillis));
218+
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
219+
dateFormat.setTimeZone(TimeZone.getDefault());
220+
String date = dateFormat.format(new Date(planStartDateMillis));
221+
209222
String startDateString = getContext().getString(R.string.label_custom_start_date, date);
210223
binding.customStartDate.setText(setBoldSpan(startDateString, date));
211224
}
@@ -240,7 +253,7 @@ public void onClick(View v) {
240253
@Override
241254
public void onPositiveButtonClick(Object selection) {
242255
planEndDateMillis = Long.parseLong(selection.toString());
243-
planEndDateMillis = UTCToLocal(planEndDateMillis) + 86399999; // 86,399,999 is added to change the time to 23:59:59
256+
planEndDateMillis = UTCToLocal(planEndDateMillis);
244257
String date = new SimpleDateFormat("dd/MM/yyyy").format(planEndDateMillis);
245258
String endDateString = getContext().getString(R.string.label_custom_end_date, date);
246259
binding.customEndDate.setText(setBoldSpan(endDateString, date));
@@ -371,8 +384,10 @@ public void onClick(View v) {
371384
e.printStackTrace();
372385
}
373386

374-
if (binding.dataReset.getCheckedRadioButtonId() == R.id.custom_reset &&
375-
startMillis > System.currentTimeMillis() || endMillis < System.currentTimeMillis()) {
387+
if ((binding.dataReset.getCheckedRadioButtonId() == R.id.custom_reset &&
388+
startMillis > System.currentTimeMillis()) ||
389+
(binding.dataReset.getCheckedRadioButtonId() == R.id.custom_reset &&
390+
endMillis < System.currentTimeMillis())) {
376391
Snackbar snackbar = Snackbar.make(binding.getRoot(),
377392
requireContext().getString(R.string.error_invalid_plan_duration),
378393
Snackbar.LENGTH_SHORT);
@@ -483,6 +498,8 @@ private void showTimePicker(int type) {
483498
(((LinearLayout) ((LinearLayout) timePicker.getChildAt(0)).getChildAt(0)).getChildAt(0)).setVerticalScrollBarEnabled(false);
484499
(((LinearLayout) ((LinearLayout) timePicker.getChildAt(0)).getChildAt(0)).getChildAt(2)).setVerticalScrollBarEnabled(false);
485500

501+
timePicker.setIs24HourView(!is12HourView);
502+
486503
if (type == TYPE_PLAN_START) {
487504
timePicker.setHour(startHour);
488505
timePicker.setMinute(startMinute);
@@ -523,7 +540,7 @@ public void onClick(View view) {
523540

524541
String time, timeText;
525542

526-
time = getTime(timePicker.getHour(), timePicker.getMinute());
543+
time = getTime(timePicker.getHour(), timePicker.getMinute(), is12HourView);
527544

528545
if (type == TYPE_PLAN_START) {
529546
timeText = getContext().getString(R.string.label_custom_start_time, time);
@@ -556,52 +573,68 @@ public void onShow(DialogInterface dialogInterface) {
556573
dialog.show();
557574
}
558575

559-
private String getTime(int hour, int minute) {
576+
private String getTime(int hour, int minute, boolean is12HourView) {
560577
String time;
561-
562578
int hourOfDay;
563-
564-
if (hour >= 12) {
565-
if (hour == 12) {
566-
hourOfDay = 12;
579+
if (!is12HourView) {
580+
String formattedHour, formattedMinute;
581+
if (hour < 10) {
582+
formattedHour = "0" + hour;
567583
}
568584
else {
569-
hourOfDay = (hour - 12);
585+
formattedHour = "" + hour;
570586
}
571587
if (minute < 10) {
572-
time = hourOfDay + ":0" + minute + " pm";
588+
formattedMinute = "0" + minute;
573589
}
574590
else {
575-
time = hourOfDay + ":" + minute + " pm";
591+
formattedMinute = "" + minute;
576592
}
593+
time = formattedHour + ":" + formattedMinute;
577594
}
578595
else {
579-
if (hour == 0) {
580-
hourOfDay = 12;
581-
}
582-
else if (hour < 10) {
583-
hourOfDay = hour;
596+
if (hour >= 12) {
597+
if (hour == 12) {
598+
hourOfDay = 12;
599+
}
600+
else {
601+
hourOfDay = (hour - 12);
602+
}
584603
if (minute < 10) {
585-
time = "0" + hourOfDay + ":0" + minute + " pm";
604+
time = hourOfDay + ":0" + minute + " pm";
586605
}
587606
else {
588-
time = "0" + hourOfDay + ":" + minute + " pm";
607+
time = hourOfDay + ":" + minute + " pm";
589608
}
590609
}
591610
else {
592-
hourOfDay = hour;
593-
}
594-
if (hourOfDay < 10) {
595-
time = "0" + hourOfDay + ":" + minute + " am";
596-
}
597-
else {
598-
time = hourOfDay + ":" + minute + " am";
599-
}
600-
if (minute < 10) {
601-
time = hourOfDay + ":0" + minute + " am";
602-
}
603-
else {
604-
time = hourOfDay + ":" + minute + " am";
611+
if (hour == 0) {
612+
hourOfDay = 12;
613+
}
614+
else if (hour < 10) {
615+
hourOfDay = hour;
616+
if (minute < 10) {
617+
time = "0" + hourOfDay + ":0" + minute + " pm";
618+
}
619+
else {
620+
time = "0" + hourOfDay + ":" + minute + " pm";
621+
}
622+
}
623+
else {
624+
hourOfDay = hour;
625+
}
626+
if (hourOfDay < 10) {
627+
time = "0" + hourOfDay + ":" + minute + " am";
628+
}
629+
else {
630+
time = hourOfDay + ":" + minute + " am";
631+
}
632+
if (minute < 10) {
633+
time = hourOfDay + ":0" + minute + " am";
634+
}
635+
else {
636+
time = hourOfDay + ":" + minute + " am";
637+
}
605638
}
606639
}
607640
return time;

app/src/main/java/com/drnoob/datamonitor/utils/BootReceiver.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public class BootReceiver extends BroadcastReceiver {
3232
@Override
3333
public void onReceive(Context context, Intent intent) {
3434
Log.d(TAG, "onReceive: Boot complete");
35-
Common.refreshService(context);
35+
try {
36+
Common.refreshService(context);
37+
}
38+
catch (Exception e) {
39+
e.printStackTrace();
40+
}
3641
}
3742
}

0 commit comments

Comments
 (0)