Skip to content

Commit

Permalink
news: refactor towards more stability (fixes open-learning-exchange#2589
Browse files Browse the repository at this point in the history
  • Loading branch information
Okuro3499 and dogi authored Oct 9, 2023
1 parent 6d4cf3c commit f957a29
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1087
versionName "0.10.87"
versionCode 1088
versionName "0.10.88"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CommunityFragment : BaseContainerFragment(), AdapterNews.OnNewsItemClickLi
changeLayoutManager(orientation)

Utilities.log("list size " + list.size)
var adapter = AdapterNews(activity, list, user, null)
var adapter = AdapterNews(activity, list, user, null, true)
adapter.setListener(this)
adapter.setFromLogin(requireArguments().getBoolean("fromLogin", false))
adapter.setmRealm(mRealm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.ole.planet.myplanet.utilities.Utilities;

import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
Expand All @@ -55,16 +56,18 @@ public class AdapterNews extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public Context context;
public RealmUserModel currentUser;
public boolean fromLogin;
private boolean isFromNewsFragment;

public void setImageList(RealmList<String> imageList) {
this.imageList = imageList;
}

public AdapterNews(Context context, List<RealmNews> list, RealmUserModel user, RealmNews parentNews) {
public AdapterNews(Context context, List<RealmNews> list, RealmUserModel user, RealmNews parentNews,boolean isFromNewsFragment) {
this.context = context;
this.list = list;
this.currentUser = user;
this.parentNews = parentNews;
this.isFromNewsFragment = isFromNewsFragment;
config = Utilities.getCloudConfig().selectMode(ChipCloud.SelectMode.close);
}

Expand Down Expand Up @@ -278,9 +281,12 @@ private void showHideButtons(RealmUserModel userModel, RecyclerView.ViewHolder h
}
}


private void deletePost(RealmNews news) {
if (!mRealm.isInTransaction()) mRealm.beginTransaction();
list.remove(news);
if (isFromNewsFragment) {
list.remove(news);
}
if (news != null) {
news.deleteFromRealm();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void setData(List<RealmNews> list) {
SharedPreferences settings = getActivity().getSharedPreferences(SyncActivity.PREFS_NAME, Context.MODE_PRIVATE);
List<RealmMyLibrary> lib = mRealm.where(RealmMyLibrary.class).in("_id", resourceIds.toArray(new String[]{})).findAll();
getUrlsAndStartDownload(lib, settings, urls);
adapterNews = new AdapterNews(getActivity(), list, user, null);
adapterNews = new AdapterNews(getActivity(), list, user, null, true);
adapterNews.setmRealm(mRealm);
adapterNews.setFromLogin(getArguments().getBoolean("fromLogin"));
adapterNews.setListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void showData(String id) {
RealmNews news = mRealm.where(RealmNews.class).equalTo("id", id).findFirst();

List<RealmNews> list = mRealm.where(RealmNews.class).sort("time", Sort.DESCENDING).equalTo("replyTo", id, Case.INSENSITIVE).findAll();
newsAdapter = new AdapterNews(this, list, user, news);
newsAdapter = new AdapterNews(this, list, user, news, false);
newsAdapter.setListener(this);
newsAdapter.setmRealm(mRealm);
newsAdapter.setFromLogin(getIntent().getBooleanExtra("fromLogin", false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private void createTeamLog() {
}

private void showRecyclerView(List<RealmNews> realmNewsList) {
AdapterNews adapterNews = new AdapterNews(getActivity(), realmNewsList, user, null);
AdapterNews adapterNews = new AdapterNews(getActivity(), realmNewsList, user, null, true);
adapterNews.setmRealm(mRealm);
adapterNews.setListener(this);
rvDiscussion.setAdapter(adapterNews);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void onConfigurationChanged(Configuration newConfig) {
}

private void showRecyclerView(List<RealmNews> realmNewsList) {
AdapterNews adapterNews = new AdapterNews(getActivity(), realmNewsList, user, null);
AdapterNews adapterNews = new AdapterNews(getActivity(), realmNewsList, user, null, true);
adapterNews.setmRealm(mRealm);
adapterNews.setListener(this);
fragmentDiscussionListBinding.rvDiscussion.setAdapter(adapterNews);
Expand Down

0 comments on commit f957a29

Please sign in to comment.