-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wumeng1
authored and
wumeng1
committed
Jul 27, 2021
1 parent
adb8145
commit a5f44c6
Showing
13 changed files
with
267 additions
and
86 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/mirkowu/mvm/recycelerview/FirstBean.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,10 @@ | ||
package com.mirkowu.mvm.recycelerview; | ||
|
||
import com.mirkowu.lib_widget.adapter.IMultiType; | ||
|
||
public class FirstBean implements IMultiType { | ||
@Override | ||
public int getItemViewType() { | ||
return GridAdapter.TYPE_FIRST; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/mirkowu/mvm/recycelerview/FourBean.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,10 @@ | ||
package com.mirkowu.mvm.recycelerview; | ||
|
||
import com.mirkowu.lib_widget.adapter.IMultiType; | ||
|
||
public class FourBean implements IMultiType { | ||
@Override | ||
public int getItemViewType() { | ||
return GridAdapter.TYPE_FOUR; | ||
} | ||
} |
73 changes: 60 additions & 13 deletions
73
app/src/main/java/com/mirkowu/mvm/recycelerview/GridAdapter.kt
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,25 +1,72 @@ | ||
package com.mirkowu.mvm.recycelerview | ||
|
||
import android.view.ViewGroup | ||
import com.mirkowu.lib_widget.adapter.BaseRVAdapter | ||
import android.view.View | ||
import com.mirkowu.lib_image.ImageLoader | ||
import com.mirkowu.lib_widget.adapter.BaseRVHolder | ||
import com.mirkowu.mvm.databinding.ItemBindingListBinding | ||
import com.mirkowu.lib_widget.adapter.IMultiType | ||
import com.mirkowu.lib_widget.adapter.MultiTypeRVAdapter | ||
import com.mirkowu.mvm.R | ||
|
||
class GridAdapter : BaseRVAdapter<String, GridAdapter.Holder>() { | ||
class Holder(val binding: ItemBindingListBinding) : BaseRVHolder(binding.root) { | ||
class GridAdapter : MultiTypeRVAdapter<IMultiType, GridAdapter.Holder> { | ||
|
||
|
||
companion object { | ||
const val TYPE_FIRST = 1 | ||
const val TYPE_SECOND = 2 | ||
const val TYPE_THIRD = 3 | ||
const val TYPE_FOUR = 4 | ||
} | ||
|
||
override fun onCreateHolder(parent: ViewGroup, viewType: Int): Holder { | ||
return Holder(ItemBindingListBinding.inflate(mLayoutInflater, parent, false)) | ||
constructor() : super() { | ||
addItemViewType(TYPE_FIRST, R.layout.item_first) | ||
addItemViewType(TYPE_SECOND, R.layout.item_second) | ||
addItemViewType(TYPE_THIRD, R.layout.item_binding_list) | ||
addItemViewType(TYPE_FOUR, R.layout.item_binding_list) | ||
} | ||
|
||
override fun onBindHolder(holder: Holder, item: String?, position: Int) { | ||
holder.binding.apply { | ||
tvTitle.text = "第${position}XXXXXXXXXX" | ||
tvContent.text = "内容${position}" | ||
addOnClickListener(holder,tvTitle) | ||
addOnClickListener(holder,tvContent) | ||
override fun onBindHolder(holder: GridAdapter.Holder, item: IMultiType?, position: Int) { | ||
if (item == null) return | ||
when (item) { | ||
is FirstBean -> { | ||
bindHolderFirst(holder, item, position) | ||
} | ||
is SecondBean -> { | ||
bindHolderSecond(holder, item, position) | ||
} | ||
is ThirdBean -> { | ||
bindHolderThird(holder, item, position) | ||
} | ||
} | ||
|
||
// holder.binding.apply { | ||
// tvTitle.text = "第${position}XXXXXXXXXX" | ||
// tvContent.text = "内容${position}" | ||
// addOnClickListener(holder, tvTitle) | ||
// addOnClickListener(holder, tvContent) | ||
// } | ||
} | ||
|
||
private fun bindHolderFirst(holder: BaseRVHolder, item: FirstBean, position: Int) { | ||
holder.setText(R.id.tv_title, "第一张类型") | ||
|
||
} | ||
|
||
private fun bindHolderSecond(holder: BaseRVHolder, item: SecondBean, position: Int) { | ||
|
||
ImageLoader.load(holder.getView(R.id.iv_image), R.mipmap.ic_launcher) | ||
} | ||
|
||
private fun bindHolderThird(holder: BaseRVHolder, item: ThirdBean, position: Int) { | ||
holder.setText(R.id.tv_title, "标题") | ||
holder.setText(R.id.tv_content, "内容") | ||
|
||
} | ||
|
||
// class Holder(val binding: ItemBindingListBinding) : BaseRVHolder(binding.root) { | ||
// | ||
// } | ||
class Holder(val view: View) : BaseRVHolder(view) { | ||
|
||
} | ||
|
||
} |
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
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/mirkowu/mvm/recycelerview/SecondBean.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,10 @@ | ||
package com.mirkowu.mvm.recycelerview; | ||
|
||
import com.mirkowu.lib_widget.adapter.IMultiType; | ||
|
||
public class SecondBean implements IMultiType { | ||
@Override | ||
public int getItemViewType() { | ||
return GridAdapter.TYPE_SECOND; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/mirkowu/mvm/recycelerview/ThirdBean.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,10 @@ | ||
package com.mirkowu.mvm.recycelerview; | ||
|
||
import com.mirkowu.lib_widget.adapter.IMultiType; | ||
|
||
public class ThirdBean implements IMultiType { | ||
@Override | ||
public int getItemViewType() { | ||
return GridAdapter.TYPE_THIRD; | ||
} | ||
} |
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,10 @@ | ||
<?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" | ||
android:layout_height="wrap_content"> | ||
|
||
<TextView | ||
android:id="@+id/tv_title" | ||
android:layout_width="wrap_content" | ||
android:layout_height="40dp" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
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,10 @@ | ||
<?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" | ||
android:layout_height="wrap_content"> | ||
|
||
<ImageView | ||
android:id="@+id/iv_image" | ||
android:layout_width="match_parent" | ||
android:layout_height="200dp"/> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
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
8 changes: 8 additions & 0 deletions
8
lib_widget/src/main/java/com/mirkowu/lib_widget/adapter/IMultiType.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,8 @@ | ||
package com.mirkowu.lib_widget.adapter; | ||
|
||
/** | ||
* 需要做多类型Item的接口 | ||
*/ | ||
public interface IMultiType { | ||
int getItemViewType(); | ||
} |
Oops, something went wrong.