Skip to content

Commit

Permalink
Merge pull request #66 from martinlaizg/dev
Browse files Browse the repository at this point in the history
Versión v0.3.1
  • Loading branch information
martinlaizg authored Jul 26, 2019
2 parents be3a04b + 0477fa4 commit bce37e3
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {
minSdkVersion 26
targetSdkVersion 28
versionCode 7
versionName 'v0.3'
versionName 'v0.3.1'
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public interface RestClient {
@GET("tours/{tour_id}/users/{user_id}/play")
Call<Play> getUserPlay(@Path("tour_id") Integer tour_id, @Path("user_id") Integer user_id);

@POST("tours/{tour_id}/users/{user_id}/play")
Call<Play> createUserPlay(@Path("tour_id") Integer tour_id, @Path("user_id") Integer user_id);

@POST("login")
Call<User> login(@Body Login login);

@POST("users")
Call<User> registry(@Body Login login);

@POST("plays")
Call<Play> createUserPlay(@QueryMap Map<String, String> params);

@POST("plays/{play_id}/places/{place_id}")
Call<Play> createPlacePlay(@Path("play_id") Integer play_id,
@Path("place_id") Integer place_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

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

import retrofit2.Response;
Expand Down Expand Up @@ -76,10 +75,7 @@ public Play createUserPlay(int user_id, int tour_id) throws APIException {
Response<Play> response;
APIException apiException;
try {
HashMap<String, String> params = new HashMap<>();
params.put("user_id", String.valueOf(user_id));
params.put("tour_id", String.valueOf(tour_id));
response = restClient.createUserPlay(params).execute();
response = restClient.createUserPlay(tour_id, user_id).execute();
if(response.isSuccessful()) {
return response.body();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
Expand All @@ -10,7 +12,10 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
Expand All @@ -28,10 +33,12 @@
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.textfield.TextInputLayout;
import com.martinlaizg.geofind.R;
import com.martinlaizg.geofind.data.access.database.entities.Place;
import com.martinlaizg.geofind.views.viewmodel.CreatorViewModel;
import com.squareup.picasso.Picasso;

import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -63,6 +70,10 @@ public class CreatePlaceFragment
@BindView(R.id.new_place_map_view)
MapView new_place_map_view;

@BindView(R.id.new_place_image_button)
MaterialButton new_place_image_button;
@BindView(R.id.place_image_view)
ImageView place_image_view;
@BindView(R.id.question_switch)
Switch question_switch;
@BindView(R.id.question_layout)
Expand All @@ -75,6 +86,7 @@ public class CreatePlaceFragment
TextInputLayout new_place_answer_2;
@BindView(R.id.new_place_answer_3)
TextInputLayout new_place_answer_3;
private String image_url;

private CreatorViewModel viewModel;
private MarkerOptions marker;
Expand Down Expand Up @@ -226,6 +238,7 @@ private void setMarker() {
gMap.getUiSettings().setMyLocationButtonEnabled(true);
gMap.getUiSettings().setMapToolbarEnabled(false);
gMap.getUiSettings().setTiltGesturesEnabled(false);
gMap.getUiSettings().setZoomControlsEnabled(true);

LatLng usrLatLng = new LatLng(usrLocation.getLatitude(), usrLocation.getLongitude());
gMap.clear();
Expand Down Expand Up @@ -297,6 +310,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
Log.i(TAG, "onViewCreated: Get place and set");
}
create_button.setOnClickListener(this);
new_place_image_button.setOnClickListener(v -> {
AlertDialog alertDialog = buildDialog();
alertDialog.show();
});
if(marker != null) create_button.setText(R.string.update_place);
}

Expand Down Expand Up @@ -329,12 +346,45 @@ private void setPlace(Place place) {
Objects.requireNonNull(new_place_answer_3.getEditText())
.setText(place.getAnswer3());
}

place_image_view.setVisibility(View.GONE);

if(place.getImage() != null && !place.getImage().isEmpty()) {
Picasso.with(requireContext()).load(image_url).into(place_image_view);
place_image_view.setVisibility(View.VISIBLE);
}
} else {
Toast.makeText(requireContext(), getResources().getString(R.string.invalid_place),
Toast.LENGTH_SHORT).show();
}
}

private AlertDialog buildDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = requireActivity().getLayoutInflater();

View view = inflater.inflate(R.layout.add_image_layout, new LinearLayout(requireContext()));
TextInputLayout image_url_layout = view.findViewById(R.id.image_url_layout);
Objects.requireNonNull(image_url_layout.getEditText()).setText(image_url);
return builder.setView(view).setPositiveButton(R.string.ok, (dialog, id) -> {
image_url = Objects.requireNonNull(image_url_layout.getEditText()).getText().toString();
place_image_view.setVisibility(View.GONE);
if(!image_url.isEmpty()) {
Picasso.with(requireContext()).load(image_url).into(place_image_view);
place_image_view.setVisibility(View.VISIBLE);
}

// Hide the keyboard
InputMethodManager editTextInput = (InputMethodManager) requireActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE);
View currentFocus = requireActivity().getCurrentFocus();
if(currentFocus != null) {
editTextInput.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
}
}).create();
}

@Override
public void onMapLongClick(LatLng latLng) {
alert_no_place_text.setVisibility(View.INVISIBLE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.martinlaizg.geofind.views.fragment.creator;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;

import androidx.annotation.NonNull;
Expand All @@ -21,6 +26,7 @@
import com.martinlaizg.geofind.data.access.database.entities.User;
import com.martinlaizg.geofind.data.enums.PlayLevel;
import com.martinlaizg.geofind.views.viewmodel.CreatorViewModel;
import com.squareup.picasso.Picasso;

import java.util.Objects;

Expand All @@ -37,6 +43,8 @@ public class CreateTourFragment
TextInputLayout tour_name_layout;
@BindView(R.id.tour_description_layout)
TextInputLayout tour_description_layout;
@BindView(R.id.tour_image_view)
ImageView tour_image_view;

@BindView(R.id.done_button)
MaterialButton done_button;
Expand All @@ -46,6 +54,7 @@ public class CreateTourFragment
Spinner difficulty_spinner;

private CreatorViewModel viewModel;
private String image_url = "";

@Override
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
Expand All @@ -58,20 +67,56 @@ public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
viewModel = ViewModelProviders.of(requireActivity()).get(CreatorViewModel.class);
Tour m = viewModel.getTour();
if(m != null) {
if(!m.getName().isEmpty()) {
Objects.requireNonNull(tour_name_layout.getEditText()).setText(m.getName());
Tour t = viewModel.getTour();
if(t != null) {
if(!t.getName().isEmpty()) {
Objects.requireNonNull(tour_name_layout.getEditText()).setText(t.getName());
}
if(!m.getDescription().isEmpty()) {
if(!t.getDescription().isEmpty()) {
Objects.requireNonNull(tour_description_layout.getEditText())
.setText(m.getDescription());
.setText(t.getDescription());
}
if(m.getMin_level() != null) {
difficulty_spinner.setSelection(m.getMin_level().ordinal());
if(t.getMin_level() != null) {
difficulty_spinner.setSelection(t.getMin_level().ordinal());
}
tour_image_view.setVisibility(View.GONE);
if(t.getImage() != null) image_url = t.getImage();
if(!image_url.isEmpty()) {
Picasso.with(requireContext()).load(image_url).into(tour_image_view);
tour_image_view.setVisibility(View.VISIBLE);
}
}
done_button.setOnClickListener(this);
add_image_button.setOnClickListener(v -> {
AlertDialog alertDialog = buildDialog();
alertDialog.show();
});
}

private AlertDialog buildDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = requireActivity().getLayoutInflater();

View view = inflater.inflate(R.layout.add_image_layout, new LinearLayout(requireContext()));
TextInputLayout image_url_layout = view.findViewById(R.id.image_url_layout);
Objects.requireNonNull(image_url_layout.getEditText()).setText(image_url);
return builder.setView(view).setPositiveButton(R.string.ok, (dialog, id) -> {
image_url = Objects.requireNonNull(image_url_layout.getEditText()).getText().toString();
tour_image_view.setVisibility(View.GONE);
if(!image_url.isEmpty()) {
Picasso.with(requireContext()).load(image_url).into(tour_image_view);
tour_image_view.setVisibility(View.VISIBLE);
}

// Hide the keyboard
InputMethodManager editTextInput = (InputMethodManager) requireActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE);
View currentFocus = requireActivity().getCurrentFocus();
if(currentFocus != null) {
editTextInput.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
}
}).create();
}

@Override
Expand Down Expand Up @@ -103,7 +148,7 @@ public void onClick(View v) {
PlayLevel pl = PlayLevel.getPlayLevel(difficulty_spinner.getSelectedItemPosition());
User user = Preferences
.getLoggedUser(PreferenceManager.getDefaultSharedPreferences(requireContext()));
viewModel.updateTour(name, description, user.getId(), pl);
viewModel.updateTour(name, description, user.getId(), pl, image_url);
Navigation.findNavController(requireActivity(), R.id.main_fragment_holder).popBackStack();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ public MutableLiveData<Tour> createTour() {
return m;
}

public void updateTour(String name, String description, Integer creator_id, PlayLevel pl) {
public void updateTour(String name, String description, Integer creator_id, PlayLevel pl,
String image_url) {
if(tour == null) tour = new Tour();
tour.setName(name);
tour.setDescription(description);
tour.setCreator_id(creator_id);
tour.setMin_level(pl);
tour.setImage(image_url);
}

public MutableLiveData<Tour> loadTour(Integer tour_id) {
Expand Down Expand Up @@ -117,4 +119,5 @@ public void setPlace(Place place) {
public void reset() {
tour = null;
}

}
28 changes: 28 additions & 0 deletions app/src/main/res/layout/add_image_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:orientation="vertical">

<TextView
android:id="@+id/add_image_text"
style="@style/TextAppearance.MaterialComponents.Headline5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/add_image_url" />

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/image_url_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp">

<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/image_url" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
17 changes: 15 additions & 2 deletions app/src/main/res/layout/fragment_create_place.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,31 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/alert_no_place_text" />

<ImageView
android:id="@+id/place_image_view"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/new_place_image_button"
tools:srcCompat="@tools:sample/backgrounds/scenic[9]" />

<Switch
android:id="@+id/question_switch"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="@string/with_question"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/new_place_image_button" />
app:layout_constraintTop_toBottomOf="@+id/place_image_view" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/question_layout"
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/layout/fragment_create_tour.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down Expand Up @@ -116,6 +117,19 @@
app:layout_constraintEnd_toStartOf="@id/add_image_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/select_difficulty_text" />

<ImageView
android:id="@+id/tour_image_view"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/difficulty_spinner"
tools:srcCompat="@tools:sample/backgrounds/scenic[11]" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

Expand Down
Loading

0 comments on commit bce37e3

Please sign in to comment.