Skip to content

Commit

Permalink
Multiples cambios
Browse files Browse the repository at this point in the history
Actualizadas versiones de dependencias
Añadido manejo de falta de imágenes
Arreglada falta de comprobación de GPS al seleccionar la localización
Cambiado orden de creación de un tour #39
Añadido selector de sitio en fragment independiente #71
Code clean up
  • Loading branch information
martinlaizg committed Aug 13, 2019
1 parent 49e3b74 commit 48bc7c1
Show file tree
Hide file tree
Showing 34 changed files with 202 additions and 230 deletions.
82 changes: 27 additions & 55 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ android {
storeFile file('../android-studio-settings/debug.jks')
}
}
compileSdkVersion 28
compileSdkVersion 29
defaultConfig {
applicationId 'com.martinlaizg.geofind'
minSdkVersion 26
targetSdkVersion 28
targetSdkVersion 29
versionCode 8
versionName 'v0.4-SNAPSHOT'
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
Expand Down Expand Up @@ -44,79 +44,51 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

//
// AndroidX
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.activity:activity:1.1.0-alpha02'
testImplementation 'androidx.arch.core:core-testing:2.0.1'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.viewpager:viewpager:1.0.0'
// Lifecycle
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.lifecycle:lifecycle-livedata:2.0.0'
implementation 'androidx.lifecycle:lifecycle-reactivestreams:2.0.0'
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.0.0'
// Navigation
implementation 'androidx.navigation:navigation-common:2.1.0-beta02'
implementation 'androidx.navigation:navigation-fragment:2.1.0-beta02'
implementation 'androidx.navigation:navigation-ui:2.1.0-beta02'
implementation 'androidx.preference:preference:1.0.0'
// Room
implementation 'androidx.navigation:navigation-common:2.1.0-rc01'
implementation 'androidx.navigation:navigation-fragment:2.1.0-rc01'
implementation 'androidx.navigation:navigation-ui:2.1.0-rc01'
implementation 'androidx.preference:preference:1.1.0-rc01'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.room:room-runtime:2.1.0'
annotationProcessor 'androidx.room:room-compiler:2.1.0'
implementation 'androidx.viewpager:viewpager:1.0.0'

//
// Google services
// Auth
implementation 'com.google.android.gms:play-services-auth:17.0.0'
// Maps
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'

//
// Google Material
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha09'

// Android Test
androidTestImplementation 'androidx.test:core:1.2.0'
implementation 'com.jakewharton:butterknife:10.1.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.0'

// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
testImplementation 'androidx.arch.core:core-testing:2.0.1'
testImplementation 'androidx.test:core:1.2.0'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.19.0'

// Assertions
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.ext:truth:1.2.0'
androidTestImplementation 'com.google.truth:truth:0.45'
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.0.0'
annotationProcessor 'androidx.room:room-compiler:2.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'

//
// Android Espresso
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.2.0'
androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.2.0'

//
// RetrofitService
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'

//
// Butter Knife
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'

// Picasso
implementation 'com.squareup.picasso:picasso:2.5.2'

// Testing
testImplementation 'junit:junit:4.12'
testImplementation 'androidx.test:core:1.2.0'
testImplementation 'org.mockito:mockito-core:2.19.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.ext:truth:1.2.0'
androidTestImplementation 'com.google.truth:truth:0.45'
}
10 changes: 10 additions & 0 deletions app/sampledata/plays.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"comment" : "Plays",
"data" : [
{
"name" : "Lugar 1",
"description" : "Descripción del lugar 1",
"num_plays" : 5
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public interface RestClient {

/**
* Get the entier list of {@link Tour}
* Get the entire list of {@link Tour}
*
* @param params
* the params to get tours
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class PlayService {
private static final String TAG = PlayService.class.getSimpleName();
private static PlayService instance;

private RestClient restClient;
private final RestClient restClient;

private PlayService(Application application) {
restClient = RetrofitInstance.getRestClient(application);
Expand Down Expand Up @@ -113,7 +113,7 @@ public Play createPlacePlay(Integer play_id, Integer place_id) throws APIExcepti
throw apiException;
}

public List<Play> getUserPlays(int user_id) throws APIException {
public List<Play> getUserPlays() {
return new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public User login(Login login) throws APIException {
*
* @param login
* the login data
* @return the registred user
* @return the registered user
* @throws APIException
* exception from server
*/
Expand Down Expand Up @@ -116,7 +116,7 @@ public void sendMessage(String title, String message) throws APIException {
}

/**
* Upadte user data
* Update user data
*
* @param login
* the login data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class PlaceRepository {
private static final String TAG = PlaceRepository.class.getSimpleName();
private static PlaceRepository instance;

private PlaceDAO placeDAO;
private final PlaceDAO placeDAO;

private PlaceRepository(Application application) {
AppDatabase database = AppDatabase.getInstance(application);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public class PlayRepository {
private static final String TAG = PlayRepository.class.getSimpleName();
private static PlayRepository instance;

private PlayDAO playDAO;
private PlayService playService;
private final PlayDAO playDAO;
private final PlayService playService;

private TourRepository tourRepo;
private UserRepository userRepo;
private final TourRepository tourRepo;
private final UserRepository userRepo;

private PlacePlayDAO placePlayDAO;
private final PlacePlayDAO placePlayDAO;

private PlayRepository(Application application) {
AppDatabase database = AppDatabase.getInstance(application);
Expand Down Expand Up @@ -163,7 +163,7 @@ public Play createPlay(int user_id, int tour_id) throws APIException {
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));
plays.addAll(playService.getUserPlays());
for(Play p : plays) {
userRepo.insert(p.getUser());
tourRepo.insert(p.getTour());
Expand All @@ -187,13 +187,9 @@ public List<Play> getUserPlays(int user_id) throws APIException {

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);
List<Play> plays = playService.getUserPlays();
for(Play p : plays) {
insert(p);
}
}).start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.martinlaizg.geofind.data.access.database.entities.Play;
import com.martinlaizg.geofind.data.access.database.entities.Tour;
import com.martinlaizg.geofind.views.fragment.single.TourFragment;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
Expand Down Expand Up @@ -50,9 +51,17 @@ public void onBindViewHolder(@NonNull PlaysViewHolder holder, final int i) {
holder.tour_description.setText(t.getDescription());

if(t.getImage() != null && !t.getImage().isEmpty()) {
Picasso.with(context).load(t.getImage()).into(holder.tour_image);
} else {
holder.tour_image.setImageResource(R.drawable.default_map_image);
Picasso.with(context).load(t.getImage()).into(holder.tour_image, new Callback() {
@Override
public void onSuccess() {
holder.tour_image.setVisibility(View.VISIBLE);
}

@Override
public void onError() {
holder.tour_image.setVisibility(View.GONE);
}
});
}
int completed = play.getPlaces().size();
int numPlaces = t.getPlaces().size();
Expand All @@ -61,7 +70,7 @@ public void onBindViewHolder(@NonNull PlaysViewHolder holder, final int i) {
holder.tour_progress_text.setText(context.getString(R.string.div, completed, numPlaces));

Bundle b = new Bundle();
b.putInt(TourFragment.TOUR_ID, plays.get(i).getId());
b.putInt(TourFragment.TOUR_ID, plays.get(i).getTour_id());
holder.tour_card
.setOnClickListener(v -> Navigation.findNavController(v).navigate(R.id.toTour, b));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.martinlaizg.geofind.R;
import com.martinlaizg.geofind.data.access.database.entities.Tour;
import com.martinlaizg.geofind.views.fragment.single.TourFragment;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
Expand Down Expand Up @@ -47,9 +48,19 @@ public void onBindViewHolder(@NonNull ToursViewHolder holder, final int i) {
holder.tourDescription.setText(tour.getDescription());

if(tour.getImage() != null && !tour.getImage().isEmpty()) {
Picasso.with(context).load(tour.getImage()).into(holder.tour_image);
Picasso.with(context).load(tour.getImage()).into(holder.tour_image, new Callback() {
@Override
public void onSuccess() {
holder.tour_image.setVisibility(View.VISIBLE);
}

@Override
public void onError() {
holder.tour_image.setVisibility(View.GONE);
}
});
} else {
holder.tour_image.setImageResource(R.drawable.default_map_image);
holder.tour_image.setVisibility(View.GONE);
}

Bundle b = new Bundle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class MainFragment

private User user;
private PlayListAdapter adapter;
@SuppressWarnings("FieldCanBeLocal")
private MainFragmentViewModel viewModel;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,14 @@ public void onClick(View v) {
.getSystemService(Context.INPUT_METHOD_SERVICE);
View currentFocus = requireActivity().getCurrentFocus();
if(currentFocus != null) {
editTextInput.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
Objects.requireNonNull(editTextInput)
.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
}

if(!storePlace()) return;

viewModel.savePlace();

Navigation.findNavController(requireActivity(), R.id.main_fragment_holder).popBackStack();
}

Expand All @@ -110,6 +112,7 @@ public void onClick(View v) {
*
* @return true if no has errors else false
*/
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean storePlace() {
// Get the name
String placeName = Objects.requireNonNull(new_place_name.getEditText()).getText().toString()
Expand Down Expand Up @@ -234,7 +237,7 @@ private void setPosition(Place place) {
.setText(getString(R.string.two_csv, position.latitude, position.longitude));
try {
locations = gc.getFromLocation(position.latitude, position.longitude, 1);
if(locations != null && locations.size() > 1) {
if(locations != null && locations.size() >= 1) {
new_place_address.setText(locations.get(0).getAddressLine(0));
}
} catch(IOException e) {
Expand Down Expand Up @@ -294,7 +297,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
.getSystemService(Context.INPUT_METHOD_SERVICE);
View currentFocus = requireActivity().getCurrentFocus();
if(currentFocus != null) {
editTextInput.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
Objects.requireNonNull(editTextInput)
.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
}

Navigation.findNavController(requireActivity(), R.id.main_fragment_holder)
Expand Down Expand Up @@ -365,17 +369,17 @@ private AlertDialog buildDialog() {
.getSystemService(Context.INPUT_METHOD_SERVICE);
View currentFocus = requireActivity().getCurrentFocus();
if(currentFocus != null) {
editTextInput.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
Objects.requireNonNull(editTextInput)
.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
}
}).create();
}

private void showExitDialog() {
new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.are_you_sure)
.setMessage(getString(R.string.exit_lose_data_alert))
.setPositiveButton(getString(R.string.ok), (dialog, which) -> {
Navigation.findNavController(requireActivity(), R.id.main_fragment_holder)
.popBackStack();
}).show();
.setPositiveButton(getString(R.string.ok), (dialog, which) -> Navigation
.findNavController(requireActivity(), R.id.main_fragment_holder)
.popBackStack()).show();
}
}
Loading

0 comments on commit 48bc7c1

Please sign in to comment.