mirror of
https://github.com/xoureldeen/Vectras-VM-Android.git
synced 2026-04-29 14:59:50 +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
|
|
@ -24,6 +24,7 @@ import androidx.core.view.WindowInsetsCompat;
|
|||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.vectras.qemu.MainSettingsManager;
|
||||
import com.vectras.vm.databinding.ActivityRomInfoBinding;
|
||||
import com.vectras.vm.utils.FileUtils;
|
||||
import com.vectras.vm.utils.UIUtils;
|
||||
|
||||
|
|
@ -32,13 +33,15 @@ import java.util.Objects;
|
|||
|
||||
public class RomInfo extends AppCompatActivity {
|
||||
|
||||
ActivityRomInfoBinding binding;
|
||||
public static boolean isFinishNow = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EdgeToEdge.enable(this);
|
||||
setContentView(R.layout.activity_rom_info);
|
||||
binding = ActivityRomInfoBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
// UIUtils.setOnApplyWindowInsetsListener(findViewById(R.id.main));
|
||||
|
||||
ImageView ivIcon;
|
||||
|
|
@ -152,4 +155,40 @@ public class RomInfo extends AppCompatActivity {
|
|||
public String getPath(Uri uri) {
|
||||
return FileUtils.getPath(RomInfo.this, uri);
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
if (getIntent().hasExtra("verified")) {
|
||||
if (!getIntent().getBooleanExtra("verified", false)) {
|
||||
binding.ivVerified.setImageResource(R.drawable.gpp_maybe_24px);
|
||||
binding.tvVerified.setText(getString(R.string.not_verified));
|
||||
}
|
||||
}
|
||||
|
||||
if (getIntent().hasExtra("creator")) {
|
||||
binding.tvCreator.setText(getIntent().getStringExtra("creator"));
|
||||
}
|
||||
|
||||
switch (Objects.requireNonNull(getIntent().getStringExtra("arch"))) {
|
||||
case "X86_64":
|
||||
binding.tvArch.setText("x86_64");
|
||||
break;
|
||||
case "i386":
|
||||
binding.tvArch.setText("i386");
|
||||
break;
|
||||
case "ARM64":
|
||||
binding.tvArch.setText("ARM64");
|
||||
break;
|
||||
case "PowerPC":
|
||||
binding.tvArch.setText("PowerPC");
|
||||
break;
|
||||
}
|
||||
|
||||
if (getIntent().hasExtra("size")) {
|
||||
binding.tvSize.setText(getIntent().getStringExtra("size"));
|
||||
}
|
||||
|
||||
if (getIntent().hasExtra("filename")) {
|
||||
binding.tvFilename.setText(getIntent().getStringExtra("filename"));
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,145 +1,53 @@
|
|||
package com.vectras.vm;
|
||||
|
||||
import static android.content.Intent.ACTION_OPEN_DOCUMENT;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.StrictMode;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.Html;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.webkit.URLUtil;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.google.android.material.button.MaterialButtonToggleGroup;
|
||||
import com.vectras.qemu.Config;
|
||||
import com.vectras.qemu.MainSettingsManager;
|
||||
import com.vectras.qemu.MainVNCActivity;
|
||||
import com.vectras.vm.AppConfig;
|
||||
import com.vectras.vm.Fragment.HomeFragment;
|
||||
import com.vectras.vm.MainRoms.AdapterMainRoms;
|
||||
import com.vectras.vm.MainRoms.DataMainRoms;
|
||||
import com.google.android.material.search.SearchBar;
|
||||
import com.google.android.material.search.SearchView;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import com.vectras.vm.Roms.AdapterRomStoreSearch;
|
||||
import com.vectras.vm.Roms.AdapterRoms;
|
||||
import com.vectras.vm.Roms.DataRoms;
|
||||
import com.vectras.vm.logger.VectrasStatus;
|
||||
import com.vectras.qemu.utils.FileInstaller;
|
||||
import com.vectras.vm.utils.FileUtils;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
|
||||
import com.vectras.vm.utils.UIUtils;
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileWriter;
|
||||
import java.io.InputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RomsManagerActivity extends AppCompatActivity {
|
||||
|
||||
private RequestNetwork net;
|
||||
private RequestNetwork.RequestListener _net_request_listener;
|
||||
private String contentJSON = "";
|
||||
|
||||
private String contentJSON = "[]";
|
||||
public static RomsManagerActivity activity;
|
||||
|
||||
public static MaterialButton goBtn;
|
||||
|
||||
public static AlertDialog ad;
|
||||
|
||||
public static String license;
|
||||
public static RecyclerView mRVRoms;
|
||||
public static AdapterRoms mAdapter;
|
||||
public static List<DataRoms> data;
|
||||
public static Boolean selected = false;
|
||||
public static String selectedPath = null;
|
||||
public static String selectedExtra = null;
|
||||
public static String selectedLink = null;
|
||||
public static String selectedName = null;
|
||||
public static String selectedIcon = null;
|
||||
public static String selectedArch = null;
|
||||
public static String selectedFinalRomFileName = null;
|
||||
|
||||
public MaterialButtonToggleGroup filterToggle;
|
||||
public MaterialButton windowsToggle;
|
||||
public MaterialButton linuxToggle;
|
||||
public MaterialButton appleToggle;
|
||||
public MaterialButton androidToggle;
|
||||
public MaterialButton otherToggle;
|
||||
|
||||
public ProgressBar loadingPb;
|
||||
|
||||
private SearchView searchView;
|
||||
private RecyclerView romsSearch;
|
||||
private AdapterRoms mAdapter;
|
||||
private AdapterRomStoreSearch mAdapterSearch;
|
||||
private List<DataRoms> data = new ArrayList<>();
|
||||
private List<DataRoms> dataSearch = new ArrayList<>();
|
||||
private LinearLayout linearload;
|
||||
private LinearLayout linearnothinghere;
|
||||
private Button buttontryagain;
|
||||
|
||||
public static String sAvailable = "";
|
||||
public static String sUnavailable = "";
|
||||
public static String sInstalled = "";
|
||||
|
|
@ -148,44 +56,18 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
super.onBackPressed();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* CHECK WHETHER INTERNET CONNECTION IS AVAILABLE OR NOT
|
||||
*/
|
||||
public boolean checkConnection(Context context) {
|
||||
final ConnectivityManager connMgr = (ConnectivityManager) context
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
if (connMgr != null) {
|
||||
NetworkInfo activeNetworkInfo = connMgr.getActiveNetworkInfo();
|
||||
|
||||
if (activeNetworkInfo != null) { // connected to the internet
|
||||
// connected to the mobile provider's data plan
|
||||
if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
||||
// connected to wifi
|
||||
return true;
|
||||
} else
|
||||
return activeNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
|
|
@ -194,85 +76,53 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
|
||||
super.onCreate(savedInstanceState);
|
||||
activity = this;
|
||||
|
||||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
||||
StrictMode.setThreadPolicy(policy);
|
||||
|
||||
sAvailable = getResources().getString(R.string.available);
|
||||
sUnavailable = getResources().getString(R.string.unavailable);
|
||||
sInstalled = getResources().getString(R.string.installed);
|
||||
SharedPreferences prefs = getSharedPreferences(CREDENTIAL_SHARED_PREF, Context.MODE_PRIVATE);
|
||||
boolean isAccessed = prefs.getBoolean("isFirstLaunch", false);
|
||||
//if (!isAccessed && !checkConnection(activity))
|
||||
//UIUtils.UIAlert(activity, "for first time you need internet connection to load app data!", "No internet connection!");
|
||||
|
||||
UIUtils.edgeToEdge(this);
|
||||
setContentView(R.layout.activity_roms_manager);
|
||||
// UIUtils.setOnApplyWindowInsetsListener(findViewById(R.id.main));
|
||||
UIUtils.setOnApplyWindowInsetsListenerTop(findViewById(R.id.appbar));
|
||||
UIUtils.setOnApplyWindowInsetsListenerBottom(findViewById(R.id.romsRv));
|
||||
UIUtils.setOnApplyWindowInsetsListenerBottom(findViewById(R.id.romsSearch));
|
||||
UIUtils.setOnApplyWindowInsetsListenerBottom(findViewById(R.id.linear_search_emty));
|
||||
|
||||
linearload = findViewById(R.id.linearload);
|
||||
linearnothinghere = findViewById(R.id.linearnothinghere);
|
||||
buttontryagain = findViewById(R.id.buttontryagain);
|
||||
// loadingPb = findViewById(R.id.loadingPb);
|
||||
filterToggle = findViewById(R.id.filterToggle);
|
||||
windowsToggle = findViewById(R.id.windowsToggle);
|
||||
linuxToggle = findViewById(R.id.linuxToggle);
|
||||
appleToggle = findViewById(R.id.appleToggle);
|
||||
androidToggle = findViewById(R.id.androidToggle);
|
||||
otherToggle = findViewById(R.id.otherToggle);
|
||||
Button buttontryagain = findViewById(R.id.buttontryagain);
|
||||
RecyclerView mRVRoms = findViewById(R.id.romsRv);
|
||||
romsSearch = findViewById(R.id.romsSearch);
|
||||
|
||||
mRVRoms = findViewById(R.id.romsRv);
|
||||
filterToggle.addOnButtonCheckedListener(new MaterialButtonToggleGroup.OnButtonCheckedListener() {
|
||||
mAdapter = new AdapterRoms(this, data);
|
||||
mRVRoms.setAdapter(mAdapter);
|
||||
mRVRoms.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
|
||||
|
||||
romsSearch = findViewById(R.id.romsSearch);
|
||||
mAdapterSearch = new AdapterRomStoreSearch(this, dataSearch);
|
||||
romsSearch.setAdapter(mAdapterSearch);
|
||||
romsSearch.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
|
||||
|
||||
SearchBar searchBar = findViewById(R.id.search_bar);
|
||||
searchBar.setNavigationOnClickListener(v -> onBackPressed());
|
||||
|
||||
searchView = findViewById(R.id.searchView);
|
||||
searchView.getEditText().addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void onButtonChecked(MaterialButtonToggleGroup group, int checkedId, boolean isChecked) {
|
||||
if (checkedId == R.id.windowsToggle) {
|
||||
if (isChecked)
|
||||
filter = "windows";
|
||||
else
|
||||
filter = null;
|
||||
} else if (checkedId == R.id.linuxToggle) {
|
||||
if (isChecked)
|
||||
filter = "linux";
|
||||
else
|
||||
filter = null;
|
||||
} else if (checkedId == R.id.appleToggle) {
|
||||
if (isChecked)
|
||||
filter = "apple";
|
||||
else
|
||||
filter = null;
|
||||
} else if (checkedId == R.id.androidToggle) {
|
||||
if (isChecked)
|
||||
filter = "android";
|
||||
else
|
||||
filter = null;
|
||||
} else if (checkedId == R.id.otherToggle) {
|
||||
if (isChecked)
|
||||
filter = "other";
|
||||
else
|
||||
filter = null;
|
||||
}
|
||||
loadData();
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
});
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
setTitle(getResources().getString(R.string.roms_store));
|
||||
|
||||
goBtn = (MaterialButton) findViewById(R.id.goBtn);
|
||||
|
||||
goBtn.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
onFirstStartup();
|
||||
public void afterTextChanged(Editable s) {
|
||||
search(s.toString());
|
||||
}
|
||||
});
|
||||
|
||||
CardView custom = (CardView) findViewById(R.id.cdCustom);
|
||||
|
||||
custom.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(new Intent(activity, CustomRomActivity.class));
|
||||
public void onTextChanged(CharSequence newText, int start, int before, int count) {
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -280,10 +130,10 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
_net_request_listener = new RequestNetwork.RequestListener() {
|
||||
@Override
|
||||
public void onResponse(String tag, String response, HashMap<String, Object> responseHeaders) {
|
||||
contentJSON = response;
|
||||
if (contentJSON.length() == 0)
|
||||
contentJSON ="[]";
|
||||
if (!response.isEmpty())
|
||||
contentJSON = response;
|
||||
loadData();
|
||||
loadDataSearch();
|
||||
linearload.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
|
@ -294,15 +144,12 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
}
|
||||
};
|
||||
|
||||
buttontryagain.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
linearload.setVisibility(View.VISIBLE);
|
||||
net.startRequestNetwork(RequestNetworkController.GET,AppConfig.vectrasRaw + "vroms-store.json","anbui",_net_request_listener);
|
||||
}
|
||||
buttontryagain.setOnClickListener(v -> {
|
||||
linearload.setVisibility(View.VISIBLE);
|
||||
net.startRequestNetwork(RequestNetworkController.GET,AppConfig.vectrasRaw + "vroms-store.json","",_net_request_listener);
|
||||
});
|
||||
|
||||
net.startRequestNetwork(RequestNetworkController.GET,AppConfig.vectrasRaw + "vroms-store.json","anbui",_net_request_listener);
|
||||
net.startRequestNetwork(RequestNetworkController.GET,AppConfig.vectrasRaw + "vroms-store.json","",_net_request_listener);
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
|
|
@ -313,349 +160,83 @@ public class RomsManagerActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
private void loadData() {
|
||||
data = new ArrayList<>();
|
||||
try {
|
||||
JSONArray jArray = new JSONArray(contentJSON);
|
||||
List<DataRoms> dataRoms;
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<List<DataRoms>>() {}.getType();
|
||||
dataRoms = gson.fromJson(contentJSON, listType);
|
||||
|
||||
data.clear();
|
||||
data.addAll(dataRoms);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
} catch (Exception e) {
|
||||
linearload.setVisibility(View.GONE);
|
||||
linearnothinghere.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadDataSearch() {
|
||||
List<DataRoms> dataRoms;
|
||||
try {
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<List<DataRoms>>() {}.getType();
|
||||
dataRoms = gson.fromJson(contentJSON, listType);
|
||||
|
||||
dataSearch.clear();
|
||||
dataSearch.addAll(dataRoms);
|
||||
mAdapterSearch.notifyDataSetChanged();
|
||||
} catch (Exception e) {
|
||||
linearload.setVisibility(View.GONE);
|
||||
linearnothinghere.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void search(String keyword) {
|
||||
try {
|
||||
// Extract data from json and store into ArrayList as class objects
|
||||
for (int i = 0; i < jArray.length(); i++) {
|
||||
JSONObject json_data = jArray.getJSONObject(i);
|
||||
DataRoms romsData = new DataRoms();
|
||||
romsData.itemName = json_data.getString("rom_name");
|
||||
romsData.itemIcon = json_data.getString("rom_icon");
|
||||
romsData.itemUrl = json_data.getString("rom_url");
|
||||
romsData.itemPath = json_data.getString("rom_path");
|
||||
romsData.itemFinalRomFileName = json_data.getString("final_rom_file_name");
|
||||
romsData.itemAvail = json_data.getBoolean("rom_avail");
|
||||
romsData.itemSize = json_data.getString("rom_size");
|
||||
romsData.itemArch = json_data.getString("rom_arch");
|
||||
romsData.itemKernel = json_data.getString("rom_kernel");
|
||||
romsData.itemExtra = json_data.getString("rom_extra");
|
||||
romsData.itemDesc = json_data.getString("desc");
|
||||
if (filter != null) {
|
||||
if (romsData.itemKernel.toLowerCase().contains(filter.toLowerCase())) {
|
||||
data.add(romsData);
|
||||
}
|
||||
} else {
|
||||
data.add(romsData);
|
||||
}
|
||||
}
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<List<DataRoms>>() {}.getType();
|
||||
List<DataRoms> allData = gson.fromJson(contentJSON, listType);
|
||||
List<DataRoms> filteredData = new ArrayList<>();
|
||||
|
||||
// Setup and Handover data to recyclerview
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
filteredData = allData.stream()
|
||||
.filter(rom -> {
|
||||
String romName = (rom.romName != null) ? rom.romName : "";
|
||||
String romKernel = (rom.romKernel != null) ? rom.romKernel : "";
|
||||
|
||||
} catch (JSONException e) {
|
||||
UIUtils.UIAlert(activity, "ERROR", e.toString());
|
||||
}
|
||||
mRVRoms = (RecyclerView) activity.findViewById(R.id.romsRv);
|
||||
mAdapter = new AdapterRoms(activity, data);
|
||||
mRVRoms.setAdapter(mAdapter);
|
||||
mRVRoms.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
|
||||
}
|
||||
|
||||
|
||||
public static String filter = null;
|
||||
|
||||
public static class RomsJso extends JSONObject {
|
||||
|
||||
public JSONObject makeJSONObject(String imgName, String imgIcon, String imgArch, String imgPath, String imgExtra) {
|
||||
|
||||
JSONObject obj = new JSONObject();
|
||||
|
||||
try {
|
||||
obj.put("imgName", imgName);
|
||||
obj.put("imgIcon", imgIcon);
|
||||
obj.put("imgArch", imgArch);
|
||||
obj.put("imgPath", imgPath);
|
||||
obj.put("imgExtra", imgExtra);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
public static final String CREDENTIAL_SHARED_PREF = "settings_prefs";
|
||||
|
||||
private void startIconDownload() {
|
||||
|
||||
}
|
||||
|
||||
public void onFirstStartup() {
|
||||
if (selected) {
|
||||
if (FileUtils.fileValid(activity, AppConfig.maindirpath + selectedPath)) {
|
||||
SharedPreferences credentials = activity.getSharedPreferences(CREDENTIAL_SHARED_PREF, Context.MODE_PRIVATE);
|
||||
ProgressDialog mProgressDialog = new ProgressDialog(this, R.style.MainDialogTheme);
|
||||
mProgressDialog.setTitle("Data Setup");
|
||||
mProgressDialog.setMessage("Please Wait...");
|
||||
mProgressDialog.setCancelable(false);
|
||||
mProgressDialog.show();
|
||||
//FileInstaller.installFiles(activity, false);
|
||||
SharedPreferences.Editor editor = credentials.edit();
|
||||
editor.putBoolean("isFirstLaunch", Boolean.TRUE);
|
||||
editor.apply();
|
||||
RomsJso obj = new RomsJso();
|
||||
try {
|
||||
startIconDownload();
|
||||
} catch (Exception e) {
|
||||
File file = new File(selectedPath);
|
||||
try {
|
||||
file.delete();
|
||||
} catch (Exception er) {
|
||||
throw new RuntimeException(er);
|
||||
}
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
mProgressDialog.dismiss();
|
||||
final File jsonFile = new File(AppConfig.maindirpath + "roms-data.json");
|
||||
|
||||
if (jsonFile.exists()) {
|
||||
try {
|
||||
List<DataMainRoms> data = new ArrayList<>();
|
||||
JSONArray jArray = new JSONArray(FileUtils.readFromFile(MainActivity.activity, jsonFile));
|
||||
|
||||
try {
|
||||
// Extract data from json and store into ArrayList as class objects
|
||||
for (int i = 0; i < jArray.length(); i++) {
|
||||
JSONObject json_data = jArray.getJSONObject(i);
|
||||
DataMainRoms romsMainData = new DataMainRoms();
|
||||
romsMainData.itemName = json_data.getString("imgName");
|
||||
romsMainData.itemIcon = json_data.getString("imgIcon");
|
||||
romsMainData.itemPath = json_data.getString("imgPath");
|
||||
romsMainData.itemExtra = json_data.getString("imgExtra");
|
||||
data.add(romsMainData);
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
Toast.makeText(MainActivity.activity, e.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
JSONObject jsonObject = obj.makeJSONObject(selectedName, AppConfig.maindirpath + "icons/" + selectedPath.replace(".IMG", ".jpg"), MainSettingsManager.getArch(activity), AppConfig.maindirpath + selectedPath, selectedExtra);
|
||||
jArray.put(jsonObject);
|
||||
try {
|
||||
Writer output = null;
|
||||
output = new BufferedWriter(new FileWriter(jsonFile));
|
||||
output.write(jArray.toString().replace("\\", "").replace("//", "/"));
|
||||
output.close();
|
||||
} catch (Exception e) {
|
||||
UIUtils.toastLong(activity, e.toString());
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
UIUtils.toastLong(activity, e.toString());
|
||||
}
|
||||
//MainActivity.activity.finish();
|
||||
} else {
|
||||
JSONObject jsonObject = obj.makeJSONObject(selectedName, AppConfig.maindirpath + "icons/" + selectedPath.replace(".IMG", ".jpg"), MainSettingsManager.getArch(activity), AppConfig.maindirpath + selectedPath, selectedExtra);
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
jsonArray.put(jsonObject);
|
||||
try {
|
||||
Writer output = null;
|
||||
output = new BufferedWriter(new FileWriter(jsonFile));
|
||||
output.write(jsonArray.toString().replace("\\", "").replace("//", "/"));
|
||||
output.close();
|
||||
} catch (Exception e) {
|
||||
UIUtils.toastLong(activity, e.toString());
|
||||
}
|
||||
VectrasStatus.logInfo("Welcome to Vectras ♡");
|
||||
}
|
||||
|
||||
/*new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
mProgressDialog.dismiss(); }
|
||||
}, 3000);*/
|
||||
finish();
|
||||
startActivity(new Intent(activity, SplashActivity.class));
|
||||
}
|
||||
return romName.toLowerCase().contains(keyword.toLowerCase())
|
||||
|| romKernel.toLowerCase().contains(keyword.toLowerCase());
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
AlertDialog ad;
|
||||
ad = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
|
||||
ad.setTitle(selectedPath);
|
||||
ad.setMessage("Have you downloaded this file yet? If you have, you will need to select it to continue. If not, you can get it.");
|
||||
ad.setButton(Dialog.BUTTON_POSITIVE, "Select that file now", (dialog, which) -> {
|
||||
Intent intent = new Intent(ACTION_OPEN_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("*/*");
|
||||
|
||||
// Optionally, specify a URI for the file that should appear in the
|
||||
// system file picker when it loads.
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, Environment.DIRECTORY_DOWNLOADS);
|
||||
for (DataRoms rom : allData) {
|
||||
if (rom.romName.toLowerCase().contains(keyword.toLowerCase()) ||
|
||||
rom.romKernel.toLowerCase().contains(keyword.toLowerCase())) {
|
||||
filteredData.add(rom);
|
||||
}
|
||||
|
||||
startActivityForResult(intent, 0);
|
||||
});
|
||||
ad.setButton(Dialog.BUTTON_NEGATIVE, "Get " + selectedPath.replace(".IMG", ".vbi"), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (selectedLink != null) {
|
||||
String gt = selectedLink;
|
||||
Intent g = new Intent(Intent.ACTION_VIEW);
|
||||
g.setData(Uri.parse(gt));
|
||||
startActivity(g);
|
||||
}
|
||||
}
|
||||
});
|
||||
ad.show();
|
||||
}
|
||||
} else {
|
||||
AlertDialog ad;
|
||||
ad = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
|
||||
ad.setTitle("Please Select");
|
||||
ad.setMessage("Select the os (operating system) you need.");
|
||||
ad.setButton(Dialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
ad.show();
|
||||
}
|
||||
}
|
||||
|
||||
public String getPath(Uri uri) {
|
||||
return FileUtils.getPath(activity, uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == 0 && resultCode == RESULT_OK) {
|
||||
Uri content_describer = data.getData();
|
||||
File selectedFilePath = new File(getPath(content_describer));
|
||||
if (selectedFilePath.getName().equals(selectedPath) || (selectedFilePath.getName().endsWith(".cvbi.zip") && selectedFilePath.getName().equals(selectedPath + ".zip"))) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(getApplicationContext(), CustomRomActivity.class);
|
||||
intent.putExtra("addromnow", "");
|
||||
intent.putExtra("romname", selectedName);
|
||||
intent.putExtra("romfilename", selectedPath);
|
||||
intent.putExtra("finalromfilename", selectedFinalRomFileName);
|
||||
intent.putExtra("rompath", selectedFilePath.getPath());
|
||||
if (selectedExtra.contains(selectedFilePath.getName())) {
|
||||
intent.putExtra("addtodrive", "");
|
||||
intent.putExtra("romextra", selectedExtra);
|
||||
} else {
|
||||
intent.putExtra("addtodrive", "1");
|
||||
intent.putExtra("romextra", selectedExtra);
|
||||
}
|
||||
intent.putExtra("romicon", AppConfig.maindirpath + "icons/" + selectedPath + ".png");
|
||||
switch (selectedArch) {
|
||||
case "X86_64":
|
||||
MainSettingsManager.setArch(this, "X86_64");
|
||||
break;
|
||||
case "i386":
|
||||
MainSettingsManager.setArch(this, "I386");
|
||||
break;
|
||||
case "ARM64":
|
||||
MainSettingsManager.setArch(this, "ARM64");
|
||||
break;
|
||||
case "PowerPC":
|
||||
MainSettingsManager.setArch(this, "PPC");
|
||||
break;
|
||||
}
|
||||
startActivity(intent);
|
||||
} else {
|
||||
UIUtils.UIAlert(activity, "Please select " + selectedPath.replace(".IMG", ".vbi") + " file to continue.", "File not supported");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class DownloadsImage extends AsyncTask<String, Void, Void> {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(String... strings) {
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL(strings[0]);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Bitmap bm = null;
|
||||
try {
|
||||
bm = BitmapFactory.decodeStream(url.openConnection().getInputStream());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//Create Path to save Image
|
||||
File path = new File(AppConfig.maindirpath + "icons"); //Creates app specific folder
|
||||
|
||||
if (!path.exists()) {
|
||||
path.mkdirs();
|
||||
}
|
||||
|
||||
File imageFile = new File(path, selectedPath.replace(".IMG", ".jpg")); // Imagename.png
|
||||
FileOutputStream out = null;
|
||||
try {
|
||||
out = new FileOutputStream(imageFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
bm.compress(Bitmap.CompressFormat.PNG, 100, out); // Compress Image
|
||||
out.flush();
|
||||
out.close();
|
||||
// Tell the media scanner about the new file so that it is
|
||||
// immediately available to the user.
|
||||
MediaScannerConnection.scanFile(activity, new String[]{imageFile.getAbsolutePath()}, null, new MediaScannerConnection.OnScanCompletedListener() {
|
||||
public void onScanCompleted(String path, Uri uri) {
|
||||
// Log.i("ExternalStorage", "Scanned " + path + ":");
|
||||
// Log.i("ExternalStorage", "-> uri=" + uri);
|
||||
}
|
||||
});
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return null;
|
||||
dataSearch.clear();
|
||||
dataSearch.addAll(filteredData);
|
||||
} catch (Exception e) {
|
||||
Log.e("RomManagerActivity", "Json parsing error: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
super.onPostExecute(aVoid);
|
||||
}
|
||||
if (dataSearch.isEmpty())
|
||||
romsSearch.setVisibility(View.GONE);
|
||||
else
|
||||
romsSearch.setVisibility(View.VISIBLE);
|
||||
|
||||
mAdapterSearch.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
if (getParentActivityIntent() == MainActivity.activity.getIntent())
|
||||
finish();
|
||||
if (searchView.isShowing())
|
||||
searchView.hide();
|
||||
else
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (MainSettingsManager.getArch(activity) == null) {
|
||||
startActivity(new Intent(this, SetArchActivity.class));
|
||||
}
|
||||
activity = this;
|
||||
}
|
||||
|
||||
private String getDataFromUrl(String _url) {
|
||||
Log.d("RomsManagerActivity", _url);
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
URL url = new URL(_url);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setConnectTimeout(30000);
|
||||
conn.setReadTimeout(30000);
|
||||
conn.setRequestMethod("GET");
|
||||
conn.connect();
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String response;
|
||||
|
||||
while ((response = br.readLine()) != null) {
|
||||
sb.append(response);
|
||||
}
|
||||
return sb.toString();
|
||||
} catch (ExceptionInInitializerError ex) {
|
||||
ex.printStackTrace();
|
||||
return "[]";
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "[]";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -434,4 +434,31 @@ public class UIUtils {
|
|||
return insets;
|
||||
});
|
||||
}
|
||||
|
||||
public static void setOnApplyWindowInsetsListenerTop(View _view) {
|
||||
int originalPaddingLeft = _view.getPaddingLeft();
|
||||
int originalPaddingTop = _view.getPaddingTop();
|
||||
int originalPaddingRight = _view.getPaddingRight();
|
||||
int originalPaddingBottom = _view.getPaddingBottom();
|
||||
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(_view, (v, insets) -> {
|
||||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout() | WindowInsetsCompat.Type.ime());
|
||||
v.setPadding(systemBars.left + originalPaddingLeft , systemBars.top + originalPaddingTop, systemBars.right + originalPaddingRight, originalPaddingBottom);
|
||||
return insets;
|
||||
});
|
||||
}
|
||||
|
||||
public static void setOnApplyWindowInsetsListenerBottom(View _view) {
|
||||
int originalPaddingLeft = _view.getPaddingLeft();
|
||||
int originalPaddingTop = _view.getPaddingTop();
|
||||
int originalPaddingRight = _view.getPaddingRight();
|
||||
int originalPaddingBottom = _view.getPaddingBottom();
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(_view, (v, insets) -> {
|
||||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout() | WindowInsetsCompat.Type.ime());
|
||||
v.setPadding(systemBars.left + originalPaddingLeft, originalPaddingTop, systemBars.right + originalPaddingRight, systemBars.bottom + originalPaddingBottom);
|
||||
return insets;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue