Commit fa53758d authored by Tiago Cunha's avatar Tiago Cunha

Cleaned up WIP

parent b920ef07
......@@ -90,7 +90,8 @@ import permissions.dispatcher.RuntimePermissions;
@RuntimePermissions
public class RoomFragment extends AbstractChatRoomFragment
implements OnBackPressListener, ExtraActionPickerDialogFragment.Callback,
ModelListAdapter.OnItemClickListener<PairedMessage>, RoomContract.View {
ModelListAdapter.OnItemClickListener<PairedMessage>,
ModelListAdapter.OnItemLongClickListener<PairedMessage>, RoomContract.View {
private static final int DIALOG_ID = 1;
private static final String HOSTNAME = "hostname";
......@@ -187,6 +188,7 @@ public class RoomFragment extends AbstractChatRoomFragment
adapter = new MessageListAdapter(getContext());
listView.setAdapter(adapter);
adapter.setOnItemClickListener(this);
adapter.setOnItemLongClickListener(this);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(),
LinearLayoutManager.VERTICAL, true);
......@@ -282,6 +284,11 @@ public class RoomFragment extends AbstractChatRoomFragment
presenter.onMessageSelected(pairedMessage.target);
}
@Override
public boolean onItemLongClick(PairedMessage model) {
return false;
}
private void setupSideMenu() {
View sideMenu = rootView.findViewById(R.id.room_side_menu);
sideMenu.findViewById(R.id.btn_users).setOnClickListener(view -> {
......
......@@ -18,6 +18,7 @@ public abstract class ModelListAdapter<T, VM, VH extends ModelViewHolder<VM>>
protected final LayoutInflater inflater;
private List<VM> adapterData;
private OnItemClickListener<VM> onItemClickListener;
private OnItemLongClickListener<VM> onItemLongClickListener;
protected ModelListAdapter(Context context) {
this.inflater = LayoutInflater.from(context);
......@@ -42,6 +43,20 @@ public abstract class ModelListAdapter<T, VM, VH extends ModelViewHolder<VM>>
@Override
public final VH onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = inflater.inflate(getLayout(viewType), parent, false);
itemView.setOnClickListener(view -> {
VM model = (VM) (view.getTag());
if (model != null && onItemClickListener != null) {
onItemClickListener.onItemClick(model);
}
});
itemView.setOnLongClickListener(view -> {
VM model = (VM) (view.getTag());
return model != null && onItemLongClickListener != null
&& onItemLongClickListener.onItemLongClick(model);
});
return onCreateRealmModelViewHolder(viewType, itemView);
}
......@@ -49,12 +64,6 @@ public abstract class ModelListAdapter<T, VM, VH extends ModelViewHolder<VM>>
public void onBindViewHolder(VH holder, int position) {
VM model = getItem(position);
holder.itemView.setTag(model);
holder.itemView.setOnClickListener(view -> {
VM model2 = (VM) (view.getTag());
if (model2 != null && onItemClickListener != null) {
onItemClickListener.onItemClick(model2);
}
});
holder.bind(model, shouldAutoloadImages());
}
......@@ -114,6 +123,10 @@ public abstract class ModelListAdapter<T, VM, VH extends ModelViewHolder<VM>>
this.onItemClickListener = onItemClickListener;
}
public void setOnItemLongClickListener(OnItemLongClickListener<VM> onItemLongClickListener) {
this.onItemLongClickListener = onItemLongClickListener;
}
public interface Constructor<T, VM, VH extends ModelViewHolder<VM>> {
ModelListAdapter<T, VM, VH> getNewInstance(Context context);
}
......@@ -121,4 +134,8 @@ public abstract class ModelListAdapter<T, VM, VH extends ModelViewHolder<VM>>
public interface OnItemClickListener<VM> {
void onItemClick(VM model);
}
public interface OnItemLongClickListener<VM> {
boolean onItemLongClick(VM model);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment