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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations