use of dev.dworks.apps.anexplorer.network.NetworkConnection in project AnExplorer by 1hakr.
the class NetworkStorageProvider method updateConnections.
public void updateConnections() {
Cursor cursor = null;
mRoots.clear();
try {
cursor = getContext().getContentResolver().query(ExplorerProvider.buildConnection(), null, null, null, null);
while (cursor.moveToNext()) {
int id = getCursorInt(cursor, BaseColumns._ID);
NetworkConnection networkConnection = NetworkConnection.fromConnectionsCursor(cursor);
mRoots.put(networkConnection.getHost(), networkConnection);
}
} catch (Exception e) {
Log.w(TAG, "Failed to load some roots from " + ExplorerProvider.AUTHORITY + ": " + e);
CrashReportingManager.logException(e);
} finally {
IoUtils.closeQuietly(cursor);
}
notifyRootsChanged(getContext());
}
use of dev.dworks.apps.anexplorer.network.NetworkConnection in project AnExplorer by 1hakr.
the class NetworkStorageProvider method deleteDocument.
@Override
public void deleteDocument(String documentId) throws FileNotFoundException {
NetworkFile file = getFileForDocId(documentId);
final NetworkConnection connection = getNetworkConnection(documentId);
try {
connection.getConnectedClient().deleteFile(file.getPath());
} catch (IOException e) {
throw new FileNotFoundException("Failed to delete document with id " + documentId);
}
}
use of dev.dworks.apps.anexplorer.network.NetworkConnection in project AnExplorer by 1hakr.
the class NetworkStorageProvider method openDocument.
@Override
public ParcelFileDescriptor openDocument(final String documentId, final String mode, CancellationSignal signal) throws FileNotFoundException {
final NetworkFile file = getFileForDocId(documentId);
final NetworkConnection connection = getNetworkConnection(documentId);
try {
final boolean isWrite = (mode.indexOf('w') != -1);
if (isWrite) {
return null;
} else {
Uri ftpUri = connection.toUri(file);
URL url = new URL(ftpUri.toString());
URLConnection conn = url.openConnection();
InputStream inputStream = conn.getInputStream();
if (null != inputStream) {
return ParcelFileDescriptorUtil.pipeFrom(inputStream);
}
}
return null;
} catch (Exception e) {
CrashReportingManager.logException(e);
throw new FileNotFoundException("Failed to open document with id " + documentId + " and mode " + mode);
}
}
use of dev.dworks.apps.anexplorer.network.NetworkConnection in project AnExplorer by 1hakr.
the class ConnectionsFragment method onPopupMenuItemClick.
public boolean onPopupMenuItemClick(MenuItem item, int position) {
final Cursor cursor = mAdapter.getItem(position);
int connection_id = getCursorInt(cursor, BaseColumns._ID);
NetworkConnection networkConnection = NetworkConnection.fromConnectionsCursor(cursor);
final int id = item.getItemId();
switch(id) {
case R.id.menu_edit:
editConnection(connection_id);
return true;
case R.id.menu_delete:
if (!networkConnection.type.equals(SERVER)) {
deleteConnection(connection_id);
} else {
((BaseActivity) getActivity()).showSnackBar("Default server connection can't be deleted", Snackbar.LENGTH_SHORT);
}
return true;
default:
return false;
}
}
use of dev.dworks.apps.anexplorer.network.NetworkConnection in project AnExplorer by 1hakr.
the class DocumentsActivity method onCreate.
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onCreate(Bundle icicle) {
setTheme(R.style.Theme_Document);
if (Utils.hasLollipop()) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
} else if (Utils.hasKitKat()) {
setTheme(R.style.Theme_Document_Translucent);
}
setUpStatusBar();
/* StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll()
.penaltyLog()
.build());
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll()
.penaltyLog()
.build());
*/
super.onCreate(icicle);
mRoots = DocumentsApplication.getRootsCache(this);
setResult(Activity.RESULT_CANCELED);
setContentView(R.layout.activity);
final Context context = this;
final Resources res = getResources();
mShowAsDialog = res.getBoolean(R.bool.show_as_dialog);
mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory);
mRateContainer = (FrameLayout) findViewById(R.id.container_rate);
initControls();
if (icicle != null) {
mState = icicle.getParcelable(EXTRA_STATE);
mAuthenticated = icicle.getBoolean(EXTRA_AUTHENTICATED);
mActionMode = icicle.getBoolean(EXTRA_ACTIONMODE);
} else {
buildDefaultState();
}
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mToolbar.setTitleTextAppearance(context, R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);
if (Utils.hasKitKat() && !Utils.hasLollipop()) {
((LinearLayout.LayoutParams) mToolbar.getLayoutParams()).setMargins(0, getStatusBarHeight(this), 0, 0);
mToolbar.setPadding(0, getStatusBarHeight(this), 0, 0);
}
mToolbarStack = (Spinner) findViewById(R.id.stack);
mToolbarStack.setOnItemSelectedListener(mStackListener);
setSupportActionBar(mToolbar);
mRootsContainer = findViewById(R.id.drawer_roots);
mInfoContainer = findViewById(R.id.container_info);
if (!mShowAsDialog) {
// Non-dialog means we have a drawer
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close);
mDrawerLayout.setDrawerListener(mDrawerListener);
// mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START);
lockInfoContainter();
}
changeActionBarColor();
initProtection();
// Hide roots when we're managing a specific root
if (mState.action == ACTION_MANAGE) {
if (mShowAsDialog) {
findViewById(R.id.container_roots).setVisibility(View.GONE);
} else {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
}
}
if (mState.action == ACTION_CREATE) {
final String mimeType = getIntent().getType();
final String title = getIntent().getStringExtra(IntentUtils.EXTRA_TITLE);
SaveFragment.show(getFragmentManager(), mimeType, title);
} else if (mState.action == ACTION_OPEN_TREE) {
PickFragment.show(getFragmentManager());
}
if (mState.action == ACTION_BROWSE) {
final Intent moreApps = new Intent(getIntent());
moreApps.setComponent(null);
moreApps.setPackage(null);
RootsFragment.show(getFragmentManager(), moreApps);
} else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE || mState.action == ACTION_GET_CONTENT || mState.action == ACTION_OPEN_TREE) {
RootsFragment.show(getFragmentManager(), new Intent());
}
if (!mState.restored) {
if (mState.action == ACTION_MANAGE) {
final Uri rootUri = getIntent().getData();
new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor());
} else {
if (isDownloadAuthority(getIntent())) {
onRootPicked(getDownloadRoot(), true);
} else if (ConnectionUtils.isServerAuthority(getIntent())) {
RootInfo root = getIntent().getExtras().getParcelable(EXTRA_ROOT);
onRootPicked(root, true);
} else if (Utils.isQSTile(getIntent())) {
NetworkConnection networkConnection = NetworkConnection.getDefaultServer(this);
RootInfo root = mRoots.getRootInfo(networkConnection);
onRootPicked(root, true);
} else {
try {
new RestoreStackTask().execute();
} catch (SQLiteFullException e) {
CrashReportingManager.logException(e);
}
}
}
} else {
onCurrentDirectoryChanged(ANIM_NONE);
}
if (!PermissionUtil.hasStoragePermission(this)) {
requestStoragePermissions();
}
}
Aggregations