Skip to content

Commit 15e5268

Browse files
author
“TechnourceDeveloper”
committed
Add comments in functions
1 parent 1ae12c1 commit 15e5268

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

app/src/main/java/com/technource/android/ui/moreModule/MoreListAdapter.kt

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@ class MoreListAdapter : RecyclerView.Adapter<MoreListViewHolder>() {
1111
private val moreList: MutableList<MoreModel> = mutableListOf()
1212
private lateinit var setOnItemClick: RecyclerviewInterface
1313

14-
// Set item click listener
15-
fun setOnItemClick(onItemClick: RecyclerviewInterface) {
16-
setOnItemClick = onItemClick
17-
}
18-
19-
// Set data for the adapter
20-
fun setData(more: List<MoreModel>) {
21-
this.moreList.clear()
22-
this.moreList.addAll(more)
23-
notifyDataSetChanged()
24-
}
25-
2614
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MoreListViewHolder {
2715
// Inflate the layout for the item view
2816
val inflater = LayoutInflater.from(parent.context)
@@ -44,6 +32,26 @@ class MoreListAdapter : RecyclerView.Adapter<MoreListViewHolder>() {
4432
override fun getItemCount(): Int {
4533
return moreList.size
4634
}
35+
36+
/**
37+
Sets the click listener for the RecyclerView item.
38+
@param onItemClick The click listener to be set.
39+
*/
40+
fun setOnItemClick(onItemClick: RecyclerviewInterface) {
41+
setOnItemClick = onItemClick
42+
}
43+
44+
/**
45+
Sets the data for the adapter.
46+
Clears the existing data in moreList and adds the new data from the provided list.
47+
Notifies the adapter that the data set has changed.
48+
@param more The list of MoreModel objects to be set as data.
49+
*/
50+
fun setData(more: List<MoreModel>) {
51+
this.moreList.clear()
52+
this.moreList.addAll(more)
53+
notifyDataSetChanged()
54+
}
4755
}
4856

4957
class MoreListViewHolder(private val binding: MoreListItemBinding) :

app/src/main/java/com/technource/android/ui/moreModule/MoreViewModel.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,22 @@ class MoreViewModel : ViewModel() {
1313
fetchData()
1414
}
1515

16+
/**
17+
Returns the LiveData object containing the list of MoreModel objects.
18+
The LiveData object is used to observe changes to the list in the UI.
19+
@return The LiveData object representing the list of MoreModel objects.
20+
*/
1621
fun getList(): LiveData<List<MoreModel>> {
1722
return more
1823
}
1924

25+
/**
26+
Fetches the data asynchronously and updates the users LiveData.
27+
The data is fetched from a data source or generated locally.
28+
In this example, a list of MoreModel objects is created and assigned to the more LiveData.
29+
The observers of the LiveData will be notified of the updated data.
30+
*/
2031
private fun fetchData() {
21-
// Perform an asynchronous operation to fetch the data
22-
// Once the data is available, update the users LiveData
23-
// For example:
2432
val moreList = listOf(
2533
MoreModel("About us", Constants.aboutUs),
2634
MoreModel("Terms & Condition", Constants.termsNCondition),

0 commit comments

Comments
 (0)