add icons

This commit is contained in:
olebeck 2024-04-28 18:23:19 +02:00
parent 0929574b08
commit df15995772
4 changed files with 79 additions and 1 deletions

View File

@ -25,6 +25,14 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
applicationVariants.configureEach { variant ->
variant.outputs.configureEach {
def flavor = variant.name
def versionName = variant.versionName
outputFileName = "${applicationName}-${flavor}_${versionName}.apk"
}
}
}
dependencies {

View File

@ -0,0 +1,53 @@
package com.psmreborn.pkga;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.util.Log;
import android.view.animation.AlphaAnimation;
import android.widget.ImageView;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
public class DownloadImage {
static void download(Context context, String url, ImageView imageView, File cacheIcon, String titleId) {
Handler handler = new Handler(context.getMainLooper());
new Thread(() -> {
try {
InputStream in = new URL(url).openStream();
OutputStream out = new FileOutputStream(cacheIcon);
byte[] buffer = new byte[1024];
int len;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
out.flush();
out.close();
in.close();
final Bitmap icon = BitmapFactory.decodeFile(cacheIcon.getAbsolutePath());
handler.post(() -> {
String tag = (String)imageView.getTag();
if(!titleId.equals(tag)) {
return;
}
AlphaAnimation animation = new AlphaAnimation(0f, 1f);
animation.setDuration(250);
animation.setFillAfter(true);
imageView.setAnimation(animation);
imageView.setImageBitmap(icon);
});
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
}).start();
}
}

View File

@ -1,6 +1,8 @@
package com.psmreborn.pkga;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -8,8 +10,10 @@ import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.File;
import java.util.ArrayList;
public class GameListAdapter extends ArrayAdapter<Game> implements Filterable {
@ -39,6 +43,17 @@ public class GameListAdapter extends ArrayAdapter<Game> implements Filterable {
download_button.setOnClickListener(view -> {
this.downloadHandler.call(game);
});
ImageView icon = (ImageView)convertView.findViewById(R.id.download_item_image);
File cachedIcon = new File(getContext().getCacheDir(), game.titleId+".png");
if(cachedIcon.exists()) {
Bitmap bitmap = BitmapFactory.decodeFile(cachedIcon.getAbsolutePath());
icon.setImageBitmap(bitmap);
} else {
icon.setImageBitmap(null);
icon.setTag(game.titleId);
DownloadImage.download(getContext(), String.format("http://psmreborn.com/gameinfo/%s/icon_128x128.png", game.titleId), icon, cachedIcon, game.titleId);
}
return convertView;
}

View File

@ -18,4 +18,6 @@ android.useAndroidX=true
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
applicationName = PKGa