diff --git a/app/src/main/java/nl/ags/picum/UI/MapActivity.java b/app/src/main/java/nl/ags/picum/UI/MapActivity.java index 4fd6fc4..cdbf798 100644 --- a/app/src/main/java/nl/ags/picum/UI/MapActivity.java +++ b/app/src/main/java/nl/ags/picum/UI/MapActivity.java @@ -1,11 +1,13 @@ package nl.ags.picum.UI; +import android.content.Context; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.FragmentManager; import androidx.lifecycle.ViewModelProvider; @@ -19,10 +21,16 @@ import java.util.List; import nl.ags.picum.R; +import nl.ags.picum.UI.fragments.RouteDetailsFragment; +import nl.ags.picum.UI.fragments.SightDetailsPopupFragment; +import nl.ags.picum.UI.fragments.SightsListFragment; import nl.ags.picum.UI.viewmodels.MapViewModel; -import nl.ags.picum.UI.viewmodels.SightViewModel; +import nl.ags.picum.dataStorage.managing.AppDatabaseManager; +import nl.ags.picum.dataStorage.roomData.AppDatabase; import nl.ags.picum.dataStorage.roomData.Route; import nl.ags.picum.dataStorage.roomData.Sight; +import nl.ags.picum.mapManagement.MapManager; +import nl.ags.picum.UI.viewmodels.SightViewModel; public class MapActivity extends AppCompatActivity { @@ -31,6 +39,7 @@ public class MapActivity extends AppCompatActivity { private MapView mMap; private IMapController mMapController; + private List sights; @Override protected void onCreate(Bundle savedInstanceState) { @@ -50,12 +59,19 @@ protected void onCreate(Bundle savedInstanceState) { initializeMap(); Route selectedRoute = (Route)getIntent().getSerializableExtra("SelectedRoute"); - mapViewModel.setCurrentRoute(selectedRoute); + new Thread(() -> {getSights();}).start(); + Log.d("pizzaparty", "onCreate: " + mapViewModel.getCurrentRoute()); } + public void getSights(){ + AppDatabaseManager dbManager = new AppDatabaseManager(this); + sights = dbManager.getSightsPerRoute(mapViewModel.getCurrentRoute()); + } + + private void onSightsChanged(List sights) { Log.d("TAG", "Sights updated: " + sights.toString()); } @@ -64,7 +80,6 @@ private void onSightChanged(Sight sight) { Log.d("TAG", "Sight location triggered: " + sight); } - public void onStartRouteButtonClick(View view){ ((Button)view).setVisibility(View.INVISIBLE); //TODO add function to start route @@ -107,4 +122,8 @@ public void onPause() { //Configuration.getInstance().save(this, prefs); mMap.onPause(); //needed for compass, my location overlays, v6.0.0 and up } + + public void onFABClicked(View view){ + new SightsListFragment(sights, this).show(getSupportFragmentManager(), "list"); + } } \ No newline at end of file diff --git a/app/src/main/java/nl/ags/picum/UI/Util/SightAdapter.java b/app/src/main/java/nl/ags/picum/UI/Util/SightAdapter.java new file mode 100644 index 0000000..2701c74 --- /dev/null +++ b/app/src/main/java/nl/ags/picum/UI/Util/SightAdapter.java @@ -0,0 +1,78 @@ +package nl.ags.picum.UI.Util; + +import android.app.Activity; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.List; + +import nl.ags.picum.R; +import nl.ags.picum.UI.MapActivity; +import nl.ags.picum.UI.fragments.SightDetailsPopupFragment; +import nl.ags.picum.dataStorage.roomData.Sight; +import nl.ags.picum.mapManagement.MapManager; + +public class SightAdapter extends RecyclerView.Adapter { + private List sights; + private MapActivity context; + public SightAdapter(List sights, MapActivity context){ + this.sights = sights; + this.context = context; + } + + @NonNull + @Override + public SightAdapter.SightViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View viewItem = LayoutInflater.from(parent.getContext()).inflate(R.layout.sight_list_item, parent, false); + SightAdapter.SightViewHolder viewHolder = new SightAdapter.SightViewHolder(viewItem); + return viewHolder; + } + + @Override + public void onBindViewHolder(@NonNull SightViewHolder holder, int position) { + Sight sight = sights.get(position); + holder.title.setText(sight.getSightName()); + String url = "@" + sight.getPhotoURL().substring(0, sight.getPhotoURL().lastIndexOf(".")); + holder.image.setImageDrawable(context.getDrawable(context.getResources().getIdentifier(url, null, context.getPackageName()))); + holder.description.setText(sight.getSightDescription().substring(0, sight.getSightDescription().indexOf(".", 100) + 1)); + holder.layout.setOnClickListener(new View.OnClickListener(){ + @Override + public void onClick(View view){ + new SightDetailsPopupFragment(sight, context).show(context.getSupportFragmentManager(), null); + } + }); + //TODO add visual indication that sight has been visited + } + + @Override + public int getItemCount() { + return sights.size(); + } + + class SightViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ + TextView title; + TextView description; + ImageView image; + ConstraintLayout layout; + public SightViewHolder(@NonNull View itemView) { + super(itemView); + title = itemView.findViewById(R.id.sight_list_item_name); + description = itemView.findViewById(R.id.sight_list_item_description); + image = itemView.findViewById(R.id.sight_list_item_image); + layout = itemView.findViewById(R.id.sight_list_item_layout); + } + + @Override + public void onClick(View view) { + + } + } +} diff --git a/app/src/main/java/nl/ags/picum/UI/fragments/LargeImageFragment.java b/app/src/main/java/nl/ags/picum/UI/fragments/LargeImageFragment.java new file mode 100644 index 0000000..2395185 --- /dev/null +++ b/app/src/main/java/nl/ags/picum/UI/fragments/LargeImageFragment.java @@ -0,0 +1,55 @@ +package nl.ags.picum.UI.fragments; + +import android.app.Dialog; +import android.graphics.drawable.Drawable; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; + +import nl.ags.picum.R; + +public class LargeImageFragment extends DialogFragment { + + private int resource; + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + public LargeImageFragment(int resource){ + this.resource = resource; + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + Dialog dialog = getDialog(); + if(dialog != null){ + int width = ViewGroup.LayoutParams.MATCH_PARENT; + int height = ViewGroup.LayoutParams.MATCH_PARENT; + dialog.getWindow().setLayout(width, height); + } + ((ImageView)view.findViewById(R.id.large_image_image)).setImageResource(resource); + view.findViewById(R.id.large_image_image).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + } + }); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_large_image, container, false); + } +} \ No newline at end of file diff --git a/app/src/main/java/nl/ags/picum/UI/fragments/RouteDetailsFragment.java b/app/src/main/java/nl/ags/picum/UI/fragments/RouteDetailsFragment.java index b6fa9c1..9e11a68 100644 --- a/app/src/main/java/nl/ags/picum/UI/fragments/RouteDetailsFragment.java +++ b/app/src/main/java/nl/ags/picum/UI/fragments/RouteDetailsFragment.java @@ -59,14 +59,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat } private void setTextAndButtons(View view){ + AppDatabaseManager manager = new AppDatabaseManager(getContext()); - try { ((TextView)view.findViewById(R.id.route_details_fragment_details_description)).setText(getString(R.string.class.getDeclaredField(selectedRoute.getDescription()).getInt(null))); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - } ((TextView)view.findViewById(R.id.route_details_fragment_details_name)).setText(selectedRoute.getRouteName()); ((Button)view.findViewById(R.id.route_details_fragment_details_backButton)).setOnClickListener(v -> dismiss()); @@ -119,6 +114,7 @@ private void openSelectedRoute(){ intent.putExtra("SelectedRoute",selectedRoute); startActivity(intent); + dismiss(); } diff --git a/app/src/main/java/nl/ags/picum/UI/fragments/SightDetailsPopupFragment.java b/app/src/main/java/nl/ags/picum/UI/fragments/SightDetailsPopupFragment.java new file mode 100644 index 0000000..3b045d9 --- /dev/null +++ b/app/src/main/java/nl/ags/picum/UI/fragments/SightDetailsPopupFragment.java @@ -0,0 +1,74 @@ +package nl.ags.picum.UI.fragments; + +import android.app.Dialog; +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.content.res.AppCompatResources; +import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.Fragment; + +import android.text.method.ScrollingMovementMethod; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import nl.ags.picum.R; +import nl.ags.picum.dataStorage.roomData.Sight; + +public class SightDetailsPopupFragment extends DialogFragment { + + private Sight sight; + private Context context; + public SightDetailsPopupFragment(Sight sight, Context context){ + this.sight = sight; + this.context = context; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + Dialog dialog = getDialog(); + if(dialog != null){ + int width = ViewGroup.LayoutParams.MATCH_PARENT; + int height = ViewGroup.LayoutParams.MATCH_PARENT; + dialog.getWindow().setLayout(width, height); + } + String photoUrl = "@" + sight.getPhotoURL().substring(0, sight.getPhotoURL().indexOf(".")); + ImageView image = (ImageView)getView().findViewById(R.id.sight_details_image); + image.setImageResource(context.getResources().getIdentifier(photoUrl, null, context.getPackageName())); + image.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + new LargeImageFragment(context.getResources().getIdentifier(photoUrl, null, context.getPackageName())).show(getParentFragmentManager(), "image"); + } + }); + ((TextView)getView().findViewById(R.id.sight_details_title)).setText(sight.getSightName()); + ((TextView)getView().findViewById(R.id.sight_details_detailsText)).setText(sight.getSightDescription()); + ((TextView)getView().findViewById(R.id.sight_details_detailsText)).setMovementMethod(new ScrollingMovementMethod()); + if(sight.getWebsiteURL().equals("") || sight.getWebsiteURL() == null){ + ((TextView)getView().findViewById(R.id.sight_details_siteRef)).setText(""); + } else { + ((TextView)getView().findViewById(R.id.sight_details_siteRef)).setText(sight.getWebsiteURL()); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_sight_details_popup, container, false); + } +} \ No newline at end of file diff --git a/app/src/main/java/nl/ags/picum/UI/fragments/SightsListFragment.java b/app/src/main/java/nl/ags/picum/UI/fragments/SightsListFragment.java new file mode 100644 index 0000000..41c95a5 --- /dev/null +++ b/app/src/main/java/nl/ags/picum/UI/fragments/SightsListFragment.java @@ -0,0 +1,62 @@ +package nl.ags.picum.UI.fragments; + +import android.app.Dialog; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.List; + +import nl.ags.picum.R; +import nl.ags.picum.UI.MapActivity; +import nl.ags.picum.UI.Util.SightAdapter; +import nl.ags.picum.dataStorage.roomData.Sight; + +public class SightsListFragment extends DialogFragment { + + + public List sightList; + private MapActivity mapActivity; + + public SightsListFragment(List sightList, MapActivity activity){ + this.sightList = sightList; + this.mapActivity = activity; + } + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + Dialog dialog = getDialog(); + if(dialog != null){ + int width = ViewGroup.LayoutParams.MATCH_PARENT; + int height = ViewGroup.LayoutParams.MATCH_PARENT; + dialog.getWindow().setLayout(width, height); + } + RecyclerView recyclerView = view.findViewById(R.id.sight_recyclerview); + recyclerView.setAdapter(new SightAdapter(sightList, mapActivity)); + recyclerView.setLayoutManager(new LinearLayoutManager(mapActivity, RecyclerView.VERTICAL, false)); + recyclerView.addItemDecoration(new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL)); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_sights_list, container, false); + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_baseline_checklist_24.xml b/app/src/main/res/drawable/ic_baseline_checklist_24.xml new file mode 100644 index 0000000..3862cb3 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_checklist_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/activity_map.xml b/app/src/main/res/layout/activity_map.xml index 68dce37..a91e954 100644 --- a/app/src/main/res/layout/activity_map.xml +++ b/app/src/main/res/layout/activity_map.xml @@ -20,8 +20,21 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" + app:layout_constraintHorizontal_bias="0.7" android:layout_marginBottom="20dp" android:onClick="onStartRouteButtonClick" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_large_image.xml b/app/src/main/res/layout/fragment_large_image.xml new file mode 100644 index 0000000..9b656fb --- /dev/null +++ b/app/src/main/res/layout/fragment_large_image.xml @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_route_details.xml b/app/src/main/res/layout/fragment_route_details.xml index f0e2820..52c0894 100644 --- a/app/src/main/res/layout/fragment_route_details.xml +++ b/app/src/main/res/layout/fragment_route_details.xml @@ -46,12 +46,15 @@ + app:layout_constraintTop_toBottomOf="@id/route_details_fragment_details_description" + app:layout_constraintRight_toRightOf="parent" + android:layout_marginRight="20dp" + /> -