From de0f1b7ab0ca7a102a84de7fd1400462afd965d8 Mon Sep 17 00:00:00 2001 From: Zachary Epps Date: Fri, 7 Apr 2017 03:40:59 -0400 Subject: [PATCH 1/2] added new option in preferences.xml modified MainActivity so that the "compose new toot" button is exposed as a static (had to copy its reference into a new variable so as to not upset BindView) modified TimelineFragment so that when the RecycleView is instantiated we overload the onScroll so that we can hide the FAB --- .../com/keylesspalace/tusky/MainActivity.java | 4 ++++ .../keylesspalace/tusky/TimelineFragment.java | 19 ++++++++++++++++++- app/src/main/res/xml/preferences.xml | 5 +++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index dd651af5..a75e869e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -77,6 +77,8 @@ public class MainActivity extends BaseActivity { @BindView(R.id.tab_layout) TabLayout tabLayout; @BindView(R.id.pager) ViewPager viewPager; + static FloatingActionButton composeBtn; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -176,6 +178,8 @@ public class MainActivity extends BaseActivity { // Setup push notifications if (arePushNotificationsEnabled()) enablePushNotifications(); + + composeBtn = floatingBtn; } @Override diff --git a/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java b/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java index 27a96dc8..0bcb2dfb 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java @@ -16,9 +16,12 @@ package com.keylesspalace.tusky; import android.content.Context; +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.TabLayout; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.DividerItemDecoration; @@ -85,7 +88,7 @@ public class TimelineFragment extends SFragment implements hashtagOrId = arguments.getString("hashtag_or_id"); } - View rootView = inflater.inflate(R.layout.fragment_timeline, container, false); + final View rootView = inflater.inflate(R.layout.fragment_timeline, container, false); // Setup the SwipeRefreshLayout. Context context = getContext(); @@ -103,6 +106,20 @@ public class TimelineFragment extends SFragment implements divider.setDrawable(drawable); recyclerView.addItemDecoration(divider); scrollListener = new EndlessOnScrollListener(layoutManager) { + @Override + public void onScrolled(RecyclerView view, int dx, int dy) { + super.onScrolled(view, dx, dy); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); + + if (dy > 0 && prefs.getBoolean("fabHide", false) && MainActivity.composeBtn.isShown()) { + MainActivity.composeBtn.hide(); // hides the button if we're scrolling down + } else if (dy < 0 && prefs.getBoolean("fabHide", false) && !MainActivity.composeBtn.isShown()) { + MainActivity.composeBtn.show(); // shows it if we are scrolling up + } + + } + @Override public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { TimelineAdapter adapter = (TimelineAdapter) view.getAdapter(); diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index f1771636..c9adf0e9 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -9,6 +9,11 @@ android:title="@string/pref_title_light_theme" android:defaultValue="false" /> + + From 2a418e06da843fa2073165570d6020876f42f10c Mon Sep 17 00:00:00 2001 From: Zachary Epps Date: Fri, 7 Apr 2017 04:14:25 -0400 Subject: [PATCH 2/2] changed the construction of the AccountHeader so that it listens for clicks on the current profile avatar and opens the user's account if they click on it --- .../com/keylesspalace/tusky/MainActivity.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index a75e869e..662c4e0f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -49,6 +49,7 @@ import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; import com.mikepenz.materialdrawer.model.ProfileDrawerItem; import com.mikepenz.materialdrawer.model.SecondaryDrawerItem; import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; +import com.mikepenz.materialdrawer.model.interfaces.IProfile; import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader; import com.mikepenz.materialdrawer.util.DrawerImageLoader; import com.squareup.picasso.Picasso; @@ -212,6 +213,23 @@ public class MainActivity extends BaseActivity { .withActivity(this) .withSelectionListEnabledForSingleProfile(false) .withDividerBelowHeader(false) + .withOnAccountHeaderProfileImageListener(new AccountHeader.OnAccountHeaderProfileImageListener() { + @Override + public boolean onProfileImageClick(View view, IProfile profile, boolean current) { + if (current && loggedInAccountId != null) { + Intent intent = new Intent(MainActivity.this, AccountActivity.class); + intent.putExtra("id", loggedInAccountId); + startActivity(intent); + return true; + } + return false; + } + + @Override + public boolean onProfileImageLongClick(View view, IProfile profile, boolean current) { + return false; + } + }) .withCompactStyle(true) .build();