This commit is contained in:
Ammar Githam 2021-03-29 23:02:42 +09:00
parent 7dc9583e51
commit 4507d8b588
2 changed files with 15 additions and 2 deletions

View File

@ -146,7 +146,12 @@ public final class DirectItemsAdapter extends RecyclerView.Adapter<RecyclerView.
@NonNull
private DirectItemViewHolder getItemViewHolder(final LayoutInflater layoutInflater,
final LayoutDmBaseBinding baseBinding,
@NonNull final DirectItemType directItemType) {
final DirectItemType directItemType) {
if (directItemType == null) {
// For unknown dm types
final LayoutDmTextBinding binding = LayoutDmTextBinding.inflate(layoutInflater, baseBinding.message, false);
return new DirectItemDefaultViewHolder(baseBinding, binding, currentUser, thread, callback);
}
switch (directItemType) {
case TEXT: {
final LayoutDmTextBinding binding = LayoutDmTextBinding.inflate(layoutInflater, baseBinding.message, false);
@ -240,7 +245,11 @@ public final class DirectItemsAdapter extends RecyclerView.Adapter<RecyclerView.
if (itemOrHeader.isHeader()) {
return -1;
}
return itemOrHeader.item.getItemType().getId();
final DirectItemType itemType = itemOrHeader.item.getItemType();
if (itemType == null) {
return 0;
}
return itemType.getId();
}
@Override

View File

@ -1,5 +1,7 @@
package awais.instagrabber.models.enums;
import androidx.annotation.Nullable;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
@ -59,7 +61,9 @@ public enum DirectItemType implements Serializable {
return id;
}
@Nullable
public static DirectItemType valueOf(final int id) {
if (!map.containsKey(id)) return null;
return map.get(id);
}