Пример #1
0
  /** Makes a GET request to the server to download the owned squares */
  public static void downloadOwnedSquares() {
    VolleyManager.getInstance()
        .getOwnedSquares(
            "true",
            InSquareProfile.getUserId(),
            new VolleyManager.VolleyResponseListener() {
              @Override
              public void responseGET(Object object) {
                if (object == null) {
                  Log.d(TAG, "responseGET: getOwnedSquares returned NULL!");
                } else {
                  setOwnedSquaresList((ArrayList<Square>) object);
                  Log.d(TAG, "onResponse: ho ottenuto OWNED con successo!");
                  //                            Log.d(TAG, "onResponse Owned: " +
                  // InSquareProfile.getOwnedSquaresList().toString());

                }
              }

              @Override
              public void responsePOST(Object object) {}

              @Override
              public void responsePATCH(Object object) {}

              @Override
              public void responseDELETE(Object object) {}
            });
  }
Пример #2
0
  /** Makes a GET request to the server to download the favourite squares */
  public static void downloadFavoriteSquares() {
    VolleyManager.getInstance()
        .getFavoriteSquares(
            InSquareProfile.getUserId(),
            new VolleyManager.VolleyResponseListener() {
              @Override
              public void responseGET(Object object) {
                if (object == null) {
                  Log.d(TAG, "responseGET: getFavoriteSquares returned NULL!");
                } else {
                  setFavouriteSquaresList((ArrayList<Square>) object);
                  Log.d(TAG, "onResponse: ho ottenuto FAVS con successo!");
                }
              }

              @Override
              public void responsePOST(Object object) {
                // Empty - GET Request
              }

              @Override
              public void responsePATCH(Object object) {
                // Empty - GET Request
              }

              @Override
              public void responseDELETE(Object object) {
                // Empty - GET Request
              }
            });
  }
Пример #3
0
  /**
   * Clears all the credentials saved on the disk
   *
   * @see #clearFacebookCredentials(Context)
   * @see #clearGoogleCredentials(Context)
   */
  public static void clearProfileCredentials(final Context c) {
    VolleyManager.getInstance(c)
        .patchGCMToken(
            "dummy",
            new VolleyManager.VolleyResponseListener() {
              @Override
              public void responseGET(Object object) {
                // Vuoto - PATCH Request
              }

              @Override
              public void responsePOST(Object object) {
                // Vuoto - PATCH Request
              }

              @Override
              public void responsePATCH(Object object) {
                if (object == null) {
                  Log.d(TAG, "responsePOST: my token wasn't posted correctly!");
                } else {
                  Log.d(TAG, "responsePOST: everything is fine!");
                  userId = null;
                  username = null;
                  email = null;
                  pictureUrl = null;

                  clearFacebookCredentials(c);
                  clearGoogleCredentials(c);
                  save(c);

                  Intent intent = new Intent(c, LoginActivity.class);
                  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                  c.startActivity(intent);
                }
              }

              @Override
              public void responseDELETE(Object object) {
                // Vuoto - PATCH Request
              }
            });
  }
Пример #4
0
  /**
   * Loads the data from the disk and creates user's InSquareProfile
   *
   * @param c The context of the application
   * @return Returns the instance of the user's InSquareProfile
   */
  public static InSquareProfile getInstance(Context c) {
    if (profile != null) {
      Log.d(TAG, "getInstance: already instantiated!");
      return profile;
    }

    Log.d(TAG, "getInstance: Instantiating profile!");
    profile = new InSquareProfile();

    Gson gs = new Gson();
    Type listType = new TypeToken<ArrayList<Square>>() {}.getType();
    Type hashmapType = new TypeToken<HashMap<String, ArrayList<Message>>>() {}.getType();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    profile.userId = prefs.getString(USER_ID_KEY, null);
    profile.username = prefs.getString(USERNAME_KEY, null);
    profile.email = prefs.getString(EMAIL_KEY, null);
    profile.pictureUrl = prefs.getString(PICTURE_URL_KEY, null);

    profile.listeners = new ArrayList<>();
    profile.ownedSquaresList = gs.fromJson(prefs.getString(OWNED_SQUARES_KEY, null), listType);
    if (profile.ownedSquaresList == null) {
      profile.ownedSquaresList = new ArrayList<>();
      Log.d(TAG, "ownedSquaresList was null");
    }
    profile.favouriteSquaresList =
        gs.fromJson(prefs.getString(FAVOURITE_SQUARES_KEY, null), listType);
    if (profile.favouriteSquaresList == null) {
      profile.favouriteSquaresList = new ArrayList<>();
      Log.d(TAG, "favourtieSquaresList was null");
    }
    profile.recentSquaresList = gs.fromJson(prefs.getString(RECENT_SQUARES_KEY, null), listType);
    if (profile.recentSquaresList == null) {
      profile.recentSquaresList = new ArrayList<>();
      Log.d(TAG, "recentSquaresList was null");
    }
    profile.outgoingMessages = gs.fromJson(prefs.getString(OUTGOING_MESSAGES, null), hashmapType);
    if (profile.outgoingMessages == null) {
      profile.outgoingMessages = new HashMap<>();
      Log.d(TAG, "outgoingMessages was null");
    }

    profile.facebookId = prefs.getString(FACEBOOK_ID_KEY, null);
    profile.facebookToken = prefs.getString(FACEBOOK_TOKEN_KEY, null);
    profile.facebookEmail = prefs.getString(FACEBOOK_EMAIL_KEY, null);
    profile.facebookName = prefs.getString(FACEBOOK_NAME_KEY, null);

    profile.googleId = prefs.getString(GOOGLE_ID_KEY, null);
    profile.googleToken = prefs.getString(GOOGLE_TOKEN_KEY, null);
    profile.googleEmail = prefs.getString(GOOGLE_EMAIL_KEY, null);
    profile.googleName = prefs.getString(GOOGLE_NAME_KEY, null);

    profile.showTutorial = prefs.getBoolean(SHOW_TUTORIAL, true);
    Log.d(TAG, "getInstance: ho caricato showtutorial: " + profile.showTutorial);

    if (hasLoginData()) {
      // VolleyManager viene istanziato e si procede con la richiesta al server
      VolleyManager.getInstance(c);
      downloadFavoriteSquares();
      downloadOwnedSquares();
      downloadRecentSquares();
    }

    return profile;
  }