// Path: Reddit Headlines for DashClock/src/main/java/net/trolldad/dashclock/redditheadlines/RedditHeadlinesApplication.java
// @EApplication
// public class RedditHeadlinesApplication extends Application {
//     public static final String TAG = "RedditHeadlinesApplication";
//     private static RedditHeadlinesApplication mInstance;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         EasyTracker.getInstance(this);
//         Thread.UncaughtExceptionHandler uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
//         if (uncaughtExceptionHandler instanceof ExceptionReporter) {
//             ExceptionReporter exceptionReporter = (ExceptionReporter) uncaughtExceptionHandler;
//             exceptionReporter.setExceptionParser(new AnalyticsExceptionParser());
//         }
//         mInstance = this;
//     }
// 
//     public static Context getContext() {
//         return mInstance;
//     }
// 
//     public static void toast(String message) {
//         mInstance.makeToast(message);
//     }
// 
//     @UiThread
//     void makeToast(String message) {
//         Toast.makeText(getContext(), message, Toast.LENGTH_LONG).show();
//     }
// }


import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import net.trolldad.dashclock.redditheadlines.R;
import net.trolldad.dashclock.redditheadlines.RedditHeadlinesApplication;
import net.trolldad.dashclock.redditheadlines.preferences.MyPrefs_;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.res.StringRes;
import org.androidannotations.annotations.sharedpreferences.Pref;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.URLEncoder;
import retrofit.RequestInterceptor;
import retrofit.RestAdapter;
import retrofit.converter.GsonConverter;
package net.trolldad.dashclock.redditheadlines.reddit;







/**
 * Created by jacob-tabak on 1/19/14.
 */
@EBean
public class RedditClient {
    @StringRes(R.string.reddit_base_url) String mRedditApiUrl;
    @Pref
    MyPrefs_ mPrefs;

    public RedditService getService() {
        RestAdapter restAdapter = new RestAdapter.Builder()
                .setServer(mRedditApiUrl)
                .setRequestInterceptor(new RedditServiceInterceptor())
                .setConverter(new GsonConverter(getGson()))
                .setLog(new RedditLog())
                .setLogLevel(RestAdapter.LogLevel.FULL)
                .build();
        return restAdapter.create(RedditService.class);
    }

    class RedditLog implements RestAdapter.Log {
        @Override
        public void log(String s) {
            Log.d("RedditLog", s);
        }
    }

    class RedditServiceInterceptor implements RequestInterceptor {

        @Override
        public void intercept(RequestFacade requestFacade) {
            try {
                requestFacade.addHeader("cookie", "reddit_session=" + URLEncoder.encode(mPrefs.cookie().get(), "UTF-8"));
                requestFacade.addHeader("X-Modhash", URLEncoder.encode(mPrefs.modHash().get(), "UTF-8"));
            } catch (UnsupportedEncodingException e) {
// Path: Reddit Headlines for DashClock/src/main/java/net/trolldad/dashclock/redditheadlines/RedditHeadlinesApplication.java
// @EApplication
// public class RedditHeadlinesApplication extends Application {
//     public static final String TAG = "RedditHeadlinesApplication";
//     private static RedditHeadlinesApplication mInstance;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         EasyTracker.getInstance(this);
//         Thread.UncaughtExceptionHandler uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
//         if (uncaughtExceptionHandler instanceof ExceptionReporter) {
//             ExceptionReporter exceptionReporter = (ExceptionReporter) uncaughtExceptionHandler;
//             exceptionReporter.setExceptionParser(new AnalyticsExceptionParser());
//         }
//         mInstance = this;
//     }
// 
//     public static Context getContext() {
//         return mInstance;
//     }
// 
//     public static void toast(String message) {
//         mInstance.makeToast(message);
//     }
// 
//     @UiThread
//     void makeToast(String message) {
//         Toast.makeText(getContext(), message, Toast.LENGTH_LONG).show();
//     }
// }


// Path: Reddit Headlines for DashClock/src/main/java/net/trolldad/dashclock/redditheadlines/reddit/RedditClient.java
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import net.trolldad.dashclock.redditheadlines.R;
import net.trolldad.dashclock.redditheadlines.RedditHeadlinesApplication;
import net.trolldad.dashclock.redditheadlines.preferences.MyPrefs_;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.res.StringRes;
import org.androidannotations.annotations.sharedpreferences.Pref;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.URLEncoder;
import retrofit.RequestInterceptor;
import retrofit.RestAdapter;
import retrofit.converter.GsonConverter;

package net.trolldad.dashclock.redditheadlines.reddit;







/**
 * Created by jacob-tabak on 1/19/14.
 */
@EBean
public class RedditClient {
    @StringRes(R.string.reddit_base_url) String mRedditApiUrl;
    @Pref
    MyPrefs_ mPrefs;

    public RedditService getService() {
        RestAdapter restAdapter = new RestAdapter.Builder()
                .setServer(mRedditApiUrl)
                .setRequestInterceptor(new RedditServiceInterceptor())
                .setConverter(new GsonConverter(getGson()))
                .setLog(new RedditLog())
                .setLogLevel(RestAdapter.LogLevel.FULL)
                .build();
        return restAdapter.create(RedditService.class);
    }

    class RedditLog implements RestAdapter.Log {
        @Override
        public void log(String s) {
            Log.d("RedditLog", s);
        }
    }

    class RedditServiceInterceptor implements RequestInterceptor {

        @Override
        public void intercept(RequestFacade requestFacade) {
            try {
                requestFacade.addHeader("cookie", "reddit_session=" + URLEncoder.encode(mPrefs.cookie().get(), "UTF-8"));
                requestFacade.addHeader("X-Modhash", URLEncoder.encode(mPrefs.modHash().get(), "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                Log.e(RedditHeadlinesApplication.TAG, Log.getStackTraceString(e));