aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-07-06 15:40:37 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-07-06 15:40:37 +0000
commitac72a30458ca6e2557abedbd1ba2247dd5c366eb (patch)
tree42716881419ac0f715dbd69c53b546d85728338c /app/src
parent236b6b66f1bc60bdcec1322367f0239174e2d802 (diff)
downloadinfinity-for-reddit-ac72a30458ca6e2557abedbd1ba2247dd5c366eb.tar
infinity-for-reddit-ac72a30458ca6e2557abedbd1ba2247dd5c366eb.tar.gz
infinity-for-reddit-ac72a30458ca6e2557abedbd1ba2247dd5c366eb.tar.bz2
infinity-for-reddit-ac72a30458ca6e2557abedbd1ba2247dd5c366eb.tar.lz
infinity-for-reddit-ac72a30458ca6e2557abedbd1ba2247dd5c366eb.tar.xz
infinity-for-reddit-ac72a30458ca6e2557abedbd1ba2247dd5c366eb.tar.zst
infinity-for-reddit-ac72a30458ca6e2557abedbd1ba2247dd5c366eb.zip
Initialize player and websocket connection in onResume in ViewRPANBroadcastFragment.
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java39
2 files changed, 35 insertions, 20 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
index b539fc89..435969a0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
@@ -44,7 +44,7 @@ class AppModule {
@Provides
@Named("oauth")
@Singleton
- Retrofit provideOauthRetrofit(OkHttpClient okHttpClient) {
+ Retrofit provideOauthRetrofit(@Named("default") OkHttpClient okHttpClient) {
return new Retrofit.Builder()
.baseUrl(APIUtils.OAUTH_API_BASE_URI)
.client(okHttpClient)
@@ -155,7 +155,7 @@ class AppModule {
@Provides
@Named("strapi")
@Singleton
- Retrofit providestrapiRetrofit(OkHttpClient okHttpClient) {
+ Retrofit providestrapiRetrofit(@Named("default") OkHttpClient okHttpClient) {
return new Retrofit.Builder()
.baseUrl(APIUtils.STRAPI_BASE_URI)
.client(okHttpClient)
@@ -164,6 +164,7 @@ class AppModule {
}
@Provides
+ @Named("default")
@Singleton
OkHttpClient provideOkHttpClient(@Named("no_oauth") Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase,
@Named("current_account") SharedPreferences currentAccountSharedPreferences) {
@@ -177,6 +178,17 @@ class AppModule {
}
@Provides
+ @Named("rpan")
+ @Singleton
+ OkHttpClient provideRPANOkHttpClient() {
+ return new OkHttpClient.Builder()
+ .connectTimeout(30, TimeUnit.SECONDS)
+ .readTimeout(30, TimeUnit.SECONDS)
+ .writeTimeout(30, TimeUnit.SECONDS)
+ .build();
+ }
+
+ @Provides
@Singleton
RedditDataRoomDatabase provideRedditDataRoomDatabase() {
return RedditDataRoomDatabase.getDatabase(mApplication);
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 5fa26888..bc3d92ae 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java
@@ -40,7 +40,6 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.util.concurrent.Executor;
-import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Named;
@@ -85,6 +84,9 @@ public class ViewRPANBroadcastFragment extends Fragment {
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
+ @Inject
+ @Named("rpan")
+ OkHttpClient okHttpClient;
private AppCompatActivity mActivity;
private RPANBroadcast rpanBroadcast;
private SimpleExoPlayer player;
@@ -92,6 +94,7 @@ public class ViewRPANBroadcastFragment extends Fragment {
private DataSource.Factory dataSourceFactory;
private Handler handler;
private RPANCommentStreamRecyclerViewAdapter adapter;
+ private WebSocket webSocket;
private boolean wasPlaying;
private boolean isMute = false;
@@ -152,13 +155,6 @@ public class ViewRPANBroadcastFragment extends Fragment {
player = ExoPlayerFactory.newSimpleInstance(mActivity, trackSelector);
playerView.setPlayer(player);
- dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(mActivity, "Infinity"));
- // Prepare the player with the source.
- player.prepare(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(rpanBroadcast.rpanStream.hlsUrl)));
- player.setRepeatMode(Player.REPEAT_MODE_ALL);
- if (resumePosition > 0) {
- player.seekTo(resumePosition);
- }
wasPlaying = true;
boolean muteVideo = mSharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_VIDEO, false) ||
@@ -229,16 +225,6 @@ public class ViewRPANBroadcastFragment extends Fragment {
handler = new Handler();
- Request request = new Request.Builder().url(rpanBroadcast.rpanPost.liveCommentsWebsocketUrl).build();
- CommentStreamWebSocketListener listener = new CommentStreamWebSocketListener(this::parseComment);
- OkHttpClient okHttpClient = new OkHttpClient.Builder()
- .connectTimeout(30, TimeUnit.SECONDS)
- .readTimeout(30, TimeUnit.SECONDS)
- .writeTimeout(30, TimeUnit.SECONDS)
- .build();
- WebSocket webSocket = okHttpClient.newWebSocket(request, listener);
- okHttpClient.dispatcher().executorService().shutdown();
-
return rootView;
}
@@ -299,9 +285,26 @@ public class ViewRPANBroadcastFragment extends Fragment {
@Override
public void onResume() {
super.onResume();
+ if (dataSourceFactory == null) {
+ dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(mActivity, "Infinity"));
+ // Prepare the player with the source.
+ player.prepare(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(rpanBroadcast.rpanStream.hlsUrl)));
+ player.setRepeatMode(Player.REPEAT_MODE_ALL);
+ 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);
+ okHttpClient.dispatcher().executorService().shutdown();
+ }
}
@Override