package com.comic.chhreader.evernoteshare;

import android.content.Context;

import com.comic.chhreader.Loge;
import com.evernote.client.android.EvernoteSession;
import com.evernote.client.android.EvernoteUtil;
import com.evernote.client.android.OnClientCallback;
import com.evernote.edam.type.Note;
import com.evernote.thrift.transport.TTransportException;

public class ShareToEvernote {
	private static final String CONSUMER_KEY = "zjywill";
	private static final String CONSUMER_SECRET = "6ced9b74e128bcfb";
	private static final EvernoteSession.EvernoteService EVERNOTE_SERVICE = EvernoteSession.EvernoteService.SANDBOX;
	private static final boolean SUPPORT_APP_LINKED_NOTEBOOKS = true;

	public static ShareToEvernote sShareToEvernote = null;

	public static EvernoteSession sEvernoteSession = null;
	public static Context sContext = null;

	synchronized public static ShareToEvernote getInstance(Context context) {
		if (sShareToEvernote == null) {
			sShareToEvernote = new ShareToEvernote(context);
		}
		return sShareToEvernote;
	}

	private ShareToEvernote(Context context) {
		sContext = context;
		genEvernoteSession(context);
	}

	private void genEvernoteSession(Context context) {
		sEvernoteSession = EvernoteSession.getInstance(context, CONSUMER_KEY, CONSUMER_SECRET, EVERNOTE_SERVICE, SUPPORT_APP_LINKED_NOTEBOOKS);
	}

	public EvernoteSession getEvernoteSession() {
		return sEvernoteSession;
	}

	public boolean isAppLinkedNotebook() {
		if (sEvernoteSession != null) {
			return sEvernoteSession.getAuthenticationResult().isAppLinkedNotebook();
		}
		Loge.d("isAppLinkedNotebook sEvernoteSession is null");
		return false;
	}

	public boolean isLoggedIn() {
		if (sEvernoteSession != null) {
			return sEvernoteSession.isLoggedIn();
		}
		Loge.d("isLoggedIn sEvernoteSession is null");
		return false;
	}

	public void authenticate() {
		if (sEvernoteSession != null && sContext != null) {
			sEvernoteSession.authenticate(sContext);
		}
	}

	public void shareNote(Context context, String title, String content,
			OnClientCallback<Note> mNoteCreateCallback) {
		genEvernoteSession(context);

		Note note = new Note();
		note.setTitle(title);
		note.setContent(EvernoteUtil.NOTE_PREFIX + content + EvernoteUtil.NOTE_SUFFIX);

		if (sEvernoteSession == null) {
			return;
		}
		try {
			sEvernoteSession.getClientFactory().createNoteStoreClient().createNote(note, mNoteCreateCallback);
		} catch (TTransportException exception) {
			Loge.e("Error creating notestore", exception);
		}
	}
}

@@ -614,15 +614,18 @@
 ice.
-SANDBOX
+PRODUCTION
 ;%0A%09p

change evernote to production