Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f4fbedb6 authored by jruesga's avatar jruesga
Browse files

Reorganize ActionsPolicy to make it clearly

parent 54e70eae
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -68,7 +68,8 @@ import com.cyanogenmod.explorer.providers.RecentSearchesContentProvider;
import com.cyanogenmod.explorer.tasks.SearchResultDrawingAsyncTask;
import com.cyanogenmod.explorer.ui.dialogs.ActionsDialog;
import com.cyanogenmod.explorer.ui.dialogs.MessageProgressDialog;
import com.cyanogenmod.explorer.ui.policy.ActionsPolicy;
import com.cyanogenmod.explorer.ui.policy.InfoActionPolicy;
import com.cyanogenmod.explorer.ui.policy.IntentsActionPolicy;
import com.cyanogenmod.explorer.ui.widgets.ButtonItem;
import com.cyanogenmod.explorer.util.CommandHelper;
import com.cyanogenmod.explorer.util.DialogHelper;
@@ -822,19 +823,19 @@ public class SearchActivity extends Activity
        // Show content description
        if (this.mDefaultLongClickAction.compareTo(
                DefaultLongClickAction.SHOW_CONTENT_DESCRIPTION) == 0) {
            ActionsPolicy.showContentDescription(this, fso);
            InfoActionPolicy.showContentDescription(this, fso);
        }

        // Open with
        else if (this.mDefaultLongClickAction.compareTo(
                DefaultLongClickAction.OPEN_WITH) == 0) {
            ActionsPolicy.openFileSystemObject(this, fso, true);
            IntentsActionPolicy.openFileSystemObject(this, fso, true);
        }

        // Show properties
        else if (this.mDefaultLongClickAction.compareTo(
                DefaultLongClickAction.SHOW_PROPERTIES) == 0) {
            ActionsPolicy.showPropertiesDialog(this, fso, this);
            InfoActionPolicy.showPropertiesDialog(this, fso, this);
        }

        // Show actions
@@ -966,7 +967,7 @@ public class SearchActivity extends Activity
                    } else {
                        // Open the file here, so when focus back to the app, the search activity
                        // its in top of the stack
                        ActionsPolicy.openFileSystemObject(this, fso, false);
                        IntentsActionPolicy.openFileSystemObject(this, fso, false);
                        return;
                    }
                } else {
+45 −21
Original line number Diff line number Diff line
@@ -37,8 +37,16 @@ import com.cyanogenmod.explorer.adapters.TwoColumnsMenuListAdapter;
import com.cyanogenmod.explorer.listeners.OnRequestRefreshListener;
import com.cyanogenmod.explorer.listeners.OnSelectionListener;
import com.cyanogenmod.explorer.model.FileSystemObject;
import com.cyanogenmod.explorer.ui.policy.ActionsPolicy;
import com.cyanogenmod.explorer.ui.policy.ActionsPolicy.LinkedResource;
import com.cyanogenmod.explorer.model.SystemFile;
import com.cyanogenmod.explorer.ui.policy.BookmarksActionPolicy;
import com.cyanogenmod.explorer.ui.policy.CompressActionPolicy;
import com.cyanogenmod.explorer.ui.policy.CopyMoveActionPolicy;
import com.cyanogenmod.explorer.ui.policy.CopyMoveActionPolicy.LinkedResource;
import com.cyanogenmod.explorer.ui.policy.DeleteActionPolicy;
import com.cyanogenmod.explorer.ui.policy.ExecutionActionPolicy;
import com.cyanogenmod.explorer.ui.policy.InfoActionPolicy;
import com.cyanogenmod.explorer.ui.policy.IntentsActionPolicy;
import com.cyanogenmod.explorer.ui.policy.NewActionPolicy;
import com.cyanogenmod.explorer.util.DialogHelper;
import com.cyanogenmod.explorer.util.FileHelper;
import com.cyanogenmod.explorer.util.MimeTypeHelper;
@@ -116,7 +124,8 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
        //Create the list view
        this.mListView = new ListView(context);
        LinearLayout.LayoutParams params =
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
                new LinearLayout.LayoutParams(
                        LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        this.mListView.setLayoutParams(params);
        this.mListView.setAdapter(adapter);

@@ -209,7 +218,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen

            //- Delete
            case R.id.mnu_actions_delete:
                ActionsPolicy.removeFileSystemObject(
                DeleteActionPolicy.removeFileSystemObject(
                        this.mContext,
                        this.mFso,
                        this.mOnSelectionListener,
@@ -243,21 +252,21 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen

            //- Open
            case R.id.mnu_actions_open:
                ActionsPolicy.openFileSystemObject(this.mContext, this.mFso, false);
                IntentsActionPolicy.openFileSystemObject(this.mContext, this.mFso, false);
                break;
            //- Open with
            case R.id.mnu_actions_open_with:
                ActionsPolicy.openFileSystemObject(this.mContext, this.mFso, true);
                IntentsActionPolicy.openFileSystemObject(this.mContext, this.mFso, true);
                break;

            //- Execute
            case R.id.mnu_actions_execute:
                ActionsPolicy.execute(this.mContext, this.mFso);
                ExecutionActionPolicy.execute(this.mContext, this.mFso);
                break;

            //- Send
            case R.id.mnu_actions_send:
                ActionsPolicy.sendFileSystemObject(this.mContext, this.mFso);
                IntentsActionPolicy.sendFileSystemObject(this.mContext, this.mFso);
                break;


@@ -266,7 +275,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
                if (this.mOnSelectionListener != null) {
                    List<FileSystemObject> selection =
                            this.mOnSelectionListener.onRequestSelectedFiles();
                    ActionsPolicy.copyFileSystemObjects(
                    CopyMoveActionPolicy.copyFileSystemObjects(
                            this.mContext,
                            createLinkedResource(selection, this.mFso),
                            this.mOnSelectionListener,
@@ -278,7 +287,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
                if (this.mOnSelectionListener != null) {
                    List<FileSystemObject> selection =
                            this.mOnSelectionListener.onRequestSelectedFiles();
                    ActionsPolicy.moveFileSystemObjects(
                    CopyMoveActionPolicy.moveFileSystemObjects(
                            this.mContext,
                            createLinkedResource(selection, this.mFso),
                            this.mOnSelectionListener,
@@ -290,7 +299,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
                if (this.mOnSelectionListener != null) {
                    List<FileSystemObject> selection =
                            this.mOnSelectionListener.onRequestSelectedFiles();
                    ActionsPolicy.removeFileSystemObjects(
                    DeleteActionPolicy.removeFileSystemObjects(
                            this.mContext,
                            selection,
                            this.mOnSelectionListener,
@@ -300,7 +309,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen

            //- Uncompress
            case R.id.mnu_actions_extract:
                ActionsPolicy.uncompress(
                CompressActionPolicy.uncompress(
                            this.mContext,
                            this.mFso,
                            this.mOnRequestRefreshListener);
@@ -310,7 +319,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
            case R.id.mnu_actions_create_copy:
                // Create a copy of the fso
                if (this.mOnSelectionListener != null) {
                    ActionsPolicy.createCopyFileSystemObject(
                    CopyMoveActionPolicy.createCopyFileSystemObject(
                                this.mContext,
                                this.mFso,
                                this.mOnSelectionListener,
@@ -321,13 +330,13 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
            //- Add to bookmarks
            case R.id.mnu_actions_add_to_bookmarks:
            case R.id.mnu_actions_add_to_bookmarks_current_folder:
                ActionsPolicy.addToBookmarks(this.mContext, this.mFso);
                BookmarksActionPolicy.addToBookmarks(this.mContext, this.mFso);
                break;

            //- Properties
            case R.id.mnu_actions_properties:
            case R.id.mnu_actions_properties_current_folder:
                ActionsPolicy.showPropertiesDialog(
                InfoActionPolicy.showPropertiesDialog(
                        this.mContext, this.mFso, this.mOnRequestRefreshListener);
                break;

@@ -414,7 +423,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
                        case R.id.mnu_actions_rename:
                            // Rename the fso
                            if (ActionsDialog.this.mOnSelectionListener != null) {
                                ActionsPolicy.renameFileSystemObject(
                                CopyMoveActionPolicy.renameFileSystemObject(
                                        ActionsDialog.this.mContext,
                                        inputNameDialog.mFso,
                                        name,
@@ -427,7 +436,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
                        case R.id.mnu_actions_create_link_global:
                            // Create a link to the fso
                            if (ActionsDialog.this.mOnSelectionListener != null) {
                                ActionsPolicy.createSymlink(
                                NewActionPolicy.createSymlink(
                                        ActionsDialog.this.mContext,
                                        inputNameDialog.mFso,
                                        name,
@@ -471,12 +480,12 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
    void createNewFileSystemObject(final int menuId, final String name) {
        switch (menuId) {
            case R.id.mnu_actions_new_directory:
                ActionsPolicy.createNewDirectory(
                NewActionPolicy.createNewDirectory(
                        this.mContext, name,
                        this.mOnSelectionListener, this.mOnRequestRefreshListener);
                break;
            case R.id.mnu_actions_new_file:
                ActionsPolicy.createNewFile(
                NewActionPolicy.createNewFile(
                        this.mContext, name,
                        this.mOnSelectionListener, this.mOnRequestRefreshListener);
                break;
@@ -560,7 +569,22 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen

        // Compress/Uncompress (only when selection is available)
        if (this.mOnSelectionListener != null) {
            //Uncompress
            //Compress
            if (this.mGlobal) {
                List<FileSystemObject> selection = null;
                if (this.mOnSelectionListener != null) {
                    selection = this.mOnSelectionListener.onRequestSelectedFiles();
                }
                if (selection == null || selection.size() == 0) {
                    menu.removeItem(R.id.mnu_actions_compress_selection);
                }
            } else {
                // Ignore for system files
                if (this.mFso instanceof SystemFile) {
                    menu.removeItem(R.id.mnu_actions_compress);
                }
            }
            //Uncompress (Only supported files)
            if (!this.mGlobal && !FileHelper.isSupportedUncompressedFile(this.mFso)) {
                menu.removeItem(R.id.mnu_actions_extract);
            }
@@ -578,7 +602,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
    private static List<LinkedResource> createLinkedResource(
            List<FileSystemObject> items, FileSystemObject directory) {
        List<LinkedResource> resources =
                new ArrayList<ActionsPolicy.LinkedResource>(items.size());
                new ArrayList<LinkedResource>(items.size());
        for (int i = 0; i < items.size(); i++) {
            FileSystemObject fso = items.get(i);
            File src = new File(fso.getFullPath());
+2 −2
Original line number Diff line number Diff line
@@ -379,12 +379,12 @@ public class FsoPropertiesDialog
        try {
            if (this.mFso instanceof Symlink && ((Symlink) this.mFso).getLinkRef() != null) {
                this.mFolderUsageExecutable =
                    (FolderUsageExecutable)CommandHelper.getFolderUsage(
                    CommandHelper.getFolderUsage(
                            this.mContext,
                            ((Symlink) this.mFso).getLinkRef().getFullPath(), this, null);
            } else {
                this.mFolderUsageExecutable =
                    (FolderUsageExecutable)CommandHelper.getFolderUsage(
                    CommandHelper.getFolderUsage(
                        this.mContext, this.mFso.getFullPath(), this, null);
            }
        } catch (Exception cause) {
+4 −1555

File changed.

Preview size limit exceeded, changes collapsed.

+65 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cyanogenmod.explorer.ui.policy;

import android.content.Context;
import android.widget.Toast;

import com.cyanogenmod.explorer.R;
import com.cyanogenmod.explorer.model.Bookmark;
import com.cyanogenmod.explorer.model.Bookmark.BOOKMARK_TYPE;
import com.cyanogenmod.explorer.model.FileSystemObject;
import com.cyanogenmod.explorer.preferences.Bookmarks;
import com.cyanogenmod.explorer.util.ExceptionUtil;

/**
 * A class with the convenience methods for resolve bookmarks related actions
 */
public final class BookmarksActionPolicy extends ActionsPolicy {

    /**
     * Method that adds the {@link FileSystemObject} to the bookmarks database.
     *
     * @param ctx The current context
     * @param fso The file system object
     */
    public static void addToBookmarks(final Context ctx, final FileSystemObject fso) {
        try {
            // Create the bookmark
            Bookmark bookmark =
                    new Bookmark(BOOKMARK_TYPE.USER_DEFINED, fso.getName(), fso.getFullPath());
            bookmark = Bookmarks.addBookmark(ctx, bookmark);
            if (bookmark == null) {
                // The operation fails
                Toast.makeText(
                        ctx,
                        R.string.msgs_operation_failure,
                        Toast.LENGTH_SHORT).show();
            } else {
                // Success
                Toast.makeText(
                        ctx,
                        R.string.bookmarks_msgs_add_success,
                        Toast.LENGTH_SHORT).show();
            }

        } catch (Exception e) {
            ExceptionUtil.translateException(ctx, e);
        }
    }

}
 No newline at end of file
Loading