From 61d907308cd0944e99ef61cf6d2abe77f988e357 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 8 Jul 2021 09:00:49 +0800 Subject: Share rpan post url and rpan url. Show rpan post title in ViewRPANBroadcastFragment. --- .../infinityforreddit/RPANBroadcast.java | 12 +++++- .../infinityforreddit/activities/RPANActivity.java | 46 ++++++++++++++++++++++ .../fragments/ViewRPANBroadcastFragment.java | 5 +++ 3 files changed, 61 insertions(+), 2 deletions(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RPANBroadcast.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RPANBroadcast.java index 1d317e2d..d7c936c2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RPANBroadcast.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RPANBroadcast.java @@ -3,6 +3,8 @@ package ml.docilealligator.infinityforreddit; import android.os.Parcel; import android.os.Parcelable; +import ml.docilealligator.infinityforreddit.utils.APIUtils; + public class RPANBroadcast implements Parcelable { public int upvotes; @@ -76,7 +78,7 @@ public class RPANBroadcast implements Parcelable { parcel.writeParcelable(rpanStream, i); } - public static class RPANPost implements Parcelable{ + public static class RPANPost implements Parcelable { public String fullname; public String title; public String subredditName; @@ -86,6 +88,7 @@ public class RPANBroadcast implements Parcelable { public String voteState; public double upvoteRatio; public String postPermalink; + public String rpanUrl; public boolean isNsfw; public boolean isLocked; public boolean isArchived; @@ -105,7 +108,8 @@ public class RPANBroadcast implements Parcelable { this.postScore = postScore; this.voteState = voteState; this.upvoteRatio = upvoteRatio; - this.postPermalink = postPermalink; + this.postPermalink = APIUtils.API_BASE_URI + postPermalink; + this.rpanUrl = rpanUrl; this.isNsfw = isNsfw; this.isLocked = isLocked; this.isArchived = isArchived; @@ -115,6 +119,7 @@ public class RPANBroadcast implements Parcelable { } protected RPANPost(Parcel in) { + fullname = in.readString(); title = in.readString(); subredditName = in.readString(); subredditIconUrl = in.readString(); @@ -123,6 +128,7 @@ public class RPANBroadcast implements Parcelable { voteState = in.readString(); upvoteRatio = in.readDouble(); postPermalink = in.readString(); + rpanUrl = in.readString(); isNsfw = in.readByte() != 0; isLocked = in.readByte() != 0; isArchived = in.readByte() != 0; @@ -150,6 +156,7 @@ public class RPANBroadcast implements Parcelable { @Override public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(fullname); parcel.writeString(title); parcel.writeString(subredditName); parcel.writeString(subredditIconUrl); @@ -158,6 +165,7 @@ public class RPANBroadcast implements Parcelable { parcel.writeString(voteState); parcel.writeDouble(upvoteRatio); parcel.writeString(postPermalink); + parcel.writeString(rpanUrl); parcel.writeByte((byte) (isNsfw ? 1 : 0)); parcel.writeByte((byte) (isLocked ? 1 : 0)); parcel.writeByte((byte) (isArchived ? 1 : 0)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java index cc4c83ef..8f681676 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java @@ -1,5 +1,7 @@ package ml.docilealligator.infinityforreddit.activities; +import android.content.ActivityNotFoundException; +import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; @@ -7,6 +9,8 @@ import android.graphics.drawable.Drawable; import android.media.AudioManager; import android.os.Bundle; import android.os.Handler; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.widget.ProgressBar; import android.widget.Toast; @@ -241,6 +245,48 @@ public class RPANActivity extends AppCompatActivity { } catch (NoSuchFieldException | IllegalAccessException ignore) {} } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.rpan_activity, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } else if (item.getItemId() == R.id.action_share_rpan_link_rpan_activity) { + if (rpanBroadcasts != null) { + int position = viewPager2.getCurrentItem(); + if (position >= 0 && position < rpanBroadcasts.size()) { + shareLink(rpanBroadcasts.get(position).rpanPost.rpanUrl); + return true; + } + } + } else if (item.getItemId() == R.id.action_share_post_link_rpan_activity) { + if (rpanBroadcasts != null) { + int position = viewPager2.getCurrentItem(); + if (position >= 0 && position < rpanBroadcasts.size()) { + shareLink(rpanBroadcasts.get(position).rpanPost.postPermalink); + return true; + } + } + } + return false; + } + + private void shareLink(String link) { + try { + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_TEXT, link); + startActivity(Intent.createChooser(intent, getString(R.string.share))); + } catch (ActivityNotFoundException e) { + Toast.makeText(this, R.string.no_activity_found_for_share, Toast.LENGTH_SHORT).show(); + } + } + private class SectionsPagerAdapter extends FragmentStateAdapter { public SectionsPagerAdapter(FragmentActivity fa) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java index 09aa6ee7..400de425 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java @@ -12,6 +12,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.ImageButton; +import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; @@ -70,6 +71,8 @@ public class ViewRPANBroadcastFragment extends Fragment { ConstraintLayout constraintLayout; @BindView(R.id.player_view_view_rpan_broadcast_fragment) PlayerView playerView; + @BindView(R.id.title_text_view_exo_rpan_broadcast_playback_control_view) + TextView titleTextView; @BindView(R.id.recycler_view_exo_rpan_broadcast_playback_control_view) RecyclerView recyclerView; @BindView(R.id.mute_exo_rpan_broadcast_playback_control_view) @@ -226,6 +229,8 @@ public class ViewRPANBroadcastFragment extends Fragment { } }); + titleTextView.setText(rpanBroadcast.rpanPost.title); + recyclerView.setOnTouchListener(new View.OnTouchListener() { float x1; float x2; -- cgit v1.2.3