Exemplo n.º 1
0
  public void addFavourite(Context context, final CatModel cat) {
    SharedPreferences prefs = context.getSharedPreferences("AppConfig", Context.MODE_PRIVATE);
    String android_id = prefs.getString("android_id", "thecatappid");

    // Use retrofit to get data
    RestAdapter restAdapter =
        new RestAdapter.Builder()
            .setEndpoint(context.getString(R.string.catApiBaseUrl))
            .setConverter(new SimpleXMLConverter())
            .build();

    CatApi catapi = restAdapter.create(CatApi.class);
    catapi.addFavourite(
        context.getString(R.string.catApiKey),
        android_id,
        cat.getId(),
        new Callback<FavouriteResponseModel>() {
          @Override
          public void success(FavouriteResponseModel responseModel, Response response) {
            // Set the model
            if (responseModel != null) {
              // Call view method to set the name list in the listView
              view.addFavourite(cat);
            }
          }

          @Override
          public void failure(RetrofitError error) {
            Log.e("Error parsing XML", error.getMessage());
            // Call view method to show a toast with an error message
            view.showErrorToast();
          }
        });
  }
Exemplo n.º 2
0
  public void getCat(Context context, final CatModel cat) {
    // Use retrofit to get data
    RestAdapter restAdapter =
        new RestAdapter.Builder()
            .setEndpoint(context.getString(R.string.catApiBaseUrl))
            .setConverter(new SimpleXMLConverter())
            .build();

    CatApi catapi = restAdapter.create(CatApi.class);
    catapi.getCat(
        context.getString(R.string.catApiKey),
        cat.getId(),
        new Callback<CatApiResponseModel>() {
          @Override
          public void success(CatApiResponseModel responseModel, Response response) {
            // Set the model
            if (responseModel != null) {
              CatModel cat = responseModel.getData().getCats().get(0);
              // Call view method to set the name list in the listView
              view.setCat(cat);
            }
          }

          @Override
          public void failure(RetrofitError error) {
            Log.e("Error parsing XML", error.getMessage());
            // Call view method to show a toast with an error message
            view.showErrorToast();
          }
        });
  }