2019-11-28 23:06:56 +03:00
|
|
|
package su.xash.engine;
|
2016-05-01 03:15:27 +03:00
|
|
|
//Created by Solexid
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.ListActivity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2016-08-05 19:16:01 +06:00
|
|
|
import android.os.AsyncTask;
|
2016-05-01 03:15:27 +03:00
|
|
|
import android.os.Environment;
|
|
|
|
import android.os.Bundle;
|
2016-05-01 12:53:36 +00:00
|
|
|
import android.os.Build;
|
2016-05-01 03:15:27 +03:00
|
|
|
import android.util.Log;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2016-08-05 19:16:01 +06:00
|
|
|
import android.view.Window;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
|
2016-05-01 03:15:27 +03:00
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
2016-05-06 08:58:01 +00:00
|
|
|
import android.widget.Button;
|
2016-05-01 03:15:27 +03:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
2018-04-05 22:08:11 +07:00
|
|
|
import su.xash.fwgslib.FWGSLib;
|
2019-11-28 23:06:56 +03:00
|
|
|
import su.xash.engine.R;
|
2016-05-01 03:15:27 +03:00
|
|
|
|
|
|
|
public class FPicker extends Activity {
|
|
|
|
private File currentDir;
|
|
|
|
private FileArrayAdapter adapter;
|
|
|
|
static ListView delta;
|
2016-05-06 08:58:01 +00:00
|
|
|
public static final int sdk = Integer.valueOf(Build.VERSION.SDK);
|
2017-09-28 21:01:46 +03:00
|
|
|
static private Button mSelectBtn;
|
2016-05-06 08:58:01 +00:00
|
|
|
|
2016-05-01 03:15:27 +03:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
2016-08-05 19:16:01 +06:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
if ( sdk >= 21 )
|
|
|
|
super.setTheme( 0x01030224 );
|
2016-09-13 21:06:41 +03:00
|
|
|
else super.setTheme( 0x01030005 );
|
2016-08-05 19:16:01 +06:00
|
|
|
|
2017-09-28 21:01:46 +03:00
|
|
|
setContentView( R.layout.activity_fpicker );
|
2016-08-05 19:16:01 +06:00
|
|
|
String path = Environment.getExternalStorageDirectory().toString();
|
2017-09-28 21:01:46 +03:00
|
|
|
currentDir = new File( path );
|
|
|
|
mSelectBtn = ((Button)findViewById( R.id.button_fpicker_select ));
|
|
|
|
mSelectBtn.setOnClickListener(new View.OnClickListener()
|
2016-08-05 19:16:01 +06:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v)
|
|
|
|
{
|
|
|
|
onFileClick(v);
|
|
|
|
}
|
|
|
|
});
|
2018-04-05 22:08:11 +07:00
|
|
|
|
|
|
|
FWGSLib.changeButtonsStyle((ViewGroup)mSelectBtn.getParent());
|
|
|
|
|
2016-08-05 19:16:01 +06:00
|
|
|
fill(currentDir);
|
2016-05-01 03:15:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private void fill(File folder)
|
|
|
|
{
|
2017-09-28 21:01:46 +03:00
|
|
|
mSelectBtn.setEnabled( false );
|
2016-08-05 19:16:01 +06:00
|
|
|
new Fill(folder).execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
private class Fill extends AsyncTask<Void, Void, List<Item>>
|
|
|
|
{
|
|
|
|
File folder;
|
|
|
|
|
|
|
|
public Fill(File f)
|
|
|
|
{
|
|
|
|
folder = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected List<Item> doInBackground(Void... voids)
|
|
|
|
{
|
|
|
|
File[] dirs = folder.listFiles();
|
|
|
|
List<Item> dir = new ArrayList<Item>();
|
2017-06-23 09:58:36 +07:00
|
|
|
|
2016-08-05 19:16:01 +06:00
|
|
|
while( dirs == null )
|
|
|
|
{
|
2017-06-23 18:45:57 +07:00
|
|
|
String parent = folder.getParent();
|
2018-03-01 21:50:13 +03:00
|
|
|
folder = new File( parent != null ? parent : Environment.getExternalStorageDirectory().toString() );
|
2016-08-05 19:16:01 +06:00
|
|
|
dirs = folder.listFiles();
|
|
|
|
}
|
2016-05-01 03:15:27 +03:00
|
|
|
|
2018-03-01 21:50:13 +03:00
|
|
|
for( File ff: dirs )
|
2016-08-05 19:16:01 +06:00
|
|
|
{
|
|
|
|
Date lastModDate = new Date(ff.lastModified());
|
|
|
|
DateFormat formater = DateFormat.getDateTimeInstance();
|
|
|
|
String date_modify = formater.format(lastModDate);
|
|
|
|
if(ff.isDirectory())
|
|
|
|
{
|
2018-03-01 21:50:13 +03:00
|
|
|
boolean isXashDir = false;
|
2016-08-05 19:16:01 +06:00
|
|
|
File[] fbuf = ff.listFiles();
|
|
|
|
int buf = 0;
|
2018-03-01 21:50:13 +03:00
|
|
|
|
|
|
|
if( fbuf != null && fbuf.length < 20 )
|
2016-08-05 19:16:01 +06:00
|
|
|
{
|
|
|
|
buf = fbuf.length;
|
|
|
|
for (File valves: fbuf)
|
|
|
|
{
|
|
|
|
if (valves.isDirectory() && valves.getName().contains("valve"))
|
|
|
|
isXashDir=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-01 23:45:29 +03:00
|
|
|
String num_item = getResources().getQuantityString(R.plurals.item_plurals, buf, buf);
|
2020-07-07 07:26:25 +07:00
|
|
|
dir.add(new Item(ff.getName(), num_item, date_modify, ff.getAbsolutePath(), isXashDir ? R.drawable.ic_launcher : R.drawable.folder ));
|
2016-08-05 19:16:01 +06:00
|
|
|
}
|
2016-05-01 03:15:27 +03:00
|
|
|
}
|
2016-08-05 19:16:01 +06:00
|
|
|
|
|
|
|
Collections.sort(dir);
|
2016-05-01 03:15:27 +03:00
|
|
|
|
2016-11-25 11:12:31 +07:00
|
|
|
if(folder.getPath().length() > 1)
|
2018-03-01 23:45:29 +03:00
|
|
|
dir.add(0, new Item( "..", getString(R.string.parent_directory), "", folder.getParent(), R.drawable.folder));
|
2016-08-05 19:16:01 +06:00
|
|
|
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void onPostExecute(List<Item> dir)
|
|
|
|
{
|
2018-03-01 23:45:29 +03:00
|
|
|
setTitle(getString(R.string.current_dir) + " " +folder.getName());
|
2016-08-05 19:16:01 +06:00
|
|
|
|
|
|
|
adapter = new FileArrayAdapter(FPicker.this,R.layout.row,dir);
|
|
|
|
delta = (ListView)findViewById(R.id.FileView);
|
|
|
|
delta.setAdapter(adapter);
|
|
|
|
delta.setOnItemClickListener(new AdapterView.OnItemClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> parent , View v, int position, long id)
|
|
|
|
{
|
|
|
|
Item o = adapter.getItem(position);
|
|
|
|
currentDir = new File(o.getPath());
|
|
|
|
fill(currentDir);
|
|
|
|
}
|
|
|
|
});
|
2017-09-28 21:01:46 +03:00
|
|
|
FPicker.mSelectBtn.setEnabled( true );
|
2016-08-05 19:16:01 +06:00
|
|
|
}
|
2016-05-01 03:15:27 +03:00
|
|
|
}
|
2016-08-05 19:16:01 +06:00
|
|
|
|
|
|
|
public void onFileClick(View v)
|
|
|
|
{
|
2018-03-01 23:45:29 +03:00
|
|
|
Toast.makeText(this, getString(R.string.chosen_path) + " " + currentDir, Toast.LENGTH_SHORT).show();
|
2016-08-05 19:16:01 +06:00
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.putExtra("GetPath",currentDir.toString());
|
|
|
|
setResult(RESULT_OK, intent);
|
|
|
|
finish();
|
|
|
|
}
|
2016-05-01 03:15:27 +03:00
|
|
|
}
|
|
|
|
|
2016-08-05 19:16:01 +06:00
|
|
|
class FileArrayAdapter extends ArrayAdapter<Item>
|
|
|
|
{
|
|
|
|
private Context c;
|
|
|
|
private int id;
|
|
|
|
private List<Item>items;
|
2016-05-01 03:15:27 +03:00
|
|
|
|
2016-08-05 19:16:01 +06:00
|
|
|
public FileArrayAdapter(Context context, int textViewResourceId, List<Item> objects)
|
|
|
|
{
|
|
|
|
super(context, textViewResourceId, objects);
|
|
|
|
c = context;
|
|
|
|
id = textViewResourceId;
|
|
|
|
items = objects;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Item getItem(int i)
|
|
|
|
{
|
|
|
|
return items.get(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
|
View v = convertView;
|
|
|
|
if (v == null)
|
|
|
|
{
|
|
|
|
LayoutInflater vi = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
v = vi.inflate(id, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
final Item finstance = items.get(position);
|
|
|
|
if (finstance != null)
|
|
|
|
{
|
|
|
|
TextView filename = (TextView) v.findViewById(R.id.filename);
|
|
|
|
TextView fileitems = (TextView) v.findViewById(R.id.fileitems);
|
|
|
|
TextView filedate = (TextView) v.findViewById(R.id.filedate);
|
|
|
|
ImageView imageicon = (ImageView) v.findViewById(R.id.fd_Icon1);
|
2016-05-01 03:15:27 +03:00
|
|
|
|
2016-08-05 19:16:01 +06:00
|
|
|
Drawable image = c.getResources().getDrawable(finstance.getImage());
|
|
|
|
imageicon.setImageDrawable(image);
|
2016-05-01 03:15:27 +03:00
|
|
|
|
2016-08-05 19:16:01 +06:00
|
|
|
if(filename!=null)
|
|
|
|
filename.setText(finstance.getName());
|
|
|
|
if(fileitems!=null)
|
|
|
|
fileitems.setText(finstance.getData());
|
|
|
|
if(filedate!=null)
|
|
|
|
filedate.setText(finstance.getDate());
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
2016-05-01 03:15:27 +03:00
|
|
|
}
|
|
|
|
|
2017-09-28 21:01:46 +03:00
|
|
|
class Item implements Comparable<Item>
|
|
|
|
{
|
2016-08-05 19:16:01 +06:00
|
|
|
private String name;
|
|
|
|
private String data;
|
|
|
|
private String date;
|
|
|
|
private String path;
|
|
|
|
private int image;
|
|
|
|
|
|
|
|
public Item(String n,String d, String dt, String p, int img)
|
|
|
|
{
|
|
|
|
name = n;
|
|
|
|
data = d;
|
|
|
|
date = dt;
|
|
|
|
path = p;
|
|
|
|
image = img;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getName()
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getData()
|
|
|
|
{
|
|
|
|
return data;
|
2016-05-01 03:15:27 +03:00
|
|
|
}
|
2016-08-05 19:16:01 +06:00
|
|
|
|
|
|
|
public String getDate()
|
|
|
|
{
|
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPath()
|
|
|
|
{
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getImage()
|
|
|
|
{
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int compareTo(Item o)
|
|
|
|
{
|
|
|
|
if(this.name != null)
|
|
|
|
return this.name.toLowerCase().compareTo(o.getName().toLowerCase());
|
|
|
|
else
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
2016-05-01 03:15:27 +03:00
|
|
|
}
|