Change the UI of ViewMultiRedditActivity.

This commit is contained in:
Alex Ning 2019-12-17 18:33:27 +08:00
parent f834f5804c
commit cc86e047f0
2 changed files with 43 additions and 146 deletions

View File

@ -12,7 +12,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -20,19 +19,14 @@ import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.chip.Chip;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment; import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
@ -48,7 +42,6 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class ViewMultiRedditDetailActivity extends BaseActivity implements SortTypeSelectionCallback, public class ViewMultiRedditDetailActivity extends BaseActivity implements SortTypeSelectionCallback,
@ -64,24 +57,12 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
@BindView(R.id.coordinator_layout_view_multi_reddit_detail_activity) @BindView(R.id.coordinator_layout_view_multi_reddit_detail_activity)
CoordinatorLayout coordinatorLayout; CoordinatorLayout coordinatorLayout;
@BindView(R.id.appbar_layout_view_multi_reddit_detail) @BindView(R.id.appbar_layout_view_multi_reddit_detail_activity)
AppBarLayout appBarLayout; AppBarLayout appBarLayout;
@BindView(R.id.collapsing_toolbar_layout_view_multi_reddit_detail_activity) @BindView(R.id.collapsing_toolbar_layout_view_multi_reddit_detail_activity)
CollapsingToolbarLayout collapsingToolbarLayout; CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.toolbar) @BindView(R.id.toolbar_view_multi_reddit_detail_activity)
Toolbar toolbar; Toolbar toolbar;
@BindView(R.id.icon_gif_image_view_view_multi_reddit_detail_activity)
GifImageView iconGifImageView;
@BindView(R.id.duplicate_multi_reddit_chip_view_multi_reddit_detail_activity)
Chip duplicateSubredditChip;
@BindView(R.id.multi_reddit_name_text_view_view_multi_reddit_detail_activity)
TextView multiRedditNameTextView;
@BindView(R.id.owner_text_view_view_multi_reddit_detail_activity)
TextView ownerTextView;
@BindView(R.id.subreddits_count_view_multi_reddit_detail_activity)
TextView subredditsCountTextView;
@BindView(R.id.description_text_view_view_multi_reddit_detail_activity)
TextView descriptionTextView;
@Inject @Inject
@Named("no_oauth") @Named("no_oauth")
Retrofit mRetrofit; Retrofit mRetrofit;
@ -97,8 +78,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
private String mAccountName; private String mAccountName;
private String multiPath; private String multiPath;
private boolean isInLazyMode = false; private boolean isInLazyMode = false;
private boolean showToast = false;
private RequestManager glide;
private Fragment mFragment; private Fragment mFragment;
private Menu mMenu; private Menu mMenu;
private AppBarLayout.LayoutParams params; private AppBarLayout.LayoutParams params;
@ -114,10 +93,11 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
ButterKnife.bind(this); ButterKnife.bind(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
Resources resources = getResources(); Resources resources = getResources();
if ((resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1
&& (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT
|| resources.getBoolean(R.bool.isTablet))
&& mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) {
Window window = getWindow(); Window window = getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
@ -129,9 +109,12 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
boolean finalLightNavBar = lightNavBar; boolean finalLightNavBar = lightNavBar;
View decorView = window.getDecorView(); View decorView = window.getDecorView();
if (finalLightNavBar) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
}
appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
@Override @Override
public void onStateChanged(AppBarLayout appBarLayout, AppBarStateChangeListener.State state) { public void onStateChanged(AppBarLayout appBarLayout, State state) {
if (state == State.COLLAPSED) { if (state == State.COLLAPSED) {
if (finalLightNavBar) { if (finalLightNavBar) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
@ -144,10 +127,11 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
} }
}); });
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (navBarResourceId > 0) { if (statusBarResourceId > 0) {
showToast = true; ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
} params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId);
toolbar.setLayoutParams(params);
} }
} }
@ -158,8 +142,10 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
return; return;
} }
multiPath = multiReddit.getPath(); multiPath = multiReddit.getPath();
multiRedditNameTextView.setText(multiReddit.getDisplayName());
ownerTextView.setText(multiReddit.getOwner()); toolbar.setTitle(multiReddit.getDisplayName());
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState != null) { if (savedInstanceState != null) {
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
@ -194,20 +180,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
if (resourceId > 0) { if (resourceId > 0) {
statusBarHeight = getResources().getDimensionPixelSize(resourceId); statusBarHeight = getResources().getDimensionPixelSize(resourceId);
} }
toolbar.setTitle(multiReddit.getDisplayName());
ViewGroup.MarginLayoutParams toolbarParams = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
toolbarParams.topMargin = statusBarHeight;
toolbar.setLayoutParams(toolbarParams);
setSupportActionBar(toolbar);
glide = Glide.with(this);
glide.load(multiReddit.getIconUrl())
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0)))
.error(glide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0))))
.into(iconGifImageView);
} }
private void getCurrentAccountAndInitializeFragment() { private void getCurrentAccountAndInitializeFragment() {

View File

@ -9,7 +9,7 @@
tools:context=".Activity.ViewMultiRedditDetailActivity"> tools:context=".Activity.ViewMultiRedditDetailActivity">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_layout_view_multi_reddit_detail" android:id="@+id/appbar_layout_view_multi_reddit_detail_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/toolbarAndTabBackgroundColor" android:background="?attr/toolbarAndTabBackgroundColor"
@ -19,89 +19,14 @@
android:id="@+id/collapsing_toolbar_layout_view_multi_reddit_detail_activity" android:id="@+id/collapsing_toolbar_layout_view_multi_reddit_detail_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/backgroundColor" app:layout_scrollFlags="scroll|enterAlways"
app:titleEnabled="false" app:titleEnabled="false"
app:contentScrim="?attr/colorPrimary" app:toolbarId="@+id/toolbar_view_multi_reddit_detail_activity">
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
app:toolbarId="@+id/toolbar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<pl.droidsonroids.gif.GifImageView
android:id="@+id/icon_gif_image_view_view_multi_reddit_detail_activity"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:elevation="4dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:layout_below="@id/icon_gif_image_view_view_multi_reddit_detail_activity"
android:background="?attr/backgroundColor">
<TextView
android:id="@+id/multi_reddit_name_text_view_view_multi_reddit_detail_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:textSize="?attr/font_18"
android:textColor="@color/colorAccent"
android:layout_gravity="center_horizontal"/>
<com.google.android.material.chip.Chip
android:id="@+id/duplicate_multi_reddit_chip_view_multi_reddit_detail_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:layout_gravity="center_horizontal"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/owner_text_view_view_multi_reddit_detail_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/usernameColor"
android:textSize="?attr/font_default"/>
<TextView
android:id="@+id/subreddits_count_view_multi_reddit_detail_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/primaryTextColor"
android:textSize="?attr/font_default"/>
</LinearLayout>
<TextView
android:id="@+id/description_text_view_view_multi_reddit_detail_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:textColor="@color/primaryTextColor"
android:textSize="?attr/font_default"
android:visibility="gone"/>
</LinearLayout>
</RelativeLayout>
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar_view_multi_reddit_detail_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
app:popupTheme="@style/AppTheme.PopupOverlay" app:popupTheme="@style/AppTheme.PopupOverlay"
app:navigationIcon="?attr/homeAsUpIndicator" /> app:navigationIcon="?attr/homeAsUpIndicator" />