From 3a041fa0f69af0d993acc9c5fb634fe48d4a9c02 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 21 Mar 2021 15:13:14 +1000 Subject: [PATCH] Android: Add a 'no games found' version of game list --- .../duckstation/EmptyGameListFragment.java | 31 +++++++++++ .../stenzek/duckstation/MainActivity.java | 28 ++++++---- .../app/src/main/res/layout/activity_main.xml | 12 +--- .../res/layout/fragment_empty_game_list.xml | 55 +++++++++++++++++++ android/app/src/main/res/values/strings.xml | 4 ++ 5 files changed, 107 insertions(+), 23 deletions(-) create mode 100644 android/app/src/main/java/com/github/stenzek/duckstation/EmptyGameListFragment.java create mode 100644 android/app/src/main/res/layout/fragment_empty_game_list.xml diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/EmptyGameListFragment.java b/android/app/src/main/java/com/github/stenzek/duckstation/EmptyGameListFragment.java new file mode 100644 index 000000000..91008735d --- /dev/null +++ b/android/app/src/main/java/com/github/stenzek/duckstation/EmptyGameListFragment.java @@ -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()); + } +} diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/MainActivity.java b/android/app/src/main/java/com/github/stenzek/duckstation/MainActivity.java index 8ba90943c..27d749066 100644 --- a/android/app/src/main/java/com/github/stenzek/duckstation/MainActivity.java +++ b/android/app/src/main/java/com/github/stenzek/duckstation/MainActivity.java @@ -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); diff --git a/android/app/src/main/res/layout/activity_main.xml b/android/app/src/main/res/layout/activity_main.xml index 54e0fcc95..c9dc2d100 100644 --- a/android/app/src/main/res/layout/activity_main.xml +++ b/android/app/src/main/res/layout/activity_main.xml @@ -46,18 +46,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" - android:layout_marginBottom="@dimen/fab_margin" - android:layout_marginRight="96dp" + android:layout_margin="@dimen/fab_margin" app:backgroundTint="@color/fab_background" app:srcCompat="@drawable/ic_baseline_play_arrow_24" /> - - \ No newline at end of file diff --git a/android/app/src/main/res/layout/fragment_empty_game_list.xml b/android/app/src/main/res/layout/fragment_empty_game_list.xml new file mode 100644 index 000000000..3b9f438f2 --- /dev/null +++ b/android/app/src/main/res/layout/fragment_empty_game_list.xml @@ -0,0 +1,55 @@ + + + + + + + + +