Pause rpan broadcast when switching to anther ViewRPANBroadcastFragment.

This commit is contained in:
Alex Ning 2021-07-06 08:36:53 +08:00
parent b031047d12
commit 4204ce4773
5 changed files with 34 additions and 20 deletions

View File

@ -33,6 +33,7 @@
android:usesCleartextTraffic="true"
tools:replace="android:label">
<activity android:name=".activities.RPANActivity"
android:configChanges="orientation|screenSize|layoutDirection"
android:label="@string/rpan_activity_label"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.TranslucentStatusBar" />

View File

@ -1,11 +1,14 @@
package ml.docilealligator.infinityforreddit.activities;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;
import androidx.annotation.NonNull;
@ -18,6 +21,9 @@ import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;
import com.evernote.android.state.State;
import com.livefront.bridge.Bridge;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -53,6 +59,8 @@ public class RPANActivity extends AppCompatActivity {
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;
@ -68,8 +76,10 @@ public class RPANActivity extends AppCompatActivity {
Executor mExecutor;
private String mAccessToken;
private String mAccountName;
private ArrayList<RPANBroadcast> rpanBroadcasts;
private String nextCursor;
@State
ArrayList<RPANBroadcast> rpanBroadcasts;
@State
String nextCursor;
private SectionsPagerAdapter sectionsPagerAdapter;
@Override
@ -93,23 +103,30 @@ public class RPANActivity extends AppCompatActivity {
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(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
loadRPANVideos();
if (rpanBroadcasts == null) {
loadRPANVideos();
} else {
initializeViewPager();
}
}
private void loadRPANVideos() {
strapiRetrofit.create(Strapi.class).getAllBroadcasts(APIUtils.getOAuthHeader(mAccessToken)).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 {
@ -120,6 +137,7 @@ public class RPANActivity extends AppCompatActivity {
@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();
}
@ -199,7 +217,6 @@ public class RPANActivity extends AppCompatActivity {
sectionsPagerAdapter = new SectionsPagerAdapter(this);
viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(3);
viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false));
//fixViewPager2Sensitivity(viewPager2);
}

View File

@ -8,7 +8,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
@ -50,8 +49,6 @@ public class ViewRPANBroadcastFragment extends Fragment {
@BindView(R.id.player_view_view_rpan_broadcast_fragment)
PlayerView playerView;
@BindView(R.id.progress_bar_view_rpan_broadcast_fragment)
ProgressBar progressBar;
@BindView(R.id.mute_exo_playback_control_view)
ImageButton muteButton;
@BindView(R.id.hd_exo_playback_control_view)
@ -124,7 +121,6 @@ public class ViewRPANBroadcastFragment extends Fragment {
if (resumePosition > 0) {
player.seekTo(resumePosition);
}
player.setPlayWhenReady(true);
wasPlaying = true;
boolean muteVideo = mSharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_VIDEO, false) ||
@ -214,16 +210,16 @@ public class ViewRPANBroadcastFragment extends Fragment {
}
@Override
public void onStart() {
super.onStart();
public void onResume() {
super.onResume();
if (wasPlaying) {
player.setPlayWhenReady(true);
}
}
@Override
public void onStop() {
super.onStop();
public void onPause() {
super.onPause();
wasPlaying = player.getPlayWhenReady();
player.setPlayWhenReady(false);
}

View File

@ -6,6 +6,7 @@
android:layout_height="match_parent"
android:background="#000000"
android:id="@+id/coordinator_layout_rpan_activity"
android:keepScreenOn="true"
tools:context=".activities.RPANActivity">
<androidx.viewpager2.widget.ViewPager2
@ -13,4 +14,10 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="@+id/progress_bar_rpan_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -12,11 +12,4 @@
android:layout_height="match_parent"
app:controller_layout_id="@layout/exo_playback_control_view" />
<ProgressBar
android:id="@+id/progress_bar_view_rpan_broadcast_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
</FrameLayout>