use of com.cloudrail.si.types.CloudMetaData in project cloudrail-si-android-sdk by CloudRail.
the class CloudMetadataAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// assign the view we are converting to a local variable
View v = convertView;
// to inflate it basically means to render, or show, the view.
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.list_item, null);
}
final CloudMetaData cmd = this.data.get(position);
if (cmd != null) {
final ImageView img = (ImageView) v.findViewById(R.id.icon);
if (img != null) {
if (cmd.getFolder()) {
img.setImageResource(R.drawable.ic_file_folder);
} else {
img.setImageResource(R.drawable.ic_editor_insert_drive_file);
}
}
TextView tv = (TextView) v.findViewById(R.id.list_item);
tv.setText(cmd.getName());
}
return v;
}
use of com.cloudrail.si.types.CloudMetaData in project cloudrail-si-android-sdk by CloudRail.
the class Files method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_files, container, false);
TextView tv = (TextView) v.findViewById(R.id.service_name);
switch(this.currentService) {
case 1:
{
tv.setText("My Dropbox:");
break;
}
case 2:
{
tv.setText("My Box:");
break;
}
case 3:
{
tv.setText("My GoogleDrive:");
break;
}
case 4:
{
tv.setText("My OneDrive:");
break;
}
case 5:
{
tv.setText("My Egnyte:");
break;
}
case 6:
{
tv.setText("My OneDrive Business:");
break;
}
}
final TextView tv2 = (TextView) v.findViewById(R.id.allocation);
new Thread(new Runnable() {
@Override
public void run() {
final SpaceAllocation alloc = getService().getAllocation();
getOwnActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
String used = getSizeString(alloc.getUsed());
String total = getSizeString(alloc.getTotal());
tv2.setText(used + " used of " + total);
}
});
}
}).start();
this.list = (ListView) v.findViewById(R.id.listView);
this.list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
startSpinner();
LinearLayout ll = (LinearLayout) view;
TextView tv = (TextView) ll.findViewById(R.id.list_item);
final String name = (String) tv.getText();
new Thread(new Runnable() {
@Override
public void run() {
String next = currentPath;
if (!currentPath.equals("/")) {
next += "/";
}
next += name;
CloudMetaData info = getService().getMetadata(next);
if (info.getFolder()) {
setNewPath(next);
} else {
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
InputStream data = getService().download(next);
File file = new File(path, name);
try {
FileOutputStream stream = new FileOutputStream(file, true);
pipe(data, stream);
data.close();
stream.close();
} catch (Exception e) {
stopSpinner();
e.printStackTrace();
}
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
getOwnActivity().sendBroadcast(intent);
String ext = getMimeType(name);
String mime = null;
stopSpinner();
if (ext != null && isDisplayable(ext)) {
mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), mime);
startActivity(intent);
} else {
getOwnActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(context, "Download complete! Stored to download folder.", Toast.LENGTH_SHORT).show();
}
});
}
}
}
}).start();
}
});
this.list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
selectedItem = view;
PopupMenu popupMenu = new PopupMenu(getOwnActivity(), view);
MenuInflater menuInflater = getOwnActivity().getMenuInflater();
menuInflater.inflate(R.menu.selected_item_bar, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.action_delete:
{
removeItem();
return true;
}
case R.id.action_copy:
{
copyItem();
return true;
}
case R.id.action_create_share_link:
{
createShareLink();
return true;
}
case R.id.action_cut:
{
cutItem();
return true;
}
default:
return false;
}
}
});
popupMenu.show();
return true;
}
});
this.spinner = (ProgressBar) v.findViewById(R.id.spinner);
this.spinner.setVisibility(View.GONE);
this.currentPath = "/";
this.updateList();
return v;
}
use of com.cloudrail.si.types.CloudMetaData in project cloudrail-si-android-sdk by CloudRail.
the class Files method sortList.
private List<CloudMetaData> sortList(List<CloudMetaData> list) {
List<CloudMetaData> folders = new ArrayList<>();
List<CloudMetaData> files = new ArrayList<>();
for (CloudMetaData cmd : list) {
if (cmd == null)
continue;
if (cmd.getFolder()) {
folders.add(cmd);
} else {
files.add(cmd);
}
}
folders.addAll(files);
return folders;
}
use of com.cloudrail.si.types.CloudMetaData in project cloudrail-si-android-sdk by CloudRail.
the class Files method findSafeName.
private String findSafeName(List<CloudMetaData> cmds, String fileNameStart, String fileNameEnd, int i) {
String checkName = fileNameStart;
if (i != 0) {
checkName += "(" + i + ")";
}
checkName += "." + fileNameEnd;
for (CloudMetaData cmd : cmds) {
if (checkName.equals(cmd.getPath())) {
return findSafeName(cmds, fileNameStart, fileNameEnd, i + 1);
}
}
System.out.println("returning checkName " + checkName);
return checkName;
}
use of com.cloudrail.si.types.CloudMetaData in project cloudrail-si-android-sdk by CloudRail.
the class Files method removeItem.
private void removeItem() {
this.startSpinner();
TextView tv = (TextView) this.selectedItem.findViewById(R.id.list_item);
final String name = (String) tv.getText();
CloudMetaData cloudMetaData = new CloudMetaData();
cloudMetaData.setName(name);
ArrayAdapter<CloudMetaData> adapter = (ArrayAdapter<CloudMetaData>) this.list.getAdapter();
adapter.remove(cloudMetaData);
new Thread(new Runnable() {
@Override
public void run() {
String next = currentPath;
if (!currentPath.equals("/")) {
next += "/";
}
next += name;
getService().delete(next);
updateList();
}
}).start();
}
Aggregations