5757public class FileBrowser extends AppCompatActivity implements OnFileChangedListener ,IContextSwitcher {
5858
5959 private Context mContext ;
60- private Toolbar toolbar ;
6160
6261 private CustomAdapter mAdapter ;
6362 private FastScrollRecyclerView .LayoutManager mLayoutManager ;
6463 private FastScrollRecyclerView mFilesListView ;
6564
6665 private BottomBar mBottomView ;
67- private BottomBar mPathChange ;
66+ private BottomBar mTopStorageView ;
6867 private TabChangeListener mTabChangeListener ;
6968
7069 private TextView mCurrentPath ;
@@ -79,34 +78,32 @@ public class FileBrowser extends AppCompatActivity implements OnFileChangedListe
7978 private SearchView mSearchView ;
8079 private MenuItem mSearchMenuItem ;
8180 private SearchViewListener mSearchViewListener ;
82- private Handler mUIUpdateHandler ;
8381 private List <FileItem > mFileList = new ArrayList <>();
8482
85- private String mInitialDirectory ;
86- private String mFilterFilesWithExtension ;
87-
8883 @ Override
8984 protected void onCreate (Bundle savedInstanceState ) {
9085 super .onCreate (savedInstanceState );
9186
9287 mContext = this ;
88+
89+ // Get File Storage Permission
9390 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
9897 mNavigationHelper = new NavigationHelper (mContext );
9998 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 );
102100 op = Operations .getInstance (mContext );
103101
104102 //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 );
110107 }
111108
112109 mFileList = mNavigationHelper .getFilesItemsInCurrentDirectory ();
@@ -115,22 +112,22 @@ protected void onCreate(Bundle savedInstanceState) {
115112 @ Override
116113 public void onBackPressed () {
117114
118- if (mAdapter .getChoiceMode ()== Constants .CHOICE_MODE .MULTI_CHOICE ) {
115+ if (mAdapter .getChoiceMode () == Constants .CHOICE_MODE .MULTI_CHOICE ) {
119116 switchMode (Constants .CHOICE_MODE .SINGLE_CHOICE );
120117 return ;
121118 }
122119
123- if (!mNavigationHelper .navigateBack ()) {
120+ if (!mNavigationHelper .navigateBack ()) {
124121 super .onBackPressed ();
125122 }
126123 }
127124
128125 @ Override
129126 protected void onActivityResult (int requestCode , int resultCode , Intent data ) {
130127 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 ();
134131 loadUi ();
135132 }
136133 }
@@ -153,52 +150,53 @@ public boolean onCreateOptionsMenu(Menu menu) {
153150 @ Override
154151 public boolean onOptionsItemSelected (MenuItem item ) {
155152
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 ()));
179167 }
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 );
181173 }
174+ if (op .getSelectedFiles () == null ) {
175+ UIUtils .ShowToast (mContext .getString (R .string .no_files_paste ), mContext );
176+ }
177+ io .pasteFiles (mNavigationHelper .getCurrentDirectory ());
178+ }
179+
182180 return false ;
183181 }
184182
185183 @ Override
186184 public void onFileChanged (File updatedDirectory ) {
187- if (updatedDirectory != null && updatedDirectory .exists () && updatedDirectory .isDirectory ()) {
185+ if (updatedDirectory != null && updatedDirectory .exists () && updatedDirectory .isDirectory ()) {
188186 mFileList = mNavigationHelper .getFilesItemsInCurrentDirectory ();
189187 mCurrentPath .setText (updatedDirectory .getAbsolutePath ());
190188 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 ()));
192190 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 ()));
194192 }
195193 }
196194
197195 private void loadUi () {
198196 setContentView (R .layout .filebrowser_activity_main );
199197
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 );
202200 mAdapter = new CustomAdapter (mFileList ,mContext );
203201 mFilesListView .setAdapter (mAdapter );
204202 mLayoutManager = new LinearLayoutManager (mContext );
@@ -216,7 +214,7 @@ public void onItemClick(View view, int position) {
216214 MimeTypeMap mimeMap = MimeTypeMap .getSingleton ();
217215 Intent openFileIntent = new Intent (Intent .ACTION_VIEW );
218216 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 );
220218 openFileIntent .setDataAndType (uri ,mimeType );
221219 openFileIntent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
222220 openFileIntent .setFlags (Intent .FLAG_GRANT_READ_URI_PERMISSION );
@@ -252,57 +250,59 @@ public void onFastScrollStop() {
252250
253251 mSearchViewListener = new SearchViewListener (mAdapter );
254252
255- toolbar = ( Toolbar ) findViewById (R .id .filebrowser_tool_bar );
253+ Toolbar toolbar = findViewById (R .id .filebrowser_tool_bar );
256254 setSupportActionBar (toolbar );
257255
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 );
260258
261- mTabChangeListener = new TabChangeListener (this ,mNavigationHelper ,mAdapter ,io ,this );
262- mTabChangeListener .setmRecyclerView (mFilesListView );
259+ mTabChangeListener = new TabChangeListener (this , mNavigationHelper , mAdapter , io ,this );
263260
264261 mBottomView .setOnTabSelectListener (mTabChangeListener );
265262 mBottomView .setOnTabReselectListener (mTabChangeListener );
266263
267- mPathChange .setOnTabSelectListener (mTabChangeListener );
268- mPathChange .setOnTabReselectListener (mTabChangeListener );
264+ mTopStorageView .setOnTabSelectListener (mTabChangeListener );
265+ mTopStorageView .setOnTabReselectListener (mTabChangeListener );
269266
270267 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+
272270 onFileChanged (mNavigationHelper .getCurrentDirectory ());
273271
274272 //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 );
278276 if (initDir .exists ())
279277 mNavigationHelper .changeDirectory (initDir );
280278 }
281279 }
282280
281+ @ Override
283282 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 )
286285 mActionMode .finish ();
287286 } else {
288- if (mActionMode == null ) {
287+ if (mActionMode == null ) {
289288 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 );
291290 mActionMode = startSupportActionMode (newToolBar );
292291 mActionMode .setTitle (mContext .getString (R .string .select_multiple ));
293292 }
294293 }
295294 }
296295
296+ @ Override
297297 public void changeBottomNavMenu (Constants .CHOICE_MODE multiChoice ) {
298- if (multiChoice == Constants .CHOICE_MODE .SINGLE_CHOICE ) {
298+ if (multiChoice == Constants .CHOICE_MODE .SINGLE_CHOICE ) {
299299 mBottomView .setItems (R .xml .bottom_nav_items );
300300 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 );
302302 } else {
303303 mBottomView .setItems (R .xml .bottom_nav_items_multiselect );
304304 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 );
306306 }
307307 }
308308
0 commit comments