-
-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from xuexiangjys/dev/1.1.7
Dev/1.1.7
- Loading branch information
Showing
63 changed files
with
1,686 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 18 additions & 1 deletion
19
...adapter/base/BroccoliRecyclerAdapter.java → ...ase/broccoli/BroccoliRecyclerAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,21 @@ | ||
package com.xuexiang.xuidemo.adapter.base; | ||
/* | ||
* Copyright (C) 2021 xuexiangjys([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.xuexiang.xuidemo.adapter.base.broccoli; | ||
|
||
import android.view.View; | ||
|
||
|
112 changes: 112 additions & 0 deletions
112
...c/main/java/com/xuexiang/xuidemo/adapter/base/broccoli/BroccoliSimpleDelegateAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright (C) 2021 xuexiangjys([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.xuexiang.xuidemo.adapter.base.broccoli; | ||
|
||
import android.view.View; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.alibaba.android.vlayout.LayoutHelper; | ||
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder; | ||
import com.xuexiang.xuidemo.adapter.base.delegate.SimpleDelegateAdapter; | ||
import com.xuexiang.xuidemo.adapter.base.delegate.XDelegateAdapter; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import me.samlss.broccoli.Broccoli; | ||
|
||
/** | ||
* 使用Broccoli占位的基础适配器 | ||
* | ||
* @author xuexiang | ||
* @since 2021/1/9 4:52 PM | ||
*/ | ||
public abstract class BroccoliSimpleDelegateAdapter<T> extends SimpleDelegateAdapter<T> { | ||
|
||
/** | ||
* 是否已经加载成功 | ||
*/ | ||
private boolean mHasLoad = false; | ||
private Map<View, Broccoli> mBroccoliMap = new HashMap<>(); | ||
|
||
public BroccoliSimpleDelegateAdapter(int layoutId, LayoutHelper layoutHelper) { | ||
super(layoutId, layoutHelper); | ||
} | ||
|
||
public BroccoliSimpleDelegateAdapter(int layoutId, LayoutHelper layoutHelper, Collection<T> list) { | ||
super(layoutId, layoutHelper, list); | ||
} | ||
|
||
public BroccoliSimpleDelegateAdapter(int layoutId, LayoutHelper layoutHelper, T[] data) { | ||
super(layoutId, layoutHelper, data); | ||
} | ||
|
||
@Override | ||
protected void bindData(@NonNull RecyclerViewHolder holder, int position, T item) { | ||
Broccoli broccoli = mBroccoliMap.get(holder.itemView); | ||
if (broccoli == null) { | ||
broccoli = new Broccoli(); | ||
mBroccoliMap.put(holder.itemView, broccoli); | ||
} | ||
if (mHasLoad) { | ||
broccoli.removeAllPlaceholders(); | ||
|
||
onBindData(holder, item, position); | ||
} else { | ||
onBindBroccoli(holder, broccoli); | ||
broccoli.show(); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* 绑定控件 | ||
* | ||
* @param holder | ||
* @param model | ||
* @param position | ||
*/ | ||
protected abstract void onBindData(RecyclerViewHolder holder, T model, int position); | ||
|
||
/** | ||
* 绑定占位控件 | ||
* | ||
* @param holder | ||
* @param broccoli | ||
*/ | ||
protected abstract void onBindBroccoli(RecyclerViewHolder holder, Broccoli broccoli); | ||
|
||
@Override | ||
public XDelegateAdapter refresh(Collection<T> collection) { | ||
mHasLoad = true; | ||
return super.refresh(collection); | ||
} | ||
|
||
/** | ||
* 资源释放,防止内存泄漏 | ||
*/ | ||
public void recycle() { | ||
for (Broccoli broccoli : mBroccoliMap.values()) { | ||
broccoli.removeAllPlaceholders(); | ||
} | ||
mBroccoliMap.clear(); | ||
clear(); | ||
} | ||
} |
Oops, something went wrong.