2015-10-21 15:32:29 -07:00
|
|
|
package org.thoughtcrime.securesms.components;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.R;
|
|
|
|
|
2016-12-08 14:20:38 -08:00
|
|
|
public class RemovableEditableMediaView extends FrameLayout {
|
2015-10-21 15:32:29 -07:00
|
|
|
|
|
|
|
private final @NonNull ImageView remove;
|
2016-12-08 14:20:38 -08:00
|
|
|
private final @NonNull ImageView edit;
|
|
|
|
|
2015-10-21 15:32:29 -07:00
|
|
|
private final int removeSize;
|
2016-12-08 14:20:38 -08:00
|
|
|
private final int editSize;
|
2015-10-21 15:32:29 -07:00
|
|
|
|
|
|
|
private @Nullable View current;
|
|
|
|
|
2016-12-08 14:20:38 -08:00
|
|
|
public RemovableEditableMediaView(Context context) {
|
2015-10-21 15:32:29 -07:00
|
|
|
this(context, null);
|
|
|
|
}
|
|
|
|
|
2016-12-08 14:20:38 -08:00
|
|
|
public RemovableEditableMediaView(Context context, AttributeSet attrs) {
|
2015-10-21 15:32:29 -07:00
|
|
|
this(context, attrs, 0);
|
|
|
|
}
|
|
|
|
|
2016-12-08 14:20:38 -08:00
|
|
|
public RemovableEditableMediaView(Context context, AttributeSet attrs, int defStyleAttr) {
|
2015-10-21 15:32:29 -07:00
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
|
|
|
|
this.remove = (ImageView)LayoutInflater.from(context).inflate(R.layout.media_view_remove_button, this, false);
|
2016-12-08 14:20:38 -08:00
|
|
|
this.edit = (ImageView)LayoutInflater.from(context).inflate(R.layout.media_view_edit_button, this, false);
|
|
|
|
|
2015-10-21 15:32:29 -07:00
|
|
|
this.removeSize = getResources().getDimensionPixelSize(R.dimen.media_bubble_remove_button_size);
|
2016-12-08 14:20:38 -08:00
|
|
|
this.editSize = getResources().getDimensionPixelSize(R.dimen.media_bubble_edit_button_size);
|
2015-10-21 15:32:29 -07:00
|
|
|
|
|
|
|
this.remove.setVisibility(View.GONE);
|
2016-12-08 14:20:38 -08:00
|
|
|
this.edit.setVisibility(View.GONE);
|
2015-10-21 15:32:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFinishInflate() {
|
|
|
|
super.onFinishInflate();
|
|
|
|
this.addView(remove);
|
2016-12-08 14:20:38 -08:00
|
|
|
this.addView(edit);
|
2015-10-21 15:32:29 -07:00
|
|
|
}
|
|
|
|
|
2016-12-08 14:20:38 -08:00
|
|
|
public void display(@Nullable View view, boolean editable) {
|
|
|
|
edit.setVisibility(editable ? View.VISIBLE : View.GONE);
|
|
|
|
|
2015-10-21 15:32:29 -07:00
|
|
|
if (view == current) return;
|
|
|
|
if (current != null) current.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
if (view != null) {
|
2016-12-08 14:20:38 -08:00
|
|
|
view.setPadding(0, removeSize / 2, removeSize / 2, 0);
|
|
|
|
edit.setPadding(0, 0, removeSize / 2, 0);
|
2015-10-21 15:32:29 -07:00
|
|
|
|
|
|
|
view.setVisibility(View.VISIBLE);
|
|
|
|
remove.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
remove.setVisibility(View.GONE);
|
2016-12-08 14:20:38 -08:00
|
|
|
edit.setVisibility(View.GONE);
|
2015-10-21 15:32:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
current = view;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setRemoveClickListener(View.OnClickListener listener) {
|
|
|
|
this.remove.setOnClickListener(listener);
|
|
|
|
}
|
2016-12-08 14:20:38 -08:00
|
|
|
|
|
|
|
public void setEditClickListener(View.OnClickListener listener) {
|
|
|
|
this.edit.setOnClickListener(listener);
|
|
|
|
}
|
2015-10-21 15:32:29 -07:00
|
|
|
}
|