Search in sources :

Example 1 with PostLocation

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());
}
Also used : PostLocation(org.wordpress.android.fluxc.model.post.PostLocation)

Example 2 with PostLocation

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());
}
Also used : PostLocation(org.wordpress.android.fluxc.model.post.PostLocation)

Example 3 with PostLocation

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();
    }
}
Also used : ViewStub(android.view.ViewStub) PostLocation(org.wordpress.android.fluxc.model.post.PostLocation) Button(android.widget.Button) AppCompatButton(android.support.v7.widget.AppCompatButton) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) NetworkImageView(com.android.volley.toolbox.NetworkImageView)

Example 4 with PostLocation

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());
}
Also used : PostLocation(org.wordpress.android.fluxc.model.post.PostLocation)

Example 5 with PostLocation

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());
    }
}
Also used : PostLocation(org.wordpress.android.fluxc.model.post.PostLocation)

Aggregations

PostLocation (org.wordpress.android.fluxc.model.post.PostLocation)6 AppCompatButton (android.support.v7.widget.AppCompatButton)1 View (android.view.View)1 ViewStub (android.view.ViewStub)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 NetworkImageView (com.android.volley.toolbox.NetworkImageView)1