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