Browse Source

Handle unknown dm types. Fixes the crash in https://github.com/austinhuang0131/barinsta/issues/891

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
4507d8b588
  1. 13
      app/src/main/java/awais/instagrabber/adapters/DirectItemsAdapter.java
  2. 4
      app/src/main/java/awais/instagrabber/models/enums/DirectItemType.java

13
app/src/main/java/awais/instagrabber/adapters/DirectItemsAdapter.java

@ -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

4
app/src/main/java/awais/instagrabber/models/enums/DirectItemType.java

@ -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);
}

Loading…
Cancel
Save