Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlaizg committed May 7, 2019
1 parent bbd2e17 commit 78eb198
Show file tree
Hide file tree
Showing 32 changed files with 380 additions and 193 deletions.
25 changes: 21 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,32 @@ dependencies {
implementation 'androidx.navigation:navigation-ui:2.0.0'
implementation 'androidx.preference:preference:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.room:room-coroutines:2.1.0-alpha04'
implementation 'androidx.room:room-runtime:2.1.0-alpha07'
implementation 'androidx.room:room-rxjava2:2.1.0-alpha07'
annotationProcessor 'androidx.room:room-compiler:2.1.0-alpha07'
implementation 'androidx.viewpager:viewpager:1.0.0'
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.0.0'
annotationProcessor 'androidx.room:room-compiler:2.1.0-alpha07'
testImplementation 'androidx.room:room-testing:2.1.0-alpha07'
testImplementation 'androidx.arch.core:core-testing:2.0.1'

// Core library
androidTestImplementation 'androidx.test:core:1.1.0'

// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'

// Assertions
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.ext:truth:1.1.0'
androidTestImplementation 'com.google.truth:truth:0.42'

// Espresso dependencies
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.1.1'
androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.1.1'

androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

// Android Material Design
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

public class RetrofitInstance {

private static final String BASE_URL = "https://geofind1.herokuapp.com/api/";
// private static final String BASE_URL = "http://192.168.1.34:8000/api/";
// private static final String BASE_URL = "https://geofind1.herokuapp.com/api/";
private static final String BASE_URL = "http://192.168.1.34:8000/api/";
private static Retrofit retrofitInstance;

public static RestClient getRestClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.martinlaizg.geofind.data.access.database.entities.User;

@Database(entities = {User.class, Tour.class, Place.class, Play.class, PlacePlay.class},
version = 1, exportSchema = false)
version = 5, exportSchema = false)
@TypeConverters(
{DateTypeConverter.class, PlayLevelTypeConverter.class, UserTypeTypeConverter.class})
public abstract class AppDatabase
Expand All @@ -34,7 +34,7 @@ public abstract class AppDatabase
public static synchronized AppDatabase getInstance(Context context) {
if(instance == null) {
instance = Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class,
"geo_find_database").
"geo_find_database.db").
fallbackToDestructiveMigration().
build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ public interface PlaceDAO {
@Update
void update(Place place);

@Query("SELECT * FROM places WHERE tour_id = :place_id")
Place getPlace(Integer place_id);

@Query("SELECT * FROM places WHERE tour_id = :tour_id ORDER BY `order`")
List<Place> getPlacesByTour(Integer tour_id);

@Query("DELETE FROM places WHERE tour_id = :tour_id")
void removeTourPlaces(Integer tour_id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@

import com.martinlaizg.geofind.data.access.database.entities.User;

import java.util.List;

@Dao
public interface UserDAO {

@Insert(onConflict = OnConflictStrategy.REPLACE)
@Insert(onConflict = OnConflictStrategy.IGNORE)
void insert(User user);

@Update
void update(User user);

@Query("SELECT * FROM users WHERE id = :user_id")
User getUser(int user_id);

@Query("SELECT * FROM users")
List<User> getAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class Place {

@PrimaryKey
private final Integer id;
private final int id;
private String name;
private Double lat;
private Double lon;
Expand Down Expand Up @@ -48,7 +48,7 @@ public Place() {
id = 0;
}

public Integer getId() {
public int getId() {
return id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import com.martinlaizg.geofind.utils.DateUtils;

import org.jetbrains.annotations.NotNull;

import java.sql.Date;
import java.util.Calendar;

Expand All @@ -31,28 +29,28 @@ public class PlacePlay {
private Date updated_at;
private Date updated;

public PlacePlay(@NotNull Integer place_id, @NotNull Integer play_id) {
public PlacePlay(@NonNull Integer place_id, @NonNull Integer play_id) {
this.play_id = play_id;
this.place_id = place_id;
this.created_at = new Date(Calendar.getInstance().getTime().getTime());
this.updated_at = new Date(Calendar.getInstance().getTime().getTime());
}

@NotNull
@NonNull
public Integer getPlay_id() {
return play_id;
}

public void setPlay_id(@NotNull Integer play_id) {
public void setPlay_id(@NonNull Integer play_id) {
this.play_id = play_id;
}

@NotNull
@NonNull
public Integer getPlace_id() {
return place_id;
}

public void setPlace_id(@NotNull Integer place_id) {
public void setPlace_id(@NonNull Integer place_id) {
this.place_id = place_id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import com.martinlaizg.geofind.utils.DateUtils;

import org.jetbrains.annotations.NotNull;

import java.sql.Date;
import java.util.Calendar;
import java.util.List;
Expand Down Expand Up @@ -63,7 +61,7 @@ public Play(int tour_id, int user_id) {
this.user_id = user_id;
}

@NotNull
@NonNull
public Integer getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.martinlaizg.geofind.data.access.database.entities;

import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Ignore;
Expand All @@ -9,23 +10,21 @@
import com.martinlaizg.geofind.data.enums.PlayLevel;
import com.martinlaizg.geofind.utils.DateUtils;

import org.jetbrains.annotations.NotNull;

import java.sql.Date;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import static androidx.room.ForeignKey.CASCADE;

@Entity(tableName = "tours",
foreignKeys = @ForeignKey(entity = User.class, childColumns = "creator_id",
parentColumns = "id", onDelete = CASCADE),
@Entity(tableName = "tours", foreignKeys = @ForeignKey(entity = User.class, parentColumns = "id",
childColumns = "creator_id",
onDelete = CASCADE),
indices = @Index("creator_id"))
public class Tour {

@PrimaryKey
private final Integer id;
private final int id;
private String name;
private String description;
private PlayLevel min_level;
Expand Down Expand Up @@ -59,8 +58,8 @@ public Tour() {
places = new ArrayList<>();
}

@NotNull
public Integer getId() {
@NonNull
public int getId() {
return id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,33 @@

import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.Index;
import androidx.room.PrimaryKey;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.martinlaizg.geofind.data.enums.UserType;
import com.martinlaizg.geofind.utils.DateUtils;

import org.jetbrains.annotations.NotNull;

import java.sql.Date;
import java.util.Calendar;
import java.util.List;

@Entity(tableName = "users")
@Entity(tableName = "users", indices = {@Index({"id"})})
public class User {

@PrimaryKey
private final Integer id;
private int id;
private String email;
@Ignore
private String password;
private String username;
private String name;
private UserType user_type;
private Date created_at;
private Date updated_at;
private Date updated;

@Ignore
private String password;
@Ignore
private List<Place> createdPlaces;

Expand All @@ -49,8 +48,7 @@ public User() {
id = 0;
}

@NotNull
public Integer getId() {
public int getId() {
return id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ public void insert(Place place) {
placeDAO.insert(place);
}

public void getPlaceOnStart(int userId) {
// TODO
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,8 @@ public Play completePlay(Integer play_id, Integer place_id) throws APIException
placePlayDAO.insert(pp);
return p;
}

public void getPlayOnStart(int userId) {
// TODO
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,41 @@ public TourRepository(Application application) {
userRepo = RepositoryFactory.getUserRepository(application);
}

public List<Tour> getAllTours() throws APIException {
// List<TourCreatorPlaces> mls = tourPlacesDAO.getTourCreatorPlaces();
List<Tour> ts = new ArrayList<>();
// for(TourCreatorPlaces ml : mls) {
// Tour t = ml.getTour();
// User u = new User();
// u.setUsername(ml.getUsername());
// t.setCreator(u);
// ts.add(t);
// }

if(ts.isEmpty()) {
ts = tourService.getAllTours();
if(ts != null) {
for(Tour t : ts) {
userRepo.insert(t.getCreator());
tourDAO.insert(t);
for(Place p : t.getPlaces()) {
placeRepo.insert(p);
}
public List<TourCreatorPlaces> getAllTours() throws APIException {
List<TourCreatorPlaces> mls = tourPlacesDAO.getTourCreatorPlaces();

if(mls != null) {
for(int i = 0; i < mls.size(); i++) {
if(mls.get(i).getTour().isOutOfDate()) {
mls.remove(i);
i--;
}
}
}

if(mls == null || mls.isEmpty()) {
mls = new ArrayList<>();
List<Tour> tours = tourService.getAllTours();
if(tours != null) {
for(Tour t : tours) {
insert(t);
TourCreatorPlaces tcp = new TourCreatorPlaces();
tcp.setTour(t);
tcp.setUsername(t.getCreator().getUsername());
tcp.setPlaces(t.getPlaces());
mls.add(tcp);
}
}
}
// }
return ts;
return mls;
}

public void insert(Tour t) {
if(t != null) {
userRepo.insert(t.getCreator());
tourDAO.insert(t);
placeRepo.insert(t.getPlaces());
}
}

public Tour getTour(Integer id) throws APIException {
Expand Down Expand Up @@ -91,7 +101,7 @@ public Tour update(Tour tour) throws APIException {
return tour;
}

public void insert(Tour tour) {
tourDAO.insert(tour);
public void getToursOnStart(int userId) {
// TODO
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.martinlaizg.geofind.data.access.database.dao.UserDAO;
import com.martinlaizg.geofind.data.access.database.entities.User;

import java.util.List;

public class UserRepository {

private final UserDAO userDAO;
Expand Down Expand Up @@ -36,7 +38,10 @@ public User registry(User u) throws APIException {
}

public void insert(User user) {
userDAO.insert(user);
if(user != null) {
List<User> users = userDAO.getAll();
userDAO.insert(user);
}
}

public User getUser(int user_id) {
Expand Down
Loading

0 comments on commit 78eb198

Please sign in to comment.