Search in sources :

Example 6 with MainActivity

use of com.amaze.filemanager.activities.MainActivity in project AmazeFileManager by TeamAmaze.

the class SftpConnectDialog method authenticateAndSaveSetup.

private boolean authenticateAndSaveSetup(String connectionName, String hostname, int port, String hostKeyFingerprint, String username, String password, String selectedParsedKeyPairName, KeyPair selectedParsedKeyPair, boolean isEdit) {
    if (isEdit)
        password = getArguments().getString("password", null);
    final String path = deriveSftpPathFrom(hostname, port, username, password, selectedParsedKeyPair);
    final String encryptedPath = SshClientUtils.encryptSshPathAsNecessary(path);
    if (!isEdit) {
        try {
            AsyncTaskResult<SSHClient> taskResult = new SshAuthenticationTask(hostname, port, hostKeyFingerprint, username, password, selectedParsedKeyPair).execute().get();
            SSHClient result = taskResult.result;
            if (result != null) {
                if (DataUtils.getInstance().containsServer(path) == -1) {
                    DataUtils.getInstance().addServer(new String[] { connectionName, path });
                    ((MainActivity) getActivity()).getDrawer().refreshDrawer();
                    utilsHandler.addSsh(connectionName, encryptedPath, hostKeyFingerprint, selectedParsedKeyPairName, getPemContents());
                    MainFragment ma = ((MainActivity) getActivity()).getCurrentMainFragment();
                    ma.loadlist(path, false, OpenMode.UNKNOWN);
                    dismiss();
                } else {
                    Snackbar.make(getActivity().findViewById(R.id.content_frame), getResources().getString(R.string.connection_exists), Snackbar.LENGTH_SHORT).show();
                    dismiss();
                }
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    } else {
        DataUtils.getInstance().removeServer(DataUtils.getInstance().containsServer(path));
        DataUtils.getInstance().addServer(new String[] { connectionName, path });
        Collections.sort(DataUtils.getInstance().getServers(), new BookSorter());
        ((MainActivity) getActivity()).getDrawer().refreshDrawer();
        AppConfig.runInBackground(() -> {
            utilsHandler.updateSsh(connectionName, getArguments().getString("name"), encryptedPath, selectedParsedKeyPairName, getPemContents());
        });
        dismiss();
        return true;
    }
}
Also used : MainFragment(com.amaze.filemanager.fragments.MainFragment) BookSorter(com.amaze.filemanager.utils.BookSorter) SSHClient(net.schmizz.sshj.SSHClient) SshAuthenticationTask(com.amaze.filemanager.asynchronous.asynctasks.ssh.SshAuthenticationTask) MainActivity(com.amaze.filemanager.activities.MainActivity) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 7 with MainActivity

use of com.amaze.filemanager.activities.MainActivity in project AmazeFileManager by TeamAmaze.

the class MainFragment method onListItemClicked.

/**
 * method called when list item is clicked in the adapter
 *
 * @param isBackButton is it the back button aka '..'
 * @param position the position
 * @param e the list item
 * @param imageView the check {@link RoundedImageView} that is to be animated
 */
public void onListItemClicked(boolean isBackButton, int position, LayoutElementParcelable e, ImageView imageView) {
    if (results) {
        // check to initialize search results
        // if search task is been running, cancel it
        FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
        SearchWorkerFragment fragment = (SearchWorkerFragment) fragmentManager.findFragmentByTag(MainActivity.TAG_ASYNC_HELPER);
        if (fragment != null) {
            if (fragment.mSearchAsyncTask.getStatus() == AsyncTask.Status.RUNNING) {
                fragment.mSearchAsyncTask.cancel(true);
            }
            getActivity().getSupportFragmentManager().beginTransaction().remove(fragment).commit();
        }
        mRetainSearchTask = true;
        results = false;
    } else {
        mRetainSearchTask = false;
        MainActivityHelper.SEARCH_TEXT = null;
    }
    if (selection) {
        if (isBackButton) {
            selection = false;
            if (mActionMode != null)
                mActionMode.finish();
            mActionMode = null;
        } else {
            // the first {goback} item if back navigation is enabled
            adapter.toggleChecked(position, imageView);
        }
    } else {
        if (isBackButton) {
            goBackItemClick();
        } else {
            // hiding search view if visible
            if (getMainActivity().getAppbar().getSearchView().isEnabled()) {
                getMainActivity().getAppbar().getSearchView().hideSearchView();
            }
            String path = !e.hasSymlink() ? e.desc : e.symlink;
            if (e.isDirectory) {
                computeScroll();
                loadlist(path, false, openMode);
            } else if (e.desc.endsWith(CryptUtil.CRYPT_EXTENSION)) {
                // decrypt the file
                isEncryptOpen = true;
                encryptBaseFile = new HybridFileParcelable(getActivity().getExternalCacheDir().getPath() + "/" + e.generateBaseFile().getName().replace(CryptUtil.CRYPT_EXTENSION, ""));
                encryptBaseFiles.add(encryptBaseFile);
                EncryptDecryptUtils.decryptFile(getContext(), getMainActivity(), ma, openMode, e.generateBaseFile(), getActivity().getExternalCacheDir().getPath(), utilsProvider, true);
            } else {
                if (getMainActivity().mReturnIntent) {
                    // are we here to return an intent to another app
                    returnIntentResults(e.generateBaseFile());
                } else {
                    switch(e.getMode()) {
                        case SMB:
                            try {
                                SmbFile smbFile = new SmbFile(e.desc);
                                launchSMB(smbFile, e.longSize, getMainActivity());
                            } catch (MalformedURLException ex) {
                                ex.printStackTrace();
                            }
                            break;
                        case SFTP:
                            Toast.makeText(getContext(), getResources().getString(R.string.please_wait), Toast.LENGTH_LONG).show();
                            SshClientUtils.launchSftp(e.generateBaseFile(), getMainActivity());
                            break;
                        case OTG:
                            FileUtils.openFile(OTGUtil.getDocumentFile(e.desc, getContext(), false), (MainActivity) getActivity(), sharedPref);
                            break;
                        case DROPBOX:
                        case BOX:
                        case GDRIVE:
                        case ONEDRIVE:
                            Toast.makeText(getContext(), getResources().getString(R.string.please_wait), Toast.LENGTH_LONG).show();
                            CloudUtil.launchCloud(e.generateBaseFile(), openMode, getMainActivity());
                            break;
                        default:
                            FileUtils.openFile(new File(e.desc), (MainActivity) getActivity(), sharedPref);
                            break;
                    }
                    dataUtils.addHistoryFile(e.desc);
                }
            }
        }
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) MalformedURLException(java.net.MalformedURLException) MainActivity(com.amaze.filemanager.activities.MainActivity) File(java.io.File) SmbFile(jcifs.smb.SmbFile) HybridFile(com.amaze.filemanager.filesystem.HybridFile) SmbFile(jcifs.smb.SmbFile)

Example 8 with MainActivity

use of com.amaze.filemanager.activities.MainActivity in project AmazeFileManager by TeamAmaze.

the class TabFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.tabfragment, container, false);
    tabHandler = new TabHandler(getContext());
    fragmentManager = getActivity().getSupportFragmentManager();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        indicator = getActivity().findViewById(R.id.indicator);
    } else {
        circleDrawable1 = getActivity().findViewById(R.id.tab_indicator1);
        circleDrawable2 = getActivity().findViewById(R.id.tab_indicator2);
    }
    sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    savepaths = sharedPrefs.getBoolean("savepaths", true);
    mViewPager = rootView.findViewById(R.id.pager);
    if (getArguments() != null) {
        path = getArguments().getString("path");
    }
    mainActivity = ((MainActivity) getActivity());
    mainActivity.supportInvalidateOptionsMenu();
    mViewPager.addOnPageChangeListener(this);
    mSectionsPagerAdapter = new ScreenSlidePagerAdapter(getActivity().getSupportFragmentManager());
    if (savedInstanceState == null) {
        int l = sharedPrefs.getInt(PreferenceUtils.KEY_CURRENT_TAB, PreferenceUtils.DEFAULT_CURRENT_TAB);
        MainActivity.currentTab = l;
        List<Tab> tabs1 = tabHandler.getAllTabs();
        int i = tabs1.size();
        if (i == 0) {
            // creating tabs in db for the first time, probably the first launch of app
            if (mainActivity.getDrawer().getFirstPath() != null) {
                addNewTab(1, mainActivity.getDrawer().getFirstPath());
            } else {
                if (mainActivity.getDrawer().getSecondPath() != null) {
                    addNewTab(1, mainActivity.getDrawer().getSecondPath());
                } else {
                    sharedPrefs.edit().putBoolean(PreferencesConstants.PREFERENCE_ROOTMODE, true).apply();
                    addNewTab(1, "/");
                }
            }
            if (mainActivity.getDrawer().getSecondPath() != null) {
                addNewTab(2, mainActivity.getDrawer().getSecondPath());
            } else {
                addNewTab(2, mainActivity.getDrawer().getFirstPath());
            }
        } else {
            if (path != null && path.length() != 0) {
                if (l == 1) {
                    addTab(tabHandler.findTab(1), "");
                }
                addTab(tabHandler.findTab(l + 1), path);
                if (l == 0) {
                    addTab(tabHandler.findTab(2), "");
                }
            } else {
                addTab(tabHandler.findTab(1), "");
                addTab(tabHandler.findTab(2), "");
            }
        }
        mViewPager.setAdapter(mSectionsPagerAdapter);
        try {
            mViewPager.setCurrentItem(l, true);
            if (circleDrawable1 != null && circleDrawable2 != null) {
                updateIndicator(mViewPager.getCurrentItem());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        fragments.clear();
        try {
            if (fragmentManager == null) {
                fragmentManager = getActivity().getSupportFragmentManager();
            }
            fragments.add(0, fragmentManager.getFragment(savedInstanceState, "tab" + 0));
            fragments.add(1, fragmentManager.getFragment(savedInstanceState, "tab" + 1));
        } catch (Exception e) {
            e.printStackTrace();
        }
        mSectionsPagerAdapter = new ScreenSlidePagerAdapter(getActivity().getSupportFragmentManager());
        mViewPager.setAdapter(mSectionsPagerAdapter);
        int pos1 = savedInstanceState.getInt(KEY_POSITION, 0);
        MainActivity.currentTab = pos1;
        mViewPager.setCurrentItem(pos1);
        mSectionsPagerAdapter.notifyDataSetChanged();
    }
    if (indicator != null)
        indicator.setViewPager(mViewPager);
    // color of viewpager when current tab is 0
    startColor = mainActivity.getColorPreference().getColor(ColorUsage.PRIMARY);
    // color of viewpager when current tab is 1
    endColor = mainActivity.getColorPreference().getColor(ColorUsage.PRIMARY_TWO);
    // update the views as there is any change in {@link MainActivity#currentTab}
    // probably due to config change
    /*colorDrawable.setColor(Color.parseColor(MainActivity.currentTab==1 ?
                ThemedActivity.skinTwo : ThemedActivity.skin));
        mainActivity.updateViews(colorDrawable);*/
    mainActivity.mainFragment = (MainFragment) getCurrentTabFragment();
    return rootView;
}
Also used : Tab(com.amaze.filemanager.database.models.Tab) ViewGroup(android.view.ViewGroup) TabHandler(com.amaze.filemanager.database.TabHandler) MainActivity(com.amaze.filemanager.activities.MainActivity)

Example 9 with MainActivity

use of com.amaze.filemanager.activities.MainActivity in project AmazeFileManager by TeamAmaze.

the class CloudSheetFragment method onClick.

@Override
public void onClick(View v) {
    Log.d(TAG_FRAGMENT, "Clicked: " + v.getId());
    switch(v.getId()) {
        case R.id.linear_layout_smb:
            dismiss();
            SmbSearchDialog smbDialog = new SmbSearchDialog();
            smbDialog.show(getActivity().getFragmentManager(), "tab");
            return;
        case R.id.linear_layout_scp:
            dismiss();
            SftpConnectDialog sftpConnectDialog = new SftpConnectDialog();
            Bundle args = new Bundle();
            args.putBoolean("edit", false);
            sftpConnectDialog.setArguments(args);
            sftpConnectDialog.show(getActivity().getFragmentManager(), "tab");
            return;
        case R.id.linear_layout_box:
            ((MainActivity) getActivity()).addConnection(OpenMode.BOX);
            break;
        case R.id.linear_layout_dropbox:
            ((MainActivity) getActivity()).addConnection(OpenMode.DROPBOX);
            break;
        case R.id.linear_layout_google_drive:
            ((MainActivity) getActivity()).addConnection(OpenMode.GDRIVE);
            break;
        case R.id.linear_layout_onedrive:
            ((MainActivity) getActivity()).addConnection(OpenMode.ONEDRIVE);
            break;
        case R.id.linear_layout_get_cloud:
            Intent cloudPluginIntent = new Intent(Intent.ACTION_VIEW);
            cloudPluginIntent.setData(Uri.parse("market://details?id=com.filemanager.amazecloud"));
            startActivity(cloudPluginIntent);
            break;
    }
    // dismiss this sheet dialog
    dismiss();
}
Also used : SftpConnectDialog(com.amaze.filemanager.ui.dialogs.SftpConnectDialog) Bundle(android.os.Bundle) Intent(android.content.Intent) MainActivity(com.amaze.filemanager.activities.MainActivity) SmbSearchDialog(com.amaze.filemanager.ui.dialogs.SmbSearchDialog)

Example 10 with MainActivity

use of com.amaze.filemanager.activities.MainActivity in project AmazeFileManager by TeamAmaze.

the class SmbSearchDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity());
    builder.title(R.string.searchingdevices);
    builder.negativeColor(accentColor);
    builder.negativeText(R.string.cancel);
    builder.onNegative((dialog, which) -> {
        if (subnetScanner != null)
            subnetScanner.interrupt();
        dismiss();
    });
    builder.onPositive((dialog, which) -> {
        if (subnetScanner != null)
            subnetScanner.interrupt();
        if (getActivity() != null && getActivity() instanceof MainActivity) {
            dismiss();
            MainActivity mainActivity = (MainActivity) getActivity();
            mainActivity.showSMBDialog("", "", false);
        }
    });
    builder.positiveText(R.string.use_custom_ip);
    builder.positiveColor(accentColor);
    computers.add(new ComputerParcelable("-1", "-1"));
    listViewAdapter = new ListViewAdapter(getActivity(), computers);
    subnetScanner = new SubnetScanner(getActivity());
    subnetScanner.setObserver(new SubnetScanner.ScanObserver() {

        @Override
        public void computerFound(final ComputerParcelable computer) {
            if (getActivity() != null)
                getActivity().runOnUiThread(() -> {
                    if (!computers.contains(computer))
                        computers.add(computer);
                    listViewAdapter.notifyDataSetChanged();
                });
        }

        @Override
        public void searchFinished() {
            if (getActivity() != null) {
                getActivity().runOnUiThread(() -> {
                    if (computers.size() == 1) {
                        dismiss();
                        Toast.makeText(getActivity(), getResources().getString(R.string.nodevicefound), Toast.LENGTH_SHORT).show();
                        MainActivity mainActivity = (MainActivity) getActivity();
                        mainActivity.showSMBDialog("", "", false);
                        return;
                    }
                    computers.remove(computers.size() - 1);
                    listViewAdapter.notifyDataSetChanged();
                });
            }
        }
    });
    subnetScanner.start();
    builder.adapter(listViewAdapter, null);
    return builder.build();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) MainActivity(com.amaze.filemanager.activities.MainActivity) ComputerParcelable(com.amaze.filemanager.utils.ComputerParcelable) SubnetScanner(com.amaze.filemanager.utils.SubnetScanner)

Aggregations

MainActivity (com.amaze.filemanager.activities.MainActivity)10 Intent (android.content.Intent)4 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)4 MainFragment (com.amaze.filemanager.fragments.MainFragment)4 IOException (java.io.IOException)4 Context (android.content.Context)3 Uri (android.net.Uri)3 Editable (android.text.Editable)3 View (android.view.View)3 Button (android.widget.Button)3 EditText (android.widget.EditText)3 HybridFile (com.amaze.filemanager.filesystem.HybridFile)3 HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)3 File (java.io.File)3 SharedPreferences (android.content.SharedPreferences)2 Color (android.graphics.Color)2 Typeface (android.graphics.Typeface)2 FingerprintManager (android.hardware.fingerprint.FingerprintManager)2 AsyncTask (android.os.AsyncTask)2 Build (android.os.Build)2