diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java index 94a1c59..a77c863 100644 --- a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java @@ -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) diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteListFragment.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteListFragment.java index 2ed4480..423142a 100644 --- a/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteListFragment.java +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteListFragment.java @@ -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); + } + } diff --git a/app/src/main/res/drawable/ic_view_map.xml b/app/src/main/res/drawable/ic_view_map.xml new file mode 100644 index 0000000..ffd9dd9 --- /dev/null +++ b/app/src/main/res/drawable/ic_view_map.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_view_module.xml b/app/src/main/res/drawable/ic_view_module.xml deleted file mode 100644 index 0a8190e..0000000 --- a/app/src/main/res/drawable/ic_view_module.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - diff --git a/app/src/main/res/layout/activity_list_view.xml b/app/src/main/res/layout/activity_list_view.xml index 94451c0..834408f 100644 --- a/app/src/main/res/layout/activity_list_view.xml +++ b/app/src/main/res/layout/activity_list_view.xml @@ -15,98 +15,13 @@ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see . --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/app_toolbar.xml b/app/src/main/res/layout/app_toolbar.xml new file mode 100644 index 0000000..c0ac27f --- /dev/null +++ b/app/src/main/res/layout/app_toolbar.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_geofavorite_list.xml b/app/src/main/res/layout/fragment_geofavorite_list.xml index 7132cac..17b31c7 100644 --- a/app/src/main/res/layout/fragment_geofavorite_list.xml +++ b/app/src/main/res/layout/fragment_geofavorite_list.xml @@ -1,40 +1,89 @@ - + android:layout_height="match_parent"> - + + + + + + + + + + + + + + + + + + + app:layout_behavior="@string/appbar_scrolling_view_behavior"> - - - - + android:layout_height="match_parent"> - + + - \ No newline at end of file + + + + + \ No newline at end of file