Updated to change icon when a toot has been pinned.

This commit is contained in:
PhotonQyv 2017-09-13 21:02:55 +01:00
parent c4c26742d4
commit 793c77f2ab
1 changed files with 38 additions and 16 deletions

View File

@ -113,6 +113,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
private final int REBLOG = 1; private final int REBLOG = 1;
private final int FAVOURITE = 2; private final int FAVOURITE = 2;
private final int PIN = 3; private final int PIN = 3;
private final int UNPIN = 4;
private RetrieveFeedsAsyncTask.Type type; private RetrieveFeedsAsyncTask.Type type;
private String targetedId; private String targetedId;
private HashMap<String, String> urlConversion; private HashMap<String, String> urlConversion;
@ -714,7 +715,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
holder.status_privacy.setImageResource(R.drawable.ic_local_post_office); holder.status_privacy.setImageResource(R.drawable.ic_local_post_office);
break; break;
} }
Drawable imgFav, imgReblog, imgPinToot; Drawable imgFav, imgReblog;
if( status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited())) if( status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited()))
imgFav = ContextCompat.getDrawable(context, R.drawable.ic_fav_yellow); imgFav = ContextCompat.getDrawable(context, R.drawable.ic_fav_yellow);
else else
@ -739,15 +740,26 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
final boolean isOwner = status.getAccount().getId().equals(userId); final boolean isOwner = status.getAccount().getId().equals(userId);
if (isOwner) { if (isOwner) {
Drawable imgUnPinToot, imgPinToot;
imgUnPinToot = ContextCompat.getDrawable(context, R.drawable.ic_action_pin);
imgPinToot = ContextCompat.getDrawable(context, R.drawable.ic_action_pin_yellow);
imgPinToot = ContextCompat.getDrawable(context, R.drawable.ic_action_pin); imgUnPinToot.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)); imgPinToot.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f));
if (status.isPinned()) {
holder.status_pin.setImageDrawable(imgPinToot);
} else {
holder.status_pin.setImageDrawable(imgUnPinToot);
}
holder.status_pin.setOnClickListener(new View.OnClickListener() { holder.status_pin.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Toast.makeText(context, "Clicked on Pin", Toast.LENGTH_SHORT).show(); /* Code is in for displayConfirmationDialog() but we don't call it.
//displayConfirmationDialog(PIN,status); * Need to make sure we can successfully get a pinned toots list by
* this point, after async call earlier.
*/
pinAction(status); pinAction(status);
} }
}); });
@ -905,6 +917,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
*/ */
private void pinAction(Status status) { private void pinAction(Status status) {
// Assuming that by this point pins list has already been set up.
for (Status pin : pins) { for (Status pin : pins) {
if (status.getId().equals(pin.getId())) if (status.getId().equals(pin.getId()))
status.setPinned(true); status.setPinned(true);
@ -913,6 +926,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
if (status.isPinned()) { if (status.isPinned()) {
new PostActionAsyncTask(context, API.StatusAction.UNPIN, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new PostActionAsyncTask(context, API.StatusAction.UNPIN, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
status.setPinned(false); status.setPinned(false);
} else { } else {
new PostActionAsyncTask(context, API.StatusAction.PIN, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new PostActionAsyncTask(context, API.StatusAction.PIN, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
status.setPinned(true); status.setPinned(true);
@ -1021,11 +1035,12 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
@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) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
if( error != null){ if( error != null){
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, "Here: " + error.getError(),Toast.LENGTH_LONG).show(); Toast.makeText(context, error.getError(),Toast.LENGTH_LONG).show();
return; return;
} }
Helper.manageMessageStatusCode(context, statusCode, statusAction); Helper.manageMessageStatusCode(context, statusCode, statusAction);
@ -1046,6 +1061,15 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
statuses.removeAll(statusesToRemove); statuses.removeAll(statusesToRemove);
statusListAdapter.notifyDataSetChanged(); statusListAdapter.notifyDataSetChanged();
} }
// Need to refresh the list of pins
else if ( statusAction == API.StatusAction.PIN || statusAction == API.StatusAction.UNPIN ) {
String accountId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.PINS, accountId, null, false,
StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
} }
@Override @Override
@ -1207,14 +1231,12 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
title = context.getString(R.string.reblog_remove); title = context.getString(R.string.reblog_remove);
else else
title = context.getString(R.string.reblog_add); title = context.getString(R.string.reblog_add);
} }else if ( action == PIN) {
else if ( action == PIN){
//Checks for pinned toot to be done
// If not already pinned...
title = context.getString(R.string.pin_add); title = context.getString(R.string.pin_add);
// else }else if (action == UNPIN) {
// title = context.getString(R.string.pin_remove); title = context.getString(R.string.pin_remove);
} }
AlertDialog.Builder builder = new AlertDialog.Builder(context); AlertDialog.Builder builder = new AlertDialog.Builder(context);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
@ -1233,6 +1255,8 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
favouriteAction(status); favouriteAction(status);
else if ( action == PIN) else if ( action == PIN)
pinAction(status); pinAction(status);
else if ( action == UNPIN)
pinAction(status);
dialog.dismiss(); dialog.dismiss();
} }
}) })
@ -1263,7 +1287,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
if( isOwner) { if( isOwner) {
stringArray = context.getResources().getStringArray(R.array.more_action_owner); stringArray = context.getResources().getStringArray(R.array.more_action_owner);
stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm); stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm);
doAction = new API.StatusAction[]{API.StatusAction.PIN,API.StatusAction.UNSTATUS}; doAction = new API.StatusAction[]{API.StatusAction.UNSTATUS};
}else { }else {
stringArray = context.getResources().getStringArray(R.array.more_action); stringArray = context.getResources().getStringArray(R.array.more_action);
@ -1375,9 +1399,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
doAction[position] == API.StatusAction.UNFAVOURITE || doAction[position] == API.StatusAction.UNFAVOURITE ||
doAction[position] == API.StatusAction.REBLOG || doAction[position] == API.StatusAction.REBLOG ||
doAction[position] == API.StatusAction.UNREBLOG || doAction[position] == API.StatusAction.UNREBLOG ||
doAction[position] == API.StatusAction.UNSTATUS || doAction[position] == API.StatusAction.UNSTATUS
doAction[position] == API.StatusAction.PIN ||
doAction[position] == API.StatusAction.UNPIN
) )
targetedId = status.getId(); targetedId = status.getId();
else else