Getting repeated program stages in the adapter

Hi, I have tried to add program stages activity in the Android skeleton app, it was working well until I added a program stages in the server. When I updated metadata, I found three program stages are repeating all the time. In the attached image, after blue rectangle area, first and last three stages are in repetition. Thank you for helping me out.

Sdk.d2().programModule().programStages()
.byProgramUid().eq(programUid)
.orderBySortOrder(RepositoryScope.OrderByDirection.ASC)
.getPaged(20).observe(this, programStagePagedList -> {
adapter.submitList(programStagePagedList);
findViewById(R.id.programStageNotificator).setVisibility(
programStagePagedList.isEmpty() ? View.VISIBLE : View.GONE);
});

Note, In debugger, I found five program stages in the contigouspagedlist.
One more thing, it seems that five stages loaded first, then after a fraction of second, the repeated items loaded in the list.

Hi @RahmanMonjur,
that piece of code seems fine to me, but maybe the adapter or another class makes it behave like that. Could we take a look at the whole class? Is it public?

Thanks @vgarciabnz. I guess so, however, not finding any anomaly in the adapter. The behaviour is weird and clueless. Yes, I forked it and here are the codes

Just a plus @vgarciabnz, if I revoke the permission of BCG stage, everything behaves fine. I mean no repeating stages then.

Hi,
Although it’s not a solution, I got a temp fix to work on. onBindViewHolder event I changed…

ProgramStage programStage = getItem(position);
if (pstagelist.indexOf(programStage.uid()) < 0) {
pstagelist.add(programStage.uid());
holder.title.setText(programStage.displayName());
holder.title.setTextSize(20);
Integer programStageInstancesCount = Sdk.d2().eventModule().events()
.byProgramStageUid().eq(programStage.uid())
.byTrackedEntityInstanceUids(Lists.newArrayList(trackedEntityInstanceUid))
.blockingCount();

        if (programStageInstancesCount > 1)
            holder.subtitle1.setText(programStageInstancesCount.toString() + " instances");
        else
            holder.subtitle1.setText(programStageInstancesCount.toString() + " instance");
        holder.subtitle1.setTextSize(16);
        //StyleBinderHelper.bindStyle(holder, programStage.style());

        holder.cardSimple.setOnClickListener(view -> programStageSelectionListener
                .onProgramStageSelected(programUid, programStage.uid(), trackedEntityInstanceUid));
    } else {
        holder.itemView.setVisibility(View.INVISIBLE);
        holder.itemView.invalidate();
    }