Pinned toots are only accessible from authenticated account, so I changed the way they are displayed in ShowAccountActivity

This commit is contained in:
tom79 2017-09-15 19:51:41 +02:00
parent 03c09c8465
commit a84a478969
13 changed files with 50 additions and 83 deletions

View File

@ -20,7 +20,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
@ -49,7 +48,6 @@ import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@ -93,8 +91,6 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAccountInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsAccountInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRelationshipInterface;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import mastodon.etalab.gouv.fr.mastodon.R;
import fr.gouv.etalab.mastodon.client.Entities.Relationship;
@ -115,7 +111,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
private StatusListAdapter statusListAdapter;
private FloatingActionButton account_follow;
private static final int NUM_PAGES = 4;
private static final int NUM_PAGES = 3;
private ViewPager mPager;
private String accountId;
private TabLayout tabLayout;
@ -123,7 +119,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
private String userId;
private static int instanceValue = 0;
private Relationship relationship;
private boolean showMediaOnly;
private boolean showMediaOnly, showPinned;
private ImageView pp_actionBar;
private BroadcastReceiver hide_header;
private boolean isHiddingShowing = false;
@ -166,13 +162,11 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
new RetrieveAccountAsyncTask(getApplicationContext(),accountId, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
// Get the pins, as early as we can
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.PINS, userId, null, false,
ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
Toast.makeText(this,R.string.toast_error_loading_account,Toast.LENGTH_LONG).show();
}
showMediaOnly = false;
showPinned = false;
imageLoader = ImageLoader.getInstance();
File cacheDir = new File(getCacheDir(), getString(R.string.app_name));
ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(this)
@ -202,7 +196,6 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.following)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.followers)));
mPager = (ViewPager) findViewById(R.id.account_viewpager);
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
@ -252,11 +245,6 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
if (displayAccountsFragment != null)
displayAccountsFragment.scrollToTop();
break;
case 3:
displayStatusFragment = ((DisplayStatusFragment) fragment);
if( displayStatusFragment != null )
displayStatusFragment.scrollToTop();
break;
}
}
});
@ -346,6 +334,9 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_showaccount, menu);
if( !Helper.canPin || !accountId.equals(userId)) {
menu.findItem(R.id.action_show_pinned).setVisible(false);
}
return true;
}
@ -355,6 +346,14 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
case android.R.id.home:
finish();
return true;
case R.id.action_show_pinned:
showPinned = !showPinned;
if( tabLayout.getTabAt(0) != null)
//noinspection ConstantConditions
tabLayout.getTabAt(0).select();
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
return true;
case R.id.action_show_media:
showMediaOnly = !showMediaOnly;
if( showMediaOnly )
@ -364,7 +363,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
if( tabLayout.getTabAt(0) != null)
//noinspection ConstantConditions
tabLayout.getTabAt(0).select();
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
return true;
default:
@ -503,6 +502,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
tabLayout.getTabAt(1).setText(getString(R.string.following_cnt, account.getFollowing_count()));
//noinspection ConstantConditions
tabLayout.getTabAt(2).setText(getString(R.string.followers_cnt, account.getFollowers_count()));
}
imageLoader.displayImage(account.getAvatar(), account_pp, options);
@ -528,11 +528,11 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
Toast.makeText(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
return;
}
pins = apiResponse.getStatuses();
if (pins != null && pins.size() > 0) {
if( pins.get(0).isPinned()) {
tabLayout.addTab(tabLayout.newTab().setText(R.string.pinned_toots));
for (Status pin : pins) {
this.statuses.add(pin);
}
@ -614,6 +614,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
bundle.putString("targetedId", accountId);
bundle.putBoolean("hideHeader",true);
bundle.putBoolean("showMediaOnly",showMediaOnly);
bundle.putBoolean("showPinned",showPinned);
bundle.putString("hideHeaderValue",String.valueOf(instanceValue));
displayStatusFragment.setArguments(bundle);
return displayStatusFragment;
@ -633,15 +634,6 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
bundle.putString("hideHeaderValue",String.valueOf(instanceValue));
displayAccountsFragment.setArguments(bundle);
return displayAccountsFragment;
case 3:
displayStatusFragment = new DisplayStatusFragment();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PINS);
bundle.putString("targetedId", userId);
bundle.putBoolean("hideHeader",true);
bundle.putBoolean("showMediaOnly",showMediaOnly);
bundle.putString("hideHeaderValue",String.valueOf(instanceValue));
displayStatusFragment.setArguments(bundle);
return displayStatusFragment;
}
return null;
}

View File

@ -161,7 +161,7 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet
isRefreshed = false;
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeContainer);
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.ONESTATUS, statusId,null, false, ShowConversationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.ONESTATUS, statusId,null, false,false, ShowConversationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if( theme == Helper.THEME_LIGHT) {
swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent,
@ -176,7 +176,7 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet
@Override
public void onRefresh() {
isRefreshed = true;
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.ONESTATUS, statusId,null, false, ShowConversationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.ONESTATUS, statusId,null, false,false, ShowConversationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
lv_status = (ListView) findViewById(R.id.lv_status);
@ -193,7 +193,7 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet
@Override
public void run() {
isRefreshed = true;
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.ONESTATUS, statusId,null, false, ShowConversationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.ONESTATUS, statusId,null, false, false, ShowConversationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}, 1000);

View File

@ -39,6 +39,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
private String targetedID;
private String tag;
private boolean showMediaOnly = false;
private boolean showPinned = false;
private boolean refreshData;
public enum Type{
@ -50,8 +51,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
FAVOURITES,
ONESTATUS,
CONTEXT,
TAG,
PINS
TAG
}
public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
@ -62,7 +62,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
this.refreshData = true;
}
public RetrieveFeedsAsyncTask(Context context, Type action, String targetedID, String max_id, boolean showMediaOnly, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
public RetrieveFeedsAsyncTask(Context context, Type action, String targetedID, String max_id, boolean showMediaOnly, boolean showPinned, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
this.context = context;
this.action = action;
this.max_id = max_id;
@ -70,6 +70,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
this.targetedID = targetedID;
this.showMediaOnly = showMediaOnly;
this.refreshData = true;
this.showPinned = showPinned;
}
public RetrieveFeedsAsyncTask(Context context, Type action, String tag, String targetedID, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
this.context = context;
@ -99,10 +100,12 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
apiResponse = api.getFavourites(max_id);
break;
case USER:
if( !showMediaOnly)
apiResponse = api.getStatus(targetedID, max_id);
else
if( showMediaOnly)
apiResponse = api.getStatusWithMedia(targetedID, max_id);
else if (showPinned)
apiResponse = api.getPinnedStatuses(targetedID, max_id);
else
apiResponse = api.getStatus(targetedID, max_id);
break;
case ONESTATUS:
apiResponse = api.getStatusbyId(targetedID);
@ -110,9 +113,6 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
case TAG:
apiResponse = api.getPublicTimelineTag(tag, false, max_id);
break;
case PINS:
apiResponse = api.getPinnedStatuses(targetedID); // Might need max_id later?
break;
case HASHTAG:
break;
}

View File

@ -68,7 +68,6 @@ public class API {
private Attachment attachment;
private List<Account> accounts;
private List<Status> statuses;
private List<Status> pins;
private List<Notification> notifications;
private int tootPerPage, accountPerPage, notificationPerPage;
private int actionCode;
@ -277,7 +276,7 @@ public class API {
* @return APIResponse
*/
public APIResponse getStatus(String accountId) {
return getStatus(accountId, false, false, null, null, tootPerPage);
return getStatus(accountId, false, false, false, null, null, tootPerPage);
}
/**
@ -288,7 +287,7 @@ public class API {
* @return APIResponse
*/
public APIResponse getStatus(String accountId, String max_id) {
return getStatus(accountId, false, false, max_id, null, tootPerPage);
return getStatus(accountId, false, false, false, max_id, null, tootPerPage);
}
/**
@ -299,43 +298,20 @@ public class API {
* @return APIResponse
*/
public APIResponse getStatusWithMedia(String accountId, String max_id) {
return getStatus(accountId, true, false, max_id, null, tootPerPage);
return getStatus(accountId, true, false, false, max_id, null, tootPerPage);
}
/**
* Retrieves pinned status(es) *synchronously*
*
* @param accountId String Id of the account
* @param max_id String id max
* @return APIResponse
*/
public APIResponse getPinnedStatuses(String accountId)
{
pins = new ArrayList<>();
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);
pins.add(status);
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
pins = parseStatuses(response);
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
apiResponse.setStatuses(pins);
return apiResponse;
public APIResponse getPinnedStatuses(String accountId, String max_id) {
return getStatus(accountId, false, true, false, max_id, null, tootPerPage);
}
/**
* Retrieves status for the account *synchronously*
*
@ -347,7 +323,7 @@ public class API {
* @param limit int limit - max value 40
* @return APIResponse
*/
private APIResponse getStatus(String accountId, boolean onlyMedia,
private APIResponse getStatus(String accountId, boolean onlyMedia, boolean pinned,
boolean exclude_replies, String max_id, String since_id, int limit) {
RequestParams params = new RequestParams();
@ -361,6 +337,8 @@ public class API {
limit = 40;
if( onlyMedia)
params.put("only_media", Boolean.toString(true));
if( pinned)
params.put("pinned", Boolean.toString(true));
params.put("limit", String.valueOf(limit));
statuses = new ArrayList<>();
get(String.format("/accounts/%s/statuses", accountId), params, new JsonHttpResponseHandler() {

View File

@ -232,10 +232,6 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
// Get the pins, as early as we can
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*
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
boolean showPreview = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES, false);

View File

@ -71,7 +71,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
private ListView lv_status;
private boolean isOnWifi;
private int behaviorWithAttachments;
private boolean showMediaOnly;
private boolean showMediaOnly, showPinned;
private int positionSpinnerTrans;
private boolean hideHeader;
private String instanceValue;
@ -90,6 +90,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
boolean comesFromSearch = false;
hideHeader = false;
showMediaOnly = false;
showPinned = false;
if (bundle != null) {
type = (RetrieveFeedsAsyncTask.Type) bundle.get("type");
targetedId = bundle.getString("targetedId", null);
@ -97,6 +98,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
instanceValue = bundle.getString("hideHeaderValue", null);
hideHeader = bundle.getBoolean("hideHeader", false);
showMediaOnly = bundle.getBoolean("showMediaOnly",false);
showPinned = bundle.getBoolean("showPinned",false);
if( bundle.containsKey("statuses")){
ArrayList<Parcelable> statusesReceived = bundle.getParcelableArrayList("statuses");
assert statusesReceived != null;
@ -162,11 +164,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
if(!flag_loading ) {
flag_loading = true;
if( type == RetrieveFeedsAsyncTask.Type.USER)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if ( type == RetrieveFeedsAsyncTask.Type.PINS)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, false, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -189,11 +189,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
swiped = true;
MainActivity.countNewStatus = 0;
if( type == RetrieveFeedsAsyncTask.Type.USER)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if ( type == RetrieveFeedsAsyncTask.Type.PINS)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, false, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@ -203,11 +201,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
R.color.mastodonC3);
if( type == RetrieveFeedsAsyncTask.Type.USER)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if ( type == RetrieveFeedsAsyncTask.Type.PINS)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, false, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 575 B

After

Width:  |  Height:  |  Size: 495 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 318 B

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 470 B

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 400 B

After

Width:  |  Height:  |  Size: 640 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 979 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_show_pinned"
android:title="@string/pinned_toots"
android:icon="@drawable/ic_action_pin"
app:showAsAction="always" />
<item
android:id="@+id/action_show_media"
android:title="@string/media"