diff --git a/app/src/main/java/com/amaze/filemanager/adapters/CompressedExplorerAdapter.java b/app/src/main/java/com/amaze/filemanager/adapters/CompressedExplorerAdapter.java index 73b6e2bb07..27a01465f6 100644 --- a/app/src/main/java/com/amaze/filemanager/adapters/CompressedExplorerAdapter.java +++ b/app/src/main/java/com/amaze/filemanager/adapters/CompressedExplorerAdapter.java @@ -155,7 +155,7 @@ private void toggleChecked(int position, AppCompatImageView imageView) { compressedExplorerFragment .requireMainActivity() .getAppbar() - .getToolbar() + .toolbar .startActionMode(compressedExplorerFragment.mActionModeCallback); } compressedExplorerFragment.mActionMode.invalidate(); diff --git a/app/src/main/java/com/amaze/filemanager/ui/activities/MainActivity.java b/app/src/main/java/com/amaze/filemanager/ui/activities/MainActivity.java index 391950311d..98ff753388 100644 --- a/app/src/main/java/com/amaze/filemanager/ui/activities/MainActivity.java +++ b/app/src/main/java/com/amaze/filemanager/ui/activities/MainActivity.java @@ -913,9 +913,9 @@ public void onBackPressed() { } Fragment fragment = getFragmentAtFrame(); - if (getAppbar().getSearchView().isShown()) { + if (getAppbar().searchView.isShown()) { // hide search view if visible, with an animation - getAppbar().getSearchView().hideSearchView(); + getAppbar().searchView.hideSearchView(); } else if (fragment instanceof TabFragment) { if (floatingActionButton.isOpen()) { floatingActionButton.close(true); @@ -1069,23 +1069,21 @@ public boolean onPrepareOptionsMenu(Menu menu) { } else { s.setTitle(R.string.listview); } - appbar - .getBottomBar() - .updatePath( - mainFragment.getCurrentPath(), - mainFragment.getMainFragmentViewModel().getResults(), - MainActivityHelper.SEARCH_TEXT, - mainFragment.getMainFragmentViewModel().getOpenMode(), - mainFragment.getMainFragmentViewModel().getFolderCount(), - mainFragment.getMainFragmentViewModel().getFileCount(), - mainFragment); + appbar.bottomBar.updatePath( + mainFragment.getCurrentPath(), + mainFragment.getMainFragmentViewModel().getResults(), + MainActivityHelper.SEARCH_TEXT, + mainFragment.getMainFragmentViewModel().getOpenMode(), + mainFragment.getMainFragmentViewModel().getFolderCount(), + mainFragment.getMainFragmentViewModel().getFileCount(), + mainFragment); return null; }); } catch (Exception e) { LOG.warn("failure while preparing options menu", e); } - appbar.getBottomBar().setClickListener(); + appbar.bottomBar.setClickListener(); search.setVisible(true); if (indicator_layout != null) indicator_layout.setVisibility(View.VISIBLE); @@ -1125,7 +1123,7 @@ public boolean onPrepareOptionsMenu(Menu menu) { appbar.setTitle(R.string.appbar_name); menu.findItem(R.id.sethome).setVisible(false); if (indicator_layout != null) indicator_layout.setVisibility(View.GONE); - getAppbar().getBottomBar().resetClickListener(); + getAppbar().bottomBar.resetClickListener(); menu.findItem(R.id.search).setVisible(false); menu.findItem(R.id.home).setVisible(false); menu.findItem(R.id.history).setVisible(false); @@ -1267,7 +1265,7 @@ public boolean onOptionsItemSelected(MenuItem item) { } break; case R.id.search: - getAppbar().getSearchView().revealSearchView(); + getAppbar().searchView.revealSearchView(); break; } return null; @@ -1705,9 +1703,9 @@ void initialiseViews() { mainActivityHelper.search(getPrefs(), queue); } }); - appBarLayout = getAppbar().getAppbarLayout(); + appBarLayout = getAppbar().appbarLayout; - setSupportActionBar(getAppbar().getToolbar()); + setSupportActionBar(getAppbar().toolbar); drawer = new Drawer(this); indicator_layout = findViewById(R.id.indicator_layout); @@ -1726,7 +1724,7 @@ void initialiseViews() { fabBgView.setOnClickListener( view -> { - if (getAppbar().getSearchView().isEnabled()) getAppbar().getSearchView().hideSearchView(); + if (getAppbar().searchView.isEnabled()) getAppbar().searchView.hideSearchView(); }); // drawer.setDrawerHeaderBackground(); @@ -1739,7 +1737,7 @@ void initialiseViews() { */ public void updateViews(ColorDrawable colorDrawable) { // appbar view color - appbar.getBottomBar().setBackgroundColor(colorDrawable.getColor()); + appbar.bottomBar.setBackgroundColor(colorDrawable.getColor()); // action bar color mainActivity.getSupportActionBar().setBackgroundDrawable(colorDrawable); diff --git a/app/src/main/java/com/amaze/filemanager/ui/fragments/AppsListFragment.java b/app/src/main/java/com/amaze/filemanager/ui/fragments/AppsListFragment.java index 0ccfd4d0cf..857cfd8c32 100644 --- a/app/src/main/java/com/amaze/filemanager/ui/fragments/AppsListFragment.java +++ b/app/src/main/java/com/amaze/filemanager/ui/fragments/AppsListFragment.java @@ -128,7 +128,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { fastScroller.setRecyclerView(getRecyclerView(), 1); mainActivity .getAppbar() - .getAppbarLayout() + .appbarLayout .addOnOffsetChangedListener( (appBarLayout, verticalOffset) -> { fastScroller.updateHandlePosition(verticalOffset, 112); @@ -165,7 +165,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { private void updateViews(MainActivity mainActivity, UtilitiesProvider utilsProvider) { mainActivity.getAppbar().setTitle(R.string.apps); mainActivity.hideFab(); - mainActivity.getAppbar().getBottomBar().setVisibility(View.GONE); + mainActivity.getAppbar().bottomBar.setVisibility(View.GONE); mainActivity.supportInvalidateOptionsMenu(); if (utilsProvider.getAppTheme().equals(AppTheme.DARK)) { @@ -284,7 +284,7 @@ public void adjustListViewForTv( int[] location = new int[2]; viewHolder.rl.getLocationOnScreen(location); Log.i(getClass().getSimpleName(), "Current x and y " + location[0] + " " + location[1]); - if (location[1] < mainActivity.getAppbar().getAppbarLayout().getHeight()) { + if (location[1] < mainActivity.getAppbar().appbarLayout.getHeight()) { getRecyclerView().scrollToPosition(Math.max(viewHolder.getAdapterPosition() - 5, 0)); } else if (location[1] + viewHolder.rl.getHeight() >= getContext().getResources().getDisplayMetrics().heightPixels) { diff --git a/app/src/main/java/com/amaze/filemanager/ui/fragments/MainFragment.java b/app/src/main/java/com/amaze/filemanager/ui/fragments/MainFragment.java index 3f95d74ca0..80c5713401 100644 --- a/app/src/main/java/com/amaze/filemanager/ui/fragments/MainFragment.java +++ b/app/src/main/java/com/amaze/filemanager/ui/fragments/MainFragment.java @@ -222,7 +222,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat super.onViewCreated(view, savedInstanceState); mainFragmentViewModel = new ViewModelProvider(this).get(MainFragmentViewModel.class); listView = rootView.findViewById(R.id.listView); - mToolbarContainer = requireMainActivity().getAppbar().getAppbarLayout(); + mToolbarContainer = requireMainActivity().getAppbar().appbarLayout; fastScroller = rootView.findViewById(R.id.fastscroll); fastScroller.setPressedHandleColor(mainFragmentViewModel.getAccentColor()); View.OnTouchListener onTouchListener = @@ -254,7 +254,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat initNoFileLayout(); HybridFile f = new HybridFile(OpenMode.UNKNOWN, mainFragmentViewModel.getCurrentPath()); f.generateMode(getActivity()); - getMainActivity().getAppbar().getBottomBar().setClickListener(); + getMainActivity().getAppbar().bottomBar.setClickListener(); if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT) && !mainFragmentViewModel.isList()) { listView.setBackgroundColor(Utils.getColor(getContext(), R.color.grid_background_light)); @@ -476,8 +476,8 @@ public void onListItemClicked( goBackItemClick(); } else { // hiding search view if visible - if (requireMainActivity().getAppbar().getSearchView().isEnabled()) { - requireMainActivity().getAppbar().getSearchView().hideSearchView(); + if (requireMainActivity().getAppbar().searchView.isEnabled()) { + requireMainActivity().getAppbar().searchView.hideSearchView(); } String path = @@ -845,7 +845,7 @@ public void reloadListElements(boolean back, boolean results, boolean grid) { requireMainActivity().updatePaths(mainFragmentViewModel.getNo()); requireMainActivity().showFab(); - requireMainActivity().getAppbar().getAppbarLayout().setExpanded(true); + requireMainActivity().getAppbar().appbarLayout.setExpanded(true); listView.stopScroll(); fastScroller.setRecyclerView( listView, @@ -1445,10 +1445,10 @@ public void addShortcut(LayoutElementParcelable path) { // This method is used to implement the modification for the pre Searching public void onSearchPreExecute(String query) { - requireMainActivity().getAppbar().getBottomBar().setPathText(""); + requireMainActivity().getAppbar().bottomBar.setPathText(""); requireMainActivity() .getAppbar() - .getBottomBar() + .bottomBar .setFullPathText(getString(R.string.searching, query)); } @@ -1470,17 +1470,17 @@ public void addSearchResult(@NonNull HybridFileParcelable hybridFileParcelable, @Nullable LayoutElementParcelable layoutElementAdded = addTo(hybridFileParcelable); if (!requireMainActivity() .getAppbar() - .getBottomBar() + .bottomBar .getFullPathText() .contains(getString(R.string.searching))) { requireMainActivity() .getAppbar() - .getBottomBar() + .bottomBar .setFullPathText(getString(R.string.searching, query)); } if (!mainFragmentViewModel.getResults()) { reloadListElements(false, true, !mainFragmentViewModel.isList()); - requireMainActivity().getAppbar().getBottomBar().setPathText(""); + requireMainActivity().getAppbar().bottomBar.setPathText(""); } else if (layoutElementAdded != null) { adapter.addItem(layoutElementAdded); } @@ -1652,7 +1652,7 @@ public void adjustListViewForTv( int[] location = new int[2]; viewHolder.baseItemView.getLocationOnScreen(location); LOG.info("Current x and y " + location[0] + " " + location[1]); - if (location[1] < requireMainActivity().getAppbar().getAppbarLayout().getHeight()) { + if (location[1] < requireMainActivity().getAppbar().appbarLayout.getHeight()) { listView.scrollToPosition(Math.max(viewHolder.getAdapterPosition() - 5, 0)); } else if (location[1] + viewHolder.baseItemView.getHeight() > requireContext().getResources().getDisplayMetrics().heightPixels) { diff --git a/app/src/main/java/com/amaze/filemanager/ui/fragments/ProcessViewerFragment.java b/app/src/main/java/com/amaze/filemanager/ui/fragments/ProcessViewerFragment.java index c9f4a181c2..cbf768342b 100644 --- a/app/src/main/java/com/amaze/filemanager/ui/fragments/ProcessViewerFragment.java +++ b/app/src/main/java/com/amaze/filemanager/ui/fragments/ProcessViewerFragment.java @@ -132,7 +132,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat mainActivity.getAppbar().setTitle(R.string.process_viewer); mainActivity.hideFab(); - mainActivity.getAppbar().getBottomBar().setVisibility(View.GONE); + mainActivity.getAppbar().bottomBar.setVisibility(View.GONE); mainActivity.supportInvalidateOptionsMenu(); int skin_color = mainActivity.getCurrentColorPreference().getPrimaryFirstTab(); diff --git a/app/src/main/java/com/amaze/filemanager/ui/fragments/TabFragment.java b/app/src/main/java/com/amaze/filemanager/ui/fragments/TabFragment.java index 1e7ffe6be9..338e64cdb7 100644 --- a/app/src/main/java/com/amaze/filemanager/ui/fragments/TabFragment.java +++ b/app/src/main/java/com/amaze/filemanager/ui/fragments/TabFragment.java @@ -282,7 +282,7 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse public void onPageSelected(int p1) { requireMainActivity() .getAppbar() - .getAppbarLayout() + .appbarLayout .animate() .translationY(0) .setInterpolator(new DecelerateInterpolator(2)) @@ -432,7 +432,7 @@ public void updateBottomBar(MainFragment mainFragment) { } requireMainActivity() .getAppbar() - .getBottomBar() + .bottomBar .updatePath( mainFragment.getCurrentPath(), mainFragment.getMainFragmentViewModel().getResults(), diff --git a/app/src/main/java/com/amaze/filemanager/ui/views/appbar/AppBar.kt b/app/src/main/java/com/amaze/filemanager/ui/views/appbar/AppBar.kt index b090d0df6a..aa19d40cad 100644 --- a/app/src/main/java/com/amaze/filemanager/ui/views/appbar/AppBar.kt +++ b/app/src/main/java/com/amaze/filemanager/ui/views/appbar/AppBar.kt @@ -18,78 +18,54 @@ * along with this program. If not, see . */ -package com.amaze.filemanager.ui.views.appbar; - -import static android.os.Build.VERSION.SDK_INT; - -import com.amaze.filemanager.R; -import com.amaze.filemanager.ui.activities.MainActivity; -import com.amaze.filemanager.ui.fragments.preferencefragments.PreferencesConstants; -import com.google.android.material.appbar.AppBarLayout; - -import android.content.SharedPreferences; - -import androidx.annotation.StringRes; -import androidx.appcompat.widget.Toolbar; - -/** - * layout_appbar.xml contains the layout for AppBar and BottomBar - * - *

This is a class containing containing methods to each section of the AppBar, creating the - * object loads the views. - * - * @author Emmanuel on 2/8/2017, at 23:27. - */ -public class AppBar { - - private int TOOLBAR_START_INSET; - - private Toolbar toolbar; - private SearchView searchView; - private BottomBar bottomBar; - - private AppBarLayout appbarLayout; - - public AppBar( - MainActivity a, SharedPreferences sharedPref, SearchView.SearchListener searchListener) { - toolbar = a.findViewById(R.id.action_bar); - searchView = new SearchView(this, a, searchListener); - bottomBar = new BottomBar(this, a); - - appbarLayout = a.findViewById(R.id.lin); - - if (SDK_INT >= 21) toolbar.setElevation(0); - /* For SearchView, see onCreateOptionsMenu(Menu menu)*/ - TOOLBAR_START_INSET = toolbar.getContentInsetStart(); - - if (!sharedPref.getBoolean(PreferencesConstants.PREFERENCE_INTELLI_HIDE_TOOLBAR, true)) { - AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams(); - params.setScrollFlags(0); - appbarLayout.setExpanded(true, true); +package com.amaze.filemanager.ui.views.appbar + +import android.content.SharedPreferences +import android.os.Build.VERSION +import androidx.annotation.StringRes +import androidx.appcompat.widget.Toolbar +import com.amaze.filemanager.R +import com.amaze.filemanager.ui.activities.MainActivity +import com.amaze.filemanager.ui.fragments.preferencefragments.PreferencesConstants +import com.amaze.filemanager.ui.views.appbar.SearchView.SearchListener +import com.google.android.material.appbar.AppBarLayout + +class AppBar( + mainActivity: MainActivity, + sharedPref: SharedPreferences, + searchListener: SearchListener? +) { + @JvmField + val toolbar: Toolbar? + + @JvmField + val searchView: SearchView + + @JvmField + val bottomBar: BottomBar + + @JvmField + val appbarLayout: AppBarLayout + + init { + toolbar = mainActivity.findViewById(R.id.action_bar) + searchView = SearchView(this, mainActivity, searchListener) + bottomBar = BottomBar(this, mainActivity) + appbarLayout = mainActivity.findViewById(R.id.lin) + + if (VERSION.SDK_INT >= 21) toolbar.elevation = 0f + + if (!sharedPref.getBoolean(PreferencesConstants.PREFERENCE_INTELLI_HIDE_TOOLBAR, true)) { + (toolbar.layoutParams as AppBarLayout.LayoutParams).scrollFlags = 0 + appbarLayout.setExpanded(true, true) + } } - } - - public Toolbar getToolbar() { - return toolbar; - } - public SearchView getSearchView() { - return searchView; - } - - public BottomBar getBottomBar() { - return bottomBar; - } - - public AppBarLayout getAppbarLayout() { - return appbarLayout; - } - - public void setTitle(String title) { - if (toolbar != null) toolbar.setTitle(title); - } + fun setTitle(title: String?) { + if (toolbar != null) toolbar.title = title + } - public void setTitle(@StringRes int title) { - if (toolbar != null) toolbar.setTitle(title); - } + fun setTitle(@StringRes title: Int) { + toolbar?.setTitle(title) + } } diff --git a/app/src/main/java/com/amaze/filemanager/ui/views/appbar/BottomBar.java b/app/src/main/java/com/amaze/filemanager/ui/views/appbar/BottomBar.java index 0fc53e1da4..45aea4e98c 100644 --- a/app/src/main/java/com/amaze/filemanager/ui/views/appbar/BottomBar.java +++ b/app/src/main/java/com/amaze/filemanager/ui/views/appbar/BottomBar.java @@ -260,7 +260,7 @@ public void showButtons(final BottomBarButtonPath buttonPathInterface) { View view = new View(mainActivity); LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams( - appbar.getToolbar().getContentInsetLeft(), LinearLayout.LayoutParams.WRAP_CONTENT); + appbar.toolbar.getContentInsetLeft(), LinearLayout.LayoutParams.WRAP_CONTENT); view.setLayoutParams(params1); buttons.addView(view); diff --git a/app/src/main/java/com/amaze/filemanager/ui/views/appbar/SearchView.java b/app/src/main/java/com/amaze/filemanager/ui/views/appbar/SearchView.java index 78fedb8851..4f6ad062d6 100644 --- a/app/src/main/java/com/amaze/filemanager/ui/views/appbar/SearchView.java +++ b/app/src/main/java/com/amaze/filemanager/ui/views/appbar/SearchView.java @@ -123,7 +123,7 @@ public SearchView(final AppBar appbar, MainActivity mainActivity, SearchListener clearRecyclerView(); }); - backImageView.setOnClickListener(v -> appbar.getSearchView().hideSearchView()); + backImageView.setOnClickListener(v -> appbar.searchView.hideSearchView()); searchViewEditText.addTextChangedListener( new TextWatcher() { @@ -183,7 +183,7 @@ public void afterTextChanged(Editable s) {} } else if (searchMode == 2) { searchListener.onSearch(s); - appbar.getSearchView().hideSearchView(); + appbar.searchView.hideSearchView(); deepSearchTV.setVisibility(View.GONE); } @@ -312,7 +312,7 @@ private void resetSearchMode() { /** show search view with a circular reveal animation */ public void revealSearchView() { final int START_RADIUS = 16; - int endRadius = Math.max(appbar.getToolbar().getWidth(), appbar.getToolbar().getHeight()); + int endRadius = Math.max(appbar.toolbar.getWidth(), appbar.toolbar.getHeight()); resetSearchMode(); clearRecyclerView(); @@ -321,9 +321,7 @@ public void revealSearchView() { if (SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { int[] searchCoords = new int[2]; View searchItem = - appbar - .getToolbar() - .findViewById(R.id.search); // It could change position, get it every time + appbar.toolbar.findViewById(R.id.search); // It could change position, get it every time searchViewEditText.setText(""); searchItem.getLocationOnScreen(searchCoords); animator = @@ -374,9 +372,7 @@ public void hideSearchView() { if (SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { int[] searchCoords = new int[2]; View searchItem = - appbar - .getToolbar() - .findViewById(R.id.search); // It could change position, get it every time + appbar.toolbar.findViewById(R.id.search); // It could change position, get it every time searchViewEditText.setText(""); searchItem.getLocationOnScreen(searchCoords); animator = diff --git a/app/src/main/java/com/amaze/filemanager/ui/views/drawer/Drawer.java b/app/src/main/java/com/amaze/filemanager/ui/views/drawer/Drawer.java index 06b390a4e8..3e71cd8ec8 100644 --- a/app/src/main/java/com/amaze/filemanager/ui/views/drawer/Drawer.java +++ b/app/src/main/java/com/amaze/filemanager/ui/views/drawer/Drawer.java @@ -529,7 +529,7 @@ public void refreshDrawer() { transaction2.replace(R.id.content_frame, new FtpServerFragment()); mainActivity .getAppbar() - .getAppbarLayout() + .appbarLayout .animate() .translationY(0) .setInterpolator(new DecelerateInterpolator(2)) @@ -601,7 +601,7 @@ public void refreshDrawer() { transaction2.replace(R.id.content_frame, new AppsListFragment()); mainActivity .getAppbar() - .getAppbarLayout() + .appbarLayout .animate() .translationY(0) .setInterpolator(new DecelerateInterpolator(2)) @@ -647,8 +647,8 @@ private void initDrawerFocusItems() { (v, keyCode, event) -> { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) { - mainActivity.getAppbar().getAppbarLayout().requestFocus(); - mainActivity.getAppbar().getToolbar().requestFocus(); + mainActivity.getAppbar().appbarLayout.requestFocus(); + mainActivity.getAppbar().toolbar.requestFocus(); } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER) { new Billing(mainActivity); } else if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {