Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support new field
overriddenDisplayName
in Social API response (#41)
- Loading branch information
1 parent
802a1b9
commit 781cece
Showing
11 changed files
with
277 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
line-sdk/src/main/java/com/linecorp/linesdk/LineFriendProfile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package com.linecorp.linesdk; | ||
|
||
import android.net.Uri; | ||
import android.os.Parcel; | ||
import android.os.Parcelable; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.text.TextUtils; | ||
|
||
/** | ||
* Represents a friend's LINE profile in the Social API. | ||
*/ | ||
public class LineFriendProfile extends LineProfile { | ||
public static final Parcelable.Creator<LineFriendProfile> CREATOR = | ||
new Parcelable.Creator<LineFriendProfile>() { | ||
@Override | ||
public LineFriendProfile createFromParcel(final Parcel in) { | ||
return new LineFriendProfile(in); | ||
} | ||
|
||
@Override | ||
public LineFriendProfile[] newArray(final int size) { | ||
return new LineFriendProfile[size]; | ||
} | ||
}; | ||
|
||
/** | ||
* Friend's nickname which changed by owner user | ||
*/ | ||
@Nullable | ||
private final String overriddenDisplayName; | ||
|
||
/** | ||
* Constructs a new {@link LineFriendProfile} instance. | ||
* @param userId Friend's user ID. | ||
* @param displayName Friend's display name. | ||
* @param pictureUrl Friend's profile image URL. | ||
* @param statusMessage Friend's status message. | ||
* @param overriddenDisplayName Friend's nickname which changed by owner user | ||
*/ | ||
public LineFriendProfile(@NonNull final String userId, | ||
@NonNull final String displayName, | ||
@Nullable final Uri pictureUrl, | ||
@Nullable final String statusMessage, | ||
@NonNull final String overriddenDisplayName) { | ||
super(userId, displayName, pictureUrl, statusMessage); | ||
this.overriddenDisplayName = overriddenDisplayName; | ||
} | ||
|
||
protected LineFriendProfile(@NonNull final Parcel in) { | ||
super(in); | ||
overriddenDisplayName = in.readString(); | ||
} | ||
|
||
@Override | ||
public void writeToParcel(final Parcel dest, final int flags) { | ||
super.writeToParcel(dest, flags); | ||
dest.writeString(overriddenDisplayName); | ||
} | ||
|
||
/** | ||
* get the friend's nickname which changed by owner user | ||
* @return The friend's nickname which changed by owner user | ||
*/ | ||
@Nullable | ||
public String getOverriddenDisplayName() { | ||
return overriddenDisplayName; | ||
} | ||
|
||
/** | ||
* get the friend's nickname which changed by owner user, or the original display name. | ||
* @return The friend's nickname which changed by owner user, if not available, return the original display name | ||
*/ | ||
@NonNull | ||
public String getAvailableDisplayName() { | ||
return !TextUtils.isEmpty(overriddenDisplayName) | ||
? overriddenDisplayName | ||
: getDisplayName(); | ||
} | ||
|
||
/** | ||
* @hide | ||
*/ | ||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { return true; } | ||
if (!(o instanceof LineFriendProfile)) { return false; } | ||
if (!super.equals(o)) { return false; } | ||
|
||
final LineFriendProfile that = (LineFriendProfile) o; | ||
|
||
return overriddenDisplayName != null ? overriddenDisplayName.equals(that.overriddenDisplayName) : | ||
that.overriddenDisplayName == null; | ||
} | ||
|
||
/** | ||
* @hide | ||
*/ | ||
@Override | ||
public int hashCode() { | ||
int result = super.hashCode(); | ||
result = 31 * result + (overriddenDisplayName != null ? overriddenDisplayName.hashCode() : 0); | ||
return result; | ||
} | ||
|
||
/** | ||
* @hide | ||
*/ | ||
@Override | ||
public String toString() { | ||
return "LineFriendProfile{" + | ||
"userId='" + getUserId() + '\'' + | ||
", displayName='" + getDisplayName() + '\'' + | ||
", pictureUrl=" + getPictureUrl() + | ||
", statusMessage='" + getStatusMessage() + '\'' + | ||
", overriddenDisplayName='" + overriddenDisplayName + '\'' + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
line-sdk/src/test/java/com/linecorp/linesdk/LineFriendProfileTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.linecorp.linesdk; | ||
|
||
import android.net.Uri; | ||
import android.os.Parcel; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Test for {@link LineFriendProfile}. | ||
*/ | ||
@RunWith(RobolectricTestRunner.class) | ||
@Config(constants = BuildConfig.class, sdk = TestConfig.TARGET_SDK_VERSION) | ||
public class LineFriendProfileTest { | ||
@Test | ||
public void testParcelable() { | ||
LineFriendProfile expected = new LineFriendProfile( | ||
"userId", "displayName", Uri.parse("http://line.me"), "statusMessage", "overriddenDisplayName"); | ||
|
||
Parcel parcel = Parcel.obtain(); | ||
expected.writeToParcel(parcel, 0); | ||
|
||
parcel.setDataPosition(0); | ||
|
||
LineFriendProfile actual = LineFriendProfile.CREATOR.createFromParcel(parcel); | ||
assertTrue(expected.equals(actual)); | ||
} | ||
|
||
@Test | ||
public void testEquals() { | ||
LineFriendProfile expected = new LineFriendProfile( | ||
"userId", "displayName", Uri.parse("http://line.me"), "statusMessage", "overriddenDisplayName"); | ||
|
||
assertTrue(expected.equals(new LineFriendProfile( | ||
"userId", "displayName", Uri.parse("http://line.me"), "statusMessage", | ||
"overriddenDisplayName"))); | ||
assertFalse(expected.equals(new LineFriendProfile( | ||
"userId2", "displayName", Uri.parse("http://line.me"), "statusMessage", | ||
"overriddenDisplayName"))); | ||
assertFalse(expected.equals(new LineFriendProfile( | ||
"userId", "displayName2", Uri.parse("http://line.me"), "statusMessage", | ||
"overriddenDisplayName"))); | ||
assertFalse(expected.equals(new LineFriendProfile( | ||
"userId", "displayName", Uri.parse("http://line.me/2"), "statusMessage", | ||
"overriddenDisplayName"))); | ||
assertFalse(expected.equals(new LineFriendProfile( | ||
"userId", "displayName", Uri.parse("http://line.me"), "statusMessage2", | ||
"overriddenDisplayName"))); | ||
assertFalse(expected.equals(new LineFriendProfile( | ||
"userId", "displayName", Uri.parse("http://line.me"), "statusMessage", | ||
"overriddenDisplayName2"))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.