better notification layout
This commit is contained in:
parent
7e5d96f3f3
commit
7d9d70fba8
|
@ -1,14 +1,16 @@
|
|||
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.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
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.LoggerFactory;
|
||||
|
||||
|
@ -29,10 +31,11 @@ public class NotificationRecyclerViewAdapter extends RecyclerView.Adapter<Notifi
|
|||
|
||||
private List<Notification> notificationsList;
|
||||
|
||||
public NotificationRecyclerViewAdapter(List<Notification> notificationsList) {
|
||||
NotificationRecyclerViewAdapter(List<Notification> notificationsList) {
|
||||
this.notificationsList = notificationsList;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public NotificationsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||
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)
|
||||
holder.dismiss.setText(((NotificationWithAction) notification).buttonText);
|
||||
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.time.setText(DateUtil.timeString(notification.date));
|
||||
holder.text.setText(DateUtil.timeString(notification.date) + " " + notification.text);
|
||||
if (notification.level == Notification.URGENT)
|
||||
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationUrgent));
|
||||
else if (notification.level == Notification.NORMAL)
|
||||
|
@ -68,48 +70,42 @@ public class NotificationRecyclerViewAdapter extends RecyclerView.Adapter<Notifi
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
|
||||
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView);
|
||||
}
|
||||
|
||||
static class NotificationsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
CardView cv;
|
||||
TextView time;
|
||||
TextView text;
|
||||
Button dismiss;
|
||||
|
||||
NotificationsViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
cv = (CardView) itemView.findViewById(R.id.notification_cardview);
|
||||
time = (TextView) itemView.findViewById(R.id.notification_time);
|
||||
text = (TextView) itemView.findViewById(R.id.notification_text);
|
||||
dismiss = (Button) itemView.findViewById(R.id.notification_dismiss);
|
||||
cv = itemView.findViewById(R.id.notification_cardview);
|
||||
text = itemView.findViewById(R.id.notification_text);
|
||||
dismiss = itemView.findViewById(R.id.notification_dismiss);
|
||||
dismiss.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Notification notification = (Notification) v.getTag();
|
||||
switch (v.getId()) {
|
||||
case R.id.notification_dismiss:
|
||||
MainApp.bus().post(new EventDismissNotification(notification.id));
|
||||
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))
|
||||
log.debug("Notification text is: " + notification.text);
|
||||
if (notification.text.equals(MainApp.gs(R.string.nsalarm_staledata))) {
|
||||
NotificationStore nstore = OverviewPlugin.getPlugin().notificationStore;
|
||||
long msToSnooze = SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L;
|
||||
if (L.isEnabled(L.NOTIFICATION))
|
||||
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();
|
||||
}
|
||||
break;
|
||||
MainApp.bus().post(new EventDismissNotification(notification.id));
|
||||
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))
|
||||
log.debug("Notification text is: " + notification.text);
|
||||
if (notification.text.equals(MainApp.gs(R.string.nsalarm_staledata))) {
|
||||
NotificationStore nstore = OverviewPlugin.getPlugin().notificationStore;
|
||||
long msToSnooze = SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L;
|
||||
if (L.isEnabled(L.NOTIFICATION))
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview.notifications;
|
||||
|
||||
import androidx.annotation.IntegerRes;
|
||||
|
||||
public class NotificationWithAction extends Notification {
|
||||
|
||||
Runnable action;
|
||||
String buttonText;
|
||||
int buttonText;
|
||||
|
||||
public NotificationWithAction(int id, String text, int level) {
|
||||
super(id, text, level);
|
||||
}
|
||||
|
||||
public void action(String buttonText, Runnable action) {
|
||||
public void action(int buttonText, Runnable action) {
|
||||
this.buttonText = buttonText;
|
||||
this.action = action;
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class AndroidPermission {
|
|||
if (SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)) {
|
||||
if (permissionNotGranted(activity, Manifest.permission.RECEIVE_SMS)) {
|
||||
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.RECEIVE_MMS}, AndroidPermission.CASE_SMS));
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
|
@ -91,7 +91,7 @@ public class AndroidPermission {
|
|||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
|
||||
if (permissionNotGranted(activity, Manifest.permission.READ_PHONE_STATE)) {
|
||||
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));
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
} else
|
||||
|
@ -103,7 +103,7 @@ public class AndroidPermission {
|
|||
public static synchronized void notifyForBatteryOptimizationPermission(Activity activity) {
|
||||
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);
|
||||
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));
|
||||
} else
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_BATTERY));
|
||||
|
@ -112,7 +112,7 @@ public class AndroidPermission {
|
|||
public static synchronized void notifyForStoragePermission(Activity activity) {
|
||||
if (permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
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));
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
} else
|
||||
|
@ -122,7 +122,7 @@ public class AndroidPermission {
|
|||
public static synchronized void notifyForLocationPermissions(Activity activity) {
|
||||
if (permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
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));
|
||||
} else
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_LOCATION));
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/notification_cardview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -9,31 +10,31 @@
|
|||
card_view:cardBackgroundColor="@color/cardColorBackground"
|
||||
card_view:cardCornerRadius="6dp">
|
||||
|
||||
<LinearLayout
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<Button
|
||||
android:id="@+id/notification_dismiss"
|
||||
android:layout_width="wrap_content"
|
||||
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
|
||||
android:id="@+id/notification_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Notification text" />
|
||||
android:layout_marginStart="5dp"
|
||||
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
|
||||
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.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
|
|
@ -1604,6 +1604,7 @@
|
|||
<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="loading">Loading ...</string>
|
||||
<string name="snooze">Snooze</string>
|
||||
|
||||
<plurals name="objective_days">
|
||||
<item quantity="one">%1$d day</item>
|
||||
|
|
Loading…
Reference in a new issue