57
57
public class FileBrowser extends AppCompatActivity implements OnFileChangedListener ,IContextSwitcher {
58
58
59
59
private Context mContext ;
60
- private Toolbar toolbar ;
61
60
62
61
private CustomAdapter mAdapter ;
63
62
private FastScrollRecyclerView .LayoutManager mLayoutManager ;
64
63
private FastScrollRecyclerView mFilesListView ;
65
64
66
65
private BottomBar mBottomView ;
67
- private BottomBar mPathChange ;
66
+ private BottomBar mTopStorageView ;
68
67
private TabChangeListener mTabChangeListener ;
69
68
70
69
private TextView mCurrentPath ;
@@ -79,34 +78,32 @@ public class FileBrowser extends AppCompatActivity implements OnFileChangedListe
79
78
private SearchView mSearchView ;
80
79
private MenuItem mSearchMenuItem ;
81
80
private SearchViewListener mSearchViewListener ;
82
- private Handler mUIUpdateHandler ;
83
81
private List <FileItem > mFileList = new ArrayList <>();
84
82
85
- private String mInitialDirectory ;
86
- private String mFilterFilesWithExtension ;
87
-
88
83
@ Override
89
84
protected void onCreate (Bundle savedInstanceState ) {
90
85
super .onCreate (savedInstanceState );
91
86
92
87
mContext = this ;
88
+
89
+ // Get File Storage Permission
93
90
Intent in = new Intent (this , Permissions .class );
94
- Bundle b =new Bundle ();
95
- b .putStringArray (Constants .APP_PREMISSION_KEY , Constants .APP_PREMISSIONS );
96
- in .putExtras (b );
97
- startActivityForResult (in ,APP_PERMISSION_REQUEST );
91
+ Bundle bundle = new Bundle ();
92
+ bundle .putStringArray (Constants .APP_PREMISSION_KEY , Constants .APP_PREMISSIONS );
93
+ in .putExtras (bundle );
94
+ startActivityForResult (in , APP_PERMISSION_REQUEST );
95
+
96
+ // Initialize Stuff
98
97
mNavigationHelper = new NavigationHelper (mContext );
99
98
mNavigationHelper .setmChangeDirectoryListener (this );
100
- mUIUpdateHandler = new Handler (Looper .getMainLooper ());
101
- io = new FileIO (mNavigationHelper ,mUIUpdateHandler ,mContext );
99
+ io = new FileIO (mNavigationHelper , new Handler (Looper .getMainLooper ()), mContext );
102
100
op = Operations .getInstance (mContext );
103
101
104
102
//set file filter (i.e display files with the given extension)
105
- mFilterFilesWithExtension = getIntent ().getStringExtra (Constants .ALLOWED_FILE_EXTENSIONS );
106
- if (mFilterFilesWithExtension !=null && !mFilterFilesWithExtension .isEmpty ()) {
107
- String allowedFileExtension [] = mFilterFilesWithExtension .split (";" );
108
- Set <String > allowedFilesFilter = new HashSet <String >(Arrays .asList (allowedFileExtension ));
109
- mNavigationHelper .setAllowedFileExtensionFilter (allowedFilesFilter );
103
+ String filterFilesWithExtension = getIntent ().getStringExtra (Constants .ALLOWED_FILE_EXTENSIONS );
104
+ if (filterFilesWithExtension != null && !filterFilesWithExtension .isEmpty ()) {
105
+ Set <String > allowedFileExtensions = new HashSet <String >(Arrays .asList (filterFilesWithExtension .split (";" )));
106
+ mNavigationHelper .setAllowedFileExtensionFilter (allowedFileExtensions );
110
107
}
111
108
112
109
mFileList = mNavigationHelper .getFilesItemsInCurrentDirectory ();
@@ -115,22 +112,22 @@ protected void onCreate(Bundle savedInstanceState) {
115
112
@ Override
116
113
public void onBackPressed () {
117
114
118
- if (mAdapter .getChoiceMode ()== Constants .CHOICE_MODE .MULTI_CHOICE ) {
115
+ if (mAdapter .getChoiceMode () == Constants .CHOICE_MODE .MULTI_CHOICE ) {
119
116
switchMode (Constants .CHOICE_MODE .SINGLE_CHOICE );
120
117
return ;
121
118
}
122
119
123
- if (!mNavigationHelper .navigateBack ()) {
120
+ if (!mNavigationHelper .navigateBack ()) {
124
121
super .onBackPressed ();
125
122
}
126
123
}
127
124
128
125
@ Override
129
126
protected void onActivityResult (int requestCode , int resultCode , Intent data ) {
130
127
super .onActivityResult (requestCode , resultCode , data );
131
- if (requestCode == APP_PERMISSION_REQUEST ) {
132
- if (resultCode != Activity .RESULT_OK )
133
- Toast .makeText (mContext ,mContext .getString (R .string .error_no_permissions ),Toast .LENGTH_LONG ).show ();
128
+ if (requestCode == APP_PERMISSION_REQUEST ) {
129
+ if (resultCode != Activity .RESULT_OK )
130
+ Toast .makeText (mContext , mContext .getString (R .string .error_no_permissions ), Toast .LENGTH_LONG ).show ();
134
131
loadUi ();
135
132
}
136
133
}
@@ -153,52 +150,53 @@ public boolean onCreateOptionsMenu(Menu menu) {
153
150
@ Override
154
151
public boolean onOptionsItemSelected (MenuItem item ) {
155
152
156
- if (item .getItemId ()== R .id .action_showfoldersizes ) {
157
- if (AssortedUtils .GetPrefs (Constants .SHOW_FOLDER_SIZE , mContext ).equalsIgnoreCase ("true" ))
158
- AssortedUtils .SavePrefs (Constants .SHOW_FOLDER_SIZE , "false" , mContext );
159
- else
160
- AssortedUtils .SavePrefs (Constants .SHOW_FOLDER_SIZE , "true" , mContext );
161
- onFileChanged (mNavigationHelper .getCurrentDirectory ());
162
- }
163
- else if (item .getItemId ()== R .id .action_newfolder ) {
164
- UIUtils .showEditTextDialog (this , getString (R .string .new_folder ), "" , new IFuncPtr (){
165
- @ Override
166
- public void execute (final String val ) {
167
- io .createDirectory (new File (mNavigationHelper .getCurrentDirectory (),val .trim ()));
168
- }
169
- });
170
- }
171
- else if (item .getItemId ()== R .id .action_paste ) {
172
- if (op .getOperation () == Operations .FILE_OPERATIONS .NONE ) {
173
- UIUtils .ShowToast (mContext .getString (R .string .no_operation_error ), mContext );
174
- return false ;
175
- }
176
- if (op .getSelectedFiles ()==null ) {
177
- UIUtils .ShowToast (mContext .getString (R .string .no_files_paste ), mContext );
178
- return false ;
153
+ if (item .getItemId () == R .id .action_showfoldersizes ) {
154
+
155
+ if (AssortedUtils .GetPrefs (Constants .SHOW_FOLDER_SIZE , mContext ).equalsIgnoreCase ("true" ))
156
+ AssortedUtils .SavePrefs (Constants .SHOW_FOLDER_SIZE , "false" , mContext );
157
+ else
158
+ AssortedUtils .SavePrefs (Constants .SHOW_FOLDER_SIZE , "true" , mContext );
159
+
160
+ onFileChanged (mNavigationHelper .getCurrentDirectory ());
161
+ }
162
+ else if (item .getItemId () == R .id .action_newfolder ) {
163
+ UIUtils .showEditTextDialog (this , getString (R .string .new_folder ), "" , new IFuncPtr (){
164
+ @ Override
165
+ public void execute (final String val ) {
166
+ io .createDirectory (new File (mNavigationHelper .getCurrentDirectory (),val .trim ()));
179
167
}
180
- io .pasteFiles (mNavigationHelper .getCurrentDirectory ());
168
+ });
169
+ }
170
+ else if (item .getItemId () == R .id .action_paste ) {
171
+ if (op .getOperation () == Operations .FILE_OPERATIONS .NONE ) {
172
+ UIUtils .ShowToast (mContext .getString (R .string .no_operation_error ), mContext );
181
173
}
174
+ if (op .getSelectedFiles () == null ) {
175
+ UIUtils .ShowToast (mContext .getString (R .string .no_files_paste ), mContext );
176
+ }
177
+ io .pasteFiles (mNavigationHelper .getCurrentDirectory ());
178
+ }
179
+
182
180
return false ;
183
181
}
184
182
185
183
@ Override
186
184
public void onFileChanged (File updatedDirectory ) {
187
- if (updatedDirectory != null && updatedDirectory .exists () && updatedDirectory .isDirectory ()) {
185
+ if (updatedDirectory != null && updatedDirectory .exists () && updatedDirectory .isDirectory ()) {
188
186
mFileList = mNavigationHelper .getFilesItemsInCurrentDirectory ();
189
187
mCurrentPath .setText (updatedDirectory .getAbsolutePath ());
190
188
mAdapter .notifyDataSetChanged ();
191
- mPathChange .getTabWithId (R .id .menu_internal_storage ).setTitle (FileUtils .byteCountToDisplaySize (Constants .internalStorageRoot .getUsableSpace ()) + "/" + FileUtils .byteCountToDisplaySize (Constants .internalStorageRoot .getTotalSpace ()));
189
+ mTopStorageView .getTabWithId (R .id .menu_internal_storage ).setTitle (FileUtils .byteCountToDisplaySize (Constants .internalStorageRoot .getUsableSpace ()) + "/" + FileUtils .byteCountToDisplaySize (Constants .internalStorageRoot .getTotalSpace ()));
192
190
if (Constants .externalStorageRoot != null )
193
- mPathChange .getTabWithId (R .id .menu_external_storage ).setTitle (FileUtils .byteCountToDisplaySize (Constants .externalStorageRoot .getUsableSpace ()) + "/" + FileUtils .byteCountToDisplaySize (Constants .externalStorageRoot .getTotalSpace ()));
191
+ mTopStorageView .getTabWithId (R .id .menu_external_storage ).setTitle (FileUtils .byteCountToDisplaySize (Constants .externalStorageRoot .getUsableSpace ()) + "/" + FileUtils .byteCountToDisplaySize (Constants .externalStorageRoot .getTotalSpace ()));
194
192
}
195
193
}
196
194
197
195
private void loadUi () {
198
196
setContentView (R .layout .filebrowser_activity_main );
199
197
200
- mCurrentPath = ( TextView ) findViewById (R .id .currentPath );
201
- mFilesListView = ( FastScrollRecyclerView ) findViewById (R .id .recycler_view );
198
+ mCurrentPath = findViewById (R .id .currentPath );
199
+ mFilesListView = findViewById (R .id .recycler_view );
202
200
mAdapter = new CustomAdapter (mFileList ,mContext );
203
201
mFilesListView .setAdapter (mAdapter );
204
202
mLayoutManager = new LinearLayoutManager (mContext );
@@ -216,7 +214,7 @@ public void onItemClick(View view, int position) {
216
214
MimeTypeMap mimeMap = MimeTypeMap .getSingleton ();
217
215
Intent openFileIntent = new Intent (Intent .ACTION_VIEW );
218
216
String mimeType = mimeMap .getMimeTypeFromExtension (FilenameUtils .getExtension (f .getName ()));
219
- Uri uri = FileProvider .getUriForFile (mContext , mContext .getString (R .string .aditya_filebrowser_provider ), f );
217
+ Uri uri = FileProvider .getUriForFile (mContext , mContext .getString (R .string .filebrowser_provider ), f );
220
218
openFileIntent .setDataAndType (uri ,mimeType );
221
219
openFileIntent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
222
220
openFileIntent .setFlags (Intent .FLAG_GRANT_READ_URI_PERMISSION );
@@ -252,57 +250,59 @@ public void onFastScrollStop() {
252
250
253
251
mSearchViewListener = new SearchViewListener (mAdapter );
254
252
255
- toolbar = ( Toolbar ) findViewById (R .id .filebrowser_tool_bar );
253
+ Toolbar toolbar = findViewById (R .id .filebrowser_tool_bar );
256
254
setSupportActionBar (toolbar );
257
255
258
- mBottomView = ( BottomBar ) findViewById (R .id .bottom_navigation );
259
- mPathChange = ( BottomBar ) findViewById (R .id .currPath_Nav );
256
+ mBottomView = findViewById (R .id .bottom_navigation );
257
+ mTopStorageView = findViewById (R .id .currPath_Nav );
260
258
261
- mTabChangeListener = new TabChangeListener (this ,mNavigationHelper ,mAdapter ,io ,this );
262
- mTabChangeListener .setmRecyclerView (mFilesListView );
259
+ mTabChangeListener = new TabChangeListener (this , mNavigationHelper , mAdapter , io ,this );
263
260
264
261
mBottomView .setOnTabSelectListener (mTabChangeListener );
265
262
mBottomView .setOnTabReselectListener (mTabChangeListener );
266
263
267
- mPathChange .setOnTabSelectListener (mTabChangeListener );
268
- mPathChange .setOnTabReselectListener (mTabChangeListener );
264
+ mTopStorageView .setOnTabSelectListener (mTabChangeListener );
265
+ mTopStorageView .setOnTabReselectListener (mTabChangeListener );
269
266
270
267
mBottomView .getTabWithId (R .id .menu_none ).setVisibility (View .GONE );
271
- mPathChange .getTabWithId (R .id .menu_none ).setVisibility (View .GONE );
268
+ mTopStorageView .getTabWithId (R .id .menu_none ).setVisibility (View .GONE );
269
+
272
270
onFileChanged (mNavigationHelper .getCurrentDirectory ());
273
271
274
272
//switch to initial directory if given
275
- mInitialDirectory = getIntent ().getStringExtra (Constants .INITIAL_DIRECTORY );
276
- if ( mInitialDirectory != null && !mInitialDirectory .isEmpty () ) {
277
- File initDir = new File (mInitialDirectory );
273
+ String initialDirectory = getIntent ().getStringExtra (Constants .INITIAL_DIRECTORY );
274
+ if ( initialDirectory != null && !initialDirectory .isEmpty () ) {
275
+ File initDir = new File (initialDirectory );
278
276
if (initDir .exists ())
279
277
mNavigationHelper .changeDirectory (initDir );
280
278
}
281
279
}
282
280
281
+ @ Override
283
282
public void switchMode (Constants .CHOICE_MODE mode ) {
284
- if (mode == Constants .CHOICE_MODE .SINGLE_CHOICE ) {
285
- if (mActionMode != null )
283
+ if (mode == Constants .CHOICE_MODE .SINGLE_CHOICE ) {
284
+ if (mActionMode != null )
286
285
mActionMode .finish ();
287
286
} else {
288
- if (mActionMode == null ) {
287
+ if (mActionMode == null ) {
289
288
closeSearchView ();
290
- ToolbarActionMode newToolBar = new ToolbarActionMode (this ,this ,mAdapter ,Constants .APP_MODE .FILE_BROWSER ,io );
289
+ ToolbarActionMode newToolBar = new ToolbarActionMode (this ,this , mAdapter , Constants .APP_MODE .FILE_BROWSER , io );
291
290
mActionMode = startSupportActionMode (newToolBar );
292
291
mActionMode .setTitle (mContext .getString (R .string .select_multiple ));
293
292
}
294
293
}
295
294
}
296
295
296
+ @ Override
297
297
public void changeBottomNavMenu (Constants .CHOICE_MODE multiChoice ) {
298
- if (multiChoice == Constants .CHOICE_MODE .SINGLE_CHOICE ) {
298
+ if (multiChoice == Constants .CHOICE_MODE .SINGLE_CHOICE ) {
299
299
mBottomView .setItems (R .xml .bottom_nav_items );
300
300
mBottomView .getTabWithId (R .id .menu_none ).setVisibility (View .GONE );
301
- mPathChange .getTabWithId (R .id .menu_none ).setVisibility (View .GONE );
301
+ mTopStorageView .getTabWithId (R .id .menu_none ).setVisibility (View .GONE );
302
302
} else {
303
303
mBottomView .setItems (R .xml .bottom_nav_items_multiselect );
304
304
mBottomView .getTabWithId (R .id .menu_none ).setVisibility (View .GONE );
305
- mPathChange .getTabWithId (R .id .menu_none ).setVisibility (View .GONE );
305
+ mTopStorageView .getTabWithId (R .id .menu_none ).setVisibility (View .GONE );
306
306
}
307
307
}
308
308
0 commit comments