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 #37

Merged
merged 12 commits into from
Dec 16, 2021
25 changes: 22 additions & 3 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 @@ -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 {

Expand All @@ -31,6 +39,7 @@ public class MapActivity extends AppCompatActivity {

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

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -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<Sight> sights) {
Log.d("TAG", "Sights updated: " + sights.toString());
}
Expand All @@ -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
Expand Down Expand Up @@ -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");
}
}
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,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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -119,6 +114,7 @@ private void openSelectedRoute(){
intent.putExtra("SelectedRoute",selectedRoute);

startActivity(intent);

dismiss();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
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