Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sight popup branch #36

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions app/src/main/java/nl/ags/picum/UI/MapActivity.java
Original file line number Diff line number Diff line change
@@ -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;


Expand All @@ -16,16 +18,25 @@
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.gestures.RotationGestureOverlay;

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.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;

public class MapActivity extends AppCompatActivity {

private MapViewModel mapViewModel;
private MapView mMap;
private IMapController mMapController;
private List<Sight> sights;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -37,16 +48,21 @@ protected void onCreate(Bundle savedInstanceState) {
initializeMap();

Route selectedRoute = (Route)getIntent().getSerializableExtra("SelectedRoute");
mapViewModel = new ViewModelProvider(this).get(MapViewModel.class);

mapViewModel.setCurrentRoute(selectedRoute);
new Thread(() -> {getSights();}).start();


Log.d("pizzaparty", "onCreate: " + mapViewModel.getcurrentRoute());
MapManager m = new MapManager(this);
m.setMapViewModel(mapViewModel);
m.startGPSUpdates();
}

public void getSights(){
AppDatabaseManager dbManager = new AppDatabaseManager(this);
sights = dbManager.getSightsPerRoute(mapViewModel.getcurrentRoute());
}

public void onStartRouteButtonClick(View view){
((Button)view).setVisibility(View.INVISIBLE);
//TODO add function to start route
Expand Down Expand Up @@ -89,4 +105,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");
}
}
78 changes: 78 additions & 0 deletions app/src/main/java/nl/ags/picum/UI/Util/SightAdapter.java
Original file line number Diff line number Diff line change
@@ -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<SightAdapter.SightViewHolder> {
private List<Sight> sights;
private MapActivity context;
public SightAdapter(List<Sight> 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) {

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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 nl.ags.picum.R;

public class LargeImageFragment extends DialogFragment {

private Drawable drawable;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

public LargeImageFragment(Drawable drawable){
this.drawable = drawable;
}

@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);
}
view.findViewById(R.id.large_image_image).setBackgroundDrawable(drawable);
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
}

private void setTextAndButtons(View view){
((TextView)view.findViewById(R.id.route_details_fragment_details_description)).setText(selectedRoute.getDescription());
((TextView)view.findViewById(R.id.route_details_fragment_details_descriptionText)).setText(selectedRoute.getDescription());
((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());

Expand Down Expand Up @@ -108,13 +108,12 @@ public void onClick(View view) {
}

private void openSelectedRoute(){
MapViewModel mapViewModel = new ViewModelProvider(requireActivity()).get(MapViewModel.class);
mapViewModel.setCurrentRoute(selectedRoute);
Intent intent = new Intent(getContext(), MapActivity.class);

intent.putExtra("SelectedRoute",selectedRoute);

startActivity(intent);

dismiss();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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("."));
Drawable drawable = context.getDrawable(context.getResources().getIdentifier(photoUrl, null, context.getPackageName()));
ImageView image = (ImageView)getView().findViewById(R.id.sight_details_image);
image.setImageDrawable(drawable);
image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new LargeImageFragment(drawable).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);
}
}
Original file line number Diff line number Diff line change
@@ -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<Sight> sightList;
private MapActivity mapActivity;

public SightsListFragment(List<Sight> 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);
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_baseline_checklist_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M22,7h-9v2h9V7zM22,15h-9v2h9V15zM5.54,11L2,7.46l1.41,-1.41l2.12,2.12l4.24,-4.24l1.41,1.41L5.54,11zM5.54,19L2,15.46l1.41,-1.41l2.12,2.12l4.24,-4.24l1.41,1.41L5.54,19z"/>
</vector>
Loading