pref: 优化平板设备判断方法

This commit is contained in:
HuanCheng65 2022-04-10 10:08:12 +08:00
parent f25b9a6e0f
commit 2a44a4fb1c
10 changed files with 12 additions and 16 deletions

Binary file not shown.

View File

@ -71,7 +71,7 @@ public class PersonalizedFeedAdapter extends MultiBaseAdapter<PersonalizedBean.T
private int getMaxWidth() { private int getMaxWidth() {
int maxWidth = BaseApplication.ScreenInfo.EXACT_SCREEN_WIDTH - DisplayUtil.dp2px(mContext, 56); int maxWidth = BaseApplication.ScreenInfo.EXACT_SCREEN_WIDTH - DisplayUtil.dp2px(mContext, 56);
if (mContext.getResources().getBoolean(R.bool.is_tablet)) { if (ExtensionsKt.isTablet(mContext)) {
if (ExtensionsKt.isLandscape(mContext.getResources().getConfiguration())) { if (ExtensionsKt.isLandscape(mContext.getResources().getConfiguration())) {
return maxWidth / 3; return maxWidth / 3;
} else { } else {

View File

@ -20,6 +20,7 @@ import com.alibaba.android.vlayout.layout.LinearLayoutHelper;
import com.alibaba.android.vlayout.layout.StaggeredGridLayoutHelper; import com.alibaba.android.vlayout.layout.StaggeredGridLayoutHelper;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.huanchengfly.tieba.post.BaseApplication; import com.huanchengfly.tieba.post.BaseApplication;
import com.huanchengfly.tieba.post.ExtensionsKt;
import com.huanchengfly.tieba.post.R; import com.huanchengfly.tieba.post.R;
import com.huanchengfly.tieba.post.activities.ThreadActivity; import com.huanchengfly.tieba.post.activities.ThreadActivity;
import com.huanchengfly.tieba.post.adapters.base.BaseMultiTypeDelegateAdapter; import com.huanchengfly.tieba.post.adapters.base.BaseMultiTypeDelegateAdapter;
@ -60,7 +61,7 @@ public class NewForumAdapter extends BaseMultiTypeDelegateAdapter<ForumPageBean.
@NonNull @NonNull
@Override @Override
public LayoutHelper onCreateLayoutHelper() { public LayoutHelper onCreateLayoutHelper() {
if (getContext().getResources().getBoolean(R.bool.is_tablet)) { if (ExtensionsKt.isTablet(getContext())) {
return new StaggeredGridLayoutHelper(2); return new StaggeredGridLayoutHelper(2);
} else { } else {
return new LinearLayoutHelper(); return new LinearLayoutHelper();
@ -86,7 +87,7 @@ public class NewForumAdapter extends BaseMultiTypeDelegateAdapter<ForumPageBean.
private int getMaxWidth() { private int getMaxWidth() {
int maxWidth = BaseApplication.ScreenInfo.EXACT_SCREEN_WIDTH - DisplayUtil.dp2px(getContext(), 40); int maxWidth = BaseApplication.ScreenInfo.EXACT_SCREEN_WIDTH - DisplayUtil.dp2px(getContext(), 40);
if (getContext().getResources().getBoolean(R.bool.is_tablet)) { if (ExtensionsKt.isTablet(getContext())) {
return maxWidth / 2; return maxWidth / 2;
} }
return maxWidth; return maxWidth;
@ -94,7 +95,7 @@ public class NewForumAdapter extends BaseMultiTypeDelegateAdapter<ForumPageBean.
private int getGridHeight() { private int getGridHeight() {
int maxWidth = BaseApplication.ScreenInfo.EXACT_SCREEN_WIDTH - DisplayUtil.dp2px(getContext(), 70); int maxWidth = BaseApplication.ScreenInfo.EXACT_SCREEN_WIDTH - DisplayUtil.dp2px(getContext(), 70);
if (getContext().getResources().getBoolean(R.bool.is_tablet)) { if (ExtensionsKt.isTablet(getContext())) {
maxWidth = maxWidth / 2; maxWidth = maxWidth / 2;
} }
return maxWidth / 3; return maxWidth / 3;

View File

@ -12,6 +12,7 @@ import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.huanchengfly.tieba.post.ExtensionsKt;
import com.huanchengfly.tieba.post.R; import com.huanchengfly.tieba.post.R;
import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable; import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable;
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils; import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils;
@ -38,7 +39,7 @@ public class ForumDivider extends RecyclerView.ItemDecoration implements Tintabl
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state); super.getItemOffsets(outRect, view, parent, state);
int position = parent.getChildAdapterPosition(view) - 1; int position = parent.getChildAdapterPosition(view) - 1;
if (parent.getResources().getBoolean(R.bool.is_tablet)) { if (ExtensionsKt.isTablet(parent.getContext())) {
if (position % 2 == 0) { if (position % 2 == 0) {
outRect.set(0, 0, mDividerHeight / 2, mDividerHeight); outRect.set(0, 0, mDividerHeight / 2, mDividerHeight);
} else { } else {

View File

@ -12,11 +12,11 @@ import androidx.annotation.CallSuper
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import butterknife.ButterKnife import butterknife.ButterKnife
import butterknife.Unbinder import butterknife.Unbinder
import com.huanchengfly.tieba.post.R
import com.huanchengfly.tieba.post.interfaces.BackHandledInterface import com.huanchengfly.tieba.post.interfaces.BackHandledInterface
import com.huanchengfly.tieba.post.interfaces.Refreshable import com.huanchengfly.tieba.post.interfaces.Refreshable
import com.huanchengfly.tieba.post.isLandscape import com.huanchengfly.tieba.post.isLandscape
import com.huanchengfly.tieba.post.isPortrait import com.huanchengfly.tieba.post.isPortrait
import com.huanchengfly.tieba.post.isTablet
import com.huanchengfly.tieba.post.utils.AppPreferencesUtils import com.huanchengfly.tieba.post.utils.AppPreferencesUtils
import com.huanchengfly.tieba.post.utils.HandleBackUtil import com.huanchengfly.tieba.post.utils.HandleBackUtil
import kotlinx.coroutines.* import kotlinx.coroutines.*
@ -191,7 +191,7 @@ abstract class BaseFragment : Fragment(), BackHandledInterface, CoroutineScope {
} }
protected val isTablet: Boolean protected val isTablet: Boolean
get() = attachContext.resources.getBoolean(R.bool.is_tablet) get() = attachContext.isTablet
protected val isPortrait: Boolean protected val isPortrait: Boolean
get() = attachContext.resources.configuration.isPortrait get() = attachContext.resources.configuration.isPortrait

View File

@ -126,7 +126,7 @@ class MainForumListFragment : BaseFragment(), Refreshable, Toolbar.OnMenuItemCli
appPreferences.listSingle -> { appPreferences.listSingle -> {
1 1
} }
resources.getBoolean(R.bool.is_tablet) -> { attachContext.isTablet -> {
3 3
} }
else -> { else -> {

View File

@ -29,8 +29,8 @@
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
app:bottomNavigationBackgroundTint="@color/default_color_nav" app:bottomNavigationBackgroundTint="@color/default_color_nav"
app:elevation="4dp" app:elevation="4dp"
app:itemIconTintList="@drawable/bottom_item_icon_tint_list" app:itemIconTintList="@color/bottom_item_icon_tint_list"
app:itemTextTintList="@drawable/bottom_item_icon_tint_list" app:itemTextTintList="@color/bottom_item_icon_tint_list"
app:labelVisibilityMode="unlabeled" app:labelVisibilityMode="unlabeled"
app:menu="@menu/navbar_main" /> app:menu="@menu/navbar_main" />

View File

@ -1,3 +0,0 @@
<resources>
<bool name="is_tablet">true</bool>
</resources>

View File

@ -1,3 +0,0 @@
<resources>
<bool name="is_tablet">false</bool>
</resources>