Linked map BTN to Map Activity
Linked Map markers back to Properties Details Activity
This commit is contained in:
parent
95b73a0b34
commit
d6ab1178e8
@ -5,18 +5,22 @@ import android.location.Address;
|
|||||||
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
||||||
import com.google.android.gms.maps.model.LatLng;
|
import com.google.android.gms.maps.model.LatLng;
|
||||||
|
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
|
||||||
|
|
||||||
public class MapMarker {
|
public class MapMarker {
|
||||||
|
|
||||||
private Address address;
|
private Address address;
|
||||||
private LatLng latLng;
|
private LatLng latLng;
|
||||||
private String title;
|
private String title;
|
||||||
private float color;
|
private float color;
|
||||||
|
private Property property;
|
||||||
|
|
||||||
public MapMarker(Address address, String title, float color) {
|
public MapMarker(Address address, String title, float color, Property property) {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.latLng = new LatLng(this.address.getLatitude(), this.address.getLongitude());
|
this.latLng = new LatLng(this.address.getLatitude(), this.address.getLongitude());
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
this.property = property;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Address getAddress() {
|
public Address getAddress() {
|
||||||
|
|||||||
@ -16,6 +16,9 @@ import fr.romanet.vj.apps.myrealestateagency.entities.Property;
|
|||||||
@Dao
|
@Dao
|
||||||
public interface PropertyDao {
|
public interface PropertyDao {
|
||||||
|
|
||||||
|
@Query("SELECT * FROM property WHERE property_id = :propertyId")
|
||||||
|
Property getOnePropertyById(int propertyId);
|
||||||
|
|
||||||
@Query("SELECT * FROM property WHERE belongs_agency_id = :agencyId")
|
@Query("SELECT * FROM property WHERE belongs_agency_id = :agencyId")
|
||||||
List<Property> getPropertyFromAgencyList(int agencyId);
|
List<Property> getPropertyFromAgencyList(int agencyId);
|
||||||
|
|
||||||
|
|||||||
@ -54,9 +54,9 @@ public class MapsActivityRepository {
|
|||||||
|
|
||||||
for (Property property: propertiesFromAgency){
|
for (Property property: propertiesFromAgency){
|
||||||
if(property.propertyStatue.statueSale){
|
if(property.propertyStatue.statueSale){
|
||||||
mapMarkers.add(new MapMarker(get_lat_long_from_address(property.address, MyApp.getContext()), property.description, BitmapDescriptorFactory.HUE_RED));
|
mapMarkers.add(new MapMarker(get_lat_long_from_address(property.address, MyApp.getContext()), String.valueOf(property.propertyId), BitmapDescriptorFactory.HUE_RED, property));
|
||||||
}else{
|
}else{
|
||||||
mapMarkers.add(new MapMarker(get_lat_long_from_address(property.address, MyApp.getContext()), property.description, BitmapDescriptorFactory.HUE_BLUE));
|
mapMarkers.add(new MapMarker(get_lat_long_from_address(property.address, MyApp.getContext()), String.valueOf(property.propertyId), BitmapDescriptorFactory.HUE_BLUE, property));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -64,5 +64,11 @@ public class MapsActivityRepository {
|
|||||||
return mapMarkers;
|
return mapMarkers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Property get_one_property_by_id(Application application, Integer propertyId){
|
||||||
|
propertyRepository = new PropertyRepository(application);
|
||||||
|
Property property = propertyRepository.getOnePropertyById(propertyId);
|
||||||
|
return property;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -22,6 +22,9 @@ public class PropertyRepository {
|
|||||||
allProperties = propertyDao.getPropertyList();
|
allProperties = propertyDao.getPropertyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Property getOnePropertyById(int propertyId){return propertyDao.getOnePropertyById(propertyId);}
|
||||||
|
|
||||||
public List<Property> getPropertyFromAgencyList(Agency agency){return propertyDao.getPropertyFromAgencyList(agency.agencyId); }
|
public List<Property> getPropertyFromAgencyList(Agency agency){return propertyDao.getPropertyFromAgencyList(agency.agencyId); }
|
||||||
|
|
||||||
public LiveData<List<Property>> getAllProperties() {
|
public LiveData<List<Property>> getAllProperties() {
|
||||||
|
|||||||
@ -5,9 +5,11 @@ import androidx.lifecycle.Observer;
|
|||||||
import androidx.lifecycle.ViewModel;
|
import androidx.lifecycle.ViewModel;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.location.Address;
|
import android.location.Address;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.Property;
|
||||||
|
|
||||||
import com.google.android.gms.maps.CameraUpdate;
|
import com.google.android.gms.maps.CameraUpdate;
|
||||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||||
@ -26,6 +28,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.romanet.vj.apps.myrealestateagency.MapMarker;
|
import fr.romanet.vj.apps.myrealestateagency.MapMarker;
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.MyApp;
|
||||||
import fr.romanet.vj.apps.myrealestateagency.R;
|
import fr.romanet.vj.apps.myrealestateagency.R;
|
||||||
import fr.romanet.vj.apps.myrealestateagency.repository.MapsActivityRepository;
|
import fr.romanet.vj.apps.myrealestateagency.repository.MapsActivityRepository;
|
||||||
import fr.romanet.vj.apps.myrealestateagency.viewmodel.MapsActivityViewModel;
|
import fr.romanet.vj.apps.myrealestateagency.viewmodel.MapsActivityViewModel;
|
||||||
@ -75,6 +78,16 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private GoogleMap.OnMarkerClickListener markerClickListener = new GoogleMap.OnMarkerClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMarkerClick(Marker marker) {
|
||||||
|
viewModel.intent_property_activity_from_marker(marker);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
private void observeAddresses(GoogleMap mMap){
|
private void observeAddresses(GoogleMap mMap){
|
||||||
viewModel.markers_to_display.observe(this, new Observer<List<MapMarker>>() {
|
viewModel.markers_to_display.observe(this, new Observer<List<MapMarker>>() {
|
||||||
List<MarkerOptions> markers = new ArrayList<MarkerOptions>();
|
List<MarkerOptions> markers = new ArrayList<MarkerOptions>();
|
||||||
@ -103,9 +116,13 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
|
|||||||
|
|
||||||
mMap.animateCamera(cu);
|
mMap.animateCamera(cu);
|
||||||
|
|
||||||
|
mMap.setOnMarkerClickListener(markerClickListener);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,7 +1,9 @@
|
|||||||
package fr.romanet.vj.apps.myrealestateagency.viewmodel;
|
package fr.romanet.vj.apps.myrealestateagency.viewmodel;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.content.Intent;
|
||||||
import android.location.Address;
|
import android.location.Address;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
@ -13,6 +15,7 @@ import androidx.lifecycle.OnLifecycleEvent;
|
|||||||
|
|
||||||
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
||||||
import com.google.android.gms.maps.model.LatLng;
|
import com.google.android.gms.maps.model.LatLng;
|
||||||
|
import com.google.android.gms.maps.model.Marker;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -26,47 +29,46 @@ import fr.romanet.vj.apps.myrealestateagency.entities.Property;
|
|||||||
import fr.romanet.vj.apps.myrealestateagency.repository.MapsActivityRepository;
|
import fr.romanet.vj.apps.myrealestateagency.repository.MapsActivityRepository;
|
||||||
import fr.romanet.vj.apps.myrealestateagency.repository.PropertyRepository;
|
import fr.romanet.vj.apps.myrealestateagency.repository.PropertyRepository;
|
||||||
import fr.romanet.vj.apps.myrealestateagency.view.MapsActivity;
|
import fr.romanet.vj.apps.myrealestateagency.view.MapsActivity;
|
||||||
|
import fr.romanet.vj.apps.myrealestateagency.view.PropertiesDetailActivity;
|
||||||
|
|
||||||
public class MapsActivityViewModel extends AndroidViewModel implements LifecycleObserver {
|
public class MapsActivityViewModel extends AndroidViewModel implements LifecycleObserver {
|
||||||
|
|
||||||
// private PropertyRepository propertyRepository;
|
|
||||||
|
public MutableLiveData<List<MapMarker>> markers_to_display = new MutableLiveData<>();
|
||||||
|
private MapsActivityRepository mapsActivityRepository;
|
||||||
|
|
||||||
|
|
||||||
private Application _application;
|
private Application _application;
|
||||||
public MapsActivityViewModel(@NonNull Application application) {
|
public MapsActivityViewModel(@NonNull Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
this._application = application;
|
this._application = application;
|
||||||
// propertyRepository = new PropertyRepository(application);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<List<MapMarker>> markers_to_display = new MutableLiveData<>();
|
|
||||||
|
|
||||||
// private PropertyRepository propertyRepository;
|
|
||||||
|
|
||||||
private MapsActivityRepository mapsActivityRepository;
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||||
private void init_map() throws IOException {
|
private void init_map() throws IOException {
|
||||||
mapsActivityRepository = new MapsActivityRepository();
|
mapsActivityRepository = new MapsActivityRepository();
|
||||||
|
|
||||||
// LiveData<List<Property>> properties = propertyRepository.getAllProperties();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// List<MapMarker> mapMarkers = new ArrayList<MapMarker>();
|
|
||||||
List<MapMarker> mapMarkers = mapsActivityRepository.get_all_map_markers_for_this_agency(this._application);
|
List<MapMarker> mapMarkers = mapsActivityRepository.get_all_map_markers_for_this_agency(this._application);
|
||||||
// List<LatLng> latLngs = null;
|
|
||||||
|
|
||||||
// mapMarkers.add(new MapMarker(MapsActivityRepository.get_lat_long_from_address("Paris, France", MyApp.getContext()), "Paris", BitmapDescriptorFactory.HUE_BLUE));
|
|
||||||
// mapMarkers.add(new MapMarker(MapsActivityRepository.get_lat_long_from_address("Villejuif, France", MyApp.getContext()), "Villejuif", BitmapDescriptorFactory.HUE_BLUE));
|
|
||||||
// mapMarkers.add(new MapMarker(MapsActivityRepository.get_lat_long_from_address("Cachan, France", MyApp.getContext()), "Cachan", BitmapDescriptorFactory.HUE_BLUE));
|
|
||||||
// mapMarkers.add(new MapMarker(MapsActivityRepository.get_lat_long_from_address("Massy, France", MyApp.getContext()), "Massy", BitmapDescriptorFactory.HUE_GREEN));
|
|
||||||
// mapMarkers.add(new MapMarker(MapsActivityRepository.get_lat_long_from_address("Ivry, France", MyApp.getContext()), "Ivry", BitmapDescriptorFactory.HUE_RED));
|
|
||||||
|
|
||||||
// for (MapMarker mapMarker : mapMarkers){
|
|
||||||
// latLngs.add(new LatLng(addr.getLatitude(), addr.getLongitude()));
|
|
||||||
// }
|
|
||||||
|
|
||||||
markers_to_display.postValue(mapMarkers);
|
markers_to_display.postValue(mapMarkers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Property get_one_property_by_id(Integer propertyId){
|
||||||
|
Property property = mapsActivityRepository.get_one_property_by_id(_application, propertyId);
|
||||||
|
return property;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void intent_property_activity_from_marker(Marker marker){
|
||||||
|
Intent intent1 = new Intent(MyApp.getContext(), PropertiesDetailActivity.class);
|
||||||
|
int propertyId = Integer.parseInt(marker.getTitle());
|
||||||
|
Property property = get_one_property_by_id(propertyId);
|
||||||
|
|
||||||
|
intent1.putExtra(PropertiesDetailActivity.PROPERTY_EXTRA, property);
|
||||||
|
// intent1.putExtra("markerProperty", property);
|
||||||
|
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
// Log.d("CAT", "-----------> PROP " + property.propertyStatue.statueSale);
|
||||||
|
MyApp.getContext().startActivity(intent1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user