1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 14:47:29 +00:00

convert some to kotlin

This commit is contained in:
Austin Huang 2021-05-30 20:51:54 -04:00
parent 7cf659c4f5
commit d532d28ac3
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
5 changed files with 44 additions and 72 deletions

View File

@ -139,7 +139,7 @@ public final class DirectItemsAdapter extends RecyclerView.Adapter<RecyclerView.
return new HeaderViewHolder(LayoutDmHeaderBinding.inflate(layoutInflater, parent, false)); return new HeaderViewHolder(LayoutDmHeaderBinding.inflate(layoutInflater, parent, false));
} }
final LayoutDmBaseBinding baseBinding = LayoutDmBaseBinding.inflate(layoutInflater, parent, false); final LayoutDmBaseBinding baseBinding = LayoutDmBaseBinding.inflate(layoutInflater, parent, false);
final DirectItemType directItemType = DirectItemType.valueOf(type); final DirectItemType directItemType = DirectItemType.Companion.getId(type);
final DirectItemViewHolder itemViewHolder = getItemViewHolder(layoutInflater, baseBinding, directItemType); final DirectItemViewHolder itemViewHolder = getItemViewHolder(layoutInflater, baseBinding, directItemType);
itemViewHolder.setLongClickListener(longClickListener); itemViewHolder.setLongClickListener(longClickListener);
return itemViewHolder; return itemViewHolder;

View File

@ -10,6 +10,7 @@ import androidx.lifecycle.Transformations.distinctUntilChanged
import androidx.lifecycle.Transformations.map import androidx.lifecycle.Transformations.map
import awais.instagrabber.R import awais.instagrabber.R
import awais.instagrabber.customviews.emoji.Emoji import awais.instagrabber.customviews.emoji.Emoji
import awais.instagrabber.models.enums.DirectItemType.Companion.getName
import awais.instagrabber.models.Resource import awais.instagrabber.models.Resource
import awais.instagrabber.models.Resource.Companion.error import awais.instagrabber.models.Resource.Companion.error
import awais.instagrabber.models.Resource.Companion.loading import awais.instagrabber.models.Resource.Companion.loading
@ -645,7 +646,7 @@ class ThreadManager private constructor(
data.postValue(error("item type is null", null)) data.postValue(error("item type is null", null))
return data return data
} }
val itemTypeName = itemType.getName() val itemTypeName = getName(itemType)
if (itemTypeName == null) { if (itemTypeName == null) {
Log.e(TAG, "forward: itemTypeName was null!") Log.e(TAG, "forward: itemTypeName was null!")
data.postValue(error("itemTypeName is null", null)) data.postValue(error("itemTypeName is null", null))

View File

@ -1,12 +1,11 @@
package awais.instagrabber.models.enums; package awais.instagrabber.models.enums
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName
import java.io.Serializable; import java.io.Serializable
import java.util.HashMap; import java.util.*
import java.util.Map;
public enum DirectItemType implements Serializable { enum class DirectItemType(val id: Int) : Serializable {
UNKNOWN(0), UNKNOWN(0),
@SerializedName("text") @SerializedName("text")
TEXT(1), TEXT(1),
@ -45,65 +44,42 @@ public enum DirectItemType implements Serializable {
@SerializedName("xma") @SerializedName("xma")
XMA(18); // self avatar stickers XMA(18); // self avatar stickers
private final int id; companion object {
private static final Map<Integer, DirectItemType> map = new HashMap<>(); private val map: MutableMap<Int, DirectItemType> = mutableMapOf()
static { @JvmStatic
for (DirectItemType type : DirectItemType.values()) { fun getId(id: Int): DirectItemType? {
map.put(type.id, type); return map[id]
} }
}
DirectItemType(final int id) { @JvmStatic
this.id = id; fun getName(directItemType: DirectItemType): String? {
} when (directItemType) {
TEXT -> return "text"
public int getId() { LIKE -> return "like"
return id; LINK -> return "link"
} MEDIA -> return "media"
RAVEN_MEDIA -> return "raven_media"
public static DirectItemType valueOf(final int id) { PROFILE -> return "profile"
if (!map.containsKey(id)) return DirectItemType.UNKNOWN; VIDEO_CALL_EVENT -> return "video_call_event"
return map.get(id); ANIMATED_MEDIA -> return "animated_media"
} VOICE_MEDIA -> return "voice_media"
MEDIA_SHARE -> return "media_share"
public String getName() { REEL_SHARE -> return "reel_share"
switch (this) { ACTION_LOG -> return "action_log"
case TEXT: PLACEHOLDER -> return "placeholder"
return "text"; STORY_SHARE -> return "story_share"
case LIKE: CLIP -> return "clip"
return "like"; FELIX_SHARE -> return "felix_share"
case LINK: LOCATION -> return "location"
return "link"; }
case MEDIA: return null
return "media"; }
case RAVEN_MEDIA:
return "raven_media"; init {
case PROFILE: for (type in DirectItemType.values()) {
return "profile"; map[type.id] = type
case VIDEO_CALL_EVENT: }
return "video_call_event";
case ANIMATED_MEDIA:
return "animated_media";
case VOICE_MEDIA:
return "voice_media";
case MEDIA_SHARE:
return "media_share";
case REEL_SHARE:
return "reel_share";
case ACTION_LOG:
return "action_log";
case PLACEHOLDER:
return "placeholder";
case STORY_SHARE:
return "story_share";
case CLIP:
return "clip";
case FELIX_SHARE:
return "felix_share";
case LOCATION:
return "location";
} }
return null;
} }
} }

View File

@ -1,8 +1,8 @@
package awais.instagrabber.models.enums; package awais.instagrabber.models.enums
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName
public enum RavenMediaViewMode { enum class RavenMediaViewMode {
@SerializedName("permanent") @SerializedName("permanent")
PERMANENT, PERMANENT,
@SerializedName("replayable") @SerializedName("replayable")

View File

@ -1,5 +0,0 @@
package awais.instagrabber.models.enums
enum class SuggestionType {
TYPE_USER, TYPE_HASHTAG, TYPE_LOCATION
}