Search in sources :

Example 31 with HybridFileParcelable

use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.

the class CompressedExplorerFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    compressedFile = new File(Uri.parse(getArguments().getString(KEY_PATH)).getPath());
    mToolbarContainer = mainActivity.getAppbar().getAppbarLayout();
    mToolbarContainer.setOnTouchListener((view, motionEvent) -> {
        if (stopAnims) {
            if ((!compressedExplorerAdapter.stoppedAnimation)) {
                stopAnim();
            }
            compressedExplorerAdapter.stoppedAnimation = true;
        }
        stopAnims = false;
        return false;
    });
    listView.setVisibility(View.VISIBLE);
    mLayoutManager = new LinearLayoutManager(getActivity());
    listView.setLayoutManager(mLayoutManager);
    if (utilsProvider.getAppTheme().equals(AppTheme.DARK)) {
        rootView.setBackgroundColor(Utils.getColor(getContext(), R.color.holo_dark_background));
    } else if (utilsProvider.getAppTheme().equals(AppTheme.BLACK)) {
        listView.setBackgroundColor(Utils.getColor(getContext(), android.R.color.black));
    } else {
        listView.setBackgroundColor(Utils.getColor(getContext(), android.R.color.background_light));
    }
    gobackitem = sp.getBoolean(PreferencesConstants.PREFERENCE_SHOW_GOBACK_BUTTON, false);
    coloriseIcons = sp.getBoolean(PreferencesConstants.PREFERENCE_COLORIZE_ICONS, true);
    showSize = sp.getBoolean(PreferencesConstants.PREFERENCE_SHOW_FILE_SIZE, false);
    showLastModified = sp.getBoolean(PreferencesConstants.PREFERENCE_SHOW_LAST_MODIFIED, true);
    showDividers = sp.getBoolean(PreferencesConstants.PREFERENCE_SHOW_DIVIDERS, true);
    year = ("" + Calendar.getInstance().get(Calendar.YEAR)).substring(2, 4);
    skin = mainActivity.getColorPreference().getColorAsString(ColorUsage.PRIMARY);
    accentColor = mainActivity.getColorPreference().getColorAsString(ColorUsage.ACCENT);
    iconskin = mainActivity.getColorPreference().getColorAsString(ColorUsage.ICON_SKIN);
    if (savedInstanceState == null && compressedFile != null) {
        files = new ArrayList<>();
        // adding a cache file to delete where any user interaction elements will be cached
        String fileName = compressedFile.getName().substring(0, compressedFile.getName().lastIndexOf("."));
        String path = getActivity().getExternalCacheDir().getPath() + SEPARATOR + fileName;
        files.add(new HybridFileParcelable(path));
        decompressor = CompressedHelper.getCompressorInstance(getContext(), compressedFile);
        changePath("");
    } else {
        onRestoreInstanceState(savedInstanceState);
    }
    mainActivity.supportInvalidateOptionsMenu();
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) SharedPreferences(android.content.SharedPreferences) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) File(java.io.File)

Example 32 with HybridFileParcelable

use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.

the class FileUtils method otgFolderSize.

/**
 * Helper method to get size of an otg folder
 */
public static long otgFolderSize(String path, final Context context) {
    final AtomicLong totalBytes = new AtomicLong(0);
    OTGUtil.getDocumentFiles(path, context, new OnFileFound() {

        @Override
        public void onFileFound(HybridFileParcelable file) {
            totalBytes.addAndGet(getBaseFileSize(file, context));
        }
    });
    return totalBytes.longValue();
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) AtomicLong(java.util.concurrent.atomic.AtomicLong) OnFileFound(com.amaze.filemanager.utils.OnFileFound)

Example 33 with HybridFileParcelable

use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.

the class FileUtils method parseName.

/**
 * We're parsing a line returned from a stdout of shell.
 * @param line must be the line returned from a 'ls' command
 */
public static HybridFileParcelable parseName(String line) {
    boolean linked = false;
    StringBuilder name = new StringBuilder();
    StringBuilder link = new StringBuilder();
    String size = "-1";
    String date = "";
    String[] array = line.split(" ");
    if (array.length < 6)
        return null;
    for (String anArray : array) {
        if (anArray.contains("->") && array[0].startsWith("l")) {
            linked = true;
        }
    }
    int p = getColonPosition(array);
    if (p != -1) {
        date = array[p - 1] + " | " + array[p];
        size = array[p - 2];
    }
    if (!linked) {
        for (int i = p + 1; i < array.length; i++) {
            name.append(" ").append(array[i]);
        }
        name = new StringBuilder(name.toString().trim());
    } else {
        int q = getLinkPosition(array);
        for (int i = p + 1; i < q; i++) {
            name.append(" ").append(array[i]);
        }
        name = new StringBuilder(name.toString().trim());
        for (int i = q + 1; i < array.length; i++) {
            link.append(" ").append(array[i]);
        }
    }
    long Size = (size == null || size.trim().length() == 0) ? -1 : Long.parseLong(size);
    if (date.trim().length() > 0) {
        ParsePosition pos = new ParsePosition(0);
        SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd | HH:mm");
        Date stringDate = simpledateformat.parse(date, pos);
        HybridFileParcelable baseFile = new HybridFileParcelable(name.toString(), array[0], stringDate.getTime(), Size, true);
        baseFile.setLink(link.toString());
        return baseFile;
    } else {
        HybridFileParcelable baseFile = new HybridFileParcelable(name.toString(), array[0], new File("/").lastModified(), Size, true);
        baseFile.setLink(link.toString());
        return baseFile;
    }
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) SimpleDateFormat(java.text.SimpleDateFormat) DocumentFile(android.support.v4.provider.DocumentFile) HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File) SmbFile(jcifs.smb.SmbFile) Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Example 34 with HybridFileParcelable

use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.

the class CloudUtil method listFiles.

/**
 * @deprecated use getCloudFiles()
 */
public static ArrayList<HybridFileParcelable> listFiles(String path, CloudStorage cloudStorage, OpenMode openMode) throws CloudPluginException {
    final ArrayList<HybridFileParcelable> baseFiles = new ArrayList<>();
    getCloudFiles(path, cloudStorage, openMode, new OnFileFound() {

        @Override
        public void onFileFound(HybridFileParcelable file) {
            baseFiles.add(file);
        }
    });
    return baseFiles;
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) ArrayList(java.util.ArrayList) OnFileFound(com.amaze.filemanager.utils.OnFileFound)

Example 35 with HybridFileParcelable

use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.

the class MainActivityHelper method showFailedOperationDialog.

public void showFailedOperationDialog(ArrayList<HybridFileParcelable> failedOps, Context contextc) {
    MaterialDialog.Builder mat = new MaterialDialog.Builder(contextc);
    mat.title(contextc.getString(R.string.operationunsuccesful));
    mat.theme(mainActivity.getAppTheme().getMaterialDialogTheme());
    mat.positiveColor(accentColor);
    mat.positiveText(R.string.cancel);
    String content = contextc.getResources().getString(R.string.operation_fail_following);
    int k = 1;
    for (HybridFileParcelable s : failedOps) {
        content = content + "\n" + (k) + ". " + s.getName();
        k++;
    }
    mat.content(content);
    mat.build().show();
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog)

Aggregations

HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)35 File (java.io.File)19 ArrayList (java.util.ArrayList)16 HybridFile (com.amaze.filemanager.filesystem.HybridFile)15 LayoutElementParcelable (com.amaze.filemanager.adapters.data.LayoutElementParcelable)11 SmbFile (jcifs.smb.SmbFile)11 Intent (android.content.Intent)8 Cursor (android.database.Cursor)7 ShellNotRunningException (com.amaze.filemanager.exceptions.ShellNotRunningException)7 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)6 SharedPreferences (android.content.SharedPreferences)5 DataUtils (com.amaze.filemanager.utils.DataUtils)5 Context (android.content.Context)4 AppsListFragment (com.amaze.filemanager.fragments.AppsListFragment)4 MainFragment (com.amaze.filemanager.fragments.MainFragment)4 OnFileFound (com.amaze.filemanager.utils.OnFileFound)4 Uri (android.net.Uri)3 AsyncTask (android.os.AsyncTask)3 Build (android.os.Build)3 TextUtils (android.text.TextUtils)3