Use bottom toolbar in ViewVideoActivity is available.

This commit is contained in:
Alex Ning 2021-08-04 14:15:28 +08:00
parent 085eaa8505
commit 5ecb2b7f14

View File

@ -22,8 +22,10 @@ import android.view.OrientationEventListener;
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.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -51,6 +53,7 @@ import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory; import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.SimpleCache; import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.thefuntasty.hauler.DragDirection; import com.thefuntasty.hauler.DragDirection;
import com.thefuntasty.hauler.HaulerView; import com.thefuntasty.hauler.HaulerView;
@ -123,6 +126,12 @@ public class ViewVideoActivity extends AppCompatActivity {
ImageButton muteButton; ImageButton muteButton;
@BindView(R.id.hd_exo_playback_control_view) @BindView(R.id.hd_exo_playback_control_view)
ImageButton hdButton; ImageButton hdButton;
@BindView(R.id.bottom_navigation_exo_playback_control_view)
BottomAppBar bottomAppBar;
@BindView(R.id.title_text_view_exo_playback_control_view)
TextView titleTextView;
@BindView(R.id.download_image_view_exo_playback_control_view)
ImageView downloadImageView;
private Uri mVideoUri; private Uri mVideoUri;
private SimpleExoPlayer player; private SimpleExoPlayer player;
@ -203,10 +212,29 @@ public class ViewVideoActivity extends AppCompatActivity {
Resources resources = getResources(); Resources resources = getResources();
ActionBar actionBar = getSupportActionBar(); boolean useBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_BOTTOM_TOOLBAR_IN_MEDIA_VIEWER, false);
Drawable upArrow = resources.getDrawable(R.drawable.ic_arrow_back_white_24dp); if (useBottomAppBar) {
actionBar.setHomeAsUpIndicator(upArrow); getSupportActionBar().hide();
actionBar.setBackgroundDrawable(new ColorDrawable(resources.getColor(R.color.transparentActionBarAndExoPlayerControllerColor))); bottomAppBar.setVisibility(View.VISIBLE);
downloadImageView.setOnClickListener(view -> {
if (isDownloading) {
return;
}
if (videoDownloadUrl == null) {
Toast.makeText(this, R.string.fetching_video_info_please_wait, Toast.LENGTH_SHORT).show();
return;
}
isDownloading = true;
requestPermissionAndDownload();
});
} else {
ActionBar actionBar = getSupportActionBar();
Drawable upArrow = resources.getDrawable(R.drawable.ic_arrow_back_white_24dp);
actionBar.setHomeAsUpIndicator(upArrow);
actionBar.setBackgroundDrawable(new ColorDrawable(resources.getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
}
String dataSavingModeString = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF); String dataSavingModeString = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
int networkType = Utils.getConnectedNetwork(this); int networkType = Utils.getConnectedNetwork(this);
@ -584,29 +612,33 @@ public class ViewVideoActivity extends AppCompatActivity {
} }
isDownloading = true; isDownloading = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { requestPermissionAndDownload();
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
// No explanation needed; request the permission
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
} else {
// Permission has already been granted
download();
}
} else {
download();
}
return true; return true;
} }
return false; return false;
} }
private void requestPermissionAndDownload() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
// No explanation needed; request the permission
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
} else {
// Permission has already been granted
download();
}
} else {
download();
}
}
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();