diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java index bc3a0233..103bfb10 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java @@ -41,11 +41,13 @@ import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import com.keylesspalace.tusky.entity.Account; import com.keylesspalace.tusky.entity.Relationship; +import com.keylesspalace.tusky.interfaces.ActionButtonActivity; import com.keylesspalace.tusky.interfaces.LinkListener; import com.keylesspalace.tusky.pager.AccountPagerAdapter; import com.keylesspalace.tusky.receiver.TimelineReceiver; @@ -63,7 +65,7 @@ import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; -public class AccountActivity extends BaseActivity { +public class AccountActivity extends BaseActivity implements ActionButtonActivity { private static final String TAG = "AccountActivity"; // logging tag private enum FollowState { @@ -81,9 +83,13 @@ public class AccountActivity extends BaseActivity { private CircularImageView avatar; private ImageView header; private FloatingActionButton floatingBtn; + private Button followBtn; + private TextView followsYouView; private TabLayout tabLayout; private ImageView accountLockedView; private View container; + private boolean hideFab; + private int oldOffset; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -93,6 +99,8 @@ public class AccountActivity extends BaseActivity { avatar = (CircularImageView) findViewById(R.id.account_avatar); header = (ImageView) findViewById(R.id.account_header); floatingBtn = (FloatingActionButton) findViewById(R.id.floating_btn); + followBtn = (Button) findViewById(R.id.follow_btn); + followsYouView = (TextView) findViewById(R.id.account_follows_you); tabLayout = (TabLayout) findViewById(R.id.tab_layout); accountLockedView = (ImageView) findViewById(R.id.account_locked); container = findViewById(R.id.activity_account); @@ -124,6 +132,8 @@ public class AccountActivity extends BaseActivity { actionBar.setDisplayShowHomeEnabled(true); } + hideFab = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("fabHide", false); + // 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 = @@ -155,11 +165,23 @@ public class AccountActivity extends BaseActivity { ThemeUtils.setDrawableTint(context, toolbar.getNavigationIcon(), attribute); ThemeUtils.setDrawableTint(context, toolbar.getOverflowIcon(), attribute); } + + if(floatingBtn != null && hideFab && !isSelf && !blocking) { + if (verticalOffset > oldOffset) { + floatingBtn.show(); + } + if (verticalOffset < oldOffset) { + floatingBtn.hide(); + } + } + oldOffset = verticalOffset; } }); // Initialise the default UI states. floatingBtn.hide(); + followBtn.setVisibility(View.GONE); + followsYouView.setVisibility(View.GONE); // Obtain information to fill out the profile. obtainAccount(); @@ -321,8 +343,7 @@ public class AccountActivity extends BaseActivity { Response> response) { if (response.isSuccessful()) { Relationship relationship = response.body().get(0); - onObtainRelationshipsSuccess(relationship.requested, relationship.following, - relationship.blocking, relationship.muting); + onObtainRelationshipsSuccess(relationship); } else { onObtainRelationshipsFailure(new Exception(response.message())); } @@ -335,40 +356,38 @@ public class AccountActivity extends BaseActivity { }); } - private void onObtainRelationshipsSuccess(boolean followRequested, boolean following, - boolean blocking, boolean muting) { - if (following) { + private void onObtainRelationshipsSuccess(Relationship relation) { + if (relation.following) { followState = FollowState.FOLLOWING; - } else if (followRequested) { + } else if (relation.requested) { followState = FollowState.REQUESTED; } else { followState = FollowState.NOT_FOLLOWING; } - this.blocking = blocking; - this.muting = muting; + this.blocking = relation.blocking; + this.muting = relation.muting; - if (followState != FollowState.NOT_FOLLOWING || !blocking || !muting) { - invalidateOptionsMenu(); + if(relation.followedBy) { + followsYouView.setVisibility(View.VISIBLE); + } else { + followsYouView.setVisibility(View.GONE); } updateButtons(); } - private void updateFollowButton(FloatingActionButton button) { + private void updateFollowButton(Button button) { switch (followState) { case NOT_FOLLOWING: { - button.setImageResource(R.drawable.ic_person_add_24dp); - button.setContentDescription(getString(R.string.action_follow)); + button.setText(getString(R.string.action_follow)); break; } case REQUESTED: { - button.setImageResource(R.drawable.ic_hourglass_24dp); - button.setContentDescription(getString(R.string.state_follow_requested)); + button.setText(getString(R.string.state_follow_requested)); break; } case FOLLOWING: { - button.setImageResource(R.drawable.ic_person_minus_24px); - button.setContentDescription(getString(R.string.action_unfollow)); + button.setText(getString(R.string.action_unfollow)); break; } } @@ -379,20 +398,31 @@ public class AccountActivity extends BaseActivity { if(!isSelf && !blocking) { floatingBtn.show(); + followBtn.setVisibility(View.VISIBLE); - updateFollowButton(floatingBtn); + updateFollowButton(followBtn); floatingBtn.setOnClickListener(new View.OnClickListener() { @Override 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); } else { showFollowRequestPendingDialog(accountId); } - updateFollowButton(floatingBtn); + updateFollowButton(followBtn); } }); + } else { + floatingBtn.hide(); + followBtn.setVisibility(View.GONE); } } @@ -543,7 +573,6 @@ public class AccountActivity extends BaseActivity { .show(); } - private void mute(final String id) { Callback cb = new Callback() { @Override @@ -582,6 +611,17 @@ public class AccountActivity extends BaseActivity { .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) { Intent intent = new Intent(action); intent.putExtra("id", id); @@ -596,14 +636,7 @@ public class AccountActivity extends BaseActivity { return true; } case R.id.action_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; + return mention(); } case R.id.action_open_in_web: { if (loadedAccount == null) { @@ -630,4 +663,14 @@ public class AccountActivity extends BaseActivity { } return super.onOptionsItemSelected(item); } + + @Nullable + @Override + public FloatingActionButton getActionButton() { + if(!isSelf && !blocking) { + return floatingBtn; + } + return null; + } + } diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index 1e034837..7a3a64d5 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -23,6 +23,7 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.PersistableBundle; +import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.TabLayout; import android.support.graphics.drawable.VectorDrawableCompat; @@ -37,6 +38,7 @@ import android.widget.ImageButton; import android.widget.ImageView; import com.keylesspalace.tusky.entity.Account; +import com.keylesspalace.tusky.interfaces.ActionButtonActivity; import com.keylesspalace.tusky.pager.TimelinePagerAdapter; import com.keylesspalace.tusky.receiver.TimelineReceiver; import com.keylesspalace.tusky.util.ThemeUtils; @@ -63,7 +65,7 @@ import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; -public class MainActivity extends BaseActivity { +public class MainActivity extends BaseActivity implements ActionButtonActivity { private static final String TAG = "MainActivity"; // logging tag private static final long DRAWER_ITEM_EDIT_PROFILE = 0; private static final long DRAWER_ITEM_FAVOURITES = 1; @@ -77,7 +79,8 @@ public class MainActivity extends BaseActivity { private static final long DRAWER_ITEM_SAVED_TOOT = 9; protected static int COMPOSE_RESULT = 1; - public FloatingActionButton composeButton; + + private FloatingActionButton composeButton; private String loggedInAccountId; private String loggedInAccountUsername; private Stack pageHistory; @@ -493,4 +496,10 @@ public class MainActivity extends BaseActivity { private void onFetchUserInfoFailure(Exception exception) { Log.e(TAG, "Failed to fetch user info. " + exception.getMessage()); } + + @Nullable + @Override + public FloatingActionButton getActionButton() { + return composeButton; + } } \ No newline at end of file diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/AccountListFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/AccountListFragment.java index e37cbd57..a3f81c0d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/AccountListFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/AccountListFragment.java @@ -17,9 +17,12 @@ package com.keylesspalace.tusky.fragment; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.annotation.Nullable; +import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.design.widget.TabLayout; import android.support.v7.widget.DividerItemDecoration; @@ -42,6 +45,7 @@ import com.keylesspalace.tusky.BaseActivity; import com.keylesspalace.tusky.entity.Account; import com.keylesspalace.tusky.entity.Relationship; import com.keylesspalace.tusky.interfaces.AccountActionListener; +import com.keylesspalace.tusky.interfaces.ActionButtonActivity; import com.keylesspalace.tusky.network.MastodonApi; import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.util.HttpHeaderLink; @@ -77,6 +81,7 @@ public class AccountListFragment extends BaseFragment implements AccountActionLi private int bottomFetches; private boolean topLoading; private int topFetches; + private boolean hideFab; public static AccountListFragment newInstance(Type type) { Bundle arguments = new Bundle(); @@ -168,15 +173,56 @@ public class AccountListFragment extends BaseFragment implements AccountActionLi * activity is created, so everything needing to access the api object has to be delayed * until here. */ api = activity.mastodonApi; - scrollListener = new EndlessOnScrollListener(layoutManager) { - @Override - public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { - AccountListFragment.this.onLoadMore(view); - } - }; + + + if (actionButtonPresent()) { + /* Use a modified scroll listener that both loads more statuses as it goes, and hides + * the follow button on down-scroll. */ + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext()); + hideFab = preferences.getBoolean("fabHide", false); + scrollListener = new EndlessOnScrollListener(layoutManager) { + @Override + public void onScrolled(RecyclerView view, int dx, int dy) { + super.onScrolled(view, dx, dy); + + ActionButtonActivity actionButtonActivity = (ActionButtonActivity) getActivity(); + FloatingActionButton composeButton = actionButtonActivity.getActionButton(); + + if (composeButton != null) { + if (hideFab) { + if (dy > 0 && composeButton.isShown()) { + composeButton.hide(); // hides the button if we're scrolling down + } else if (dy < 0 && !composeButton.isShown()) { + composeButton.show(); // shows it if we are scrolling up + } + } else if (!composeButton.isShown()) { + composeButton.show(); + } + } + } + + @Override + public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { + AccountListFragment.this.onLoadMore(view); + } + }; + } else { + // Just use the basic scroll listener to load more accounts. + scrollListener = new EndlessOnScrollListener(layoutManager) { + @Override + public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { + AccountListFragment.this.onLoadMore(view); + } + }; + } + recyclerView.addOnScrollListener(scrollListener); } + private boolean actionButtonPresent() { + return type == Type.FOLLOWS || type == Type.FOLLOWERS; + } + @Override public void onDestroyView() { if (jumpToTopAllowed()) { diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java index 91f20654..f4de5665 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java @@ -40,6 +40,7 @@ import com.keylesspalace.tusky.adapter.NotificationsAdapter; import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.entity.Notification; import com.keylesspalace.tusky.entity.Status; +import com.keylesspalace.tusky.interfaces.ActionButtonActivity; import com.keylesspalace.tusky.interfaces.StatusActionListener; import com.keylesspalace.tusky.receiver.TimelineReceiver; import com.keylesspalace.tusky.util.HttpHeaderLink; @@ -172,9 +173,7 @@ public class NotificationsFragment extends SFragment implements * guaranteed to be set until then. * Use a modified scroll listener that both loads more notifications as it goes, and hides * the compose button on down-scroll. */ - final FloatingActionButton composeButton = activity.composeButton; - final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences( - activity); + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); preferences.registerOnSharedPreferenceChangeListener(this); hideFab = preferences.getBoolean("fabHide", false); scrollListener = new EndlessOnScrollListener(layoutManager) { @@ -182,14 +181,19 @@ public class NotificationsFragment extends SFragment implements public void onScrolled(RecyclerView view, int dx, int dy) { super.onScrolled(view, dx, dy); - if (hideFab) { - if (dy > 0 && composeButton.isShown()) { - composeButton.hide(); // hides the button if we're scrolling down - } else if (dy < 0 && !composeButton.isShown()) { - composeButton.show(); // shows it if we are scrolling up + ActionButtonActivity activity = (ActionButtonActivity) getActivity(); + FloatingActionButton composeButton = activity.getActionButton(); + + if(composeButton != null) { + if (hideFab) { + if (dy > 0 && composeButton.isShown()) { + composeButton.hide(); // hides the button if we're scrolling down + } else if (dy < 0 && !composeButton.isShown()) { + composeButton.show(); // shows it if we are scrolling up + } + } else if (!composeButton.isShown()) { + composeButton.show(); } - } else if (!composeButton.isShown()) { - composeButton.show(); } } diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java index 0141dd37..103f7e81 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java @@ -34,11 +34,11 @@ import android.view.View; import android.view.ViewGroup; import com.keylesspalace.tusky.BuildConfig; -import com.keylesspalace.tusky.MainActivity; import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.adapter.FooterViewHolder; import com.keylesspalace.tusky.adapter.TimelineAdapter; import com.keylesspalace.tusky.entity.Status; +import com.keylesspalace.tusky.interfaces.ActionButtonActivity; import com.keylesspalace.tusky.interfaces.StatusActionListener; import com.keylesspalace.tusky.network.MastodonApi; import com.keylesspalace.tusky.receiver.TimelineReceiver; @@ -195,28 +195,30 @@ public class TimelineFragment extends SFragment implements /* This is delayed until onActivityCreated solely because MainActivity.composeButton isn't * guaranteed to be set until then. */ - if (composeButtonPresent()) { + if (actionButtonPresent()) { /* Use a modified scroll listener that both loads more statuses as it goes, and hides * the follow button on down-scroll. */ - MainActivity activity = (MainActivity) getActivity(); - final FloatingActionButton composeButton = activity.composeButton; - final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences( - activity); + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext()); hideFab = preferences.getBoolean("fabHide", false); scrollListener = new EndlessOnScrollListener(layoutManager) { @Override public void onScrolled(RecyclerView view, int dx, int dy) { super.onScrolled(view, dx, dy); - if (hideFab) { - if (dy > 0 && composeButton.isShown()) { - composeButton.hide(); // hides the button if we're scrolling down - } else if (dy < 0 && !composeButton.isShown()) { - composeButton.show(); // shows it if we are scrolling up + ActionButtonActivity activity = (ActionButtonActivity) getActivity(); + FloatingActionButton composeButton = activity.getActionButton(); + + if (composeButton != null) { + if (hideFab) { + if (dy > 0 && composeButton.isShown()) { + composeButton.hide(); // hides the button if we're scrolling down + } else if (dy < 0 && !composeButton.isShown()) { + composeButton.show(); // shows it if we are scrolling up + } + } else if (!composeButton.isShown()) { + composeButton.show(); } - } else if (!composeButton.isShown()) { - composeButton.show(); - } + } } @Override @@ -438,8 +440,8 @@ public class TimelineFragment extends SFragment implements return kind != Kind.TAG && kind != Kind.FAVOURITES; } - private boolean composeButtonPresent() { - return kind != Kind.TAG && kind != Kind.FAVOURITES && kind != Kind.USER; + private boolean actionButtonPresent() { + return kind != Kind.TAG && kind != Kind.FAVOURITES; } private void jumpToTop() { diff --git a/app/src/main/java/com/keylesspalace/tusky/interfaces/ActionButtonActivity.java b/app/src/main/java/com/keylesspalace/tusky/interfaces/ActionButtonActivity.java new file mode 100644 index 00000000..faf2352d --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/interfaces/ActionButtonActivity.java @@ -0,0 +1,26 @@ +/* Copyright 2017 Andrew Dawson + * + * This file is a part of Tusky. + * + * 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. + * + * Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Tusky; if not, + * see . */ + +package com.keylesspalace.tusky.interfaces; + +import android.support.annotation.Nullable; +import android.support.design.widget.FloatingActionButton; + +public interface ActionButtonActivity { + + /* return the ActionButton of the Activity to hide or show it on scroll */ + @Nullable + FloatingActionButton getActionButton(); +} diff --git a/app/src/main/res/color/account_tab_font_color.xml b/app/src/main/res/color/account_tab_font_color.xml new file mode 100644 index 00000000..accc21cb --- /dev/null +++ b/app/src/main/res/color/account_tab_font_color.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_hourglass_24dp.xml b/app/src/main/res/drawable/ic_hourglass_24dp.xml deleted file mode 100644 index 22c1f349..00000000 --- a/app/src/main/res/drawable/ic_hourglass_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_person_minus_24px.xml b/app/src/main/res/drawable/ic_person_minus_24px.xml deleted file mode 100644 index c8a7ea0b..00000000 --- a/app/src/main/res/drawable/ic_person_minus_24px.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_account.xml b/app/src/main/res/layout/activity_account.xml index ee853c1e..a1788cb4 100644 --- a/app/src/main/res/layout/activity_account.xml +++ b/app/src/main/res/layout/activity_account.xml @@ -1,6 +1,7 @@ - - + +