Make navigation bar and status bar transparent to display posts, comments, subreddits and users under them. Minor UI tweaks for bottom sheet fragments.

This commit is contained in:
Alex Ning 2019-08-10 18:29:04 +08:00
parent 4c21eea852
commit 413a18f6d3
31 changed files with 476 additions and 115 deletions

View File

@ -0,0 +1,41 @@
package ml.docilealligator.infinityforreddit;
import com.google.android.material.appbar.AppBarLayout;
abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener {
// State
public enum State {
EXPANDED,
COLLAPSED,
IDLE
}
private AppBarStateChangeListener.State mCurrentState = AppBarStateChangeListener.State.IDLE;
@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
if (i == 0) {
if (mCurrentState != AppBarStateChangeListener.State.EXPANDED) {
onStateChanged(appBarLayout, AppBarStateChangeListener.State.EXPANDED);
}
mCurrentState = AppBarStateChangeListener.State.EXPANDED;
} else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
if (mCurrentState != AppBarStateChangeListener.State.COLLAPSED) {
onStateChanged(appBarLayout, AppBarStateChangeListener.State.COLLAPSED);
}
mCurrentState = AppBarStateChangeListener.State.COLLAPSED;
} else {
if (mCurrentState != AppBarStateChangeListener.State.IDLE) {
onStateChanged(appBarLayout, AppBarStateChangeListener.State.IDLE);
}
mCurrentState = AppBarStateChangeListener.State.IDLE;
}
}
/**
* Notifies on state change
* @param appBarLayout Layout
* @param state Collapse state
*/
abstract void onStateChanged(AppBarLayout appBarLayout, AppBarStateChangeListener.State state);
}

View File

@ -3,6 +3,9 @@ package ml.docilealligator.infinityforreddit;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -76,6 +79,17 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
mGlide = Glide.with(activity); mGlide = Glide.with(activity);
Resources resources = getResources();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) {
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) {
mCommentRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
}
}
}
mCommentRecyclerView.setLayoutManager(new LinearLayoutManager(activity)); mCommentRecyclerView.setLayoutManager(new LinearLayoutManager(activity));
mAdapter = new CommentsListingRecyclerViewAdapter(activity, mOauthRetrofit, mAdapter = new CommentsListingRecyclerViewAdapter(activity, mOauthRetrofit,
@ -85,7 +99,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
mCommentRecyclerView.setAdapter(mAdapter); mCommentRecyclerView.setAdapter(mAdapter);
CommentViewModel.Factory factory = new CommentViewModel.Factory(mRetrofit, getResources().getConfiguration().locale, username); CommentViewModel.Factory factory = new CommentViewModel.Factory(mRetrofit, resources.getConfiguration().locale, username);
mCommentViewModel = ViewModelProviders.of(this, factory).get(CommentViewModel.class); mCommentViewModel = ViewModelProviders.of(this, factory).get(CommentViewModel.class);
mCommentViewModel.getComments().observe(this, comments -> mAdapter.submitList(comments)); mCommentViewModel.getComments().observe(this, comments -> mAdapter.submitList(comments));

View File

@ -2,6 +2,8 @@ package ml.docilealligator.infinityforreddit;
import android.app.Activity; import android.app.Activity;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -67,6 +69,11 @@ public class FlairBottomSheetFragment extends BottomSheetDialogFragment {
((Infinity) mAcitivity.getApplication()).getAppComponent().inject(this); ((Infinity) mAcitivity.getApplication()).getAppComponent().inject(this);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
}
mAdapter = new FlairBottomSheetRecyclerViewAdapter(flair -> ((FlairSelectionCallback) mAcitivity).flairSelected(flair)); mAdapter = new FlairBottomSheetRecyclerViewAdapter(flair -> ((FlairSelectionCallback) mAcitivity).flairSelected(flair));
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(mAdapter); recyclerView.setAdapter(mAdapter);

View File

@ -2,6 +2,9 @@ package ml.docilealligator.infinityforreddit;
import android.app.Activity; import android.app.Activity;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -59,6 +62,17 @@ public class FollowedUsersListingFragment extends Fragment {
((Infinity) mActivity.getApplication()).getAppComponent().inject(this); ((Infinity) mActivity.getApplication()).getAppComponent().inject(this);
Resources resources = getResources();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) {
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) {
mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
}
}
}
mGlide = Glide.with(this); mGlide = Glide.with(this);
mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity)); mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));

View File

@ -2,11 +2,16 @@ package ml.docilealligator.infinityforreddit;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@ -15,6 +20,7 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.GravityCompat; import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
@ -62,6 +68,8 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
private static final int LOGIN_ACTIVITY_REQUEST_CODE = 0; private static final int LOGIN_ACTIVITY_REQUEST_CODE = 0;
@BindView(R.id.drawer_layout) DrawerLayout drawer; @BindView(R.id.drawer_layout) DrawerLayout drawer;
@BindView(R.id.coordinator_layout_main_activity) CoordinatorLayout coordinatorLayout;
@BindView(R.id.appbar_layout_main_activity) AppBarLayout appBarLayout;
@BindView(R.id.view_pager_main_activity) ViewPager viewPager; @BindView(R.id.view_pager_main_activity) ViewPager viewPager;
@BindView(R.id.collapsing_toolbar_layout_main_activity) CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.collapsing_toolbar_layout_main_activity) CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.toolbar) Toolbar toolbar; @BindView(R.id.toolbar) Toolbar toolbar;
@ -119,6 +127,41 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
((Infinity) getApplication()).getAppComponent().inject(this); ((Infinity) getApplication()).getAppComponent().inject(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
Resources resources = getResources();
if(resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) {
Window window = getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
View decorView = window.getDecorView();
appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
@Override
void onStateChanged(AppBarLayout appBarLayout, State state) {
if(state == State.COLLAPSED) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
} else if(state == State.EXPANDED) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
}
}
});
int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (statusBarResourceId > 0) {
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId);
toolbar.setLayoutParams(params);
}
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
params.bottomMargin = resources.getDimensionPixelSize(navBarResourceId);
fab.setLayoutParams(params);
}
}
}
postTypeBottomSheetFragment = new PostTypeBottomSheetFragment(); postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
bestSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); bestSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
@ -390,10 +433,9 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == LOGIN_ACTIVITY_REQUEST_CODE && resultCode == Activity.RESULT_OK) { if(requestCode == LOGIN_ACTIVITY_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Intent intent = getIntent(); Intent intent = new Intent(this, MainActivity.class);
finish();
startActivity(intent); startActivity(intent);
overridePendingTransition(0, 0); finish();
} }
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);

View File

@ -4,6 +4,9 @@ package ml.docilealligator.infinityforreddit;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.os.Handler; import android.os.Handler;
@ -125,6 +128,17 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
window = activity.getWindow(); window = activity.getWindow();
Resources resources = getResources();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) {
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) {
mPostRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
}
}
}
mGlide = Glide.with(activity); mGlide = Glide.with(activity);
lazyModeRunnable = new Runnable() { lazyModeRunnable = new Runnable() {

View File

@ -2,6 +2,8 @@ package ml.docilealligator.infinityforreddit;
import android.app.Activity; import android.app.Activity;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -48,6 +50,11 @@ public class PostTypeBottomSheetFragment extends RoundedBottomSheetDialogFragmen
Activity activity = getActivity(); Activity activity = getActivity();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
}
textTypeLinearLayout.setOnClickListener(view -> { textTypeLinearLayout.setOnClickListener(view -> {
((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_TEXT); ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_TEXT);
dismiss(); dismiss();

View File

@ -2,6 +2,8 @@ package ml.docilealligator.infinityforreddit;
import android.app.Activity; import android.app.Activity;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -44,6 +46,11 @@ public class SearchPostSortTypeBottomSheetFragment extends RoundedBottomSheetDia
Activity activity = getActivity(); Activity activity = getActivity();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
}
relevanceTypeTextView.setOnClickListener(view -> { relevanceTypeTextView.setOnClickListener(view -> {
((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_RELEVANCE); ((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_RELEVANCE);
dismiss(); dismiss();

View File

@ -1,10 +1,16 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -14,6 +20,7 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter; import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayout;
import javax.inject.Inject; import javax.inject.Inject;
@ -36,6 +43,7 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos
private String mQuery; private String mQuery;
private String mSubredditName; private String mSubredditName;
@BindView(R.id.appbar_search_result_activity) AppBarLayout appBarLayout;
@BindView(R.id.toolbar_search_result_activity) Toolbar toolbar; @BindView(R.id.toolbar_search_result_activity) Toolbar toolbar;
@BindView(R.id.tab_layout_search_result_activity) TabLayout tabLayout; @BindView(R.id.tab_layout_search_result_activity) TabLayout tabLayout;
@BindView(R.id.view_pager_search_result_activity) ViewPager viewPager; @BindView(R.id.view_pager_search_result_activity) ViewPager viewPager;
@ -57,6 +65,34 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos
((Infinity) getApplication()).getAppComponent().inject(this); ((Infinity) getApplication()).getAppComponent().inject(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
Resources resources = getResources();
if(resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) {
Window window = getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
View decorView = window.getDecorView();
appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
@Override
void onStateChanged(AppBarLayout appBarLayout, State state) {
if(state == State.COLLAPSED) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
} else if(state == State.EXPANDED) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
}
}
});
int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (statusBarResourceId > 0) {
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId);
toolbar.setLayoutParams(params);
}
}
}
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);

View File

@ -2,6 +2,8 @@ package ml.docilealligator.infinityforreddit;
import android.app.Activity; import android.app.Activity;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -43,6 +45,11 @@ public class SearchUserAndSubredditSortTypeBottomSheetFragment extends RoundedBo
Activity activity = getActivity(); Activity activity = getActivity();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
}
int position = getArguments().getInt(EXTRA_FRAGMENT_POSITION); int position = getArguments().getInt(EXTRA_FRAGMENT_POSITION);
relevanceTypeTextView.setOnClickListener(view -> { relevanceTypeTextView.setOnClickListener(view -> {

View File

@ -2,6 +2,8 @@ package ml.docilealligator.infinityforreddit;
import android.app.Activity; import android.app.Activity;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -49,6 +51,11 @@ public class SortTypeBottomSheetFragment extends RoundedBottomSheetDialogFragmen
Activity activity = getActivity(); Activity activity = getActivity();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
}
if(getArguments().getBoolean(EXTRA_NO_BEST_TYPE)) { if(getArguments().getBoolean(EXTRA_NO_BEST_TYPE)) {
bestTypeTextView.setVisibility(View.GONE); bestTypeTextView.setVisibility(View.GONE);
} else { } else {

View File

@ -3,6 +3,9 @@ package ml.docilealligator.infinityforreddit;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -78,6 +81,17 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
ButterKnife.bind(this, rootView); ButterKnife.bind(this, rootView);
Resources resources = getResources();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) {
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) {
mSubredditListingRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
}
}
}
mLinearLayoutManager = new LinearLayoutManager(getActivity()); mLinearLayoutManager = new LinearLayoutManager(getActivity());
mSubredditListingRecyclerView.setLayoutManager(mLinearLayoutManager); mSubredditListingRecyclerView.setLayoutManager(mLinearLayoutManager);

View File

@ -2,6 +2,9 @@ package ml.docilealligator.infinityforreddit;
import android.app.Activity; import android.app.Activity;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -63,6 +66,17 @@ public class SubscribedSubredditsListingFragment extends Fragment {
((Infinity) mActivity.getApplication()).getAppComponent().inject(this); ((Infinity) mActivity.getApplication()).getAppComponent().inject(this);
Resources resources = getResources();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) {
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) {
mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
}
}
}
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
mGlide = Glide.with(this); mGlide = Glide.with(this);

View File

@ -1,8 +1,14 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -12,6 +18,7 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter; import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList; import java.util.ArrayList;
@ -33,6 +40,7 @@ public class SubscribedThingListingActivity extends AppCompatActivity {
private static final String ACCESS_TOKEN_STATE = "ATS"; private static final String ACCESS_TOKEN_STATE = "ATS";
private static final String ACCOUNT_NAME_STATE = "ANS"; private static final String ACCOUNT_NAME_STATE = "ANS";
@BindView(R.id.appbar_subscribed_thing_listing_activity) AppBarLayout appBarLayout;
@BindView(R.id.toolbar_subscribed_thing_listing_activity) Toolbar toolbar; @BindView(R.id.toolbar_subscribed_thing_listing_activity) Toolbar toolbar;
@BindView(R.id.tab_layout_subscribed_thing_listing_activity) TabLayout tabLayout; @BindView(R.id.tab_layout_subscribed_thing_listing_activity) TabLayout tabLayout;
@BindView(R.id.view_pager_subscribed_thing_listing_activity) ViewPager viewPager; @BindView(R.id.view_pager_subscribed_thing_listing_activity) ViewPager viewPager;
@ -60,6 +68,34 @@ public class SubscribedThingListingActivity extends AppCompatActivity {
((Infinity) getApplication()).getAppComponent().inject(this); ((Infinity) getApplication()).getAppComponent().inject(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
Resources resources = getResources();
if(resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) {
Window window = getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
View decorView = window.getDecorView();
appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
@Override
void onStateChanged(AppBarLayout appBarLayout, State state) {
if(state == State.COLLAPSED) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
} else if(state == State.EXPANDED) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
}
}
});
int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (statusBarResourceId > 0) {
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId);
toolbar.setLayoutParams(params);
}
}
}
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);

View File

@ -1,6 +1,9 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -74,6 +77,17 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
ButterKnife.bind(this, rootView); ButterKnife.bind(this, rootView);
Resources resources = getResources();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) {
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) {
mUserListingRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
}
}
}
mLinearLayoutManager = new LinearLayoutManager(getActivity()); mLinearLayoutManager = new LinearLayoutManager(getActivity());
mUserListingRecyclerView.setLayoutManager(mLinearLayoutManager); mUserListingRecyclerView.setLayoutManager(mLinearLayoutManager);

View File

@ -1,12 +1,17 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -99,6 +104,41 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
((Infinity) getApplication()).getAppComponent().inject(this); ((Infinity) getApplication()).getAppComponent().inject(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
Resources resources = getResources();
if(resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) {
Window window = getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
View decorView = window.getDecorView();
appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
@Override
void onStateChanged(AppBarLayout appBarLayout, State state) {
if (state == State.COLLAPSED) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
} else if (state == State.EXPANDED) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
}
}
});
int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (statusBarResourceId > 0) {
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId);
toolbar.setLayoutParams(params);
}
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
params.bottomMargin = resources.getDimensionPixelSize(navBarResourceId);
fab.setLayoutParams(params);
}
}
}
subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME_KEY); subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME_KEY);
if(savedInstanceState == null) { if(savedInstanceState == null) {

View File

@ -1,12 +1,17 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -51,16 +56,26 @@ public class ViewUserDetailActivity extends AppCompatActivity {
private static final String ACCOUNT_NAME_STATE = "ANS"; private static final String ACCOUNT_NAME_STATE = "ANS";
private static final String IS_IN_LAZY_MODE_STATE = "IILMS"; private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
@BindView(R.id.coordinator_layout_view_user_detail_activity) CoordinatorLayout coordinatorLayout; @BindView(R.id.coordinator_layout_view_user_detail_activity)
@BindView(R.id.view_pager_view_user_detail_activity) ViewPager viewPager; CoordinatorLayout coordinatorLayout;
@BindView(R.id.appbar_layout_view_user_detail) AppBarLayout appBarLayout; @BindView(R.id.view_pager_view_user_detail_activity)
@BindView(R.id.tab_layout_view_user_detail_activity) TabLayout tabLayout; ViewPager viewPager;
@BindView(R.id.collapsing_toolbar_layout_view_user_detail_activity) CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.appbar_layout_view_user_detail)
@BindView(R.id.banner_image_view_view_user_detail_activity) GifImageView bannerImageView; AppBarLayout appBarLayout;
@BindView(R.id.icon_gif_image_view_view_user_detail_activity) GifImageView iconGifImageView; @BindView(R.id.tab_layout_view_user_detail_activity)
@BindView(R.id.user_name_text_view_view_user_detail_activity) TextView userNameTextView; TabLayout tabLayout;
@BindView(R.id.subscribe_user_chip_view_user_detail_activity) Chip subscribeUserChip; @BindView(R.id.collapsing_toolbar_layout_view_user_detail_activity)
@BindView(R.id.karma_text_view_view_user_detail_activity) TextView karmaTextView; CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.banner_image_view_view_user_detail_activity)
GifImageView bannerImageView;
@BindView(R.id.icon_gif_image_view_view_user_detail_activity)
GifImageView iconGifImageView;
@BindView(R.id.user_name_text_view_view_user_detail_activity)
TextView userNameTextView;
@BindView(R.id.subscribe_user_chip_view_user_detail_activity)
Chip subscribeUserChip;
@BindView(R.id.karma_text_view_view_user_detail_activity)
TextView karmaTextView;
private SectionsPagerAdapter sectionsPagerAdapter; private SectionsPagerAdapter sectionsPagerAdapter;
@ -106,7 +121,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
username = getIntent().getExtras().getString(EXTRA_USER_NAME_KEY); username = getIntent().getExtras().getString(EXTRA_USER_NAME_KEY);
if(savedInstanceState == null) { if (savedInstanceState == null) {
getCurrentAccountAndInitializeViewPager(); getCurrentAccountAndInitializeViewPager();
} else { } else {
mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE); mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE);
@ -115,7 +130,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE); mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE); isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
if(!mNullAccessToken && mAccessToken == null) { if (!mNullAccessToken && mAccessToken == null) {
getCurrentAccountAndInitializeViewPager(); getCurrentAccountAndInitializeViewPager();
} else { } else {
initializeViewPager(); initializeViewPager();
@ -140,8 +155,8 @@ public class ViewUserDetailActivity extends AppCompatActivity {
toolbar.setTitle(title); toolbar.setTitle(title);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams(); ViewGroup.MarginLayoutParams toolbarLayoutParams = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
params.topMargin = statusBarHeight; toolbarLayoutParams.topMargin = statusBarHeight;
expandedTabTextColor = getResources().getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTextColor); expandedTabTextColor = getResources().getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTextColor);
expandedTabBackgroundColor = getResources().getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTabBackground); expandedTabBackgroundColor = getResources().getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTabBackground);
@ -151,20 +166,54 @@ public class ViewUserDetailActivity extends AppCompatActivity {
collapsedTabBackgroundColor = getResources().getColor(R.color.tabLayoutWithCollapsedCollapsingToolbarTabBackground); collapsedTabBackgroundColor = getResources().getColor(R.color.tabLayoutWithCollapsedCollapsingToolbarTabBackground);
collapsedTabIndicatorColor = getResources().getColor(R.color.tabLayoutWithCollapsedCollapsingToolbarTabIndicator); collapsedTabIndicatorColor = getResources().getColor(R.color.tabLayoutWithCollapsedCollapsingToolbarTabIndicator);
Resources resources = getResources();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1
&& (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT
|| resources.getBoolean(R.bool.isTablet))) {
Window window = getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
View decorView = window.getDecorView();
appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
@Override @Override
void onStateChanged(AppBarLayout appBarLayout, State state) { void onStateChanged(AppBarLayout appBarLayout, State state) {
if(state == State.EXPANDED) { if (state == State.COLLAPSED) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
tabLayout.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor);
tabLayout.setSelectedTabIndicatorColor(collapsedTabIndicatorColor);
tabLayout.setBackgroundColor(collapsedTabBackgroundColor);
} else if (state == State.EXPANDED) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
tabLayout.setTabTextColors(expandedTabTextColor, expandedTabTextColor); tabLayout.setTabTextColors(expandedTabTextColor, expandedTabTextColor);
tabLayout.setSelectedTabIndicatorColor(expandedTabIndicatorColor); tabLayout.setSelectedTabIndicatorColor(expandedTabIndicatorColor);
tabLayout.setBackgroundColor(expandedTabBackgroundColor); tabLayout.setBackgroundColor(expandedTabBackgroundColor);
} else if(state == State.COLLAPSED) { }
}
});
int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (statusBarResourceId > 0) {
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId);
toolbar.setLayoutParams(params);
}
} else {
appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
@Override
void onStateChanged(AppBarLayout appBarLayout, State state) {
if (state == State.EXPANDED) {
tabLayout.setTabTextColors(expandedTabTextColor, expandedTabTextColor);
tabLayout.setSelectedTabIndicatorColor(expandedTabIndicatorColor);
tabLayout.setBackgroundColor(expandedTabBackgroundColor);
} else if (state == State.COLLAPSED) {
tabLayout.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor); tabLayout.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor);
tabLayout.setSelectedTabIndicatorColor(collapsedTabIndicatorColor); tabLayout.setSelectedTabIndicatorColor(collapsedTabIndicatorColor);
tabLayout.setBackgroundColor(collapsedTabBackgroundColor); tabLayout.setBackgroundColor(collapsedTabBackgroundColor);
} }
} }
}); });
}
subscribedUserDao = mRedditDataRoomDatabase.subscribedUserDao(); subscribedUserDao = mRedditDataRoomDatabase.subscribedUserDao();
glide = Glide.with(this); glide = Glide.with(this);
@ -172,8 +221,8 @@ public class ViewUserDetailActivity extends AppCompatActivity {
userViewModel = ViewModelProviders.of(this, new UserViewModel.Factory(getApplication(), mRedditDataRoomDatabase, username)) userViewModel = ViewModelProviders.of(this, new UserViewModel.Factory(getApplication(), mRedditDataRoomDatabase, username))
.get(UserViewModel.class); .get(UserViewModel.class);
userViewModel.getUserLiveData().observe(this, userData -> { userViewModel.getUserLiveData().observe(this, userData -> {
if(userData != null) { if (userData != null) {
if(userData.getBanner().equals("")) { if (userData.getBanner().equals("")) {
bannerImageView.setOnClickListener(view -> { bannerImageView.setOnClickListener(view -> {
//Do nothing since the user has no banner image //Do nothing since the user has no banner image
}); });
@ -188,7 +237,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
}); });
} }
if(userData.getIconUrl().equals("")) { if (userData.getIconUrl().equals("")) {
glide.load(getDrawable(R.drawable.subreddit_default_icon)) glide.load(getDrawable(R.drawable.subreddit_default_icon))
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(216, 0))) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(216, 0)))
.into(iconGifImageView); .into(iconGifImageView);
@ -211,12 +260,12 @@ public class ViewUserDetailActivity extends AppCompatActivity {
}); });
} }
if(userData.isCanBeFollowed()) { if (userData.isCanBeFollowed()) {
subscribeUserChip.setVisibility(View.VISIBLE); subscribeUserChip.setVisibility(View.VISIBLE);
subscribeUserChip.setOnClickListener(view -> { subscribeUserChip.setOnClickListener(view -> {
if(subscriptionReady) { if (subscriptionReady) {
subscriptionReady = false; subscriptionReady = false;
if(subscribeUserChip.getText().equals(getResources().getString(R.string.follow))) { if (subscribeUserChip.getText().equals(getResources().getString(R.string.follow))) {
UserFollowing.followUser(mOauthRetrofit, mRetrofit, mAccessToken, UserFollowing.followUser(mOauthRetrofit, mRetrofit, mAccessToken,
username, mAccountName, subscribedUserDao, new UserFollowing.UserFollowingListener() { username, mAccountName, subscribedUserDao, new UserFollowing.UserFollowingListener() {
@Override @Override
@ -275,7 +324,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
String userFullName = "u/" + userData.getName(); String userFullName = "u/" + userData.getName();
userNameTextView.setText(userFullName); userNameTextView.setText(userFullName);
if(!title.equals(userFullName)) { if (!title.equals(userFullName)) {
getSupportActionBar().setTitle(userFullName); getSupportActionBar().setTitle(userFullName);
} }
String karma = getString(R.string.karma_info, userData.getKarma()); String karma = getString(R.string.karma_info, userData.getKarma());
@ -286,7 +335,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
private void getCurrentAccountAndInitializeViewPager() { private void getCurrentAccountAndInitializeViewPager() {
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
if(account == null) { if (account == null) {
mNullAccessToken = true; mNullAccessToken = true;
} else { } else {
mAccessToken = account.getAccessToken(); mAccessToken = account.getAccessToken();
@ -304,7 +353,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
} }
private void fetchUserInfo() { private void fetchUserInfo() {
if(!mFetchUserInfoSuccess) { if (!mFetchUserInfoSuccess) {
FetchUserData.fetchUserData(mRetrofit, username, new FetchUserData.FetchUserDataListener() { FetchUserData.fetchUserData(mRetrofit, username, new FetchUserData.FetchUserDataListener() {
@Override @Override
public void onFetchUserDataSuccess(UserData userData) { public void onFetchUserDataSuccess(UserData userData) {
@ -326,7 +375,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
getMenuInflater().inflate(R.menu.view_user_detail_activity, menu); getMenuInflater().inflate(R.menu.view_user_detail_activity, menu);
mMenu = menu; mMenu = menu;
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_user_detail_activity); MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_user_detail_activity);
if(isInLazyMode) { if (isInLazyMode) {
lazyModeItem.setTitle(R.string.action_stop_lazy_mode); lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED); params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
collapsingToolbarLayout.setLayoutParams(params); collapsingToolbarLayout.setLayoutParams(params);
@ -389,7 +438,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
} }
private void makeSnackbar(int resId, boolean retry) { private void makeSnackbar(int resId, boolean retry) {
if(retry) { if (retry) {
Snackbar.make(coordinatorLayout, resId, Snackbar.LENGTH_SHORT).setAction(R.string.retry, Snackbar.make(coordinatorLayout, resId, Snackbar.LENGTH_SHORT).setAction(R.string.retry,
view -> fetchUserInfo()).show(); view -> fetchUserInfo()).show();
} else { } else {
@ -397,44 +446,6 @@ public class ViewUserDetailActivity extends AppCompatActivity {
} }
} }
public abstract static class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener {
// State
public enum State {
EXPANDED,
COLLAPSED,
IDLE
}
private State mCurrentState = State.IDLE;
@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
if (i == 0) {
if (mCurrentState != State.EXPANDED) {
onStateChanged(appBarLayout, State.EXPANDED);
}
mCurrentState = State.EXPANDED;
} else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
if (mCurrentState != State.COLLAPSED) {
onStateChanged(appBarLayout, State.COLLAPSED);
}
mCurrentState = State.COLLAPSED;
} else {
if (mCurrentState != State.IDLE) {
onStateChanged(appBarLayout, State.IDLE);
}
mCurrentState = State.IDLE;
}
}
/**
* Notifies on state change
* @param appBarLayout Layout
* @param state Collapse state
*/
abstract void onStateChanged(AppBarLayout appBarLayout, State state);
}
private static class InsertUserDataAsyncTask extends AsyncTask<Void, Void, Void> { private static class InsertUserDataAsyncTask extends AsyncTask<Void, Void, Void> {
interface InsertUserDataAsyncTaskListener { interface InsertUserDataAsyncTaskListener {
@ -524,7 +535,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
} }
public void refresh() { public void refresh() {
if(viewPager.getCurrentItem() == 0) { if (viewPager.getCurrentItem() == 0) {
postFragment.refresh(); postFragment.refresh();
} else { } else {
commentsListingFragment.refresh(); commentsListingFragment.refresh();

View File

@ -11,6 +11,13 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"> android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
app:titleEnabled="false"
app:toolbarId="@+id/toolbar_search_result_activity">
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@ -38,11 +45,14 @@
</FrameLayout> </FrameLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<com.google.android.material.tabs.TabLayout <com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout_search_result_activity" android:id="@+id/tab_layout_search_result_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/colorPrimary" android:background="@color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:tabGravity="fill" app:tabGravity="fill"
app:tabMode="fixed" app:tabMode="fixed"
app:tabIndicatorColor="@android:color/white" app:tabIndicatorColor="@android:color/white"

View File

@ -12,6 +12,13 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"> android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
app:titleEnabled="false"
app:toolbarId="@+id/toolbar_subscribed_thing_listing_activity">
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_subscribed_thing_listing_activity" android:id="@+id/toolbar_subscribed_thing_listing_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -19,11 +26,14 @@
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" /> app:popupTheme="@style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
<com.google.android.material.tabs.TabLayout <com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout_subscribed_thing_listing_activity" android:id="@+id/tab_layout_subscribed_thing_listing_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/colorPrimary" android:background="@color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:tabGravity="fill" app:tabGravity="fill"
app:tabMode="fixed" app:tabMode="fixed"
app:tabIndicatorColor="@android:color/white" app:tabIndicatorColor="@android:color/white"

View File

@ -4,9 +4,11 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/coordinator_layout_main_activity"
tools:application="ml.docilealligator.infinityforreddit.MainActivity"> tools:application="ml.docilealligator.infinityforreddit.MainActivity">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_layout_main_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"> android:theme="@style/AppTheme.AppBarOverlay">

View File

@ -21,7 +21,8 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_comments_listing_fragment" android:id="@+id/recycler_view_comments_listing_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:clipToPadding="false" />
<LinearLayout <LinearLayout
android:id="@+id/fetch_comments_info_linear_layout_comments_listing_fragment" android:id="@+id/fetch_comments_info_linear_layout_comments_listing_fragment"

View File

@ -8,7 +8,8 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_followed_users_listing_fragment" android:id="@+id/recycler_view_followed_users_listing_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:clipToPadding="false" />
<LinearLayout <LinearLayout
android:id="@+id/no_subscriptions_linear_layout_followed_users_listing_fragment" android:id="@+id/no_subscriptions_linear_layout_followed_users_listing_fragment"

View File

@ -20,7 +20,8 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_post_fragment" android:id="@+id/recycler_view_post_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:clipToPadding="false" />
<LinearLayout <LinearLayout
android:id="@+id/fetch_post_info_linear_layout_post_fragment" android:id="@+id/fetch_post_info_linear_layout_post_fragment"

View File

@ -21,7 +21,8 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_subreddit_listing_fragment" android:id="@+id/recycler_view_subreddit_listing_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:clipToPadding="false" />
<LinearLayout <LinearLayout
android:id="@+id/fetch_subreddit_listing_info_linear_layout_subreddit_listing_fragment" android:id="@+id/fetch_subreddit_listing_info_linear_layout_subreddit_listing_fragment"

View File

@ -8,7 +8,8 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_subscribed_subreddits_listing_fragment" android:id="@+id/recycler_view_subscribed_subreddits_listing_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:clipToPadding="false" />
<LinearLayout <LinearLayout
android:id="@+id/no_subscriptions_linear_layout_subreddits_listing_fragment" android:id="@+id/no_subscriptions_linear_layout_subreddits_listing_fragment"

View File

@ -21,7 +21,8 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_user_listing_fragment" android:id="@+id/recycler_view_user_listing_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:clipToPadding="false" />
<LinearLayout <LinearLayout
android:id="@+id/fetch_user_listing_info_linear_layout_user_listing_fragment" android:id="@+id/fetch_user_listing_info_linear_layout_user_listing_fragment"

View File

@ -26,7 +26,7 @@
<color name="roundedBottomSheetPrimaryBackground">#242424</color> <color name="roundedBottomSheetPrimaryBackground">#242424</color>
<color name="roundedBottomSheetPrimaryNavigationBarColor">#000000</color> <color name="roundedBottomSheetPrimaryNavigationBarColor">@color/roundedBottomSheetPrimaryBackground</color>
<color name="voteUnavailableVoteButtonColor">#3C3C3C</color> <color name="voteUnavailableVoteButtonColor">#3C3C3C</color>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="isTablet">true</bool>
</resources>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="isTablet">false</bool>
</resources>

View File

@ -26,7 +26,7 @@
<color name="roundedBottomSheetPrimaryBackground">#FFFFFF</color> <color name="roundedBottomSheetPrimaryBackground">#FFFFFF</color>
<color name="roundedBottomSheetPrimaryNavigationBarColor">#000000</color> <color name="roundedBottomSheetPrimaryNavigationBarColor">@color/roundedBottomSheetPrimaryBackground</color>
<color name="voteUnavailableVoteButtonColor">#F0F0F0</color> <color name="voteUnavailableVoteButtonColor">#F0F0F0</color>

View File

@ -1,4 +1,4 @@
<resources> <resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight"> <style name="AppTheme" parent="Theme.MaterialComponents.DayNight">