Search in sources :

Example 1 with NetworkConnection

use of dev.dworks.apps.anexplorer.network.NetworkConnection in project AnExplorer by 1hakr.

the class CreateConnectionFragment method getNetworkConnection.

private NetworkConnection getNetworkConnection() {
    NetworkConnection networkConnection = new NetworkConnection();
    networkConnection.name = name.getText().toString();
    networkConnection.host = host.getText().toString();
    String portNumber = port.getText().toString();
    if (!TextUtils.isEmpty(portNumber)) {
        networkConnection.port = Integer.parseInt(portNumber);
    }
    networkConnection.username = username.getText().toString();
    networkConnection.password = password.getText().toString();
    networkConnection.scheme = scheme.getSelectedItem().toString().toLowerCase();
    networkConnection.type = CLIENT;
    networkConnection.setAnonymous(anonymous.isChecked());
    networkConnection.build();
    return networkConnection;
}
Also used : NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection)

Example 2 with NetworkConnection

use of dev.dworks.apps.anexplorer.network.NetworkConnection in project AnExplorer by 1hakr.

the class NetworkStorageProvider method queryChildDocuments.

@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final NetworkFile parent = getFileForDocId(parentDocumentId);
    final NetworkConnection connection = getNetworkConnection(parentDocumentId);
    try {
        connection.getConnectedClient().changeWorkingDirectory(parent.getPath());
        for (FTPFile file : connection.getConnectedClient().listFiles()) {
            includeFile(result, null, new NetworkFile(parent, file));
        }
    } catch (IOException e) {
        CrashReportingManager.logException(e);
    }
    return result;
}
Also used : NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection) FTPFile(org.apache.commons.net.ftp.FTPFile) IOException(java.io.IOException) NetworkFile(dev.dworks.apps.anexplorer.network.NetworkFile) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 3 with NetworkConnection

use of dev.dworks.apps.anexplorer.network.NetworkConnection in project AnExplorer by 1hakr.

the class NetworkStorageProvider method getFileForDocId.

/**
 * Translate your custom URI scheme into a File object.
 *
 * @param docId the document ID representing the desired file
 * @return a File represented by the given document ID
 * @throws java.io.FileNotFoundException
 */
private NetworkFile getFileForDocId(String docId) throws FileNotFoundException {
    final int splitIndex = docId.indexOf(':', 1);
    final String tag = docId.substring(0, splitIndex);
    final String path = docId.substring(splitIndex + 1);
    NetworkConnection root;
    synchronized (mRootsLock) {
        root = mRoots.get(tag);
    }
    if (root == null) {
        throw new FileNotFoundException("No root for " + tag);
    }
    NetworkFile target = root.file;
    if (target == null) {
        return null;
    }
    target = new NetworkFile(target.getAbsolutePath() + path, tag);
    return target;
}
Also used : NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection) FileNotFoundException(java.io.FileNotFoundException) NetworkFile(dev.dworks.apps.anexplorer.network.NetworkFile)

Example 4 with NetworkConnection

use of dev.dworks.apps.anexplorer.network.NetworkConnection in project AnExplorer by 1hakr.

the class NetworkStorageProvider method createDocument.

@Override
public String createDocument(String documentId, String mimeType, String displayName) throws FileNotFoundException {
    NetworkFile parent = getFileForDocId(documentId);
    NetworkFile file = new NetworkFile(parent.getPath() + displayName, "");
    final NetworkConnection connection = getNetworkConnection(documentId);
    try {
        connection.getConnectedClient().createDirectories(file.getPath());
    } catch (IOException e) {
        throw new FileNotFoundException("Failed to create document with name " + displayName + " and documentId " + documentId);
    }
    return getDocIdForFile(file);
}
Also used : NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) NetworkFile(dev.dworks.apps.anexplorer.network.NetworkFile)

Example 5 with NetworkConnection

use of dev.dworks.apps.anexplorer.network.NetworkConnection in project AnExplorer by 1hakr.

the class NetworkStorageProvider method queryRoots.

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
    synchronized (mRootsLock) {
        for (Map.Entry<String, NetworkConnection> root : mRoots.entrySet()) {
            NetworkConnection networkConnection = root.getValue();
            String documentId = getDocIdForFile(networkConnection.file);
            int flags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPPORTS_IS_CHILD;
            boolean isServer = networkConnection.getType().compareToIgnoreCase(SERVER) == 0;
            if (isServer) {
                if (!Utils.hasWiFi(getContext())) {
                    continue;
                }
                flags |= Root.FLAG_CONNECTION_SERVER;
            }
            final RowBuilder row = result.newRow();
            // These columns are required
            row.add(Root.COLUMN_ROOT_ID, root.getKey());
            row.add(Root.COLUMN_DOCUMENT_ID, documentId);
            row.add(Root.COLUMN_TITLE, networkConnection.name);
            row.add(Root.COLUMN_FLAGS, flags);
            // These columns are optional
            row.add(Root.COLUMN_SUMMARY, isServer ? networkConnection.getPath() : networkConnection.getSummary());
            row.add(Root.COLUMN_PATH, networkConnection.getPath());
        }
    }
    return result;
}
Also used : NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection) RowBuilder(dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Aggregations

NetworkConnection (dev.dworks.apps.anexplorer.network.NetworkConnection)13 NetworkFile (dev.dworks.apps.anexplorer.network.NetworkFile)5 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 Context (android.content.Context)3 Cursor (android.database.Cursor)3 MatrixCursor (dev.dworks.apps.anexplorer.cursor.MatrixCursor)3 Uri (android.net.Uri)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 BaseActivity (dev.dworks.apps.anexplorer.BaseActivity)2 TargetApi (android.annotation.TargetApi)1 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 SQLiteFullException (android.database.sqlite.SQLiteFullException)1 ArrayMap (android.support.v4.util.ArrayMap)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 AlertDialog (android.support.v7.app.AlertDialog)1