WIP adding geofavorite map fragment

This commit is contained in:
Daniele Verducci (Slimpenguin) 2024-02-19 18:31:39 +01:00
parent e1b1adf9ad
commit e1747b73f3
5 changed files with 103 additions and 10 deletions

View File

@ -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<NavigationItem> navItems = new ArrayList<>();

View File

@ -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;
}

View File

@ -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) {
}
}

View File

@ -15,7 +15,6 @@
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"

View File

@ -0,0 +1,47 @@
<?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:id="@+id/activity_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.osmdroid.views.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
android:orientation="vertical">
<include layout="@layout/app_toolbar"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/view_mode_list"
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_list" />
</RelativeLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
</FrameLayout>