aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/cyanogenmod/explorer/parcelables/NavigationViewInfoParcelable.java
blob: 1e7bd18979f3d2a9f68602af3b7c85334f7e9e50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
 * 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.parcelables;

import android.os.Parcel;
import android.os.Parcelable;

import com.cyanogenmod.explorer.ExplorerApplication;
import com.cyanogenmod.explorer.R;
import com.cyanogenmod.explorer.model.FileSystemObject;
import com.cyanogenmod.explorer.util.FileHelper;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * A serializer/deserializer class for {@link "NavigationView"}.
 */
public class NavigationViewInfoParcelable extends HistoryNavigable {

    private static final long serialVersionUID = -3400094396685969235L;

    private int mId;
    private String mCurrentDir;
    private boolean mChRooted;
    private List<FileSystemObject> mFiles;
    private List<FileSystemObject> mSelectedFiles;

    /**
     * Constructor of <code>NavigationViewInfoParcelable</code>.
     */
    public NavigationViewInfoParcelable() {
        super();
    }

    /**
     * Constructor of <code>NavigationViewInfoParcelable</code>.
     *
     * @param in The parcel information
     */
    public NavigationViewInfoParcelable(Parcel in) {
        readFromParcel(in);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getTitle() {
        if (this.mCurrentDir.compareTo(FileHelper.ROOT_DIRECTORY) == 0) {
            ExplorerApplication.getInstance().getResources().getString(
                    R.string.root_directory_name);
        }
        return new File(this.mCurrentDir).getName();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getDescription() {
        return this.mCurrentDir;
    }

    /**
     * Method that returns the identifier of the view.
     *
     * @return int The identifier of the view
     */
    public int getId() {
        return this.mId;
    }

    /**
     * Method that sets the identifier of the view.
     *
     * @param id The identifier of the view
     */
    public void setId(int id) {
        this.mId = id;
    }

    /**
     * Method that returns the current directory.
     *
     * @return String The current directory
     */
    public String getCurrentDir() {
        return this.mCurrentDir;
    }

    /**
     * Method that sets the current directory.
     *
     * @param currentDir The current directory
     */
    public void setCurrentDir(String currentDir) {
        this.mCurrentDir = currentDir;
    }

    /**
     * Method that returns if the view is in a ChRooted environment.
     *
     * @return boolean If the view is in a ChRooted environment
     */
    public boolean getChRooted() {
        return this.mChRooted;
    }

    /**
     * Method that sets if the view is in a ChRooted environment.
     *
     * @param chRooted If the view is in a ChRooted environment
     */
    public void setChRooted(boolean chRooted) {
        this.mChRooted = chRooted;
    }

    /**
     * Method that returns the current file list.
     *
     * @return List<FileSystemObject> The current file list
     */
    public List<FileSystemObject> getFiles() {
        return this.mFiles;
    }

    /**
     * Method that sets the current file list.
     *
     * @param files The current file list
     */
    public void setFiles(List<FileSystemObject> files) {
        this.mFiles = files;
    }

    /**
     * Method that returns the current selected file list.
     *
     * @return List<FileSystemObject> The current selected file list
     */
    public List<FileSystemObject> getSelectedFiles() {
        return this.mSelectedFiles;
    }

    /**
     * Method that sets the current selected file list.
     *
     * @param selectedFiles The current selected file list
     */
    public void setSelectedFiles(List<FileSystemObject> selectedFiles) {
        this.mSelectedFiles = selectedFiles;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int describeContents() {
        return 0;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        //- 0
        dest.writeInt(this.mId);
        //- 1
        dest.writeInt(this.mCurrentDir == null ? 0 : 1);
        if (this.mCurrentDir != null) {
            dest.writeString(this.mCurrentDir);
        }
        //- 2
        dest.writeInt(this.mChRooted ? 1 : 0);
        //- 3
        dest.writeInt(this.mSelectedFiles == null ? 0 : 1);
        if (this.mSelectedFiles != null) {
            dest.writeList(this.mSelectedFiles);
        }
        //- 4
        dest.writeInt(this.mFiles == null ? 0 : 1);
        if (this.mFiles != null) {
            dest.writeList(this.mFiles);
        }
    }

    /**
     * Fill the object from the parcel information.
     *
     * @param in The parcel information to recreate the object
     */
    private void readFromParcel(Parcel in) {
        //- 0
        this.mId = in.readInt();
        //- 1
        int hasCurrentDir = in.readInt();
        if (hasCurrentDir == 1) {
            this.mCurrentDir = in.readString();
        }
        //- 2
        this.mChRooted = (in.readInt() == 1);
        //- 3
        int hasSelectedFiles = in.readInt();
        if (hasSelectedFiles == 1) {
            List<FileSystemObject> selectedFiles = new ArrayList<FileSystemObject>();
            in.readList(selectedFiles, NavigationViewInfoParcelable.class.getClassLoader());
            this.mSelectedFiles = new ArrayList<FileSystemObject>(selectedFiles);
        }
        //- 4
        int hasFiles = in.readInt();
        if (hasFiles == 1) {
            List<FileSystemObject> files = new ArrayList<FileSystemObject>();
            in.readList(files, NavigationViewInfoParcelable.class.getClassLoader());
            this.mFiles = new ArrayList<FileSystemObject>(files);
        }
    }

    /**
     * The {@link android.os.Parcelable.Creator}.
     *
     * This field is needed for Android to be able to
     * create new objects, individually or as arrays.
     */
    public static final Parcelable.Creator<NavigationViewInfoParcelable> CREATOR =
            new Parcelable.Creator<NavigationViewInfoParcelable>() {
        /**
         * {@inheritDoc}
         */
        @Override
        public NavigationViewInfoParcelable createFromParcel(Parcel in) {
            return new NavigationViewInfoParcelable(in);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public NavigationViewInfoParcelable[] newArray(int size) {
            return new NavigationViewInfoParcelable[size];
        }
    };

}