hide follow button on own profile correctly, code optimizations

main
Conny Duck 7 years ago
parent 58307774f4
commit 3f49a2c921
  1. 169
      app/src/main/java/com/keylesspalace/tusky/AccountActivity.java

@ -19,7 +19,6 @@ import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
@ -46,6 +45,7 @@ import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.keylesspalace.tusky.db.AccountEntity;
import com.keylesspalace.tusky.entity.Account; import com.keylesspalace.tusky.entity.Account;
import com.keylesspalace.tusky.entity.Relationship; import com.keylesspalace.tusky.entity.Relationship;
import com.keylesspalace.tusky.interfaces.ActionButtonActivity; import com.keylesspalace.tusky.interfaces.ActionButtonActivity;
@ -128,9 +128,6 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
} }
loadedAccount = null; loadedAccount = null;
SharedPreferences preferences = getPrivatePreferences();
String loggedInAccountId = preferences.getString("loggedInAccountId", null);
// Setup the toolbar. // Setup the toolbar.
final Toolbar toolbar = findViewById(R.id.toolbar); final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
@ -194,14 +191,14 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
// Obtain information to fill out the profile. // Obtain information to fill out the profile.
obtainAccount(); obtainAccount();
if (!accountId.equals(loggedInAccountId)) {
AccountEntity activeAccount = TuskyApplication.getAccountManager().getActiveAccount();
if (accountId.equals(activeAccount.getAccountId())) {
isSelf = true;
} else {
isSelf = false; isSelf = false;
obtainRelationships(); obtainRelationships();
} else {
/* Cause the options menu to update and instead show an options menu for when the
* account being shown is their own account. */
isSelf = true;
invalidateOptionsMenu();
} }
// Setup the tabs and timeline pager. // Setup the tabs and timeline pager.
@ -222,44 +219,33 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
viewPager.setOffscreenPageLimit(0); viewPager.setOffscreenPageLimit(0);
tabLayout.setupWithViewPager(viewPager); tabLayout.setupWithViewPager(viewPager);
View.OnClickListener accountListClickListener = new View.OnClickListener() { View.OnClickListener accountListClickListener = v -> {
@Override AccountListActivity.Type type;
public void onClick(View v) { switch (v.getId()) {
AccountListActivity.Type type; case R.id.followers_tv:
switch (v.getId()) { type = AccountListActivity.Type.FOLLOWERS;
case R.id.followers_tv: break;
type = AccountListActivity.Type.FOLLOWERS; case R.id.following_tv:
break; type = AccountListActivity.Type.FOLLOWING;
case R.id.following_tv: break;
type = AccountListActivity.Type.FOLLOWING; default:
break; throw new AssertionError();
default: }
throw new AssertionError(); Intent intent = AccountListActivity.newIntent(AccountActivity.this, type,
} accountId);
Intent intent = AccountListActivity.newIntent(AccountActivity.this, type, startActivity(intent);
accountId);
startActivity(intent);
}
}; };
followersTextView.setOnClickListener(accountListClickListener); followersTextView.setOnClickListener(accountListClickListener);
followingTextView.setOnClickListener(accountListClickListener); followingTextView.setOnClickListener(accountListClickListener);
statusesTextView.setOnClickListener(new View.OnClickListener() { statusesTextView.setOnClickListener(v -> {
@Override // Make nice ripple effect on tab
public void onClick(View v) {
// Make nice ripple effect on tab //noinspection ConstantConditions
tabLayout.getTabAt(0).select();
//noinspection ConstantConditions final View poorTabView = ((ViewGroup) tabLayout.getChildAt(0)).getChildAt(0);
tabLayout.getTabAt(0).select(); poorTabView.setPressed(true);
final View poorTabView = ((ViewGroup) tabLayout.getChildAt(0)).getChildAt(0); tabLayout.postDelayed(() -> poorTabView.setPressed(false), 300);
poorTabView.setPressed(true);
tabLayout.postDelayed(new Runnable() {
@Override
public void run() {
poorTabView.setPressed(false);
}
}, 300);
}
}); });
} }
@ -354,12 +340,7 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
private void onObtainAccountFailure() { private void onObtainAccountFailure() {
Snackbar.make(tabLayout, R.string.error_generic, Snackbar.LENGTH_LONG) Snackbar.make(tabLayout, R.string.error_generic, Snackbar.LENGTH_LONG)
.setAction(R.string.action_retry, new View.OnClickListener() { .setAction(R.string.action_retry, v -> obtainAccount())
@Override
public void onClick(View v) {
obtainAccount();
}
})
.show(); .show();
} }
@ -409,15 +390,15 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
private void updateFollowButton(Button button) { private void updateFollowButton(Button button) {
switch (followState) { switch (followState) {
case NOT_FOLLOWING: { case NOT_FOLLOWING: {
button.setText(getString(R.string.action_follow)); button.setText(R.string.action_follow);
break; break;
} }
case REQUESTED: { case REQUESTED: {
button.setText(getString(R.string.state_follow_requested)); button.setText(R.string.state_follow_requested);
break; break;
} }
case FOLLOWING: { case FOLLOWING: {
button.setText(getString(R.string.action_unfollow)); button.setText(R.string.action_unfollow);
break; break;
} }
} }
@ -432,32 +413,24 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
updateFollowButton(followBtn); updateFollowButton(followBtn);
floatingBtn.setOnClickListener(new View.OnClickListener() { floatingBtn.setOnClickListener(v -> mention());
@Override
public void onClick(View v) {
mention();
}
});
followBtn.setOnClickListener(new View.OnClickListener() { followBtn.setOnClickListener(v -> {
@Override switch (followState) {
public void onClick(View v) { case NOT_FOLLOWING: {
switch (followState) { follow(accountId);
case NOT_FOLLOWING: { break;
follow(accountId); }
break; case REQUESTED: {
} showFollowRequestPendingDialog();
case REQUESTED: { break;
showFollowRequestPendingDialog(); }
break; case FOLLOWING: {
} showUnfollowWarningDialog();
case FOLLOWING: { break;
showUnfollowWarningDialog();
break;
}
} }
updateFollowButton(followBtn);
} }
updateFollowButton(followBtn);
}); });
} else { } else {
floatingBtn.hide(); floatingBtn.hide();
@ -560,47 +533,25 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
} }
private void onFollowFailure(final String id) { private void onFollowFailure(final String id) {
View.OnClickListener listener = new View.OnClickListener() { View.OnClickListener listener = v -> follow(id);
@Override
public void onClick(View v) {
follow(id);
}
};
Snackbar.make(container, R.string.error_generic, Snackbar.LENGTH_LONG) Snackbar.make(container, R.string.error_generic, Snackbar.LENGTH_LONG)
.setAction(R.string.action_retry, listener) .setAction(R.string.action_retry, listener)
.show(); .show();
} }
private void showFollowRequestPendingDialog() { private void showFollowRequestPendingDialog() {
DialogInterface.OnClickListener waitListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
};
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
.setMessage(R.string.dialog_message_follow_request) .setMessage(R.string.dialog_message_follow_request)
.setPositiveButton(android.R.string.ok, waitListener) .setPositiveButton(android.R.string.ok, null)
.show(); .show();
} }
private void showUnfollowWarningDialog() { private void showUnfollowWarningDialog() {
DialogInterface.OnClickListener cancelListener = new DialogInterface.OnClickListener() { DialogInterface.OnClickListener unfollowListener = (dialogInterface, i) -> follow(accountId);
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
};
DialogInterface.OnClickListener unfollowListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
follow(accountId);
}
};
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
.setMessage(R.string.dialog_unfollow_warning) .setMessage(R.string.dialog_unfollow_warning)
.setPositiveButton(android.R.string.ok, unfollowListener) .setPositiveButton(android.R.string.ok, unfollowListener)
.setNegativeButton(android.R.string.cancel, cancelListener) .setNegativeButton(android.R.string.cancel, null)
.show(); .show();
} }
@ -632,12 +583,7 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
} }
private void onBlockFailure(final String id) { private void onBlockFailure(final String id) {
View.OnClickListener listener = new View.OnClickListener() { View.OnClickListener listener = v -> block(id);
@Override
public void onClick(View v) {
block(id);
}
};
Snackbar.make(container, R.string.error_generic, Snackbar.LENGTH_LONG) Snackbar.make(container, R.string.error_generic, Snackbar.LENGTH_LONG)
.setAction(R.string.action_retry, listener) .setAction(R.string.action_retry, listener)
.show(); .show();
@ -672,12 +618,7 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
} }
private void onMuteFailure(final String id) { private void onMuteFailure(final String id) {
View.OnClickListener listener = new View.OnClickListener() { View.OnClickListener listener = v -> mute(id);
@Override
public void onClick(View v) {
mute(id);
}
};
Snackbar.make(container, R.string.error_generic, Snackbar.LENGTH_LONG) Snackbar.make(container, R.string.error_generic, Snackbar.LENGTH_LONG)
.setAction(R.string.action_retry, listener) .setAction(R.string.action_retry, listener)
.show(); .show();

Loading…
Cancel
Save