mirror of
https://github.com/xoureldeen/Vectras-VM-Android.git
synced 2026-05-05 09:46:33 +00:00
2.9.5.1
Testing...
This commit is contained in:
parent
f4a2afa0d0
commit
69b299c644
17 changed files with 1038 additions and 959 deletions
150
app/src/main/java/com/vectras/vm/Roms/AdapterRomStoreSearch.java
Normal file
150
app/src/main/java/com/vectras/vm/Roms/AdapterRomStoreSearch.java
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
package com.vectras.vm.Roms;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import com.vectras.vm.AppConfig;
|
||||
import com.vectras.vm.RomInfo;
|
||||
import com.vectras.vm.RomsManagerActivity;
|
||||
import com.vectras.vm.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class AdapterRomStoreSearch extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private final LayoutInflater inflater;
|
||||
static List<DataRoms> dataRom = Collections.emptyList();
|
||||
private final String TAG = "AdapterRomStoreSearch";
|
||||
|
||||
// create constructor to innitilize context and data sent from MainActivity
|
||||
public AdapterRomStoreSearch(Context context, List<DataRoms> data) {
|
||||
inflater = LayoutInflater.from(context);
|
||||
dataRom = data;
|
||||
}
|
||||
|
||||
// Inflate the layout when viewholder created
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = inflater.inflate(R.layout.container_roms, parent, false);
|
||||
return new MyHolder(view);
|
||||
}
|
||||
|
||||
// Bind data
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
|
||||
|
||||
// Get current position of item in recyclerview to bind data and assign values from list
|
||||
final MyHolder myHolder = (MyHolder) holder;
|
||||
final DataRoms current = dataRom.get(position);
|
||||
Glide.with(RomsManagerActivity.activity).load(current.romIcon).placeholder(R.drawable.ic_computer_180dp_with_padding).error(R.drawable.ic_computer_180dp_with_padding).into(myHolder.ivIcon);
|
||||
myHolder.textName.setText(current.romName);
|
||||
myHolder.textSize.setText(current.romArch + " - " + current.romSize);
|
||||
if (current.romAvail) {
|
||||
myHolder.linearItem.setOnClickListener(v -> {
|
||||
notifyItemRangeChanged(0, dataRom.size());
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(RomsManagerActivity.activity, RomInfo.class);
|
||||
intent.putExtra("title", current.romName);
|
||||
intent.putExtra("shortdesc", current.romArch + " - " + current.romSize);
|
||||
intent.putExtra("getrom", current.romUrl);
|
||||
intent.putExtra("desc", current.desc);
|
||||
intent.putExtra("icon", current.romIcon);
|
||||
intent.putExtra("filename", current.romPath);
|
||||
intent.putExtra("finalromfilename", current.finalromfilename);
|
||||
intent.putExtra("extra", current.romExtra);
|
||||
intent.putExtra("arch", current.romArch);
|
||||
intent.putExtra("verified", current.verified);
|
||||
intent.putExtra("creator", current.creator);
|
||||
intent.putExtra("size", current.fileSize);
|
||||
RomsManagerActivity.activity.startActivity(intent);
|
||||
|
||||
if (!current.romPath.endsWith(".cvbi")) {
|
||||
//Save image to icon folder
|
||||
myHolder.ivIcon.buildDrawingCache();
|
||||
Bitmap bm = myHolder.ivIcon.getDrawingCache();
|
||||
OutputStream fOut = null;
|
||||
try {
|
||||
File root = new File(AppConfig.maindirpath + "/icons/");
|
||||
if(root.mkdirs()) {
|
||||
File sdImageMainDirectory = new File(root, current.romPath + ".png");
|
||||
fOut = new FileOutputStream(sdImageMainDirectory);
|
||||
} else {
|
||||
Log.e(TAG, "Directory: " + AppConfig.maindirpath + "/icons/");
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(TAG, "File: " + Objects.requireNonNull(e.getMessage()));
|
||||
}
|
||||
|
||||
try {
|
||||
assert fOut != null;
|
||||
bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);
|
||||
fOut.flush();
|
||||
fOut.close();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Bitmap: " + Objects.requireNonNull(e.getMessage()));
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
myHolder.textAvail.setText(RomsManagerActivity.sUnavailable);
|
||||
myHolder.textAvail.setTextColor(Color.RED);
|
||||
}
|
||||
|
||||
if (position == 0) {
|
||||
myHolder.linearItem.setBackground(AppCompatResources.getDrawable(RomsManagerActivity.activity, R.drawable.object_shape_top_on_surface));
|
||||
} else if (position == dataRom.size() - 1) {
|
||||
myHolder.linearItem.setBackground(AppCompatResources.getDrawable(RomsManagerActivity.activity, R.drawable.object_shape_bottom_on_surface));
|
||||
} else {
|
||||
myHolder.linearItem.setBackground(AppCompatResources.getDrawable(RomsManagerActivity.activity, R.drawable.object_shape_middle_on_surface));
|
||||
}
|
||||
}
|
||||
|
||||
// return total item from List
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return dataRom.size();
|
||||
}
|
||||
|
||||
static class MyHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
TextView textName, textAvail, textSize;
|
||||
ImageView ivIcon;
|
||||
LinearLayout linearItem;
|
||||
|
||||
// create constructor to get widget reference
|
||||
public MyHolder(View itemView) {
|
||||
super(itemView);
|
||||
textName = itemView.findViewById(R.id.textName);
|
||||
ivIcon = itemView.findViewById(R.id.ivIcon);
|
||||
textSize = itemView.findViewById(R.id.textSize);
|
||||
textAvail = itemView.findViewById(R.id.textAvail);
|
||||
|
||||
linearItem = itemView.findViewById(R.id.linearItem);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -3,158 +3,119 @@ package com.vectras.vm.Roms;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.graphics.Color;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.webkit.URLUtil;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.vectras.vm.AppConfig;
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import com.vectras.vm.AppConfig;
|
||||
import com.vectras.vm.RomInfo;
|
||||
import com.vectras.vm.RomsManagerActivity;
|
||||
import com.vectras.vm.MainActivity;
|
||||
import com.vectras.vm.R;
|
||||
import com.vectras.vm.utils.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.app.Dialog;
|
||||
import android.widget.Toast;
|
||||
import java.util.Objects;
|
||||
|
||||
public class AdapterRoms extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Context context;
|
||||
private LayoutInflater inflater;
|
||||
static List<DataRoms> data = Collections.emptyList();
|
||||
static List<DataRoms> filteredData = Collections.emptyList();
|
||||
DataRoms current;
|
||||
int currentPos = 0;
|
||||
private int mSelectedItem = -1;
|
||||
private final LayoutInflater inflater;
|
||||
static List<DataRoms> dataRom = Collections.emptyList();
|
||||
private final String TAG = "AdapterRoms";
|
||||
|
||||
// create constructor to innitilize context and data sent from MainActivity
|
||||
public AdapterRoms(Context context, List<DataRoms> data) {
|
||||
this.context = context;
|
||||
inflater = LayoutInflater.from(context);
|
||||
AdapterRoms.data = data;
|
||||
AdapterRoms.filteredData = data;
|
||||
dataRom = data;
|
||||
}
|
||||
|
||||
// Inflate the layout when viewholder created
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = inflater.inflate(R.layout.container_roms, parent, false);
|
||||
MyHolder holder = new MyHolder(view);
|
||||
return holder;
|
||||
return new MyHolder(view);
|
||||
}
|
||||
|
||||
// Bind data
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
|
||||
|
||||
// Get current position of item in recyclerview to bind data and assign values from list
|
||||
final MyHolder myHolder = (MyHolder) holder;
|
||||
final DataRoms current = data.get(position);
|
||||
Glide.with(RomsManagerActivity.activity).load(current.itemIcon).placeholder(R.drawable.ic_computer_180dp_with_padding).error(R.drawable.ic_computer_180dp_with_padding).into(myHolder.ivIcon);
|
||||
myHolder.textName.setText(current.itemName);
|
||||
myHolder.textSize.setText(current.itemArch + " - " + current.itemSize);
|
||||
//myHolder.checkBox.setChecked(position == mSelectedItem);
|
||||
if (current.itemAvail) {
|
||||
// if (FileUtils.fileValid(RomsManagerActivity.activity, AppConfig.maindirpath + current.itemPath)) {
|
||||
// //myHolder.checkBox.setEnabled(false);
|
||||
// myHolder.textAvail.setTextColor(Color.BLUE);
|
||||
// myHolder.textAvail.setText(RomsManagerActivity.sInstalled);
|
||||
// } else {
|
||||
// //myHolder.checkBox.setEnabled(true);
|
||||
// myHolder.textAvail.setTextColor(Color.GREEN);
|
||||
// myHolder.textAvail.setText(RomsManagerActivity.sAvailable);
|
||||
// }
|
||||
myHolder.linearItem.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mSelectedItem = position;
|
||||
notifyItemRangeChanged(0, data.size());
|
||||
// RomsManagerActivity.selected = true;
|
||||
// RomsManagerActivity.selectedPath = current.itemPath;
|
||||
// RomsManagerActivity.selectedFinalRomFileName = current.itemFinalRomFileName;
|
||||
// RomsManagerActivity.selectedExtra = current.itemExtra;
|
||||
// RomsManagerActivity.selectedName = current.itemName;
|
||||
// RomsManagerActivity.selectedLink = current.itemUrl;
|
||||
// RomsManagerActivity.selectedIcon = current.itemIcon;
|
||||
// RomsManagerActivity.selectedArch = current.itemArch;
|
||||
final DataRoms current = dataRom.get(position);
|
||||
Glide.with(RomsManagerActivity.activity).load(current.romIcon).placeholder(R.drawable.ic_computer_180dp_with_padding).error(R.drawable.ic_computer_180dp_with_padding).into(myHolder.ivIcon);
|
||||
myHolder.textName.setText(current.romName);
|
||||
myHolder.textSize.setText(current.romArch + " - " + current.romSize);
|
||||
if (current.romAvail) {
|
||||
myHolder.linearItem.setOnClickListener(v -> {
|
||||
notifyItemRangeChanged(0, dataRom.size());
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(RomsManagerActivity.activity, RomInfo.class);
|
||||
intent.putExtra("title", current.itemName);
|
||||
intent.putExtra("shortdesc", current.itemArch + " - " + current.itemSize);
|
||||
intent.putExtra("getrom", current.itemUrl);
|
||||
intent.putExtra("desc", current.itemDesc);
|
||||
intent.putExtra("icon", current.itemIcon);
|
||||
intent.putExtra("filename", current.itemPath);
|
||||
intent.putExtra("finalromfilename", current.itemFinalRomFileName);
|
||||
intent.putExtra("extra", current.itemExtra);
|
||||
intent.putExtra("arch", current.itemArch);
|
||||
RomsManagerActivity.activity.startActivity(intent);
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(RomsManagerActivity.activity, RomInfo.class);
|
||||
intent.putExtra("title", current.romName);
|
||||
intent.putExtra("shortdesc", current.romArch + " - " + current.romSize);
|
||||
intent.putExtra("getrom", current.romUrl);
|
||||
intent.putExtra("desc", current.desc);
|
||||
intent.putExtra("icon", current.romIcon);
|
||||
intent.putExtra("filename", current.romPath);
|
||||
intent.putExtra("finalromfilename", current.finalromfilename);
|
||||
intent.putExtra("extra", current.romExtra);
|
||||
intent.putExtra("arch", current.romArch);
|
||||
intent.putExtra("verified", current.verified);
|
||||
intent.putExtra("creator", current.creator);
|
||||
intent.putExtra("size", current.fileSize);
|
||||
RomsManagerActivity.activity.startActivity(intent);
|
||||
|
||||
if (!current.itemPath.endsWith(".cvbi")) {
|
||||
//Save image to icon folder
|
||||
myHolder.ivIcon.buildDrawingCache();
|
||||
Bitmap bm = myHolder.ivIcon.getDrawingCache();
|
||||
OutputStream fOut = null;
|
||||
Uri outputFileUri;
|
||||
try {
|
||||
File root = new File(AppConfig.maindirpath + "/icons/");
|
||||
root.mkdirs();
|
||||
File sdImageMainDirectory = new File(root, current.itemPath + ".png");
|
||||
outputFileUri = Uri.fromFile(sdImageMainDirectory);
|
||||
if (!current.romPath.endsWith(".cvbi")) {
|
||||
//Save image to icon folder
|
||||
myHolder.ivIcon.buildDrawingCache();
|
||||
Bitmap bm = myHolder.ivIcon.getDrawingCache();
|
||||
OutputStream fOut = null;
|
||||
try {
|
||||
File root = new File(AppConfig.maindirpath + "/icons/");
|
||||
if(root.mkdirs()) {
|
||||
File sdImageMainDirectory = new File(root, current.romPath + ".png");
|
||||
fOut = new FileOutputStream(sdImageMainDirectory);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} else {
|
||||
Log.e(TAG, "Directory: " + AppConfig.maindirpath + "/icons/");
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(TAG, "File: " + Objects.requireNonNull(e.getMessage()));
|
||||
}
|
||||
|
||||
try {
|
||||
bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);
|
||||
fOut.flush();
|
||||
fOut.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
assert fOut != null;
|
||||
bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);
|
||||
fOut.flush();
|
||||
fOut.close();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Bitmap: " + Objects.requireNonNull(e.getMessage()));
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
myHolder.textAvail.setText(RomsManagerActivity.sUnavailable);
|
||||
myHolder.textAvail.setTextColor(Color.RED);
|
||||
//myHolder.checkBox.setEnabled(false);
|
||||
}
|
||||
|
||||
if (position == 0) {
|
||||
myHolder.linearItem.setBackground(AppCompatResources.getDrawable(RomsManagerActivity.activity, R.drawable.object_shape_top));
|
||||
} else if (position == data.size() - 1) {
|
||||
} else if (position == dataRom.size() - 1) {
|
||||
myHolder.linearItem.setBackground(AppCompatResources.getDrawable(RomsManagerActivity.activity, R.drawable.object_shape_bottom));
|
||||
} else {
|
||||
myHolder.linearItem.setBackground(AppCompatResources.getDrawable(RomsManagerActivity.activity, R.drawable.object_shape_middle));
|
||||
|
|
@ -164,27 +125,23 @@ public class AdapterRoms extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|||
// return total item from List
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return data.size();
|
||||
return dataRom.size();
|
||||
}
|
||||
|
||||
class MyHolder extends RecyclerView.ViewHolder {
|
||||
static class MyHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
TextView textName, textAvail, textSize;
|
||||
ImageView ivIcon;
|
||||
|
||||
//RadioButton checkBox;
|
||||
|
||||
LinearLayout linearItem;
|
||||
|
||||
// create constructor to get widget reference
|
||||
public MyHolder(View itemView) {
|
||||
super(itemView);
|
||||
textName = (TextView) itemView.findViewById(R.id.textName);
|
||||
ivIcon = (ImageView) itemView.findViewById(R.id.ivIcon);
|
||||
textSize = (TextView) itemView.findViewById(R.id.textSize);
|
||||
textAvail = (TextView) itemView.findViewById(R.id.textAvail);
|
||||
textName = itemView.findViewById(R.id.textName);
|
||||
ivIcon = itemView.findViewById(R.id.ivIcon);
|
||||
textSize = itemView.findViewById(R.id.textSize);
|
||||
textAvail = itemView.findViewById(R.id.textAvail);
|
||||
|
||||
//checkBox = (RadioButton) itemView.findViewById(R.id.checkBox);
|
||||
linearItem = itemView.findViewById(R.id.linearItem);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,34 @@
|
|||
package com.vectras.vm.Roms;
|
||||
|
||||
public class DataRoms {
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public String itemIcon;
|
||||
public String itemName;
|
||||
public String itemArch;
|
||||
public String itemKernel;
|
||||
public Boolean itemAvail;
|
||||
public String itemSize;
|
||||
public String itemUrl;
|
||||
public String itemPath;
|
||||
public String itemFinalRomFileName;
|
||||
public String itemExtra;
|
||||
public String itemDesc;
|
||||
public class DataRoms {
|
||||
@SerializedName("rom_icon")
|
||||
public String romIcon;
|
||||
@SerializedName("rom_name")
|
||||
public String romName;
|
||||
@SerializedName("rom_arch")
|
||||
public String romArch;
|
||||
@SerializedName("rom_kernel")
|
||||
public String romKernel;
|
||||
@SerializedName("rom_avail")
|
||||
public Boolean romAvail;
|
||||
@SerializedName("rom_size")
|
||||
public String romSize;
|
||||
@SerializedName("rom_url")
|
||||
public String romUrl;
|
||||
@SerializedName("rom_path")
|
||||
public String romPath;
|
||||
@SerializedName("finalromfilename")
|
||||
public String finalromfilename;
|
||||
@SerializedName("rom_extra")
|
||||
public String romExtra;
|
||||
@SerializedName("desc")
|
||||
public String desc;
|
||||
@SerializedName("filesize")
|
||||
public String fileSize;
|
||||
@SerializedName("creator")
|
||||
public String creator;
|
||||
@SerializedName("verified")
|
||||
public String verified;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue