mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-09 23:59:27 +01:00
Merge pull request #11272 from t895/tv-update-fix
Android: Use progress bar that does not inherit from AppCompat on leanback
This commit is contained in:
commit
f614f94568
@ -10,6 +10,7 @@ import android.widget.Button;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
|||||||
|
|
||||||
import org.dolphinemu.dolphinemu.R;
|
import org.dolphinemu.dolphinemu.R;
|
||||||
import org.dolphinemu.dolphinemu.databinding.DialogProgressBinding;
|
import org.dolphinemu.dolphinemu.databinding.DialogProgressBinding;
|
||||||
|
import org.dolphinemu.dolphinemu.databinding.DialogProgressTvBinding;
|
||||||
|
|
||||||
public class SystemUpdateProgressBarDialogFragment extends DialogFragment
|
public class SystemUpdateProgressBarDialogFragment extends DialogFragment
|
||||||
{
|
{
|
||||||
@ -32,32 +34,58 @@ public class SystemUpdateProgressBarDialogFragment extends DialogFragment
|
|||||||
SystemUpdateViewModel viewModel =
|
SystemUpdateViewModel viewModel =
|
||||||
new ViewModelProvider(requireActivity()).get(SystemUpdateViewModel.class);
|
new ViewModelProvider(requireActivity()).get(SystemUpdateViewModel.class);
|
||||||
|
|
||||||
DialogProgressBinding dialogProgressBinding =
|
DialogProgressBinding dialogProgressBinding;
|
||||||
DialogProgressBinding.inflate(getLayoutInflater());
|
DialogProgressTvBinding dialogProgressTvBinding;
|
||||||
|
|
||||||
// We need to set the message to something here, otherwise the text will not appear when we set it later.
|
// We need to set the message to something here, otherwise the text will not appear when we set it later.
|
||||||
AlertDialog progressDialog = new MaterialAlertDialogBuilder(requireContext())
|
MaterialAlertDialogBuilder progressDialogBuilder =
|
||||||
.setTitle(getString(R.string.updating))
|
new MaterialAlertDialogBuilder(requireContext())
|
||||||
.setMessage("")
|
.setTitle(getString(R.string.updating))
|
||||||
.setNegativeButton(getString(R.string.cancel), null)
|
.setMessage("")
|
||||||
.setView(dialogProgressBinding.getRoot())
|
.setNegativeButton(getString(R.string.cancel), null)
|
||||||
.setCancelable(false)
|
.setCancelable(false);
|
||||||
.create();
|
|
||||||
|
|
||||||
viewModel.getProgressData()
|
// TODO: Remove dialog_progress_tv if we switch to an AppCompatActivity for leanback
|
||||||
.observe(this, (@Nullable
|
if (getActivity() instanceof AppCompatActivity)
|
||||||
Integer progress) -> dialogProgressBinding.updateProgress.setProgress(
|
|
||||||
progress));
|
|
||||||
|
|
||||||
viewModel.getTotalData().observe(this, (@Nullable Integer total) ->
|
|
||||||
{
|
{
|
||||||
if (total == 0)
|
dialogProgressBinding = DialogProgressBinding.inflate(getLayoutInflater());
|
||||||
{
|
progressDialogBuilder.setView(dialogProgressBinding.getRoot());
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dialogProgressBinding.updateProgress.setMax(total);
|
viewModel.getProgressData().observe(this,
|
||||||
});
|
(@Nullable Integer progress) -> dialogProgressBinding.updateProgress.setProgress(
|
||||||
|
progress));
|
||||||
|
|
||||||
|
viewModel.getTotalData().observe(this, (@Nullable Integer total) ->
|
||||||
|
{
|
||||||
|
if (total == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dialogProgressBinding.updateProgress.setMax(total);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dialogProgressTvBinding = DialogProgressTvBinding.inflate(getLayoutInflater());
|
||||||
|
progressDialogBuilder.setView(dialogProgressTvBinding.getRoot());
|
||||||
|
|
||||||
|
viewModel.getProgressData().observe(this,
|
||||||
|
(@Nullable Integer progress) -> dialogProgressTvBinding.updateProgress.setProgress(
|
||||||
|
progress));
|
||||||
|
|
||||||
|
viewModel.getTotalData().observe(this, (@Nullable Integer total) ->
|
||||||
|
{
|
||||||
|
if (total == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dialogProgressTvBinding.updateProgress.setMax(total);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
AlertDialog progressDialog = progressDialogBuilder.create();
|
||||||
|
|
||||||
viewModel.getTitleIdData().observe(this, (@Nullable Long titleId) -> progressDialog.setMessage(
|
viewModel.getTitleIdData().observe(this, (@Nullable Long titleId) -> progressDialog.setMessage(
|
||||||
getString(R.string.updating_message, titleId)));
|
getString(R.string.updating_message, titleId)));
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/dialog_progress"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/update_progress"
|
||||||
|
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:layout_marginEnd="24dp"
|
||||||
|
android:layout_marginStart="24dp"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:indeterminate="false" />
|
||||||
|
|
||||||
|
</androidx.appcompat.widget.LinearLayoutCompat>
|
Loading…
x
Reference in New Issue
Block a user