Closer, but still can't get a pinned toot to unpin.
This commit is contained in:
parent
50fb1a1515
commit
58661f54a4
|
@ -50,7 +50,8 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
FAVOURITES,
|
FAVOURITES,
|
||||||
ONESTATUS,
|
ONESTATUS,
|
||||||
CONTEXT,
|
CONTEXT,
|
||||||
TAG
|
TAG,
|
||||||
|
PINS
|
||||||
}
|
}
|
||||||
|
|
||||||
public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
|
public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
|
||||||
|
@ -109,6 +110,9 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
case TAG:
|
case TAG:
|
||||||
apiResponse = api.getPublicTimelineTag(tag, false, max_id);
|
apiResponse = api.getPublicTimelineTag(tag, false, max_id);
|
||||||
break;
|
break;
|
||||||
|
case PINS:
|
||||||
|
apiResponse = api.getPinnedStatuses(targetedID); // Might need max_id later?
|
||||||
|
break;
|
||||||
case HASHTAG:
|
case HASHTAG:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ public class API {
|
||||||
private Attachment attachment;
|
private Attachment attachment;
|
||||||
private List<Account> accounts;
|
private List<Account> accounts;
|
||||||
private List<Status> statuses;
|
private List<Status> statuses;
|
||||||
|
private List<Status> pins;
|
||||||
private List<Notification> notifications;
|
private List<Notification> notifications;
|
||||||
private int tootPerPage, accountPerPage, notificationPerPage;
|
private int tootPerPage, accountPerPage, notificationPerPage;
|
||||||
private int actionCode;
|
private int actionCode;
|
||||||
|
@ -309,26 +310,28 @@ public class API {
|
||||||
*/
|
*/
|
||||||
public APIResponse getPinnedStatuses(String accountId)
|
public APIResponse getPinnedStatuses(String accountId)
|
||||||
{
|
{
|
||||||
|
pins = new ArrayList<>();
|
||||||
|
|
||||||
RequestParams params = new RequestParams();
|
RequestParams params = new RequestParams();
|
||||||
|
|
||||||
params.put("pinned", Boolean.toString(true));
|
params.put("pinned", Boolean.toString(true));
|
||||||
|
|
||||||
get(String.format("/accounts/%s/statuses", accountId), params, new JsonHttpResponseHandler() {
|
get(String.format("/accounts/%s/statuses", accountId), params, new JsonHttpResponseHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
|
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
|
||||||
Status status = parseStatuses(context, response);
|
Status status = parseStatuses(context, response);
|
||||||
statuses.add(status);
|
pins.add(status);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
|
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
|
||||||
statuses = parseStatuses(response);
|
pins = parseStatuses(response);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
|
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
|
||||||
setError(statusCode, error);
|
setError(statusCode, error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
apiResponse.setStatuses(statuses);
|
apiResponse.setStatuses(pins);
|
||||||
return apiResponse;
|
return apiResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ public class Status implements Parcelable {
|
||||||
private int favourites_count;
|
private int favourites_count;
|
||||||
private boolean reblogged;
|
private boolean reblogged;
|
||||||
private boolean favourited;
|
private boolean favourited;
|
||||||
|
private boolean pinned;
|
||||||
private boolean sensitive;
|
private boolean sensitive;
|
||||||
private String spoiler_text;
|
private String spoiler_text;
|
||||||
private String visibility;
|
private String visibility;
|
||||||
|
@ -51,6 +52,7 @@ public class Status implements Parcelable {
|
||||||
private List<Status> replies;
|
private List<Status> replies;
|
||||||
private List<Mention> mentions;
|
private List<Mention> mentions;
|
||||||
private List<Tag> tags;
|
private List<Tag> tags;
|
||||||
|
private List<Status> pins;
|
||||||
private Application application;
|
private Application application;
|
||||||
private String language;
|
private String language;
|
||||||
private boolean isTranslated = false;
|
private boolean isTranslated = false;
|
||||||
|
@ -81,6 +83,9 @@ public class Status implements Parcelable {
|
||||||
isTranslated = in.readByte() != 0;
|
isTranslated = in.readByte() != 0;
|
||||||
isTranslationShown = in.readByte() != 0;
|
isTranslationShown = in.readByte() != 0;
|
||||||
isNew = in.readByte() != 0;
|
isNew = in.readByte() != 0;
|
||||||
|
|
||||||
|
pinned = false;
|
||||||
|
pins = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Status(){}
|
public Status(){}
|
||||||
|
@ -201,6 +206,14 @@ public class Status implements Parcelable {
|
||||||
this.favourited = favourited;
|
this.favourited = favourited;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPinned(boolean pinned) { this.pinned = pinned; }
|
||||||
|
|
||||||
|
public boolean isPinned() { return pinned; }
|
||||||
|
|
||||||
|
public List<Status> getPins() { return pins; }
|
||||||
|
|
||||||
|
public void setPins(List<Status> pins) { this.pins = pins; }
|
||||||
|
|
||||||
public boolean isSensitive() {
|
public boolean isSensitive() {
|
||||||
return sensitive;
|
return sensitive;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,12 +78,14 @@ import fr.gouv.etalab.mastodon.activities.TootActivity;
|
||||||
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
|
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.client.API;
|
import fr.gouv.etalab.mastodon.client.API;
|
||||||
|
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||||
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
|
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
|
||||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
||||||
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnTranslatedInterface;
|
import fr.gouv.etalab.mastodon.interfaces.OnTranslatedInterface;
|
||||||
import fr.gouv.etalab.mastodon.translation.GoogleTranslateQuery;
|
import fr.gouv.etalab.mastodon.translation.GoogleTranslateQuery;
|
||||||
import fr.gouv.etalab.mastodon.translation.YandexQuery;
|
import fr.gouv.etalab.mastodon.translation.YandexQuery;
|
||||||
|
@ -97,7 +99,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
||||||
* Created by Thomas on 24/04/2017.
|
* Created by Thomas on 24/04/2017.
|
||||||
* Adapter for Status
|
* Adapter for Status
|
||||||
*/
|
*/
|
||||||
public class StatusListAdapter extends BaseAdapter implements OnPostActionInterface, OnTranslatedInterface {
|
public class StatusListAdapter extends BaseAdapter implements OnPostActionInterface, OnTranslatedInterface, OnRetrieveFeedsInterface {
|
||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
private List<Status> statuses;
|
private List<Status> statuses;
|
||||||
|
@ -116,6 +118,8 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
||||||
private HashMap<String, String> urlConversion;
|
private HashMap<String, String> urlConversion;
|
||||||
private HashMap<String, String> tagConversion;
|
private HashMap<String, String> tagConversion;
|
||||||
|
|
||||||
|
private List<Status> pins;
|
||||||
|
|
||||||
public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
|
public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.statuses = statuses;
|
this.statuses = statuses;
|
||||||
|
@ -126,6 +130,8 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.targetedId = targetedId;
|
this.targetedId = targetedId;
|
||||||
this.translator = translator;
|
this.translator = translator;
|
||||||
|
|
||||||
|
pins = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -220,6 +226,11 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
||||||
|
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
|
||||||
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
|
|
||||||
|
new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.PINS, userId,null, false,
|
||||||
|
StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
|
||||||
//Display a preview for accounts that have replied *if enabled and only for home timeline*
|
//Display a preview for accounts that have replied *if enabled and only for home timeline*
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
|
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
|
||||||
boolean showPreview = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES, false);
|
boolean showPreview = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES, false);
|
||||||
|
@ -725,10 +736,10 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
||||||
holder.status_spoiler_button.setTextColor(ContextCompat.getColor(context, R.color.white));
|
holder.status_spoiler_button.setTextColor(ContextCompat.getColor(context, R.color.white));
|
||||||
}
|
}
|
||||||
|
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
final boolean isOwner = status.getAccount().getId().equals(userId);
|
final boolean isOwner = status.getAccount().getId().equals(userId);
|
||||||
|
|
||||||
if (isOwner) {
|
if (isOwner) {
|
||||||
|
|
||||||
imgPinToot = ContextCompat.getDrawable(context, R.drawable.ic_action_pin);
|
imgPinToot = ContextCompat.getDrawable(context, R.drawable.ic_action_pin);
|
||||||
imgPinToot.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f));
|
imgPinToot.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f));
|
||||||
|
|
||||||
|
@ -893,9 +904,22 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
||||||
* @param status Status
|
* @param status Status
|
||||||
*/
|
*/
|
||||||
private void pinAction(Status status) {
|
private void pinAction(Status status) {
|
||||||
// Checks for if status is already pinned & owned (Though maybe we can do this prior to getting here?
|
|
||||||
new PostActionAsyncTask(context, API.StatusAction.PIN, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
for (Status pin : pins) {
|
||||||
|
if (status.getId().equals(pin.getId()))
|
||||||
|
status.setPinned(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status.isPinned()) {
|
||||||
|
new PostActionAsyncTask(context, API.StatusAction.UNPIN, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
status.setPinned(false);
|
||||||
|
} else {
|
||||||
|
new PostActionAsyncTask(context, API.StatusAction.PIN, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
status.setPinned(true);
|
||||||
|
}
|
||||||
|
|
||||||
statusListAdapter.notifyDataSetChanged();
|
statusListAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadAttachments(final Status status, ViewHolder holder){
|
private void loadAttachments(final Status status, ViewHolder holder){
|
||||||
|
@ -981,6 +1005,19 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
||||||
holder.status_show_more.setVisibility(View.GONE);
|
holder.status_show_more.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRetrieveFeeds(APIResponse apiResponse, boolean refreshData) {
|
||||||
|
if( apiResponse.getError() != null){
|
||||||
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||||
|
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||||
|
if( show_error_messages)
|
||||||
|
Toast.makeText(context, apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pins = apiResponse.getStatuses();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPostAction(int statusCode, API.StatusAction statusAction, String targetedId, Error error) {
|
public void onPostAction(int statusCode, API.StatusAction statusAction, String targetedId, Error error) {
|
||||||
|
|
||||||
|
@ -988,7 +1025,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||||
if( show_error_messages)
|
if( show_error_messages)
|
||||||
Toast.makeText(context, error.getError(),Toast.LENGTH_LONG).show();
|
Toast.makeText(context, "Here: " + error.getError(),Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Helper.manageMessageStatusCode(context, statusCode, statusAction);
|
Helper.manageMessageStatusCode(context, statusCode, statusAction);
|
||||||
|
|
Loading…
Reference in New Issue