From 9626ec9977a018cb542460093e54748ec6e93a40 Mon Sep 17 00:00:00 2001 From: PhotonQyv Date: Thu, 14 Sep 2017 21:29:49 +0100 Subject: [PATCH] Added code to display the pinned toots in the ShowAccountActivity. The counter works, even though the thumb tacks don't quite, due to my code in DisplayStatusFragment not being quite right. --- .../activities/ShowAccountActivity.java | 56 +++++++++++++++++-- .../mastodon/drawers/StatusListAdapter.java | 2 +- .../fragments/DisplayStatusFragment.java | 6 ++ app/src/main/res/values/strings.xml | 2 + 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java index 577cbcff8..8eacbbdef 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java @@ -78,6 +78,7 @@ import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveRelationshipAsyncTask; import fr.gouv.etalab.mastodon.client.API; +import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Error; import fr.gouv.etalab.mastodon.client.Entities.Status; @@ -89,6 +90,7 @@ import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface; 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; @@ -103,7 +105,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor; * Show account activity class */ -public class ShowAccountActivity extends AppCompatActivity implements OnPostActionInterface, OnRetrieveAccountInterface, OnRetrieveFeedsAccountInterface, OnRetrieveRelationshipInterface { +public class ShowAccountActivity extends AppCompatActivity implements OnPostActionInterface, OnRetrieveAccountInterface, OnRetrieveFeedsAccountInterface, OnRetrieveRelationshipInterface, OnRetrieveFeedsInterface { private ImageLoader imageLoader; @@ -112,7 +114,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi private StatusListAdapter statusListAdapter; private FloatingActionButton account_follow; - private static final int NUM_PAGES = 3; + private static final int NUM_PAGES = 4; private ViewPager mPager; private String accountId; private TabLayout tabLayout; @@ -126,6 +128,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi private boolean isHiddingShowing = false; private LinearLayout main_header_container; private ImageView header_edit_profile; + private List pins; public enum action{ FOLLOW, @@ -149,6 +152,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi setContentView(R.layout.activity_show_account); setTitle(""); instanceValue += 1; + pins = new ArrayList<>(); Bundle b = getIntent().getExtras(); account_follow = (FloatingActionButton) findViewById(R.id.account_follow); account_follow_request = (TextView) findViewById(R.id.account_follow_request); @@ -160,6 +164,10 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi new RetrieveRelationshipAsyncTask(getApplicationContext(), accountId,ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 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(); } @@ -192,6 +200,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.toots))); tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.following))); tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.followers))); + tabLayout.addTab(tabLayout.newTab().setText(R.string.pinned_toots)); mPager = (ViewPager) findViewById(R.id.account_viewpager); PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); @@ -242,6 +251,11 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi if (displayAccountsFragment != null) displayAccountsFragment.scrollToTop(); break; + case 3: + displayStatusFragment = ((DisplayStatusFragment) fragment); + if( displayStatusFragment != null ) + displayStatusFragment.scrollToTop(); + break; } } }); @@ -481,7 +495,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi SpannableString spannableString = Helper.clickableElementsDescription(ShowAccountActivity.this, account.getNote()); account_note.setText(spannableString, TextView.BufferType.SPANNABLE); account_note.setMovementMethod(LinkMovementMethod.getInstance()); - if (tabLayout.getTabAt(0) != null && tabLayout.getTabAt(1) != null && tabLayout.getTabAt(2) != null) { + if (tabLayout.getTabAt(0) != null && tabLayout.getTabAt(1) != null && tabLayout.getTabAt(2) != null && tabLayout.getTabAt(3) != null) { //noinspection ConstantConditions tabLayout.getTabAt(0).setText(getString(R.string.status_cnt, account.getStatuses_count())); //noinspection ConstantConditions @@ -489,6 +503,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi //noinspection ConstantConditions tabLayout.getTabAt(2).setText(getString(R.string.followers_cnt, account.getFollowers_count())); } + imageLoader.displayImage(account.getAvatar(), account_pp, options); } } @@ -503,6 +518,30 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi } } + @Override + public void onRetrieveFeeds(APIResponse apiResponse, boolean refreshData) { + if( apiResponse.getError() != null){ + final SharedPreferences sharedpreferences = getApplicationContext().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(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show(); + return; + } + + pins = apiResponse.getStatuses(); + + if (pins != null) + { + for (Status pin : pins) + { + this.statuses.add(pin); + } + + tabLayout.getTabAt(3).setText(getString(R.string.pins_cnt, pins.size())); + statusListAdapter.notifyDataSetChanged(); + } + } + @Override public void onRetrieveRelationship(Relationship relationship, Error error) { @@ -557,7 +596,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi } /** - * Pager adapter for the 3 fragments + * Pager adapter for the 4 fragments */ private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { ScreenSlidePagerAdapter(FragmentManager fm) { @@ -593,6 +632,15 @@ 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; } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index a5d218881..a2f49dfc9 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -240,7 +240,7 @@ 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, + 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* diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java index 246bea3ef..27cb54e75 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java @@ -165,6 +165,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, 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); @@ -190,6 +192,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, 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); } @@ -202,6 +206,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, 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 { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 672fe2b5e..fb886c167 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -214,6 +214,7 @@ Toots \n %d Following \n %d Followers \n %d + Pinned \n %d Authorize Reject @@ -248,6 +249,7 @@ Following Followers + Pinned Unable to get client id! No Internet connection!