diff options
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
2 files changed, 26 insertions, 13 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java index 7d041d21..57b419ee 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java @@ -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); } 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 468a931f..80f98cee 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java @@ -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); } |