Moved toolbar to fragment to allow hide-on-scroll
This commit is contained in:
@ -78,15 +78,15 @@ public class MainActivity extends NextcloudMapsStyledActivity {
|
||||
private static final String NAVIGATION_KEY_SWITCH_ACCOUNT = "switch_account";
|
||||
|
||||
private DrawerLayout drawerLayout;
|
||||
private Toolbar toolbar;
|
||||
private MaterialCardView homeToolbar;
|
||||
private SearchView searchView;
|
||||
private FloatingActionButton fab;
|
||||
|
||||
private boolean isFabOpen = false;
|
||||
|
||||
NavigationAdapter navigationCommonAdapter;
|
||||
|
||||
public void openDrawer() {
|
||||
drawerLayout.openDrawer(GravityCompat.START);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
@ -104,7 +104,7 @@ public class MainActivity extends NextcloudMapsStyledActivity {
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
fab = findViewById(R.id.open_fab);
|
||||
FloatingActionButton fab = findViewById(R.id.open_fab);
|
||||
fab.setOnClickListener(view -> openFab(!this.isFabOpen));
|
||||
|
||||
fab = findViewById(R.id.add_from_gps);
|
||||
@ -113,44 +113,9 @@ public class MainActivity extends NextcloudMapsStyledActivity {
|
||||
fab = findViewById(R.id.add_from_map);
|
||||
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();
|
||||
|
||||
homeToolbar.setOnClickListener(view -> updateToolbars(false));
|
||||
|
||||
drawerLayout = findViewById(R.id.drawerLayout);
|
||||
AppCompatImageButton menuButton = findViewById(R.id.menu_button);
|
||||
menuButton.setOnClickListener(view -> drawerLayout.openDrawer(GravityCompat.START));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -189,15 +154,6 @@ public class MainActivity extends NextcloudMapsStyledActivity {
|
||||
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() {
|
||||
startActivity(
|
||||
new Intent(this, GeofavoriteDetailActivity.class)
|
||||
|
@ -1,11 +1,15 @@
|
||||
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_CREATED;
|
||||
import static it.danieleverducci.nextcloudmaps.activity.main.GeofavoriteAdapter.SORT_BY_DISTANCE;
|
||||
import static it.danieleverducci.nextcloudmaps.activity.main.GeofavoriteAdapter.SORT_BY_TITLE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -13,7 +17,10 @@ import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatImageButton;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
@ -23,6 +30,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import it.danieleverducci.nextcloudmaps.R;
|
||||
@ -35,24 +44,57 @@ import it.danieleverducci.nextcloudmaps.utils.SettingsManager;
|
||||
public class GeofavoriteListFragment extends GeofavoritesFragment implements SortingOrderDialogFragment.OnSortingOrderListener {
|
||||
|
||||
private SwipeRefreshLayout swipeRefresh;
|
||||
private RecyclerView recyclerView;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private GeofavoriteAdapter geofavoriteAdapter;
|
||||
private GeofavoriteAdapter.ItemClickListener rvItemClickListener;
|
||||
private Toolbar toolbar;
|
||||
private MaterialCardView homeToolbar;
|
||||
private SearchView searchView;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
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
|
||||
int sortRule = SettingsManager.getGeofavoriteListSortBy(requireContext());
|
||||
|
||||
recyclerView = v.findViewById(R.id.recycler_view);
|
||||
layoutManager = new LinearLayoutManager(requireContext());
|
||||
RecyclerView recyclerView = v.findViewById(R.id.recycler_view);
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(requireContext());
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
rvItemClickListener = new GeofavoriteAdapter.ItemClickListener() {
|
||||
GeofavoriteAdapter.ItemClickListener rvItemClickListener = new GeofavoriteAdapter.ItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(Geofavorite item) {
|
||||
openGeofavorite(item);
|
||||
@ -113,7 +155,6 @@ public class GeofavoriteListFragment extends GeofavoritesFragment implements Sor
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
// Set icons
|
||||
// Setup list
|
||||
int sortRule = SettingsManager.getGeofavoriteListSortBy(requireContext());
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user