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

Añadido listado de tours pantalla principal #61

Merged
merged 1 commit into from
Jul 24, 2019
Merged
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
50 changes: 25 additions & 25 deletions app/sampledata/places.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"comment": "Places",
"data": [
{
"name": "Lugar 1",
"description": "Descripción del sitio 1 del tour 1.Es un sitio fantabuloso",
"visits": "2.456",
"distance": "563m",
"completeness": "Place 2/3",
"question": "Pregunta corta?",
"answer1": "Respuesta corta",
"answer2": "Respuesta un poco más larga",
"answer3": "Respuesta extremadamente larga que podría joderte todo el diseño"
},
{
"name": "Lugar 2",
"description": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec.",
"visits": "2.456",
"distance": "563m",
"completeness": "Place 2/3",
"question": "Esta sería una pregunta larga en la que el diseño se te puede ir a la mierda? Es muy importante tener esto en cuenta",
"answer1": "Respuesta corta",
"answer2": "Respuesta un poco más larga",
"answer3": "Respuesta extremadamente larga que podría joderte todo el diseño"
}
]
"comment" : "Places",
"data" : [
{
"name" : "Lugar 1",
"description" : "Descripción del sitio 1 del tour 1.Es un sitio fantabuloso",
"visits" : "2.456",
"distance" : "563m",
"completeness" : "Place 2/3",
"question" : "Pregunta corta?",
"answer1" : "Respuesta corta",
"answer2" : "Respuesta un poco más larga",
"answer3" : "Respuesta extremadamente larga que podría joderte todo el diseño"
},
{
"name" : "Lugar 2",
"description" : "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec.",
"visits" : "2.456",
"distance" : "563m",
"completeness" : "Place 2/3",
"question" : "Esta sería una pregunta larga en la que el diseño se te puede ir a la mierda? Es muy importante tener esto en cuenta",
"answer1" : "Respuesta corta",
"answer2" : "Respuesta un poco más larga",
"answer3" : "Respuesta extremadamente larga que podría joderte todo el diseño"
}
]
}
86 changes: 43 additions & 43 deletions app/sampledata/tours.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
{
"comment": "Tours",
"data": [
{
"name": "Tour 1",
"description": "Descripcion 1",
"creator": "Creador 1",
"progress": "50",
"progress_text": "15/30",
"num_places": "30 localizaciones"
},
{
"name": "Tour 2",
"description": "Descripcion 2",
"creator": "Creador 2",
"progress": "50",
"progress_text": "15/30",
"num_places": "30 localizaciones"
},
{
"name": "Tour 3",
"description": "Descripcion 3",
"creator": "Creador 3",
"progress": "50",
"progress_text": "15/30",
"num_places": "30 localizaciones"
},
{
"name": "Tour 4",
"description": "Descripcion 4",
"creator": "Creador 4",
"progress": "50",
"progress_text": "15/30",
"num_places": "30 localizaciones"
},
{
"name": "Tour 5",
"description": "Descripcion 5",
"creator": "Creador 5",
"progress": "50",
"progress_text": "15/30",
"num_places": "30 localizaciones"
}
]
"comment" : "Tours",
"data" : [
{
"name" : "Tour 1",
"description" : "Descripcion 1",
"creator" : "Creador 1",
"progress" : "50",
"progress_text" : "15/30",
"num_places" : "30 localizaciones"
},
{
"name" : "Tour 2",
"description" : "Descripcion 2",
"creator" : "Creador 2",
"progress" : "50",
"progress_text" : "1/4",
"num_places" : "30 localizaciones"
},
{
"name" : "Tour 3",
"description" : "Descripcion 3",
"creator" : "Creador 3",
"progress" : "50",
"progress_text" : "15/30",
"num_places" : "30 localizaciones"
},
{
"name" : "Tour 4",
"description" : "Descripcion 4",
"creator" : "Creador 4",
"progress" : "50",
"progress_text" : "15/30",
"num_places" : "30 localizaciones"
},
{
"name" : "Tour 5",
"description" : "Descripcion 5",
"creator" : "Creador 5",
"progress" : "50",
"progress_text" : "15/30",
"num_places" : "30 localizaciones"
}
]
}
12 changes: 6 additions & 6 deletions app/sampledata/user.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"comment": "Usuario loggeado",
"data": {
"name": "Martin Laiz Gomez",
"username": "martinlaizg",
"email": "martinlaizg@gmail.com"
}
"comment" : "Usuario loggeado",
"data" : {
"name" : "Martin Laiz Gomez",
"username" : "martinlaizg",
"email" : "martinlaizg@gmail.com"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import com.martinlaizg.geofind.data.access.database.entities.Play;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import retrofit2.Response;

Expand Down Expand Up @@ -115,4 +117,8 @@ public Play createPlacePlay(Integer play_id, Integer place_id) throws APIExcepti
}
throw apiException;
}

public List<Play> getUserPlays(int user_id) throws APIException {
return new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ public interface PlayDAO {

@Query("SELECT * from plays WHERE id = :play_id")
Play getPlay(Integer play_id);

@Query("SELECT * FROM plays WHERE user_id = :user_id")
List<Play> getUserPlays(int user_id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import com.martinlaizg.geofind.data.access.database.entities.Place;
import com.martinlaizg.geofind.data.access.database.entities.PlacePlay;

import java.util.List;

@Dao
public interface PlacePlayDAO {

@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(PlacePlay placePlay);

@Query("SELECT p.* FROM places p INNER JOIN place_play pp ON p.id = pp.place_id WHERE pp.play_id = :play_id")
List<Place> getPlayPlace(Integer play_id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,6 @@ public void setUpdated_at(Date updated_at) {
this.updated_at = updated_at;
}

public Tour getTour() {
return tour;
}

public void setTour(Tour tour) {
this.tour_id = tour.getId();
this.tour = tour;
}

public User getUser() {
return user;
}
Expand All @@ -116,14 +107,6 @@ public void setUser(User user) {
this.user = user;
}

public List<Place> getPlaces() {
return places;
}

public void setPlaces(List<Place> places) {
this.places = places;
}

public boolean isOutOfDate() {
return DateUtils.isDateExpire(updated);
}
Expand All @@ -138,4 +121,25 @@ public void setUpdated(Date updated) {
}
this.updated = updated;
}

public boolean isCompleted() {
return getPlaces().size() == getTour().getPlaces().size();
}

public List<Place> getPlaces() {
return places;
}

public Tour getTour() {
return tour;
}

public void setTour(Tour tour) {
this.tour_id = tour.getId();
this.tour = tour;
}

public void setPlaces(List<Place> places) {
this.places = places;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.martinlaizg.geofind.data.access.database.entities.PlacePlay;
import com.martinlaizg.geofind.data.access.database.entities.Play;

import java.util.List;

public class PlayRepository {

private static final String TAG = PlayRepository.class.getSimpleName();
Expand Down Expand Up @@ -146,4 +148,47 @@ public Play createPlay(int user_id, int tour_id) throws APIException {
return p;
}

/**
* Get the list of plays of users
*
* @param user_id
* the id of the user to get plays
* @return the list of plays
*/
public List<Play> getUserPlays(int user_id) throws APIException {
List<Play> plays = playDAO.getUserPlays(user_id);
if(plays.isEmpty()) {
plays.addAll(playService.getUserPlays(user_id));
for(Play p : plays) {
userRepo.insert(p.getUser());
tourRepo.insert(p.getTour());
userRepo.insert(p.getTour().getCreator());
playDAO.insert(p);
}
} else {
for(int i = 0; i < plays.size(); i++) {
if(plays.get(i).isOutOfDate()) {
plays.remove(i);
i--;
}
plays.get(i).setTour(tourRepo.getTour(plays.get(i).getTour_id()));
plays.get(i).setPlaces(placePlayDAO.getPlayPlace(plays.get(i).getId()));
}
}
refreshUserPlays(user_id);
return plays;
}

private void refreshUserPlays(int user_id) {
new Thread(() -> {
try {
List<Play> plays = playService.getUserPlays(user_id);
for(Play p : plays) {
insert(p);
}
} catch(APIException e) {
Log.e(TAG, "refreshUserPlays: ", e);
}
}).start();
}
}
Loading