diff options
Diffstat (limited to 'app/src/main/java/ml')
10 files changed, 1 insertions, 1220 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 8b8f5533..2bf647ec 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -37,7 +37,6 @@ import ml.docilealligator.infinityforreddit.activities.PostLinkActivity; import ml.docilealligator.infinityforreddit.activities.PostPollActivity; import ml.docilealligator.infinityforreddit.activities.PostTextActivity; import ml.docilealligator.infinityforreddit.activities.PostVideoActivity; -import ml.docilealligator.infinityforreddit.activities.RPANActivity; import ml.docilealligator.infinityforreddit.activities.ReportActivity; import ml.docilealligator.infinityforreddit.activities.RulesActivity; import ml.docilealligator.infinityforreddit.activities.SearchActivity; @@ -81,7 +80,6 @@ import ml.docilealligator.infinityforreddit.fragments.UserListingFragment; import ml.docilealligator.infinityforreddit.fragments.ViewImgurImageFragment; import ml.docilealligator.infinityforreddit.fragments.ViewImgurVideoFragment; import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment; -import ml.docilealligator.infinityforreddit.fragments.ViewRPANBroadcastFragment; import ml.docilealligator.infinityforreddit.fragments.ViewRedditGalleryImageOrGifFragment; import ml.docilealligator.infinityforreddit.fragments.ViewRedditGalleryVideoFragment; import ml.docilealligator.infinityforreddit.services.DownloadMediaService; @@ -281,10 +279,6 @@ public interface AppComponent { void inject(LockScreenActivity lockScreenActivity); - void inject(RPANActivity rpanActivity); - - void inject(ViewRPANBroadcastFragment viewRPANBroadcastFragment); - void inject(PostGalleryActivity postGalleryActivity); void inject(TrendingActivity trendingActivity); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RPANBroadcast.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RPANBroadcast.java deleted file mode 100644 index d7c936c2..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RPANBroadcast.java +++ /dev/null @@ -1,236 +0,0 @@ -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; - public int downvotes; - public int uniqueWatchers; - public int continuousWatchers; - public int totalContinuousWatchers; - public boolean chatDisabled; - public double broadcastTime; - public double estimatedRemainingTime; - - public RPANPost rpanPost; - public RPANStream rpanStream; - - public RPANBroadcast(int upvotes, int downvotes, int uniqueWatchers, int continuousWatchers, - int totalContinuousWatchers, boolean chatDisabled, double broadcastTime, - double estimatedRemainingTime, RPANPost rpanPost, RPANStream rpanStream) { - this.upvotes = upvotes; - this.downvotes = downvotes; - this.uniqueWatchers = uniqueWatchers; - this.continuousWatchers = continuousWatchers; - this.totalContinuousWatchers = totalContinuousWatchers; - this.chatDisabled = chatDisabled; - this.broadcastTime = broadcastTime; - this.estimatedRemainingTime = estimatedRemainingTime; - this.rpanPost = rpanPost; - this.rpanStream = rpanStream; - } - - protected RPANBroadcast(Parcel in) { - upvotes = in.readInt(); - downvotes = in.readInt(); - uniqueWatchers = in.readInt(); - continuousWatchers = in.readInt(); - totalContinuousWatchers = in.readInt(); - chatDisabled = in.readByte() != 0; - broadcastTime = in.readDouble(); - estimatedRemainingTime = in.readDouble(); - rpanPost = in.readParcelable(RPANPost.class.getClassLoader()); - rpanStream = in.readParcelable(RPANStream.class.getClassLoader()); - } - - public static final Creator<RPANBroadcast> CREATOR = new Creator<RPANBroadcast>() { - @Override - public RPANBroadcast createFromParcel(Parcel in) { - return new RPANBroadcast(in); - } - - @Override - public RPANBroadcast[] newArray(int size) { - return new RPANBroadcast[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeInt(upvotes); - parcel.writeInt(downvotes); - parcel.writeInt(uniqueWatchers); - parcel.writeInt(continuousWatchers); - parcel.writeInt(totalContinuousWatchers); - parcel.writeByte((byte) (chatDisabled ? 1 : 0)); - parcel.writeDouble(broadcastTime); - parcel.writeDouble(estimatedRemainingTime); - parcel.writeParcelable(rpanPost, i); - parcel.writeParcelable(rpanStream, i); - } - - public static class RPANPost implements Parcelable { - public String fullname; - public String title; - public String subredditName; - public String subredditIconUrl; - public String username; - public int postScore; - public String voteState; - public double upvoteRatio; - public String postPermalink; - public String rpanUrl; - public boolean isNsfw; - public boolean isLocked; - public boolean isArchived; - public boolean isSpoiler; - public String suggestedCommentSort; - public String liveCommentsWebsocketUrl; - - public RPANPost(String fullname, String title, String subredditName, String subredditIconUrl, String username, - int postScore, String voteState, double upvoteRatio, String postPermalink, String rpanUrl, - boolean isNsfw, boolean isLocked, boolean isArchived, boolean isSpoiler, - String suggestedCommentSort, String liveCommentsWebsocketUrl) { - this.fullname = fullname; - this.title = title; - this.subredditName = subredditName; - this.subredditIconUrl = subredditIconUrl; - this.username = username; - this.postScore = postScore; - this.voteState = voteState; - this.upvoteRatio = upvoteRatio; - this.postPermalink = APIUtils.API_BASE_URI + postPermalink; - this.rpanUrl = rpanUrl; - this.isNsfw = isNsfw; - this.isLocked = isLocked; - this.isArchived = isArchived; - this.isSpoiler = isSpoiler; - this.suggestedCommentSort = suggestedCommentSort; - this.liveCommentsWebsocketUrl = liveCommentsWebsocketUrl; - } - - protected RPANPost(Parcel in) { - fullname = in.readString(); - title = in.readString(); - subredditName = in.readString(); - subredditIconUrl = in.readString(); - username = in.readString(); - postScore = in.readInt(); - voteState = in.readString(); - upvoteRatio = in.readDouble(); - postPermalink = in.readString(); - rpanUrl = in.readString(); - isNsfw = in.readByte() != 0; - isLocked = in.readByte() != 0; - isArchived = in.readByte() != 0; - isSpoiler = in.readByte() != 0; - suggestedCommentSort = in.readString(); - liveCommentsWebsocketUrl = in.readString(); - } - - public static final Creator<RPANPost> CREATOR = new Creator<RPANPost>() { - @Override - public RPANPost createFromParcel(Parcel in) { - return new RPANPost(in); - } - - @Override - public RPANPost[] newArray(int size) { - return new RPANPost[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(fullname); - parcel.writeString(title); - parcel.writeString(subredditName); - parcel.writeString(subredditIconUrl); - parcel.writeString(username); - parcel.writeInt(postScore); - 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)); - parcel.writeByte((byte) (isSpoiler ? 1 : 0)); - parcel.writeString(suggestedCommentSort); - parcel.writeString(liveCommentsWebsocketUrl); - } - } - - public static class RPANStream implements Parcelable { - public String streamId; - public String hlsUrl; - public String thumbnail; - public int width; - public int height; - public long publishAt; - public String state; - - public RPANStream(String streamId, String hlsUrl, String thumbnail, int width, int height, long publishAt, - String state) { - this.streamId = streamId; - this.hlsUrl = hlsUrl; - this.thumbnail = thumbnail; - this.width = width; - this.height = height; - this.publishAt = publishAt; - this.state = state; - } - - protected RPANStream(Parcel in) { - streamId = in.readString(); - hlsUrl = in.readString(); - thumbnail = in.readString(); - width = in.readInt(); - height = in.readInt(); - publishAt = in.readLong(); - state = in.readString(); - } - - public static final Creator<RPANStream> CREATOR = new Creator<RPANStream>() { - @Override - public RPANStream createFromParcel(Parcel in) { - return new RPANStream(in); - } - - @Override - public RPANStream[] newArray(int size) { - return new RPANStream[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(streamId); - parcel.writeString(hlsUrl); - parcel.writeString(thumbnail); - parcel.writeInt(width); - parcel.writeInt(height); - parcel.writeLong(publishAt); - parcel.writeString(state); - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RPANComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RPANComment.java deleted file mode 100644 index 077031bf..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RPANComment.java +++ /dev/null @@ -1,15 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -public class RPANComment { - public String author; - public String authorIconImage; - public String content; - public long createdUTC; - - public RPANComment(String author, String authorIconImage, String content, long createdUTC) { - this.author = author; - this.authorIconImage = authorIconImage; - this.content = content; - this.createdUTC = createdUTC; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java index 5bba98bc..9fba9cdf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java @@ -49,7 +49,6 @@ public class LinkResolverActivity extends AppCompatActivity { private static final String IMGUR_GALLERY_PATTERN = "/gallery/\\w+/?"; private static final String IMGUR_ALBUM_PATTERN = "/(album|a)/\\w+/?"; private static final String IMGUR_IMAGE_PATTERN = "/\\w+/?"; - private static final String RPAN_BROADCAST_PATTERN = "/rpan/r/[\\w-]+/\\w+/?\\w+/?"; private static final String WIKI_PATTERN = "/[rR]/[\\w-]+/(wiki|w)(?:/[\\w-]+)*"; private static final String GOOGLE_AMP_PATTERN = "/amp/s/amp.reddit.com/.*"; private static final String STREAMABLE_PATTERN = "/\\w+/?"; @@ -248,10 +247,6 @@ public class LinkResolverActivity extends AppCompatActivity { intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); startActivity(intent); - } else if (path.matches(RPAN_BROADCAST_PATTERN)) { - Intent intent = new Intent(this, RPANActivity.class); - intent.putExtra(RPANActivity.EXTRA_RPAN_BROADCAST_FULLNAME_OR_ID, path.substring(path.lastIndexOf('/') + 1)); - startActivity(intent); } else if (authority.equals("redd.it") && path.matches(REDD_IT_POST_PATTERN)) { Intent intent = new Intent(this, ViewPostDetailActivity.class); intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 43d41e8a..bbc23811 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -779,8 +779,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true); } else if (stringId == R.string.history) { intent = new Intent(MainActivity.this, HistoryActivity.class); - } else if (stringId == R.string.rpan) { - intent = new Intent(MainActivity.this, RPANActivity.class); } else if (stringId == R.string.trending) { intent = new Intent(MainActivity.this, TrendingActivity.class); } else if (stringId == R.string.upvoted) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java deleted file mode 100644 index ecc459a4..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java +++ /dev/null @@ -1,426 +0,0 @@ -package ml.docilealligator.infinityforreddit.activities; - -import android.content.ActivityNotFoundException; -import android.content.Intent; -import android.content.SharedPreferences; -import android.graphics.Color; -import android.graphics.Typeface; -import android.graphics.drawable.ColorDrawable; -import android.graphics.drawable.Drawable; -import android.media.AudioManager; -import android.os.Bundle; -import android.os.Handler; -import android.text.Html; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.ProgressBar; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.app.AppCompatActivity; -import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; -import androidx.recyclerview.widget.RecyclerView; -import androidx.viewpager2.adapter.FragmentStateAdapter; -import androidx.viewpager2.widget.ViewPager2; - -import com.evernote.android.state.State; -import com.google.android.material.snackbar.Snackbar; -import com.livefront.bridge.Bridge; - -import org.greenrobot.eventbus.EventBus; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.concurrent.Executor; - -import javax.inject.Inject; -import javax.inject.Named; - -import butterknife.BindView; -import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.CustomFontReceiver; -import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RPANBroadcast; -import ml.docilealligator.infinityforreddit.apis.Strapi; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.font.ContentFontFamily; -import ml.docilealligator.infinityforreddit.font.ContentFontStyle; -import ml.docilealligator.infinityforreddit.font.FontFamily; -import ml.docilealligator.infinityforreddit.font.FontStyle; -import ml.docilealligator.infinityforreddit.font.TitleFontFamily; -import ml.docilealligator.infinityforreddit.font.TitleFontStyle; -import ml.docilealligator.infinityforreddit.fragments.ViewRPANBroadcastFragment; -import ml.docilealligator.infinityforreddit.utils.JSONUtils; -import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.utils.Utils; -import okhttp3.ResponseBody; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; -import retrofit2.Retrofit; - -public class RPANActivity extends AppCompatActivity implements CustomFontReceiver { - - public static final String EXTRA_RPAN_BROADCAST_FULLNAME_OR_ID = "ERBFOI"; - - @BindView(R.id.coordinator_layout_rpan_activity) - CoordinatorLayout coordinatorLayout; - @BindView(R.id.view_pager_2_rpan_activity) - ViewPager2 viewPager2; - @BindView(R.id.progress_bar_rpan_activity) - ProgressBar progressBar; - @Inject - @Named("strapi") - Retrofit strapiRetrofit; - @Inject - @Named("default") - SharedPreferences mSharedPreferences; - @Inject - CustomThemeWrapper mCustomThemeWrapper; - @Inject - Executor mExecutor; - @State - ArrayList<RPANBroadcast> rpanBroadcasts; - @State - String nextCursor; - public Typeface typeface; - private SectionsPagerAdapter sectionsPagerAdapter; - - @Override - protected void onCreate(Bundle savedInstanceState) { - ((Infinity) getApplication()).getAppComponent().inject(this); - - super.onCreate(savedInstanceState); - - getTheme().applyStyle(R.style.Theme_Normal, true); - - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(FontFamily.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_FAMILY_KEY, FontFamily.Default.name())).getResId(), true); - - getTheme().applyStyle(TitleFontFamily.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_FAMILY_KEY, TitleFontFamily.Default.name())).getResId(), true); - - getTheme().applyStyle(ContentFontFamily.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY, ContentFontFamily.Default.name())).getResId(), true); - - setContentView(R.layout.activity_rpanactivity); - - setVolumeControlStream(AudioManager.STREAM_MUSIC); - - Bridge.restoreInstanceState(this, savedInstanceState); - - ButterKnife.bind(this); - - ActionBar actionBar = getSupportActionBar(); - Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp); - actionBar.setHomeAsUpIndicator(upArrow); - actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000"))); - actionBar.setTitle(Utils.getTabTextWithCustomFont(typeface, Html.fromHtml("<font color=\"#FFFFFF\">" + getString(R.string.rpan_activity_label) + "</font>"))); - - if (rpanBroadcasts == null) { - loadRPANVideos(); - } else { - initializeViewPager(); - } - } - - private void loadRPANVideos() { - String rpanBroadcastFullNameOrId = getIntent().getStringExtra(EXTRA_RPAN_BROADCAST_FULLNAME_OR_ID); - if (rpanBroadcastFullNameOrId == null) { - strapiRetrofit.create(Strapi.class).getAllBroadcasts().enqueue(new Callback<String>() { - @Override - public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { - progressBar.setVisibility(View.GONE); - if (response.isSuccessful()) { - parseRPANBroadcasts(response.body()); - } else { - try { - ResponseBody responseBody = response.errorBody(); - if (responseBody != null) { - JSONObject errorObject = new JSONObject(responseBody.string()); - String errorMessage = errorObject.getString(JSONUtils.DATA_KEY); - if (!errorMessage.isEmpty() && !errorMessage.equals("null")) { - Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_LONG).show(); - } else { - Toast.makeText(RPANActivity.this, - R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show(); - } - } else { - Toast.makeText(RPANActivity.this, - R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show(); - } - } catch (IOException | JSONException e) { - e.printStackTrace(); - Toast.makeText(RPANActivity.this, - R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show(); - } - } - } - - @Override - public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { - progressBar.setVisibility(View.GONE); - Toast.makeText(RPANActivity.this, - R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show(); - } - }); - } else { - strapiRetrofit.create(Strapi.class).getRPANBroadcast(rpanBroadcastFullNameOrId).enqueue(new Callback<String>() { - @Override - public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { - progressBar.setVisibility(View.GONE); - if (response.isSuccessful()) { - Handler handler = new Handler(); - mExecutor.execute(() -> { - try { - rpanBroadcasts = new ArrayList<>(); - rpanBroadcasts.add(parseSingleRPANBroadcast(new JSONObject(response.body()).getJSONObject(JSONUtils.DATA_KEY))); - handler.post(() -> initializeViewPager()); - } catch (JSONException e) { - e.printStackTrace(); - handler.post(() -> Toast.makeText(RPANActivity.this, - R.string.parse_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show()); - } - }); - } else { - try { - ResponseBody responseBody = response.errorBody(); - if (responseBody != null) { - JSONObject errorObject = new JSONObject(responseBody.string()); - String errorMessage = errorObject.getString(JSONUtils.DATA_KEY); - if (!errorMessage.isEmpty() && !errorMessage.equals("null")) { - Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_LONG).show(); - } else { - Toast.makeText(RPANActivity.this, - R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show(); - } - } else { - Toast.makeText(RPANActivity.this, - R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show(); - } - } catch (IOException | JSONException e) { - e.printStackTrace(); - Toast.makeText(RPANActivity.this, - R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show(); - } - } - } - - @Override - public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { - progressBar.setVisibility(View.GONE); - Toast.makeText(RPANActivity.this, - R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show(); - } - }); - } - } - - private void parseRPANBroadcasts(String response) { - Handler handler = new Handler(); - mExecutor.execute(() -> { - try { - ArrayList<RPANBroadcast> rpanBroadcasts = new ArrayList<>(); - JSONObject responseObject = new JSONObject(response); - String nextCursor = responseObject.getString(JSONUtils.NEXT_CURSOR_KEY); - - JSONArray dataArray = responseObject.getJSONArray(JSONUtils.DATA_KEY); - for (int i = 0; i < dataArray.length(); i++) { - try { - JSONObject singleData = dataArray.getJSONObject(i); - rpanBroadcasts.add(parseSingleRPANBroadcast(singleData)); - } catch (JSONException e) { - e.printStackTrace(); - } - } - - handler.post(() -> { - RPANActivity.this.rpanBroadcasts = rpanBroadcasts; - RPANActivity.this.nextCursor = nextCursor; - - initializeViewPager(); - }); - } catch (JSONException e) { - e.printStackTrace(); - handler.post(() -> Toast.makeText(RPANActivity.this, - R.string.parse_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show()); - } - }); - } - - private RPANBroadcast parseSingleRPANBroadcast(JSONObject singleData) throws JSONException { - JSONObject rpanPostObject = singleData.getJSONObject(JSONUtils.POST_KEY); - RPANBroadcast.RPANPost rpanPost = new RPANBroadcast.RPANPost( - rpanPostObject.getString(JSONUtils.ID_KEY), - rpanPostObject.getString(JSONUtils.TITLE_KEY), - rpanPostObject.getJSONObject(JSONUtils.SUBREDDIT_KEY).getString(JSONUtils.NAME_KEY), - rpanPostObject.getJSONObject(JSONUtils.SUBREDDIT_KEY).getJSONObject(JSONUtils.STYLES_KEY).getString(JSONUtils.ICON_KEY), - rpanPostObject.getJSONObject(JSONUtils.AUTHOR_INFO_KEY).getString(JSONUtils.NAME_KEY), - rpanPostObject.getInt(JSONUtils.SCORE_KEY), - rpanPostObject.getString(JSONUtils.VOTE_STATE_KEY), - rpanPostObject.getDouble(JSONUtils.UPVOTE_RATIO_CAMEL_CASE_KEY), - rpanPostObject.getString(JSONUtils.PERMALINK_KEY), - rpanPostObject.getJSONObject(JSONUtils.OUTBOUND_LINK_KEY).getString(JSONUtils.URL_KEY), - rpanPostObject.getBoolean(JSONUtils.IS_NSFW_KEY), - rpanPostObject.getBoolean(JSONUtils.IS_LOCKED_KEY), - rpanPostObject.getBoolean(JSONUtils.IS_ARCHIVED_KEY), - rpanPostObject.getBoolean(JSONUtils.IS_SPOILER), - rpanPostObject.getString(JSONUtils.SUGGESTED_COMMENT_SORT_CAMEL_CASE_KEY), - rpanPostObject.getString(JSONUtils.LIVE_COMMENTS_WEBSOCKET_KEY) - ); - - JSONObject rpanStreamObject = singleData.getJSONObject(JSONUtils.STREAM_KEY); - RPANBroadcast.RPANStream rpanStream = new RPANBroadcast.RPANStream( - rpanStreamObject.getString(JSONUtils.STREAM_ID_KEY), - rpanStreamObject.getString(JSONUtils.HLS_URL_KEY), - rpanStreamObject.getString(JSONUtils.THUMBNAIL_KEY), - rpanStreamObject.getInt(JSONUtils.WIDTH_KEY), - rpanStreamObject.getInt(JSONUtils.HEIGHT_KEY), - rpanStreamObject.getLong(JSONUtils.PUBLISH_AT_KEY), - rpanStreamObject.getString(JSONUtils.STATE_KEY) - ); - - return new RPANBroadcast( - singleData.getInt(JSONUtils.UPVOTES_KEY), - singleData.getInt(JSONUtils.DOWNVOTES_KEY), - singleData.getInt(JSONUtils.UNIQUE_WATCHERS_KEY), - singleData.getInt(JSONUtils.CONTINUOUS_WATCHERS_KEY), - singleData.getInt(JSONUtils.TOTAL_CONTINUOUS_WATCHERS_KEY), - singleData.getBoolean(JSONUtils.CHAT_DISABLED_KEY), - singleData.getDouble(JSONUtils.BROADCAST_TIME_KEY), - singleData.getDouble(JSONUtils.ESTIMATED_REMAINING_TIME_KEY), - rpanPost, - rpanStream - ); - } - - private void initializeViewPager() { - sectionsPagerAdapter = new SectionsPagerAdapter(this); - viewPager2.setAdapter(sectionsPagerAdapter); - viewPager2.setOffscreenPageLimit(3); - fixViewPager2Sensitivity(viewPager2); - } - - private void fixViewPager2Sensitivity(ViewPager2 viewPager2) { - try { - Field recyclerViewField = ViewPager2.class.getDeclaredField("mRecyclerView"); - recyclerViewField.setAccessible(true); - - RecyclerView recyclerView = (RecyclerView) recyclerViewField.get(viewPager2); - - Field touchSlopField = RecyclerView.class.getDeclaredField("mTouchSlop"); - touchSlopField.setAccessible(true); - - Object touchSlopBox = touchSlopField.get(recyclerView); - if (touchSlopBox != null) { - int touchSlop = (int) touchSlopBox; - touchSlopField.set(recyclerView, touchSlop * 4); - } - } catch (NoSuchFieldException | IllegalAccessException ignore) {} - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.rpan_activity, menu); - for (int i = 0; i < menu.size(); i++) { - Utils.setTitleWithCustomFontToMenuItem(typeface, menu.getItem(i), null); - } - 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; - } - - @Override - protected void onDestroy() { - super.onDestroy(); - EventBus.getDefault().unregister(this); - } - - 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(); - } - } - - @Override - public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) { - this.typeface = typeface; - } - - private class SectionsPagerAdapter extends FragmentStateAdapter { - - public SectionsPagerAdapter(FragmentActivity fa) { - super(fa); - } - - @NonNull - @Override - public Fragment createFragment(int position) { - ViewRPANBroadcastFragment fragment = new ViewRPANBroadcastFragment(); - Bundle bundle = new Bundle(); - bundle.putParcelable(ViewRPANBroadcastFragment.EXTRA_RPAN_BROADCAST, rpanBroadcasts.get(position)); - fragment.setArguments(bundle); - return fragment; - } - - @Nullable - private Fragment getCurrentFragment() { - if (viewPager2 == null || getSupportFragmentManager() == null) { - return null; - } - return getSupportFragmentManager().findFragmentByTag("f" + viewPager2.getCurrentItem()); - } - - @Override - public int getItemCount() { - return rpanBroadcasts == null ? 0 : rpanBroadcasts.size(); - } - } -}
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RPANCommentStreamRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RPANCommentStreamRecyclerViewAdapter.java deleted file mode 100644 index d3c029af..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RPANCommentStreamRecyclerViewAdapter.java +++ /dev/null @@ -1,89 +0,0 @@ -package ml.docilealligator.infinityforreddit.adapters; - -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.RequestManager; -import com.bumptech.glide.request.RequestOptions; - -import java.util.ArrayList; - -import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RPANComment; -import ml.docilealligator.infinityforreddit.activities.RPANActivity; - -public class RPANCommentStreamRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { - private RPANActivity activity; - private RequestManager glide; - private ArrayList<RPANComment> rpanComments; - - public RPANCommentStreamRecyclerViewAdapter(RPANActivity activity) { - this.activity = activity; - glide = Glide.with(activity); - rpanComments = new ArrayList<>(); - } - - @NonNull - @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new RPANCommentViewHolder(LayoutInflater.from(parent.getContext()).inflate( - R.layout.item_rpan_comment, parent, false)); - } - - @Override - public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - if (holder instanceof RPANCommentViewHolder) { - ((RPANCommentViewHolder) holder).authorTextView.setText(rpanComments.get(position).author); - ((RPANCommentViewHolder) holder).contentTextView.setText(rpanComments.get(position).content); - glide.load(rpanComments.get(position).authorIconImage) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(glide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((RPANCommentViewHolder) holder).iconImageView); - } - } - - @Override - public int getItemCount() { - return rpanComments == null ? 0 : rpanComments.size(); - } - - @Override - public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { - super.onViewRecycled(holder); - if (holder instanceof RPANCommentViewHolder) { - glide.clear(((RPANCommentViewHolder) holder).iconImageView); - } - } - - public void addRPANComment(RPANComment rpanComment) { - rpanComments.add(rpanComment); - notifyItemInserted(rpanComments.size() - 1); - } - - class RPANCommentViewHolder extends RecyclerView.ViewHolder { - ImageView iconImageView; - TextView authorTextView; - TextView contentTextView; - - public RPANCommentViewHolder(@NonNull View itemView) { - super(itemView); - iconImageView = itemView.findViewById(R.id.icon_image_view_item_rpan_comment); - authorTextView = itemView.findViewById(R.id.author_text_view_item_rpan_comment); - contentTextView = itemView.findViewById(R.id.content_text_view_item_rpan_comment); - - if (activity.typeface != null) { - authorTextView.setTypeface(activity.typeface); - contentTextView.setTypeface(activity.typeface); - } - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/RedditSectionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/RedditSectionRecyclerViewAdapter.java index ab6ed539..487e9d33 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/RedditSectionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/RedditSectionRecyclerViewAdapter.java @@ -22,7 +22,7 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc private static final int VIEW_TYPE_MENU_GROUP_TITLE = 1; private static final int VIEW_TYPE_MENU_ITEM = 2; - private static final int REDDIT_SECTION_ITEMS = 2; + private static final int REDDIT_SECTION_ITEMS = 1; private BaseActivity baseActivity; private int primaryTextColor; @@ -85,10 +85,6 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc switch (position) { case 1: - stringId = R.string.rpan; - drawableId = R.drawable.ic_rpan_24dp; - break; - case 2: stringId = R.string.trending; drawableId = R.drawable.ic_trending_24dp; break; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/Strapi.java b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/Strapi.java deleted file mode 100644 index e68b8850..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/Strapi.java +++ /dev/null @@ -1,13 +0,0 @@ -package ml.docilealligator.infinityforreddit.apis; - -import retrofit2.Call; -import retrofit2.http.GET; -import retrofit2.http.Path; - -public interface Strapi { - @GET("/broadcasts") - Call<String> getAllBroadcasts(); - - @GET("/videos/{rpan_id_or_fullname}") - Call<String> getRPANBroadcast(@Path("rpan_id_or_fullname") String rpanIdOrFullname); -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java deleted file mode 100644 index b00f6d4c..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java +++ /dev/null @@ -1,423 +0,0 @@ -package ml.docilealligator.infinityforreddit.fragments; - -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.Context; -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.os.Bundle; -import android.os.Handler; -import android.view.LayoutInflater; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageButton; -import android.widget.ImageView; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.constraintlayout.widget.ConstraintLayout; -import androidx.fragment.app.Fragment; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.request.RequestOptions; -import com.google.android.exoplayer2.ExoPlaybackException; -import com.google.android.exoplayer2.ExoPlayer; -import com.google.android.exoplayer2.MediaItem; -import com.google.android.exoplayer2.Player; -import com.google.android.exoplayer2.Tracks; -import com.google.android.exoplayer2.source.BehindLiveWindowException; -import com.google.android.exoplayer2.source.hls.HlsMediaSource; -import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; -import com.google.android.exoplayer2.ui.PlayerView; -import com.google.android.exoplayer2.ui.TrackSelectionDialogBuilder; -import com.google.android.exoplayer2.upstream.DataSource; -import com.google.android.exoplayer2.upstream.DefaultHttpDataSource; -import com.google.android.exoplayer2.upstream.cache.CacheDataSource; -import com.google.android.exoplayer2.upstream.cache.SimpleCache; -import com.google.common.collect.ImmutableList; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.concurrent.Executor; - -import javax.inject.Inject; -import javax.inject.Named; - -import butterknife.BindView; -import butterknife.ButterKnife; -import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RPANBroadcast; -import ml.docilealligator.infinityforreddit.RPANComment; -import ml.docilealligator.infinityforreddit.activities.RPANActivity; -import ml.docilealligator.infinityforreddit.adapters.RPANCommentStreamRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import ml.docilealligator.infinityforreddit.utils.JSONUtils; -import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.WebSocket; -import okhttp3.WebSocketListener; -import retrofit2.Retrofit; - -public class ViewRPANBroadcastFragment extends Fragment { - - public static final String EXTRA_RPAN_BROADCAST = "ERB"; - private static final String IS_MUTE_STATE = "IMS"; - - @BindView(R.id.constraint_layout_exo_rpan_broadcast_playback_control_view) - ConstraintLayout constraintLayout; - @BindView(R.id.player_view_view_rpan_broadcast_fragment) - PlayerView playerView; - @BindView(R.id.subreddit_icon_image_view_exo_rpan_broadcast_playback_control_view) - ImageView subredditIconImageView; - @BindView(R.id.subreddit_name_text_view_exo_rpan_broadcast_playback_control_view) - TextView subredditNameTextView; - @BindView(R.id.username_text_view_exo_rpan_broadcast_playback_control_view) - TextView usernameTextView; - @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) - ImageButton muteButton; - @BindView(R.id.hd_exo_rpan_broadcast_playback_control_view) - ImageButton hdButton; - @Inject - @Named("strapi") - Retrofit mStrapiRetrofit; - @Inject - @Named("default") - SharedPreferences mSharedPreferences; - @Inject - @Named("current_account") - SharedPreferences mCurrentAccountSharedPreferences; - @Inject - CustomThemeWrapper mCustomThemeWrapper; - @Inject - Executor mExecutor; - @Inject - @Named("rpan") - OkHttpClient okHttpClient; - @Inject - SimpleCache mSimpleCache; - private RPANActivity mActivity; - private RPANBroadcast rpanBroadcast; - private ExoPlayer player; - private DefaultTrackSelector trackSelector; - private DataSource.Factory dataSourceFactory; - private Handler handler; - private RPANCommentStreamRecyclerViewAdapter adapter; - private WebSocket webSocket; - - private boolean wasPlaying; - private boolean isMute = false; - private long resumePosition = -1; - private boolean isDataSavingMode; - - public ViewRPANBroadcastFragment() { - // Required empty public constructor - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - // Inflate the layout for this fragment - View rootView = inflater.inflate(R.layout.fragment_view_rpan_broadcast, container, false); - - ((Infinity) mActivity.getApplication()).getAppComponent().inject(this); - - ButterKnife.bind(this, rootView); - - if (mActivity.typeface != null) { - subredditNameTextView.setTypeface(mActivity.typeface); - usernameTextView.setTypeface(mActivity.typeface); - titleTextView.setTypeface(mActivity.typeface); - } - - rpanBroadcast = getArguments().getParcelable(EXTRA_RPAN_BROADCAST); - - if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || getResources().getBoolean(R.bool.isTablet)) { - //Set player controller bottom margin in order to display it above the navbar - int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android"); - //LinearLayout controllerLinearLayout = findViewById(R.id.linear_layout_exo_playback_control_view); - ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) constraintLayout.getLayoutParams(); - params.bottomMargin = getResources().getDimensionPixelSize(resourceId); - } else { - //Set player controller right margin in order to display it above the navbar - int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android"); - //LinearLayout controllerLinearLayout = findViewById(R.id.linear_layout_exo_playback_control_view); - ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) constraintLayout.getLayoutParams(); - params.rightMargin = getResources().getDimensionPixelSize(resourceId); - } - - playerView.setControllerVisibilityListener(visibility -> { - switch (visibility) { - case View.GONE: - mActivity.getWindow().getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_FULLSCREEN - | View.SYSTEM_UI_FLAG_IMMERSIVE); - playerView.setControllerShowTimeoutMs(0); - break; - case View.VISIBLE: - mActivity.getWindow().getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); - } - }); - - trackSelector = new DefaultTrackSelector(mActivity); - player = new ExoPlayer.Builder(mActivity).setTrackSelector(trackSelector).build(); - playerView.setPlayer(player); - - wasPlaying = true; - - boolean muteVideo = mSharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_VIDEO, false) || - (mSharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_NSFW_VIDEO, false) && rpanBroadcast.rpanPost.isNsfw); - - if (savedInstanceState != null) { - isMute = savedInstanceState.getBoolean(IS_MUTE_STATE); - if (isMute) { - player.setVolume(0f); - muteButton.setImageResource(R.drawable.ic_mute_24dp); - } else { - player.setVolume(1f); - muteButton.setImageResource(R.drawable.ic_unmute_24dp); - } - } else if (muteVideo) { - isMute = true; - player.setVolume(0f); - muteButton.setImageResource(R.drawable.ic_mute_24dp); - } else { - muteButton.setImageResource(R.drawable.ic_unmute_24dp); - } - - player.addListener(new Player.Listener() { - @Override - public void onTracksChanged(@NonNull Tracks tracks) { - ImmutableList<Tracks.Group> trackGroups = tracks.getGroups(); - if (!trackGroups.isEmpty()) { - if (isDataSavingMode) { - trackSelector.setParameters( - trackSelector.buildUponParameters() - .setMaxVideoSize(720, 720)); - } - - hdButton.setVisibility(View.VISIBLE); - hdButton.setOnClickListener(view -> { - TrackSelectionDialogBuilder builder = new TrackSelectionDialogBuilder(mActivity, getString(R.string.select_video_quality), player, 0); - builder.setShowDisableOption(true); - builder.setAllowAdaptiveSelections(false); - Dialog dialog = builder.build(); - dialog.show(); - if (dialog instanceof AlertDialog) { - ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); - ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); - } - }); - - for (int i = 0; i < trackGroups.size(); i++) { - String mimeType = trackGroups.get(i).getTrackFormat(0).sampleMimeType; - if (mimeType != null && mimeType.contains("audio")) { - muteButton.setVisibility(View.VISIBLE); - muteButton.setOnClickListener(view -> { - if (isMute) { - isMute = false; - player.setVolume(1f); - muteButton.setImageResource(R.drawable.ic_unmute_24dp); - } else { - isMute = true; - player.setVolume(0f); - muteButton.setImageResource(R.drawable.ic_mute_24dp); - } - }); - break; - } - } - } else { - muteButton.setVisibility(View.GONE); - } - } - }); - - Glide.with(mActivity).load(rpanBroadcast.rpanPost.subredditIconUrl) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(Glide.with(mActivity).load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(subredditIconImageView); - subredditNameTextView.setText(rpanBroadcast.rpanPost.subredditName); - usernameTextView.setText(rpanBroadcast.rpanPost.username); - titleTextView.setText(rpanBroadcast.rpanPost.title); - - recyclerView.setOnTouchListener(new View.OnTouchListener() { - float x1; - float x2; - float y1; - float y2; - - @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - switch (motionEvent.getAction()) { - case MotionEvent.ACTION_DOWN: - x1 = motionEvent.getX(); - y1 = motionEvent.getY(); - return true; - case MotionEvent.ACTION_UP: - x2 = motionEvent.getX(); - y2 = motionEvent.getY(); - - if (x1 == x2 && y1 == y2) { - playerView.hideController(); - } - - return true; - } - - return false; - } - }); - adapter = new RPANCommentStreamRecyclerViewAdapter(mActivity); - recyclerView.setAdapter(adapter); - - handler = new Handler(); - - return rootView; - } - - private boolean isBehindLiveWindow(ExoPlaybackException e) { - if (e.type != ExoPlaybackException.TYPE_SOURCE) { - return false; - } - Throwable cause = e.getSourceException(); - while (cause != null) { - if (cause instanceof BehindLiveWindowException) { - return true; - } - cause = cause.getCause(); - } - return false; - } - - private void parseComment(String commentJson) { - mExecutor.execute(() -> { - try { - JSONObject commentObject = new JSONObject(commentJson); - if (commentObject.getString(JSONUtils.TYPE_KEY).equals("new_comment")) { - JSONObject payload = commentObject.getJSONObject(JSONUtils.PAYLOAD_KEY); - RPANComment rpanComment = new RPANComment( - payload.getString(JSONUtils.AUTHOR_KEY), - payload.getString(JSONUtils.AUTHOR_ICON_IMAGE), - payload.getString(JSONUtils.BODY_KEY), - payload.getLong(JSONUtils.CREATED_UTC_KEY)); - - handler.post(() -> { - LinearLayoutManagerBugFixed manager = ((LinearLayoutManagerBugFixed) recyclerView.getLayoutManager()); - boolean shouldScrollToBottom = false; - if (manager != null) { - int lastPosition = manager.findLastCompletelyVisibleItemPosition(); - int currentItemCount = adapter.getItemCount(); - if (currentItemCount > 0 && lastPosition == currentItemCount - 1) { - shouldScrollToBottom = true; - } - } - adapter.addRPANComment(rpanComment); - if (shouldScrollToBottom) { - recyclerView.smoothScrollToPosition(adapter.getItemCount() - 1); - } - }); - } - } catch (JSONException e) { - e.printStackTrace(); - } - }); - } - - @Override - public void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - outState.putBoolean(IS_MUTE_STATE, isMute); - } - - @Override - public void onResume() { - super.onResume(); - if (dataSourceFactory == null) { - dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache) - .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.USER_AGENT)); - // Prepare the player with the source. - player.prepare(); - player.setMediaSource(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(rpanBroadcast.rpanStream.hlsUrl))); - if (mSharedPreferences.getBoolean(SharedPreferencesUtils.LOOP_VIDEO, true)) { - player.setRepeatMode(Player.REPEAT_MODE_ALL); - } else { - player.setRepeatMode(Player.REPEAT_MODE_OFF); - } - if (resumePosition > 0) { - player.seekTo(resumePosition); - } - } - - if (wasPlaying) { - player.setPlayWhenReady(true); - } - - if (webSocket == null) { - Request request = new Request.Builder().url(rpanBroadcast.rpanPost.liveCommentsWebsocketUrl).build(); - CommentStreamWebSocketListener listener = new CommentStreamWebSocketListener(this::parseComment); - webSocket = okHttpClient.newWebSocket(request, listener); - } - } - - @Override - public void onPause() { - super.onPause(); - wasPlaying = player.getPlayWhenReady(); - player.setPlayWhenReady(false); - } - - @Override - public void onDestroy() { - super.onDestroy(); - player.seekToDefaultPosition(); - player.stop(true); - player.release(); - - if (webSocket != null) { - webSocket.cancel(); - } - } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - mActivity = (RPANActivity) context; - } - - private static class CommentStreamWebSocketListener extends WebSocketListener { - MessageReceivedListener messageReceivedListener; - - CommentStreamWebSocketListener(MessageReceivedListener messageReceivedListener) { - this.messageReceivedListener = messageReceivedListener; - } - - @Override - public void onMessage(@NonNull WebSocket webSocket, @NonNull String text) { - messageReceivedListener.onMessage(text); - } - - interface MessageReceivedListener { - void onMessage(String text); - } - } -}
\ No newline at end of file |