mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 16:16:04 -04:00
VUI fixes & improvements pt.3
Made plenty of changes to the file selector fragment Refactored FileListView to use Files instead of string paths Replaced some hardcoded strings with localizable ones
This commit is contained in:
parent
a824c5f4f5
commit
8419cee745
@ -83,7 +83,7 @@ public class mcAccountSpinner extends AppCompatSpinner implements AdapterView.On
|
||||
};
|
||||
|
||||
private final DoneListener mDoneListener = account -> {
|
||||
Toast.makeText(getContext(), "Login done", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getContext(), R.string.main_login_done, Toast.LENGTH_SHORT).show();
|
||||
mSelectecAccount = account;
|
||||
invalidate();
|
||||
mAccountList.add(account.username);
|
||||
@ -220,7 +220,7 @@ public class mcAccountSpinner extends AppCompatSpinner implements AdapterView.On
|
||||
if(fromFiles){
|
||||
mAccountList.clear();
|
||||
|
||||
mAccountList.add("Add account");
|
||||
mAccountList.add(getContext().getString(R.string.main_add_account));
|
||||
File accountFolder = new File(Tools.DIR_ACCOUNT_NEW);
|
||||
if(accountFolder.exists()){
|
||||
for (String fileName : accountFolder.list()) {
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.kdt.pickafile;
|
||||
|
||||
public interface DialogTitleListener {
|
||||
void onChangeDialogTitle(String newTitle);
|
||||
}
|
@ -3,9 +3,8 @@ package com.kdt.pickafile;
|
||||
import androidx.appcompat.app.*;
|
||||
import android.content.*;
|
||||
import android.util.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
import android.widget.AdapterView.*;
|
||||
|
||||
import com.ipaulpro.afilechooser.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
@ -15,14 +14,14 @@ import android.os.*;
|
||||
public class FileListView extends LinearLayout
|
||||
{
|
||||
//For list view:
|
||||
private String fullPath;
|
||||
private File fullPath;
|
||||
private ListView mainLv;
|
||||
private Context context;
|
||||
|
||||
//For File selected listener:
|
||||
private FileSelectedListener listener;
|
||||
private AlertDialog build;
|
||||
private String lockPath = "/";
|
||||
private FileSelectedListener fileSelectedListener;
|
||||
private DialogTitleListener dialogTitleListener;
|
||||
private File lockPath = new File("/");
|
||||
|
||||
//For filtering by file types:
|
||||
private final String[] fileSuffixes;
|
||||
@ -31,17 +30,17 @@ public class FileListView extends LinearLayout
|
||||
|
||||
public FileListView(AlertDialog build) {
|
||||
this(build.getContext(), null, new String[0]);
|
||||
this.build = build;
|
||||
dialogToTitleListener(build);
|
||||
}
|
||||
|
||||
public FileListView(AlertDialog build, String fileSuffix) {
|
||||
this(build.getContext(), null, new String[]{fileSuffix});
|
||||
this.build = build;
|
||||
dialogToTitleListener(build);
|
||||
}
|
||||
|
||||
public FileListView(AlertDialog build, String[] fileSuffixes){
|
||||
this(build.getContext(), null, fileSuffixes);
|
||||
this.build = build;
|
||||
dialogToTitleListener(build);
|
||||
}
|
||||
|
||||
public FileListView(Context context){
|
||||
@ -62,11 +61,15 @@ public class FileListView extends LinearLayout
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void dialogToTitleListener(AlertDialog dialog) {
|
||||
if(dialog != null) dialogTitleListener = dialog::setTitle;
|
||||
}
|
||||
|
||||
public void init(final Context context) {
|
||||
//Main setup:
|
||||
this.context = context;
|
||||
|
||||
LayoutParams layParam = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
|
||||
LayoutParams layParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
||||
|
||||
setOrientation(VERTICAL);
|
||||
|
||||
@ -78,7 +81,7 @@ public class FileListView extends LinearLayout
|
||||
if (p3 == 0 && !lockPath.equals(fullPath)) {
|
||||
parentDir();
|
||||
} else {
|
||||
listFileAt(mainFile.getAbsolutePath());
|
||||
listFileAt(mainFile);
|
||||
}
|
||||
});
|
||||
|
||||
@ -86,7 +89,7 @@ public class FileListView extends LinearLayout
|
||||
// TODO: Implement this method
|
||||
File mainFile = new File(p1.getItemAtPosition(p3).toString());
|
||||
if (mainFile.isFile()) {
|
||||
listener.onFileLongClick(mainFile, mainFile.getAbsolutePath());
|
||||
fileSelectedListener.onFileLongClick(mainFile, mainFile.getAbsolutePath());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -94,22 +97,24 @@ public class FileListView extends LinearLayout
|
||||
addView(mainLv, layParam);
|
||||
|
||||
try {
|
||||
listFileAt(Environment.getExternalStorageDirectory().getAbsolutePath());
|
||||
listFileAt(Environment.getExternalStorageDirectory());
|
||||
} catch (NullPointerException e) {} // Android 10+ disallows access to sdcard
|
||||
}
|
||||
public void setFileSelectedListener(FileSelectedListener listener)
|
||||
{
|
||||
this.listener = listener;
|
||||
this.fileSelectedListener = listener;
|
||||
}
|
||||
public void setDialogTitleListener(DialogTitleListener listener) {
|
||||
this.dialogTitleListener = listener;
|
||||
}
|
||||
|
||||
public void listFileAt(final String path) {
|
||||
public void listFileAt(final File path) {
|
||||
try{
|
||||
final File mainPath = new File(path);
|
||||
if(mainPath.exists()){
|
||||
if(mainPath.isDirectory()){
|
||||
if(path.exists()){
|
||||
if(path.isDirectory()){
|
||||
fullPath = path;
|
||||
|
||||
File[] listFile = mainPath.listFiles();
|
||||
File[] listFile = path.listFiles();
|
||||
FileListAdapter fileAdapter = new FileListAdapter(context);
|
||||
if(!path.equals(lockPath)){
|
||||
fileAdapter.add(new File(path, ".."));
|
||||
@ -140,9 +145,9 @@ public class FileListView extends LinearLayout
|
||||
}
|
||||
}
|
||||
mainLv.setAdapter(fileAdapter);
|
||||
if (build != null) build.setTitle(new File(path).getName());
|
||||
if(dialogTitleListener != null) dialogTitleListener.onChangeDialogTitle(path.getAbsolutePath());
|
||||
} else {
|
||||
listener.onFileSelected(mainPath, path);
|
||||
fileSelectedListener.onFileSelected(path, path.getAbsolutePath());
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(context, "This folder (or file) doesn't exist", Toast.LENGTH_SHORT).show();
|
||||
@ -153,7 +158,7 @@ public class FileListView extends LinearLayout
|
||||
}
|
||||
}
|
||||
|
||||
public String getFullPath(){
|
||||
public File getFullPath(){
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
@ -162,13 +167,12 @@ public class FileListView extends LinearLayout
|
||||
}
|
||||
|
||||
public void parentDir() {
|
||||
File pathFile = new File(fullPath);
|
||||
if(!pathFile.getAbsolutePath().equals("/")){
|
||||
listFileAt(pathFile.getParent());
|
||||
if(!fullPath.getAbsolutePath().equals("/")){
|
||||
listFileAt(fullPath.getParentFile());
|
||||
}
|
||||
}
|
||||
|
||||
public void lockPathAt(String path) {
|
||||
public void lockPathAt(File path) {
|
||||
lockPath = path;
|
||||
listFileAt(path);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class CustomControlsActivity extends BaseActivity {
|
||||
|
||||
final AlertDialog dialog = builder.create();
|
||||
FileListView flv = new FileListView(dialog, "json");
|
||||
flv.lockPathAt(Tools.CTRLMAP_PATH);
|
||||
flv.lockPathAt(new File(Tools.CTRLMAP_PATH));
|
||||
flv.setFileSelectedListener(new FileSelectedListener(){
|
||||
|
||||
@Override
|
||||
@ -200,8 +200,8 @@ public class CustomControlsActivity extends BaseActivity {
|
||||
|
||||
final AlertDialog dialog = builder.create();
|
||||
FileListView flv = new FileListView(dialog, "json");
|
||||
if(Build.VERSION.SDK_INT < 29)flv.listFileAt(Tools.CTRLMAP_PATH);
|
||||
else flv.lockPathAt(Tools.CTRLMAP_PATH);
|
||||
if(Build.VERSION.SDK_INT < 29)flv.listFileAt(new File(Tools.CTRLMAP_PATH));
|
||||
else flv.lockPathAt(new File(Tools.CTRLMAP_PATH));
|
||||
flv.setFileSelectedListener(new FileSelectedListener(){
|
||||
|
||||
@Override
|
||||
|
@ -1,13 +1,13 @@
|
||||
package net.kdt.pojavlaunch.fragments;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -31,6 +31,7 @@ public class FileSelectorFragment extends Fragment {
|
||||
|
||||
private Button mSelectFolderButton, mCreateFolderButton;
|
||||
private FileListView mFileListView;
|
||||
private TextView mFilePathView;
|
||||
|
||||
private boolean mSelectFolder = true;
|
||||
private boolean mShowFiles = true;
|
||||
@ -48,23 +49,26 @@ public class FileSelectorFragment extends Fragment {
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
bindViews(view);
|
||||
parseBundle();
|
||||
if(!mSelectFolder) mSelectFolderButton.setVisibility(View.GONE);
|
||||
else mSelectFolderButton.setVisibility(View.VISIBLE);
|
||||
|
||||
mFileListView.setShowFiles(mShowFiles);
|
||||
mFileListView.setShowFolders(mShowFolders);
|
||||
mFileListView.lockPathAt(mRootPath);
|
||||
mFileListView.lockPathAt(new File(mRootPath));
|
||||
mFileListView.setDialogTitleListener((title)->mFilePathView.setText(removeLockPath(title)));
|
||||
mFileListView.refreshPath();
|
||||
|
||||
mCreateFolderButton.setOnClickListener(v -> {
|
||||
final EditText editText = new EditText(getContext());
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle("Insert folder name")
|
||||
.setTitle(R.string.folder_dialog_insert_name)
|
||||
.setView(editText)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton("Create", (dialog, which) -> {
|
||||
.setPositiveButton(R.string.folder_dialog_create, (dialog, which) -> {
|
||||
File folder = new File(mFileListView.getFullPath(), editText.getText().toString());
|
||||
boolean success = folder.mkdir();
|
||||
if(success){
|
||||
mFileListView.listFileAt(mFileListView.getFullPath() + "/" + editText.getText().toString());
|
||||
mFileListView.listFileAt(new File(mFileListView.getFullPath(),editText.getText().toString()));
|
||||
}else{
|
||||
mFileListView.refreshPath();
|
||||
}
|
||||
@ -72,7 +76,7 @@ public class FileSelectorFragment extends Fragment {
|
||||
});
|
||||
|
||||
mSelectFolderButton.setOnClickListener(v -> {
|
||||
ExtraCore.setValue(ExtraConstants.FILE_SELECTOR, removeLockPath(mFileListView.getFullPath()));
|
||||
ExtraCore.setValue(ExtraConstants.FILE_SELECTOR, removeLockPath(mFileListView.getFullPath().getAbsolutePath()));
|
||||
Tools.removeCurrentFragment(requireActivity());
|
||||
});
|
||||
|
||||
@ -86,7 +90,7 @@ public class FileSelectorFragment extends Fragment {
|
||||
}
|
||||
|
||||
private String removeLockPath(String path){
|
||||
return path.replace(mRootPath, "");
|
||||
return path.replace(mRootPath, ".");
|
||||
}
|
||||
|
||||
private void parseBundle(){
|
||||
@ -102,5 +106,6 @@ public class FileSelectorFragment extends Fragment {
|
||||
mSelectFolderButton = view.findViewById(R.id.file_selector_select_folder);
|
||||
mCreateFolderButton = view.findViewById(R.id.file_selector_create_folder);
|
||||
mFileListView = view.findViewById(R.id.file_selector);
|
||||
mFilePathView = view.findViewById(R.id.file_selector_current_path);
|
||||
}
|
||||
}
|
||||
|
@ -102,6 +102,7 @@ public class ProfileEditorFragment extends Fragment {
|
||||
Bundle bundle = new Bundle(2);
|
||||
bundle.putBoolean(FileSelectorFragment.BUNDLE_SELECT_FOLDER, true);
|
||||
bundle.putString(FileSelectorFragment.BUNDLE_ROOT_PATH, Tools.DIR_GAME_HOME);
|
||||
bundle.putBoolean(FileSelectorFragment.BUNDLE_SHOW_FILE, false);
|
||||
mValueToConsume = FileSelectorFragment.BUNDLE_SELECT_FOLDER;
|
||||
|
||||
Tools.swapFragment(requireActivity(),
|
||||
|
@ -11,8 +11,9 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/file_selector_create_folder"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/file_selector_current_path" />
|
||||
|
||||
<com.kdt.mcgui.MineButton
|
||||
android:id="@+id/file_selector_select_folder"
|
||||
@ -42,5 +43,16 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintWidth_percent="0.45" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/file_selector_current_path"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="."
|
||||
android:textColor="@color/primary_text"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -312,4 +312,8 @@
|
||||
<string name="progresslayout_tasks_in_progress">%d tasks in progress</string>
|
||||
<string name="notification_terminate">Terminate</string>
|
||||
<string name="notification_game_runs">The game is running!</string>
|
||||
<string name="folder_dialog_create">Create</string>
|
||||
<string name="folder_dialog_insert_name">Insert folder name</string>
|
||||
<string name="main_login_done">Login done</string>
|
||||
<string name="main_add_account">Add account</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user