Share rpan post url and rpan url. Show rpan post title in ViewRPANBroadcastFragment.

This commit is contained in:
Alex Ning 2021-07-08 09:00:49 +08:00
parent 6eecaaccfa
commit 61d907308c
7 changed files with 90 additions and 3 deletions

View File

@ -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;
@ -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));

View File

@ -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) {

View File

@ -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;

View File

@ -7,6 +7,17 @@
android:focusableInTouchMode="true"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/title_text_view_exo_rpan_broadcast_playback_control_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:textColor="#FFFFFF"
android:textSize="20sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/control_linear_layout"
app:layout_constraintVertical_bias="1" />
<LinearLayout
android:id="@+id/control_linear_layout"
android:layout_width="match_parent"

View File

@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:paddingBottom="8dp">
android:layout_marginBottom="8dp">
<ImageView
android:id="@+id/icon_image_view_item_rpan_comment"

View File

@ -0,0 +1,15 @@
<?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_share_rpan_link_rpan_activity"
android:orderInCategory="1"
android:title="@string/action_share_rpan_link"
app:showAsAction="never" />
<item
android:id="@+id/action_share_post_link_rpan_activity"
android:orderInCategory="1"
android:title="@string/action_share_post_link"
app:showAsAction="never" />
</menu>

View File

@ -84,6 +84,8 @@
<string name="action_copy_link">Copy Link</string>
<string name="action_add_to_post_filter">Add to Post Filter</string>
<string name="action_delete_logs">Delete Logs</string>
<string name="action_share_rpan_link">Share RPAN Link</string>
<string name="action_share_post_link">Share Post Link</string>
<string name="parse_json_response_error">Error occurred when parsing the JSON response</string>
<string name="retrieve_token_error">Error Retrieving the token</string>