2017-01-28 14:33:43 +11:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* This file is a part of Tusky.
|
2017-01-28 14:33:43 +11:00
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-01-28 14:33:43 +11:00
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2017-04-10 10:12:31 +10:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
2017-01-28 14:33:43 +11:00
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2017-01-28 14:33:43 +11:00
|
|
|
|
|
|
|
package com.keylesspalace.tusky;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2017-03-03 11:25:35 +11:00
|
|
|
import android.graphics.drawable.Drawable;
|
2017-01-31 15:51:02 +11:00
|
|
|
import android.net.Uri;
|
2017-01-28 14:33:43 +11:00
|
|
|
import android.os.Bundle;
|
2017-03-07 18:28:12 +11:00
|
|
|
import android.support.annotation.AttrRes;
|
2017-01-28 14:33:43 +11:00
|
|
|
import android.support.annotation.Nullable;
|
2017-03-07 18:28:12 +11:00
|
|
|
import android.support.design.widget.AppBarLayout;
|
2017-03-07 06:48:31 +11:00
|
|
|
import android.support.design.widget.CollapsingToolbarLayout;
|
|
|
|
import android.support.design.widget.FloatingActionButton;
|
2017-01-31 15:51:02 +11:00
|
|
|
import android.support.design.widget.Snackbar;
|
2017-01-28 14:33:43 +11:00
|
|
|
import android.support.design.widget.TabLayout;
|
2017-03-07 18:28:12 +11:00
|
|
|
import android.support.v4.view.ViewCompat;
|
2017-01-28 14:33:43 +11:00
|
|
|
import android.support.v4.view.ViewPager;
|
|
|
|
import android.support.v7.app.ActionBar;
|
|
|
|
import android.support.v7.widget.Toolbar;
|
2017-02-02 07:20:39 +11:00
|
|
|
import android.text.method.LinkMovementMethod;
|
2017-01-28 14:33:43 +11:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2017-01-31 15:51:02 +11:00
|
|
|
import android.view.View;
|
2017-03-07 06:48:31 +11:00
|
|
|
import android.widget.ImageView;
|
2017-01-28 14:33:43 +11:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2017-03-09 09:19:03 +11:00
|
|
|
import com.keylesspalace.tusky.entity.Account;
|
2017-03-09 11:01:45 +11:00
|
|
|
import com.keylesspalace.tusky.entity.Relationship;
|
2017-03-07 06:48:31 +11:00
|
|
|
import com.pkmmte.view.CircularImageView;
|
|
|
|
import com.squareup.picasso.Picasso;
|
2017-01-28 14:33:43 +11:00
|
|
|
|
2017-04-05 06:36:42 +10:00
|
|
|
import java.text.NumberFormat;
|
2017-03-09 11:01:45 +11:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2017-01-28 14:33:43 +11:00
|
|
|
|
2017-03-15 01:27:22 +11:00
|
|
|
import butterknife.BindView;
|
|
|
|
import butterknife.ButterKnife;
|
2017-03-09 09:19:03 +11:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
2017-03-10 03:51:44 +11:00
|
|
|
import retrofit2.Response;
|
2017-03-09 09:19:03 +11:00
|
|
|
|
2017-02-17 05:52:55 +11:00
|
|
|
public class AccountActivity extends BaseActivity {
|
2017-03-10 10:20:08 +11:00
|
|
|
private static final String TAG = "AccountActivity"; // logging tag
|
2017-01-31 15:51:02 +11:00
|
|
|
|
|
|
|
private String accountId;
|
2017-01-28 14:33:43 +11:00
|
|
|
private boolean following = false;
|
|
|
|
private boolean blocking = false;
|
2017-03-10 03:51:44 +11:00
|
|
|
private boolean muting = false;
|
2017-02-20 11:27:15 +11:00
|
|
|
private boolean isSelf;
|
2017-01-31 15:51:02 +11:00
|
|
|
private TabLayout tabLayout;
|
2017-03-11 09:37:02 +11:00
|
|
|
private Account loadedAccount;
|
2017-01-28 14:33:43 +11:00
|
|
|
|
2017-03-15 01:27:22 +11:00
|
|
|
@BindView(R.id.account_locked) ImageView accountLockedView;
|
|
|
|
|
2017-01-28 14:33:43 +11:00
|
|
|
@Override
|
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_account);
|
2017-03-15 01:27:22 +11:00
|
|
|
ButterKnife.bind(this);
|
2017-01-28 14:33:43 +11:00
|
|
|
|
2017-04-05 06:36:42 +10:00
|
|
|
if (savedInstanceState != null) {
|
|
|
|
accountId = savedInstanceState.getString("accountId");
|
|
|
|
} else {
|
|
|
|
Intent intent = getIntent();
|
|
|
|
accountId = intent.getStringExtra("id");
|
|
|
|
}
|
2017-01-28 14:33:43 +11:00
|
|
|
|
|
|
|
SharedPreferences preferences = getSharedPreferences(
|
|
|
|
getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
|
2017-01-31 15:51:02 +11:00
|
|
|
String loggedInAccountId = preferences.getString("loggedInAccountId", null);
|
2017-01-28 14:33:43 +11:00
|
|
|
|
2017-03-07 18:28:12 +11:00
|
|
|
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
2017-01-28 14:33:43 +11:00
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
2017-03-07 06:48:31 +11:00
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
|
|
|
|
if (actionBar != null) {
|
|
|
|
actionBar.setTitle(null);
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
actionBar.setDisplayShowHomeEnabled(true);
|
|
|
|
}
|
|
|
|
|
2017-03-07 18:28:12 +11:00
|
|
|
// Add a listener to change the toolbar icon color when it enters/exits its collapsed state.
|
|
|
|
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.account_app_bar_layout);
|
|
|
|
final CollapsingToolbarLayout collapsingToolbar =
|
|
|
|
(CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
|
|
|
|
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
|
|
|
|
@AttrRes int priorAttribute = R.attr.account_toolbar_icon_tint_uncollapsed;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
|
|
|
|
@AttrRes int attribute;
|
|
|
|
if (collapsingToolbar.getHeight() + verticalOffset
|
|
|
|
< 2 * ViewCompat.getMinimumHeight(collapsingToolbar)) {
|
|
|
|
attribute = R.attr.account_toolbar_icon_tint_collapsed;
|
|
|
|
} else {
|
|
|
|
attribute = R.attr.account_toolbar_icon_tint_uncollapsed;
|
|
|
|
}
|
|
|
|
if (attribute != priorAttribute) {
|
|
|
|
priorAttribute = attribute;
|
|
|
|
Context context = toolbar.getContext();
|
|
|
|
ThemeUtils.setDrawableTint(context, toolbar.getNavigationIcon(), attribute);
|
|
|
|
ThemeUtils.setDrawableTint(context, toolbar.getOverflowIcon(), attribute);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-03-07 06:48:31 +11:00
|
|
|
FloatingActionButton floatingBtn = (FloatingActionButton) findViewById(R.id.floating_btn);
|
|
|
|
floatingBtn.hide();
|
|
|
|
|
|
|
|
CircularImageView avatar = (CircularImageView) findViewById(R.id.account_avatar);
|
|
|
|
ImageView header = (ImageView) findViewById(R.id.account_header);
|
|
|
|
avatar.setImageResource(R.drawable.avatar_default);
|
|
|
|
header.setImageResource(R.drawable.account_header_default);
|
2017-01-28 14:33:43 +11:00
|
|
|
|
2017-01-31 15:51:02 +11:00
|
|
|
obtainAccount();
|
|
|
|
if (!accountId.equals(loggedInAccountId)) {
|
2017-02-20 11:27:15 +11:00
|
|
|
isSelf = false;
|
2017-01-31 15:51:02 +11:00
|
|
|
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();
|
|
|
|
}
|
2017-01-28 14:33:43 +11:00
|
|
|
|
|
|
|
// Setup the tabs and timeline pager.
|
2017-02-23 06:13:51 +11:00
|
|
|
AccountPagerAdapter adapter = new AccountPagerAdapter(getSupportFragmentManager(), this,
|
|
|
|
accountId);
|
2017-01-28 14:33:43 +11:00
|
|
|
String[] pageTitles = {
|
2017-01-31 15:51:02 +11:00
|
|
|
getString(R.string.title_statuses),
|
|
|
|
getString(R.string.title_follows),
|
|
|
|
getString(R.string.title_followers)
|
2017-01-28 14:33:43 +11:00
|
|
|
};
|
|
|
|
adapter.setPageTitles(pageTitles);
|
|
|
|
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
|
2017-03-03 11:25:35 +11:00
|
|
|
int pageMargin = getResources().getDimensionPixelSize(R.dimen.tab_page_margin);
|
2017-02-03 11:18:41 +11:00
|
|
|
viewPager.setPageMargin(pageMargin);
|
2017-03-03 11:25:35 +11:00
|
|
|
Drawable pageMarginDrawable = ThemeUtils.getDrawable(this, R.attr.tab_page_margin_drawable,
|
|
|
|
R.drawable.tab_page_margin_dark);
|
|
|
|
viewPager.setPageMarginDrawable(pageMarginDrawable);
|
2017-01-28 14:33:43 +11:00
|
|
|
viewPager.setAdapter(adapter);
|
2017-01-31 15:51:02 +11:00
|
|
|
tabLayout = (TabLayout) findViewById(R.id.tab_layout);
|
2017-01-28 14:33:43 +11:00
|
|
|
tabLayout.setupWithViewPager(viewPager);
|
2017-01-31 15:51:02 +11:00
|
|
|
for (int i = 0; i < tabLayout.getTabCount(); i++) {
|
|
|
|
TabLayout.Tab tab = tabLayout.getTabAt(i);
|
2017-02-02 07:20:39 +11:00
|
|
|
if (tab != null) {
|
2017-02-23 06:13:51 +11:00
|
|
|
tab.setCustomView(adapter.getTabView(i, tabLayout));
|
2017-02-02 07:20:39 +11:00
|
|
|
}
|
2017-01-31 15:51:02 +11:00
|
|
|
}
|
2017-01-28 14:33:43 +11:00
|
|
|
}
|
|
|
|
|
2017-01-31 15:51:02 +11:00
|
|
|
private void obtainAccount() {
|
2017-03-09 09:19:03 +11:00
|
|
|
mastodonAPI.account(accountId).enqueue(new Callback<Account>() {
|
2017-01-28 14:33:43 +11:00
|
|
|
@Override
|
2017-03-09 09:19:03 +11:00
|
|
|
public void onResponse(Call<Account> call, retrofit2.Response<Account> response) {
|
2017-03-14 11:49:12 +11:00
|
|
|
if (response.isSuccessful()) {
|
|
|
|
onObtainAccountSuccess(response.body());
|
|
|
|
} else {
|
|
|
|
onObtainAccountFailure();
|
|
|
|
}
|
2017-01-28 14:33:43 +11:00
|
|
|
}
|
2017-03-09 09:19:03 +11:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Call<Account> call, Throwable t) {
|
|
|
|
onObtainAccountFailure();
|
|
|
|
}
|
|
|
|
});
|
2017-01-28 14:33:43 +11:00
|
|
|
}
|
|
|
|
|
2017-04-05 06:36:42 +10:00
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
outState.putString("accountId", accountId);
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
}
|
|
|
|
|
2017-01-31 15:51:02 +11:00
|
|
|
private void onObtainAccountSuccess(Account account) {
|
2017-03-11 09:37:02 +11:00
|
|
|
loadedAccount = account;
|
|
|
|
|
2017-01-28 14:33:43 +11:00
|
|
|
TextView username = (TextView) findViewById(R.id.account_username);
|
|
|
|
TextView displayName = (TextView) findViewById(R.id.account_display_name);
|
|
|
|
TextView note = (TextView) findViewById(R.id.account_note);
|
2017-03-07 06:48:31 +11:00
|
|
|
CircularImageView avatar = (CircularImageView) findViewById(R.id.account_avatar);
|
|
|
|
ImageView header = (ImageView) findViewById(R.id.account_header);
|
2017-01-28 14:33:43 +11:00
|
|
|
|
|
|
|
String usernameFormatted = String.format(
|
2017-01-31 15:51:02 +11:00
|
|
|
getString(R.string.status_username_format), account.username);
|
2017-01-28 14:33:43 +11:00
|
|
|
username.setText(usernameFormatted);
|
|
|
|
|
2017-03-11 09:31:08 +11:00
|
|
|
displayName.setText(account.getDisplayName());
|
2017-01-28 14:33:43 +11:00
|
|
|
|
2017-01-31 15:51:02 +11:00
|
|
|
note.setText(account.note);
|
|
|
|
note.setLinksClickable(true);
|
2017-02-02 07:20:39 +11:00
|
|
|
note.setMovementMethod(LinkMovementMethod.getInstance());
|
2017-01-28 14:33:43 +11:00
|
|
|
|
2017-03-15 01:27:22 +11:00
|
|
|
if (account.locked) {
|
|
|
|
accountLockedView.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
accountLockedView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2017-03-08 13:38:20 +11:00
|
|
|
Picasso.with(this)
|
|
|
|
.load(account.avatar)
|
|
|
|
.placeholder(R.drawable.avatar_default)
|
|
|
|
.error(R.drawable.avatar_error)
|
|
|
|
.into(avatar);
|
|
|
|
Picasso.with(this)
|
|
|
|
.load(account.header)
|
|
|
|
.placeholder(R.drawable.account_header_missing)
|
|
|
|
.into(header);
|
2017-01-31 15:51:02 +11:00
|
|
|
|
2017-04-05 06:36:42 +10:00
|
|
|
NumberFormat nf = NumberFormat.getInstance();
|
2017-01-31 15:51:02 +11:00
|
|
|
|
|
|
|
// Add counts to the tabs in the TabLayout.
|
|
|
|
String[] counts = {
|
2017-03-07 06:48:31 +11:00
|
|
|
nf.format(Integer.parseInt(account.statusesCount)),
|
|
|
|
nf.format(Integer.parseInt(account.followingCount)),
|
|
|
|
nf.format(Integer.parseInt(account.followersCount)),
|
2017-01-31 15:51:02 +11:00
|
|
|
};
|
2017-03-07 06:48:31 +11:00
|
|
|
|
2017-01-31 15:51:02 +11:00
|
|
|
for (int i = 0; i < tabLayout.getTabCount(); i++) {
|
|
|
|
TabLayout.Tab tab = tabLayout.getTabAt(i);
|
|
|
|
if (tab != null) {
|
|
|
|
View view = tab.getCustomView();
|
2017-02-02 07:20:39 +11:00
|
|
|
if (view != null) {
|
|
|
|
TextView total = (TextView) view.findViewById(R.id.total);
|
|
|
|
total.setText(counts[i]);
|
|
|
|
}
|
2017-01-31 15:51:02 +11:00
|
|
|
}
|
2017-01-28 14:33:43 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onObtainAccountFailure() {
|
2017-04-06 17:09:49 +10:00
|
|
|
Snackbar.make(tabLayout, R.string.error_generic, Snackbar.LENGTH_LONG)
|
2017-02-27 11:14:50 +11:00
|
|
|
.setAction(R.string.action_retry, new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
obtainAccount();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
2017-01-28 14:33:43 +11:00
|
|
|
}
|
|
|
|
|
2017-01-31 15:51:02 +11:00
|
|
|
private void obtainRelationships() {
|
2017-03-09 11:01:45 +11:00
|
|
|
List<String> ids = new ArrayList<>(1);
|
|
|
|
ids.add(accountId);
|
|
|
|
mastodonAPI.relationships(ids).enqueue(new Callback<List<Relationship>>() {
|
2017-01-28 14:33:43 +11:00
|
|
|
@Override
|
2017-03-09 11:01:45 +11:00
|
|
|
public void onResponse(Call<List<Relationship>> call, retrofit2.Response<List<Relationship>> response) {
|
2017-03-14 11:49:12 +11:00
|
|
|
if (response.isSuccessful()) {
|
|
|
|
Relationship relationship = response.body().get(0);
|
|
|
|
onObtainRelationshipsSuccess(relationship.following, relationship.blocking, relationship.muting);
|
|
|
|
} else {
|
|
|
|
onObtainRelationshipsFailure(new Exception(response.message()));
|
|
|
|
}
|
2017-01-28 14:33:43 +11:00
|
|
|
}
|
2017-03-09 11:01:45 +11:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Call<List<Relationship>> call, Throwable t) {
|
|
|
|
onObtainRelationshipsFailure((Exception) t);
|
|
|
|
}
|
|
|
|
});
|
2017-01-28 14:33:43 +11:00
|
|
|
}
|
|
|
|
|
2017-03-10 03:51:44 +11:00
|
|
|
private void onObtainRelationshipsSuccess(boolean following, boolean blocking, boolean muting) {
|
2017-01-28 14:33:43 +11:00
|
|
|
this.following = following;
|
|
|
|
this.blocking = blocking;
|
2017-03-10 03:51:44 +11:00
|
|
|
this.muting = muting;
|
2017-03-07 06:48:31 +11:00
|
|
|
|
2017-03-10 03:51:44 +11:00
|
|
|
if (!following || !blocking || !muting) {
|
2017-01-28 14:33:43 +11:00
|
|
|
invalidateOptionsMenu();
|
|
|
|
}
|
2017-03-07 06:48:31 +11:00
|
|
|
|
|
|
|
updateButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateButtons() {
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
|
2017-04-06 03:49:28 +10:00
|
|
|
final FloatingActionButton floatingBtn = (FloatingActionButton) findViewById(R.id.floating_btn);
|
2017-03-07 06:48:31 +11:00
|
|
|
|
2017-04-07 01:07:40 +10:00
|
|
|
if(!isSelf && !blocking) {
|
2017-03-07 06:48:31 +11:00
|
|
|
floatingBtn.show();
|
2017-04-07 01:07:40 +10:00
|
|
|
|
|
|
|
if (following) {
|
|
|
|
floatingBtn.setImageResource(R.drawable.ic_person_minus_24px);
|
|
|
|
} else {
|
|
|
|
floatingBtn.setImageResource(R.drawable.ic_person_add_24dp);
|
|
|
|
}
|
|
|
|
|
2017-03-07 06:48:31 +11:00
|
|
|
floatingBtn.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-04-07 01:07:40 +10:00
|
|
|
|
2017-03-07 06:48:31 +11:00
|
|
|
follow(accountId);
|
2017-04-07 01:07:40 +10:00
|
|
|
|
|
|
|
if (following) {
|
|
|
|
floatingBtn.setImageResource(R.drawable.ic_person_minus_24px);
|
|
|
|
} else {
|
|
|
|
floatingBtn.setImageResource(R.drawable.ic_person_add_24dp);
|
|
|
|
}
|
|
|
|
|
2017-03-07 06:48:31 +11:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-01-28 14:33:43 +11:00
|
|
|
}
|
|
|
|
|
2017-02-27 11:14:50 +11:00
|
|
|
private void onObtainRelationshipsFailure(Exception exception) {
|
|
|
|
Log.e(TAG, "Could not obtain relationships. " + exception.getMessage());
|
2017-01-28 14:33:43 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
getMenuInflater().inflate(R.menu.account_toolbar, menu);
|
|
|
|
return super.onCreateOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
2017-01-31 15:51:02 +11:00
|
|
|
if (!isSelf) {
|
|
|
|
MenuItem follow = menu.findItem(R.id.action_follow);
|
|
|
|
String title;
|
|
|
|
if (following) {
|
|
|
|
title = getString(R.string.action_unfollow);
|
|
|
|
} else {
|
|
|
|
title = getString(R.string.action_follow);
|
|
|
|
}
|
|
|
|
follow.setTitle(title);
|
|
|
|
MenuItem block = menu.findItem(R.id.action_block);
|
|
|
|
if (blocking) {
|
|
|
|
title = getString(R.string.action_unblock);
|
|
|
|
} else {
|
|
|
|
title = getString(R.string.action_block);
|
|
|
|
}
|
|
|
|
block.setTitle(title);
|
2017-03-10 03:51:44 +11:00
|
|
|
MenuItem mute = menu.findItem(R.id.action_mute);
|
|
|
|
if (muting) {
|
|
|
|
title = getString(R.string.action_unmute);
|
|
|
|
} else {
|
|
|
|
title = getString(R.string.action_mute);
|
|
|
|
}
|
|
|
|
mute.setTitle(title);
|
2017-01-28 14:33:43 +11:00
|
|
|
} else {
|
2017-01-31 15:51:02 +11:00
|
|
|
// It shouldn't be possible to block or follow yourself.
|
|
|
|
menu.removeItem(R.id.action_follow);
|
|
|
|
menu.removeItem(R.id.action_block);
|
2017-03-10 03:51:44 +11:00
|
|
|
menu.removeItem(R.id.action_mute);
|
2017-01-28 14:33:43 +11:00
|
|
|
}
|
|
|
|
return super.onPrepareOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
2017-03-09 11:01:45 +11:00
|
|
|
private void follow(final String id) {
|
|
|
|
Callback<Relationship> cb = new Callback<Relationship>() {
|
2017-01-31 15:51:02 +11:00
|
|
|
@Override
|
2017-03-09 11:01:45 +11:00
|
|
|
public void onResponse(Call<Relationship> call, retrofit2.Response<Relationship> response) {
|
2017-03-14 11:49:12 +11:00
|
|
|
if (response.isSuccessful()) {
|
|
|
|
following = response.body().following;
|
|
|
|
// TODO: display message/indicator when "requested" is true (i.e. when the follow is awaiting approval)
|
|
|
|
updateButtons();
|
|
|
|
} else {
|
|
|
|
onFollowFailure(id);
|
|
|
|
}
|
2017-03-09 11:01:45 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Call<Relationship> call, Throwable t) {
|
|
|
|
onFollowFailure(id);
|
2017-01-31 15:51:02 +11:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (following) {
|
2017-03-09 11:01:45 +11:00
|
|
|
mastodonAPI.unfollowAccount(id).enqueue(cb);
|
2017-01-31 15:51:02 +11:00
|
|
|
} else {
|
2017-03-09 11:01:45 +11:00
|
|
|
mastodonAPI.followAccount(id).enqueue(cb);
|
2017-01-31 15:51:02 +11:00
|
|
|
}
|
|
|
|
}
|
2017-01-28 14:33:43 +11:00
|
|
|
|
2017-01-31 15:51:02 +11:00
|
|
|
private void onFollowFailure(final String id) {
|
|
|
|
View.OnClickListener listener = new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
follow(id);
|
|
|
|
}
|
|
|
|
};
|
2017-04-06 17:09:49 +10:00
|
|
|
View anyView = findViewById(R.id.activity_account);
|
|
|
|
Snackbar.make(anyView, R.string.error_generic, Snackbar.LENGTH_LONG)
|
2017-01-31 15:51:02 +11:00
|
|
|
.setAction(R.string.action_retry, listener)
|
|
|
|
.show();
|
2017-01-28 14:33:43 +11:00
|
|
|
}
|
|
|
|
|
2017-01-31 15:51:02 +11:00
|
|
|
private void block(final String id) {
|
2017-03-09 11:01:45 +11:00
|
|
|
Callback<Relationship> cb = new Callback<Relationship>() {
|
|
|
|
@Override
|
|
|
|
public void onResponse(Call<Relationship> call, retrofit2.Response<Relationship> response) {
|
2017-03-14 11:49:12 +11:00
|
|
|
if (response.isSuccessful()) {
|
|
|
|
blocking = response.body().blocking;
|
|
|
|
updateButtons();
|
|
|
|
} else {
|
|
|
|
onBlockFailure(id);
|
|
|
|
}
|
2017-03-09 11:01:45 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Call<Relationship> call, Throwable t) {
|
|
|
|
onBlockFailure(id);
|
|
|
|
}
|
|
|
|
};
|
2017-01-31 15:51:02 +11:00
|
|
|
if (blocking) {
|
2017-03-09 11:01:45 +11:00
|
|
|
mastodonAPI.unblockAccount(id).enqueue(cb);
|
2017-01-31 15:51:02 +11:00
|
|
|
} else {
|
2017-03-09 11:01:45 +11:00
|
|
|
mastodonAPI.blockAccount(id).enqueue(cb);
|
2017-01-31 15:51:02 +11:00
|
|
|
}
|
|
|
|
}
|
2017-01-28 14:33:43 +11:00
|
|
|
|
2017-01-31 15:51:02 +11:00
|
|
|
private void onBlockFailure(final String id) {
|
|
|
|
View.OnClickListener listener = new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
block(id);
|
|
|
|
}
|
|
|
|
};
|
2017-04-06 17:09:49 +10:00
|
|
|
View anyView = findViewById(R.id.activity_account);
|
|
|
|
Snackbar.make(anyView, R.string.error_generic, Snackbar.LENGTH_LONG)
|
2017-01-31 15:51:02 +11:00
|
|
|
.setAction(R.string.action_retry, listener)
|
|
|
|
.show();
|
2017-01-28 14:33:43 +11:00
|
|
|
}
|
|
|
|
|
2017-03-10 03:51:44 +11:00
|
|
|
|
|
|
|
private void mute(final String id) {
|
|
|
|
Callback<Relationship> cb = new Callback<Relationship>() {
|
|
|
|
@Override
|
|
|
|
public void onResponse(Call<Relationship> call, Response<Relationship> response) {
|
2017-03-14 11:49:12 +11:00
|
|
|
if (response.isSuccessful()) {
|
|
|
|
muting = response.body().muting;
|
|
|
|
updateButtons();
|
|
|
|
} else {
|
|
|
|
onMuteFailure(id);
|
|
|
|
}
|
2017-03-10 03:51:44 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Call<Relationship> call, Throwable t) {
|
|
|
|
onMuteFailure(id);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (muting) {
|
|
|
|
mastodonAPI.unmuteAccount(id).enqueue(cb);
|
|
|
|
} else {
|
|
|
|
mastodonAPI.muteAccount(id).enqueue(cb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onMuteFailure(final String id) {
|
|
|
|
View.OnClickListener listener = new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
mute(id);
|
|
|
|
}
|
|
|
|
};
|
2017-04-06 17:09:49 +10:00
|
|
|
View anyView = findViewById(R.id.activity_account);
|
|
|
|
Snackbar.make(anyView, R.string.error_generic, Snackbar.LENGTH_LONG)
|
2017-03-10 03:51:44 +11:00
|
|
|
.setAction(R.string.action_retry, listener)
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-28 14:33:43 +11:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
2017-03-07 06:48:31 +11:00
|
|
|
case android.R.id.home: {
|
|
|
|
onBackPressed();
|
2017-01-28 14:33:43 +11:00
|
|
|
return true;
|
|
|
|
}
|
2017-03-11 09:37:02 +11:00
|
|
|
case R.id.action_mention: {
|
2017-03-28 13:13:55 +11:00
|
|
|
if (loadedAccount == null) {
|
|
|
|
// If the account isn't loaded yet, eat the input.
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-11 09:37:02 +11:00
|
|
|
Intent intent = new Intent(this, ComposeActivity.class);
|
|
|
|
intent.putExtra("mentioned_usernames", new String[] { loadedAccount.username });
|
|
|
|
startActivity(intent);
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-31 15:51:02 +11:00
|
|
|
case R.id.action_open_in_web: {
|
2017-03-20 13:38:39 +11:00
|
|
|
if (loadedAccount == null) {
|
2017-03-28 13:13:55 +11:00
|
|
|
// If the account isn't loaded yet, eat the input.
|
2017-03-20 13:38:39 +11:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Uri uri = Uri.parse(loadedAccount.url);
|
2017-01-31 15:51:02 +11:00
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
|
|
|
startActivity(intent);
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-28 14:33:43 +11:00
|
|
|
case R.id.action_follow: {
|
2017-01-31 15:51:02 +11:00
|
|
|
follow(accountId);
|
2017-01-28 14:33:43 +11:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case R.id.action_block: {
|
2017-01-31 15:51:02 +11:00
|
|
|
block(accountId);
|
2017-01-28 14:33:43 +11:00
|
|
|
return true;
|
|
|
|
}
|
2017-03-10 03:51:44 +11:00
|
|
|
case R.id.action_mute: {
|
|
|
|
mute(accountId);
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-28 14:33:43 +11:00
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|