Search in sources :

Example 1 with CloudMetaData

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;
}
Also used : LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) CloudMetaData(com.cloudrail.si.types.CloudMetaData)

Example 2 with CloudMetaData

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;
}
Also used : MenuInflater(android.view.MenuInflater) InputStream(java.io.InputStream) Intent(android.content.Intent) MenuItem(android.view.MenuItem) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) IOException(java.io.IOException) CloudMetaData(com.cloudrail.si.types.CloudMetaData) SpaceAllocation(com.cloudrail.si.types.SpaceAllocation) FileOutputStream(java.io.FileOutputStream) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) File(java.io.File) LinearLayout(android.widget.LinearLayout) PopupMenu(android.widget.PopupMenu)

Example 3 with CloudMetaData

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;
}
Also used : ArrayList(java.util.ArrayList) CloudMetaData(com.cloudrail.si.types.CloudMetaData)

Example 4 with CloudMetaData

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;
}
Also used : CloudMetaData(com.cloudrail.si.types.CloudMetaData)

Example 5 with CloudMetaData

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();
}
Also used : TextView(android.widget.TextView) ArrayAdapter(android.widget.ArrayAdapter) CloudMetaData(com.cloudrail.si.types.CloudMetaData)

Aggregations

CloudMetaData (com.cloudrail.si.types.CloudMetaData)5 TextView (android.widget.TextView)3 View (android.view.View)2 Intent (android.content.Intent)1 LayoutInflater (android.view.LayoutInflater)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 PopupMenu (android.widget.PopupMenu)1 SpaceAllocation (com.cloudrail.si.types.SpaceAllocation)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1