mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-27 01:54:45 +01:00
Fixing issues with reading info for kbin magazines
This commit fixes the issue where the information for Kbin/Mbin magazines weren't displayed properly on community pages. The problem was related to magazines having a different actor id (/m/ instead of /c/) Closes #182
This commit is contained in:
parent
67115e0dd6
commit
16dfc65c64
@ -274,6 +274,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
private boolean disableImagePreview;
|
private boolean disableImagePreview;
|
||||||
|
|
||||||
private boolean hideSubredditDescription;
|
private boolean hideSubredditDescription;
|
||||||
|
private boolean isKbinMagazine = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -557,10 +558,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
String actorID = (!isKbinMagazine) ? LemmyUtils.qualifiedCommunityName2ActorId(qualifiedName) : LemmyUtils.qualifiedMagazineName2ActorId(qualifiedName);
|
||||||
mSubredditViewModel = new ViewModelProvider(this,
|
mSubredditViewModel = new ViewModelProvider(this,
|
||||||
new SubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, LemmyUtils.qualifiedCommunityName2ActorId(qualifiedName)))
|
new SubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, actorID))
|
||||||
.get(SubredditViewModel.class);
|
.get(SubredditViewModel.class);
|
||||||
|
addObserverToLiveData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addObserverToLiveData() {
|
||||||
mSubredditViewModel.getSubredditLiveData().observe(this, subredditData -> {
|
mSubredditViewModel.getSubredditLiveData().observe(this, subredditData -> {
|
||||||
if (subredditData != null) {
|
if (subredditData != null) {
|
||||||
isNsfwSubreddit = subredditData.isNSFW();
|
isNsfwSubreddit = subredditData.isNSFW();
|
||||||
@ -768,6 +773,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
communityName = communityData.getTitle();
|
communityName = communityData.getTitle();
|
||||||
}
|
}
|
||||||
mCommunityStats = communityData.getCommunityStats();
|
mCommunityStats = communityData.getCommunityStats();
|
||||||
|
if (communityData.getActorId().contains("/m/")) {
|
||||||
|
isKbinMagazine = true;
|
||||||
|
if (mSubredditViewModel != null) {
|
||||||
|
// Remove current observer
|
||||||
|
mSubredditViewModel.getSubredditLiveData().removeObservers(ViewSubredditDetailActivity.this);
|
||||||
|
addObserverToLiveData();
|
||||||
|
}
|
||||||
|
}
|
||||||
setupVisibleElements();
|
setupVisibleElements();
|
||||||
communityId = communityData.getId();
|
communityId = communityData.getId();
|
||||||
ViewSubredditDetailActivity.this.communityData = communityData;
|
ViewSubredditDetailActivity.this.communityData = communityData;
|
||||||
|
@ -130,6 +130,8 @@ public class SidebarFragment extends Fragment {
|
|||||||
private boolean mDisableImagePreview;
|
private boolean mDisableImagePreview;
|
||||||
|
|
||||||
private String communityQualifiedName;
|
private String communityQualifiedName;
|
||||||
|
|
||||||
|
private boolean isKbinMagazine = false;
|
||||||
private LinearLayoutManagerBugFixed linearLayoutManager;
|
private LinearLayoutManagerBugFixed linearLayoutManager;
|
||||||
private int markdownColor;
|
private int markdownColor;
|
||||||
private String sidebarDescription;
|
private String sidebarDescription;
|
||||||
@ -137,6 +139,8 @@ public class SidebarFragment extends Fragment {
|
|||||||
@State
|
@State
|
||||||
CommunityStats mCommunityStats;
|
CommunityStats mCommunityStats;
|
||||||
private BasicUserRecyclerViewAdapter moderatorAdapter;
|
private BasicUserRecyclerViewAdapter moderatorAdapter;
|
||||||
|
private Markwon markwon;
|
||||||
|
private MarkwonAdapter markwonAdapter;
|
||||||
|
|
||||||
public SidebarFragment() {
|
public SidebarFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
@ -227,9 +231,9 @@ public class SidebarFragment extends Fragment {
|
|||||||
urlMenuBottomSheetFragment.show(getChildFragmentManager(), null);
|
urlMenuBottomSheetFragment.show(getChildFragmentManager(), null);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
Markwon markwon = MarkdownUtils.createFullRedditMarkwon(activity,
|
markwon = MarkdownUtils.createFullRedditMarkwon(activity,
|
||||||
miscPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener, mDisableImagePreview);
|
miscPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener, mDisableImagePreview);
|
||||||
MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter();
|
markwonAdapter = MarkdownUtils.createTablesAdapter();
|
||||||
|
|
||||||
linearLayoutManager = new LinearLayoutManagerBugFixed(activity);
|
linearLayoutManager = new LinearLayoutManagerBugFixed(activity);
|
||||||
recyclerView.setLayoutManager(linearLayoutManager);
|
recyclerView.setLayoutManager(linearLayoutManager);
|
||||||
@ -252,8 +256,17 @@ public class SidebarFragment extends Fragment {
|
|||||||
moderatorsRecyclerView.setAdapter(moderatorAdapter);
|
moderatorsRecyclerView.setAdapter(moderatorAdapter);
|
||||||
|
|
||||||
mSubredditViewModel = new ViewModelProvider(activity,
|
mSubredditViewModel = new ViewModelProvider(activity,
|
||||||
new SubredditViewModel.Factory(activity.getApplication(), mRedditDataRoomDatabase, LemmyUtils.qualifiedCommunityName2ActorId(communityQualifiedName)))
|
new SubredditViewModel.Factory(activity.getApplication(), mRedditDataRoomDatabase, (!isKbinMagazine) ? LemmyUtils.qualifiedCommunityName2ActorId(communityQualifiedName) :
|
||||||
|
LemmyUtils.qualifiedMagazineName2ActorId(communityQualifiedName)))
|
||||||
.get(SubredditViewModel.class);
|
.get(SubredditViewModel.class);
|
||||||
|
addLiveDataObserver();
|
||||||
|
|
||||||
|
swipeRefreshLayout.setOnRefreshListener(this::fetchSubredditData);
|
||||||
|
|
||||||
|
return rootView;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addLiveDataObserver() {
|
||||||
mSubredditViewModel.getSubredditLiveData().observe(getViewLifecycleOwner(), subredditData -> {
|
mSubredditViewModel.getSubredditLiveData().observe(getViewLifecycleOwner(), subredditData -> {
|
||||||
if (subredditData != null) {
|
if (subredditData != null) {
|
||||||
sidebarDescription = subredditData.getSidebarDescription();
|
sidebarDescription = subredditData.getSidebarDescription();
|
||||||
@ -276,10 +289,6 @@ public class SidebarFragment extends Fragment {
|
|||||||
fetchSubredditData();
|
fetchSubredditData();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
swipeRefreshLayout.setOnRefreshListener(this::fetchSubredditData);
|
|
||||||
|
|
||||||
return rootView;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -296,6 +305,12 @@ public class SidebarFragment extends Fragment {
|
|||||||
swipeRefreshLayout.setRefreshing(false);
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
mCommunityStats = subredditData.getCommunityStats();
|
mCommunityStats = subredditData.getCommunityStats();
|
||||||
moderatorAdapter.setUsers(subredditData.getModerators());
|
moderatorAdapter.setUsers(subredditData.getModerators());
|
||||||
|
if (subredditData.getActorId().contains("/m/")) {
|
||||||
|
isKbinMagazine = true;
|
||||||
|
mSubredditViewModel.getSubredditLiveData().removeObservers(getViewLifecycleOwner());
|
||||||
|
mSubredditViewModel.setSubredditName(LemmyUtils.qualifiedMagazineName2ActorId(communityQualifiedName));
|
||||||
|
addLiveDataObserver();
|
||||||
|
}
|
||||||
InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
||||||
subredditData, () -> swipeRefreshLayout.setRefreshing(false));
|
subredditData, () -> swipeRefreshLayout.setRefreshing(false));
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ public class ParseSubredditData {
|
|||||||
String name = community.getString("name");
|
String name = community.getString("name");
|
||||||
String description = "";
|
String description = "";
|
||||||
if (!community.isNull("description")) {
|
if (!community.isNull("description")) {
|
||||||
description = community.getString("description");
|
description = community.getString("description").trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean removed = community.getBoolean("removed");
|
boolean removed = community.getBoolean("removed");
|
||||||
|
@ -5,6 +5,7 @@ import android.app.Application;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
import androidx.lifecycle.ViewModel;
|
import androidx.lifecycle.ViewModel;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
@ -14,16 +15,40 @@ public class SubredditViewModel extends AndroidViewModel {
|
|||||||
private SubredditRepository mSubredditRepository;
|
private SubredditRepository mSubredditRepository;
|
||||||
private LiveData<SubredditData> mSubredditLiveData;
|
private LiveData<SubredditData> mSubredditLiveData;
|
||||||
|
|
||||||
|
private MutableLiveData<String> mSubredditNameLiveData;
|
||||||
|
private RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
|
||||||
public SubredditViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String id) {
|
public SubredditViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String id) {
|
||||||
super(application);
|
super(application);
|
||||||
mSubredditRepository = new SubredditRepository(redditDataRoomDatabase, id);
|
mSubredditRepository = new SubredditRepository(redditDataRoomDatabase, id);
|
||||||
mSubredditLiveData = mSubredditRepository.getSubredditLiveData();
|
mSubredditLiveData = mSubredditRepository.getSubredditLiveData();
|
||||||
|
mSubredditNameLiveData = new MutableLiveData<>(id);
|
||||||
|
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<SubredditData> getSubredditLiveData() {
|
public LiveData<SubredditData> getSubredditLiveData() {
|
||||||
return mSubredditLiveData;
|
return mSubredditLiveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<String> getSubredditNameLiveData() {
|
||||||
|
return mSubredditNameLiveData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubredditName(String subredditName) {
|
||||||
|
mSubredditNameLiveData.setValue(subredditName);
|
||||||
|
updateSubredditRepository();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSubredditRepository() {
|
||||||
|
String subredditName = mSubredditNameLiveData.getValue();
|
||||||
|
if (subredditName != null) {
|
||||||
|
mSubredditRepository = new SubredditRepository(mRedditDataRoomDatabase, subredditName);
|
||||||
|
|
||||||
|
mSubredditLiveData = mSubredditRepository.getSubredditLiveData();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void insert(SubredditData subredditData) {
|
public void insert(SubredditData subredditData) {
|
||||||
mSubredditRepository.insert(subredditData);
|
mSubredditRepository.insert(subredditData);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,14 @@ public class LemmyUtils {
|
|||||||
return "https://" + domain + "/u/" + userName;
|
return "https://" + domain + "/u/" + userName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String qualifiedMagazineName2ActorId(String qualifiedName) {
|
||||||
|
String[] splitQualifiedName = qualifiedName.split("@");
|
||||||
|
String userName = splitQualifiedName[0];
|
||||||
|
String domain = splitQualifiedName[1];
|
||||||
|
return "https://" + domain + "/m/" + userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Long dateStringToMills(String dateStr) {
|
public static Long dateStringToMills(String dateStr) {
|
||||||
long postTimeMillis = 0;
|
long postTimeMillis = 0;
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user