better notification layout
This commit is contained in:
parent
7e5d96f3f3
commit
7d9d70fba8
|
@ -1,14 +1,16 @@
|
||||||
package info.nightscout.androidaps.plugins.general.overview.notifications;
|
package info.nightscout.androidaps.plugins.general.overview.notifications;
|
||||||
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.cardview.widget.CardView;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.cardview.widget.CardView;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -29,10 +31,11 @@ public class NotificationRecyclerViewAdapter extends RecyclerView.Adapter<Notifi
|
||||||
|
|
||||||
private List<Notification> notificationsList;
|
private List<Notification> notificationsList;
|
||||||
|
|
||||||
public NotificationRecyclerViewAdapter(List<Notification> notificationsList) {
|
NotificationRecyclerViewAdapter(List<Notification> notificationsList) {
|
||||||
this.notificationsList = notificationsList;
|
this.notificationsList = notificationsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public NotificationsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
public NotificationsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||||
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.overview_notification_item, viewGroup, false);
|
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.overview_notification_item, viewGroup, false);
|
||||||
|
@ -46,10 +49,9 @@ public class NotificationRecyclerViewAdapter extends RecyclerView.Adapter<Notifi
|
||||||
if (notification instanceof NotificationWithAction)
|
if (notification instanceof NotificationWithAction)
|
||||||
holder.dismiss.setText(((NotificationWithAction) notification).buttonText);
|
holder.dismiss.setText(((NotificationWithAction) notification).buttonText);
|
||||||
else if (Objects.equals(notification.text, MainApp.gs(R.string.nsalarm_staledata)))
|
else if (Objects.equals(notification.text, MainApp.gs(R.string.nsalarm_staledata)))
|
||||||
holder.dismiss.setText("snooze");
|
holder.dismiss.setText(R.string.snooze);
|
||||||
|
|
||||||
holder.text.setText(notification.text + '\n');
|
holder.text.setText(DateUtil.timeString(notification.date) + " " + notification.text);
|
||||||
holder.time.setText(DateUtil.timeString(notification.date));
|
|
||||||
if (notification.level == Notification.URGENT)
|
if (notification.level == Notification.URGENT)
|
||||||
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationUrgent));
|
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationUrgent));
|
||||||
else if (notification.level == Notification.NORMAL)
|
else if (notification.level == Notification.NORMAL)
|
||||||
|
@ -68,48 +70,42 @@ public class NotificationRecyclerViewAdapter extends RecyclerView.Adapter<Notifi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
|
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||||
super.onAttachedToRecyclerView(recyclerView);
|
super.onAttachedToRecyclerView(recyclerView);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class NotificationsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
static class NotificationsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
CardView cv;
|
CardView cv;
|
||||||
TextView time;
|
|
||||||
TextView text;
|
TextView text;
|
||||||
Button dismiss;
|
Button dismiss;
|
||||||
|
|
||||||
NotificationsViewHolder(View itemView) {
|
NotificationsViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
cv = (CardView) itemView.findViewById(R.id.notification_cardview);
|
cv = itemView.findViewById(R.id.notification_cardview);
|
||||||
time = (TextView) itemView.findViewById(R.id.notification_time);
|
text = itemView.findViewById(R.id.notification_text);
|
||||||
text = (TextView) itemView.findViewById(R.id.notification_text);
|
dismiss = itemView.findViewById(R.id.notification_dismiss);
|
||||||
dismiss = (Button) itemView.findViewById(R.id.notification_dismiss);
|
|
||||||
dismiss.setOnClickListener(this);
|
dismiss.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Notification notification = (Notification) v.getTag();
|
Notification notification = (Notification) v.getTag();
|
||||||
switch (v.getId()) {
|
MainApp.bus().post(new EventDismissNotification(notification.id));
|
||||||
case R.id.notification_dismiss:
|
if (notification.nsAlarm != null) {
|
||||||
MainApp.bus().post(new EventDismissNotification(notification.id));
|
BroadcastAckAlarm.handleClearAlarm(notification.nsAlarm, MainApp.instance().getApplicationContext(), 60 * 60 * 1000L);
|
||||||
if (notification.nsAlarm != null) {
|
}
|
||||||
BroadcastAckAlarm.handleClearAlarm(notification.nsAlarm, MainApp.instance().getApplicationContext(), 60 * 60 * 1000L);
|
// Adding current time to snooze if we got staleData
|
||||||
}
|
if (L.isEnabled(L.NOTIFICATION))
|
||||||
// Adding current time to snooze if we got staleData
|
log.debug("Notification text is: " + notification.text);
|
||||||
if (L.isEnabled(L.NOTIFICATION))
|
if (notification.text.equals(MainApp.gs(R.string.nsalarm_staledata))) {
|
||||||
log.debug("Notification text is: " + notification.text);
|
NotificationStore nstore = OverviewPlugin.getPlugin().notificationStore;
|
||||||
if (notification.text.equals(MainApp.gs(R.string.nsalarm_staledata))) {
|
long msToSnooze = SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L;
|
||||||
NotificationStore nstore = OverviewPlugin.getPlugin().notificationStore;
|
if (L.isEnabled(L.NOTIFICATION))
|
||||||
long msToSnooze = SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L;
|
log.debug("snooze nsalarm_staledatavalue in minutes is " + SP.getInt("nsalarm_staledatavalue", 15) + "\n in ms is: " + msToSnooze + " currentTimeMillis is: " + System.currentTimeMillis());
|
||||||
if (L.isEnabled(L.NOTIFICATION))
|
nstore.snoozeTo(System.currentTimeMillis() + (SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L));
|
||||||
log.debug("snooze nsalarm_staledatavalue in minutes is " + SP.getInt("nsalarm_staledatavalue", 15) + "\n in ms is: " + msToSnooze + " currentTimeMillis is: " + System.currentTimeMillis());
|
}
|
||||||
nstore.snoozeTo(System.currentTimeMillis() + (SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L));
|
if (notification instanceof NotificationWithAction) {
|
||||||
}
|
((NotificationWithAction) notification).action.run();
|
||||||
if (notification instanceof NotificationWithAction) {
|
|
||||||
((NotificationWithAction) notification).action.run();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
package info.nightscout.androidaps.plugins.general.overview.notifications;
|
package info.nightscout.androidaps.plugins.general.overview.notifications;
|
||||||
|
|
||||||
|
import androidx.annotation.IntegerRes;
|
||||||
|
|
||||||
public class NotificationWithAction extends Notification {
|
public class NotificationWithAction extends Notification {
|
||||||
|
|
||||||
Runnable action;
|
Runnable action;
|
||||||
String buttonText;
|
int buttonText;
|
||||||
|
|
||||||
public NotificationWithAction(int id, String text, int level) {
|
public NotificationWithAction(int id, String text, int level) {
|
||||||
super(id, text, level);
|
super(id, text, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void action(String buttonText, Runnable action) {
|
public void action(int buttonText, Runnable action) {
|
||||||
this.buttonText = buttonText;
|
this.buttonText = buttonText;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class AndroidPermission {
|
||||||
if (SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)) {
|
if (SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)) {
|
||||||
if (permissionNotGranted(activity, Manifest.permission.RECEIVE_SMS)) {
|
if (permissionNotGranted(activity, Manifest.permission.RECEIVE_SMS)) {
|
||||||
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_SMS, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.URGENT);
|
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_SMS, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.URGENT);
|
||||||
notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.RECEIVE_SMS,
|
notification.action(R.string.request, () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.RECEIVE_SMS,
|
||||||
Manifest.permission.SEND_SMS,
|
Manifest.permission.SEND_SMS,
|
||||||
Manifest.permission.RECEIVE_MMS}, AndroidPermission.CASE_SMS));
|
Manifest.permission.RECEIVE_MMS}, AndroidPermission.CASE_SMS));
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
|
@ -91,7 +91,7 @@ public class AndroidPermission {
|
||||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
|
||||||
if (permissionNotGranted(activity, Manifest.permission.READ_PHONE_STATE)) {
|
if (permissionNotGranted(activity, Manifest.permission.READ_PHONE_STATE)) {
|
||||||
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_PHONESTATE, MainApp.gs(R.string.smscommunicator_missingphonestatepermission), Notification.URGENT);
|
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_PHONESTATE, MainApp.gs(R.string.smscommunicator_missingphonestatepermission), Notification.URGENT);
|
||||||
notification.action(MainApp.gs(R.string.request), () ->
|
notification.action(R.string.request, () ->
|
||||||
AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_PHONE_STATE}, AndroidPermission.CASE_PHONE_STATE));
|
AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_PHONE_STATE}, AndroidPermission.CASE_PHONE_STATE));
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
} else
|
} else
|
||||||
|
@ -103,7 +103,7 @@ public class AndroidPermission {
|
||||||
public static synchronized void notifyForBatteryOptimizationPermission(Activity activity) {
|
public static synchronized void notifyForBatteryOptimizationPermission(Activity activity) {
|
||||||
if (permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) {
|
if (permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) {
|
||||||
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_BATTERY, String.format(MainApp.gs(R.string.needwhitelisting), MainApp.gs(R.string.app_name)), Notification.URGENT);
|
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_BATTERY, String.format(MainApp.gs(R.string.needwhitelisting), MainApp.gs(R.string.app_name)), Notification.URGENT);
|
||||||
notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS}, AndroidPermission.CASE_BATTERY));
|
notification.action(R.string.request, () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS}, AndroidPermission.CASE_BATTERY));
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
} else
|
} else
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_BATTERY));
|
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_BATTERY));
|
||||||
|
@ -112,7 +112,7 @@ public class AndroidPermission {
|
||||||
public static synchronized void notifyForStoragePermission(Activity activity) {
|
public static synchronized void notifyForStoragePermission(Activity activity) {
|
||||||
if (permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
if (permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||||
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_STORAGE, MainApp.gs(R.string.needstoragepermission), Notification.URGENT);
|
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_STORAGE, MainApp.gs(R.string.needstoragepermission), Notification.URGENT);
|
||||||
notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
|
notification.action(R.string.request, () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE}, AndroidPermission.CASE_STORAGE));
|
Manifest.permission.WRITE_EXTERNAL_STORAGE}, AndroidPermission.CASE_STORAGE));
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
} else
|
} else
|
||||||
|
@ -122,7 +122,7 @@ public class AndroidPermission {
|
||||||
public static synchronized void notifyForLocationPermissions(Activity activity) {
|
public static synchronized void notifyForLocationPermissions(Activity activity) {
|
||||||
if (permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION)) {
|
if (permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||||
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_LOCATION, MainApp.gs(R.string.needlocationpermission), Notification.URGENT);
|
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_LOCATION, MainApp.gs(R.string.needlocationpermission), Notification.URGENT);
|
||||||
notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, AndroidPermission.CASE_LOCATION));
|
notification.action(R.string.request, () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, AndroidPermission.CASE_LOCATION));
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
} else
|
} else
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_LOCATION));
|
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_LOCATION));
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/notification_cardview"
|
android:id="@+id/notification_cardview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -9,31 +10,31 @@
|
||||||
card_view:cardBackgroundColor="@color/cardColorBackground"
|
card_view:cardBackgroundColor="@color/cardColorBackground"
|
||||||
card_view:cardCornerRadius="6dp">
|
card_view:cardCornerRadius="6dp">
|
||||||
|
|
||||||
<LinearLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent">
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/notification_dismiss"
|
android:id="@+id/notification_dismiss"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="35dp"
|
android:layout_height="35dp"
|
||||||
android:layout_weight="0.2"
|
android:text="@string/dismiss"
|
||||||
android:text="@string/dismiss" />
|
card_view:layout_constraintEnd_toEndOf="parent"
|
||||||
|
card_view:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/notification_text"
|
android:id="@+id/notification_text"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_marginStart="5dp"
|
||||||
android:text="Notification text" />
|
android:layout_marginTop="2dp"
|
||||||
|
android:layout_marginBottom="2dp"
|
||||||
|
android:maxLines="4"
|
||||||
|
android:text="Notification text. Notification text. Notification text. Notification text. Notification text. Notification text. "
|
||||||
|
card_view:layout_constraintEnd_toStartOf="@+id/notification_dismiss"
|
||||||
|
card_view:layout_constraintStart_toStartOf="parent"
|
||||||
|
card_view:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<TextView
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
android:id="@+id/notification_time"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="0.1"
|
|
||||||
android:text="Time" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
|
@ -1604,6 +1604,7 @@
|
||||||
<string name="partialboluswizard">Deliver this part of bolus wizard result [%]</string>
|
<string name="partialboluswizard">Deliver this part of bolus wizard result [%]</string>
|
||||||
<string name="deliverpartofboluswizard">Bolus wizard performs calculation but only this part of calculated insulin is delivered. Useful with SMB algorithm.</string>
|
<string name="deliverpartofboluswizard">Bolus wizard performs calculation but only this part of calculated insulin is delivered. Useful with SMB algorithm.</string>
|
||||||
<string name="loading">Loading ...</string>
|
<string name="loading">Loading ...</string>
|
||||||
|
<string name="snooze">Snooze</string>
|
||||||
|
|
||||||
<plurals name="objective_days">
|
<plurals name="objective_days">
|
||||||
<item quantity="one">%1$d day</item>
|
<item quantity="one">%1$d day</item>
|
||||||
|
|
Loading…
Reference in a new issue