change floating action button to "mention", create new follow button in AccountActivity

This commit is contained in:
Conny Duck 2017-08-04 10:53:38 +02:00
parent 42734c4f57
commit e4c9b229d7
2 changed files with 46 additions and 27 deletions

View File

@ -41,6 +41,7 @@ import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -81,6 +82,7 @@ public class AccountActivity extends BaseActivity {
private CircularImageView avatar; private CircularImageView avatar;
private ImageView header; private ImageView header;
private FloatingActionButton floatingBtn; private FloatingActionButton floatingBtn;
private Button followBtn;
private TabLayout tabLayout; private TabLayout tabLayout;
private ImageView accountLockedView; private ImageView accountLockedView;
private View container; private View container;
@ -93,6 +95,7 @@ public class AccountActivity extends BaseActivity {
avatar = (CircularImageView) findViewById(R.id.account_avatar); avatar = (CircularImageView) findViewById(R.id.account_avatar);
header = (ImageView) findViewById(R.id.account_header); header = (ImageView) findViewById(R.id.account_header);
floatingBtn = (FloatingActionButton) findViewById(R.id.floating_btn); floatingBtn = (FloatingActionButton) findViewById(R.id.floating_btn);
followBtn = (Button) findViewById(R.id.follow_btn);
tabLayout = (TabLayout) findViewById(R.id.tab_layout); tabLayout = (TabLayout) findViewById(R.id.tab_layout);
accountLockedView = (ImageView) findViewById(R.id.account_locked); accountLockedView = (ImageView) findViewById(R.id.account_locked);
container = findViewById(R.id.activity_account); container = findViewById(R.id.activity_account);
@ -160,6 +163,7 @@ public class AccountActivity extends BaseActivity {
// Initialise the default UI states. // Initialise the default UI states.
floatingBtn.hide(); floatingBtn.hide();
followBtn.setVisibility(View.GONE);
// Obtain information to fill out the profile. // Obtain information to fill out the profile.
obtainAccount(); obtainAccount();
@ -354,21 +358,18 @@ public class AccountActivity extends BaseActivity {
updateButtons(); updateButtons();
} }
private void updateFollowButton(FloatingActionButton button) { private void updateFollowButton(Button button) {
switch (followState) { switch (followState) {
case NOT_FOLLOWING: { case NOT_FOLLOWING: {
button.setImageResource(R.drawable.ic_person_add_24dp); button.setText(getString(R.string.action_follow));
button.setContentDescription(getString(R.string.action_follow));
break; break;
} }
case REQUESTED: { case REQUESTED: {
button.setImageResource(R.drawable.ic_hourglass_24dp); button.setText(getString(R.string.state_follow_requested));
button.setContentDescription(getString(R.string.state_follow_requested));
break; break;
} }
case FOLLOWING: { case FOLLOWING: {
button.setImageResource(R.drawable.ic_person_minus_24px); button.setText(getString(R.string.action_unfollow));
button.setContentDescription(getString(R.string.action_unfollow));
break; break;
} }
} }
@ -379,18 +380,26 @@ public class AccountActivity extends BaseActivity {
if(!isSelf && !blocking) { if(!isSelf && !blocking) {
floatingBtn.show(); floatingBtn.show();
followBtn.setVisibility(View.VISIBLE);
updateFollowButton(floatingBtn); updateFollowButton(followBtn);
floatingBtn.setOnClickListener(new View.OnClickListener() { floatingBtn.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (followState != FollowState.REQUESTED) { mention();
}
});
followBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (followState != FollowState.REQUESTED) {
follow(accountId); follow(accountId);
} else { } else {
showFollowRequestPendingDialog(accountId); showFollowRequestPendingDialog(accountId);
} }
updateFollowButton(floatingBtn); updateFollowButton(followBtn);
} }
}); });
} }
@ -543,7 +552,6 @@ public class AccountActivity extends BaseActivity {
.show(); .show();
} }
private void mute(final String id) { private void mute(final String id) {
Callback<Relationship> cb = new Callback<Relationship>() { Callback<Relationship> cb = new Callback<Relationship>() {
@Override @Override
@ -582,6 +590,17 @@ public class AccountActivity extends BaseActivity {
.show(); .show();
} }
private boolean mention() {
if (loadedAccount == null) {
// If the account isn't loaded yet, eat the input.
return false;
}
Intent intent = new Intent(this, ComposeActivity.class);
intent.putExtra("mentioned_usernames", new String[] { loadedAccount.username });
startActivity(intent);
return true;
}
private void broadcast(String action, String id) { private void broadcast(String action, String id) {
Intent intent = new Intent(action); Intent intent = new Intent(action);
intent.putExtra("id", id); intent.putExtra("id", id);
@ -596,14 +615,7 @@ public class AccountActivity extends BaseActivity {
return true; return true;
} }
case R.id.action_mention: { case R.id.action_mention: {
if (loadedAccount == null) { return mention();
// If the account isn't loaded yet, eat the input.
return false;
}
Intent intent = new Intent(this, ComposeActivity.class);
intent.putExtra("mentioned_usernames", new String[] { loadedAccount.username });
startActivity(intent);
return true;
} }
case R.id.action_open_in_web: { case R.id.action_open_in_web: {
if (loadedAccount == null) { if (loadedAccount == null) {

View File

@ -52,8 +52,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingRight="16dp" android:paddingRight="16dp">
android:paddingTop="16dp">
<com.pkmmte.view.CircularImageView <com.pkmmte.view.CircularImageView
android:id="@+id/account_avatar" android:id="@+id/account_avatar"
@ -62,16 +61,24 @@
android:layout_marginEnd="10dp" android:layout_marginEnd="10dp"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:src="@drawable/avatar_default" android:src="@drawable/avatar_default"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/follow_btn"
android:layout_toStartOf="@+id/follow_btn"
app:shadow="true" /> app:shadow="true" />
<LinearLayout <Button
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_centerVertical="true" android:layout_marginTop="6dp"
android:layout_toEndOf="@id/account_avatar" android:id="@+id/follow_btn"/>
android:layout_toRightOf="@id/account_avatar"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/account_avatar"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
@ -189,7 +196,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_margin="16dp" android:layout_margin="16dp"
android:contentDescription="@string/action_follow" android:contentDescription="@string/action_mention"
app:srcCompat="@drawable/ic_person_add_24dp" /> app:srcCompat="@drawable/ic_create_24dp" />
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>