Android: Add a 'no games found' version of game list

This commit is contained in:
Connor McLaughlin 2021-03-21 15:13:14 +10:00
parent 7831769dc3
commit 3a041fa0f6
5 changed files with 107 additions and 23 deletions

View File

@ -0,0 +1,31 @@
package com.github.stenzek.duckstation;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
public class EmptyGameListFragment extends Fragment {
private static final String SUPPORTED_FORMATS_STRING = "bin/cue, iso, img, ecm, mds, chd, pbp";
private MainActivity parent;
public EmptyGameListFragment(MainActivity parent) {
super(R.layout.fragment_empty_game_list);
this.parent = parent;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
((TextView)view.findViewById(R.id.supported_formats)).setText(
getString(R.string.main_activity_empty_game_list_supported_formats, SUPPORTED_FORMATS_STRING));
((Button)view.findViewById(R.id.add_game_directory)).setOnClickListener(v -> parent.startAddGameDirectory());
((Button)view.findViewById(R.id.start_file)).setOnClickListener(v -> parent.startStartFile());
}
}

View File

@ -18,16 +18,19 @@ import android.view.Gravity;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -52,6 +55,7 @@ public class MainActivity extends AppCompatActivity {
private ListView mGameListView; private ListView mGameListView;
private GameListFragment mGameListFragment; private GameListFragment mGameListFragment;
private GameGridFragment mGameGridFragment; private GameGridFragment mGameGridFragment;
private Fragment mEmptyGameListFragment;
private boolean mHasExternalStoragePermissions = false; private boolean mHasExternalStoragePermissions = false;
private boolean mIsShowingGameGrid = false; private boolean mIsShowingGameGrid = false;
private String mPathForChosenCoverImage = null; private String mPathForChosenCoverImage = null;
@ -120,15 +124,19 @@ public class MainActivity extends AppCompatActivity {
.putBoolean("Main/GameGridView", mIsShowingGameGrid) .putBoolean("Main/GameGridView", mIsShowingGameGrid)
.commit(); .commit();
updateGameListFragment(); updateGameListFragment(true);
invalidateOptionsMenu(); invalidateOptionsMenu();
} }
private void updateGameListFragment() { private void updateGameListFragment(boolean allowEmpty) {
final Fragment listFragment = (allowEmpty && mGameList.getEntryCount() == 0) ?
mEmptyGameListFragment :
(mIsShowingGameGrid ? mGameGridFragment : mGameListFragment);
getSupportFragmentManager() getSupportFragmentManager()
.beginTransaction() .beginTransaction()
.setReorderingAllowed(true). .setReorderingAllowed(true).
replace(R.id.content_fragment, mIsShowingGameGrid ? mGameGridFragment : mGameListFragment) replace(R.id.content_fragment, listFragment)
.commit(); .commit();
} }
@ -141,12 +149,6 @@ public class MainActivity extends AppCompatActivity {
Toolbar toolbar = findViewById(R.id.toolbar); Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
findViewById(R.id.fab_add_game_directory).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startAddGameDirectory();
}
});
findViewById(R.id.fab_resume).setOnClickListener(new View.OnClickListener() { findViewById(R.id.fab_resume).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -156,9 +158,11 @@ public class MainActivity extends AppCompatActivity {
// Set up game list view. // Set up game list view.
mGameList = new GameList(this); mGameList = new GameList(this);
mGameList.addRefreshListener(() -> updateGameListFragment(true));
mGameListFragment = new GameListFragment(this); mGameListFragment = new GameListFragment(this);
mGameGridFragment = new GameGridFragment(this); mGameGridFragment = new GameGridFragment(this);
updateGameListFragment(); mEmptyGameListFragment = new EmptyGameListFragment(this);
updateGameListFragment(false);
mHasExternalStoragePermissions = checkForExternalStoragePermissions(); mHasExternalStoragePermissions = checkForExternalStoragePermissions();
if (mHasExternalStoragePermissions) if (mHasExternalStoragePermissions)
@ -182,7 +186,7 @@ public class MainActivity extends AppCompatActivity {
UpdateNotes.displayUpdateNotes(this); UpdateNotes.displayUpdateNotes(this);
} }
private void startAddGameDirectory() { public void startAddGameDirectory() {
if (!checkForExternalStoragePermissions()) if (!checkForExternalStoragePermissions())
return; return;
@ -401,7 +405,7 @@ public class MainActivity extends AppCompatActivity {
return true; return true;
} }
private void startStartFile() { public void startStartFile() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*"); intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE); intent.addCategory(Intent.CATEGORY_OPENABLE);

View File

@ -46,18 +46,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_marginBottom="@dimen/fab_margin" android:layout_margin="@dimen/fab_margin"
android:layout_marginRight="96dp"
app:backgroundTint="@color/fab_background" app:backgroundTint="@color/fab_background"
app:srcCompat="@drawable/ic_baseline_play_arrow_24" /> app:srcCompat="@drawable/ic_baseline_play_arrow_24" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_add_game_directory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:backgroundTint="@color/fab_background"
app:srcCompat="@android:drawable/ic_input_add" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/title"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:text="@string/main_activity_empty_game_list_title"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.171" />
<TextView
android:id="@+id/supported_formats"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/main_activity_empty_game_list_supported_formats"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title" />
<Button
android:id="@+id/add_game_directory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/main_activity_empty_game_list_add_directory"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/supported_formats" />
<Button
android:id="@+id/start_file"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/main_activity_empty_game_list_start_file"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/add_game_directory" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -321,6 +321,10 @@
<string name="controller_auto_mapping_no_devices">No suitable devices found. Automatic binding only supports gamepad devices, but you can still bind other device types manually.</string> <string name="controller_auto_mapping_no_devices">No suitable devices found. Automatic binding only supports gamepad devices, but you can still bind other device types manually.</string>
<string name="controller_auto_mapping_select_device">Select Device</string> <string name="controller_auto_mapping_select_device">Select Device</string>
<string name="controller_auto_mapping_results">Automatic Binding Results</string> <string name="controller_auto_mapping_results">Automatic Binding Results</string>
<string name="main_activity_empty_game_list_title">No games were found. Please add a directory with games, or manually start a file.</string>
<string name="main_activity_empty_game_list_supported_formats">Supported formats: %s</string>
<string name="main_activity_empty_game_list_add_directory">Add Game Directory</string>
<string name="main_activity_empty_game_list_start_file">Start File</string>
<string name="update_notes_title">Update Notes</string> <string name="update_notes_title">Update Notes</string>
<string name="update_notes_message_version_controller_update">This DuckStation update includes support for multiple controllers, and binding devices such as keyboards/volume buttons.\n\nYou must re-bind your controllers, otherwise they will no longer function. Do you want to do this now?</string> <string name="update_notes_message_version_controller_update">This DuckStation update includes support for multiple controllers, and binding devices such as keyboards/volume buttons.\n\nYou must re-bind your controllers, otherwise they will no longer function. Do you want to do this now?</string>
</resources> </resources>