Actually I'm trying to show posts in recyclerview by getting a set of posts from server (mongodb) and it's working fine. Then I'm trying to load post's username
by the help of post_ owner_mail
.You might say why do I load these things position wise instead of bulk wise but as there will be posts with different ownerMail
so it's not possible to prefetch their username. For that purpose I'm using a separate class for loading data from server and showing in text view . But now the problem is the although textview
is setting username but not all time and the recyclerview is lagging as well . Can anyone please help me to get rid of this problem.
Adapter Class Code :
@Override
public void onBindViewHolder( CustomRecyclerViewHolder holder, int position) {
//It's a data model class of image_links and post_owner_mails
TimelineData timelineData=totalList.get(holder.getAdapterPosition());
//It's the custom loader class through which I'm loading data and setting to txt view position wise
LoadData d=new LoadData(hold.userNameTxtView,timelineData.getPostOwnerMail());
}
LoadData Class :
public class LoadData{
private Socket socket;
{
try{
socket = IO.socket("http://192.168.43.218:8080");
}catch(URISyntaxException e){
throw new RuntimeException(e);
}
}
public LoadData(final TextView tv,final String email){
socket.disconnect();
socket.connect();
JSONObject ob=new JSONObject();
try {
ob.put("getFullnameMail",email);
socket.emit("data",ob);
socket.on("fullname", new Emitter.Listener() {
@Override
public void call(Object... args) {
final JSONObject ob=(JSONObject)args[0];
Needle.onMainThread().execute(new Runnable() {
@Override
public void run() {
try {
tv.setText(ob.getString("fullname"));
socket.disconnect();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
}
Database Storing Pattern:
{
"_id" : ObjectId("5aa9304391b4ee28f4e4525d"),
"post_owner_mail" : "john.cena",
"time" : "14 Mar 2018(01-30-50)",
"img_link" : [
"192.168.43.218:8080/user_info/john.cena/uploads/14 Mar 2018(01-30-50)/pic0.jpg",
"192.168.43.218:8080/user_info/john.cena/uploads/14 Mar 2018(01-30-50)/pic1.jpg"
],
"caption" : "#fun#cartoon"
}