Fix fab jumps to top-left of the screen. Add more items in the bottom app bar. Add a bottom app bar in ViewSubredditDetailActivity.

This commit is contained in:
Alex Ning 2020-02-02 17:48:25 +08:00
parent b09701918f
commit 51d7965527
7 changed files with 232 additions and 83 deletions

View File

@ -166,16 +166,20 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
RecyclerView accountRecyclerView;
@BindView(R.id.tab_layout_main_activity)
TabLayout tabLayout;
@BindView(R.id.fab_main_activity)
FloatingActionButton fab;
@BindView(R.id.bottom_navigation_main_activity)
BottomAppBar bottomNavigationView;
@BindView(R.id.linear_layout_bottom_app_bar_main_activity)
LinearLayout linearLayoutBottomAppBar;
@BindView(R.id.subscriptions_bottom_app_bar_main_activity)
TextView subscriptionsBottomAppBar;
ImageView subscriptionsBottomAppBar;
@BindView(R.id.multi_reddit_bottom_app_bar_main_activity)
TextView multiRedditBottomAppBar;
ImageView multiRedditBottomAppBar;
@BindView(R.id.message_bottom_app_bar_main_activity)
ImageView messageBottomAppBar;
@BindView(R.id.profile_bottom_app_bar_main_activity)
ImageView profileBottomAppBar;
@BindView(R.id.fab_main_activity)
FloatingActionButton fab;
AccountViewModel accountViewModel;
@Inject
@Named("oauth")
@ -338,8 +342,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
getCurrentAccountAndBindView();
}
fab.setOnClickListener(view -> postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()));
}
@Override
@ -460,14 +462,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} else {
if (showBottomAppBar) {
bottomNavigationView.setVisibility(View.VISIBLE);
} else {
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
lp.setAnchorId(View.NO_ID);
lp.gravity = Gravity.END | Gravity.BOTTOM;
fab.setLayoutParams(lp);
}
fab.setVisibility(View.VISIBLE);
subscriptionsBottomAppBar.setOnClickListener(view -> {
Intent intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
startActivity(intent);
@ -477,6 +471,26 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
Intent intent = new Intent(MainActivity.this, MultiRedditListingActivity.class);
startActivity(intent);
});
messageBottomAppBar.setOnClickListener(view -> {
Intent intent = new Intent(this, ViewMessageActivity.class);
startActivity(intent);
});
profileBottomAppBar.setOnClickListener(view -> {
Intent intent = new Intent(this, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mAccountName);
startActivity(intent);
});
} else {
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
lp.setAnchorId(View.NO_ID);
lp.gravity = Gravity.END | Gravity.BOTTOM;
fab.setLayoutParams(lp);
}
fab.setOnClickListener(view -> postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()));
fab.setVisibility(View.VISIBLE);
}
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
@ -491,8 +505,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
@Override
public void onPageSelected(int position) {
if (mAccessToken != null && showBottomAppBar) {
if (mAccessToken != null) {
if (showBottomAppBar) {
bottomNavigationView.performShow();
}
fab.show();
}
if (isInLazyMode) {
@ -956,18 +972,22 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
public void postScrollUp() {
if (mAccessToken != null && showBottomAppBar) {
if (mAccessToken != null) {
if (showBottomAppBar) {
bottomNavigationView.performShow();
}
fab.show();
}
}
public void postScrollDown() {
if (mAccessToken != null && showBottomAppBar) {
if (mAccessToken != null) {
fab.hide();
if (showBottomAppBar) {
bottomNavigationView.performHide();
}
}
}
@Subscribe
public void onAccountSwitchEvent(SwitchAccountEvent event) {

View File

@ -6,6 +6,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
@ -13,6 +14,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
@ -27,6 +30,7 @@ import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.chip.Chip;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
@ -107,6 +111,18 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
TextView nOnlineSubscribersTextView;
@BindView(R.id.description_text_view_view_subreddit_detail_activity)
TextView descriptionTextView;
@BindView(R.id.bottom_navigation_view_subreddit_detail_activity)
BottomAppBar bottomNavigationView;
@BindView(R.id.linear_layout_bottom_app_bar_view_subreddit_detail_activity)
LinearLayout linearLayoutBottomAppBar;
@BindView(R.id.subscriptions_bottom_app_bar_view_subreddit_detail_activity)
ImageView subscriptionsBottomAppBar;
@BindView(R.id.multi_reddit_bottom_app_bar_view_subreddit_detail_activity)
ImageView multiRedditBottomAppBar;
@BindView(R.id.message_bottom_app_bar_view_subreddit_detail_activity)
ImageView messageBottomAppBar;
@BindView(R.id.profile_bottom_app_bar_view_subreddit_detail_activity)
ImageView profileBottomAppBar;
@BindView(R.id.fab_view_subreddit_detail_activity)
FloatingActionButton fab;
@Inject
@ -128,6 +144,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private boolean subscriptionReady = false;
private boolean isInLazyMode = false;
private boolean showToast = false;
private boolean showBottomAppBar;
private String mMessageFullname;
private String mNewAccountName;
private RequestManager glide;
@ -254,6 +271,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
toolbar.setLayoutParams(toolbarParams);
setSupportActionBar(toolbar);
showBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY, false);
glide = Glide.with(this);
mSubredditViewModel = new ViewModelProvider(this,
@ -311,15 +330,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
}
});
fab.setOnClickListener(view -> {
if (mAccessToken == null) {
Toast.makeText(ViewSubredditDetailActivity.this, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag());
});
}
@Override
@ -388,7 +398,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
private void bindView(boolean initializeFragment) {
if (mAccessToken != null && mMessageFullname != null) {
if (mAccessToken != null) {
if (mMessageFullname != null) {
ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() {
@Override
public void readSuccess() {
@ -402,6 +413,42 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
});
}
if (showBottomAppBar) {
bottomNavigationView.setVisibility(View.VISIBLE);
subscriptionsBottomAppBar.setOnClickListener(view -> {
Intent intent = new Intent(ViewSubredditDetailActivity.this, SubscribedThingListingActivity.class);
startActivity(intent);
});
multiRedditBottomAppBar.setOnClickListener(view -> {
Intent intent = new Intent(ViewSubredditDetailActivity.this, MultiRedditListingActivity.class);
startActivity(intent);
});
messageBottomAppBar.setOnClickListener(view -> {
Intent intent = new Intent(this, ViewMessageActivity.class);
startActivity(intent);
});
profileBottomAppBar.setOnClickListener(view -> {
Intent intent = new Intent(this, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mAccountName);
startActivity(intent);
});
} else {
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
lp.setAnchorId(View.NO_ID);
lp.gravity = Gravity.END | Gravity.BOTTOM;
fab.setLayoutParams(lp);
}
fab.setOnClickListener(view -> postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()));
fab.setVisibility(View.VISIBLE);
} else {
bottomNavigationView.setVisibility(View.GONE);
fab.setVisibility(View.GONE);
}
subscribeSubredditChip.setOnClickListener(view -> {
if (mAccessToken == null) {
Toast.makeText(ViewSubredditDetailActivity.this, R.string.login_first, Toast.LENGTH_SHORT).show();
@ -642,11 +689,21 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
public void postScrollUp() {
if (mAccessToken != null) {
if (showBottomAppBar) {
bottomNavigationView.performShow();
}
fab.show();
}
}
public void postScrollDown() {
if (mAccessToken != null) {
fab.hide();
if (showBottomAppBar) {
bottomNavigationView.performHide();
}
}
}
@Subscribe
@ -660,32 +717,4 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
public void onChangeNSFWEvent(ChangeNSFWEvent changeNSFWEvent) {
((FragmentCommunicator) mFragment).changeNSFW(changeNSFWEvent.nsfw);
}
/*private static class InsertSubredditDataAsyncTask extends AsyncTask<Void, Void, Void> {
private SubredditDao mSubredditDao;
private SubredditData subredditData;
private InsertSubredditDataAsyncTaskListener insertSubredditDataAsyncTaskListener;
InsertSubredditDataAsyncTask(RedditDataRoomDatabase db, SubredditData subredditData,
InsertSubredditDataAsyncTaskListener insertSubredditDataAsyncTaskListener) {
mSubredditDao = db.subredditDao();
this.subredditData = subredditData;
this.insertSubredditDataAsyncTaskListener = insertSubredditDataAsyncTaskListener;
}
@Override
protected Void doInBackground(final Void... params) {
mSubredditDao.insert(subredditData);
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
insertSubredditDataAsyncTaskListener.insertSuccess();
}
interface InsertSubredditDataAsyncTaskListener {
void insertSuccess();
}
}*/
}

View File

@ -64,7 +64,7 @@
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_marginEnd="32dp"
android:src="@drawable/ic_outline_account_circle_24px"
android:src="@drawable/ic_account_circle_24dp"
android:tint="@color/primaryTextColor"/>
<TextView
@ -144,7 +144,7 @@
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_marginEnd="32dp"
android:src="@drawable/ic_outline_inbox_24px"
android:src="@drawable/ic_inbox_24dp"
android:tint="@color/primaryTextColor"/>
<TextView

View File

@ -124,14 +124,88 @@
<include layout="@layout/content_view_subreddit_detail" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_navigation_view_subreddit_detail_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:visibility="gone"
app:backgroundTint="?attr/backgroundColor"
app:fabAlignmentMode="center">
<LinearLayout
android:id="@+id/linear_layout_bottom_app_bar_view_subreddit_detail_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="5">
<ImageView
android:id="@+id/subscriptions_bottom_app_bar_view_subreddit_detail_activity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:src="@drawable/ic_subscritptions_bottom_app_bar_24dp"
android:textColor="@color/primaryTextColor"
android:background="?attr/selectableItemBackgroundBorderless" />
<ImageView
android:id="@+id/multi_reddit_bottom_app_bar_view_subreddit_detail_activity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:src="@drawable/ic_multi_reddit_24dp"
android:textColor="@color/primaryTextColor"
android:background="?attr/selectableItemBackgroundBorderless" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"/>
<ImageView
android:id="@+id/message_bottom_app_bar_view_subreddit_detail_activity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:src="@drawable/ic_inbox_24dp"
android:textColor="@color/primaryTextColor"
android:background="?attr/selectableItemBackgroundBorderless" />
<ImageView
android:id="@+id/profile_bottom_app_bar_view_subreddit_detail_activity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:gravity="center"
android:src="@drawable/ic_account_circle_24dp"
android:textColor="@color/primaryTextColor"
android:background="?attr/selectableItemBackgroundBorderless" />
</LinearLayout>
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_view_subreddit_detail_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:visibility="gone"
app:backgroundTint="@color/backgroundColorPrimary"
app:srcCompat="@drawable/ic_add_bottom_app_bar_24dp"
app:tint="@android:color/white"
app:srcCompat="@drawable/ic_add_24dp" />
app:layout_anchor="@id/bottom_navigation_view_subreddit_detail_activity" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -69,16 +69,29 @@
android:id="@+id/linear_layout_bottom_app_bar_main_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3">
android:weightSum="5">
<TextView
<ImageView
android:id="@+id/subscriptions_bottom_app_bar_main_activity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:drawableTop="@drawable/ic_subscritptions_bottom_app_bar_24dp"
android:text="@string/subscriptions"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:src="@drawable/ic_subscritptions_bottom_app_bar_24dp"
android:textColor="@color/primaryTextColor"
android:background="?attr/selectableItemBackgroundBorderless" />
<ImageView
android:id="@+id/multi_reddit_bottom_app_bar_main_activity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:src="@drawable/ic_multi_reddit_24dp"
android:textColor="@color/primaryTextColor"
android:background="?attr/selectableItemBackgroundBorderless" />
@ -88,15 +101,28 @@
android:layout_weight="1"
android:background="@android:color/transparent"/>
<TextView
android:id="@+id/multi_reddit_bottom_app_bar_main_activity"
<ImageView
android:id="@+id/message_bottom_app_bar_main_activity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:src="@drawable/ic_inbox_24dp"
android:textColor="@color/primaryTextColor"
android:background="?attr/selectableItemBackgroundBorderless" />
<ImageView
android:id="@+id/profile_bottom_app_bar_main_activity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:gravity="center"
android:drawableTop="@drawable/ic_multi_reddit_24dp"
android:text="@string/multi_reddit_listing_activity"
android:src="@drawable/ic_account_circle_24dp"
android:textColor="@color/primaryTextColor"
android:background="?attr/selectableItemBackgroundBorderless" />