package edu.rpi.cs.yacs.retrofit;

import android.app.Activity;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import java.lang.annotation.Retention;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * Created by Mark Robinson on 9/24/16.
 */

class ServiceHelper {
    @Retention(RUNTIME)
    @interface Json {
    }

    private YACSService service;
    private Activity activity;

    private ServiceHelper(Activity activity) {
        this.activity = activity;

        invalidateService();
    }

    public YACSService getService() {
        return service;
    }

    /**
     * This method is used when we need to invalidate the YACSService
     * @return new YACSService that uses the latest "House of YACS" setting
     */
    public YACSService invalidateService() {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);

        // If exists, return String value
        // Otherwise, return "unknown"
        String houseOfYACS = preferences.getString("House of YACS", "unknown");

        String baseURL = convertHouseToURL(houseOfYACS);

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(baseURL)
                .addConverterFactory(new JsonStringConverterFactory(GsonConverterFactory.create()))
                .build();

        service = retrofit.create(YACSService.class);

        return service;
    }

    /**
     * This method returns the YACS URL of the input college name.
     * @param house College name
     * @return College YACS URL if College supports YACS. Otherwise, returns "not supported yet"
     */
    private String convertHouseToURL(String house) {
        switch (house) {
            case "Rensselaer Polytechnic Institute":
                return "https://yacs.cs.rpi.edu/api/v5/";
            default :
                return "not supported yet";
        }
    }
}
@@ -47,20 +47,23 @@
 oid.
-app.Activity
+content.Context
 ;%0Aim
@@ -380,16 +380,23 @@
 6.%0A */%0A%0A
+public 
 class Se
@@ -511,33 +511,31 @@
 ate 
-Activity activity
+Context context
 ;%0A%0A    p
 riva
@@ -530,22 +530,21 @@
 ;%0A%0A    p
-rivate
+ublic
  Service
@@ -554,61 +554,57 @@
 per(
-Activity activity) %7B%0A        this.activity = activity
+Context context) %7B%0A        this.context = context
 ;%0A%0A 
@@ -1004,16 +1004,15 @@
 ces(
-activity
+context
 );%0A%0A
@@ -1033,22 +1033,22 @@
 exists, 
-return
+set to
  String 
@@ -1075,22 +1075,22 @@
 erwise, 
-return
+set to
  %22unknow

Modify ServiceHelper