package cgeo.geocaching.connector.oc;

import cgeo.geocaching.Geocache;
import cgeo.geocaching.LogCacheActivity;
import cgeo.geocaching.TrackableLog;
import cgeo.geocaching.connector.ILoggingManager;
import cgeo.geocaching.connector.ImageResult;
import cgeo.geocaching.connector.LogResult;
import cgeo.geocaching.enumerations.LogType;
import cgeo.geocaching.enumerations.StatusCode;

import android.app.Activity;
import android.net.Uri;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;

public class OkapiLoggingManager implements ILoggingManager {

    private final OCApiConnector connector;
    private final Geocache cache;
    private LogCacheActivity activity;

    private final static List<LogType> standardLogTypes = Arrays.asList(LogType.FOUND_IT, LogType.DIDNT_FIND_IT, LogType.NOTE, LogType.NEEDS_MAINTENANCE);
    private final static List<LogType> eventLogTypes = Arrays.asList(LogType.WILL_ATTEND, LogType.ATTENDED, LogType.NOTE);

    public OkapiLoggingManager(Activity activity, OCApiConnector connector, Geocache cache) {
        this.connector = connector;
        this.cache = cache;
        this.activity = (LogCacheActivity) activity;
    }

    @Override
    public void init() {
        activity.onLoadFinished();
    }

    @Override
    public LogResult postLog(Geocache cache, LogType logType, Calendar date, String log, String logPassword, List<TrackableLog> trackableLogs) {
        return OkapiClient.postLog(cache, logType, date, log, logPassword, connector);
    }

    @Override
    public ImageResult postLogImage(String logId, String imageCaption, String imageDescription, Uri imageUri) {
        return new ImageResult(StatusCode.LOG_POST_ERROR, "");
    }

    @Override
    public boolean hasLoaderError() {
        return false;
    }

    @Override
    public List<TrackableLog> getTrackables() {
        return Collections.emptyList();
    }

    @Override
    public List<LogType> getPossibleLogTypes() {
        if (cache.isEventCache()) {
            return eventLogTypes;
        }

        return standardLogTypes;
    }
}

@@ -619,24 +619,28 @@
  final OCApi
+Live
 Connector co
@@ -644,24 +644,24 @@
  connector;%0A
-
     private 
@@ -1056,16 +1056,20 @@
 y, OCApi
+Live
 Connecto
@@ -1471,22 +1471,40 @@
         
-return
+final LogResult result =
  OkapiCl
@@ -1568,16 +1568,76 @@
 ector);%0A
+        connector.login(null, null);%0A        return result;%0A
     %7D%0A%0A 

Fix #2986, OC: Cache count not updated after online log