use of org.wordpress.android.fluxc.model.post.PostLocation in project WordPress-Android by wordpress-mobile.
the class PostLocationTest method testDefaultLocationInvalid.
public void testDefaultLocationInvalid() {
PostLocation location = new PostLocation();
assertFalse("Empty location should be invalid", location.isValid());
}
use of org.wordpress.android.fluxc.model.post.PostLocation in project WordPress-Android by wordpress-mobile.
the class PostLocationTest method testInstantiateValidLocation.
public void testInstantiateValidLocation() {
PostLocation locationZero = new PostLocation(EQUATOR_LAT, EQUATOR_LNG);
assertTrue("ZeroLoc did not instantiate valid location", locationZero.isValid());
assertEquals("ZeroLoc did not return correct lat", EQUATOR_LAT, locationZero.getLatitude());
assertEquals("ZeroLoc did not return correct lng", EQUATOR_LNG, locationZero.getLongitude());
PostLocation locationMax = new PostLocation(MAX_LAT, MAX_LNG);
assertTrue("MaxLoc did not instantiate valid location", locationMax.isValid());
assertEquals("MaxLoc did not return correct lat", MAX_LAT, locationMax.getLatitude());
assertEquals("MaxLoc did not return correct lng", MAX_LNG, locationMax.getLongitude());
PostLocation locationMin = new PostLocation(MIN_LAT, MIN_LNG);
assertTrue("MinLoc did not instantiate valid location", locationMin.isValid());
assertEquals("MinLoc did not return correct lat", MIN_LAT, locationMin.getLatitude());
assertEquals("MinLoc did not return correct lng", MIN_LNG, locationMin.getLongitude());
double miscLat = 34;
double miscLng = -60;
PostLocation locationMisc = new PostLocation(miscLat, miscLng);
assertTrue("MiscLoc did not instantiate valid location", locationMisc.isValid());
assertEquals("MiscLoc did not return correct lat", miscLat, locationMisc.getLatitude());
assertEquals("MiscLoc did not return correct lng", miscLng, locationMisc.getLongitude());
}
use of org.wordpress.android.fluxc.model.post.PostLocation in project WordPress-Android by wordpress-mobile.
the class EditPostSettingsFragment method initLocation.
/*
* called when activity is created to initialize the location provider, show views related
* to location if enabled for this blog, and retrieve the current location if necessary
*/
private void initLocation(ViewGroup rootView) {
if (!mPost.supportsLocation())
return;
// show the location views if a provider was found and this is a post on a blog that has location enabled
View locationRootView = ((ViewStub) rootView.findViewById(R.id.stub_post_location_settings)).inflate();
TextView locationLabel = ((TextView) locationRootView.findViewById(R.id.locationLabel));
locationLabel.setText(getResources().getString(R.string.location).toUpperCase());
mLocationText = (TextView) locationRootView.findViewById(R.id.locationText);
mLocationText.setOnClickListener(this);
mLocationAddSection = locationRootView.findViewById(R.id.sectionLocationAdd);
mLocationSearchSection = locationRootView.findViewById(R.id.sectionLocationSearch);
mLocationViewSection = locationRootView.findViewById(R.id.sectionLocationView);
Button addLocation = (Button) locationRootView.findViewById(R.id.addLocation);
addLocation.setOnClickListener(this);
mButtonSearchLocation = (Button) locationRootView.findViewById(R.id.searchLocation);
mButtonSearchLocation.setOnClickListener(this);
mLocationEditText = (EditText) locationRootView.findViewById(R.id.searchLocationText);
mLocationEditText.setOnEditorActionListener(this);
mLocationEditText.addTextChangedListener(mLocationEditTextWatcher);
Button updateLocation = (Button) locationRootView.findViewById(R.id.updateLocation);
Button removeLocation = (Button) locationRootView.findViewById(R.id.removeLocation);
updateLocation.setOnClickListener(this);
removeLocation.setOnClickListener(this);
// if this post has location attached to it, look up the location address
if (mPost.hasLocation()) {
showLocationView();
PostLocation location = mPost.getLocation();
setLocation(location.getLatitude(), location.getLongitude());
} else {
showLocationAdd();
}
}
use of org.wordpress.android.fluxc.model.post.PostLocation in project WordPress-Android by wordpress-mobile.
the class EditPostSettingsFragment method setLocation.
private void setLocation(double latitude, double longitude) {
mPostLocation = new PostLocation(latitude, longitude);
new GetAddressTask().execute(mPostLocation.getLatitude(), mPostLocation.getLongitude());
}
use of org.wordpress.android.fluxc.model.post.PostLocation in project WordPress-Android by wordpress-mobile.
the class PostLocationTest method testInvalidLatitude.
public void testInvalidLatitude() {
PostLocation maxLoc = null;
try {
maxLoc = new PostLocation(INVALID_LAT_MAX, 0);
Assert.fail("Lat more than max should have failed on instantiation");
} catch (IllegalArgumentException e) {
assertNull("Invalid instantiation and not null", maxLoc);
}
PostLocation minLoc = null;
try {
minLoc = new PostLocation(INVALID_LAT_MIN, 0);
Assert.fail("Lat less than min should have failed on instantiation");
} catch (IllegalArgumentException e) {
assertNull("Invalid instantiation and not null", minLoc);
}
PostLocation location = new PostLocation();
try {
location.setLatitude(INVALID_LAT_MAX);
Assert.fail("Lat less than min should have failed");
} catch (IllegalArgumentException e) {
assertFalse("Invalid setLatitude and still valid", location.isValid());
}
try {
location.setLatitude(INVALID_LAT_MIN);
Assert.fail("Lat less than min should have failed");
} catch (IllegalArgumentException e) {
assertFalse("Invalid setLatitude and still valid", location.isValid());
}
}
Aggregations