作者 liyan

新功能页面基本完成

正在显示 40 个修改的文件 包含 4048 行增加6 行删除

要显示太多修改。

为保证性能只显示 40 of 40+ 个文件。

... ... @@ -297,4 +297,6 @@ dependencies {
//厂商版本和JPush SDK版本保持一致
implementation 'cn.jiguang.sdk.plugin:huawei:3.7.0'
implementation 'com.huawei.hms:push:4.0.2.300'
//柱状图、折线图、饼图
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}
... ...
... ... @@ -81,8 +81,8 @@
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="LockedOrientationActivity">
<activity android:name=".chat.ChatActivity" />
... ... @@ -124,12 +124,14 @@
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
<!--这个Activity不要删 删了一加推送就点不进去了-->
<activity android:name=".main.OpenClickActivity"
<activity
android:name=".main.OpenClickActivity"
android:exported="true">
<intent-filter>
<action android:name=".main.OpenClickActivity"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name=".main.OpenClickActivity" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!--会话列表-->
... ... @@ -579,6 +581,37 @@
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode"
android:screenOrientation="portrait" />
<activity
android:name=".mine.CreatorHomePageActivity"
android:screenOrientation="portrait" />
<activity
android:name=".mine.DataAnalysisActivity"
android:screenOrientation="portrait" />
<activity
android:name=".mine.SeeDataAnalysisActivity"
android:screenOrientation="portrait" />
<activity
android:name=".mine.SeeFansDataAnalysisActivity"
android:screenOrientation="portrait" />
<activity
android:name=".mine.CreatorWorksDetailActivity"
android:screenOrientation="portrait" />
<activity
android:name=".mine.MyIncomeActivity"
android:screenOrientation="portrait" />
<activity
android:name=".mine.IncomeCashRecordActivity"
android:screenOrientation="portrait" />
<activity
android:name=".mine.CreateIntroduceActivity"
android:screenOrientation="portrait" />
<activity
android:name=".mine.AllAreaActivity"
android:screenOrientation="portrait" />
<!-- Since JCore2.0.0 Required SDK核心功能-->
<!-- 可配置android:process参数将Service放在其他进程中;android:enabled属性不能是false -->
<!-- 这个是自定义Service,要继承极光JCommonService,可以在更多手机平台上使得推送通道保持的更稳定 -->
... ...
package com.yinhebairong.shejiao.main.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.main.bean.TabBean;
import java.util.List;
/**
* Time: 9/8/2020 16:31
* Author: TAO
* Description:
*/
public class MyTextAndImageAdapter extends FragmentPagerAdapter {
private List<Fragment> fragmentList;
private List<TabBean> jxtTypeBeans;
private Context mContext;
private String str[] = {"收益详情","规范说明","信用分规则","云创计划"};
private int ints[] = {R.mipmap.icon_shouyixiangqing,R.mipmap.icon_guifanshuoming,R.mipmap.icon_xinyongfenguize,R.mipmap.icon_yunchaungjihua};
public MyTextAndImageAdapter(Context context,FragmentManager fm, List<Fragment> fragmentList, List<TabBean> jxtTypeBeans) {
super(fm);
mContext = context;
this.fragmentList = fragmentList;
this.jxtTypeBeans = jxtTypeBeans;
}
@Override
public int getCount() {
return fragmentList.size();
}
@Override
public Fragment getItem(int position) {
return fragmentList == null ? null : fragmentList.get(position);
}
public List<TabBean> getData() {
return jxtTypeBeans;
}
@Nullable
@Override
public String getPageTitle(int position) {
return jxtTypeBeans.get(position).getTypeName();
}
public View getTabView(int position) {
View v = LayoutInflater.from(mContext).inflate(R.layout.tab_item_text_and_image, null);
ImageView iv = v.findViewById(R.id.iv_img);
TextView tv = v.findViewById(R.id.tv_text);
iv.setBackgroundResource(ints[position]);
tv.setText(str[position]);
// if (position == 0) {
// tv.setTextColor(v.getResources().getColor(R.color.saf_indus_blue));
// }
return v;
}
}
\ No newline at end of file
... ...
... ... @@ -49,9 +49,12 @@ import com.yinhebairong.shejiao.main.bean.Accompanystate;
import com.yinhebairong.shejiao.main.model.MyInfoModel;
import com.yinhebairong.shejiao.mine.AccountActivity;
import com.yinhebairong.shejiao.mine.AttentionActivity;
import com.yinhebairong.shejiao.mine.CreatorHomePageActivity;
import com.yinhebairong.shejiao.mine.CreditScoreActivity;
import com.yinhebairong.shejiao.mine.DataAnalysisActivity;
import com.yinhebairong.shejiao.mine.IntegralTaskActivity;
import com.yinhebairong.shejiao.mine.InvitefriendsActivity;
import com.yinhebairong.shejiao.mine.MyIncomeActivity;
import com.yinhebairong.shejiao.mine.MyMeetActivity;
import com.yinhebairong.shejiao.mine.SettingsActivity;
import com.yinhebairong.shejiao.mine.VipActivity;
... ... @@ -134,6 +137,7 @@ public class MineFragment extends BaseFragment {
private MyInfoModel myInfoModel;
private int is_creator = -1;
@Override
protected int getContentView() {
... ... @@ -180,7 +184,7 @@ public class MineFragment extends BaseFragment {
@OnClick({R.id.vg_menu_dizhi, R.id.vg_menu_renzheng, R.id.vg_menu_chongwen, R.id.vg_menu_xianxia, R.id.vg_coin, R.id.vg_credit_score,
R.id.iv_option, R.id.iv_head, R.id.iv_bg_img, R.id.tv_vip, R.id.vg_see_me, R.id.vg_mine_my_attention, R.id.vg_attention_me,
R.id.vg_menu_my_page, R.id.vg_menu_vip_center, R.id.vg_menu_city_activity, R.id.vg_menu_become_guru, R.id.ll_list, R.id.ll_invitation,
R.id.ll_integral_task, R.id.ll_my_prize, R.id.ll_service})
R.id.ll_integral_task, R.id.ll_my_prize, R.id.ll_service, R.id.ll_creator_home_page, R.id.ll_data_analysis, R.id.ll_my_shouyi})
public void onViewClicked(View view) {
Intent intent = new Intent();
switch (view.getId()) {
... ... @@ -227,6 +231,24 @@ public class MineFragment extends BaseFragment {
intent.setClass(getContext(), MyMeetActivity.class);
startActivity(intent);
break;
case R.id.ll_creator_home_page:
//创作者首页
intent.setClass(getContext(), CreatorHomePageActivity.class);
if (is_creator != -1) {
intent.putExtra("is_creator", is_creator);
}
startActivity(intent);
break;
case R.id.ll_data_analysis:
//数据分析
intent.setClass(getContext(), DataAnalysisActivity.class);
startActivity(intent);
break;
case R.id.ll_my_shouyi:
//我的收益
intent.setClass(getContext(), MyIncomeActivity.class);
startActivity(intent);
break;
case R.id.iv_head:
intent.setClass(getContext(), AccountActivity.class);
startActivity(intent);
... ... @@ -437,6 +459,9 @@ public class MineFragment extends BaseFragment {
ivStudent.setVisibility(myInfoModel.isStudent() ? View.VISIBLE : View.GONE);
ivBigV.setVisibility(myInfoModel.getRen_id() == 0 ? View.GONE : View.VISIBLE);
this.myInfoModel = myInfoModel;
is_creator = myInfoModel.getIs_creator();
// setColor();
}
... ...
... ... @@ -25,6 +25,15 @@ public class MyInfoModel {
private int ren_id;//0=无,1=大V个人认证,2=大V企业认证
private String ren_msg;
private int student_id;//1=是学生,0=不是学生
private int is_creator;//是否加入了创作者计划 0=否 1=是
public int getIs_creator() {
return is_creator;
}
public void setIs_creator(int is_creator) {
this.is_creator = is_creator;
}
public String getShen_id() {
return shen_id;
... ...
package com.yinhebairong.shejiao.mine;
import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BasePBActivity;
import com.yinhebairong.shejiao.mine.adapter.AreaPercentAdapter;
import com.yinhebairong.shejiao.mine.model.AttentionModel;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
/**
* Time: 9/18/2021 13:42
* Author: Captain
* Description: 初见时你很迷人
*/
public class AllAreaActivity extends BasePBActivity {
@BindView(R.id.recyclerview)
RecyclerView rvArea;
private AreaPercentAdapter areaPercentAdapter;
@Override
public int getLayoutId() {
return R.layout.activity_all_area;
}
@Override
public void initView(Bundle savedInstanceState) {
showAreaPercentage();
}
//显示地域分布
private void showAreaPercentage() {
areaPercentAdapter = new AreaPercentAdapter(this);
rvArea.setLayoutManager(new LinearLayoutManager(this));
rvArea.setAdapter(areaPercentAdapter);
AttentionModel attentionModel = new AttentionModel();
List<AttentionModel> attentionModelList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
attentionModel.setNickname2("河南");
}
attentionModelList.add(attentionModel);
areaPercentAdapter.resetDataList(attentionModelList);
}
@Override
public void initEvent() {
}
}
... ...
package com.yinhebairong.shejiao.mine;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.bang.RankingListFragment;
import com.yinhebairong.shejiao.base.BasePBActivity;
import com.yinhebairong.shejiao.main.adapter.MyAdapter;
import com.yinhebairong.shejiao.main.adapter.MyTextAndImageAdapter;
import com.yinhebairong.shejiao.main.bean.TabBean;
import com.yinhebairong.shejiao.mine.fragment.CreateIntroduceWebFragment;
import com.yinhebairong.shejiao.mine.fragment.IncomeLineChartFragment;
import com.yinhebairong.shejiao.topic.TopicNewFragment;
import com.yinhebairong.shejiao.view.ScrollableNestedScrollView;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import static com.yinhebairong.shejiao.main.fragment.SquareFragment.POSITION_ATTENTION;
import static com.yinhebairong.shejiao.main.fragment.SquareFragment.POSITION_SUGGEST;
/**
* Time: 9/17/2021 11:29
* Author: Captain
* Description: 初见时你很迷人
* 创作简介
*/
public class CreateIntroduceActivity extends BasePBActivity {
@BindView(R.id.tab_layout)
TabLayout tabLayout;
@BindView(R.id.viewPager)
ViewPager viewPager;
private List<TabBean> mTabBeanList;
private List<Fragment> fragmentList = new ArrayList<>();
private MyTextAndImageAdapter fragmentAdapter;
private String tabName;
@Override
public int getLayoutId() {
return R.layout.activity_create_introduce;
}
@Override
public void initView(Bundle savedInstanceState) {
tabName = getIntent().getStringExtra("tabName");
setUpViewpager();
}
private void setUpViewpager() {
mTabBeanList = new ArrayList<>();
mTabBeanList.add(new TabBean("收益详情", true));//0
mTabBeanList.add(new TabBean("规范说明", false));//1
mTabBeanList.add(new TabBean("信用分规则", false));
mTabBeanList.add(new TabBean("云创计划", false));
// todo 隐藏榜单
// mTabBeanList.add(new TabBean("榜单", false));
fragmentList.add(CreateIntroduceWebFragment.newInstance(0));
fragmentList.add(CreateIntroduceWebFragment.newInstance(0));
fragmentList.add(CreateIntroduceWebFragment.newInstance(0));
fragmentList.add(CreateIntroduceWebFragment.newInstance(1));
fragmentAdapter = new MyTextAndImageAdapter(this,getSupportFragmentManager(), fragmentList, mTabBeanList);
viewPager.setAdapter(fragmentAdapter);
viewPager.setOffscreenPageLimit(fragmentList.size());
tabLayout.setupWithViewPager(viewPager);
// viewPager.resetHeight(0);
//初始化Tab样式
for (int i = 0; i < tabLayout.getTabCount(); i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i).setCustomView(fragmentAdapter.getTabView(i));
if (tab != null) {
TextView textView = (TextView) tab.getCustomView().findViewById(R.id.tv_text);
textView.setText(tab.getText());
textView.getPaint().setFakeBoldText(i == POSITION_SUGGEST);
textView.setTextColor(getResources().getColor(i == POSITION_SUGGEST ? R.color.textBlackB1 : R.color.textBlackB3));
if (i == POSITION_ATTENTION) {
// textView.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.mipmap.icon_triangle_n, 0);
//反射设置TabLayout的点击事件
Class c = tab.getClass();
try {
Field field = c.getDeclaredField("view");
field.setAccessible(true);
View view = (View) field.get(tab);
if (view != null) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (viewPager.getCurrentItem() == POSITION_ATTENTION) {
// showTabMenuPopup(textView, v, tab);
} else {
tabLayout.selectTab(tab);
}
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
if (tabName.equals("0")){
tabLayout.postDelayed(new Runnable() {
@Override
public void run() {
tabLayout.getTabAt(0);
viewPager.setCurrentItem(0, false);
}
},100);
}else if (tabName.equals("1")){
tabLayout.postDelayed(new Runnable() {
@Override
public void run() {
tabLayout.getTabAt(1);
viewPager.setCurrentItem(1, false);
}
},100);
}else if (tabName.equals("2")){
tabLayout.postDelayed(new Runnable() {
@Override
public void run() {
tabLayout.getTabAt(2);
viewPager.setCurrentItem(2, false);
}
},100);
}else {
tabLayout.postDelayed(new Runnable() {
@Override
public void run() {
tabLayout.getTabAt(3);
viewPager.setCurrentItem(3, false);
}
},100);
}
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
// switch (tab.getPosition()) {
// case 0:
// tab.getCustomView().findViewById(R.id.iv_image).setBackgroundResource(R.mipmap.icon_shouyixiangqing);
// break;
// case 1:
// tab.getCustomView().findViewById(R.id.iv_image).setBackgroundResource(R.mipmap.icon_guifanshuoming);
// break;
// case 2:
// tab.getCustomView().findViewById(R.id.iv_image).setBackgroundResource(R.mipmap.icon_xinyongfenguize);
// break;
// case 3:
// tab.getCustomView().findViewById(R.id.iv_image).setBackgroundResource(R.mipmap.icon_yunchaungjihua);
// break;
// }
TextView textView = (TextView) tab.getCustomView().findViewById(R.id.tv_text);
textView.setText(tab.getText());
textView.setTextColor(getResources().getColor(R.color.textBlackB1));
textView.getPaint().setFakeBoldText(true);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
TextView textView = (TextView) tab.getCustomView().findViewById(R.id.tv_text);
textView.setText(tab.getText());
textView.setTextColor(getResources().getColor(R.color.textBlackB3));
textView.getPaint().setFakeBoldText(false);
if (tab.getPosition() == POSITION_ATTENTION) {
textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
// viewPager.setCurrentItem(0, false);
}
@Override
public void initEvent() {
}
}
... ...
package com.yinhebairong.shejiao.mine;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.google.android.material.tabs.TabLayout;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BasePBActivity;
import com.yinhebairong.shejiao.main.adapter.MyAdapter;
import com.yinhebairong.shejiao.main.bean.TabBean;
import com.yinhebairong.shejiao.mine.fragment.CreatorOpusFragment;
import com.yinhebairong.shejiao.square.MomentListFragment;
import com.yinhebairong.shejiao.util.DebugLog;
import com.yinhebairong.shejiao.view.ViewPagerForScrollView;
import com.yinhebairong.shejiao.view.ScrollableNestedScrollView;
import com.yinhebairong.shejiao.view.TitleBar;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.OnClick;
import static com.yinhebairong.shejiao.main.fragment.SquareFragment.POSITION_ATTENTION;
import static com.yinhebairong.shejiao.main.fragment.SquareFragment.POSITION_SUGGEST;
/**
* Time: 9/14/2021 11:19
* Author: Captain
* Description: 初见时你很迷人
* 创作者首页
* 根据是否加入创作者参数判断布局
*/
public class CreatorHomePageActivity extends BasePBActivity {
@BindView(R.id.title_bar)
TitleBar titleBar;
@BindView(R.id.ll_bofang_num)
LinearLayout ll_bofang_num;
@BindView(R.id.nsv)
ScrollableNestedScrollView mNsv;
@BindView(R.id.tab_layout)
TabLayout tabLayout;
@BindView(R.id.viewPager)
ViewPagerForScrollView viewPager;
@BindView(R.id.ll_unjoin_quanyi)
LinearLayout ll_unjoin_quanyi;
@BindView(R.id.ll_joined_quanyi)
LinearLayout ll_joined_quanyi;
@BindView(R.id.tv_join_chuangzuozhe)
TextView tv_join_chuangzuozhe;
private List<TabBean> mTabBeanList;
private List<Fragment> fragmentList = new ArrayList<>();
private MyAdapter fragmentAdapter;
private int is_creator;
@Override
public int getLayoutId() {
return R.layout.activity_creator_home_page;
}
@Override
public void initView(Bundle savedInstanceState) {
is_creator = getIntent().getIntExtra("is_creator",-1);
Log.e("is_creator1111",is_creator + "");
if (is_creator == 0){
//没有加入创作者计划
ll_unjoin_quanyi.setVisibility(View.VISIBLE);
ll_joined_quanyi.setVisibility(View.GONE);
tv_join_chuangzuozhe.setVisibility(View.VISIBLE);
tabLayout.setVisibility(View.GONE);
viewPager.setVisibility(View.GONE);
}else if (is_creator == 1){
//加入了创作者计划
ll_unjoin_quanyi.setVisibility(View.GONE);
ll_joined_quanyi.setVisibility(View.VISIBLE);
tv_join_chuangzuozhe.setVisibility(View.GONE);
tabLayout.setVisibility(View.VISIBLE);
viewPager.setVisibility(View.VISIBLE);
}else {
showToast("发生错误");
finish();
}
// titleBar.setRightText("发布");
// titleBar.setRightBg(mContext.getResources().getDrawable(R.drawable.bg_join_chaungzuozhe));
//自定义触摸事件拦截,用来处理滑动冲突,以实现TabLayout吸顶效果
mNsv.setOnScrollListener(new ScrollableNestedScrollView.OnScrollListener() {
@Override
public void onScrollChange(int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
DebugLog.d("scrollY=" + scrollY + " customBanner=" + ll_bofang_num.getMeasuredHeight() + " titleBar=" + titleBar.getMeasuredHeight());
if (scrollY >= ll_bofang_num.getMeasuredHeight()) {
titleBar.setBgColor(Color.WHITE);
titleBar.setTitleText("创作首页");
titleBar.setLeftDrawable(mContext.getResources().getDrawable(R.mipmap.icon_common_back3x));
} else {
titleBar.setBgColor(Color.TRANSPARENT);
titleBar.setTitleText("创作首页");
titleBar.setLeftDrawable(mContext.getResources().getDrawable(R.mipmap.icon_common_back3x));
}
}
@Override
public boolean onTouchMoved(int downX, int downY, int moveX, int moveY) {
if (mNsv.getScrollY() == 0) {
//在顶部时
//下拉的话不拦截(执行下拉刷新) 上滑就拦截让头部往上滚
// if (moveY > downY) {
// return false;
// } else {
// return true;
// }
return true;
} else if (mNsv.getScrollY() < (ll_bofang_num.getMeasuredHeight() - titleBar.getMeasuredHeight())) {
//不在顶部,并且tabLayout还没置顶,就拦截掉,让它整体滚
return true;
} else {
//如果tabLayout已经置顶
//下滑的话,如果fragment中的列表已置顶,就拦截掉,否则不拦截
// if (moveY > downY) {
// return getCurrentFragment().isScrolledToTop();
// } else {
// return false;
// }
return true;
}
}
});
mTabBeanList = new ArrayList<>();
mTabBeanList.add(new TabBean("全部", true));//0
mTabBeanList.add(new TabBean("已发布", false));//1
mTabBeanList.add(new TabBean("未发布", false));
// todo 隐藏榜单
// mTabBeanList.add(new TabBean("榜单", false));
fragmentList.add(new CreatorOpusFragment().setType(CreatorOpusFragment.TYPE_SUGGEST));
fragmentList.add(new CreatorOpusFragment().setType(CreatorOpusFragment.TYPE_ATTENTION));
// topicNewFragment = new TopicNewFragment();
fragmentList.add(new CreatorOpusFragment().setType(CreatorOpusFragment.TYPE_SUGGEST));
// todo 隐藏榜单
// fragmentList.add(new RankingListFragment());
fragmentAdapter = new MyAdapter(getSupportFragmentManager(), fragmentList, mTabBeanList);
viewPager.setAdapter(fragmentAdapter);
viewPager.setOffscreenPageLimit(fragmentList.size());
tabLayout.setupWithViewPager(viewPager);
// viewPager.resetHeight(0);
//初始化Tab样式
for (int i = 0; i < tabLayout.getTabCount(); i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i);
if (tab != null) {
TextView textView = (TextView) LayoutInflater.from(this).inflate(R.layout.tab_item_text, null);
textView.setText(tab.getText());
textView.getPaint().setFakeBoldText(i == POSITION_SUGGEST);
textView.setTextColor(getResources().getColor(i == POSITION_SUGGEST ? R.color.textBlackB1 : R.color.textBlackB3));
textView.setTextSize(i == POSITION_SUGGEST ? 16 : 14);
if (i == POSITION_ATTENTION) {
// textView.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.mipmap.icon_triangle_n, 0);
//反射设置TabLayout的点击事件
Class c = tab.getClass();
try {
Field field = c.getDeclaredField("view");
field.setAccessible(true);
View view = (View) field.get(tab);
if (view != null) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (viewPager.getCurrentItem() == POSITION_ATTENTION) {
// showTabMenuPopup(textView, v, tab);
} else {
tabLayout.selectTab(tab);
}
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
tab.setCustomView(textView);
}
}
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
// int pos = tab.getPosition();
// viewPager.resetHeight(pos);
// viewPager.setCurrentItem(pos);
TextView textView = tab.getCustomView() == null ?
(TextView) LayoutInflater.from(CreatorHomePageActivity.this).inflate(R.layout.tab_item_text, null) :
(TextView) tab.getCustomView();
textView.setText(tab.getText());
textView.setTextSize(16);
textView.setTextColor(getResources().getColor(R.color.textBlackB1));
textView.getPaint().setFakeBoldText(true);
tab.setCustomView(textView);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
TextView textView = tab.getCustomView() == null ?
(TextView) LayoutInflater.from(CreatorHomePageActivity.this).inflate(R.layout.tab_item_text, null) :
(TextView) tab.getCustomView();
textView.setText(tab.getText());
textView.setTextSize(14);
textView.setTextColor(getResources().getColor(R.color.textBlackB3));
textView.getPaint().setFakeBoldText(false);
if (tab.getPosition() == POSITION_ATTENTION) {
textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
tab.setCustomView(textView);
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
viewPager.setCurrentItem(0, false);
}
@Override
public void initEvent() {
}
@OnClick({R.id.ll_shouyi_detail,R.id.ll_guifanshuoming,R.id.ll_xinyongfenguize,R.id.ll_yunchuangjihua})
void onClick(View view){
Intent intent = new Intent();
switch (view.getId()){
case R.id.ll_shouyi_detail:
//创作简介-收益详情
intent.setClass(this, CreateIntroduceActivity.class);
intent.putExtra("tabName","0");
startActivity(intent);
break;
case R.id.ll_guifanshuoming:
//创作简介-规范说明
intent.setClass(this, CreateIntroduceActivity.class);
intent.putExtra("tabName","1");
startActivity(intent);
break;
case R.id.ll_xinyongfenguize:
//创作简介-信用分规则
intent.setClass(this, CreateIntroduceActivity.class);
intent.putExtra("tabName","2");
startActivity(intent);
break;
case R.id.ll_yunchuangjihua:
//创作简介-云创计划
intent.setClass(this, CreateIntroduceActivity.class);
intent.putExtra("tabName","3");
startActivity(intent);
break;
}
}
}
... ...
package com.yinhebairong.shejiao.mine;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.PercentFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.MPPointF;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BasePBActivity;
import com.yinhebairong.shejiao.mine.adapter.AreaPercentAdapter;
import com.yinhebairong.shejiao.mine.model.AttentionModel;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.OnClick;
/**
* Time: 9/16/2021 17:26
* Author: Captain
* Description: 初见时你很迷人
*/
public class CreatorWorksDetailActivity extends BasePBActivity implements OnChartValueSelectedListener {
@BindView(R.id.pie_chart)
PieChart pieChart;
@BindView(R.id.bar_chart)
BarChart barChart;
@BindView(R.id.rv_area)
RecyclerView rvArea;
private AreaPercentAdapter areaPercentAdapter;
@Override
public int getLayoutId() {
return R.layout.activity_creator_works_detail;
}
@Override
public void initView(Bundle savedInstanceState) {
showPieChart();
showBarChart();
showAreaPercentage();
}
//男女比例饼状图
private void showPieChart() {
pieChart.setUsePercentValues(false);
pieChart.getDescription().setEnabled(false);
pieChart.setExtraOffsets(-10, 0, 0, 0);
pieChart.setDragDecelerationFrictionCoef(0.95f);
// pieChart.setCenterTextTypeface(tfLight);
// pieChart.setCenterText(generateCenterSpannableText());
pieChart.setDrawHoleEnabled(true);
pieChart.setDrawEntryLabels(false);
pieChart.setHoleColor(Color.WHITE);
pieChart.setTransparentCircleColor(Color.WHITE);
pieChart.setTransparentCircleAlpha(110);
pieChart.setHoleRadius(70f);
pieChart.setTransparentCircleRadius(0f);
pieChart.setDrawCenterText(true);
pieChart.setRotationAngle(0);
// pieChartable rotation of the chart by touch
pieChart.setRotationEnabled(false);
pieChart.setHighlightPerTapEnabled(true);
pieChart.setOnChartValueSelectedListener(this);
Legend l = pieChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.CENTER);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setForm(Legend.LegendForm.CIRCLE);
l.setTextSize(12);
l.setFormSize(9);
l.setDrawInside(false);
l.setXEntrySpace(7f);
l.setYEntrySpace(20f);
l.setYOffset(0f);
pieChart.setEntryLabelColor(Color.WHITE);
// pieChart.setEntryLabelTypeface(tfRegular);
pieChart.setEntryLabelTextSize(12f);
ArrayList<PieEntry> entries = new ArrayList<>();
// NOTE: The order of the entries when being added to the entries array determines their position around the center of
// the chart.
// for (int i = 0; i < 2 ; i++) {
// entries.add(new PieEntry((float) ((Math.random() * range) + range / 5),
// parties[i % parties.length],
// getResources().getDrawable(R.drawable.star)));
// }
entries.add(new PieEntry(0.55f, "男性 52%"));
entries.add(new PieEntry(0.45f, "女性 48%"));
PieDataSet dataSet = new PieDataSet(entries, "");
dataSet.setDrawIcons(false);
dataSet.setSliceSpace(3f);
dataSet.setIconsOffset(new MPPointF(0, 40));
dataSet.setSelectionShift(5f);
// add a lot of colors
ArrayList<Integer> colors = new ArrayList<>();
colors.add(getResources().getColor(R.color.theme));
colors.add(getResources().getColor(R.color.textWarning));
// for (int c : ColorTemplate.VORDIPLOM_COLORS)
// colors.add(c);
//
// for (int c : ColorTemplate.JOYFUL_COLORS)
// colors.add(c);
//
// for (int c : ColorTemplate.COLORFUL_COLORS)
// colors.add(c);
//
// for (int c : ColorTemplate.LIBERTY_COLORS)
// colors.add(c);
//
// for (int c : ColorTemplate.PASTEL_COLORS)
// colors.add(c);
//
// colors.add(ColorTemplate.getHoloBlue());
dataSet.setColors(colors);
//dataSet.setSelectionShift(0f);
PieData data = new PieData(dataSet);
data.setValueFormatter(new PercentFormatter());
data.setValueTextSize(11f);
data.setValueTextColor(Color.TRANSPARENT);
// data.setValueTypeface(tfLight);
pieChart.setData(data);
// undo all highlights
pieChart.highlightValues(null);
pieChart.invalidate();
}
//年龄分布柱状图
private void showBarChart() {
barChart.getDescription().setEnabled(false); // 不显示描述
barChart.setExtraOffsets(20, 20, 20, 20); // 设置饼图的偏移量,相似于内边距 ,设置视图窗口大小
barChart.setTouchEnabled(false);
Legend legend = barChart.getLegend();
//不显示图例
legend.setForm(Legend.LegendForm.NONE);
// 设置坐标轴
// 设置x轴
XAxis xAxis = barChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); // 设置x轴显示在下方,默认在上方
xAxis.setDrawGridLines(false); // 将此设置为true,绘制该轴的网格线。
xAxis.setLabelCount(6); // 设置x轴上的标签个数
xAxis.setTextSize(12); // x轴上标签的大小
final String labelName[] = {"<18", "18~23", "24~30", "31~40", "41~50", ">50"};
// 设置x轴显示的值的格式
xAxis.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
if ((int) value < labelName.length) {
return labelName[(int) value];
} else {
return "";
}
}
});
xAxis.setYOffset(15); // 设置标签对x轴的偏移量,垂直方向
// 设置y轴,y轴有两条,分别为左和右
YAxis yAxis_right = barChart.getAxisRight();
yAxis_right.setAxisMaximum(40f); // 设置y轴的最大值
yAxis_right.setAxisMinimum(0f); // 设置y轴的最小值
yAxis_right.setEnabled(false); // 不显示右边的y轴
YAxis yAxis_left = barChart.getAxisLeft();
yAxis_left.setAxisMaximum(40f);
yAxis_left.setAxisMinimum(0f);
yAxis_left.setLabelCount(5);
yAxis_left.setTextSize(12); // 设置y轴的标签大小
final String ylabelName[] = {"0%", "10%", "20%", "30%", "40%"};
yAxis_left.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
if ((int) value < ylabelName.length) {
return ylabelName[(int) value];
} else {
return (int) value + "%";
}
}
});
// 设置数据
List<IBarDataSet> sets = new ArrayList<>();
// 此处有两个DataSet,因此有两条柱子,BarEntry()中的x和y分别表示显示的位置和高度
// x是横坐标,表示位置,y是纵坐标,表示高度
List<BarEntry> barEntries1 = new ArrayList<>();
barEntries1.add(new BarEntry(0, 5f));
barEntries1.add(new BarEntry(1, 10f));
barEntries1.add(new BarEntry(2, 40f));
barEntries1.add(new BarEntry(3, 15f));
barEntries1.add(new BarEntry(4, 35f));
barEntries1.add(new BarEntry(5, 23f));
BarDataSet barDataSet1 = new BarDataSet(barEntries1, "");
barDataSet1.setValueTextColor(Color.TRANSPARENT); // 值的颜色
// barDataSet1.setValueTextSize(15f); // 值的大小
barDataSet1.setColor(getResources().getColor(R.color.theme)); // 柱子的颜色
sets.add(barDataSet1);
BarData barData = new BarData(sets);
barData.setBarWidth(0.4f); // 设置柱子的宽度
barChart.setData(barData);
barChart.getXAxis().setDrawGridLines(false);
barChart.getAxisLeft().setDrawAxisLine(false);
}
//显示地域分布
private void showAreaPercentage() {
areaPercentAdapter = new AreaPercentAdapter(this);
rvArea.setLayoutManager(new LinearLayoutManager(this));
rvArea.setAdapter(areaPercentAdapter);
AttentionModel attentionModel = new AttentionModel();
List<AttentionModel> attentionModelList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
attentionModel.setNickname2("河南");
}
attentionModelList.add(attentionModel);
areaPercentAdapter.resetDataList(attentionModelList);
}
@Override
public void initEvent() {
}
@OnClick({R.id.tv_see_data_analysis, R.id.tv_all_area})
void onClick(View view) {
Intent intent = new Intent();
switch (view.getId()) {
case R.id.tv_see_data_analysis:
//查看记录
intent.setClass(this, SeeDataAnalysisActivity.class);
startActivity(intent);
break;
case R.id.tv_all_area:
//查看记录
intent.setClass(this, AllAreaActivity.class);
startActivity(intent);
break;
}
}
@Override
public void onValueSelected(Entry e, Highlight h) {
}
@Override
public void onNothingSelected() {
}
}
... ...
package com.yinhebairong.shejiao.mine;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BasePBActivity;
import com.yinhebairong.shejiao.main.adapter.MyAdapter;
import com.yinhebairong.shejiao.main.bean.TabBean;
import com.yinhebairong.shejiao.mine.fragment.CreatorWorksFragment;
import com.yinhebairong.shejiao.mine.fragment.DataAnalysisFansFragment;
import com.yinhebairong.shejiao.square.MomentListFragment;
import com.yinhebairong.shejiao.view.ViewPagerForScrollView;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import static com.yinhebairong.shejiao.main.fragment.SquareFragment.POSITION_ATTENTION;
import static com.yinhebairong.shejiao.main.fragment.SquareFragment.POSITION_SUGGEST;
/**
* Time: 9/15/2021 9:02
* Author: Captain
* Description: 初见时你很迷人
*/
public class DataAnalysisActivity extends BasePBActivity {
@BindView(R.id.tab_layout)
TabLayout tabLayout;
@BindView(R.id.viewPager)
ViewPager viewPager;
private List<TabBean> mTabBeanList;
private List<Fragment> fragmentList = new ArrayList<>();
private MyAdapter fragmentAdapter;
@Override
public int getLayoutId() {
return R.layout.activity_data_analysis;
}
@Override
public void initView(Bundle savedInstanceState) {
mTabBeanList = new ArrayList<>();
mTabBeanList.add(new TabBean("作品", true));//0
mTabBeanList.add(new TabBean("粉丝", false));//1
fragmentList.add(new CreatorWorksFragment());
fragmentList.add(new DataAnalysisFansFragment());
fragmentAdapter = new MyAdapter(getSupportFragmentManager(), fragmentList, mTabBeanList);
viewPager.setAdapter(fragmentAdapter);
viewPager.setOffscreenPageLimit(fragmentList.size());
tabLayout.setupWithViewPager(viewPager);
//初始化Tab样式
for (int i = 0; i < tabLayout.getTabCount(); i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i);
if (tab != null) {
TextView textView = (TextView) LayoutInflater.from(this).inflate(R.layout.tab_item_text, null);
textView.setText(tab.getText());
textView.getPaint().setFakeBoldText(i == POSITION_SUGGEST);
textView.setTextColor(getResources().getColor(i == POSITION_SUGGEST ? R.color.textBlackB1 : R.color.textBlackB3));
textView.setTextSize(i == POSITION_SUGGEST ? 16 : 14);
if (i == POSITION_ATTENTION) {
// textView.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.mipmap.icon_triangle_n, 0);
//反射设置TabLayout的点击事件
Class c = tab.getClass();
try {
Field field = c.getDeclaredField("view");
field.setAccessible(true);
View view = (View) field.get(tab);
if (view != null) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (viewPager.getCurrentItem() == POSITION_ATTENTION) {
// showTabMenuPopup(textView, v, tab);
} else {
tabLayout.selectTab(tab);
}
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
tab.setCustomView(textView);
}
}
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
TextView textView = tab.getCustomView() == null ?
(TextView) LayoutInflater.from(DataAnalysisActivity.this).inflate(R.layout.tab_item_text, null) :
(TextView) tab.getCustomView();
textView.setText(tab.getText());
textView.setTextSize(16);
textView.setTextColor(getResources().getColor(R.color.textBlackB1));
textView.getPaint().setFakeBoldText(true);
// if (tab.getPosition() == POSITION_ATTENTION) {
// textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.mipmap.icon_triangle_n, 0);
// }
tab.setCustomView(textView);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
TextView textView = tab.getCustomView() == null ?
(TextView) LayoutInflater.from(DataAnalysisActivity.this).inflate(R.layout.tab_item_text, null) :
(TextView) tab.getCustomView();
textView.setText(tab.getText());
textView.setTextSize(14);
textView.setTextColor(getResources().getColor(R.color.textBlackB3));
textView.getPaint().setFakeBoldText(false);
if (tab.getPosition() == POSITION_ATTENTION) {
textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
tab.setCustomView(textView);
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
viewPager.setCurrentItem(0, false);
}
@Override
public void initEvent() {
}
}
... ...
package com.yinhebairong.shejiao.mine;
import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BasePBActivity;
import com.yinhebairong.shejiao.mine.adapter.IncomeCashRecordAdapter;
import com.yinhebairong.shejiao.mine.adapter.IncomeDetailAdapter;
import com.yinhebairong.shejiao.mine.model.AttentionModel;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
/**
* Time: 9/17/2021 11:10
* Author: Captain
* Description: 初见时你很迷人
* 收益提现记录
*/
public class IncomeCashRecordActivity extends BasePBActivity {
@BindView(R.id.recyclerview)
RecyclerView recyclerview;
private IncomeCashRecordAdapter recordAdapter;
@Override
public int getLayoutId() {
return R.layout.activity_income_cash_record;
}
@Override
public void initView(Bundle savedInstanceState) {
recordAdapter = new IncomeCashRecordAdapter(this);
recyclerview.setLayoutManager(new LinearLayoutManager(this));
recyclerview.setAdapter(recordAdapter);
AttentionModel attentionModel = new AttentionModel();
List<AttentionModel> attentionModelList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
attentionModel.setNickname2("2020.10.01");
attentionModelList.add(attentionModel);
}
recordAdapter.resetDataList(attentionModelList);
}
@Override
public void initEvent() {
}
}
... ...
package com.yinhebairong.shejiao.mine;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BasePBActivity;
import com.yinhebairong.shejiao.main.adapter.MyAdapter;
import com.yinhebairong.shejiao.main.bean.TabBean;
import com.yinhebairong.shejiao.mine.adapter.AreaPercentAdapter;
import com.yinhebairong.shejiao.mine.adapter.IncomeDetailAdapter;
import com.yinhebairong.shejiao.mine.fragment.IncomeLineChartFragment;
import com.yinhebairong.shejiao.mine.model.AttentionModel;
import com.yinhebairong.shejiao.square.MomentListFragment;
import com.yinhebairong.shejiao.util.DebugLog;
import com.yinhebairong.shejiao.view.ScrollableNestedScrollView;
import com.yinhebairong.shejiao.view.TitleBar;
import com.yinhebairong.shejiao.view.ViewPagerForScrollView;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.OnClick;
import static com.yinhebairong.shejiao.main.fragment.SquareFragment.POSITION_ATTENTION;
import static com.yinhebairong.shejiao.main.fragment.SquareFragment.POSITION_SUGGEST;
/**
* Time: 9/16/2021 17:36
* Author: Captain
* Description: 初见时你很迷人
* 我的收益页面
*/
public class MyIncomeActivity extends BasePBActivity {
@BindView(R.id.recyclerview)
RecyclerView recyclerview;
@BindView(R.id.tab_layout)
TabLayout tabLayout;
@BindView(R.id.viewPager)
ViewPager viewPager;
@BindView(R.id.nsv)
ScrollableNestedScrollView mNsv;
@BindView(R.id.rl_top)
RelativeLayout rlTop;
@BindView(R.id.title_bar)
TitleBar titleBar;
private IncomeDetailAdapter incomeDetailAdapter;
private List<TabBean> mTabBeanList;
private List<Fragment> fragmentList = new ArrayList<>();
private MyAdapter fragmentAdapter;
@Override
public int getLayoutId() {
return R.layout.activity_my_income;
}
@Override
public void initView(Bundle savedInstanceState) {
setUpTitleBarTouched();
setUpViewpager();
setUpRecyclerview();
}
private void setUpTitleBarTouched(){
//自定义触摸事件拦截,用来处理滑动冲突,以实现TabLayout吸顶效果
mNsv.setOnScrollListener(new ScrollableNestedScrollView.OnScrollListener() {
@Override
public void onScrollChange(int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
DebugLog.d("scrollY=" + scrollY + " customBanner=" + rlTop.getMeasuredHeight() + " titleBar=" + titleBar.getMeasuredHeight());
if (scrollY >= rlTop.getMeasuredHeight()) {
titleBar.setBgColor(Color.parseColor("#0EBDD6"));
titleBar.setTitleText("我的收益");
titleBar.setLeftDrawable(mContext.getResources().getDrawable(R.mipmap.icon_common_whiteback3x));
} else {
titleBar.setBgColor(Color.TRANSPARENT);
titleBar.setTitleText("我的收益");
titleBar.setLeftDrawable(mContext.getResources().getDrawable(R.mipmap.icon_common_whiteback3x));
}
}
@Override
public boolean onTouchMoved(int downX, int downY, int moveX, int moveY) {
if (mNsv.getScrollY() == 0) {
//在顶部时
//下拉的话不拦截(执行下拉刷新) 上滑就拦截让头部往上滚
// if (moveY > downY) {
// return false;
// } else {
// return true;
// }
return true;
} else if (mNsv.getScrollY() < (rlTop.getMeasuredHeight() - titleBar.getMeasuredHeight())) {
//不在顶部,并且tabLayout还没置顶,就拦截掉,让它整体滚
return true;
} else {
//如果tabLayout已经置顶
//下滑的话,如果fragment中的列表已置顶,就拦截掉,否则不拦截
// if (moveY > downY) {
// return getCurrentFragment().isScrolledToTop();
// } else {
// return false;
// }
return true;
}
}
});
}
private void setUpRecyclerview() {
incomeDetailAdapter = new IncomeDetailAdapter(this);
recyclerview.setLayoutManager(new LinearLayoutManager(this));
recyclerview.setAdapter(incomeDetailAdapter);
AttentionModel attentionModel = new AttentionModel();
List<AttentionModel> attentionModelList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
attentionModel.setNickname2("2020.10.01");
attentionModelList.add(attentionModel);
}
incomeDetailAdapter.resetDataList(attentionModelList);
}
private void setUpViewpager() {
mTabBeanList = new ArrayList<>();
mTabBeanList.add(new TabBean("近7日收益", true));//0
mTabBeanList.add(new TabBean("近1月收益", false));//1
mTabBeanList.add(new TabBean("年收益", false));
// todo 隐藏榜单
// mTabBeanList.add(new TabBean("榜单", false));
fragmentList.add(new IncomeLineChartFragment());
fragmentList.add(new IncomeLineChartFragment());
// topicNewFragment = new TopicNewFragment();
fragmentList.add(new IncomeLineChartFragment());
// todo 隐藏榜单
// fragmentList.add(new RankingListFragment());
fragmentAdapter = new MyAdapter(getSupportFragmentManager(), fragmentList, mTabBeanList);
viewPager.setAdapter(fragmentAdapter);
viewPager.setOffscreenPageLimit(fragmentList.size());
tabLayout.setupWithViewPager(viewPager);
// viewPager.resetHeight(0);
//初始化Tab样式
for (int i = 0; i < tabLayout.getTabCount(); i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i);
if (tab != null) {
TextView textView = (TextView) LayoutInflater.from(this).inflate(R.layout.tab_item_text, null);
textView.setText(tab.getText());
textView.getPaint().setFakeBoldText(i == POSITION_SUGGEST);
textView.setTextColor(getResources().getColor(i == POSITION_SUGGEST ? R.color.textBlackB1 : R.color.textBlackB3));
textView.setTextSize(i == POSITION_SUGGEST ? 16 : 14);
if (i == POSITION_ATTENTION) {
// textView.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.mipmap.icon_triangle_n, 0);
//反射设置TabLayout的点击事件
Class c = tab.getClass();
try {
Field field = c.getDeclaredField("view");
field.setAccessible(true);
View view = (View) field.get(tab);
if (view != null) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (viewPager.getCurrentItem() == POSITION_ATTENTION) {
// showTabMenuPopup(textView, v, tab);
} else {
tabLayout.selectTab(tab);
}
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
tab.setCustomView(textView);
}
}
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
// int pos = tab.getPosition();
// viewPager.resetHeight(pos);
// viewPager.setCurrentItem(pos);
TextView textView = tab.getCustomView() == null ?
(TextView) LayoutInflater.from(MyIncomeActivity.this).inflate(R.layout.tab_item_text, null) :
(TextView) tab.getCustomView();
textView.setText(tab.getText());
textView.setTextSize(16);
textView.setTextColor(getResources().getColor(R.color.textBlackB1));
textView.getPaint().setFakeBoldText(true);
tab.setCustomView(textView);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
TextView textView = tab.getCustomView() == null ?
(TextView) LayoutInflater.from(MyIncomeActivity.this).inflate(R.layout.tab_item_text, null) :
(TextView) tab.getCustomView();
textView.setText(tab.getText());
textView.setTextSize(14);
textView.setTextColor(getResources().getColor(R.color.textBlackB3));
textView.getPaint().setFakeBoldText(false);
if (tab.getPosition() == POSITION_ATTENTION) {
textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
tab.setCustomView(textView);
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
viewPager.setCurrentItem(0, false);
}
@Override
public void initEvent() {
}
@OnClick({R.id.iv_income_cash_record})
void onClick(View view){
Intent intent = new Intent();
switch (view.getId()){
case R.id.iv_income_cash_record:
//提现记录
intent.setClass(this, IncomeCashRecordActivity.class);
startActivity(intent);
break;
}
}
}
... ...
package com.yinhebairong.shejiao.mine;
import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BasePBActivity;
import com.yinhebairong.shejiao.mine.adapter.SeeDataAnalysisAdapter;
import com.yinhebairong.shejiao.mine.model.AttentionModel;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
/**
* Time: 9/16/2021 16:11
* Author: Captain
* Description: 初见时你很迷人
*/
public class SeeDataAnalysisActivity extends BasePBActivity {
@BindView(R.id.rv_see_data_analysis)
RecyclerView recyclerView;
private SeeDataAnalysisAdapter analysisAdapter;
@Override
public int getLayoutId() {
return R.layout.activity_see_data_analysis;
}
@Override
public void initView(Bundle savedInstanceState) {
analysisAdapter = new SeeDataAnalysisAdapter(this);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(analysisAdapter);
AttentionModel attentionModel = new AttentionModel();
List<AttentionModel> attentionModelList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
attentionModel.setRecentTime("09-01");
attentionModel.setNickname2("66");
attentionModelList.add(attentionModel);
}
analysisAdapter.resetDataList(attentionModelList);
}
@Override
public void initEvent() {
}
}
... ...
package com.yinhebairong.shejiao.mine;
import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BasePBActivity;
import com.yinhebairong.shejiao.mine.adapter.SeeDataAnalysisAdapter;
import com.yinhebairong.shejiao.mine.adapter.SeeFansDataAnalysisAdapter;
import com.yinhebairong.shejiao.mine.model.AttentionModel;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
/**
* Time: 9/16/2021 16:11
* Author: Captain
* Description: 初见时你很迷人
*/
public class SeeFansDataAnalysisActivity extends BasePBActivity {
@BindView(R.id.rv_see_data_analysis)
RecyclerView recyclerView;
private SeeFansDataAnalysisAdapter seeFansDataAnalysisAdapter;
@Override
public int getLayoutId() {
return R.layout.activity_see_data_analysis;
}
@Override
public void initView(Bundle savedInstanceState) {
seeFansDataAnalysisAdapter = new SeeFansDataAnalysisAdapter(this);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(seeFansDataAnalysisAdapter);
AttentionModel attentionModel = new AttentionModel();
List<AttentionModel> attentionModelList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
attentionModel.setRecentTime("09-03");
attentionModel.setNickname2("66");
attentionModelList.add(attentionModel);
}
seeFansDataAnalysisAdapter.resetDataList(attentionModelList);
}
@Override
public void initEvent() {
}
}
... ...
package com.yinhebairong.shejiao.mine.adapter;
import android.content.Context;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BaseRvAdapter;
import com.yinhebairong.shejiao.base.BaseViewHolder;
import com.yinhebairong.shejiao.mine.model.AttentionModel;
/**
* Time: 9/16/2021 15:46
* Author: Captain
* Description: 初见时你很迷人
*/
public class AreaPercentAdapter extends BaseRvAdapter<AttentionModel> {
public AreaPercentAdapter(Context mContext) {
super(mContext);
}
@Override
protected int getLayoutId(int viewType) {
return R.layout.item_area_percent;
}
@Override
protected void bindData(BaseViewHolder holder, AttentionModel data, int position) {
}
}
... ...
package com.yinhebairong.shejiao.mine.adapter;
import android.content.Context;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BaseRvAdapter;
import com.yinhebairong.shejiao.base.BaseViewHolder;
import com.yinhebairong.shejiao.base.Config;
import com.yinhebairong.shejiao.base.Constants;
import com.yinhebairong.shejiao.base.ItemDivider;
import com.yinhebairong.shejiao.square.adapter.OnMomentItemListener;
import com.yinhebairong.shejiao.square.adapter.ZoneImageAdapter2;
import com.yinhebairong.shejiao.square.model.MomentModel;
import com.yinhebairong.shejiao.topic.model.TopicRankModel;
import com.yinhebairong.shejiao.util.GridLayoutHelper;
import com.yinhebairong.shejiao.util.ScreenUtil;
import com.yinhebairong.shejiao.util.SharedPreferenceUtil;
import com.yinhebairong.shejiao.util.TopicUtil;
import com.yinhebairong.shejiao.view.FlowLayout;
import com.yinhebairong.shejiao.view.LikeButton;
import com.yinhebairong.shejiao.view.MyGSYVideoPlayer;
import java.util.ArrayList;
import java.util.List;
/**
* @ClassName: MomentAdapter
* @Author: Lau
* @CreateDate: 2020/9/29 15:07
* @Description:
*/
public class CreatorOpusAdapter extends BaseRvAdapter<MomentModel> {
public static final String TYPE_IMAGE = "img";
public static final String TYPE_VIDEO = "mp4";
public static final String TYPE_TEXT_ONLY = "not";
public final int ITEM_TYPE_IMAGE = 1;
public final int ITEM_TYPE_VIDEO = 2;
public final int ITEM_TYPE_TEXT_ONLY = 3;
private List<BaseViewHolder> viewHolderList = new ArrayList<>();
private OnCreatorOpusItemClickListener onCreatorOpusItemClickListener = new CreatorOpusItemListener(this, mContext) {
@Override
public void onLikeClick(View view, int position, MomentModel data) {
}
@Override
public void onFollowClick(ImageView imageView, MomentModel data) {
}
};
private boolean isUserPage;
//推荐的时间需要显示成xx秒/分钟/小时/天前推荐
private boolean isSuggest;
private long lastRefreshTime = 0;
public CreatorOpusAdapter(Context mContext, boolean isUserPage) {
super(mContext);
this.isUserPage = isUserPage;
}
public CreatorOpusAdapter setSuggest(boolean suggest) {
isSuggest = suggest;
return this;
}
public void setLastRefreshTime(long lastRefreshTime) {
this.lastRefreshTime = lastRefreshTime;
}
@Override
protected int getLayoutId(int viewType) {
switch (viewType) {
case ITEM_TYPE_TEXT_ONLY:
case ITEM_TYPE_VIDEO:
// return R.layout.item_zone_video;
case ITEM_TYPE_IMAGE:
return R.layout.item_creator_opus;
}
return 0;
}
@Override
public int getItemViewType(int position) {
if (getData(position).getType() == null) {
return ITEM_TYPE_TEXT_ONLY;
}
if (getData(position).getType().equals(TYPE_VIDEO)) {
return ITEM_TYPE_VIDEO;
} else if (getData(position).getType().equals(TYPE_IMAGE)) {
return ITEM_TYPE_IMAGE;
} else {
return ITEM_TYPE_TEXT_ONLY;
}
}
@NonNull
@Override
public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
BaseViewHolder holder = super.onCreateViewHolder(parent, viewType);
this.viewHolderList.add(holder);
return holder;
}
@Override
protected void onAfterInflaterView(View itemView, int viewType) {
if (viewType == ITEM_TYPE_IMAGE) {
RecyclerView rvImage = itemView.findViewById(R.id.rv);
rvImage.setLayoutManager(new GridLayoutManager(mContext, Constants.MOMENT_IMAGE_SPAN));
// rvImage.setAdapter(new ZoneImageAdapter2(R.layout.item_zone_image2, new ArrayList<>(), rvImage));
} else if (viewType == ITEM_TYPE_VIDEO) {
}
}
@Override
protected void bindData(BaseViewHolder holder, MomentModel data, int position) {
if (isUserPage) {
holder.getView(R.id.vg_padding_left).setPadding(ScreenUtil.dp2px(14), 0, ScreenUtil.dp2px(14), 0);
holder.getView(R.id.vg_padding_left2).setPadding(ScreenUtil.dp2px(14), 0, ScreenUtil.dp2px(14), 0);
holder.getView(R.id.vg_padding_left3).setPadding(ScreenUtil.dp2px(14), 0, ScreenUtil.dp2px(14), 0);
holder.getView(R.id.vg_options).setPadding(0, 0, 0, 0);
//权限:look=广场可见,my=自己可见,index=主页可见
holder.setText(R.id.tv_permission, data.getAuth().equals("look") ? "广场可见" : data.getAuth().equals("my") ? "自己可见" : "主页可见")
.setVisibility(R.id.iv_option, data.getUser_id() == Config.USER_ID ? View.VISIBLE : View.GONE)
.setVisibility(R.id.tv_permission, data.getUser_id() == Config.USER_ID ? View.VISIBLE : View.GONE)
.setVisibility(R.id.iv_header, View.GONE)
.setVisibility(R.id.tv_name, View.GONE)
.setVisibility(R.id.iv_vip, View.GONE)
.setVisibility(R.id.tv_top, data.getTop_id() == 0 ? View.GONE : View.VISIBLE);
holder.setImage(R.id.iv_certification, data.getRen_id() != 0 ?
R.mipmap.icon_bigv3x :
data.getStudent_id() == 1 ?
R.mipmap.icon_student_certification : R.mipmap.icon_bigv3x)
.setVisibility(R.id.iv_certification,
(data.getRen_id() != 0 || data.getStudent_id() == 1) ?
View.VISIBLE : View.GONE);
} else {
holder.setVisibility(R.id.iv_option, data.getUser_id() == Config.USER_ID ? View.GONE : View.VISIBLE)
.setVisibility(R.id.tv_permission, View.GONE)
// .setVisibility(R.id.iv_header, View.VISIBLE)
// .setVisibility(R.id.tv_name, View.VISIBLE)
.setVisibility(R.id.iv_vip, data.getUser().getVip_id() == 1 ? View.VISIBLE : View.GONE)
.setImage(R.id.iv_header, R.mipmap.icon_loading_head3x, data.getUser().getAvatar2())
// .setText(R.id.tv_name, data.getUser().getNickname2())
.setVisibility(R.id.tv_top, View.GONE); //认证 优先顺序:大V>学生>不显示
holder.setImage(R.id.iv_certification, data.getUser().getRen_id() != 0 ?
R.mipmap.icon_bigv3x :
data.getUser().isStudent() ?
R.mipmap.icon_student_certification : R.mipmap.icon_bigv3x)
.setVisibility(R.id.iv_certification,
(data.getUser().getRen_id() != 0 || data.getUser().isStudent()) ?
View.VISIBLE : View.GONE);
}
// 设置textView点击时间
TextView tvContent = holder.getView(R.id.tv_content);
TextView tvTips = holder.getView(R.id.tv_tips);
tvContent.setMovementMethod(LinkMovementMethod.getInstance());
//通用的数据
holder.setText(R.id.tv_title, data.getTitle2())
.setVisibility(R.id.tv_title, TextUtils.isEmpty(data.getTitle2()) ? View.GONE : View.VISIBLE)
.setText(R.id.tv_content, TopicUtil.getSpStr(data.getCnt(),holder.itemView.getContext(),data.getHua_arr()))
.setVisibility(R.id.tv_content, TextUtils.isEmpty(data.getCnt()) ? View.GONE : View.VISIBLE)
.setText(R.id.tv_place, data.getArea())
.setVisibility(R.id.vg_place, TextUtils.isEmpty(data.getArea()) ? View.GONE : View.VISIBLE)
.setImage(R.id.iv_zan, data.getZan_id() == 0 ? R.mipmap.icon_like_not : R.mipmap.icon_like_yet)
.setText(R.id.tv_zan, data.getZan_num() + "")
.setText(R.id.tv_ping, data.getPing_num() + "")
.<LikeButton>getView(R.id.lb_like).setCheck(data.getZan_id() == 1);
// 去掉文字块点击出现背景色
tvContent.setHighlightColor(ContextCompat.getColor(mContext, android.R.color.transparent));
LinearLayout linearLayoutTips = holder.getView(R.id.vg_close_tip_off);
ImageView imageViewCloseTips = holder.getView(R.id.iv_close_tip_off);
imageViewCloseTips.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
linearLayoutTips.setVisibility(View.GONE);
SharedPreferenceUtil.put(mContext,"close_tips",true);
}
});
//时间
boolean closeTips = (boolean) SharedPreferenceUtil.get(mContext,"close_tips",false);
if (isSuggest) {
long duration = System.currentTimeMillis() - lastRefreshTime;
if (duration < 1000) {//一秒以内
holder.setText(R.id.tv_time, "刚刚推荐");
} else if (duration < 1000 * 60) {//一分钟以内
holder.setText(R.id.tv_time, duration / 1000 + "秒前推荐");
} else if (duration < 1000 * 60 * 60) {//一小时以内
holder.setText(R.id.tv_time, duration / 60000 + "分钟前推荐");
} else if (duration < 1000 * 60 * 60 * 24) {//一天以内
holder.setText(R.id.tv_time, duration / 3600000 + "小时前推荐");
} else {
holder.setText(R.id.tv_time, duration / 3600000 * 24 + "小时前推荐");
}
if (!closeTips){
if (position == 4){
tvTips.setText("获得礼物打赏可以转化为金币哟");
linearLayoutTips.setVisibility(View.VISIBLE);
}else if (position == 7){
tvTips.setText("金币可以进行现金兑换");
linearLayoutTips.setVisibility(View.VISIBLE);
} else{
linearLayoutTips.setVisibility(View.GONE);
}
}else {
linearLayoutTips.setVisibility(View.GONE);
}
} else {
holder.setText(R.id.tv_time, data.getFa_time());
linearLayoutTips.setVisibility(View.GONE);
}
//设置文字内容是否折叠(查看全部)
// TextView textView = holder.<TextView>getView(R.id.tv_content);
holder.<TextView>getView(R.id.tv_content).getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
holder.<TextView>getView(R.id.tv_content).getViewTreeObserver().removeOnPreDrawListener(this);
if (holder.<TextView>getView(R.id.tv_content).getLineCount() > holder.<TextView>getView(R.id.tv_content).getMaxLines()) {
holder.setVisibility(R.id.tv_show_all_content, View.VISIBLE);
} else {
holder.setVisibility(R.id.tv_show_all_content, View.GONE);
}
return true;
}
});
//点击事件
View.OnClickListener onClickListener = v -> {
switch (v.getId()) {
case R.id.vg_user:
onCreatorOpusItemClickListener.onUserClick(v, position, data);
break;
case R.id.iv_option:
onCreatorOpusItemClickListener.onOptionClick(v, position, data);
break;
case R.id.vg_share:
onCreatorOpusItemClickListener.onShareClick(v, position, data);
break;
case R.id.vg_like:
if (data.getZan_id() == 0) {
data.setZan_id(1);
data.setZan_num(data.getZan_num() + 1);
holder.<LikeButton>getView(R.id.lb_like).setCheck(true, true);
holder.setText(R.id.tv_zan, data.getZan_num() + "");
} else {
data.setZan_id(0);
data.setZan_num(data.getZan_num() - 1);
holder.<LikeButton>getView(R.id.lb_like).setCheck(false, false);
holder.setText(R.id.tv_zan, data.getZan_num() + "");
}
onCreatorOpusItemClickListener.onLikeClick(v, position, data);
break;
case R.id.vg_ping:
onCreatorOpusItemClickListener.onCommentClick(v, position, data);
break;
default:
onCreatorOpusItemClickListener.onItemClick(v, position, data);
}
};
holder.setOnViewClickListener(R.id.vg_user, onClickListener)
.setOnViewClickListener(R.id.iv_option, onClickListener)
.setOnViewClickListener(R.id.vg_share, onClickListener)
.setOnViewClickListener(R.id.vg_like, onClickListener)
.setOnViewClickListener(R.id.vg_ping, onClickListener)
.getRootView().setOnClickListener(onClickListener);
//显示类型
switch (getItemViewType(position)) {
case ITEM_TYPE_TEXT_ONLY:
holder.setVisibility(R.id.rv, View.GONE)
.setVisibility(R.id.video_player, View.GONE);
break;
case ITEM_TYPE_IMAGE:
holder.setVisibility(R.id.rv, View.VISIBLE)
.setVisibility(R.id.video_player, View.GONE);
break;
case ITEM_TYPE_VIDEO:
holder.setVisibility(R.id.rv, View.GONE)
.setVisibility(R.id.video_player, View.VISIBLE);
break;
}
if (getItemViewType(position) == ITEM_TYPE_IMAGE) {
//图片
// if (data.getImg_arr() != null && data.getImg_arr().size() > 9) {
// data.setImg_arr(data.getImg_arr().subList(0, 9));
// }
//
if (holder.<RecyclerView>getView(R.id.rv).getAdapter() == null) {
holder.<RecyclerView>getView(R.id.rv).setAdapter(
new ZoneImageAdapter2(R.layout.item_zone_image2, new ArrayList<>(), holder.getView(R.id.rv)));
}
((ZoneImageAdapter2) holder.<RecyclerView>getView(R.id.rv).getAdapter()).setUserPageOrDetail(isUserPage);
((ZoneImageAdapter2) holder.<RecyclerView>getView(R.id.rv).getAdapter()).setMomentModel(data);
((ZoneImageAdapter2) holder.<RecyclerView>getView(R.id.rv).getAdapter()).setNewData(data.getImg_arr());
GridLayoutHelper.setOnMarginClickListener(holder.getView(R.id.rv), v -> onCreatorOpusItemClickListener.onItemClick(v, position, data));
} else if (getItemViewType(position) == ITEM_TYPE_VIDEO) {
//视频
holder.<MyGSYVideoPlayer>getView(R.id.video_player).initPlayer(data.getMp4_info(), position, isUserPage ?
ScreenUtil.getScreenWidth() - ScreenUtil.dp2px(16 * 2) :
ScreenUtil.getScreenWidth() - ScreenUtil.dp2px(68 * 2), false, data.getId());
}
//话题
if (data.getHua_arr().isEmpty()) {
holder.setVisibility(R.id.flow_topic, View.GONE);
} else {
holder.setVisibility(R.id.flow_topic, View.VISIBLE)
.<FlowLayout>getView(R.id.flow_topic)
.addChildren(data.getHua_arr(), R.layout.flow_moment_topic)
.setDivider(30, 20)
.setOnBindData(new FlowLayout.OnChildDataBind<TopicRankModel>() {
@Override
public void onBindData(FlowLayout flowLayout, View itemView, int childPosition, TopicRankModel childData) {
TextView tvTopicName = itemView.findViewById(R.id.tv_topic_name);
tvTopicName.setText(childData.getName());
}
})
.setOnChildClickListener((flowLayout, itemView, childPosition, childData) -> onCreatorOpusItemClickListener.onTopicClick(itemView, position, data, childPosition, (TopicRankModel) childData));
}
//榜单
if (data.getBang() == null) {
holder.setVisibility(R.id.vg_bang, View.GONE);
} else {
holder.setVisibility(R.id.vg_bang, View.VISIBLE)
.setText(R.id.tv_bang, data.getBang().getStr())
.setOnViewClickListener(R.id.tv_hits, new View.OnClickListener() {
@Override
public void onClick(View v) {
onCreatorOpusItemClickListener.onHitsBangClick(v, position, data);
}
})
.setOnViewClickListener(R.id.vg_bang, new View.OnClickListener() {
@Override
public void onClick(View v) {
onCreatorOpusItemClickListener.onBangClick(v, position, data);
}
});
}
}
/**
* 分割线
*
* @return
*/
public RecyclerView.ItemDecoration getDivider() {
return new ItemDivider(2, mContext.getResources().getColor(R.color.divider));
}
public void setOnCreatorOpusItemClickListener(OnCreatorOpusItemClickListener
onCreatorOpusItemClickListener) {
this.onCreatorOpusItemClickListener = onCreatorOpusItemClickListener;
}
public List<BaseViewHolder> getViewHolderList() {
return viewHolderList;
}
public interface OnCreatorOpusItemClickListener {
//item
void onItemClick(View view, int position, MomentModel data);
//用户
void onUserClick(View view, int position, MomentModel data);
//更多选项
void onOptionClick(View view, int position, MomentModel data);
//分享
void onShareClick(View view, int position, MomentModel data);
//点赞
void onLikeClick(View view, int position, MomentModel data);
//评论
void onCommentClick(View view, int position, MomentModel data);
//话题
void onTopicClick(View view, int position, MomentModel data, int childPosition, TopicRankModel topicData);
//榜单
void onBangClick(View view, int position, MomentModel data);
//打榜
void onHitsBangClick(View view, int position, MomentModel data);
}
}
... ...
package com.yinhebairong.shejiao.mine.adapter;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.bang.BangVoteActivity;
import com.yinhebairong.shejiao.mine.TipOffActivity;
import com.yinhebairong.shejiao.square.MomentDetailActivity;
import com.yinhebairong.shejiao.square.UserPageActivity;
import com.yinhebairong.shejiao.square.adapter.MomentAdapter;
import com.yinhebairong.shejiao.square.model.MomentModel;
import com.yinhebairong.shejiao.topic.TopicDetailActivity;
import com.yinhebairong.shejiao.topic.model.TopicRankModel;
import com.yinhebairong.shejiao.view.dialog.BottomCustomDialog;
import com.yinhebairong.shejiao.view.dialog.ShareDialog;
import io.rong.imkit.RongIM;
import io.rong.imlib.model.UserInfo;
import static com.blankj.utilcode.util.ActivityUtils.startActivity;
/**
* @ClassName: OnMomentItemListener
* @Author: Lau
* @CreateDate: 2020/12/12 15:35
* @Description:
*/
public abstract class CreatorOpusItemListener implements CreatorOpusAdapter.OnCreatorOpusItemClickListener {
private CreatorOpusAdapter creatorOpusAdapter;
private Context mContext;
public CreatorOpusItemListener(CreatorOpusAdapter creatorOpusAdapter, Context mContext) {
this.creatorOpusAdapter = creatorOpusAdapter;
this.mContext = mContext;
}
@Override
public void onItemClick(View view, int position, MomentModel data) {
Bundle bundle = new Bundle();
bundle.putInt("id", data.getId());
bundle.putInt("images_count", data.getImg_arr().size());
creatorOpusAdapter.goActivity(MomentDetailActivity.class, bundle);
}
@Override
public void onUserClick(View view, int position, MomentModel data) {
Bundle bundle = new Bundle();
bundle.putInt("id", data.getUser().getId());
bundle.putInt("lookId", data.getId());
creatorOpusAdapter.goActivity(UserPageActivity.class, bundle);
}
@Override
public void onOptionClick(View view, int position, MomentModel data) {
openOptionsDialog(data);
}
@Override
public void onShareClick(View view, int position, MomentModel data) {
openShareDialog(data);
}
@Override
public void onCommentClick(View view, int position, MomentModel data) {
Bundle bundle = new Bundle();
bundle.putInt("id", data.getId());
bundle.putInt("images_count", data.getImg_arr().size());
creatorOpusAdapter.goActivity(MomentDetailActivity.class, bundle);
}
@Override
public void onTopicClick(View view, int position, MomentModel data, int childPosition, TopicRankModel topicData) {
Bundle bundle = new Bundle();
bundle.putInt("id", topicData.getId());
creatorOpusAdapter.goActivity(TopicDetailActivity.class, bundle);
}
@Override
public void onBangClick(View view, int position, MomentModel data) {
// TODO: 2020/12/15 目前没啥事件
}
@Override
public void onHitsBangClick(View view, int position, MomentModel data) {
int id = data.getBang().getId();
//为Ta打榜
Intent intent = new Intent(mContext, BangVoteActivity.class);
intent.putExtra("bang_id", data.getBang().getBang_id() + "");
intent.putExtra("person_id", data.getBang().getId() + "");
startActivity(intent);
// Intent intent = new Intent(mContext, BangVoteActivity.class);
// intent.putExtra("bang_id", bangList.get(viewFlipper.getDisplayedChild()).getBang_id() + "");
// intent.putExtra("person_id", bangList.get(viewFlipper.getDisplayedChild()).getId() + "");
// startActivity(intent);
}
public abstract void onFollowClick(ImageView imageView, MomentModel data);
/**
* 更多菜单
*
* @param data
*/
private void openOptionsDialog(MomentModel data) {
BottomCustomDialog.showCustomDialog(mContext, R.layout.dialog_moment_option)
.setImageViewRes(R.id.iv_follow, data.getUser().getGuan_id() == 1 ? R.mipmap.icon_follow_pink_yet : R.mipmap.icon_follow_pink_not)
.setOnViewClickListener(R.id.vg_chat, new BottomCustomDialog.OnDialogViewClickListener() {
@Override
public void onViewClick(View view, BottomCustomDialog dialog) {
// 私聊
RongIM.getInstance().refreshUserInfoCache(
new UserInfo(String.valueOf(data.getUser().getId()), data.getUser().getNickname2(), Uri.parse(data.getUser().getAvatar2())));
RongIM.getInstance().startPrivateChat(mContext, String.valueOf(data.getUser().getId()), data.getUser().getNickname2());
dialog.dismiss();
}
})
.setOnViewClickListener(R.id.vg_follow, new BottomCustomDialog.OnDialogViewClickListener() {
@Override
public void onViewClick(View view, BottomCustomDialog dialog) {
//关注
onFollowClick(view.findViewById(R.id.iv_follow), data);
dialog.dismiss();
}
})
.setOnViewClickListener(R.id.vg_tip_off, new BottomCustomDialog.OnDialogViewClickListener() {
@Override
public void onViewClick(View view, BottomCustomDialog dialog) {
//举报
Bundle bundle = new Bundle();
bundle.putInt("type", 4);
bundle.putInt("look_id", data.getId());
creatorOpusAdapter.goActivity(TipOffActivity.class, bundle);
dialog.dismiss();
}
});
}
/**
* 分享
*
* @param data
*/
private void openShareDialog(MomentModel data) {
ShareDialog.shareMoment(mContext, data);
}
}
... ...
package com.yinhebairong.shejiao.mine.adapter;
import android.content.Context;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BaseRvAdapter;
import com.yinhebairong.shejiao.base.BaseViewHolder;
import com.yinhebairong.shejiao.mine.model.AttentionModel;
/**
* Time: 9/16/2021 15:46
* Author: Captain
* Description: 初见时你很迷人
*/
public class IncomeCashRecordAdapter extends BaseRvAdapter<AttentionModel> {
public IncomeCashRecordAdapter(Context mContext) {
super(mContext);
}
@Override
protected int getLayoutId(int viewType) {
return R.layout.item_income_detail;
}
@Override
protected void bindData(BaseViewHolder holder, AttentionModel data, int position) {
holder.setText(R.id.tv_date,data.getNickname2());
}
}
... ...
package com.yinhebairong.shejiao.mine.adapter;
import android.content.Context;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BaseRvAdapter;
import com.yinhebairong.shejiao.base.BaseViewHolder;
import com.yinhebairong.shejiao.mine.model.AttentionModel;
/**
* Time: 9/16/2021 15:46
* Author: Captain
* Description: 初见时你很迷人
*/
public class IncomeDetailAdapter extends BaseRvAdapter<AttentionModel> {
public IncomeDetailAdapter(Context mContext) {
super(mContext);
}
@Override
protected int getLayoutId(int viewType) {
return R.layout.item_income_detail;
}
@Override
protected void bindData(BaseViewHolder holder, AttentionModel data, int position) {
holder.setText(R.id.tv_date,data.getNickname2());
}
}
... ...
package com.yinhebairong.shejiao.mine.adapter;
import android.content.Context;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BaseRvAdapter;
import com.yinhebairong.shejiao.base.BaseViewHolder;
import com.yinhebairong.shejiao.mine.model.AttentionModel;
/**
* Time: 9/16/2021 15:46
* Author: Captain
* Description: 初见时你很迷人
*/
public class SeeDataAnalysisAdapter extends BaseRvAdapter<AttentionModel> {
public SeeDataAnalysisAdapter(Context mContext) {
super(mContext);
}
@Override
protected int getLayoutId(int viewType) {
return R.layout.item_see_data_analysis;
}
@Override
protected void bindData(BaseViewHolder holder, AttentionModel data, int position) {
holder.setText(R.id.tv_date, data.getRecentTime());
}
}
... ...
package com.yinhebairong.shejiao.mine.adapter;
import android.content.Context;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BaseRvAdapter;
import com.yinhebairong.shejiao.base.BaseViewHolder;
import com.yinhebairong.shejiao.mine.model.AttentionModel;
/**
* Time: 9/16/2021 15:46
* Author: Captain
* Description: 初见时你很迷人
*/
public class SeeFansDataAnalysisAdapter extends BaseRvAdapter<AttentionModel> {
public SeeFansDataAnalysisAdapter(Context mContext) {
super(mContext);
}
@Override
protected int getLayoutId(int viewType) {
return R.layout.item_see_fans_data_analysis;
}
@Override
protected void bindData(BaseViewHolder holder, AttentionModel data, int position) {
holder.setText(R.id.tv_date, data.getRecentTime());
}
}
... ...
... ... @@ -51,8 +51,17 @@ public class UserInfoBean {
private String vip_time2;
private String join_day;
private int look_num;
private int is_creator;//是否加入了创作者计划 0=否,1=是
public int getIs_creator() {
return is_creator;
}
public void setIs_creator(int is_creator) {
this.is_creator = is_creator;
}
public int getId() {
return id;
}
... ...
package com.yinhebairong.shejiao.mine.fragment;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BaseFragment;
import com.yinhebairong.shejiao.view.MyWebView;
import com.yinhebairong.shejiao.view.NoScrollWebView;
import butterknife.BindView;
/**
* Time: 9/17/2021 13:46
* Author: Captain
* Description: 初见时你很迷人
*/
public class CreateIntroduceWebFragment extends BaseFragment {
@BindView(R.id.web_view)
MyWebView webView;
@BindView(R.id.tv_button)
TextView tvButton;
private int status;
@Override
protected int getContentView() {
return R.layout.fragment_create_introduce_web;
}
@Override
protected void initView(View root) {
if (getArguments() != null) {
status = getArguments().getInt("status");
if (status == 1){
tvButton.setVisibility(View.VISIBLE);
}else {
tvButton.setVisibility(View.GONE);
}
}
webView.setWebContent("https://www.baidu.com/");
}
public static CreateIntroduceWebFragment newInstance(int status) {
Bundle args = new Bundle();
args.putInt("status", status);
CreateIntroduceWebFragment fragment = new CreateIntroduceWebFragment();
fragment.setArguments(args);
return fragment;
}
@Override
protected void initDate() {
}
@Override
protected void initListener() {
}
@Override
protected void lazyLoad() {
}
}
... ...
package com.yinhebairong.shejiao.mine.fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BaseJsonBean;
import com.yinhebairong.shejiao.base.BaseListFragment;
import com.yinhebairong.shejiao.base.Config;
import com.yinhebairong.shejiao.main.MainActivity;
import com.yinhebairong.shejiao.main.fragment.SquareFragment;
import com.yinhebairong.shejiao.mine.adapter.CreatorOpusAdapter;
import com.yinhebairong.shejiao.mine.adapter.CreatorOpusItemListener;
import com.yinhebairong.shejiao.moment.event.MomentEvent;
import com.yinhebairong.shejiao.network.ApiService;
import com.yinhebairong.shejiao.network.OnResponse;
import com.yinhebairong.shejiao.square.adapter.MomentAdapter;
import com.yinhebairong.shejiao.square.adapter.OnMomentItemListener;
import com.yinhebairong.shejiao.square.model.MomentModel;
import com.yinhebairong.shejiao.square.model.PageBean;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import butterknife.BindView;
import cc.shinichi.library.tool.common.NetworkUtil;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
/**
* Time: 9/14/2021 11:19
* Author: Captain
* Description: 初见时你很迷人
* 创作者作品fragment
*/
public class CreatorOpusFragment extends BaseListFragment<CreatorOpusAdapter, MomentModel> implements SquareFragment.OnRefreshToTopListener {
@BindView(R.id.vg_blank)
protected LinearLayout vgBlank;
@BindView(R.id.tv_blank)
protected TextView tvBlank;
@BindView(R.id.reload_rl)
protected RelativeLayout reloadRl;
@BindView(R.id.tv_reload)
protected TextView tvReload;
protected int type = 0;
protected int page = 1;
public static final int TYPE_SUGGEST = 0;
public static final int TYPE_ATTENTION = 1;
public static final int TYPE_CITY = 2;
public static final int TYPE_SCHOOL = 3;
@IntDef({TYPE_SUGGEST, TYPE_ATTENTION, TYPE_CITY, TYPE_SCHOOL})
@Retention(RetentionPolicy.SOURCE)
public @interface Type {
}
/**
* @param type 0是关注 1是推荐
* @return
*/
public CreatorOpusFragment setType(@Type int type) {
this.type = type;
if (adapter != null) {
adapter.setSuggest(type == TYPE_SUGGEST || type == TYPE_CITY || type == TYPE_SCHOOL);
}
if (tvBlank != null) {
tvBlank.setText(getEmptyText());
}
return this;
}
@Override
public int getLayoutId() {
return R.layout.fragment_creator_opus;
}
@Override
public CreatorOpusAdapter getAdapter() {
return adapter == null ?
new CreatorOpusAdapter(mContext, false)
.setSuggest(type == TYPE_SUGGEST || type == TYPE_CITY || type == TYPE_SCHOOL)
: adapter;
}
@Override
protected RecyclerView.ItemDecoration getDivider() {
return adapter.getDivider();
}
@Override
public boolean isRefreshEnable() {
return true;
}
@Override
public boolean isLoadMoreEnable() {
return true;
}
protected String getEmptyText() {
switch (type) {
case TYPE_SUGGEST:
return "暂时还没有推荐哦";
case TYPE_ATTENTION:
return "你还没有关注的人哦";
case TYPE_CITY:
return "暂时还没有本地动态哦";
case TYPE_SCHOOL:
return "暂时还没有同校动态哦";
default:
return "暂时还没有动态哦";
}
}
private String getType() {
switch (type) {
case TYPE_SUGGEST:
return "tui";
case TYPE_ATTENTION:
return "guan";
case TYPE_CITY:
return "city";
case TYPE_SCHOOL:
return "school";
default:
return "";
}
}
@Override
public void initData() {
EventBus.getDefault().register(this);
tvBlank.setText(getEmptyText());
rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
LinearLayoutManager manager = (LinearLayoutManager) rv.getLayoutManager();
int firstVisibleItem = manager.findFirstVisibleItemPosition();
int lastVisibleItem = manager.findLastVisibleItemPosition();
//大于0说明有播放
if (GSYVideoManager.instance().getPlayPosition() >= 0) {
//当前播放的位置
int position = GSYVideoManager.instance().getPlayPosition();
//对应的播放列表TAG
if (GSYVideoManager.instance().getPlayTag().equals(MomentAdapter.class.getName())
&& (position < firstVisibleItem || position > lastVisibleItem)) {
if (GSYVideoManager.isFullState(getActivity())) {
return;
}
//如果滑出去了上面和下面就是否,和今日头条一样
GSYVideoManager.releaseAllVideos();
adapter.notifyDataSetChanged();
}
}
}
});
adapter.setOnCreatorOpusItemClickListener(new CreatorOpusItemListener(adapter, mContext) {
@Override
public void onFollowClick(ImageView imageView, MomentModel data) {
//关注
apiFollow(imageView, data);
}
@Override
public void onLikeClick(View view, int position, MomentModel data) {
//点赞
apiLike(position, data);
}
});
if (mContext instanceof MainActivity) {
rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
((MainActivity) mContext).setSquareButtonText(isNeedChangeSquareButtonToRefresh());
}
});
}
firstTimeLoadData();
}
@Override
public void onPause() {
super.onPause();
// GSYVideoManager.onPause();
}
@Override
public void onResume() {
super.onResume();
// GSYVideoManager.onResume();
}
@Override
public void onDestroy() {
super.onDestroy();
// GSYVideoManager.releaseAllVideos();
EventBus.getDefault().unregister(this);
}
@Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
page++;
getMomentList(false);
}
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
page = 1;
getMomentList(true);
}
@Override
public void initEvent() {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// ConnectivityManager manager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
// manager.registerDefaultNetworkCallback(new ConnectivityManager.NetworkCallback() {
// @Override
// public void onCapabilitiesChanged(@NonNull Network network, @NonNull NetworkCapabilities networkCapabilities) {
// super.onCapabilitiesChanged(network, networkCapabilities);
// }
// });
// }
tvReload.setOnClickListener(v -> getMomentList(true));
}
protected void firstTimeLoadData() {
refreshLayout.autoRefresh();
}
@Override
public void onItemClick(View view, int position, MomentModel data) {
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onUINeedChange(MomentEvent event) {
if (event.getAction() == MomentEvent.ACTION_LIKE ||
event.getAction() == MomentEvent.ACTION_COMMENT_COUNT ||
event.getAction() == MomentEvent.ACTION_DELETE) {
for (int i = 0; i < adapter.getDataList().size(); i++) {
if (adapter.getData(i).getId() == event.getMomentModel().getId()) {
switch (event.getAction()) {
case MomentEvent.ACTION_LIKE:
if (type != event.getType() || mContext != event.getContext()) {
adapter.getData(i).setZan_num(event.getMomentModel().getZan_num());
adapter.getData(i).setZan_id(event.getMomentModel().getZan_id());
adapter.notifyDataSetChanged();
}
break;
case MomentEvent.ACTION_COMMENT_COUNT:
adapter.getData(i).setPing_num(event.getMomentModel().getPing_num());
adapter.notifyDataSetChanged();
break;
case MomentEvent.ACTION_DELETE:
adapter.deleteDataWithAnim(i);
break;
}
}
}
} else if (event.getAction() == MomentEvent.ACTION_FOLLOW) {
for (MomentModel momentModel : adapter.getDataList()) {
if (momentModel.getUser().getId() == event.getMomentModel().getUser().getId()) {
momentModel.getUser().setGuan_id(event.getMomentModel().getUser().getGuan_id());
momentModel.setGuan_id(event.getMomentModel().getUser().getGuan_id());
}
}
}
}
long time = System.currentTimeMillis() / 1000;
protected Observable<BaseJsonBean<PageBean<MomentModel>>> getApi() {
return api().getMomentList(Config.Token, page, getType(), time);
}
/**
* 获取瞬间列表
*
* @param doClear
*/
protected void getMomentList(boolean doClear) {
if (!NetworkUtil.isNetWorkConnected(getActivity())) {
refreshLayout.finishRefresh();
reloadRl.setVisibility(View.VISIBLE);
return;
}
reloadRl.setVisibility(View.GONE);
getApi().subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new OnResponse<BaseJsonBean<PageBean<MomentModel>>>() {
@Override
public void onSubscribe(Disposable d) {
addDisposable(d);
}
@Override
public void onNext(BaseJsonBean<PageBean<MomentModel>> pageBeanBaseJsonBean) {
if (mContext == null || rv == null) {
return;
}
if (pageBeanBaseJsonBean.getCode() == ApiService.CODE_SUCCESS) {
if (doClear) {
adapter.clearDataList();
refreshLayout.finishRefresh();
if (type == TYPE_SUGGEST || type == TYPE_CITY || type == TYPE_SCHOOL) {
adapter.setLastRefreshTime(System.currentTimeMillis());
}
} else {
if (pageBeanBaseJsonBean.getData().getData().isEmpty()) {
refreshLayout.finishLoadMoreWithNoMoreData();
} else {
refreshLayout.finishLoadMore();
}
}
adapter.addDataListAndOnlyNotifyThese(pageBeanBaseJsonBean.getData().getData());
if (page == 1) {
scrollToTop();
}
if (adapter.getDataList().isEmpty()) {
vgBlank.setVisibility(View.VISIBLE);
} else {
vgBlank.setVisibility(View.GONE);
}
} else {
showToast(pageBeanBaseJsonBean.getMsg());
if (doClear) {
refreshLayout.finishRefresh(false);
} else {
refreshLayout.finishLoadMore(false);
}
}
}
@Override
public void onError(Throwable e) {
super.onError(e);
if (doClear) {
refreshLayout.finishRefresh(false);
} else {
refreshLayout.finishLoadMore(false);
}
vgBlank.setVisibility(View.VISIBLE);
tvBlank.setText("暂无动态");
}
});
}
/**
* 点赞/取消
*
* @param position
* @param data
*/
private void apiLike(int position, MomentModel data) { //0=自己未点赞,1=自己已点赞
//本地更新点赞状态
EventBus.getDefault().post(new MomentEvent(MomentEvent.ACTION_LIKE, data).setType(type).setContext(mContext));
api().changeMomentLike(Config.Token, data.getId())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new OnResponse<BaseJsonBean>() {
@Override
public void onNext(BaseJsonBean baseJsonBean) {
if (baseJsonBean.getCode() == ApiService.CODE_SUCCESS) {
} else {
showToast(baseJsonBean.getMsg());
}
}
});
}
/**
* 关注
*
* @param imageView
* @param data
*/
private void apiFollow(ImageView imageView, MomentModel data) {
api().apiFollowSomeone(Config.Token, data.getUser().getId())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new OnResponse<BaseJsonBean>() {
@Override
public void onNext(BaseJsonBean baseJsonBean) {
if (baseJsonBean.getCode() == ApiService.CODE_SUCCESS) {
//更新关注状态
if (data.getUser().getGuan_id() == 1) {
imageView.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.icon_follow_pink_not));
data.getUser().setGuan_id(0);
data.setGuan_id(0);
} else {
imageView.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.icon_follow_pink_yet));
data.getUser().setGuan_id(1);
data.setGuan_id(1);
}
EventBus.getDefault().post(new MomentEvent(MomentEvent.ACTION_FOLLOW, data));
} else {
showToast(baseJsonBean.getMsg());
}
}
});
}
@Override
public void refreshToTop() {
if (adapter == null) {
return;
}
scrollToTopAndRefresh();
}
public boolean isNeedChangeSquareButtonToRefresh() {
if (rv == null) {
return false;
}
if (rv.getLayoutManager() == null) {
return false;
}
int lastItemPosition = ((LinearLayoutManager) rv.getLayoutManager()).findLastVisibleItemPosition();
return lastItemPosition > 10;
}
}
... ...
package com.yinhebairong.shejiao.mine.fragment;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.formatter.PercentFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.MPPointF;
import com.github.mikephil.charting.utils.ViewPortHandler;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BaseFragment;
import com.yinhebairong.shejiao.mine.AllAreaActivity;
import com.yinhebairong.shejiao.mine.SeeDataAnalysisActivity;
import com.yinhebairong.shejiao.mine.adapter.AreaPercentAdapter;
import com.yinhebairong.shejiao.mine.adapter.AttentionAdapter;
import com.yinhebairong.shejiao.mine.model.AttentionModel;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.OnClick;
/**
* Time: 9/15/2021 10:51
* Author: Captain
* Description: 初见时你很迷人
* 数据分析的作品fragment
*/
public class CreatorWorksFragment extends BaseFragment implements OnChartValueSelectedListener {
@BindView(R.id.pie_chart)
PieChart pieChart;
@BindView(R.id.bar_chart)
BarChart barChart;
@BindView(R.id.rv_area)
RecyclerView rvArea;
private AreaPercentAdapter areaPercentAdapter;
@Override
protected int getContentView() {
return R.layout.fragment_creator_works;
}
@Override
protected void initView(View root) {
showPieChart();
showBarChart();
showAreaPercentage();
}
@Override
protected void initDate() {
}
@Override
protected void initListener() {
}
@Override
protected void lazyLoad() {
}
//男女比例饼状图
private void showPieChart() {
pieChart.setUsePercentValues(false);
pieChart.getDescription().setEnabled(false);
pieChart.setExtraOffsets(-10, 0, 0, 0);
pieChart.setDragDecelerationFrictionCoef(0.95f);
// pieChart.setCenterTextTypeface(tfLight);
// pieChart.setCenterText(generateCenterSpannableText());
pieChart.setDrawHoleEnabled(true);
pieChart.setDrawEntryLabels(false);
pieChart.setHoleColor(Color.WHITE);
pieChart.setTransparentCircleColor(Color.WHITE);
pieChart.setTransparentCircleAlpha(110);
pieChart.setHoleRadius(70f);
pieChart.setTransparentCircleRadius(0f);
pieChart.setDrawCenterText(true);
pieChart.setRotationAngle(0);
// pieChartable rotation of the chart by touch
pieChart.setRotationEnabled(false);
pieChart.setHighlightPerTapEnabled(true);
pieChart.setOnChartValueSelectedListener(this);
Legend l = pieChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.CENTER);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setForm(Legend.LegendForm.CIRCLE);
l.setTextSize(12);
l.setFormSize(9);
l.setDrawInside(false);
l.setXEntrySpace(7f);
l.setYEntrySpace(20f);
l.setYOffset(0f);
pieChart.setEntryLabelColor(Color.WHITE);
// pieChart.setEntryLabelTypeface(tfRegular);
pieChart.setEntryLabelTextSize(12f);
ArrayList<PieEntry> entries = new ArrayList<>();
// NOTE: The order of the entries when being added to the entries array determines their position around the center of
// the chart.
// for (int i = 0; i < 2 ; i++) {
// entries.add(new PieEntry((float) ((Math.random() * range) + range / 5),
// parties[i % parties.length],
// getResources().getDrawable(R.drawable.star)));
// }
entries.add(new PieEntry(0.55f, "男性 52%"));
entries.add(new PieEntry(0.45f, "女性 48%"));
PieDataSet dataSet = new PieDataSet(entries, "");
dataSet.setDrawIcons(false);
dataSet.setSliceSpace(3f);
dataSet.setIconsOffset(new MPPointF(0, 40));
dataSet.setSelectionShift(5f);
// add a lot of colors
ArrayList<Integer> colors = new ArrayList<>();
colors.add(getResources().getColor(R.color.theme));
colors.add(getResources().getColor(R.color.textWarning));
// for (int c : ColorTemplate.VORDIPLOM_COLORS)
// colors.add(c);
//
// for (int c : ColorTemplate.JOYFUL_COLORS)
// colors.add(c);
//
// for (int c : ColorTemplate.COLORFUL_COLORS)
// colors.add(c);
//
// for (int c : ColorTemplate.LIBERTY_COLORS)
// colors.add(c);
//
// for (int c : ColorTemplate.PASTEL_COLORS)
// colors.add(c);
//
// colors.add(ColorTemplate.getHoloBlue());
dataSet.setColors(colors);
//dataSet.setSelectionShift(0f);
PieData data = new PieData(dataSet);
data.setValueFormatter(new PercentFormatter());
data.setValueTextSize(11f);
data.setValueTextColor(Color.TRANSPARENT);
// data.setValueTypeface(tfLight);
pieChart.setData(data);
// undo all highlights
pieChart.highlightValues(null);
pieChart.invalidate();
}
//年龄分布柱状图
private void showBarChart() {
barChart.getDescription().setEnabled(false); // 不显示描述
barChart.setExtraOffsets(20, 20, 20, 20); // 设置饼图的偏移量,相似于内边距 ,设置视图窗口大小
barChart.setTouchEnabled(false);
Legend legend = barChart.getLegend();
//不显示图例
legend.setForm(Legend.LegendForm.NONE);
// 设置坐标轴
// 设置x轴
XAxis xAxis = barChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); // 设置x轴显示在下方,默认在上方
xAxis.setDrawGridLines(false); // 将此设置为true,绘制该轴的网格线。
xAxis.setLabelCount(6); // 设置x轴上的标签个数
xAxis.setTextSize(12); // x轴上标签的大小
final String labelName[] = {"<18", "18~23", "24~30", "31~40", "41~50", ">50"};
// 设置x轴显示的值的格式
xAxis.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
if ((int) value < labelName.length) {
return labelName[(int) value];
} else {
return "";
}
}
});
xAxis.setYOffset(15); // 设置标签对x轴的偏移量,垂直方向
// 设置y轴,y轴有两条,分别为左和右
YAxis yAxis_right = barChart.getAxisRight();
yAxis_right.setAxisMaximum(40f); // 设置y轴的最大值
yAxis_right.setAxisMinimum(0f); // 设置y轴的最小值
yAxis_right.setEnabled(false); // 不显示右边的y轴
YAxis yAxis_left = barChart.getAxisLeft();
yAxis_left.setAxisMaximum(40f);
yAxis_left.setAxisMinimum(0f);
yAxis_left.setLabelCount(5);
yAxis_left.setTextSize(12); // 设置y轴的标签大小
final String ylabelName[] = {"0%", "10%", "20%", "30%", "40%"};
yAxis_left.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
if ((int) value < ylabelName.length) {
return ylabelName[(int) value];
} else {
return (int) value + "%";
}
}
});
// 设置数据
List<IBarDataSet> sets = new ArrayList<>();
// 此处有两个DataSet,因此有两条柱子,BarEntry()中的x和y分别表示显示的位置和高度
// x是横坐标,表示位置,y是纵坐标,表示高度
List<BarEntry> barEntries1 = new ArrayList<>();
barEntries1.add(new BarEntry(0, 5f));
barEntries1.add(new BarEntry(1, 10f));
barEntries1.add(new BarEntry(2, 40f));
barEntries1.add(new BarEntry(3, 15f));
barEntries1.add(new BarEntry(4, 35f));
barEntries1.add(new BarEntry(5, 23f));
BarDataSet barDataSet1 = new BarDataSet(barEntries1, "");
barDataSet1.setValueTextColor(Color.TRANSPARENT); // 值的颜色
// barDataSet1.setValueTextSize(15f); // 值的大小
barDataSet1.setColor(getResources().getColor(R.color.theme)); // 柱子的颜色
sets.add(barDataSet1);
BarData barData = new BarData(sets);
barData.setBarWidth(0.4f); // 设置柱子的宽度
barChart.setData(barData);
barChart.getXAxis().setDrawGridLines(false);
barChart.getAxisLeft().setDrawAxisLine(false);
}
//显示地域分布
private void showAreaPercentage() {
areaPercentAdapter = new AreaPercentAdapter(getActivity());
rvArea.setLayoutManager(new LinearLayoutManager(getActivity()));
rvArea.setAdapter(areaPercentAdapter);
AttentionModel attentionModel = new AttentionModel();
List<AttentionModel> attentionModelList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
attentionModel.setNickname2("河南");
}
attentionModelList.add(attentionModel);
areaPercentAdapter.resetDataList(attentionModelList);
}
@Override
public void onValueSelected(Entry e, Highlight h) {
}
@Override
public void onNothingSelected() {
}
@OnClick({R.id.tv_see_data_analysis, R.id.tv_all_area})
void onClick(View view) {
Intent intent = new Intent();
switch (view.getId()) {
case R.id.tv_see_data_analysis:
//查看记录
intent.setClass(getActivity(), SeeDataAnalysisActivity.class);
startActivity(intent);
break;
case R.id.tv_all_area:
//全部地域
intent.setClass(getActivity(), AllAreaActivity.class);
startActivity(intent);
break;
}
}
}
... ...
package com.yinhebairong.shejiao.mine.fragment;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.PercentFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.MPPointF;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BaseFragment;
import com.yinhebairong.shejiao.mine.AllAreaActivity;
import com.yinhebairong.shejiao.mine.SeeDataAnalysisActivity;
import com.yinhebairong.shejiao.mine.SeeFansDataAnalysisActivity;
import com.yinhebairong.shejiao.mine.adapter.AreaPercentAdapter;
import com.yinhebairong.shejiao.mine.model.AttentionModel;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.OnClick;
/**
* Time: 9/15/2021 10:51
* Author: Captain
* Description: 初见时你很迷人
* 数据分析的作品fragment
*/
public class DataAnalysisFansFragment extends BaseFragment implements OnChartValueSelectedListener {
@BindView(R.id.pie_chart)
PieChart pieChart;
@BindView(R.id.bar_chart)
BarChart barChart;
@BindView(R.id.rv_area)
RecyclerView rvArea;
private AreaPercentAdapter areaPercentAdapter;
@Override
protected int getContentView() {
return R.layout.fragment_data_analysis_fans;
}
@Override
protected void initView(View root) {
showPieChart();
// showBarChart();
showAreaPercentage();
}
@Override
protected void initDate() {
}
@Override
protected void initListener() {
}
@Override
protected void lazyLoad() {
}
//男女比例饼状图
private void showPieChart() {
pieChart.setUsePercentValues(false);
pieChart.getDescription().setEnabled(false);
pieChart.setExtraOffsets(-10, 0, 0, 0);
pieChart.setDragDecelerationFrictionCoef(0.95f);
// pieChart.setCenterTextTypeface(tfLight);
// pieChart.setCenterText(generateCenterSpannableText());
pieChart.setDrawHoleEnabled(true);
pieChart.setDrawEntryLabels(false);
pieChart.setHoleColor(Color.WHITE);
pieChart.setTransparentCircleColor(Color.WHITE);
pieChart.setTransparentCircleAlpha(110);
pieChart.setHoleRadius(70f);
pieChart.setTransparentCircleRadius(0f);
pieChart.setDrawCenterText(true);
pieChart.setRotationAngle(0);
// pieChartable rotation of the chart by touch
pieChart.setRotationEnabled(false);
pieChart.setHighlightPerTapEnabled(true);
pieChart.setOnChartValueSelectedListener(this);
Legend l = pieChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.CENTER);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setForm(Legend.LegendForm.CIRCLE);
l.setTextSize(12);
l.setFormSize(9);
l.setDrawInside(false);
l.setXEntrySpace(7f);
l.setYEntrySpace(20f);
l.setYOffset(0f);
pieChart.setEntryLabelColor(Color.WHITE);
// pieChart.setEntryLabelTypeface(tfRegular);
pieChart.setEntryLabelTextSize(12f);
ArrayList<PieEntry> entries = new ArrayList<>();
// NOTE: The order of the entries when being added to the entries array determines their position around the center of
// the chart.
// for (int i = 0; i < 2 ; i++) {
// entries.add(new PieEntry((float) ((Math.random() * range) + range / 5),
// parties[i % parties.length],
// getResources().getDrawable(R.drawable.star)));
// }
entries.add(new PieEntry(0.55f, "男性 52%"));
entries.add(new PieEntry(0.45f, "女性 48%"));
PieDataSet dataSet = new PieDataSet(entries, "");
dataSet.setDrawIcons(false);
dataSet.setSliceSpace(3f);
dataSet.setIconsOffset(new MPPointF(0, 40));
dataSet.setSelectionShift(5f);
// add a lot of colors
ArrayList<Integer> colors = new ArrayList<>();
colors.add(getResources().getColor(R.color.theme));
colors.add(getResources().getColor(R.color.textWarning));
// for (int c : ColorTemplate.VORDIPLOM_COLORS)
// colors.add(c);
//
// for (int c : ColorTemplate.JOYFUL_COLORS)
// colors.add(c);
//
// for (int c : ColorTemplate.COLORFUL_COLORS)
// colors.add(c);
//
// for (int c : ColorTemplate.LIBERTY_COLORS)
// colors.add(c);
//
// for (int c : ColorTemplate.PASTEL_COLORS)
// colors.add(c);
//
// colors.add(ColorTemplate.getHoloBlue());
dataSet.setColors(colors);
//dataSet.setSelectionShift(0f);
PieData data = new PieData(dataSet);
data.setValueFormatter(new PercentFormatter());
data.setValueTextSize(11f);
data.setValueTextColor(Color.TRANSPARENT);
// data.setValueTypeface(tfLight);
pieChart.setData(data);
// undo all highlights
pieChart.highlightValues(null);
pieChart.invalidate();
}
//年龄分布柱状图
private void showBarChart() {
barChart.getDescription().setEnabled(false); // 不显示描述
barChart.setExtraOffsets(20, 20, 20, 20); // 设置饼图的偏移量,相似于内边距 ,设置视图窗口大小
barChart.setTouchEnabled(false);
Legend legend = barChart.getLegend();
//不显示图例
legend.setForm(Legend.LegendForm.NONE);
// 设置坐标轴
// 设置x轴
XAxis xAxis = barChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); // 设置x轴显示在下方,默认在上方
xAxis.setDrawGridLines(false); // 将此设置为true,绘制该轴的网格线。
xAxis.setLabelCount(6); // 设置x轴上的标签个数
xAxis.setTextSize(12); // x轴上标签的大小
final String labelName[] = {"<18", "18~23", "24~30", "31~40", "41~50", ">50"};
// 设置x轴显示的值的格式
xAxis.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
if ((int) value < labelName.length) {
return labelName[(int) value];
} else {
return "";
}
}
});
xAxis.setYOffset(15); // 设置标签对x轴的偏移量,垂直方向
// 设置y轴,y轴有两条,分别为左和右
YAxis yAxis_right = barChart.getAxisRight();
yAxis_right.setAxisMaximum(40f); // 设置y轴的最大值
yAxis_right.setAxisMinimum(0f); // 设置y轴的最小值
yAxis_right.setEnabled(false); // 不显示右边的y轴
YAxis yAxis_left = barChart.getAxisLeft();
yAxis_left.setAxisMaximum(40f);
yAxis_left.setAxisMinimum(0f);
yAxis_left.setLabelCount(5);
yAxis_left.setTextSize(12); // 设置y轴的标签大小
final String ylabelName[] = {"0%", "10%", "20%", "30%", "40%"};
yAxis_left.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
if ((int) value < ylabelName.length) {
return ylabelName[(int) value];
} else {
return (int) value + "%";
}
}
});
// 设置数据
List<IBarDataSet> sets = new ArrayList<>();
// 此处有两个DataSet,因此有两条柱子,BarEntry()中的x和y分别表示显示的位置和高度
// x是横坐标,表示位置,y是纵坐标,表示高度
List<BarEntry> barEntries1 = new ArrayList<>();
barEntries1.add(new BarEntry(0, 5f));
barEntries1.add(new BarEntry(1, 10f));
barEntries1.add(new BarEntry(2, 40f));
barEntries1.add(new BarEntry(3, 15f));
barEntries1.add(new BarEntry(4, 35f));
barEntries1.add(new BarEntry(5, 23f));
BarDataSet barDataSet1 = new BarDataSet(barEntries1, "");
barDataSet1.setValueTextColor(Color.TRANSPARENT); // 值的颜色
// barDataSet1.setValueTextSize(15f); // 值的大小
barDataSet1.setColor(getResources().getColor(R.color.theme)); // 柱子的颜色
sets.add(barDataSet1);
BarData barData = new BarData(sets);
barData.setBarWidth(0.4f); // 设置柱子的宽度
barChart.setData(barData);
barChart.getXAxis().setDrawGridLines(false);
barChart.getAxisLeft().setDrawAxisLine(false);
}
//显示地域分布
private void showAreaPercentage() {
areaPercentAdapter = new AreaPercentAdapter(getActivity());
rvArea.setLayoutManager(new LinearLayoutManager(getActivity()));
rvArea.setAdapter(areaPercentAdapter);
AttentionModel attentionModel = new AttentionModel();
List<AttentionModel> attentionModelList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
attentionModel.setNickname2("河南");
}
attentionModelList.add(attentionModel);
areaPercentAdapter.resetDataList(attentionModelList);
}
@Override
public void onValueSelected(Entry e, Highlight h) {
}
@Override
public void onNothingSelected() {
}
@OnClick({R.id.tv_see_fans_data_analysis, R.id.tv_all_area})
void onClick(View view) {
Intent intent = new Intent();
switch (view.getId()) {
case R.id.tv_see_fans_data_analysis:
//查看记录
intent.setClass(getActivity(), SeeFansDataAnalysisActivity.class);
startActivity(intent);
break;
case R.id.tv_all_area:
//查看记录
intent.setClass(getActivity(), AllAreaActivity.class);
startActivity(intent);
break;
}
}
}
... ...
package com.yinhebairong.shejiao.mine.fragment;
import android.graphics.Color;
import android.view.View;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.base.BaseFragment;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
/**
* Time: 9/17/2021 9:52
* Author: Captain
* Description: 初见时你很迷人
*/
public class IncomeLineChartFragment extends BaseFragment {
@BindView(R.id.line_chart)
LineChart lineChart;
//Y轴的数据 根据自己的实际情况放入集合中就行
private List<Integer> mLableYHeartRate = new ArrayList<>();
private String[] mLableXHeartRate = new String[]{"09-01", "09-02", "09-03", "09-04", "09-05"};
@Override
protected int getContentView() {
return R.layout.fragment_income_line_chart;
}
@Override
protected void initView(View root) {
setUpLineChart();
}
//初始化折线图
private void setUpLineChart() {
//设置线状图不显示描述
lineChart.setDescription(null);
//Y 自下往上动态绘制 这里添加初始的动画效果
lineChart.animateY(1000);
//获取柱状图的X轴
XAxis xAxis = lineChart.getXAxis();
//下面两个是获取Y轴 包括左右
YAxis axisLeft = lineChart.getAxisLeft();
YAxis axisRight = lineChart.getAxisRight();
//设置XY轴
setAXis(xAxis, axisLeft, axisRight);
lineChart.setData(setLineData());
lineChart.invalidate();
}
/*
* 设置折线图的XY轴
* */
public void setAXis(XAxis axis, YAxis axisLeft, YAxis axisRight) {
//设置X轴在图底部显示
axis.setPosition(XAxis.XAxisPosition.BOTTOM);
//设置X轴的宽度
axis.setAxisLineWidth(1);
axis.setAxisLineColor(Color.BLACK);
//起始0坐标开始
axis.setAxisMinimum(0);
//设置X轴显示轴线
axis.setDrawAxisLine(true);
//x的表格线不显示
axis.setDrawGridLines(false);
//设置X轴显示
axis.setEnabled(true);
//x轴显示字符串
axis.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
return mLableXHeartRate[(int) value];
}
});
//
axis.setLabelCount(7, true);
//y轴0刻度
axisLeft.setAxisMinimum(30);
//不画网格线
axisLeft.setDrawGridLines(false);
axisLeft.setAxisLineColor(Color.BLACK);
//显示Y轴轴线
axisLeft.setDrawAxisLine(true);
axisLeft.setAxisLineWidth(1);
axisLeft.setEnabled(true);
axisLeft.setDrawLabels(true);
//不显示右Y轴
axisRight.setEnabled(false);
}
/*
* 设置折线图数据
* @return BarData
* */
public LineData setLineData() {
//X轴就是0-6
List<Entry> mListEnryMin = new ArrayList<>();
mLableYHeartRate.add(0);
mLableYHeartRate.add(10);
mLableYHeartRate.add(20);
mLableYHeartRate.add(30);
mLableYHeartRate.add(40);
for (int i = 0; i < mLableXHeartRate.length; i++) {
//添加x,y坐标的值
mListEnryMin.add(new Entry(i, mLableYHeartRate.get(i)));
}
LineDataSet barDataSet = new LineDataSet(mListEnryMin, "");
//设置线条颜色为红色
barDataSet.setColor(getResources().getColor(R.color.theme));
//设置折线图转择点的值的大小
barDataSet.setValueTextSize(12);
barDataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
//不显示圆点
barDataSet.setDrawCircles(false);
LineData lineData = new LineData(barDataSet);
//图例:得到Lengend
Legend legend = lineChart.getLegend();
//隐藏Lengend
legend.setEnabled(false);
return lineData;
}
@Override
protected void initDate() {
}
@Override
protected void initListener() {
}
@Override
protected void lazyLoad() {
}
}
... ...
... ... @@ -18,8 +18,10 @@ import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import androidx.annotation.NonNull;
... ... @@ -66,6 +68,7 @@ import com.yinhebairong.shejiao.network.ApiService;
import com.yinhebairong.shejiao.network.OnResponse;
import com.yinhebairong.shejiao.topic.adapter.TopicSelectedAdapter;
import com.yinhebairong.shejiao.topic.dialog.TopicDialog;
import com.yinhebairong.shejiao.topic.dialog.YuanchuangDialog;
import com.yinhebairong.shejiao.topic.model.TopicHotModel;
import com.yinhebairong.shejiao.topic.model.TopicSearchModel;
import com.yinhebairong.shejiao.util.DebugLog;
... ... @@ -121,6 +124,8 @@ public class PublishMomentActivity extends BasePBActivity {
LinearLayout vgBang;
@BindView(R.id.tv_bang)
TextView tvBang;
@BindView(R.id.switch_yuanchuang)
Switch switchYuanchuang;
//图片每行数量
private static final int PICTURE_SELECTOR_SPAN = 3;
... ... @@ -136,6 +141,8 @@ public class PublishMomentActivity extends BasePBActivity {
private HistoryPlaceAdapter historyPlaceAdapter;
private YuanchuangDialog yuanchuangDialog;
@Override
public int getLayoutId() {
return R.layout.activity_publish_moment;
... ... @@ -199,6 +206,17 @@ public class PublishMomentActivity extends BasePBActivity {
initTopicViews();
initTopic();
initBang();
switchYuanchuang.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
//打开
yuanchuangDialog = new YuanchuangDialog(PublishMomentActivity.this);
yuanchuangDialog.show();
}
}
});
}
@Override
... ...
package com.yinhebairong.shejiao.topic.dialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.util.ScreenUtil;
/**
* Time: 4/23/2021 16:53
* Author: TAO
* Description: 创作者审核状态弹窗
*/
public class CreatorShenHeStatusDialog extends Dialog implements View.OnClickListener {
private int mImage;
private String mContent;
private String mTitle;
public CreatorShenHeStatusDialog(@NonNull Context context,int image,String title,String content) {
this(context, R.style.SucessDialog);
this.mImage = image;
this.mContent = content;
this.mTitle = title;
}
private CreatorShenHeStatusDialog(@NonNull Context context, int themeResId) {
super(context, themeResId);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_creator_shenhe_status);
Window window = getWindow();
if (window == null) return;
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = ScreenUtil.getScreenWidth() - ScreenUtil.dp2px(32);
window.setAttributes(layoutParams);
ImageView imageView = findViewById(R.id.iv_status);
imageView.setImageResource(mImage);
TextView tvTitle = findViewById(R.id.tv_title);
tvTitle.setText(mTitle);
TextView tvContent = findViewById(R.id.tv_content);
tvContent.setText(mContent);
TextView tvYes = findViewById(R.id.tv_yes);
tvYes.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_yes:
dismiss();
break;
}
}
}
... ...
package com.yinhebairong.shejiao.topic.dialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.util.ScreenUtil;
import com.yinhebairong.shejiao.view.MyRadioButton;
/**
* Time: 4/23/2021 16:53
* Author: TAO
* Description: 加入创作者计划弹窗
*/
public class JoinCreatorDialog extends Dialog implements View.OnClickListener {
public JoinCreatorDialog(@NonNull Context context) {
this(context, R.style.SucessDialog);
}
private JoinCreatorDialog(@NonNull Context context, int themeResId) {
super(context, themeResId);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_join_creator);
Window window = getWindow();
if (window == null) return;
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = ScreenUtil.getScreenWidth() - ScreenUtil.dp2px(32);
window.setAttributes(layoutParams);
ImageView imageView = findViewById(R.id.iv_guanbi);
TextView tvJoin = findViewById(R.id.tv_join);
TextView tvIntroduce = findViewById(R.id.tv_introduce);
imageView.setOnClickListener(this);
tvJoin.setOnClickListener(this);
tvIntroduce.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.iv_guanbi:
dismiss();
break;
case R.id.tv_join:
//加入创作者计划
break;
case R.id.tv_introduce:
//查看创作者计划
break;
}
}
}
... ...
package com.yinhebairong.shejiao.topic.dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.yinhebairong.shejiao.R;
import com.yinhebairong.shejiao.view.MyWebView;
import com.yinhebairong.shejiao.view.dialog.BottomCustomDialog;
import butterknife.BindView;
/**
* Time: 9/17/2021 15:59
* Author: Captain
* Description: 初见时你很迷人
*/
public class YuanchuangDialog extends BottomCustomDialog {
@BindView(R.id.web_view)
MyWebView webView;
@BindView(R.id.tv_yes)
TextView tvYes;
public YuanchuangDialog(@NonNull Context context) {
super(context, R.layout.dialog_yuanchuang);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
webView.setWebContent("https://www.baidu.com/");
tvYes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
}
}
... ...
package com.yinhebairong.shejiao.view;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
* Time: 9/17/2021 13:52
* Author: Captain
* Description: 初见时你很迷人
*/
public class NoScrollWebView extends MyWebView{
public NoScrollWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int mExpandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, mExpandSpec);
}
}
... ...
... ... @@ -9,6 +9,7 @@ import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
... ... @@ -247,6 +248,18 @@ public class TitleBar extends RelativeLayout implements View.OnClickListener {
}
/**
* 设置右边按钮图标
*
* @param drawable
*/
public void setRightBg(Drawable drawable) {
tvRight.setBackground(drawable);
tvRight.setWidth((int) getResources().getDimension(R.dimen.dp_64));
tvRight.setHeight((int) getResources().getDimension(R.dimen.dp_28));
tvRight.setGravity(Gravity.CENTER);
}
/**
* 获得标题
*/
public String getCenterText() {
... ...
package com.yinhebairong.shejiao.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;
import java.util.HashMap;
import java.util.LinkedHashMap;
import io.reactivex.annotations.NonNull;
/**
* Time: 10/13/2020 17:54
* Author: TAO
* Description:
*/
public class ViewPagerForScrollView extends ViewPager {
private int current;
private int height = 0;
/**
* 保存position与对于的View(保存view对应的索引)
*/
private HashMap<Integer, View> mChildrenViews = new LinkedHashMap<Integer, View>();
private boolean scrollble = true;
public ViewPagerForScrollView(Context context) {
super(context);
}
public ViewPagerForScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
// @Override
// public boolean onInterceptTouchEvent(MotionEvent event) {
// // Never allow swiping to switch between pages
// return false;
// }
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = 0;
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int h = child.getMeasuredHeight();
if (h > height)
height = h;
}
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
/**
* 重新设置高度
*
* @param current
*/
public void resetHeight(int current) {
this.current = current;
if (mChildrenViews.size() > current) {
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) getLayoutParams();
if (layoutParams == null) {
layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height);
} else {
layoutParams.height = height;
}
setLayoutParams(layoutParams);
}
}
/**
* 保存position与对于的View(保存View对应的索引),需要自适应高度的一定要设置这个
*/
public void setObjectForPosition(View view, int position)
{
mChildrenViews.put(position, view);
}
// @Override
// public boolean onTouchEvent(MotionEvent ev) {
// if (!scrollble) {
// return true;
// }
// return super.onTouchEvent(ev);
// }
public boolean isScrollble() {
return scrollble;
}
public void setScrollble(boolean scrollble) {
this.scrollble = scrollble;
}
}
... ...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#32D4EB" />
<corners android:radius="50dp" />
</shape>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--四个角-->
<corners android:radius="50dp"/>
<solid android:color="#32D4EB"/>
</shape>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--四个角-->
<corners android:radius="12dp"/>
<solid android:color="#fff"/>
</shape>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--四个角-->
<corners android:radius="45dp"/>
<solid android:color="#fff"/>
</shape>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.yinhebairong.shejiao.view.TitleBar
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:centerTitle="地域分布"
app:isIncludeStatusBar="true"
app:leftDrawable="@mipmap/icon_common_back3x"
app:rightTitleColor="@color/white"
app:showRight="false"
app:titleBarBg="@color/transparent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="@dimen/dp_16"
android:layout_marginTop="@dimen/dp_20"
android:layout_marginBottom="@dimen/dp_20"
android:background="@color/white"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.yinhebairong.shejiao.view.TitleBar
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:centerTitle="创作简介"
app:centerTitleColor="@color/black"
app:isIncludeStatusBar="true"
app:leftDrawable="@mipmap/icon_common_back3x"
app:rightTitle="规则"
app:rightTitleColor="@color/white"
app:showRight="true"
app:titleBarBg="@color/white" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@color/white"
app:tabGravity="center"
app:tabIndicatorColor="@color/theme"
app:tabIndicatorFullWidth="false"
app:tabMaxWidth="200dp"
app:tabMinWidth="20dp"
app:tabMode="fixed"
app:tabPaddingStart="12dp"
app:tabPaddingEnd="8dp"
app:tabRippleColor="@color/transparent" />
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible" />
</LinearLayout>
\ No newline at end of file
... ...