initHourRankList UI调整
This commit is contained in:
parent
87e372e8f9
commit
636f5ded6f
@ -1,54 +1,96 @@
|
||||
package com.yunbao.live.viewmodel;
|
||||
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.view.ViewTreeObserver;
|
||||
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.momo.mcamera.util.JsonUtil;
|
||||
import com.yunbao.common.interfaces.CommonCallback;
|
||||
import com.yunbao.common.utils.SpUtil;
|
||||
import com.yunbao.live.R;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import io.rong.common.LibStorageUtils;
|
||||
|
||||
//直播时候位置做的 viewModel 注意这里
|
||||
public class LivePositionViewModel extends ViewModel {
|
||||
|
||||
//值判断到此根节点的位置
|
||||
private View RootView ;
|
||||
//直播播放区域
|
||||
private static String LIVE_BROADCAST_AREA = "live_broadcast_area";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 计算控件 Z 相对于 ViewGroupA 的位置
|
||||
* @param child 当前控件 Z
|
||||
* @param parent 目标 ViewGroupA
|
||||
* @return 相对位置 [x, y]
|
||||
*/
|
||||
public static int[] calculateRelativePosition(View child, View parent) {
|
||||
int[] position = new int[2]; // 存储相对位置 [x, y]
|
||||
|
||||
child.getLocationInWindow(position);
|
||||
child.getLocationOnScreen(position);
|
||||
//child.getLocationInSurface(position);
|
||||
|
||||
|
||||
// while (child != null && child != parent) {
|
||||
// if (child instanceof ViewGroup) {
|
||||
// ViewGroup viewGroup = (ViewGroup) child;
|
||||
// int[] childLocation = new int[2];
|
||||
// child.getLocationInParent(viewGroup);
|
||||
// position[0] += childLocation[0];
|
||||
// position[1] += childLocation[1];
|
||||
// } else {
|
||||
// int[] childLocation = new int[2];
|
||||
// child.getLocationInParent((ViewGroup) child.getParent());
|
||||
// position[0] += childLocation[0];
|
||||
// position[1] += childLocation[1];
|
||||
// }
|
||||
// child = child.getParent() instanceof View ? (View) child.getParent() : null;
|
||||
// }
|
||||
|
||||
return position;
|
||||
// Recursively check the visibility of this view and all its parent views
|
||||
private Boolean isViewVisible(View view) {
|
||||
if (view.getVisibility() != View.VISIBLE) {
|
||||
return false;
|
||||
}
|
||||
Object currentView = view;
|
||||
while (currentView instanceof View) {
|
||||
currentView = ((View) currentView).getParent();
|
||||
if (currentView instanceof View) {
|
||||
View parent = (View) currentView;
|
||||
if (parent.getVisibility() != View.VISIBLE) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void addViewTreeObserver(View view) {
|
||||
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
// 检查view是否可见
|
||||
if (isViewVisible(view)) {//当一个控件变得可见的时候
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
|
||||
view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
||||
} else {
|
||||
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public ViewPosition calculateRelativePosition(View child) {
|
||||
int[] position = new int[2]; // 存储相对位置 [x, y]
|
||||
child.getLocationInWindow(position);
|
||||
return new ViewPosition(position[0], position[1], child.getWidth(), child.getHeight());
|
||||
}
|
||||
|
||||
|
||||
public void saveViewPosition(String keyStr, ViewPosition saveViewPosition) {
|
||||
SpUtil.setStringValue(keyStr, JsonUtil.instance.toJson(saveViewPosition));
|
||||
}
|
||||
|
||||
public ViewPosition getViewPosition(String keyStr) {
|
||||
String json = SpUtil.getStringValue(keyStr);
|
||||
if (!TextUtils.isEmpty(json)) {
|
||||
return JsonUtil.instance.fromJson(json, ViewPosition.class);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void saveViewPosition(View view) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -962,7 +962,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
|
||||
@Override
|
||||
public void run() {
|
||||
ViewGroup.LayoutParams params1 = tricky_layout_name.getLayoutParams();
|
||||
params1.width = mChatRecyclerView.getWidth()-DpUtil.dp2px(5);
|
||||
params1.width = mChatRecyclerView.getWidth() - DpUtil.dp2px(5);
|
||||
tricky_layout_name.setLayoutParams(params1);
|
||||
}
|
||||
});
|
||||
@ -1014,7 +1014,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
|
||||
public void run() {
|
||||
//TODO 这里报了类型错误 android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
|
||||
ViewGroup.LayoutParams params1 = sud_layout_name.getLayoutParams();
|
||||
params1.width = mChatRecyclerView.getWidth()-DpUtil.dp2px(5);
|
||||
params1.width = mChatRecyclerView.getWidth() - DpUtil.dp2px(5);
|
||||
sud_layout_name.setLayoutParams(params1);
|
||||
}
|
||||
});
|
||||
@ -3471,7 +3471,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
|
||||
}
|
||||
}
|
||||
initWishListData(wishlistBean);
|
||||
}else {
|
||||
} else {
|
||||
stopPart2Flipper(wishFlipperRoot);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -3520,7 +3520,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
|
||||
* @param view 要从翻页器中移除的视图
|
||||
*/
|
||||
private void stopPart2Flipper(View view) {
|
||||
if (view == null || newPart2Flipper==null) return;
|
||||
if (view == null || newPart2Flipper == null) return;
|
||||
// 获取翻页器中当前的子视图数量,以判断是否满足停止翻页的条件
|
||||
newPart2Flipper.getChildCount();
|
||||
|
||||
@ -3564,13 +3564,13 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
|
||||
if (flipper.getChildCount() > 0) {
|
||||
flipper.removeAllViews();
|
||||
}
|
||||
// LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(DpUtil.dp2px(16), DpUtil.dp2px(16));
|
||||
// LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
// textParams.leftMargin = DpUtil.dp2px(5);
|
||||
// params.leftMargin = DpUtil.dp2px(5);
|
||||
View hotView = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list2, null);
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(DpUtil.dp2px(14), DpUtil.dp2px(14));
|
||||
LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
textParams.leftMargin = DpUtil.dp2px(5);
|
||||
params.leftMargin = DpUtil.dp2px(5);
|
||||
View hotView = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list, null);
|
||||
hotView.setTag("hotView");
|
||||
View hourView = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list2, null);
|
||||
View hourView = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list, null);
|
||||
hourView.setTag("hourView");
|
||||
ImageView hotPic = hotView.findViewById(R.id.wish_pic);
|
||||
ImageView hourPic = hourView.findViewById(R.id.wish_pic);
|
||||
@ -3578,15 +3578,15 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
|
||||
mHourRank = hourView.findViewById(R.id.wish_index);
|
||||
mHotText.setText("0");
|
||||
mHourRank.setText(mHourRank.getContext().getString(R.string.heat_add));
|
||||
// mHotText.setLayoutParams(textParams);
|
||||
// mHourRank.setLayoutParams(textParams);
|
||||
// mHotText.setGravity(Gravity.CENTER);
|
||||
// mHourRank.setGravity(Gravity.CENTER);
|
||||
mHotText.setLayoutParams(textParams);
|
||||
mHourRank.setLayoutParams(textParams);
|
||||
mHotText.setGravity(Gravity.CENTER);
|
||||
mHourRank.setGravity(Gravity.CENTER);
|
||||
setHourRankData(Long.parseLong(model.getRank()));
|
||||
hotPic.setImageResource(R.mipmap.ic_live_hot_rank);
|
||||
hourPic.setImageResource(R.mipmap.ic_live_hour_rank);
|
||||
// hotPic.setLayoutParams(params);
|
||||
// hourPic.setLayoutParams(params);
|
||||
hotPic.setLayoutParams(params);
|
||||
hourPic.setLayoutParams(params);
|
||||
flipper.addView(hotView);
|
||||
flipper.addView(hourView);
|
||||
flipper.startFlipping();
|
||||
@ -3618,30 +3618,30 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
|
||||
if (flipper.getChildCount() > 0) {
|
||||
flipper.removeAllViews();
|
||||
}
|
||||
// LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(DpUtil.dp2px(16), DpUtil.dp2px(16));
|
||||
// LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
// textParams.leftMargin = DpUtil.dp2px(5);
|
||||
// params.leftMargin = DpUtil.dp2px(5);
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(DpUtil.dp2px(11), ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
textParams.leftMargin = DpUtil.dp2px(5);
|
||||
params.leftMargin = DpUtil.dp2px(5);
|
||||
API.get().pdLiveApi(mContext).getHourChartRank(mLiveUid).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(listResponseModel -> {
|
||||
List<HourRank> info = listResponseModel.getData().getInfo();
|
||||
if (!info.isEmpty()) {
|
||||
View hotView = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list2, null);
|
||||
View hourView = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list2, null);
|
||||
View hotView = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list, null);
|
||||
View hourView = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list, null);
|
||||
ImageView hotPic = hotView.findViewById(R.id.wish_pic);
|
||||
ImageView hourPic = hourView.findViewById(R.id.wish_pic);
|
||||
mHotText = hotView.findViewById(R.id.wish_index);
|
||||
mHourRank = hourView.findViewById(R.id.wish_index);
|
||||
mHotText.setText("0");
|
||||
mHourRank.setText(mHourRank.getContext().getString(R.string.heat_add));
|
||||
// mHotText.setLayoutParams(textParams);
|
||||
// mHourRank.setLayoutParams(textParams);
|
||||
// mHotText.setGravity(Gravity.CENTER);
|
||||
// mHourRank.setGravity(Gravity.CENTER);
|
||||
mHotText.setLayoutParams(textParams);
|
||||
mHourRank.setLayoutParams(textParams);
|
||||
mHotText.setGravity(Gravity.CENTER);
|
||||
mHourRank.setGravity(Gravity.CENTER);
|
||||
setHourRankData(info.get(0).getRank());
|
||||
hotPic.setImageResource(R.mipmap.ic_live_hot_rank);
|
||||
hourPic.setImageResource(R.mipmap.ic_live_hour_rank);
|
||||
// hotPic.setLayoutParams(params);
|
||||
// hourPic.setLayoutParams(params);
|
||||
hotPic.setLayoutParams(params);
|
||||
hourPic.setLayoutParams(params);
|
||||
flipper.addView(hotView);
|
||||
flipper.addView(hourView);
|
||||
flipper.startFlipping();
|
||||
|
@ -1,43 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
tools:layout_width="70dp"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:background="@color/transparent"
|
||||
tools:background="@drawable/bg_live_item"
|
||||
tools:layout_height="22.5dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/wish_pic"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
tools:src="@mipmap/ic_live_hot_rank"
|
||||
android:layout_marginStart="7dp"
|
||||
android:layout_marginBottom="1dp"
|
||||
android:layout_width="11dp"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<com.yunbao.common.views.weight.MarqueeTextView
|
||||
android:id="@+id/wish_index"
|
||||
android:layout_marginBottom="1.3dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/wish_pic"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="热度加成"
|
||||
android:ellipsize="marquee"
|
||||
android:focusable="true"
|
||||
android:gravity="center"
|
||||
android:focusableInTouchMode="true"
|
||||
android:marqueeRepeatLimit="marquee_forever"
|
||||
android:scrollHorizontally="true"
|
||||
android:singleLine="true"
|
||||
android:textColor="#FFFFFFFF"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:textSize="10sp" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue
Block a user