Kasun Kanchana
Member
Hello everyone. Recently I have developed an Android app where users can post their food recipes and see others' recipes. All the data such as recipe name, recipe images, ingredients, preparation steps, etc are stored in a MySQL database of my shared hosting service. To show recipes as a list, I'm making a remote MySQL connection through jdbcsql library.
To show recipes as a list, I have used Lazyloding with PreOptimizedCLV. The recipe image is downloaded after loading the data from the MySQL database including the image URL.
Loading around a few recipes is okay but when it comes to loading more recipes, the scrolling list is a bit laggy. I hope you can see it in below gif,
You can check the app from bellow link,
https://play.google.com/store/apps/details?id=com.foodiesdiary
To show recipes as a list, I have used Lazyloding with PreOptimizedCLV. The recipe image is downloaded after loading the data from the MySQL database including the image URL.
Loading around a few recipes is okay but when it comes to loading more recipes, the scrolling list is a bit laggy. I hope you can see it in below gif,
You can check the app from bellow link,
https://play.google.com/store/apps/details?id=com.foodiesdiary
Class_Globals:
Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Private CustomListView1 As CustomListView
Dim pclv As PreoptimizedCLV
End Sub
B4XPage_Created:
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("Filter")
pclv.Initialize(Me,"pclv",CustomListView1)
End Sub
Load Data:
Sub latest As ResumableSub
CustomListView1.Clear
Dim latestQuarry As String="SELECT r.recipe_id, r.user_id, r.category_id, r.title, r.description, r.cooking_time, r.creation_date, r.recipe_image_url, r.servings, c.category_name, u.user_name, u.user_image_url, COALESCE(rc.comment_count, 0) As comment_count, COALESCE(rr.avg_rating, 0) As avg_rating FROM tbl_recipes r JOIN tbl_users u ON r.user_id = u.user_id JOIN tbl_categories c ON r.category_id = c.category_id LEFT JOIN (Select recipe_id, COUNT(*) As comment_count FROM tbl_comments GROUP BY recipe_id) rc ON r.recipe_id = rc.recipe_id LEFT JOIN (Select recipe_id, AVG(rating_value) As avg_rating FROM tbl_ratings GROUP BY recipe_id) rr ON r.recipe_id = rr.recipe_id ORDER BY r.creation_date DESC;"
Dim SenderFilter As Object = Starter.mysql.ExecQueryAsync("SQL", latestQuarry, Null)
Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As JdbcResultSet)
If Success Then
Do While rs.NextRow
Dim r As recipes
r.Initialize
r.category_id= rs.GetInt("category_id")
r.cooking_time=rs.GetString("cooking_time")
r.creation_date=rs.GetString("creation_date")
r.description=rs.GetString("description")
r.recipe_id=rs.GetInt("recipe_id")
r.recipe_image_url=rs.GetString("recipe_image_url")
r.servings=rs.GetInt("servings")
r.title=rs.GetString("title")
r.user_id=rs.GetString("user_id")
Dim categoryName As String = rs.GetString("category_name")
Dim username As String = rs.GetString("user_name")
Dim commentCount As Int = rs.GetInt("comment_count")
Dim avgRating As Float = rs.GetString("avg_rating")
Dim userImageUrl As String = rs.GetString("user_image_url")
Dim data As List
data.Initialize
data.Add(r)
data.Add(categoryName)
data.Add(username)
data.Add(commentCount)
data.Add(avgRating)
data.Add(userImageUrl)
pclv.AddItem(200dip,Colors.White,data)
Loop
rs.Close
pclv.Commit
pclv.B4XSeekBar1.mBase.Visible=False
Return True
Else
Log(LastException)
Return False
End If
End Sub
CustomListView1_VisibleRangeChanged:
Private Sub CustomListView1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
For Each i As Int In pclv.VisibleRangeChanged(FirstIndex, LastIndex)
Dim item As CLVItem = CustomListView1.GetRawListItem(i)
Dim data As List
data.Initialize
data= CustomListView1.GetValue(i)
item.Panel.AddView(B4XPages.MainPage.recipe_item2(CustomListView1,CustomListView1.AsView.Width,200dip,data.Get(0),data.Get(2),data.Get(5),data.Get(4),data.Get(3),data.Get(1)), 0, 0, item.Panel.Width, item.Panel.Height)
Next
End Sub