From 3e096aedfb1816007b40863e833aaaac36aa9fb1 Mon Sep 17 00:00:00 2001 From: stom79 Date: Tue, 15 Jan 2019 16:36:30 +0100 Subject: [PATCH] Prepare frontend 7 - Add boosts --- .../mastodon/activities/BaseMainActivity.java | 34 ++++++++++++--- .../asynctasks/RetrieveFeedsAsyncTask.java | 3 +- .../mastodon/drawers/PixelfedListAdapter.java | 43 ++++++++++++++++--- .../res/drawable-anydpi/ic_boost_pixelfed.xml | 9 ++++ app/src/main/res/layout/drawer_pixelfed.xml | 10 +++-- app/src/main/res/values/strings.xml | 1 + 6 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 app/src/main/res/drawable-anydpi/ic_boost_pixelfed.xml diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index a55fde827..59f6c74b6 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -885,12 +885,14 @@ public abstract class BaseMainActivity extends BaseActivity }else if (social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED){ TabLayout.Tab pfTabHome = tabLayout.newTab(); TabLayout.Tab pfTabLocal = tabLayout.newTab(); + TabLayout.Tab pfTabNotification = tabLayout.newTab(); //TabLayout.Tab pfTabDiscover = tabLayout.newTab(); pfTabHome.setCustomView(R.layout.tab_badge); pfTabLocal.setCustomView(R.layout.tab_badge); + pfTabNotification.setCustomView(R.layout.tab_badge); //pfTabDiscover.setCustomView(R.layout.tab_badge); @@ -910,6 +912,10 @@ public abstract class BaseMainActivity extends BaseActivity iconLocal.setImageResource(R.drawable.ic_people); + @SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId") + ImageView iconNotif = pfTabNotification.getCustomView().findViewById(R.id.tab_icon); + iconNotif.setImageResource(R.drawable.ic_notifications); + /*@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId") ImageView iconDiscover = pfTabDiscover.getCustomView().findViewById(R.id.tab_icon); iconDiscover.setImageResource(R.drawable.ic_people);*/ @@ -919,22 +925,25 @@ public abstract class BaseMainActivity extends BaseActivity iconHome.setContentDescription(getString(R.string.home_menu)); // iconDiscover.setContentDescription(getString(R.string.overview)); iconLocal.setContentDescription(getString(R.string.local)); - + iconNotif.setContentDescription(getString(R.string.notifications)); if (theme == THEME_LIGHT) { iconHome.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.action_light_header), PorterDuff.Mode.SRC_IN); // iconDiscover.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.action_light_header), PorterDuff.Mode.SRC_IN); iconLocal.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.action_light_header), PorterDuff.Mode.SRC_IN); + iconNotif.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.action_light_header), PorterDuff.Mode.SRC_IN); } else { iconHome.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN); // iconDiscover.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN); iconLocal.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN); + iconNotif.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN); } toot.setImageResource(R.drawable.ic_cloud_upload); tabLayout.addTab(pfTabHome); tabLayout.addTab(pfTabLocal); + tabLayout.addTab(pfTabNotification); // tabLayout.addTab(pfTabDiscover); @@ -2447,17 +2456,30 @@ public abstract class BaseMainActivity extends BaseActivity } //Selection comes from another menu, no action to do Bundle bundle = new Bundle(); - DisplayStatusFragment fragment = new DisplayStatusFragment(); + if (position == 0) { + DisplayStatusFragment fragment = new DisplayStatusFragment(); bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PF_HOME); + bundle.putString("instanceType","PIXELFED"); + fragment.setArguments(bundle); + return fragment; }else if( position == 1) { + DisplayStatusFragment fragment = new DisplayStatusFragment(); bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PF_LOCAL); - }/*else if( position == 2) { + bundle.putString("instanceType","PIXELFED"); + fragment.setArguments(bundle); + return fragment; + }else if( position == 2){ + DisplayNotificationsFragment fragment = new DisplayNotificationsFragment(); + bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PF_NOTIFICATION); + fragment.setArguments(bundle); + return fragment; + } + /*else if( position == 3) { bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PF_DISCOVER); }*/ - bundle.putString("instanceType","PIXELFED"); - fragment.setArguments(bundle); - return fragment; + + return null; } return null; } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java index adb059013..8156eccb5 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java @@ -89,7 +89,8 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { MYVIDEOS, PF_HOME, PF_LOCAL, - PF_DISCOVER + PF_DISCOVER, + PF_NOTIFICATION } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/PixelfedListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/PixelfedListAdapter.java index f0a2e78d0..c69debd6f 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/PixelfedListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/PixelfedListAdapter.java @@ -143,8 +143,8 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA private class ViewHolderPixelfed extends RecyclerView.ViewHolder{ - ImageView art_media, pf_pp, pf_comment, pf_share; - SparkButton pf_fav; + ImageView art_media, pf_pp, pf_comment; + SparkButton pf_fav, pf_share; TextView pf_username, pf_likes, pf_description, pf_date; CardView pf_cardview; LinearLayout pf_bottom_container; @@ -293,21 +293,21 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA if (theme == Helper.THEME_BLACK) { holder.pf_fav.setInActiveImageTint(R.color.action_black); + holder.pf_share.setInActiveImageTint(R.color.action_black); changeDrawableColor(context, R.drawable.ic_pixelfed_favorite_border, R.color.action_black); changeDrawableColor(context, holder.pf_comment, R.color.action_black); - changeDrawableColor(context, holder.pf_share, R.color.action_black); holder.pf_cardview.setCardBackgroundColor(ContextCompat.getColor(context, R.color.black_3)); } else if (theme == Helper.THEME_DARK) { holder.pf_fav.setInActiveImageTint(R.color.action_dark); + holder.pf_share.setInActiveImageTint(R.color.action_dark); changeDrawableColor(context, holder.pf_comment, R.color.action_dark); changeDrawableColor(context, R.drawable.ic_pixelfed_favorite_border, R.color.action_dark); - changeDrawableColor(context, holder.pf_share, R.color.action_dark); holder.pf_cardview.setCardBackgroundColor(ContextCompat.getColor(context, R.color.mastodonC1_)); } else { holder.pf_fav.setInActiveImageTint(R.color.action_light); + holder.pf_share.setInActiveImageTint(R.color.action_light); changeDrawableColor(context, holder.pf_comment, R.color.action_light); changeDrawableColor(context, R.drawable.ic_pixelfed_favorite_border, R.color.action_light); - changeDrawableColor(context, holder.pf_share, R.color.action_light); holder.pf_cardview.setCardBackgroundColor(ContextCompat.getColor(context, R.color.white)); } @@ -319,6 +319,13 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA holder.pf_fav.setActiveImageTint(R.color.pixelfed_like); holder.pf_fav.setColors(R.color.pixelfed_like, R.color.pixelfed_like); + holder.pf_share.pressOnTouch(false); + holder.pf_share.setActiveImage(R.drawable.ic_boost_pixelfed); + holder.pf_share.setInactiveImage(R.drawable.ic_boost_pixelfed); + holder.pf_share.setDisableCircle(true); + holder.pf_share.setActiveImageTint(R.color.boost_icon); + holder.pf_share.setColors(R.color.boost_icon, R.color.boost_icon); + if (!status.isFavAnimated()) { if (status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited())) { holder.pf_fav.setChecked(true); @@ -331,6 +338,19 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA holder.pf_fav.setAnimationSpeed(1.0f); holder.pf_fav.playAnimation(); } + + if (!status.isBoostAnimated()) { + if (status.isReblogged() || (status.getReblog() != null && status.getReblog().isReblogged())) { + holder.pf_share.setChecked(true); + } else { + holder.pf_share.setChecked(false); + } + } else { + status.setBoostAnimated(false); + holder.pf_share.setChecked(true); + holder.pf_share.setAnimationSpeed(1.0f); + holder.pf_share.playAnimation(); + } boolean confirmFav = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION_FAV, false); holder.pf_fav.setOnClickListener(new View.OnClickListener() { @Override @@ -344,6 +364,19 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA CrossActions.doCrossAction(context, type, status, null, (status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited())) ? API.StatusAction.UNFAVOURITE : API.StatusAction.FAVOURITE, pixelfedListAdapter, PixelfedListAdapter.this, true); } }); + boolean confirmBoost = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, false); + holder.pf_share.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (!status.isReblogged() && confirmBoost) + status.setBoostAnimated(true); + if (!status.isReblogged() && !confirmBoost) { + status.setBoostAnimated(true); + notifyStatusChanged(status); + } + CrossActions.doCrossAction(context, type, status, null, (status.isReblogged() || (status.getReblog() != null && status.getReblog().isReblogged())) ? API.StatusAction.UNREBLOG : API.StatusAction.REBLOG, pixelfedListAdapter, PixelfedListAdapter.this, true); + } + }); } } diff --git a/app/src/main/res/drawable-anydpi/ic_boost_pixelfed.xml b/app/src/main/res/drawable-anydpi/ic_boost_pixelfed.xml new file mode 100644 index 000000000..e7c67d710 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_boost_pixelfed.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/drawer_pixelfed.xml b/app/src/main/res/layout/drawer_pixelfed.xml index 7d0eac925..a3fbb4c05 100644 --- a/app/src/main/res/layout/drawer_pixelfed.xml +++ b/app/src/main/res/layout/drawer_pixelfed.xml @@ -87,14 +87,16 @@ android:src="@drawable/ic_pixelfed_comment" android:layout_width="30dp" android:layout_height="30dp" /> - + android:layout_height="30dp" + app:sparkbutton_iconSize="30dp"/> No videos to display! Add media to favorites Leave a comment + Share