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 bd85c0dc6..b2eda1a6b 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 @@ -3141,7 +3141,7 @@ public abstract class BaseMainActivity extends BaseActivity DisplayStatusFragment statusFragment; Bundle bundle = new Bundle(); statusFragment = new DisplayStatusFragment(); - bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PIXELFED); + bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE); bundle.putString("remote_instance", remoteInstance.getHost()); bundle.putString("instanceType", "PIXELFED"); statusFragment.setArguments(bundle); @@ -3209,6 +3209,7 @@ public abstract class BaseMainActivity extends BaseActivity bundle.putString("remote_instance", remoteInstance.getHost()); statusFragment.setArguments(bundle); String fragmentTag = "REMOTE_INSTANCE"; + bundle.putString("instanceType", "PEERTUBE"); instance_id = remoteInstance.getDbID(); FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction() 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 92750312b..753d4abd3 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 @@ -173,9 +173,6 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { case CONVERSATION: apiResponse = api.getConversationTimeline(max_id); break; - case PIXELFED: - apiResponse = api.getPixelfedTimeline(instanceName, max_id); - break; case REMOTE_INSTANCE: if( this.name != null && this.remoteInstance != null){ //For Peertube channels apiResponse = api.getPeertubeChannelVideos(this.remoteInstance, this.name); @@ -197,7 +194,9 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { status.setType(action); } } - } else { + } else if(remoteInstanceObj != null && remoteInstanceObj.size() > 0 && remoteInstanceObj.get(0).getType().equals("PIXELFED") ) { + apiResponse = api.getPixelfedTimeline(instanceName, max_id); + }else { apiResponse = api.getPeertube(this.instanceName, max_id); } } 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 6a4af5d2e..94d5a5ca4 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 @@ -23,13 +23,13 @@ import android.graphics.Bitmap; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; +import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; @@ -68,6 +68,8 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRepliesInterface; import fr.gouv.etalab.mastodon.sqlite.Sqlite; import fr.gouv.etalab.mastodon.sqlite.StatusCacheDAO; +import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor; + /** * Created by Thomas on 14/01/2019. @@ -137,20 +139,21 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA private class ViewHolderPixelfed extends RecyclerView.ViewHolder{ - ImageView art_media, art_pp; - TextView art_username, art_acct; - LinearLayout art_author; - RelativeLayout status_show_more; - ImageView show_more_button_art; + ImageView art_media, pf_pp, pf_fav, pf_comment, pf_share; + TextView pf_username, pf_likes, pf_description, pf_date; + CardView pf_cardview; ViewHolderPixelfed(View itemView) { super(itemView); art_media = itemView.findViewById(R.id.art_media); - art_pp = itemView.findViewById(R.id.art_pp); - art_username = itemView.findViewById(R.id.art_username); - art_acct = itemView.findViewById(R.id.art_acct); - art_author = itemView.findViewById(R.id.art_author); - status_show_more = itemView.findViewById(R.id.status_show_more); - show_more_button_art = itemView.findViewById(R.id.show_more_button_art); + pf_pp = itemView.findViewById(R.id.pf_pp); + pf_username = itemView.findViewById(R.id.pf_username); + pf_likes = itemView.findViewById(R.id.pf_likes); + pf_description = itemView.findViewById(R.id.pf_description); + pf_date = itemView.findViewById(R.id.pf_date); + pf_fav = itemView.findViewById(R.id.pf_fav); + pf_comment = itemView.findViewById(R.id.pf_comment); + pf_share = itemView.findViewById(R.id.pf_share); + pf_cardview = itemView.findViewById(R.id.pf_cardview); } } @@ -175,7 +178,7 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - if( viewType != DISPLAYED_STATUS) + if( viewType == DISPLAYED_STATUS) return new ViewHolderPixelfed(layoutInflater.inflate(R.layout.drawer_pixelfed, parent, false)); else return new ViewHolderEmpty(layoutInflater.inflate(R.layout.drawer_empty, parent, false)); @@ -199,8 +202,8 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA if (status.getAccount() != null && status.getAccount().getAvatar() != null) Glide.with(context) .load(status.getAccount().getAvatar()) - .apply(new RequestOptions().transforms(new FitCenter(), new RoundedCorners(10))) - .into(holder.art_pp); + .apply(new RequestOptions().transforms(new FitCenter(), new RoundedCorners(270))) + .into(holder.pf_pp); boolean expand_media = sharedpreferences.getBoolean(Helper.SET_EXPAND_MEDIA, false); if (status.getMedia_attachments() != null && status.getMedia_attachments().size() > 0) @@ -221,28 +224,9 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA } }) .into(holder.art_media); - RelativeLayout.LayoutParams rel_btn = new RelativeLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, holder.art_media.getHeight()); - holder.status_show_more.setLayoutParams(rel_btn); - if (expand_media || !status.isSensitive()) { - status.setAttachmentShown(true); - holder.status_show_more.setVisibility(View.GONE); - } else { - if (!status.isAttachmentShown()) { - holder.status_show_more.setVisibility(View.VISIBLE); - } else { - holder.status_show_more.setVisibility(View.GONE); - } - } - holder.show_more_button_art.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - status.setAttachmentShown(true); - notifyStatusChanged(status); - } - }); - holder.art_pp.setOnClickListener(new View.OnClickListener() { + holder.pf_likes.setText(context.getResources().getQuantityString(R.plurals.likes, status.getFavourites_count(), status.getFavourites_count())); + holder.pf_pp.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) { @@ -273,7 +257,9 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA context.startActivity(intent); } }); - holder.art_author.setOnClickListener(new View.OnClickListener() { + holder.pf_description.setText(status.getContentSpan(), TextView.BufferType.SPANNABLE); + holder.pf_date.setText(Helper.dateToString(status.getCreated_at())); + holder.pf_description.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) { @@ -289,11 +275,27 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA }); if (status.getDisplayNameSpan() != null && status.getDisplayNameSpan().toString().trim().length() > 0) - holder.art_username.setText(status.getDisplayNameSpan(), TextView.BufferType.SPANNABLE); + holder.pf_username.setText(status.getDisplayNameSpan(), TextView.BufferType.SPANNABLE); else - holder.art_username.setText(status.getAccount().getUsername()); + holder.pf_username.setText(status.getAccount().getUsername()); + int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); - holder.art_acct.setText(String.format("@%s", status.getAccount().getAcct())); + if (theme == Helper.THEME_BLACK) { + changeDrawableColor(context, holder.pf_fav, 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) { + changeDrawableColor(context, holder.pf_fav, R.color.action_dark); + changeDrawableColor(context, holder.pf_comment, R.color.action_dark); + changeDrawableColor(context, holder.pf_share, R.color.action_dark); + holder.pf_cardview.setCardBackgroundColor(ContextCompat.getColor(context, R.color.mastodonC1_)); + } else { + changeDrawableColor(context, holder.pf_fav, R.color.action_light); + changeDrawableColor(context, holder.pf_comment, R.color.action_light); + changeDrawableColor(context, holder.pf_share, R.color.action_light); + holder.pf_cardview.setCardBackgroundColor(ContextCompat.getColor(context, R.color.white)); + } } } 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 13899cfd1..87740c751 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 @@ -32,6 +32,7 @@ import android.support.v4.content.LocalBroadcastManager; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -212,6 +213,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn peertubeAdapater = new PeertubeAdapter(context, remoteInstance, ownVideos, this.peertubes); lv_status.setAdapter(peertubeAdapater); }else if( instanceType.equals("PIXELFED")){ + if( remoteInstance != null && MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) //if it's a Peertube account connected + remoteInstance = account.getInstance(); pixelfedListAdapter = new PixelfedListAdapter(context, this.statuses); lv_status.setAdapter(pixelfedListAdapter); }else if( instanceType.equals("ART")){ @@ -447,7 +450,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn //remove handlers swipeRefreshLayout.setRefreshing(false); if( firstLoad && (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() ==0)){ - textviewNoActionText.setText(R.string.no_video_uploaded); + textviewNoActionText.setText(R.string.no_video_to_display); textviewNoAction.setVisibility(View.VISIBLE); } flag_loading = false; @@ -478,7 +481,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn int previousPosition = this.statuses.size(); List statuses = apiResponse.getStatuses(); //At this point all statuses are in "List statuses" - //Pagination for Pixelfed if(instanceType.equals("PIXELFED")) { if( max_id == null) @@ -526,6 +528,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn artListAdapter.notifyItemRangeInserted(previousPosition, statuses.size()); } }else if(instanceType.equals("PIXELFED") ) { + Log.v(Helper.TAG,"statuses: " + statuses.size()); this.statuses.addAll(statuses); pixelfedListAdapter.notifyItemRangeInserted(previousPosition, statuses.size()); } diff --git a/app/src/main/res/drawable-anydpi/ic_pixelfed_comment.xml b/app/src/main/res/drawable-anydpi/ic_pixelfed_comment.xml new file mode 100644 index 000000000..880a1b1a9 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_pixelfed_comment.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable-anydpi/ic_pixelfed_favorite_border.xml b/app/src/main/res/drawable-anydpi/ic_pixelfed_favorite_border.xml new file mode 100644 index 000000000..0cfbad645 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_pixelfed_favorite_border.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 af52afc60..945e6308f 100644 --- a/app/src/main/res/layout/drawer_pixelfed.xml +++ b/app/src/main/res/layout/drawer_pixelfed.xml @@ -18,61 +18,99 @@ - + - + + + + - - - - + android:orientation="vertical"> + + + + + + + + + - - - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a07acc175..09ede2fab 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -250,6 +250,10 @@ and another toot to discover and %d other toots to discover + + %d like + %d likes + Delete a notification? Delete all notifications? The notification has been deleted! @@ -819,6 +823,9 @@ No videos uploaded yet! Display NSFW videos Default %s channel + No videos to display! + Add media to favorites + Leave a comment