migrate AppBar to Kotlin

This commit is contained in:
VishnuSanal
2023-11-12 22:24:22 +05:30
parent 7582a42fc5
commit 586c995f8b
10 changed files with 84 additions and 114 deletions
@@ -155,7 +155,7 @@ public class CompressedExplorerAdapter extends RecyclerView.Adapter<CompressedIt
compressedExplorerFragment
.requireMainActivity()
.getAppbar()
.getToolbar()
.toolbar
.startActionMode(compressedExplorerFragment.mActionModeCallback);
}
compressedExplorerFragment.mActionMode.invalidate();
@@ -913,9 +913,9 @@ public class MainActivity extends PermissionsActivity
}
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 class MainActivity extends PermissionsActivity
} 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 class MainActivity extends PermissionsActivity
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 class MainActivity extends PermissionsActivity
}
break;
case R.id.search:
getAppbar().getSearchView().revealSearchView();
getAppbar().searchView.revealSearchView();
break;
}
return null;
@@ -1705,9 +1703,9 @@ public class MainActivity extends PermissionsActivity
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 @@ public class MainActivity extends PermissionsActivity
fabBgView.setOnClickListener(
view -> {
if (getAppbar().getSearchView().isEnabled()) getAppbar().getSearchView().hideSearchView();
if (getAppbar().searchView.isEnabled()) getAppbar().searchView.hideSearchView();
});
// drawer.setDrawerHeaderBackground();
@@ -1739,7 +1737,7 @@ public class MainActivity extends PermissionsActivity
*/
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);
@@ -128,7 +128,7 @@ public class AppsListFragment extends Fragment
fastScroller.setRecyclerView(getRecyclerView(), 1);
mainActivity
.getAppbar()
.getAppbarLayout()
.appbarLayout
.addOnOffsetChangedListener(
(appBarLayout, verticalOffset) -> {
fastScroller.updateHandlePosition(verticalOffset, 112);
@@ -165,7 +165,7 @@ public class AppsListFragment extends Fragment
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 class AppsListFragment extends Fragment
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) {
@@ -222,7 +222,7 @@ public class MainFragment extends Fragment
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 class MainFragment extends Fragment
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 class MainFragment extends Fragment
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 class MainFragment extends Fragment
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 class MainFragment extends Fragment
// 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 class MainFragment extends Fragment
@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 class MainFragment extends Fragment
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) {
@@ -132,7 +132,7 @@ public class ProcessViewerFragment extends Fragment {
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();
@@ -282,7 +282,7 @@ public class TabFragment extends Fragment {
public void onPageSelected(int p1) {
requireMainActivity()
.getAppbar()
.getAppbarLayout()
.appbarLayout
.animate()
.translationY(0)
.setInterpolator(new DecelerateInterpolator(2))
@@ -432,7 +432,7 @@ public class TabFragment extends Fragment {
}
requireMainActivity()
.getAppbar()
.getBottomBar()
.bottomBar
.updatePath(
mainFragment.getCurrentPath(),
mainFragment.getMainFragmentViewModel().getResults(),
@@ -18,78 +18,54 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.amaze.filemanager.ui.views.appbar;
package com.amaze.filemanager.ui.views.appbar
import static android.os.Build.VERSION.SDK_INT;
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
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;
class AppBar(
mainActivity: MainActivity,
sharedPref: SharedPreferences,
searchListener: SearchListener?
) {
@JvmField
val toolbar: Toolbar?
import android.content.SharedPreferences;
@JvmField
val searchView: SearchView
import androidx.annotation.StringRes;
import androidx.appcompat.widget.Toolbar;
@JvmField
val bottomBar: BottomBar
/**
* 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 {
@JvmField
val appbarLayout: AppBarLayout
private int TOOLBAR_START_INSET;
init {
toolbar = mainActivity.findViewById(R.id.action_bar)
searchView = SearchView(this, mainActivity, searchListener)
bottomBar = BottomBar(this, mainActivity)
appbarLayout = mainActivity.findViewById(R.id.lin)
private Toolbar toolbar;
private SearchView searchView;
private BottomBar bottomBar;
if (VERSION.SDK_INT >= 21) toolbar.elevation = 0f
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);
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;
}
fun setTitle(title: String?) {
if (toolbar != null) toolbar.title = title
}
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);
}
public void setTitle(@StringRes int title) {
if (toolbar != null) toolbar.setTitle(title);
}
fun setTitle(@StringRes title: Int) {
toolbar?.setTitle(title)
}
}
@@ -260,7 +260,7 @@ public class BottomBar implements View.OnTouchListener {
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);
@@ -123,7 +123,7 @@ public class SearchView {
clearRecyclerView();
});
backImageView.setOnClickListener(v -> appbar.getSearchView().hideSearchView());
backImageView.setOnClickListener(v -> appbar.searchView.hideSearchView());
searchViewEditText.addTextChangedListener(
new TextWatcher() {
@@ -183,7 +183,7 @@ public class SearchView {
} else if (searchMode == 2) {
searchListener.onSearch(s);
appbar.getSearchView().hideSearchView();
appbar.searchView.hideSearchView();
deepSearchTV.setVisibility(View.GONE);
}
@@ -312,7 +312,7 @@ public class SearchView {
/** 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 class SearchView {
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 class SearchView {
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 =
@@ -529,7 +529,7 @@ public class Drawer implements NavigationView.OnNavigationItemSelectedListener {
transaction2.replace(R.id.content_frame, new FtpServerFragment());
mainActivity
.getAppbar()
.getAppbarLayout()
.appbarLayout
.animate()
.translationY(0)
.setInterpolator(new DecelerateInterpolator(2))
@@ -601,7 +601,7 @@ public class Drawer implements NavigationView.OnNavigationItemSelectedListener {
transaction2.replace(R.id.content_frame, new AppsListFragment());
mainActivity
.getAppbar()
.getAppbarLayout()
.appbarLayout
.animate()
.translationY(0)
.setInterpolator(new DecelerateInterpolator(2))
@@ -647,8 +647,8 @@ public class Drawer implements NavigationView.OnNavigationItemSelectedListener {
(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) {