Skip to content

Commit

Permalink
migrate AppBar to Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSanal committed Nov 12, 2023
1 parent 7582a42 commit 586c995
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void toggleChecked(int position, AppCompatImageView imageView) {
compressedExplorerFragment
.requireMainActivity()
.getAppbar()
.getToolbar()
.toolbar
.startActionMode(compressedExplorerFragment.mActionModeCallback);
}
compressedExplorerFragment.mActionMode.invalidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1267,7 +1265,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
break;
case R.id.search:
getAppbar().getSearchView().revealSearchView();
getAppbar().searchView.revealSearchView();
break;
}
return null;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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));
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -432,7 +432,7 @@ public void updateBottomBar(MainFragment mainFragment) {
}
requireMainActivity()
.getAppbar()
.getBottomBar()
.bottomBar
.updatePath(
mainFragment.getCurrentPath(),
mainFragment.getMainFragmentViewModel().getResults(),
Expand Down
118 changes: 47 additions & 71 deletions app/src/main/java/com/amaze/filemanager/ui/views/appbar/AppBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,78 +18,54 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

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
*
* <p>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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading

0 comments on commit 586c995

Please sign in to comment.