Skip to content

Commit

Permalink
move realm thread transaction to background
Browse files Browse the repository at this point in the history
  • Loading branch information
Okuro3499 committed Nov 30, 2023
1 parent ef77f15 commit dcc03a5
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
Expand Down Expand Up @@ -115,19 +117,18 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int
else changeVisibility(holder, R.drawable.ic_visibility_off, SHOW);

}


}

public void updateVisibility(RecyclerView.ViewHolder holder, int position, boolean isVisible) {
RealmMyLife.updateVisibility(!isVisible, myLifeList.get(position).get_id(), mRealm, myLifeList.get(position).getUserId());
if (isVisible) {
changeVisibility(holder, R.drawable.ic_visibility, HIDE);
Utilities.toast(context, myLifeList.get(position).getTitle() + R.string.is_now_hidden);
} else {
changeVisibility(holder, R.drawable.ic_visibility_off, SHOW);
Utilities.toast(context, myLifeList.get(position).getTitle() + R.string.is_now_shown);
}
public void updateVisibility(final RecyclerView.ViewHolder holder, final int position, final boolean isVisible) {
mRealm.executeTransactionAsync(realm -> RealmMyLife.updateVisibility(!isVisible, myLifeList.get(position).get_id(), realm, myLifeList.get(position).getUserId()), () -> new Handler(Looper.getMainLooper()).post(() -> {
if (isVisible) {
changeVisibility(holder, R.drawable.ic_visibility, HIDE);
Utilities.toast(context, myLifeList.get(position).getTitle() + context.getString(R.string.is_now_hidden));
} else {
changeVisibility(holder, R.drawable.ic_visibility_off, SHOW);
Utilities.toast(context, myLifeList.get(position).getTitle() + context.getString(R.string.is_now_shown));
}
}), error -> Utilities.log(String.valueOf(error)));
}

public void changeVisibility(RecyclerView.ViewHolder holder, int imageId, float alpha) {
Expand Down

0 comments on commit dcc03a5

Please sign in to comment.