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 a77c863..5bbc995 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 @@ -56,6 +56,7 @@ import it.danieleverducci.nextcloudmaps.activity.main.SortingOrderDialogFragment import it.danieleverducci.nextcloudmaps.activity.mappicker.MapPickerActivity; import it.danieleverducci.nextcloudmaps.api.ApiProvider; import it.danieleverducci.nextcloudmaps.fragments.GeofavoriteListFragment; +import it.danieleverducci.nextcloudmaps.fragments.GeofavoriteMapFragment; import it.danieleverducci.nextcloudmaps.fragments.GeofavoritesFragment; import it.danieleverducci.nextcloudmaps.model.Geofavorite; import it.danieleverducci.nextcloudmaps.utils.SettingsManager; @@ -87,6 +88,14 @@ public class MainActivity extends NextcloudMapsStyledActivity { drawerLayout.openDrawer(GravityCompat.START); } + public void showMap() { + replaceFragment(new GeofavoriteMapFragment()); + } + + public void showList() { + replaceFragment(new GeofavoriteListFragment()); + } + @Override protected void onCreate(Bundle savedInstanceState) { @@ -94,15 +103,10 @@ public class MainActivity extends NextcloudMapsStyledActivity { setContentView(R.layout.activity_main); boolean showMap = SettingsManager.isGeofavoriteListShownAsMap(this); - if (showMap) { - // TODO: Map fragment - } else { - Fragment fragment = new GeofavoriteListFragment(); - FragmentManager manager = getSupportFragmentManager(); - FragmentTransaction transaction = manager.beginTransaction(); - transaction.replace(R.id.fragment_container, fragment); - transaction.commit(); - } + if (showMap) + showMap(); + else + showList(); FloatingActionButton fab = findViewById(R.id.open_fab); fab.setOnClickListener(view -> openFab(!this.isFabOpen)); @@ -124,6 +128,13 @@ public class MainActivity extends NextcloudMapsStyledActivity { super.onPause(); } + private void replaceFragment(Fragment fragment) { + FragmentManager manager = getSupportFragmentManager(); + FragmentTransaction transaction = manager.beginTransaction(); + transaction.replace(R.id.fragment_container, fragment); + transaction.commit(); + } + private void setupNavigationMenu() { ArrayList navItems = new ArrayList<>(); 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 423142a..c91cd33 100644 --- a/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteListFragment.java +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteListFragment.java @@ -147,6 +147,9 @@ public class GeofavoriteListFragment extends GeofavoritesFragment implements Sor AppCompatImageView sortButton = v.findViewById(R.id.sort_mode); sortButton.setOnClickListener(view -> openSortingOrderDialogFragment(geofavoriteAdapter.getSortRule())); + View showMapButton = v.findViewById(R.id.view_mode_map); + showMapButton.setOnClickListener(View -> ((MainActivity)requireActivity()).showMap()); + return v; } diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteMapFragment.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteMapFragment.java new file mode 100644 index 0000000..2128f8c --- /dev/null +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteMapFragment.java @@ -0,0 +1,33 @@ +package it.danieleverducci.nextcloudmaps.fragments; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import it.danieleverducci.nextcloudmaps.R; +import it.danieleverducci.nextcloudmaps.activity.main.MainActivity; + +public class GeofavoriteMapFragment extends GeofavoritesFragment { + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View v = inflater.inflate(R.layout.fragment_geofavorite_map, container, false); + + + // Setup view listeners + View showListButton = v.findViewById(R.id.view_mode_list); + showListButton.setOnClickListener(View -> ((MainActivity)requireActivity()).showMap()); + + return v; + } + + @Override + public void onSearch(String query) { + + } +} diff --git a/app/src/main/res/layout/fragment_geofavorite_list.xml b/app/src/main/res/layout/fragment_geofavorite_list.xml index 17b31c7..7500a3b 100644 --- a/app/src/main/res/layout/fragment_geofavorite_list.xml +++ b/app/src/main/res/layout/fragment_geofavorite_list.xml @@ -15,7 +15,6 @@ app:elevation="0dp"> + + + + + + + + + + + + + + + + + + \ No newline at end of file