From e93e83ceedf9b46be091819160995c7c069e4a62 Mon Sep 17 00:00:00 2001 From: ArtDev <45949002+artdeell@users.noreply.github.com> Date: Wed, 14 Jul 2021 22:26:46 +0300 Subject: [PATCH] Clean up a bit --- .../multirt/MultiRTConfigDialog.java | 20 ++++--------------- .../kdt/pojavlaunch/multirt/MultiRTUtils.java | 18 +++++++---------- .../multirt/RTRecyclerViewAdapter.java | 11 +++++----- 3 files changed, 16 insertions(+), 33 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/MultiRTConfigDialog.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/MultiRTConfigDialog.java index 9ebe061e2..ba2991a10 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/MultiRTConfigDialog.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/MultiRTConfigDialog.java @@ -2,8 +2,6 @@ package net.kdt.pojavlaunch.multirt; import android.app.Activity; import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import androidx.recyclerview.widget.LinearLayoutManager; @@ -26,23 +24,13 @@ public class MultiRTConfigDialog { dialogView.setLayoutManager(linearLayoutManager); dialogView.setAdapter(new RTRecyclerViewAdapter(this)); builder.setView(dialogView); - builder.setPositiveButton(R.string.multirt_config_add, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - /* Initialte import */ - openRuntimeSelector(ctx,MULTIRT_PICK_RUNTIME); - } - }); - builder.setNegativeButton(R.string.mcn_exit_call, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); - } - }); + builder.setPositiveButton(R.string.multirt_config_add, (dialog, which) -> openRuntimeSelector(ctx,MULTIRT_PICK_RUNTIME)); + builder.setNegativeButton(R.string.mcn_exit_call, (dialog, which) -> dialog.cancel()); dialog = builder.create(); } public void refresh() { - dialogView.getAdapter().notifyDataSetChanged(); + RecyclerView.Adapter adapter = dialogView.getAdapter(); + if(adapter != null)dialogView.getAdapter().notifyDataSetChanged(); } public static void openRuntimeSelector(Activity ctx, int code) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/MultiRTUtils.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/MultiRTUtils.java index 3339493db..37bff2442 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/MultiRTUtils.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/MultiRTUtils.java @@ -1,11 +1,8 @@ package net.kdt.pojavlaunch.multirt; -import android.annotation.SuppressLint; import android.content.Context; import android.system.Os; -import android.util.Log; -import net.kdt.pojavlaunch.PojavLoginActivity; import net.kdt.pojavlaunch.R; import net.kdt.pojavlaunch.Tools; import net.kdt.pojavlaunch.utils.JREUtils; @@ -27,7 +24,7 @@ import java.util.HashMap; import java.util.List; public class MultiRTUtils { - public static HashMap cache = new HashMap(); + public static HashMap cache = new HashMap<>(); public static class Runtime { public Runtime(String name) { this.name = name; @@ -40,7 +37,7 @@ public class MultiRTUtils { public static interface ProgressReporterThingy { void reportStringProgress(int resid, Object ... stuff); } - private static File runtimeFolder = new File(Tools.MULTIRT_HOME); + private static final File runtimeFolder = new File(Tools.MULTIRT_HOME); private static final String JAVA_VERSION_str = "JAVA_VERSION=\""; private static final String OS_ARCH_str = "OS_ARCH=\""; public static List getRuntimes() { @@ -53,7 +50,7 @@ public class MultiRTUtils { return ret; } - public static Runtime installRuntimeNamed(InputStream runtimeInputStream, String name, ProgressReporterThingy thingy) throws IOException { + public static void installRuntimeNamed(InputStream runtimeInputStream, String name, ProgressReporterThingy thingy) throws IOException { File dest = new File(runtimeFolder,"/"+name); File tmp = new File(dest,"temporary"); if(dest.exists()) FileUtils.deleteDirectory(dest); @@ -65,7 +62,7 @@ public class MultiRTUtils { runtimeInputStream.close(); uncompressTarXZ(tmp,dest,thingy); tmp.delete(); - return read(name); + read(name); } private static void __installRuntimeNamed__NoRM(InputStream runtimeInputStream, File dest, ProgressReporterThingy thingy) throws IOException { File tmp = new File(dest,"temporary"); @@ -135,12 +132,11 @@ public class MultiRTUtils { cache.remove(name); } } - public static boolean setRuntimeNamed(Context ctx, String name) throws IOException { + public static void setRuntimeNamed(Context ctx, String name) throws IOException { File dest = new File(runtimeFolder,"/"+name); - if(!dest.exists()) return false; + if(!dest.exists()) return; Tools.DIR_HOME_JRE = dest.getAbsolutePath(); JREUtils.relocateLibPath(ctx); - return true; } private static Runtime read(String name) { if(cache.containsKey(name)) return cache.get(name); @@ -201,7 +197,7 @@ public class MultiRTUtils { try { // 40 small files per second Thread.sleep(25); - } catch (InterruptedException e) {} + } catch (InterruptedException ignored) {} } final String tarEntryName = tarEntry.getName(); // publishProgress(null, "Unpacking " + tarEntry.getName()); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/RTRecyclerViewAdapter.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/RTRecyclerViewAdapter.java index 96dfeafbb..c94ce9cd2 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/RTRecyclerViewAdapter.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/RTRecyclerViewAdapter.java @@ -8,7 +8,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; -import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; @@ -21,22 +20,22 @@ import net.kdt.pojavlaunch.prefs.LauncherPreferences; import java.io.IOException; import java.util.List; -public class RTRecyclerViewAdapter extends RecyclerView.Adapter { +public class RTRecyclerViewAdapter extends RecyclerView.Adapter { MultiRTConfigDialog dialog; public RTRecyclerViewAdapter(MultiRTConfigDialog dialog) { this.dialog = dialog; } @NonNull @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + public RTViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View recyclableView = LayoutInflater.from(parent.getContext()).inflate(R.layout.multirt_recyclable_view,parent,false); return new RTViewHolder(recyclableView); } @Override - public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + public void onBindViewHolder(@NonNull RTViewHolder holder, int position) { final List runtimes = MultiRTUtils.getRuntimes(); - ((RTViewHolder)holder).bindRuntime(runtimes.get(position),position); + holder.bindRuntime(runtimes.get(position),position); } public boolean isDefaultRuntime(MultiRTUtils.Runtime rt) { return LauncherPreferences.PREF_DEFAULT_RUNTIME.equals(rt.name); @@ -88,7 +87,7 @@ public class RTRecyclerViewAdapter extends RecyclerView.Adapter { if (currentRuntime != null) { final ProgressDialog barrier = new ProgressDialog(ctx); barrier.setMessage(ctx.getString(R.string.global_waiting)); - barrier.setProgressStyle(barrier.STYLE_SPINNER); + barrier.setProgressStyle(ProgressDialog.STYLE_SPINNER); barrier.setCancelable(false); barrier.show(); Thread t = new Thread(() -> {