Make the gamelist look nicer and indicate files with a wrong extension visually

This commit is contained in:
FearlessTobi 2020-04-01 06:49:17 +02:00 committed by bunnei
parent e66a086560
commit b254548b39
7 changed files with 46 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package org.citra.citra_emu.adapters;
import android.database.Cursor; import android.database.Cursor;
import android.database.DataSetObserver; import android.database.DataSetObserver;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.SystemClock; import android.os.SystemClock;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -11,18 +12,22 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import org.citra.citra_emu.CitraApplication;
import org.citra.citra_emu.R; import org.citra.citra_emu.R;
import org.citra.citra_emu.activities.EmulationActivity; import org.citra.citra_emu.activities.EmulationActivity;
import org.citra.citra_emu.model.GameDatabase; import org.citra.citra_emu.model.GameDatabase;
import org.citra.citra_emu.ui.DividerItemDecoration;
import org.citra.citra_emu.utils.Log; import org.citra.citra_emu.utils.Log;
import org.citra.citra_emu.utils.PicassoUtils; import org.citra.citra_emu.utils.PicassoUtils;
import org.citra.citra_emu.viewholders.GameViewHolder; import org.citra.citra_emu.viewholders.GameViewHolder;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.stream.Stream;
/** /**
* This adapter gets its information from a database Cursor. This fact, paired with the usage of * This adapter gets its information from a database Cursor. This fact, paired with the usage of
@ -95,6 +100,9 @@ public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl
holder.country = mCursor.getInt(GameDatabase.GAME_COLUMN_COUNTRY); holder.country = mCursor.getInt(GameDatabase.GAME_COLUMN_COUNTRY);
holder.company = mCursor.getString(GameDatabase.GAME_COLUMN_COMPANY); holder.company = mCursor.getString(GameDatabase.GAME_COLUMN_COMPANY);
holder.screenshotPath = mCursor.getString(GameDatabase.GAME_COLUMN_SCREENSHOT_PATH); holder.screenshotPath = mCursor.getString(GameDatabase.GAME_COLUMN_SCREENSHOT_PATH);
final int backgroundColorId = isValidGame(holder.path) ? R.color.card_view_background : R.color.card_view_disabled;
holder.setBackgroundColor(ContextCompat.getColor(CitraApplication.getAppContext(), backgroundColorId));
} else { } else {
Log.error("[GameAdapter] Can't bind view; Cursor is not valid."); Log.error("[GameAdapter] Can't bind view; Cursor is not valid.");
} }
@ -197,10 +205,11 @@ public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl
EmulationActivity.launch((FragmentActivity) view.getContext(), holder.path, holder.title); EmulationActivity.launch((FragmentActivity) view.getContext(), holder.path, holder.title);
} }
public static class SpacesItemDecoration extends RecyclerView.ItemDecoration { public static class SpacesItemDecoration extends DividerItemDecoration {
private int space; private int space;
public SpacesItemDecoration(int space) { public SpacesItemDecoration(Drawable divider, int space) {
super(divider);
this.space = space; this.space = space;
} }
@ -214,6 +223,11 @@ public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl
} }
} }
private boolean isValidGame(String path) {
return Stream.of(
".rar", ".zip", ".7z", ".torrent", ".tar", ".gz").noneMatch(suffix -> path.toLowerCase().endsWith(suffix));
}
private final class GameDataSetObserver extends DataSetObserver { private final class GameDataSetObserver extends DataSetObserver {
@Override @Override
public void onChanged() { public void onChanged() {

View File

@ -16,7 +16,7 @@ import androidx.recyclerview.widget.RecyclerView;
* Implementation from: * Implementation from:
* https://gist.github.com/lapastillaroja/858caf1a82791b6c1a36 * https://gist.github.com/lapastillaroja/858caf1a82791b6c1a36
*/ */
public final class DividerItemDecoration extends RecyclerView.ItemDecoration { public class DividerItemDecoration extends RecyclerView.ItemDecoration {
private Drawable mDivider; private Drawable mDivider;
private boolean mShowFirstDivider = false; private boolean mShowFirstDivider = false;

View File

@ -6,6 +6,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -46,7 +47,7 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam
mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setAdapter(mAdapter); mRecyclerView.setAdapter(mAdapter);
mRecyclerView.addItemDecoration(new GameAdapter.SpacesItemDecoration(1)); mRecyclerView.addItemDecoration(new GameAdapter.SpacesItemDecoration(ContextCompat.getDrawable(getActivity(), R.drawable.gamelist_divider), 1));
// Add swipe down to refresh gesture // Add swipe down to refresh gesture
final SwipeRefreshLayout pullToRefresh = view.findViewById(R.id.refresh_grid_games); final SwipeRefreshLayout pullToRefresh = view.findViewById(R.id.refresh_grid_games);

View File

@ -13,6 +13,7 @@ import org.citra.citra_emu.R;
* keep calling findViewById(), which is expensive. * keep calling findViewById(), which is expensive.
*/ */
public class GameViewHolder extends RecyclerView.ViewHolder { public class GameViewHolder extends RecyclerView.ViewHolder {
private View itemView;
public ImageView imageScreenshot; public ImageView imageScreenshot;
public TextView textGameTitle; public TextView textGameTitle;
public TextView textCompany; public TextView textCompany;
@ -31,6 +32,7 @@ public class GameViewHolder extends RecyclerView.ViewHolder {
public GameViewHolder(View itemView) { public GameViewHolder(View itemView) {
super(itemView); super(itemView);
this.itemView = itemView;
itemView.setTag(this); itemView.setTag(this);
imageScreenshot = itemView.findViewById(R.id.image_game_screen); imageScreenshot = itemView.findViewById(R.id.image_game_screen);
@ -38,4 +40,8 @@ public class GameViewHolder extends RecyclerView.ViewHolder {
textCompany = itemView.findViewById(R.id.text_company); textCompany = itemView.findViewById(R.id.text_company);
textFileName = itemView.findViewById(R.id.text_filename); textFileName = itemView.findViewById(R.id.text_filename);
} }
public void setBackgroundColor(int color){
itemView.setBackgroundColor(color);
}
} }

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="1dp"
android:height="1dp" />
<solid android:color="@color/gamelist_divider" />
</shape>

View File

@ -3,4 +3,9 @@
<color name="citra_orange">#fec303</color> <color name="citra_orange">#fec303</color>
<color name="card_view_background">#121212</color>
<color name="card_view_disabled">#303030</color>
<color name="gamelist_divider">#404040</color>
</resources> </resources>

View File

@ -7,4 +7,9 @@
<color name="lb_tv_white">#FFCCCCCC</color> <color name="lb_tv_white">#FFCCCCCC</color>
<color name="card_view_background">#ffffff</color>
<color name="card_view_disabled">#dddddd</color>
<color name="gamelist_divider">#ffffff</color>
</resources> </resources>