diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-07-09 04:27:21 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-07-09 04:27:21 +0000 |
commit | 70264ee6321660414069cda09ce076eb007478d4 (patch) | |
tree | 693773a6be868f2d034a062b9c8d540963347595 | |
parent | 4fb2e3cc20feecc18932473b0a24ccb8391916a1 (diff) | |
download | infinity-for-reddit-70264ee6321660414069cda09ce076eb007478d4.tar infinity-for-reddit-70264ee6321660414069cda09ce076eb007478d4.tar.gz infinity-for-reddit-70264ee6321660414069cda09ce076eb007478d4.tar.bz2 infinity-for-reddit-70264ee6321660414069cda09ce076eb007478d4.tar.lz infinity-for-reddit-70264ee6321660414069cda09ce076eb007478d4.tar.xz infinity-for-reddit-70264ee6321660414069cda09ce076eb007478d4.tar.zst infinity-for-reddit-70264ee6321660414069cda09ce076eb007478d4.zip |
Fix fab does not show in MultiReditListingFragment when first entering SubscribedThingListingActivity.
4 files changed, 37 insertions, 29 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java index 797a1b63..38a2f84c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit.Activity; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; @@ -19,6 +20,7 @@ import androidx.viewpager.widget.ViewPager; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.tabs.TabLayout; import com.r0adkll.slidr.Slidr; import com.r0adkll.slidr.model.SlidrInterface; @@ -77,6 +79,8 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti TabLayout tabLayout; @BindView(R.id.view_pager_subscribed_thing_listing_activity) ViewPager viewPager; + @BindView(R.id.fab_subscribed_thing_listing_activity) + public FloatingActionButton fab; @Inject @Named("oauth") Retrofit mOauthRetrofit; @@ -124,6 +128,13 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti if (isImmersiveInterface()) { window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); adjustToolbar(toolbar); + + int navBarHeight = getNavBarHeight(); + if (navBarHeight > 0) { + CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); + params.bottomMargin = navBarHeight; + fab.setLayoutParams(params); + } } } @@ -163,6 +174,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); applyTabLayoutTheme(tabLayout); + applyFABTheme(fab); } private void getCurrentAccountAndInitializeViewPager() { @@ -178,6 +190,10 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti } private void initializeViewPagerAndLoadSubscriptions() { + fab.setOnClickListener(view -> { + Intent intent = new Intent(this, CreateMultiRedditActivity.class); + startActivity(intent); + }); sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(sectionsPagerAdapter); viewPager.setOffscreenPageLimit(3); @@ -186,8 +202,14 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti public void onPageSelected(int position) { if (position == 0) { unlockSwipeRightToGoBack(); + fab.hide(); } else { lockSwipeRightToGoBack(); + if (position == 1) { + fab.hide(); + } else { + fab.show(); + } } } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java index 1a58e526..21bde76a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java @@ -1,9 +1,7 @@ package ml.docilealligator.infinityforreddit.Fragment; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.ColorStateList; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; @@ -15,7 +13,6 @@ import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.LinearLayoutManager; @@ -24,7 +21,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; -import com.google.android.material.floatingactionbutton.FloatingActionButton; import javax.inject.Inject; import javax.inject.Named; @@ -33,7 +29,6 @@ import butterknife.BindView; import butterknife.ButterKnife; import me.zhanghai.android.fastscroll.FastScrollerBuilder; import ml.docilealligator.infinityforreddit.Activity.BaseActivity; -import ml.docilealligator.infinityforreddit.Activity.CreateMultiRedditActivity; import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity; import ml.docilealligator.infinityforreddit.Adapter.MultiRedditListingRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; @@ -60,8 +55,6 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm ImageView mErrorImageView; @BindView(R.id.fetch_multi_reddit_listing_info_text_view_multi_reddit_listing_fragment) TextView mErrorTextView; - @BindView(R.id.fab_multi_reddit_listing_fragment) - FloatingActionButton fab; @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject @@ -74,7 +67,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm CustomThemeWrapper mCustomThemeWrapper; public MultiRedditViewModel mMultiRedditViewModel; - private AppCompatActivity mActivity; + private SubscribedThingListingActivity mActivity; private RequestManager mGlide; private LinearLayoutManager mLinearLayoutManager; @@ -109,11 +102,6 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm mGlide = Glide.with(this); - fab.setOnClickListener(view -> { - Intent intent = new Intent(mActivity, CreateMultiRedditActivity.class); - startActivity(intent); - }); - mLinearLayoutManager = new LinearLayoutManager(mActivity); mRecyclerView.setLayoutManager(mLinearLayoutManager); MultiRedditListingRecyclerViewAdapter adapter = new MultiRedditListingRecyclerViewAdapter(mActivity, @@ -124,9 +112,9 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); if (dy > 0) { - fab.hide(); + mActivity.fab.hide(); } else { - fab.show(); + mActivity.fab.show(); } } }); @@ -136,7 +124,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm new MultiRedditViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, accountName)) .get(MultiRedditViewModel.class); - mMultiRedditViewModel.getAllMultiReddits().observe(this, subscribedUserData -> { + mMultiRedditViewModel.getAllMultiReddits().observe(getViewLifecycleOwner(), subscribedUserData -> { if (subscribedUserData == null || subscribedUserData.size() == 0) { mRecyclerView.setVisibility(View.GONE); mErrorLinearLayout.setVisibility(View.VISIBLE); @@ -149,7 +137,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm adapter.setMultiReddits(subscribedUserData); }); - mMultiRedditViewModel.getAllFavoriteMultiReddits().observe(this, favoriteSubscribedUserData -> { + mMultiRedditViewModel.getAllFavoriteMultiReddits().observe(getViewLifecycleOwner(), favoriteSubscribedUserData -> { if (favoriteSubscribedUserData != null && favoriteSubscribedUserData.size() > 0) { mErrorLinearLayout.setVisibility(View.GONE); mRecyclerView.setVisibility(View.VISIBLE); @@ -170,7 +158,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - mActivity = (AppCompatActivity) context; + mActivity = (SubscribedThingListingActivity) context; } @Override @@ -184,8 +172,6 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm } mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); - fab.setBackgroundTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorPrimaryLightTheme())); - fab.setImageTintList(ColorStateList.valueOf(mCustomThemeWrapper.getFABIconColor())); } @Override diff --git a/app/src/main/res/layout/activity_subscribed_thing_listing.xml b/app/src/main/res/layout/activity_subscribed_thing_listing.xml index bad81ce5..6ff42767 100644 --- a/app/src/main/res/layout/activity_subscribed_thing_listing.xml +++ b/app/src/main/res/layout/activity_subscribed_thing_listing.xml @@ -51,4 +51,13 @@ android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + <com.google.android.material.floatingactionbutton.FloatingActionButton + android:id="@+id/fab_subscribed_thing_listing_activity" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="@dimen/fab_margin" + android:layout_gravity="bottom|end" + android:visibility="gone" + app:srcCompat="@drawable/ic_add_day_night_24dp" /> + </androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/fragment_multi_reddit_listing.xml b/app/src/main/res/layout/fragment_multi_reddit_listing.xml index f9c3ec74..6629e56c 100644 --- a/app/src/main/res/layout/fragment_multi_reddit_listing.xml +++ b/app/src/main/res/layout/fragment_multi_reddit_listing.xml @@ -44,13 +44,4 @@ </LinearLayout> - <com.google.android.material.floatingactionbutton.FloatingActionButton - android:id="@+id/fab_multi_reddit_listing_fragment" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_margin="@dimen/fab_margin" - android:layout_gravity="bottom|end" - app:srcCompat="@drawable/ic_add_day_night_24dp" - app:tint="@android:color/white" /> - </androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file |