新增左下角功能view添加模块

This commit is contained in:
tongchenfei
2020-10-14 10:52:34 +08:00
parent 02f918dc8a
commit f37fd59467
18 changed files with 148 additions and 27 deletions

View File

@@ -876,27 +876,29 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
tv.setText(" height: " + currentHeight + ": " + v);
ViewGroup.LayoutParams params =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, currentHeight);
mApis.getTopViewManager().addView(v, params, new IMogoTopViewStatusListener() {
@Override
public void onViewAdded(View view) {
Logger.d(TAG, "onViewAdded: " + view);
}
mApis.getEntranceButtonController().addLeftFeatureView(v);
@Override
public void onViewRemoved(View view) {
Logger.d(TAG, "onViewRemoved: " + view);
}
@Override
public void beforeViewAddAnim(View view) {
Logger.d(TAG, "beforeViewAddAnim: " + view);
}
@Override
public void beforeViewRemoveAnim(View view) {
Logger.d(TAG, "beforeViewRemoveAnim: " + view);
}
});
// mApis.getTopViewManager().addView(v, params, new IMogoTopViewStatusListener() {
// @Override
// public void onViewAdded(View view) {
// Logger.d(TAG, "onViewAdded: " + view);
// }
//
// @Override
// public void onViewRemoved(View view) {
// Logger.d(TAG, "onViewRemoved: " + view);
// }
//
// @Override
// public void beforeViewAddAnim(View view) {
// Logger.d(TAG, "beforeViewAddAnim: " + view);
// }
//
// @Override
// public void beforeViewRemoveAnim(View view) {
// Logger.d(TAG, "beforeViewRemoveAnim: " + view);
// }
// });
});
findViewById(R.id.btnDebugAddBottomLayerView).setOnClickListener(v -> {

View File

@@ -43,4 +43,14 @@ public class MogoEntranceButtonControllerImpl implements IMogoEntranceButtonCont
public void init( Context context ) {
}
@Override
public void addLeftFeatureView(View view) {
EntranceViewHolder.getInstance().addLeftFeatureView(view);
}
@Override
public void removeLeftFeatureView(View view) {
EntranceViewHolder.getInstance().removeLeftFeatureView(view);
}
}

View File

@@ -5,6 +5,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.mogo.module.extensions.R;
import com.mogo.module.extensions.bean.BottomLayerViewWrapper;
import com.mogo.utils.logger.Logger;
@@ -19,6 +20,7 @@ import java.util.List;
public class EntranceViewHolder {
private static final String TAG = "EntranceViewHolder";
private List<BottomLayerViewWrapper> preAddView = new ArrayList<>();
private List<View> leftFeaturePreAddView = new ArrayList<>();
private EntranceViewHolder(){}
private volatile static EntranceViewHolder instance = null;
public static EntranceViewHolder getInstance(){
@@ -32,11 +34,13 @@ public class EntranceViewHolder {
return instance;
}
private ViewGroup rootViewGroup = null;
private ViewGroup featureViewGroup = null;
public void initRootViewGroup(View rootView) {
Logger.i(TAG, "initRootViewGroup==");
if(rootView instanceof ViewGroup) {
Logger.d(TAG, "initRootViewGroup 赋值");
rootViewGroup = (ViewGroup) rootView.getParent();
featureViewGroup = rootView.findViewById(R.id.module_entrance_id_buttons_container);
if (!preAddView.isEmpty()) {
Logger.d(TAG, "initRootViewGroup 增加底层view: " + preAddView.size());
Iterator<BottomLayerViewWrapper> iterator = preAddView.iterator();
@@ -46,6 +50,12 @@ public class EntranceViewHolder {
iterator.remove();
}
}
if (!leftFeaturePreAddView.isEmpty()) {
Logger.d(TAG, "initRootViewGroup 增加左下角FeatureView " + leftFeaturePreAddView.size());
for (View view : leftFeaturePreAddView) {
featureViewGroup.addView(view);
}
}
}
}
@@ -79,6 +89,16 @@ public class EntranceViewHolder {
return false;
}
private boolean containFeatureView(View view) {
int count = featureViewGroup.getChildCount();
for (int i = 0; i < count; i++) {
if(featureViewGroup.getChildAt(i).equals(view)){
return true;
}
}
return false;
}
/**
* 使用的时候需要预先判断rootViewGroup是否为空本方法默认rootViewGroup不为空
*/
@@ -107,7 +127,36 @@ public class EntranceViewHolder {
}
}
public void release(){
public void addLeftFeatureView(View view) {
Logger.d(TAG, "addLeftFeatureView==" + view);
if (featureViewGroup == null) {
// 先缓存起来,等待时机加载
if(!leftFeaturePreAddView.contains(view)) {
leftFeaturePreAddView.add(view);
}
}else{
// 直接加载
if (!containFeatureView(view)) {
featureViewGroup.addView(view);
}
}
}
public void removeLeftFeatureView(View view) {
if (featureViewGroup != null) {
featureViewGroup.removeView(view);
}
Iterator<View> iterator = leftFeaturePreAddView.iterator();
while (iterator.hasNext()) {
View wrapper = iterator.next();
if (wrapper.equals(view)) {
iterator.remove();
}
}
}
public void release(){
rootViewGroup = null;
}