2015-10-13 21:44:01 -07:00
|
|
|
package org.thoughtcrime.securesms.components.reminder;
|
2014-08-04 13:13:47 -07:00
|
|
|
|
|
|
|
import android.annotation.TargetApi;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.os.Build.VERSION_CODES;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.R;
|
2015-10-13 21:44:01 -07:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
2014-08-04 13:13:47 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* View to display actionable reminders to the user
|
|
|
|
*/
|
|
|
|
public class ReminderView extends LinearLayout {
|
|
|
|
private ViewGroup container;
|
2015-10-13 21:44:01 -07:00
|
|
|
private TextView acceptButton;
|
|
|
|
private TextView closeButton;
|
2014-08-04 13:13:47 -07:00
|
|
|
private TextView title;
|
|
|
|
private TextView text;
|
|
|
|
|
|
|
|
public ReminderView(Context context) {
|
|
|
|
super(context);
|
|
|
|
initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
public ReminderView(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
@TargetApi(VERSION_CODES.HONEYCOMB)
|
|
|
|
public ReminderView(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initialize() {
|
|
|
|
LayoutInflater.from(getContext()).inflate(R.layout.reminder_header, this, true);
|
2015-10-13 21:44:01 -07:00
|
|
|
container = ViewUtil.findById(this, R.id.container);
|
|
|
|
acceptButton = ViewUtil.findById(this, R.id.accept);
|
|
|
|
closeButton = ViewUtil.findById(this, R.id.cancel);
|
|
|
|
title = ViewUtil.findById(this, R.id.reminder_title);
|
|
|
|
text = ViewUtil.findById(this, R.id.reminder_text);
|
2014-08-04 13:13:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void showReminder(final Reminder reminder) {
|
2015-10-13 21:44:01 -07:00
|
|
|
title.setText(reminder.getTitle());
|
|
|
|
text.setText(reminder.getText());
|
|
|
|
acceptButton.setText(reminder.getButtonText());
|
2015-01-11 20:27:34 -08:00
|
|
|
|
2015-10-13 21:44:01 -07:00
|
|
|
acceptButton.setOnClickListener(reminder.getOkListener());
|
2015-03-11 14:23:45 -07:00
|
|
|
|
2015-01-11 20:27:34 -08:00
|
|
|
if (reminder.isDismissable()) {
|
2015-10-13 21:44:01 -07:00
|
|
|
closeButton.setOnClickListener(new OnClickListener() {
|
2015-01-11 20:27:34 -08:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
hide();
|
2015-10-13 21:44:01 -07:00
|
|
|
if (reminder.getDismissListener() != null) reminder.getDismissListener().onClick(v);
|
2015-01-11 20:27:34 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2015-10-13 21:44:01 -07:00
|
|
|
closeButton.setVisibility(View.GONE);
|
2015-01-11 20:27:34 -08:00
|
|
|
}
|
2015-03-11 14:23:45 -07:00
|
|
|
|
|
|
|
container.setVisibility(View.VISIBLE);
|
2014-08-04 13:13:47 -07:00
|
|
|
}
|
|
|
|
|
2015-10-13 21:44:01 -07:00
|
|
|
public void requestDismiss() {
|
|
|
|
closeButton.performClick();
|
|
|
|
}
|
|
|
|
|
2014-08-04 13:13:47 -07:00
|
|
|
public void hide() {
|
|
|
|
container.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|