Skip to content

Commit

Permalink
Replace Picasso with Glide
Browse files Browse the repository at this point in the history
  • Loading branch information
t895 committed Jun 27, 2022
1 parent e18053d commit 2499a23
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 200 deletions.
4 changes: 2 additions & 2 deletions Source/Android/app/build.gradle
Expand Up @@ -109,8 +109,8 @@ dependencies {
// For REST calls
implementation 'com.android.volley:volley:1.2.1'

// For loading huge screenshots from the disk.
implementation 'com.squareup.picasso:picasso:2.71828'
// For loading screenshots from the disk.
implementation 'com.github.bumptech.glide:glide:4.13.1'

implementation 'com.nononsenseapps:filepicker:4.2.1'
}
Expand Down
Expand Up @@ -17,7 +17,7 @@
import org.dolphinemu.dolphinemu.dialogs.GamePropertiesDialog;
import org.dolphinemu.dolphinemu.model.GameFile;
import org.dolphinemu.dolphinemu.services.GameFileCacheManager;
import org.dolphinemu.dolphinemu.utils.PicassoUtils;
import org.dolphinemu.dolphinemu.utils.GlideUtils;
import org.dolphinemu.dolphinemu.viewholders.GameViewHolder;

import java.util.ArrayList;
Expand Down Expand Up @@ -72,7 +72,7 @@ public void onBindViewHolder(GameViewHolder holder, int position)
{
Context context = holder.itemView.getContext();
GameFile gameFile = mGameFiles.get(position);
PicassoUtils.loadGameCover(holder.imageScreenshot, gameFile);
GlideUtils.loadGameCover(holder.imageScreenshot, gameFile);

holder.textGameTitle.setText(gameFile.getTitle());

Expand Down
Expand Up @@ -17,7 +17,7 @@
import org.dolphinemu.dolphinemu.model.GameFile;
import org.dolphinemu.dolphinemu.services.GameFileCacheManager;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.utils.PicassoUtils;
import org.dolphinemu.dolphinemu.utils.GlideUtils;
import org.dolphinemu.dolphinemu.viewholders.TvGameViewHolder;

/**
Expand Down Expand Up @@ -51,7 +51,7 @@ public void onBindViewHolder(ViewHolder viewHolder, Object item)
GameFile gameFile = (GameFile) item;

holder.imageScreenshot.setImageDrawable(null);
PicassoUtils.loadGameCover(holder.imageScreenshot, gameFile);
GlideUtils.loadGameCover(holder.imageScreenshot, gameFile);

holder.cardParent.setTitleText(gameFile.getTitle());

Expand Down
Expand Up @@ -16,7 +16,7 @@
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.model.GameFile;
import org.dolphinemu.dolphinemu.services.GameFileCacheManager;
import org.dolphinemu.dolphinemu.utils.PicassoUtils;
import org.dolphinemu.dolphinemu.utils.GlideUtils;

public final class GameDetailsDialog extends DialogFragment
{
Expand Down Expand Up @@ -114,7 +114,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
}
}

PicassoUtils.loadGameBanner(banner, gameFile);
GlideUtils.loadGameBanner(banner, gameFile);

builder.setView(contents);
return builder.create();
Expand Down

This file was deleted.

@@ -0,0 +1,163 @@
// SPDX-License-Identifier: GPL-2.0-or-later

package org.dolphinemu.dolphinemu.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
import org.dolphinemu.dolphinemu.model.GameFile;

import java.io.File;

public class GlideUtils
{
public static void loadGameBanner(ImageView imageView, GameFile gameFile)
{
Context context = imageView.getContext();
int[] vector = gameFile.getBanner();
int width = gameFile.getBannerWidth();
int height = gameFile.getBannerHeight();
if (width > 0 && height > 0)
{
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.setPixels(vector, 0, width, 0, 0, width, height);
Glide.with(context)
.load(bitmap)
.centerCrop()
.into(imageView);
}
else
{
Glide.with(context)
.load(R.drawable.no_banner)
.centerCrop()
.into(imageView);
}
}

public static void loadGameCover(ImageView imageView, GameFile gameFile)
{
Context context = imageView.getContext();
File cover = new File(gameFile.getCustomCoverPath());
if (cover.exists())
{
Glide.with(context)
.load(cover)
.centerCrop()
.error(R.drawable.no_banner)
.into(imageView);
}
else if ((cover = new File(gameFile.getCoverPath(context))).exists())
{
Glide.with(context)
.load(cover)
.centerCrop()
.error(R.drawable.no_banner)
.into(imageView);
}
// GameTDB has a pretty close to complete collection for US/EN covers. First pass at getting
// the cover will be by the disk's region, second will be the US cover, and third EN.
else if (BooleanSetting.MAIN_USE_GAME_COVERS.getBooleanGlobal())
{
Glide.with(context)
.load(CoverHelper.buildGameTDBUrl(gameFile, CoverHelper.getRegion(gameFile)))
.centerCrop()
.listener(new RequestListener<Drawable>()
{
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model,
Target<Drawable> target, boolean isFirstResource)
{
return false;
}

@Override
public boolean onResourceReady(Drawable resource,
Object model, Target<Drawable> target,
DataSource dataSource, boolean isFirstResource)
{
CoverHelper.saveCover(
((BitmapDrawable) resource).getBitmap(),
gameFile.getCoverPath(context));
return false;
}
})
.error(
Glide.with(context)
.load(CoverHelper.buildGameTDBUrl(gameFile, "US"))
.centerCrop()
.listener(new RequestListener<Drawable>()
{
@Override
public boolean onLoadFailed(@Nullable GlideException e,
Object model, Target<Drawable> target,
boolean isFirstResource)
{
return false;
}

@Override
public boolean onResourceReady(Drawable resource,
Object model, Target<Drawable> target,
DataSource dataSource, boolean isFirstResource)
{
CoverHelper.saveCover(
((BitmapDrawable) resource).getBitmap(),
gameFile.getCoverPath(context));
return false;
}
})
.error(
Glide.with(context)
.load(CoverHelper.buildGameTDBUrl(gameFile, "EN"))
.centerCrop()
.listener(new RequestListener<Drawable>()
{
@Override
public boolean onLoadFailed(
@Nullable GlideException e,
Object model, Target<Drawable> target,
boolean isFirstResource)
{
return false;
}

@Override
public boolean onResourceReady(Drawable resource,
Object model, Target<Drawable> target,
DataSource dataSource,
boolean isFirstResource)
{
CoverHelper.saveCover(
((BitmapDrawable) resource).getBitmap(),
gameFile.getCoverPath(context));
return false;
}
})
.error(R.drawable.no_banner)
)
)
.into(imageView);
}
else
{
Glide.with(context)
.load(R.drawable.no_banner)
.centerCrop()
.into(imageView);
}
}
}

0 comments on commit 2499a23

Please sign in to comment.