Search in sources :

Example 6 with NetworkConnection

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());
}
Also used : NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) Cursor(android.database.Cursor) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 7 with NetworkConnection

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);
    }
}
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 8 with NetworkConnection

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);
    }
}
Also used : InputStream(java.io.InputStream) NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection) FileNotFoundException(java.io.FileNotFoundException) NetworkFile(dev.dworks.apps.anexplorer.network.NetworkFile) Uri(android.net.Uri) URL(java.net.URL) URLConnection(java.net.URLConnection) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 9 with NetworkConnection

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;
    }
}
Also used : NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection) BaseActivity(dev.dworks.apps.anexplorer.BaseActivity) Cursor(android.database.Cursor)

Example 10 with NetworkConnection

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();
    }
}
Also used : Context(android.content.Context) LayoutParams(android.view.ViewGroup.LayoutParams) RootInfo(dev.dworks.apps.anexplorer.model.RootInfo) SQLiteFullException(android.database.sqlite.SQLiteFullException) NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) Intent(android.content.Intent) Resources(android.content.res.Resources) Uri(android.net.Uri) TargetApi(android.annotation.TargetApi)

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