mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-01 13:57:10 +01:00
Pause rpan broadcast when switching to anther ViewRPANBroadcastFragment.
This commit is contained in:
parent
b031047d12
commit
4204ce4773
@ -33,6 +33,7 @@
|
|||||||
android:usesCleartextTraffic="true"
|
android:usesCleartextTraffic="true"
|
||||||
tools:replace="android:label">
|
tools:replace="android:label">
|
||||||
<activity android:name=".activities.RPANActivity"
|
<activity android:name=".activities.RPANActivity"
|
||||||
|
android:configChanges="orientation|screenSize|layoutDirection"
|
||||||
android:label="@string/rpan_activity_label"
|
android:label="@string/rpan_activity_label"
|
||||||
android:parentActivityName=".activities.MainActivity"
|
android:parentActivityName=".activities.MainActivity"
|
||||||
android:theme="@style/AppTheme.TranslucentStatusBar" />
|
android:theme="@style/AppTheme.TranslucentStatusBar" />
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package ml.docilealligator.infinityforreddit.activities;
|
package ml.docilealligator.infinityforreddit.activities;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -18,6 +21,9 @@ import androidx.fragment.app.FragmentActivity;
|
|||||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||||
import androidx.viewpager2.widget.ViewPager2;
|
import androidx.viewpager2.widget.ViewPager2;
|
||||||
|
|
||||||
|
import com.evernote.android.state.State;
|
||||||
|
import com.livefront.bridge.Bridge;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -53,6 +59,8 @@ public class RPANActivity extends AppCompatActivity {
|
|||||||
CoordinatorLayout coordinatorLayout;
|
CoordinatorLayout coordinatorLayout;
|
||||||
@BindView(R.id.view_pager_2_rpan_activity)
|
@BindView(R.id.view_pager_2_rpan_activity)
|
||||||
ViewPager2 viewPager2;
|
ViewPager2 viewPager2;
|
||||||
|
@BindView(R.id.progress_bar_rpan_activity)
|
||||||
|
ProgressBar progressBar;
|
||||||
@Inject
|
@Inject
|
||||||
@Named("strapi")
|
@Named("strapi")
|
||||||
Retrofit strapiRetrofit;
|
Retrofit strapiRetrofit;
|
||||||
@ -68,8 +76,10 @@ public class RPANActivity extends AppCompatActivity {
|
|||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private ArrayList<RPANBroadcast> rpanBroadcasts;
|
@State
|
||||||
private String nextCursor;
|
ArrayList<RPANBroadcast> rpanBroadcasts;
|
||||||
|
@State
|
||||||
|
String nextCursor;
|
||||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -93,23 +103,30 @@ public class RPANActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||||
|
|
||||||
|
Bridge.restoreInstanceState(this, savedInstanceState);
|
||||||
|
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
|
Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
|
||||||
actionBar.setHomeAsUpIndicator(upArrow);
|
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);
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
|
if (rpanBroadcasts == null) {
|
||||||
loadRPANVideos();
|
loadRPANVideos();
|
||||||
|
} else {
|
||||||
|
initializeViewPager();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadRPANVideos() {
|
private void loadRPANVideos() {
|
||||||
strapiRetrofit.create(Strapi.class).getAllBroadcasts(APIUtils.getOAuthHeader(mAccessToken)).enqueue(new Callback<String>() {
|
strapiRetrofit.create(Strapi.class).getAllBroadcasts(APIUtils.getOAuthHeader(mAccessToken)).enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
parseRPANBroadcasts(response.body());
|
parseRPANBroadcasts(response.body());
|
||||||
} else {
|
} else {
|
||||||
@ -120,6 +137,7 @@ public class RPANActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
Toast.makeText(RPANActivity.this,
|
Toast.makeText(RPANActivity.this,
|
||||||
R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
|
R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
@ -199,7 +217,6 @@ public class RPANActivity extends AppCompatActivity {
|
|||||||
sectionsPagerAdapter = new SectionsPagerAdapter(this);
|
sectionsPagerAdapter = new SectionsPagerAdapter(this);
|
||||||
viewPager2.setAdapter(sectionsPagerAdapter);
|
viewPager2.setAdapter(sectionsPagerAdapter);
|
||||||
viewPager2.setOffscreenPageLimit(3);
|
viewPager2.setOffscreenPageLimit(3);
|
||||||
viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false));
|
|
||||||
//fixViewPager2Sensitivity(viewPager2);
|
//fixViewPager2Sensitivity(viewPager2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ProgressBar;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
@ -50,8 +49,6 @@ public class ViewRPANBroadcastFragment extends Fragment {
|
|||||||
|
|
||||||
@BindView(R.id.player_view_view_rpan_broadcast_fragment)
|
@BindView(R.id.player_view_view_rpan_broadcast_fragment)
|
||||||
PlayerView playerView;
|
PlayerView playerView;
|
||||||
@BindView(R.id.progress_bar_view_rpan_broadcast_fragment)
|
|
||||||
ProgressBar progressBar;
|
|
||||||
@BindView(R.id.mute_exo_playback_control_view)
|
@BindView(R.id.mute_exo_playback_control_view)
|
||||||
ImageButton muteButton;
|
ImageButton muteButton;
|
||||||
@BindView(R.id.hd_exo_playback_control_view)
|
@BindView(R.id.hd_exo_playback_control_view)
|
||||||
@ -124,7 +121,6 @@ public class ViewRPANBroadcastFragment extends Fragment {
|
|||||||
if (resumePosition > 0) {
|
if (resumePosition > 0) {
|
||||||
player.seekTo(resumePosition);
|
player.seekTo(resumePosition);
|
||||||
}
|
}
|
||||||
player.setPlayWhenReady(true);
|
|
||||||
wasPlaying = true;
|
wasPlaying = true;
|
||||||
|
|
||||||
boolean muteVideo = mSharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_VIDEO, false) ||
|
boolean muteVideo = mSharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_VIDEO, false) ||
|
||||||
@ -214,16 +210,16 @@ public class ViewRPANBroadcastFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onResume() {
|
||||||
super.onStart();
|
super.onResume();
|
||||||
if (wasPlaying) {
|
if (wasPlaying) {
|
||||||
player.setPlayWhenReady(true);
|
player.setPlayWhenReady(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onPause() {
|
||||||
super.onStop();
|
super.onPause();
|
||||||
wasPlaying = player.getPlayWhenReady();
|
wasPlaying = player.getPlayWhenReady();
|
||||||
player.setPlayWhenReady(false);
|
player.setPlayWhenReady(false);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="#000000"
|
android:background="#000000"
|
||||||
android:id="@+id/coordinator_layout_rpan_activity"
|
android:id="@+id/coordinator_layout_rpan_activity"
|
||||||
|
android:keepScreenOn="true"
|
||||||
tools:context=".activities.RPANActivity">
|
tools:context=".activities.RPANActivity">
|
||||||
|
|
||||||
<androidx.viewpager2.widget.ViewPager2
|
<androidx.viewpager2.widget.ViewPager2
|
||||||
@ -13,4 +14,10 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="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>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -12,11 +12,4 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:controller_layout_id="@layout/exo_playback_control_view" />
|
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>
|
</FrameLayout>
|
Loading…
Reference in New Issue
Block a user