package cgeo.geocaching.enumerations;

import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;

import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.R;

import org.eclipse.jdt.annotation.NonNull;
import java.util.ArrayList;
import java.util.List;

public enum LogTypeTrackable {
    DO_NOTHING(1, -1, "", R.string.log_tb_nothing, LogType.UNKNOWN),
    VISITED(1001, 5, "_Visited", R.string.log_tb_visit, LogType.VISIT),
    DROPPED_OFF(14, 0, "_DroppedOff", R.string.log_tb_drop, LogType.PLACED_IT),
    RETRIEVED_IT(13, 1, "", R.string.log_retrieved, R.drawable.mark_green_more, LogType.RETRIEVED_IT),
    GRABBED_IT(19, -1, "", R.string.log_tb_grabbed, R.drawable.mark_green_more, LogType.GRABBED_IT),
    NOTE(4, 2, "", R.string.log_tb_note, LogType.NOTE),
    DISCOVERED_IT(48, 3, "", R.string.log_tb_discovered, R.drawable.mark_green, LogType.DISCOVERED_IT),
    ARCHIVED(5, 4, "", R.string.log_tb_archived, R.drawable.mark_red_more, LogType.UNKNOWN),
    UNKNOWN(0, -1, "", R.string.err_unknown, LogType.UNKNOWN);

    public final int id; // id matching LogTypes
    public final int gkid; // This is the id from GeoKrety
    @NonNull final public String action;
    @StringRes
    final private int resourceId;
    @DrawableRes
    public final int markerId;
    // A link to the old LogType. This is done while Twitter still only handle LogType
    public final LogType oldLogtype;

    LogTypeTrackable(final int id, final int gkid, @NonNull final String action, @StringRes final int resourceId, @DrawableRes final int markerId, final LogType oldLogtype) {
        this.id = id;
        this.gkid = gkid;
        this.action = action;
        this.resourceId = resourceId;
        this.markerId = markerId;
        this.oldLogtype = oldLogtype;
    }

    LogTypeTrackable(final int id, final int gkid, final String action, @StringRes final int resourceId, final LogType oldLogtype) {
        this(id, gkid, action, resourceId, R.drawable.mark_gray, oldLogtype);
    }

    @NonNull
    public String getLabel() {
        return CgeoApplication.getInstance().getString(resourceId);
    }

    public static LogTypeTrackable getById(final int id) {
        for (final LogTypeTrackable logTypeTrackable : values()) {
            if (logTypeTrackable.id == id) {
                return logTypeTrackable;
            }
        }
        return UNKNOWN;
    }

    // Specify the list of trackable action when in LogCacheActivity
    public static final List<LogTypeTrackable> getLogTypeTrackableForLogCache() {
        final List<LogTypeTrackable> list = new ArrayList<>();
        list.add(DO_NOTHING);
        list.add(VISITED);
        list.add(DROPPED_OFF);
        return list;
    }

    // Some log type doesn't need Coordinates
    public static boolean isCoordinatesNeeded(final LogTypeTrackable typeSelected) {
        return !(RETRIEVED_IT == typeSelected || NOTE == typeSelected);
    }

}

@@ -192,16 +192,50 @@
 ing.R;%0A%0A
+import cgeo.geocaching.utils.Log;%0A
 import o
@@ -1026,24 +1026,228 @@
 e.UNKNOWN),%0A
+    MOVE_COLLECTION(69, -1, %22unused_collection%22, R.string.log_movecollection, LogType.MOVE_COLLECTION),%0A    MOVE_INVENTORY(70, -1, %22unused_inventory%22, R.string.log_moveinventory, LogType.MOVE_INVENTORY),%0A
     UNKNOWN(
@@ -2604,32 +2604,104 @@
     %7D%0A        %7D%0A
+        Log.e(%22LogTypeTrackable.getById(): Failed to lookup id:%22 + id);%0A
         return U

Fix #5395: "Unknown error" shown as log type for TB instead of "Move to inventory"