Compare commits

...

7 Commits

Author SHA1 Message Date
Matthieu
53f5a151ba More consistent, remove useless method 2021-10-07 23:18:07 +02:00
Matthieu
f6e4804c77 Merge branch 'master' into swap_username 2021-09-25 21:44:51 +02:00
mjaillot
2f921cda14 Add title bar tests 2021-09-06 16:26:08 +02:00
mjaillot
1b05eeedea Remove username below profile pic 2021-09-06 13:45:25 +02:00
mjaillot
d67d57b68c Merge branch 'master' into swap_username 2021-09-06 12:47:41 +02:00
mjaillot
9ef319bb7e Merge branch 'master' into swap_username 2021-08-13 15:07:36 +02:00
mjaillot
4b6003816b WIP display/username 2021-04-09 17:58:10 +02:00
11 changed files with 153 additions and 31 deletions

View File

@ -1,6 +1,7 @@
package org.pixeldroid.app
import android.content.Context
import androidx.appcompat.widget.Toolbar
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
@ -18,6 +19,8 @@ import org.pixeldroid.app.testUtility.*
import org.pixeldroid.app.utils.db.AppDatabase
import org.junit.rules.Timeout
import org.junit.runner.RunWith
import org.pixeldroid.app.testUtility.ToolbarMatchers.withToolbarSubtitle
import org.pixeldroid.app.testUtility.ToolbarMatchers.withToolbarTitle
@RunWith(AndroidJUnit4::class)
class DrawerMenuTest {
@ -156,7 +159,8 @@ class DrawerMenuTest {
waitForView(R.id.profilePictureImageView)
onView(withId(R.id.accountNameTextView)).check(matches(withText("PixelDroid Developer")))
onView(isAssignableFrom(Toolbar::class.java)).check(matches(withToolbarTitle("PixelDroid Developer")))
onView(isAssignableFrom(Toolbar::class.java)).check(matches(withToolbarSubtitle("@pixeldroid")))
}
@Test
@ -174,7 +178,8 @@ class DrawerMenuTest {
onView(withText("@user2")).perform(click())
waitForView(R.id.profilePictureImageView)
onView(withId(R.id.accountNameTextView)).check(matches(withText("User 2")))
onView(isAssignableFrom(Toolbar::class.java)).check(matches(withToolbarTitle("User 2")))
onView(isAssignableFrom(Toolbar::class.java)).check(matches(withToolbarSubtitle("@user2")))
}
@Test

View File

@ -2,6 +2,7 @@ package org.pixeldroid.app
import android.content.Context
import androidx.appcompat.widget.Toolbar
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
@ -180,7 +181,7 @@ class HomeFeedTest {
onView(withId(R.id.list)).perform(
actionOnItemAtPosition<StatusViewHolder>(0, clickChildViewWithId(R.id.username))
)
onView(withId(R.id.accountNameTextView)).check(matches(isDisplayed()))
onView(withId(R.id.profilePictureImageView)).check(matches(isDisplayed()))
}
@Test
@ -191,7 +192,7 @@ class HomeFeedTest {
onView(withId(R.id.list)).perform(
actionOnItemAtPosition<StatusViewHolder>(0, clickChildViewWithId(R.id.profilePic))
)
onView(withId(R.id.accountNameTextView)).check(matches(isDisplayed()))
onView(withId(R.id.profilePictureImageView)).check(matches(isDisplayed()))
}
@Test

View File

@ -0,0 +1,132 @@
package org.pixeldroid.app.testUtility;
import android.content.res.Resources;
import android.view.View;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import static org.hamcrest.CoreMatchers.is;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.test.espresso.matcher.BoundedMatcher;
public class ToolbarMatchers {
public static Matcher<View> withToolbarTitle(CharSequence text) {
return new WithCharSequenceMatcher(is(text), ToolbarMethod.GET_TITLE);
}
public static Matcher<View> withToolbarSubtitle(CharSequence text) {
return new WithCharSequenceMatcher(is(text), ToolbarMethod.GET_SUBTITLE);
}
public static Matcher<View> withToolbarTitle(final int resourceId) {
return new WithStringResourceMatcher(resourceId, ToolbarMethod.GET_TITLE);
}
public static Matcher<View> withToolbarSubTitle(final int resourceId) {
return new WithStringResourceMatcher(resourceId, ToolbarMethod.GET_SUBTITLE);
}
private static final class WithCharSequenceMatcher extends BoundedMatcher<View, Toolbar> {
private final Matcher<CharSequence> charSequenceMatcher;
private final ToolbarMethod method;
private WithCharSequenceMatcher(Matcher<CharSequence> charSequenceMatcher, ToolbarMethod method) {
super(Toolbar.class);
this.charSequenceMatcher = charSequenceMatcher;
this.method = method;
}
@Override
public void describeTo(Description description) {
description.appendText("with text: ");
charSequenceMatcher.describeTo(description);
}
@Override
protected boolean matchesSafely(Toolbar toolbar) {
CharSequence actualText;
switch (method) {
case GET_TITLE:
actualText = toolbar.getTitle();
break;
case GET_SUBTITLE:
actualText = toolbar.getSubtitle();
break;
default:
throw new IllegalStateException("Unexpected Toolbar method: " + method.toString());
}
return charSequenceMatcher.matches(actualText);
}
}
static final class WithStringResourceMatcher extends BoundedMatcher<View, Toolbar> {
private final int resourceId;
@Nullable
private String resourceName;
@Nullable
private String expectedText;
private final ToolbarMethod method;
private WithStringResourceMatcher(int resourceId, ToolbarMethod method) {
super(Toolbar.class);
this.resourceId = resourceId;
this.method = method;
}
@Override
public void describeTo(Description description) {
description.appendText("with string from resource id: ").appendValue(resourceId);
if (null != resourceName) {
description.appendText("[").appendText(resourceName).appendText("]");
}
if (null != expectedText) {
description.appendText(" value: ").appendText(expectedText);
}
}
@Override
public boolean matchesSafely(Toolbar toolbar) {
if (null == expectedText) {
try {
expectedText = toolbar.getResources().getString(resourceId);
resourceName = toolbar.getResources().getResourceEntryName(resourceId);
} catch (Resources.NotFoundException ignored) {
/* view could be from a context unaware of the resource id. */
}
}
CharSequence actualText;
switch (method) {
case GET_TITLE:
actualText = toolbar.getTitle();
break;
case GET_SUBTITLE:
actualText = toolbar.getSubtitle();
break;
default:
throw new IllegalStateException("Unexpected Toolbar method: " + method.toString());
}
// FYI: actualText may not be string ... its just a char sequence convert to string.
return null != expectedText
&& null != actualText
&& expectedText.equals(actualText.toString());
}
}
enum ToolbarMethod {
GET_TITLE,
GET_SUBTITLE
}
}

View File

@ -46,7 +46,7 @@ class PostActivity : BaseActivity() {
domain = user?.instance_uri.orEmpty()
supportActionBar?.title = getString(R.string.post_title).format(status.account?.getDisplayName())
supportActionBar?.title = getString(R.string.post_title).format(status.account?.username)
val holder = StatusViewHolder(binding.postFragmentSingle)

View File

@ -89,13 +89,13 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
) {
//Setup username as a button that opens the profile
binding.username.apply {
text = status?.account?.getDisplayName() ?: ""
text = status?.account?.username ?: ""
setTypeface(null, Typeface.BOLD)
setOnClickListener { status?.account?.openProfile(binding.root.context) }
}
binding.usernameDesc.apply {
text = status?.account?.getDisplayName() ?: ""
text = status?.account?.username ?: ""
setTypeface(null, Typeface.BOLD)
}

View File

@ -25,9 +25,9 @@ class FollowsActivity : BaseActivity() {
if(account == null) {
val user = db.userDao().getActiveUser()!!
startFragment(user.user_id, user.display_name, followers)
startFragment(user.user_id, user.username, followers)
} else {
startFragment(account.id!!, account.getDisplayName(), followers)
startFragment(account.id!!, account.username.orEmpty(), followers)
}
}

View File

@ -157,11 +157,10 @@ class ProfileActivity : BaseActivity() {
val displayName = account.getDisplayName()
binding.accountNameTextView.text = displayName
supportActionBar?.title = "@${account.acct}"
supportActionBar?.title = displayName
if(displayName != "@${account.acct}") {
supportActionBar?.subtitle = "@${account.acct}"
supportActionBar?.subtitle = displayName
}
binding.nbPostsTextView.text = resources.getQuantityString(

View File

@ -75,6 +75,7 @@ data class Account(
}
fun anyAvatar(): String? = avatar_static ?: avatar
/**
* @brief Open profile activity with given account
*/

View File

@ -65,19 +65,6 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/nbFollowersTextView" />
<TextView
android:id="@+id/accountNameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:layout_marginRight="20dp"
android:text="@string/no_username"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/profilePictureImageView" />
<TextView
android:id="@+id/descriptionTextView"
@ -88,7 +75,7 @@
android:layout_marginRight="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/accountNameTextView" />
app:layout_constraintTop_toBottomOf="@id/profilePictureImageView" />
<Button
android:id="@+id/followButton"

View File

@ -215,9 +215,9 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"</string>
<string name="license_info">PixelDroid is free and open source software, licensed under the GNU General Public License (version 3 or later)</string>
<string name="about">About</string>
<string name="post_title">%1$s\'s post</string>
<string name="followers_title">%1$s\'s followers</string>
<string name="followers_title">\@%1$s\'s followers</string>
<string name="hashtag_title">#%1$s</string>
<string name="follows_title">%1$s\'s follows</string>
<string name="follows_title">\@%1$s\'s follows</string>
<string name="search_empty_error">Search query can\'t be empty</string>
<string name="status_more_options">More options</string>
<string name="report">Report</string>

View File

@ -33,9 +33,6 @@ class PostUnitTest {
@Test
fun getProfilePicUrlReturnsAValidURL() = Assert.assertNotNull(status.getProfilePicUrl())
@Test
fun getUsernameReturnsACorrectName() = Assert.assertEquals(status.account!!.display_name, status.account!!.getDisplayName())
/*@Test
fun getUsernameReturnsOtherNameIfUsernameIsNull() {
val emptyDescStatus = status.copy(account = status.account!!.copy(username = ""))