|
@@ -34,8 +34,11 @@ import com.cooleshow.usercenter.helper.UserHelper;
|
|
|
import com.google.android.material.appbar.AppBarLayout;
|
|
|
import com.google.android.material.tabs.TabLayout;
|
|
|
import com.google.android.material.tabs.TabLayoutMediator;
|
|
|
+import com.zhy.view.flowlayout.FlowLayout;
|
|
|
+import com.zhy.view.flowlayout.TagAdapter;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.fragment.app.Fragment;
|
|
@@ -55,6 +58,7 @@ public class HomePageActivity extends BaseMVPActivity<ActivityHomePageLayoutBind
|
|
|
private int titleStyleMode = 1;//根据折叠展开状态控制title样式
|
|
|
|
|
|
private AppBarLayoutStateChangeListener.State lastState = AppBarLayoutStateChangeListener.State.EXPANDED;
|
|
|
+ private TagAdapter mTagAdapter;
|
|
|
|
|
|
@Override
|
|
|
protected void initView() {
|
|
@@ -119,6 +123,15 @@ public class HomePageActivity extends BaseMVPActivity<ActivityHomePageLayoutBind
|
|
|
@Override
|
|
|
public void initData() {
|
|
|
super.initData();
|
|
|
+ mTagAdapter = new TagAdapter<String>(subjectNames) {
|
|
|
+ @Override
|
|
|
+ public View getView(FlowLayout parent, int position, String s) {
|
|
|
+ View subjectView = createSubjectView(parent, s);
|
|
|
+ return subjectView;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ viewBinding.llSubjectContainer.setAdapter(mTagAdapter);
|
|
|
+
|
|
|
TabLayoutMediator tabLayoutMediator = new TabLayoutMediator(viewBinding.tabLayout, viewBinding.viewPager, new TabLayoutMediator.TabConfigurationStrategy() {
|
|
|
@Override
|
|
|
public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
|
|
@@ -264,14 +277,9 @@ public class HomePageActivity extends BaseMVPActivity<ActivityHomePageLayoutBind
|
|
|
viewBinding.tvNickname.setText(info.username);
|
|
|
//subjectName
|
|
|
try {
|
|
|
- viewBinding.llSubjectContainer.removeAllViews();
|
|
|
- viewBinding.llSubjectContainer2.removeAllViews();
|
|
|
- String[] subjectNames = UiUtils.splitSubjectName(info.subjectName);
|
|
|
- if (subjectNames != null && subjectNames.length > 0) {
|
|
|
- for (int i = 0; i < subjectNames.length; i++) {
|
|
|
- createSubjectView(subjectNames[i]);
|
|
|
- }
|
|
|
- }
|
|
|
+ subjectNames.clear();
|
|
|
+ subjectNames.addAll(Arrays.asList(UiUtils.splitSubjectName(info.subjectName)));
|
|
|
+ mTagAdapter.notifyDataChanged();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -316,20 +324,13 @@ public class HomePageActivity extends BaseMVPActivity<ActivityHomePageLayoutBind
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void createSubjectView(String text) {
|
|
|
- TextView textView = (TextView) LayoutInflater.from(this).inflate(com.cooleshow.base.R.layout.view_subject_item_layout, viewBinding.llSubjectContainer, false);
|
|
|
+ private ArrayList<String> subjectNames = new ArrayList<>();
|
|
|
+
|
|
|
+ private View createSubjectView(ViewGroup viewGroup, String text) {
|
|
|
+ TextView textView = (TextView) LayoutInflater.from(this).inflate(R.layout.view_homepage_subject_item_layout, viewGroup, false);
|
|
|
textView.setText(text);
|
|
|
textView.setTextColor(getResources().getColor(com.cooleshow.base.R.color.color_2dc7aa));
|
|
|
textView.setBackgroundResource(com.cooleshow.base.R.drawable.shape_effbf9_9dp);
|
|
|
- LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
- if (viewBinding.llSubjectContainer.getChildCount() < 4) {
|
|
|
- if (viewBinding.llSubjectContainer.getChildCount() >= 1) {
|
|
|
- params.setMargins(SizeUtils.dp2px(4), 0, 0, 0);
|
|
|
- }
|
|
|
- viewBinding.llSubjectContainer.addView(textView, params);
|
|
|
- } else {
|
|
|
- viewBinding.llSubjectContainer2.addView(textView, params);
|
|
|
- viewBinding.llSubjectContainer2.setVisibility(View.VISIBLE);
|
|
|
- }
|
|
|
+ return textView;
|
|
|
}
|
|
|
}
|