From c6d10fcf0e8da68a4db3853745d48eee3a0ce92c Mon Sep 17 00:00:00 2001 From: stom79 Date: Wed, 7 Nov 2018 08:04:04 +0100 Subject: [PATCH] Remove card calls as it is now attached by default to statuses --- .../activities/ShowConversationActivity.java | 5 -- .../asynctasks/RetrieveCardAsyncTask.java | 55 ------------------- .../fr/gouv/etalab/mastodon/client/API.java | 21 ++----- 3 files changed, 6 insertions(+), 75 deletions(-) delete mode 100644 app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveCardAsyncTask.java diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java index 7387d041a..e14877910 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java @@ -27,7 +27,6 @@ import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.ActionBar; -import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; @@ -49,7 +48,6 @@ import java.util.ArrayList; import java.util.List; import fr.gouv.etalab.mastodon.R; -import fr.gouv.etalab.mastodon.asynctasks.RetrieveCardAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveContextAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask; import fr.gouv.etalab.mastodon.client.APIResponse; @@ -354,9 +352,6 @@ public class ShowConversationActivity extends BaseActivity implements OnRetrieve loader.setVisibility(View.GONE); lv_status.setVisibility(View.VISIBLE); - - new RetrieveCardAsyncTask(getApplicationContext(), initialStatus.getId(), ShowConversationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } @Override diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveCardAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveCardAsyncTask.java deleted file mode 100644 index b8e741d60..000000000 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveCardAsyncTask.java +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright 2017 Thomas Schneider - * - * This file is a part of Mastalab - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 3 of the - * License, or (at your option) any later version. - * - * Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even - * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along with Mastalab; if not, - * see . */ -package fr.gouv.etalab.mastodon.asynctasks; - -import android.content.Context; -import android.os.AsyncTask; -import java.lang.ref.WeakReference; -import fr.gouv.etalab.mastodon.client.API; -import fr.gouv.etalab.mastodon.client.Entities.Card; -import fr.gouv.etalab.mastodon.interfaces.OnRetrieveCardInterface; - - -/** - * Created by Thomas on 20/12/2017. - * Retrieves Card - */ - -public class RetrieveCardAsyncTask extends AsyncTask { - - private String statusId; - private Card card; - private OnRetrieveCardInterface listener; - private WeakReference contextReference; - - public RetrieveCardAsyncTask(Context context, String statusId, OnRetrieveCardInterface onRetrieveCardInterface){ - this.contextReference = new WeakReference<>(context); - this.statusId = statusId; - this.listener = onRetrieveCardInterface; - } - - - @Override - protected Void doInBackground(Void... params) { - card = new API(contextReference.get()).getCard(statusId); - return null; - } - - @Override - protected void onPostExecute(Void result) { - listener.onRetrieveAccount(card); - } - -} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index cdb00fe67..4eefd19fb 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -2300,20 +2300,6 @@ public class API { } - /** - * Get card - * @param statusId String, the id of the status - * @return Card, the card (null if none) - */ - public Card getCard(String statusId){ - - Card card = null; - try { - String response = new HttpsConnection(context).get(getAbsoluteUrl(String.format("/statuses/%s/card", statusId)), 60, null, prefKeyOauthTokenT); - card = parseCardResponse(new JSONObject(response)); - }catch (Exception ignored) {ignored.printStackTrace();} - return card; - } /** * Update a list by its id @@ -2452,7 +2438,7 @@ public class API { * @param resobj JSONObject * @return Card */ - private Card parseCardResponse(JSONObject resobj){ + private static Card parseCardResponse(JSONObject resobj){ Card card = new Card(); try { @@ -2831,6 +2817,11 @@ public class API { attachments.add(attachment); } } + try { + status.setCard(parseCardResponse(resobj.getJSONObject("card"))); + }catch (Exception e){status.setCard(null);} + + status.setMedia_attachments(attachments); //Retrieves mentions List mentions = new ArrayList<>();