Show a banner in the event of a service outage.

We will now determine if there has been a service outage and render a
banner at the top of the conversation list if we detect that there has
been one.
This commit is contained in:
Greyson Parrelli
2018-06-11 09:37:01 -07:00
parent 0999359454
commit 2c17b54ef9
19 changed files with 190 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.components.reminder;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View.OnClickListener;
public abstract class Reminder {
@@ -10,14 +11,14 @@ public abstract class Reminder {
private OnClickListener okListener;
private OnClickListener dismissListener;
public Reminder(@NonNull CharSequence title,
@NonNull CharSequence text)
public Reminder(@Nullable CharSequence title,
@NonNull CharSequence text)
{
this.title = title;
this.text = text;
this.title = title;
this.text = text;
}
public CharSequence getTitle() {
public @Nullable CharSequence getTitle() {
return title;
}
@@ -44,4 +45,13 @@ public abstract class Reminder {
public boolean isDismissable() {
return true;
}
public @NonNull Importance getImportance() {
return Importance.NORMAL;
}
public enum Importance {
NORMAL, ERROR
}
}

View File

@@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.components.reminder;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build.VERSION_CODES;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
@@ -49,8 +50,16 @@ public class ReminderView extends LinearLayout {
}
public void showReminder(final Reminder reminder) {
title.setText(reminder.getTitle());
if (!TextUtils.isEmpty(reminder.getTitle())) {
title.setText(reminder.getTitle());
title.setVisibility(VISIBLE);
} else {
title.setText("");
title.setVisibility(GONE);
}
text.setText(reminder.getText());
container.setBackgroundResource(reminder.getImportance() == Reminder.Importance.ERROR ? R.drawable.reminder_background_error
: R.drawable.reminder_background_normal);
setOnClickListener(reminder.getOkListener());

View File

@@ -0,0 +1,30 @@
package org.thoughtcrime.securesms.components.reminder;
import android.content.Context;
import android.support.annotation.NonNull;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
public class ServiceOutageReminder extends Reminder {
public ServiceOutageReminder(@NonNull Context context) {
super(null,
context.getString(R.string.reminder_header_service_outage_text));
}
public static boolean isEligible(@NonNull Context context) {
return TextSecurePreferences.getServiceOutage(context);
}
@Override
public boolean isDismissable() {
return false;
}
@NonNull
@Override
public Importance getImportance() {
return Importance.ERROR;
}
}