Moved toolbar to fragment to allow hide-on-scroll

This commit is contained in:
Daniele Verducci (Slimpenguin) 2024-02-19 08:53:24 +01:00
parent a396406877
commit e1b1adf9ad
7 changed files with 218 additions and 196 deletions

View File

@ -78,15 +78,15 @@ public class MainActivity extends NextcloudMapsStyledActivity {
private static final String NAVIGATION_KEY_SWITCH_ACCOUNT = "switch_account"; private static final String NAVIGATION_KEY_SWITCH_ACCOUNT = "switch_account";
private DrawerLayout drawerLayout; private DrawerLayout drawerLayout;
private Toolbar toolbar;
private MaterialCardView homeToolbar;
private SearchView searchView;
private FloatingActionButton fab;
private boolean isFabOpen = false; private boolean isFabOpen = false;
NavigationAdapter navigationCommonAdapter; NavigationAdapter navigationCommonAdapter;
public void openDrawer() {
drawerLayout.openDrawer(GravityCompat.START);
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -104,7 +104,7 @@ public class MainActivity extends NextcloudMapsStyledActivity {
transaction.commit(); transaction.commit();
} }
fab = findViewById(R.id.open_fab); FloatingActionButton fab = findViewById(R.id.open_fab);
fab.setOnClickListener(view -> openFab(!this.isFabOpen)); fab.setOnClickListener(view -> openFab(!this.isFabOpen));
fab = findViewById(R.id.add_from_gps); fab = findViewById(R.id.add_from_gps);
@ -113,44 +113,9 @@ public class MainActivity extends NextcloudMapsStyledActivity {
fab = findViewById(R.id.add_from_map); fab = findViewById(R.id.add_from_map);
fab.setOnClickListener(view -> addGeofavoriteFromMap()); fab.setOnClickListener(view -> addGeofavoriteFromMap());
toolbar = findViewById(R.id.toolbar);
homeToolbar = findViewById(R.id.home_toolbar);
searchView = findViewById(R.id.search_view);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String query) {
GeofavoritesFragment gff = (GeofavoritesFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_container);
if (gff == null) {
Log.e(TAG, "onQueryTextChange: No fragment active!");
return false;
}
gff.onSearch(query);
return false;
}
});
searchView.setOnCloseListener(() -> {
if (toolbar.getVisibility() == VISIBLE && TextUtils.isEmpty(searchView.getQuery())) {
updateToolbars(true);
return true;
}
return false;
});
setSupportActionBar(toolbar);
setupNavigationMenu(); setupNavigationMenu();
homeToolbar.setOnClickListener(view -> updateToolbars(false));
drawerLayout = findViewById(R.id.drawerLayout); drawerLayout = findViewById(R.id.drawerLayout);
AppCompatImageButton menuButton = findViewById(R.id.menu_button);
menuButton.setOnClickListener(view -> drawerLayout.openDrawer(GravityCompat.START));
} }
@Override @Override
@ -189,15 +154,6 @@ public class MainActivity extends NextcloudMapsStyledActivity {
navigationMenuCommon.setAdapter(navigationCommonAdapter); navigationMenuCommon.setAdapter(navigationCommonAdapter);
} }
private void updateToolbars(boolean disableSearch) {
homeToolbar.setVisibility(disableSearch ? VISIBLE : GONE);
toolbar.setVisibility(disableSearch ? GONE : VISIBLE);
if (disableSearch) {
searchView.setQuery(null, true);
}
searchView.setIconified(disableSearch);
}
private void addGeofavoriteFromGps() { private void addGeofavoriteFromGps() {
startActivity( startActivity(
new Intent(this, GeofavoriteDetailActivity.class) new Intent(this, GeofavoriteDetailActivity.class)

View File

@ -1,11 +1,15 @@
package it.danieleverducci.nextcloudmaps.fragments; package it.danieleverducci.nextcloudmaps.fragments;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static it.danieleverducci.nextcloudmaps.activity.main.GeofavoriteAdapter.SORT_BY_CATEGORY; import static it.danieleverducci.nextcloudmaps.activity.main.GeofavoriteAdapter.SORT_BY_CATEGORY;
import static it.danieleverducci.nextcloudmaps.activity.main.GeofavoriteAdapter.SORT_BY_CREATED; import static it.danieleverducci.nextcloudmaps.activity.main.GeofavoriteAdapter.SORT_BY_CREATED;
import static it.danieleverducci.nextcloudmaps.activity.main.GeofavoriteAdapter.SORT_BY_DISTANCE; import static it.danieleverducci.nextcloudmaps.activity.main.GeofavoriteAdapter.SORT_BY_DISTANCE;
import static it.danieleverducci.nextcloudmaps.activity.main.GeofavoriteAdapter.SORT_BY_TITLE; import static it.danieleverducci.nextcloudmaps.activity.main.GeofavoriteAdapter.SORT_BY_TITLE;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -13,7 +17,10 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageButton;
import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
@ -23,6 +30,8 @@ import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager; import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.google.android.material.card.MaterialCardView;
import java.util.List; import java.util.List;
import it.danieleverducci.nextcloudmaps.R; import it.danieleverducci.nextcloudmaps.R;
@ -35,24 +44,57 @@ import it.danieleverducci.nextcloudmaps.utils.SettingsManager;
public class GeofavoriteListFragment extends GeofavoritesFragment implements SortingOrderDialogFragment.OnSortingOrderListener { public class GeofavoriteListFragment extends GeofavoritesFragment implements SortingOrderDialogFragment.OnSortingOrderListener {
private SwipeRefreshLayout swipeRefresh; private SwipeRefreshLayout swipeRefresh;
private RecyclerView recyclerView;
private LinearLayoutManager layoutManager;
private GeofavoriteAdapter geofavoriteAdapter; private GeofavoriteAdapter geofavoriteAdapter;
private GeofavoriteAdapter.ItemClickListener rvItemClickListener; private Toolbar toolbar;
private MaterialCardView homeToolbar;
private SearchView searchView;
@Nullable @Nullable
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_geofavorite_list, container, false); View v = inflater.inflate(R.layout.fragment_geofavorite_list, container, false);
// Setup toolbar/searchbar
toolbar = v.findViewById(R.id.toolbar);
homeToolbar = v.findViewById(R.id.home_toolbar);
searchView = v.findViewById(R.id.search_view);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String query) {
onSearch(query);
return false;
}
});
searchView.setOnCloseListener(() -> {
if (toolbar.getVisibility() == VISIBLE && TextUtils.isEmpty(searchView.getQuery())) {
updateToolbars(true);
return true;
}
return false;
});
//setSupportActionBar(toolbar);
homeToolbar.setOnClickListener(view -> updateToolbars(false));
AppCompatImageButton menuButton = v.findViewById(R.id.menu_button);
menuButton.setOnClickListener(view -> ((MainActivity)requireActivity()).openDrawer());
// Setup list // Setup list
int sortRule = SettingsManager.getGeofavoriteListSortBy(requireContext()); int sortRule = SettingsManager.getGeofavoriteListSortBy(requireContext());
recyclerView = v.findViewById(R.id.recycler_view); RecyclerView recyclerView = v.findViewById(R.id.recycler_view);
layoutManager = new LinearLayoutManager(requireContext()); LinearLayoutManager layoutManager = new LinearLayoutManager(requireContext());
recyclerView.setLayoutManager(layoutManager); recyclerView.setLayoutManager(layoutManager);
rvItemClickListener = new GeofavoriteAdapter.ItemClickListener() { GeofavoriteAdapter.ItemClickListener rvItemClickListener = new GeofavoriteAdapter.ItemClickListener() {
@Override @Override
public void onItemClick(Geofavorite item) { public void onItemClick(Geofavorite item) {
openGeofavorite(item); openGeofavorite(item);
@ -113,7 +155,6 @@ public class GeofavoriteListFragment extends GeofavoritesFragment implements Sor
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
// Set icons // Set icons
// Setup list
int sortRule = SettingsManager.getGeofavoriteListSortBy(requireContext()); int sortRule = SettingsManager.getGeofavoriteListSortBy(requireContext());
updateSortingIcon(sortRule); updateSortingIcon(sortRule);
} }
@ -157,4 +198,13 @@ public class GeofavoriteListFragment extends GeofavoritesFragment implements Sor
} }
} }
private void updateToolbars(boolean disableSearch) {
homeToolbar.setVisibility(disableSearch ? VISIBLE : GONE);
toolbar.setVisibility(disableSearch ? GONE : VISIBLE);
if (disableSearch) {
searchView.setQuery(null, true);
}
searchView.setIconified(disableSearch);
}
} }

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M20.5,3l-0.16,0.03L15,5.1 9,3 3.36,4.9c-0.21,0.07 -0.36,0.25 -0.36,0.48V20.5c0,0.28 0.22,0.5 0.5,0.5l0.16,-0.03L9,18.9l6,2.1 5.64,-1.9c0.21,-0.07 0.36,-0.25 0.36,-0.48V3.5c0,-0.28 -0.22,-0.5 -0.5,-0.5zM15,19l-6,-2.11V5l6,2.11V19z"/>
</vector>

View File

@ -1,25 +0,0 @@
<!--
~ Nextcloud Maps Geofavorites for Android
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#FFFFFF"
android:pathData="M16,5V11H21V5M10,11H15V5H10M16,18H21V12H16M10,18H15V12H10M4,18H9V12H4M4,11H9V5H4V11Z" />
</vector>

View File

@ -15,98 +15,13 @@
~ You should have received a copy of the GNU General Public License ~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>. ~ along with this program. If not, see <http://www.gnu.org/licenses/>.
--> -->
<FrameLayout
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_list_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:elevation="0dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:toolbarId="@+id/toolbar" >
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
app:contentInsetStartWithNavigation="0dp"
app:titleMarginStart="0dp"
tools:title="@string/app_name">
<androidx.appcompat.widget.SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</androidx.appcompat.widget.SearchView>
</androidx.appcompat.widget.Toolbar>
<com.google.android.material.card.MaterialCardView
android:id="@+id/home_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/spacer_2x"
android:layout_marginTop="@dimen/spacer_1hx"
android:layout_marginEnd="@dimen/spacer_2x"
android:layout_marginBottom="@dimen/spacer_1hx"
app:cardCornerRadius="30dp"
app:cardElevation="2dp"
app:strokeWidth="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/menu_button"
android:layout_width="?android:attr/actionBarSize"
android:layout_height="?android:attr/actionBarSize"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:layout_gravity="center_vertical|start"
android:paddingStart="@dimen/spacer_1x"
android:paddingTop="@dimen/spacer_2x"
android:paddingEnd="@dimen/spacer_1x"
android:paddingBottom="@dimen/spacer_2x"
android:tint="@color/text_color"
android:src="@drawable/ic_menu_grey"
android:contentDescription="@string/menu"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/search_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/spacer_1x"
android:layout_marginEnd="@dimen/spacer_1x"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="start"
android:lines="1"
android:textSize="16sp"
android:text="@string/search_in_all"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.fragment.app.FragmentContainerView <androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container" android:id="@+id/fragment_container"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -154,4 +69,4 @@
app:tint="@color/white" app:tint="@color/white"
android:contentDescription="@string/open_fab"/> android:contentDescription="@string/open_fab"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </FrameLayout>

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
app:contentInsetStartWithNavigation="0dp"
app:titleMarginStart="0dp"
tools:title="@string/app_name">
<androidx.appcompat.widget.SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</androidx.appcompat.widget.SearchView>
</androidx.appcompat.widget.Toolbar>
<com.google.android.material.card.MaterialCardView
android:id="@+id/home_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/spacer_2x"
android:layout_marginTop="@dimen/spacer_1hx"
android:layout_marginEnd="@dimen/spacer_2x"
android:layout_marginBottom="@dimen/spacer_1hx"
app:cardCornerRadius="30dp"
app:cardElevation="2dp"
app:strokeWidth="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/menu_button"
android:layout_width="?android:attr/actionBarSize"
android:layout_height="?android:attr/actionBarSize"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:layout_gravity="center_vertical|start"
android:paddingStart="@dimen/spacer_1x"
android:paddingTop="@dimen/spacer_2x"
android:paddingEnd="@dimen/spacer_1x"
android:paddingBottom="@dimen/spacer_2x"
android:tint="@color/text_color"
android:src="@drawable/ic_menu_grey"
android:contentDescription="@string/menu"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/search_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/spacer_1x"
android:layout_marginEnd="@dimen/spacer_1x"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="start"
android:lines="1"
android:textSize="16sp"
android:text="@string/search_in_all"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</FrameLayout>

View File

@ -1,23 +1,42 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipe_refresh" android:id="@+id/activity_list_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:layout_margin="@dimen/spacer_1hx"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.appcompat.widget.LinearLayoutCompat <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="vertical"> app:elevation="0dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:toolbarId="@+id/toolbar" >
<include layout="@layout/app_toolbar"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="?android:attr/actionBarSize"
android:paddingTop="10dp">
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/sort_mode" android:id="@+id/sort_mode"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="@dimen/floating_bar_height" android:layout_height="@dimen/floating_bar_height"
android:layout_alignParentLeft="true"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/list_mode" android:contentDescription="@string/list_mode"
android:paddingStart="@dimen/spacer_2x" android:paddingStart="@dimen/spacer_2x"
@ -25,6 +44,34 @@
android:tint="@color/text_color" android:tint="@color/text_color"
android:src="@drawable/ic_alphabetical_asc" /> android:src="@drawable/ic_alphabetical_asc" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/view_mode_map"
android:layout_width="wrap_content"
android:layout_height="@dimen/floating_bar_height"
android:layout_alignParentRight="true"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/list_mode"
android:paddingStart="@dimen/spacer_2x"
android:paddingEnd="@dimen/spacer_2x"
android:tint="@color/text_color"
android:src="@drawable/ic_view_map" />
</RelativeLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view" android:id="@+id/recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -35,6 +82,8 @@
tools:listitem="@layout/item_geofav"> tools:listitem="@layout/item_geofav">
</androidx.recyclerview.widget.RecyclerView> </androidx.recyclerview.widget.RecyclerView>
</androidx.appcompat.widget.LinearLayoutCompat> </androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>