Added code so that user can pin a toot.
Can't currently unpin one, nor see existing pinned toots. (API calls are coded). Work in Progress.
This commit is contained in:
parent
00ccdc42c9
commit
057a940a2e
|
@ -93,7 +93,9 @@ public class API {
|
|||
AUTHORIZE,
|
||||
REJECT,
|
||||
REPORT,
|
||||
REMOTE_FOLLOW
|
||||
REMOTE_FOLLOW,
|
||||
PIN,
|
||||
UNPIN
|
||||
}
|
||||
|
||||
public API(Context context) {
|
||||
|
@ -299,6 +301,37 @@ public class API {
|
|||
return getStatus(accountId, true, false, max_id, null, tootPerPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves pinned status(es) *synchronously*
|
||||
*
|
||||
* @param accountId String Id of the account
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getPinnedStatuses(String accountId)
|
||||
{
|
||||
RequestParams params = new RequestParams();
|
||||
|
||||
params.put("pinned", Boolean.toString(true));
|
||||
|
||||
get(String.format("/accounts/%s/statuses", accountId), params, new JsonHttpResponseHandler() {
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
|
||||
Status status = parseStatuses(context, response);
|
||||
statuses.add(status);
|
||||
}
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
|
||||
statuses = parseStatuses(response);
|
||||
}
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
|
||||
setError(statusCode, error);
|
||||
}
|
||||
});
|
||||
apiResponse.setStatuses(statuses);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves status for the account *synchronously*
|
||||
|
@ -835,6 +868,12 @@ public class API {
|
|||
case UNMUTE:
|
||||
action = String.format("/accounts/%s/unmute", targetedId);
|
||||
break;
|
||||
case PIN:
|
||||
action = String.format("/statuses/%s/pin", targetedId);
|
||||
break;
|
||||
case UNPIN:
|
||||
action = String.format("statuses/%s/unpin", targetedId);
|
||||
break;
|
||||
case UNSTATUS:
|
||||
action = String.format("/statuses/%s", targetedId);
|
||||
break;
|
||||
|
|
|
@ -91,7 +91,6 @@ import mastodon.etalab.gouv.fr.mastodon.R;
|
|||
|
||||
import static fr.gouv.etalab.mastodon.activities.MainActivity.currentLocale;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.shortnameToUnicode;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -465,7 +464,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
|
||||
//Redraws top icons (boost/reply)
|
||||
final float scale = context.getResources().getDisplayMetrics().density;
|
||||
if( !status.getIn_reply_to_account_id().equals("null") || !status.getIn_reply_to_id().equals("null") ){
|
||||
if( (status.getIn_reply_to_account_id()!= null && !status.getIn_reply_to_account_id().equals("null")) || (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null")) ){
|
||||
Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_reply);
|
||||
img.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (15 * iconSizePercent/100 * scale + 0.5f));
|
||||
holder.status_account_displayname.setCompoundDrawables( img, null, null, null);
|
||||
|
@ -1178,7 +1177,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
if( isOwner) {
|
||||
stringArray = context.getResources().getStringArray(R.array.more_action_owner);
|
||||
stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm);
|
||||
doAction = new API.StatusAction[]{API.StatusAction.UNSTATUS};
|
||||
doAction = new API.StatusAction[]{API.StatusAction.PIN,API.StatusAction.UNSTATUS};
|
||||
|
||||
}else {
|
||||
stringArray = context.getResources().getStringArray(R.array.more_action);
|
||||
|
@ -1290,7 +1289,9 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
doAction[position] == API.StatusAction.UNFAVOURITE ||
|
||||
doAction[position] == API.StatusAction.REBLOG ||
|
||||
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();
|
||||
else
|
||||
|
|
|
@ -525,6 +525,10 @@ public class Helper {
|
|||
message = context.getString(R.string.toast_favourite);
|
||||
}else if(statusAction == API.StatusAction.UNFAVOURITE){
|
||||
message = context.getString(R.string.toast_unfavourite);
|
||||
}else if(statusAction == API.StatusAction.PIN){
|
||||
message = context.getString(R.string.toast_pin);
|
||||
}else if (statusAction == API.StatusAction.UNPIN){
|
||||
message = context.getString(R.string.toast_unpin);
|
||||
}else if(statusAction == API.StatusAction.REPORT){
|
||||
message = context.getString(R.string.toast_report);
|
||||
}else if(statusAction == API.StatusAction.UNSTATUS){
|
||||
|
@ -1571,7 +1575,7 @@ public class Helper {
|
|||
navigationView.getMenu().findItem(R.id.nav_local).setVisible(false);
|
||||
navigationView.getMenu().findItem(R.id.nav_global).setVisible(false);
|
||||
navigationView.getMenu().findItem(R.id.nav_notification).setVisible(false);
|
||||
params.height = (int) Helper.convertDpToPixel(heightSearchdp, activity);;
|
||||
params.height = (int) Helper.convertDpToPixel(heightSearchdp, activity);
|
||||
toolbar_search_container.setLayoutParams(params);
|
||||
tableLayout.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
|
@ -1589,7 +1593,7 @@ public class Helper {
|
|||
navigationView.getMenu().findItem(R.id.nav_local).setVisible(true);
|
||||
navigationView.getMenu().findItem(R.id.nav_global).setVisible(true);
|
||||
navigationView.getMenu().findItem(R.id.nav_notification).setVisible(true);
|
||||
params.height = (int) Helper.convertDpToPixel(heightSearchdp, activity);;
|
||||
params.height = (int) Helper.convertDpToPixel(heightSearchdp, activity);
|
||||
toolbar_search_container.setLayoutParams(params);
|
||||
tableLayout.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
|
@ -1665,7 +1669,8 @@ public class Helper {
|
|||
Gson gson = new Gson();
|
||||
String json = sharedpreferences.getString(Helper.SET_TEMP_STATUS + userId, null);
|
||||
Type type = new TypeToken<ArrayList<Status>>() {}.getType();
|
||||
return gson.fromJson(json, type);
|
||||
ArrayList<Status> statuses = gson.fromJson(json, type);
|
||||
return (statuses != null)?statuses:new ArrayList<Status>();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1713,7 +1718,8 @@ public class Helper {
|
|||
Gson gson = new Gson();
|
||||
String json = sharedpreferences.getString(Helper.SET_TEMP_NOTIFICATIONS + userId, null);
|
||||
Type type = new TypeToken<ArrayList<Notification>>() {}.getType();
|
||||
return gson.fromJson(json, type);
|
||||
ArrayList<Notification> notifications = gson.fromJson(json, type);
|
||||
return (notifications != null)?notifications:new ArrayList<Notification>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -105,6 +105,7 @@
|
|||
<item>Share</item>
|
||||
</string-array>
|
||||
<string-array name="more_action_owner">
|
||||
<item>Pin</item>
|
||||
<item>Remove</item>
|
||||
<item>Copy</item>
|
||||
<item>Share</item>
|
||||
|
@ -125,6 +126,7 @@
|
|||
</string-array>
|
||||
|
||||
<string-array name="more_action_owner_confirm">
|
||||
<item>Pin this toot?</item>
|
||||
<item>Remove this toot?</item>
|
||||
<item>null</item> <!-- Ugly hack to fix confirm box-->
|
||||
<item>null</item>
|
||||
|
@ -261,6 +263,8 @@
|
|||
<string name="toast_unfavourite">The toot was removed from your favourites!</string>
|
||||
<string name="toast_report">The toot was reported!</string>
|
||||
<string name="toast_unstatus">The toot was deleted!</string>
|
||||
<string name="toast_pin">The toot was pinned!</string>
|
||||
<string name="toast_unpin">The toot was unpinned!</string>
|
||||
<string name="toast_error">Oops ! An error occurred!</string>
|
||||
<string name="toast_code_error">An error occurred! The instance did not return an authorisation code!</string>
|
||||
<string name="toast_error_instance">The instance domain does not seem to be valide!</string>
|
||||
|
|
Loading…
Reference in New Issue