diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/mylife/AdapterMyLife.java b/app/src/main/java/org/ole/planet/myplanet/ui/mylife/AdapterMyLife.java index 7dccb7beea..c7566100a4 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/mylife/AdapterMyLife.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/mylife/AdapterMyLife.java @@ -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; @@ -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) {