diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index bef18e69..acacff02 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -402,6 +402,11 @@
android:label="@string/subscriptions"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" />
+
call = lemmyAPI.getSiteInfo(accessToken);
+ call.enqueue(new Callback() {
+ @Override
+ public void onResponse(Call call, retrofit2.Response response) {
+ if (response.isSuccessful()) {
+ String siteInfo = response.body();
+ if (siteInfo != null) {
+ List blockedUsers = new ArrayList<>();
+ List blockedCommunities = new ArrayList<>();
+ try {
+ JSONObject siteInfoJson = new JSONObject(siteInfo).getJSONObject("my_user");
+ JSONArray blockedUsersJson = (siteInfoJson.has("person_blocks")) ? siteInfoJson.getJSONArray("person_blocks") : null;
+ JSONArray blockedCommunitiesJson = (siteInfoJson.has("community_blocks")) ? siteInfoJson.getJSONArray("community_blocks") : null;
+ if (blockedUsersJson != null) {
+ for (int i = 0; i < blockedUsersJson.length(); i++) {
+ JSONObject blockedUserJson = blockedUsersJson.getJSONObject(i).getJSONObject("target");
+ int id = blockedUserJson.getInt("id");
+ String name = blockedUserJson.getString("name");
+ String avatar = blockedUserJson.getString("avatar");
+ String qualifiedName = LemmyUtils.actorID2FullName(blockedUserJson.getString("actor_id"));
+ BlockedUserData blockedUserData = new BlockedUserData(id, name, avatar, qualifiedName, accountName);
+
+ blockedUsers.add(blockedUserData);
+ }
+ }
+ if (blockedCommunitiesJson != null) {
+ for (int i = 0; i < blockedCommunitiesJson.length(); i++) {
+ JSONObject blockedCommunityJson = blockedCommunitiesJson.getJSONObject(i);
+ SubredditData blockedCommunityData = ParseSubredditData.parseSubredditData(blockedCommunityJson, true);
+ blockedCommunities.add(new BlockedCommunityData(blockedCommunityData, accountName));
+ }
+ }
+ fetchBlockedThingsListener.onFetchBlockedThingsSuccess(blockedUsers, blockedCommunities);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ fetchBlockedThingsListener.onFetchBlockedThingsFailure();
+ }
+ } else {
+ fetchBlockedThingsListener.onFetchBlockedThingsFailure();
+ }
+ } else {
+ fetchBlockedThingsListener.onFetchBlockedThingsFailure();
+ }
+ }
+
+ @Override
+ public void onFailure(Call call, Throwable t) {
+ fetchBlockedThingsListener.onFetchBlockedThingsFailure();
+ }
+ });
+ }
+
+ public interface FetchBlockedThingsListener {
+ void onFetchBlockedThingsSuccess(List blockedUsers, List blockedCommunities);
+
+ void onFetchBlockedThingsFailure();
+ }
+}
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/BlockedThingListingActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/BlockedThingListingActivity.java
new file mode 100644
index 00000000..e2fadba4
--- /dev/null
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/BlockedThingListingActivity.java
@@ -0,0 +1,462 @@
+package eu.toldi.infinityforlemmy.activities;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Handler;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.view.WindowManager;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.widget.Toolbar;
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+import androidx.core.view.inputmethod.EditorInfoCompat;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentPagerAdapter;
+import androidx.viewpager.widget.ViewPager;
+
+import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.appbar.CollapsingToolbarLayout;
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
+import com.google.android.material.tabs.TabLayout;
+
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+
+import java.util.List;
+import java.util.concurrent.Executor;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import eu.toldi.infinityforlemmy.ActivityToolbarInterface;
+import eu.toldi.infinityforlemmy.FragmentCommunicator;
+import eu.toldi.infinityforlemmy.Infinity;
+import eu.toldi.infinityforlemmy.R;
+import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
+import eu.toldi.infinityforlemmy.RetrofitHolder;
+import eu.toldi.infinityforlemmy.account.FetchBlockedThings;
+import eu.toldi.infinityforlemmy.asynctasks.InsertBlockedThings;
+import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityData;
+import eu.toldi.infinityforlemmy.blockeduser.BlockedUserData;
+import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
+import eu.toldi.infinityforlemmy.customviews.ViewPagerBugFixed;
+import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
+import eu.toldi.infinityforlemmy.events.GoBackToMainPageEvent;
+import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
+import eu.toldi.infinityforlemmy.fragments.BlockedCommunitiesListingFragment;
+import eu.toldi.infinityforlemmy.fragments.BlockedUsersListingFragment;
+import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
+import eu.toldi.infinityforlemmy.utils.Utils;
+import retrofit2.Retrofit;
+
+
+public class BlockedThingListingActivity extends BaseActivity implements ActivityToolbarInterface {
+
+ public static final String EXTRA_SHOW_MULTIREDDITS = "ESM";
+ private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
+ private static final String INSERT_MULTIREDDIT_STATE = "IMS";
+
+ @BindView(R.id.coordinator_layout_subscribed_thing_listing_activity)
+ CoordinatorLayout coordinatorLayout;
+ @BindView(R.id.appbar_layout_subscribed_thing_listing_activity)
+ AppBarLayout appBarLayout;
+ @BindView(R.id.collapsing_toolbar_layout_subscribed_thing_listing_activity)
+ CollapsingToolbarLayout collapsingToolbarLayout;
+ @BindView(R.id.toolbar_subscribed_thing_listing_activity)
+ Toolbar toolbar;
+ @BindView(R.id.search_edit_text_subscribed_thing_listing_activity)
+ EditText searchEditText;
+ @BindView(R.id.tab_layout_subscribed_thing_listing_activity)
+ TabLayout tabLayout;
+ @BindView(R.id.view_pager_subscribed_thing_listing_activity)
+ ViewPagerBugFixed viewPager;
+ @BindView(R.id.fab_subscribed_thing_listing_activity)
+ FloatingActionButton fab;
+ @Inject
+ @Named("oauth")
+ Retrofit mOauthRetrofit;
+
+ @Inject
+ @Named("no_oauth")
+ RetrofitHolder mRetrofit;
+ @Inject
+ RedditDataRoomDatabase mRedditDataRoomDatabase;
+ @Inject
+ @Named("default")
+ SharedPreferences mSharedPreferences;
+ @Inject
+ @Named("current_account")
+ SharedPreferences mCurrentAccountSharedPreferences;
+ @Inject
+ CustomThemeWrapper mCustomThemeWrapper;
+ @Inject
+ Executor mExecutor;
+ private String mAccessToken;
+ private String mAccountName;
+
+ private String mAccountQualifiedName;
+ private boolean mInsertSuccess = false;
+ private boolean mInsertMultiredditSuccess = false;
+ private boolean showMultiReddits = false;
+ private SectionsPagerAdapter sectionsPagerAdapter;
+ private Menu mMenu;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.activity_subscribed_thing_listing);
+
+ ButterKnife.bind(this);
+
+ EventBus.getDefault().register(this);
+
+ applyCustomTheme();
+
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) {
+ mSliderPanel = Slidr.attach(this);
+ }
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ Window window = getWindow();
+
+ if (isChangeStatusBarIconColor()) {
+ addOnOffsetChangedListener(appBarLayout);
+ }
+
+ if (isImmersiveInterface()) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ window.setDecorFitsSystemWindows(false);
+ } else {
+ window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
+ }
+ adjustToolbar(toolbar);
+
+ int navBarHeight = getNavBarHeight();
+ if (navBarHeight > 0) {
+ CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
+ params.bottomMargin += navBarHeight;
+ fab.setLayoutParams(params);
+ }
+ }
+ }
+
+ setSupportActionBar(toolbar);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setToolbarGoToTop(toolbar);
+
+ mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
+ mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "-");
+ mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, "-");
+
+ if (savedInstanceState != null) {
+ mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE);
+ mInsertMultiredditSuccess = savedInstanceState.getBoolean(INSERT_MULTIREDDIT_STATE);
+ } else {
+ showMultiReddits = getIntent().getBooleanExtra(EXTRA_SHOW_MULTIREDDITS, false);
+ }
+
+ if (mAccessToken == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ searchEditText.setImeOptions(searchEditText.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING);
+ }
+
+ searchEditText.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+
+ }
+
+ @Override
+ public void afterTextChanged(Editable editable) {
+ sectionsPagerAdapter.changeSearchQuery(editable.toString());
+ }
+ });
+ initializeViewPagerAndLoadSubscriptions();
+ }
+
+ @Override
+ public SharedPreferences getDefaultSharedPreferences() {
+ return mSharedPreferences;
+ }
+
+ @Override
+ protected CustomThemeWrapper getCustomThemeWrapper() {
+ return mCustomThemeWrapper;
+ }
+
+ @Override
+ protected void applyCustomTheme() {
+ coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
+ applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar);
+ applyTabLayoutTheme(tabLayout);
+ applyFABTheme(fab, mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
+ searchEditText.setTextColor(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor());
+ searchEditText.setHintTextColor(mCustomThemeWrapper.getToolbarSecondaryTextColor());
+ }
+
+ private void initializeViewPagerAndLoadSubscriptions() {
+ fab.setOnClickListener(view -> {
+ Intent intent = new Intent(this, CreateMultiRedditActivity.class);
+ startActivity(intent);
+ });
+ sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
+ viewPager.setAdapter(sectionsPagerAdapter);
+ viewPager.setOffscreenPageLimit(2);
+ if (viewPager.getCurrentItem() != 2) {
+ fab.hide();
+ }
+ viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
+ @Override
+ public void onPageSelected(int position) {
+ if (position == 0) {
+ unlockSwipeRightToGoBack();
+ fab.hide();
+ } else {
+ lockSwipeRightToGoBack();
+ if (position != 2) {
+ fab.hide();
+ } else {
+ fab.show();
+ }
+ }
+ }
+ });
+ tabLayout.setupWithViewPager(viewPager);
+
+ if (showMultiReddits) {
+ viewPager.setCurrentItem(2, false);
+ }
+
+ loadBlocks(false);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.subscribed_thing_listing_activity, menu);
+ mMenu = menu;
+ applyMenuItemTheme(menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ if (item.getItemId() == R.id.action_search_subscribed_thing_listing_activity) {
+ item.setVisible(false);
+ searchEditText.setVisibility(View.VISIBLE);
+ searchEditText.requestFocus();
+ if (searchEditText.requestFocus()) {
+ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.showSoftInput(searchEditText, InputMethodManager.SHOW_IMPLICIT);
+ }
+ return true;
+ } else if (item.getItemId() == android.R.id.home) {
+ if (searchEditText.getVisibility() == View.VISIBLE) {
+ Utils.hideKeyboard(this);
+ searchEditText.setVisibility(View.GONE);
+ searchEditText.setText("");
+ mMenu.findItem(R.id.action_search_subscribed_thing_listing_activity).setVisible(true);
+ sectionsPagerAdapter.changeSearchQuery("");
+ return true;
+ }
+ finish();
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (searchEditText.getVisibility() == View.VISIBLE) {
+ Utils.hideKeyboard(this);
+ searchEditText.setVisibility(View.GONE);
+ searchEditText.setText("");
+ mMenu.findItem(R.id.action_search_subscribed_thing_listing_activity).setVisible(true);
+ sectionsPagerAdapter.changeSearchQuery("");
+ } else {
+ super.onBackPressed();
+ }
+ }
+
+ @Override
+ protected void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE, mInsertSuccess);
+ outState.putBoolean(INSERT_MULTIREDDIT_STATE, mInsertMultiredditSuccess);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ EventBus.getDefault().unregister(this);
+ }
+
+ public void loadBlocks(boolean forceLoad) {
+ if (mAccessToken != null && !(!forceLoad && mInsertSuccess)) {
+ FetchBlockedThings.fetchBlockedThings(mRetrofit.getRetrofit(), mAccessToken, mAccountQualifiedName, new FetchBlockedThings.FetchBlockedThingsListener() {
+ @Override
+ public void onFetchBlockedThingsSuccess(List blockedUsers, List blockedCommunities) {
+ InsertBlockedThings.insertBlockedThings(mExecutor, new Handler(), mRedditDataRoomDatabase, mAccountQualifiedName,
+ blockedCommunities, blockedUsers, () -> {
+ mInsertSuccess = true;
+ sectionsPagerAdapter.stopRefreshProgressbar();
+ });
+ }
+
+ @Override
+ public void onFetchBlockedThingsFailure() {
+
+ }
+ });
+ }
+ }
+
+
+ @Subscribe
+ public void onAccountSwitchEvent(SwitchAccountEvent event) {
+ finish();
+ }
+
+ @Subscribe
+ public void goBackToMainPageEvent(GoBackToMainPageEvent event) {
+ finish();
+ }
+
+ @Override
+ public void onLongPress() {
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.goBackToTop();
+ }
+ }
+
+ @Override
+ public void lockSwipeRightToGoBack() {
+ if (mSliderPanel != null) {
+ mSliderPanel.lock();
+ }
+ }
+
+ @Override
+ public void unlockSwipeRightToGoBack() {
+ if (mSliderPanel != null) {
+ mSliderPanel.unlock();
+ }
+ }
+
+ private class SectionsPagerAdapter extends FragmentPagerAdapter {
+
+ private BlockedCommunitiesListingFragment blockedCommunitiesListingFragment;
+ private BlockedUsersListingFragment followedUsersListingFragment;
+
+ public SectionsPagerAdapter(FragmentManager fm) {
+ super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
+ }
+
+ @NonNull
+ @Override
+ public Fragment getItem(int position) {
+ switch (position) {
+ default:
+ case 0: {
+ BlockedCommunitiesListingFragment fragment = new BlockedCommunitiesListingFragment();
+ Bundle bundle = new Bundle();
+ bundle.putBoolean(BlockedCommunitiesListingFragment.EXTRA_IS_SUBREDDIT_SELECTION, false);
+ bundle.putString(BlockedCommunitiesListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
+ bundle.putString(BlockedCommunitiesListingFragment.EXTRA_ACCOUNT_QUALIFIED_NAME, mAccountQualifiedName);
+ bundle.putString(BlockedCommunitiesListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
+ fragment.setArguments(bundle);
+ return fragment;
+ }
+ case 1: {
+ BlockedUsersListingFragment fragment = new BlockedUsersListingFragment();
+ Bundle bundle = new Bundle();
+ bundle.putString(BlockedUsersListingFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
+ bundle.putString(BlockedUsersListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
+ fragment.setArguments(bundle);
+ return fragment;
+ }
+ }
+ }
+
+ @Override
+ public int getCount() {
+ return 2;
+ }
+
+ @Override
+ public CharSequence getPageTitle(int position) {
+ switch (position) {
+ case 0:
+ return Utils.getTabTextWithCustomFont(typeface, getString(R.string.communities));
+ case 1:
+ return Utils.getTabTextWithCustomFont(typeface, getString(R.string.users));
+ case 2:
+ return Utils.getTabTextWithCustomFont(typeface, getString(R.string.multi_reddits));
+ }
+
+ return null;
+ }
+
+ @NonNull
+ @Override
+ public Object instantiateItem(@NonNull ViewGroup container, int position) {
+ Fragment fragment = (Fragment) super.instantiateItem(container, position);
+ if (position == 0) {
+ blockedCommunitiesListingFragment = (BlockedCommunitiesListingFragment) fragment;
+ } else if (position == 1) {
+ followedUsersListingFragment = (BlockedUsersListingFragment) fragment;
+ }
+
+ return fragment;
+ }
+
+ void stopRefreshProgressbar() {
+ if (blockedCommunitiesListingFragment != null) {
+ ((FragmentCommunicator) blockedCommunitiesListingFragment).stopRefreshProgressbar();
+ }
+ if (followedUsersListingFragment != null) {
+ ((FragmentCommunicator) followedUsersListingFragment).stopRefreshProgressbar();
+ }
+ }
+
+
+ void goBackToTop() {
+ if (viewPager.getCurrentItem() == 0) {
+ blockedCommunitiesListingFragment.goBackToTop();
+ } else if (viewPager.getCurrentItem() == 1) {
+ followedUsersListingFragment.goBackToTop();
+ }
+ }
+
+ void changeSearchQuery(String searchQuery) {
+ if (blockedCommunitiesListingFragment != null) {
+ blockedCommunitiesListingFragment.changeSearchQuery(searchQuery);
+ }
+ if (followedUsersListingFragment != null) {
+ followedUsersListingFragment.changeSearchQuery(searchQuery);
+ }
+ }
+ }
+}
+
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java
index 438f5f9d..07c3e9a1 100644
--- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java
@@ -882,6 +882,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
});
} else if (stringId == R.string.anonymous_account_instance) {
changeAnonymousAccountInstance();
+ } else if (stringId == R.string.blocks) {
+ intent = new Intent(MainActivity.this, BlockedThingListingActivity.class);
}
if (intent != null) {
startActivity(intent);
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/SubscribedThingListingActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/SubscribedThingListingActivity.java
index cd3fea7a..337387b5 100644
--- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/SubscribedThingListingActivity.java
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/SubscribedThingListingActivity.java
@@ -73,7 +73,6 @@ import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
import retrofit2.Retrofit;
-;
public class SubscribedThingListingActivity extends BaseActivity implements ActivityToolbarInterface {
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java
index 00b34c12..85cdaf2e 100644
--- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java
@@ -82,6 +82,7 @@ import eu.toldi.infinityforlemmy.bottomsheetfragments.RandomBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.SortTimeBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.SortTypeBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.UrlMenuBottomSheetFragment;
+import eu.toldi.infinityforlemmy.community.BlockCommunity;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.NavigationWrapper;
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
@@ -210,6 +211,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private String communityName;
private int communityId;
+
+ private SubredditData communityData;
private String description;
private String qualifiedName;
@@ -693,6 +696,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
setupVisibleElements();
communityId = communityData.getId();
+ ViewSubredditDetailActivity.this.communityData = communityData;
setupSubscribeChip();
mNCurrentOnlineSubscribers = nCurrentOnlineSubscribers;
@@ -1123,6 +1127,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.view_subreddit_detail_activity, menu);
+ if (communityData != null && communityData.isBlocked()) {
+ menu.findItem(R.id.block_community_view_subreddit_detail_activity).setVisible(false);
+ } else {
+ menu.findItem(R.id.unblock_community_view_subreddit_detail_activity).setVisible(false);
+ }
applyMenuItemTheme(menu);
return true;
}
@@ -1151,15 +1160,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true;
- } else if (itemId == R.id.action_select_user_flair_view_subreddit_detail_activity) {
- if (mAccessToken == null) {
- Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show();
- return true;
- }
- Intent selectUserFlairIntent = new Intent(this, SelectUserFlairActivity.class);
- selectUserFlairIntent.putExtra(SelectUserFlairActivity.EXTRA_SUBREDDIT_NAME, communityName);
- startActivity(selectUserFlairIntent);
- return true;
} else if (itemId == R.id.action_add_to_post_filter_view_subreddit_detail_activity) {
Intent intent = new Intent(this, PostFilterPreferenceActivity.class);
intent.putExtra(PostFilterPreferenceActivity.EXTRA_SUBREDDIT_NAME, communityName);
@@ -1179,7 +1179,39 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
} else if (itemId == R.id.action_contact_mods_view_subreddit_detail_activity) {
Intent intent = new Intent(this, SendPrivateMessageActivity.class);
intent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, "r/" + communityName);
- startActivity(intent);
+ //startActivity(intent);
+ return true;
+ } else if (itemId == R.id.block_community_view_subreddit_detail_activity) {
+ BlockCommunity.INSTANCE.blockCommunity(mRetrofit.getRetrofit(), communityId, mAccessToken, new BlockCommunity.BlockCommunityListener() {
+ @Override
+ public void onBlockCommunitySuccess() {
+ communityData.setBlocked(true);
+ Toast.makeText(ViewSubredditDetailActivity.this, R.string.block_community_success, Toast.LENGTH_SHORT).show();
+ ViewSubredditDetailActivity.this.invalidateOptionsMenu();
+ sectionsPagerAdapter.refresh(false);
+ }
+
+ @Override
+ public void onBlockCommunityError() {
+ Toast.makeText(ViewSubredditDetailActivity.this, R.string.block_community_failed, Toast.LENGTH_SHORT).show();
+ }
+ });
+ return true;
+ } else if (itemId == R.id.unblock_community_view_subreddit_detail_activity) {
+ BlockCommunity.INSTANCE.unBlockCommunity(mRetrofit.getRetrofit(), communityId, mAccessToken, new BlockCommunity.BlockCommunityListener() {
+ @Override
+ public void onBlockCommunitySuccess() {
+ communityData.setBlocked(false);
+ Toast.makeText(ViewSubredditDetailActivity.this, R.string.unblock_community_success, Toast.LENGTH_SHORT).show();
+ ViewSubredditDetailActivity.this.invalidateOptionsMenu();
+ sectionsPagerAdapter.refresh(false);
+ }
+
+ @Override
+ public void onBlockCommunityError() {
+ Toast.makeText(ViewSubredditDetailActivity.this, R.string.unblock_community_failed, Toast.LENGTH_SHORT).show();
+ }
+ });
return true;
}
return false;
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/BlockedCommunitiesRecyclerViewAdapter.java b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/BlockedCommunitiesRecyclerViewAdapter.java
new file mode 100644
index 00000000..3bd71d14
--- /dev/null
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/BlockedCommunitiesRecyclerViewAdapter.java
@@ -0,0 +1,377 @@
+package eu.toldi.infinityforlemmy.adapters;
+
+import android.content.Intent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.RequestManager;
+import com.bumptech.glide.request.RequestOptions;
+
+import java.util.List;
+import java.util.concurrent.Executor;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import eu.toldi.infinityforlemmy.R;
+import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
+import eu.toldi.infinityforlemmy.activities.BaseActivity;
+import eu.toldi.infinityforlemmy.activities.ViewSubredditDetailActivity;
+import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityData;
+import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
+import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
+import me.zhanghai.android.fastscroll.PopupTextProvider;
+import pl.droidsonroids.gif.GifImageView;
+import retrofit2.Retrofit;
+
+public class BlockedCommunitiesRecyclerViewAdapter extends RecyclerView.Adapter implements PopupTextProvider {
+ private static final int VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER = 0;
+ private static final int VIEW_TYPE_FAVORITE_SUBREDDIT = 1;
+ private static final int VIEW_TYPE_SUBREDDIT_DIVIDER = 2;
+ private static final int VIEW_TYPE_SUBREDDIT = 3;
+
+ private BaseActivity mActivity;
+ private Executor mExecutor;
+ private Retrofit mOauthRetrofit;
+ private RedditDataRoomDatabase mRedditDataRoomDatabase;
+ private List mBlockedCommunityData;
+ private List mFavoriteBlockedCommunityData;
+ private RequestManager glide;
+ private ItemClickListener itemClickListener;
+
+ private String accessToken;
+ private String username;
+ private String userIconUrl;
+ private boolean hasClearSelectionRow;
+
+ private int primaryTextColor;
+ private int secondaryTextColor;
+
+ public BlockedCommunitiesRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit,
+ RedditDataRoomDatabase redditDataRoomDatabase,
+ CustomThemeWrapper customThemeWrapper,
+ String accessToken) {
+ mActivity = activity;
+ mExecutor = executor;
+ glide = Glide.with(activity);
+ mOauthRetrofit = oauthRetrofit;
+ mRedditDataRoomDatabase = redditDataRoomDatabase;
+ this.accessToken = accessToken;
+ primaryTextColor = customThemeWrapper.getPrimaryTextColor();
+ secondaryTextColor = customThemeWrapper.getSecondaryTextColor();
+ }
+
+ public BlockedCommunitiesRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit,
+ RedditDataRoomDatabase redditDataRoomDatabase,
+ CustomThemeWrapper customThemeWrapper,
+ String accessToken, boolean hasClearSelectionRow,
+ ItemClickListener itemClickListener) {
+ this(activity, executor, oauthRetrofit, redditDataRoomDatabase, customThemeWrapper, accessToken);
+ this.hasClearSelectionRow = hasClearSelectionRow;
+ this.itemClickListener = itemClickListener;
+ }
+
+ @Override
+ public int getItemViewType(int position) {
+ if (mFavoriteBlockedCommunityData != null && mFavoriteBlockedCommunityData.size() > 0) {
+ if (itemClickListener != null && !hasClearSelectionRow) {
+ if (position == 0) {
+ return VIEW_TYPE_SUBREDDIT;
+ } else if (position == 1) {
+ return VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER;
+ } else if (position == mFavoriteBlockedCommunityData.size() + 2) {
+ return VIEW_TYPE_SUBREDDIT_DIVIDER;
+ } else if (position <= mFavoriteBlockedCommunityData.size() + 1) {
+ return VIEW_TYPE_FAVORITE_SUBREDDIT;
+ } else {
+ return VIEW_TYPE_SUBREDDIT;
+ }
+ } else if (hasClearSelectionRow) {
+ if (position == 0) {
+ return VIEW_TYPE_SUBREDDIT;
+ } else if (position == 1) {
+ return VIEW_TYPE_SUBREDDIT;
+ } else if (position == 2) {
+ return VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER;
+ } else if (position == mFavoriteBlockedCommunityData.size() + 3) {
+ return VIEW_TYPE_SUBREDDIT_DIVIDER;
+ } else if (position <= mFavoriteBlockedCommunityData.size() + 2) {
+ return VIEW_TYPE_FAVORITE_SUBREDDIT;
+ } else {
+ return VIEW_TYPE_SUBREDDIT;
+ }
+ } else {
+ if (position == 0) {
+ return VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER;
+ } else if (position == mFavoriteBlockedCommunityData.size() + 1) {
+ return VIEW_TYPE_SUBREDDIT_DIVIDER;
+ } else if (position <= mFavoriteBlockedCommunityData.size()) {
+ return VIEW_TYPE_FAVORITE_SUBREDDIT;
+ } else {
+ return VIEW_TYPE_SUBREDDIT;
+ }
+ }
+ } else {
+ return VIEW_TYPE_SUBREDDIT;
+ }
+ }
+
+ @NonNull
+ @Override
+ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
+ switch (i) {
+ case VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER:
+ return new FavoriteSubredditsDividerViewHolder(LayoutInflater.from(viewGroup.getContext())
+ .inflate(R.layout.item_favorite_thing_divider, viewGroup, false));
+ case VIEW_TYPE_FAVORITE_SUBREDDIT:
+ return new FavoriteSubredditViewHolder(LayoutInflater.from(viewGroup.getContext())
+ .inflate(R.layout.item_subscribed_thing, viewGroup, false));
+ case VIEW_TYPE_SUBREDDIT_DIVIDER:
+ return new AllSubredditsDividerViewHolder(LayoutInflater.from(viewGroup.getContext())
+ .inflate(R.layout.item_favorite_thing_divider, viewGroup, false));
+ default:
+ return new SubredditViewHolder(LayoutInflater.from(viewGroup.getContext())
+ .inflate(R.layout.item_subscribed_thing, viewGroup, false));
+ }
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int i) {
+ if (viewHolder instanceof SubredditViewHolder) {
+ String name;
+ String fullname = "";
+ String iconUrl;
+
+ if (hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 0) {
+ ((SubredditViewHolder) viewHolder).subredditNameTextView.setText(R.string.all_communities);
+ viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(null));
+ return;
+ } else {
+ int offset = hasClearSelectionRow ? 1 : 0;
+ BlockedCommunityData communityData = mBlockedCommunityData.get(viewHolder.getBindingAdapterPosition() - offset);
+ name = mBlockedCommunityData.get(viewHolder.getBindingAdapterPosition() - offset).getName();
+ fullname = mBlockedCommunityData.get(viewHolder.getBindingAdapterPosition() - offset).getQualified_name();
+ iconUrl = mBlockedCommunityData.get(viewHolder.getBindingAdapterPosition() - offset).getIconUrl();
+
+ if (itemClickListener != null) {
+ viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(communityData));
+ }
+ }
+
+ if (itemClickListener == null) {
+ String finalFullname = fullname;
+ viewHolder.itemView.setOnClickListener(view -> {
+ Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class);
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, name);
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY,
+ finalFullname);
+ mActivity.startActivity(intent);
+ });
+ }
+
+ if (iconUrl != null && !iconUrl.equals("")) {
+ glide.load(iconUrl)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .error(glide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
+ .into(((SubredditViewHolder) viewHolder).iconGifImageView);
+ } else {
+ glide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .into(((SubredditViewHolder) viewHolder).iconGifImageView);
+ }
+ ((SubredditViewHolder) viewHolder).subredditNameTextView.setText(name);
+ } else if (viewHolder instanceof FavoriteSubredditViewHolder) {
+ int offset;
+ if (itemClickListener != null) {
+ if (hasClearSelectionRow) {
+ offset = 3;
+ } else {
+ offset = 2;
+ }
+ } else {
+ offset = 1;
+ }
+ BlockedCommunityData communityData = mFavoriteBlockedCommunityData.get(viewHolder.getBindingAdapterPosition() - offset);
+ String name = mFavoriteBlockedCommunityData.get(viewHolder.getBindingAdapterPosition() - offset).getName();
+ String iconUrl = mFavoriteBlockedCommunityData.get(viewHolder.getBindingAdapterPosition() - offset).getIconUrl();
+
+ if (itemClickListener != null) {
+ viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(communityData));
+ } else {
+ viewHolder.itemView.setOnClickListener(view -> {
+ Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class);
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, name);
+ mActivity.startActivity(intent);
+ });
+ }
+
+ if (iconUrl != null && !iconUrl.equals("")) {
+ glide.load(iconUrl)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .error(glide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
+ .into(((FavoriteSubredditViewHolder) viewHolder).iconGifImageView);
+ } else {
+ glide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .into(((FavoriteSubredditViewHolder) viewHolder).iconGifImageView);
+ }
+ ((FavoriteSubredditViewHolder) viewHolder).subredditNameTextView.setText(name);
+ }
+ }
+
+ @Override
+ public int getItemCount() {
+ if (mBlockedCommunityData != null) {
+
+ if (itemClickListener != null) {
+ return mBlockedCommunityData.size() > 0 ? mBlockedCommunityData.size() + ((hasClearSelectionRow) ? 1 : 0) : 0;
+ }
+
+ return mBlockedCommunityData.size();
+ }
+ return 0;
+ }
+
+ @Override
+ public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
+ if (holder instanceof SubredditViewHolder) {
+ glide.clear(((SubredditViewHolder) holder).iconGifImageView);
+ } else if (holder instanceof FavoriteSubredditViewHolder) {
+ glide.clear(((FavoriteSubredditViewHolder) holder).iconGifImageView);
+ }
+ }
+
+ public void setSubscribedSubreddits(List subscribedSubreddits) {
+ mBlockedCommunityData = subscribedSubreddits;
+ notifyDataSetChanged();
+ }
+
+ public void setFavoriteSubscribedSubreddits(List favoriteBlockedCommunityData) {
+ mFavoriteBlockedCommunityData = favoriteBlockedCommunityData;
+ notifyDataSetChanged();
+ }
+
+ public void addUser(String username, String userIconUrl) {
+ this.username = username;
+ this.userIconUrl = userIconUrl;
+ }
+
+ @NonNull
+ @Override
+ public String getPopupText(int position) {
+ switch (getItemViewType(position)) {
+ case VIEW_TYPE_SUBREDDIT:
+ if (hasClearSelectionRow && position == 0) {
+ return "";
+ } else if (itemClickListener != null && !hasClearSelectionRow && position == 0) {
+ return "";
+ } else if (hasClearSelectionRow && position == 1) {
+ return "";
+ } else {
+ int offset;
+ if (itemClickListener != null) {
+ if (hasClearSelectionRow) {
+ offset = (mFavoriteBlockedCommunityData != null && mFavoriteBlockedCommunityData.size() > 0) ?
+ mFavoriteBlockedCommunityData.size() + 4 : 0;
+ } else {
+ offset = (mFavoriteBlockedCommunityData != null && mFavoriteBlockedCommunityData.size() > 0) ?
+ mFavoriteBlockedCommunityData.size() + 3 : 0;
+ }
+ } else {
+ offset = (mFavoriteBlockedCommunityData != null && mFavoriteBlockedCommunityData.size() > 0) ?
+ mFavoriteBlockedCommunityData.size() + 2 : 0;
+ }
+
+ return mBlockedCommunityData.get(position - offset).getName().substring(0, 1).toUpperCase();
+ }
+ case VIEW_TYPE_FAVORITE_SUBREDDIT:
+ int offset;
+ if (itemClickListener != null) {
+ if (hasClearSelectionRow) {
+ offset = 3;
+ } else {
+ offset = 2;
+ }
+ } else {
+ offset = 1;
+ }
+ return mFavoriteBlockedCommunityData.get(position - offset).getName().substring(0, 1).toUpperCase();
+ default:
+ return "";
+ }
+ }
+
+ public interface ItemClickListener {
+ void onClick(BlockedCommunityData subredditData);
+ }
+
+ class SubredditViewHolder extends RecyclerView.ViewHolder {
+ @BindView(R.id.thing_icon_gif_image_view_item_subscribed_thing)
+ GifImageView iconGifImageView;
+ @BindView(R.id.thing_name_text_view_item_subscribed_thing)
+ TextView subredditNameTextView;
+
+ SubredditViewHolder(View itemView) {
+ super(itemView);
+ ButterKnife.bind(this, itemView);
+ if (mActivity.typeface != null) {
+ subredditNameTextView.setTypeface(mActivity.typeface);
+ }
+ subredditNameTextView.setTextColor(primaryTextColor);
+ }
+ }
+
+ class FavoriteSubredditViewHolder extends RecyclerView.ViewHolder {
+ @BindView(R.id.thing_icon_gif_image_view_item_subscribed_thing)
+ GifImageView iconGifImageView;
+ @BindView(R.id.thing_name_text_view_item_subscribed_thing)
+ TextView subredditNameTextView;
+
+ FavoriteSubredditViewHolder(View itemView) {
+ super(itemView);
+ ButterKnife.bind(this, itemView);
+ if (mActivity.typeface != null) {
+ subredditNameTextView.setTypeface(mActivity.typeface);
+ }
+ subredditNameTextView.setTextColor(primaryTextColor);
+ }
+ }
+
+ class FavoriteSubredditsDividerViewHolder extends RecyclerView.ViewHolder {
+ @BindView(R.id.divider_text_view_item_favorite_thing_divider)
+ TextView dividerTextView;
+
+ FavoriteSubredditsDividerViewHolder(@NonNull View itemView) {
+ super(itemView);
+ ButterKnife.bind(this, itemView);
+ if (mActivity.typeface != null) {
+ dividerTextView.setTypeface(mActivity.typeface);
+ }
+ dividerTextView.setText(R.string.favorites);
+ dividerTextView.setTextColor(secondaryTextColor);
+ }
+ }
+
+ class AllSubredditsDividerViewHolder extends RecyclerView.ViewHolder {
+ @BindView(R.id.divider_text_view_item_favorite_thing_divider)
+ TextView dividerTextView;
+
+ AllSubredditsDividerViewHolder(@NonNull View itemView) {
+ super(itemView);
+ ButterKnife.bind(this, itemView);
+ if (mActivity.typeface != null) {
+ dividerTextView.setTypeface(mActivity.typeface);
+ }
+ dividerTextView.setText(R.string.all);
+ dividerTextView.setTextColor(secondaryTextColor);
+ }
+ }
+}
+
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/BlockedUsersRecyclerViewAdapter.java b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/BlockedUsersRecyclerViewAdapter.java
new file mode 100644
index 00000000..91e4f193
--- /dev/null
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/BlockedUsersRecyclerViewAdapter.java
@@ -0,0 +1,216 @@
+package eu.toldi.infinityforlemmy.adapters;
+
+import android.content.Intent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.RequestManager;
+import com.bumptech.glide.request.RequestOptions;
+
+import java.util.List;
+import java.util.concurrent.Executor;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import eu.toldi.infinityforlemmy.R;
+import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
+import eu.toldi.infinityforlemmy.activities.BaseActivity;
+import eu.toldi.infinityforlemmy.activities.ViewUserDetailActivity;
+import eu.toldi.infinityforlemmy.blockeduser.BlockedUserData;
+import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
+import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
+import me.zhanghai.android.fastscroll.PopupTextProvider;
+import pl.droidsonroids.gif.GifImageView;
+import retrofit2.Retrofit;
+
+public class BlockedUsersRecyclerViewAdapter extends RecyclerView.Adapter implements PopupTextProvider {
+ private static final int VIEW_TYPE_FAVORITE_USER_DIVIDER = 0;
+ private static final int VIEW_TYPE_FAVORITE_USER = 1;
+ private static final int VIEW_TYPE_USER_DIVIDER = 2;
+ private static final int VIEW_TYPE_USER = 3;
+
+ private List mBlockedUserData;
+ private List mFavoriteBlockedUserData;
+ private BaseActivity mActivity;
+ private Executor mExecutor;
+ private Retrofit mOauthRetrofit;
+ private RedditDataRoomDatabase mRedditDataRoomDatabase;
+ private String mAccessToken;
+ private RequestManager glide;
+ private int mPrimaryTextColor;
+ private int mSecondaryTextColor;
+
+ public BlockedUsersRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit,
+ RedditDataRoomDatabase redditDataRoomDatabase,
+ CustomThemeWrapper customThemeWrapper,
+ String accessToken) {
+ mActivity = activity;
+ mExecutor = executor;
+ mOauthRetrofit = oauthRetrofit;
+ mRedditDataRoomDatabase = redditDataRoomDatabase;
+ mAccessToken = accessToken;
+ glide = Glide.with(activity);
+ mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor();
+ mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
+ }
+
+ @Override
+ public int getItemViewType(int position) {
+ if (mFavoriteBlockedUserData != null && mFavoriteBlockedUserData.size() > 0) {
+ if (position == 0) {
+ return VIEW_TYPE_FAVORITE_USER_DIVIDER;
+ } else if (position == mFavoriteBlockedUserData.size() + 1) {
+ return VIEW_TYPE_USER_DIVIDER;
+ } else if (position <= mFavoriteBlockedUserData.size()) {
+ return VIEW_TYPE_FAVORITE_USER;
+ } else {
+ return VIEW_TYPE_USER;
+ }
+ } else {
+ return VIEW_TYPE_USER;
+ }
+ }
+
+ @NonNull
+ @Override
+ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
+ switch (i) {
+ case VIEW_TYPE_FAVORITE_USER_DIVIDER:
+ return new FavoriteUsersDividerViewHolder(LayoutInflater.from(viewGroup.getContext())
+ .inflate(R.layout.item_favorite_thing_divider, viewGroup, false));
+ case VIEW_TYPE_USER_DIVIDER:
+ return new AllUsersDividerViewHolder(LayoutInflater.from(viewGroup.getContext())
+ .inflate(R.layout.item_favorite_thing_divider, viewGroup, false));
+ default:
+ return new UserViewHolder(LayoutInflater.from(viewGroup.getContext())
+ .inflate(R.layout.item_subscribed_thing, viewGroup, false));
+ }
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int i) {
+ if (viewHolder instanceof UserViewHolder) {
+ int offset = 0;
+
+ if (!mBlockedUserData.get(viewHolder.getBindingAdapterPosition() - offset).getAvatar().equals("")) {
+ glide.load(mBlockedUserData.get(viewHolder.getBindingAdapterPosition() - offset).getAvatar())
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .error(glide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
+ .into(((UserViewHolder) viewHolder).iconGifImageView);
+ } else {
+ glide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .into(((UserViewHolder) viewHolder).iconGifImageView);
+ }
+ ((UserViewHolder) viewHolder).userNameTextView.setText(mBlockedUserData.get(viewHolder.getBindingAdapterPosition() - offset).getName());
+
+ }
+ }
+
+ @Override
+ public int getItemCount() {
+ if (mBlockedUserData != null && mBlockedUserData.size() > 0) {
+ return mBlockedUserData.size();
+ }
+ return 0;
+ }
+
+ @Override
+ public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
+ if (holder instanceof UserViewHolder) {
+ glide.clear(((UserViewHolder) holder).iconGifImageView);
+ }
+ }
+
+ public void setSubscribedUsers(List subscribedUsers) {
+ mBlockedUserData = subscribedUsers;
+ notifyDataSetChanged();
+ }
+
+ public void setFavoriteSubscribedUsers(List favoriteSubscribedUsers) {
+ mFavoriteBlockedUserData = favoriteSubscribedUsers;
+ notifyDataSetChanged();
+ }
+
+ @NonNull
+ @Override
+ public String getPopupText(int position) {
+ switch (getItemViewType(position)) {
+ case VIEW_TYPE_USER:
+ int offset = (mFavoriteBlockedUserData != null && mFavoriteBlockedUserData.size() > 0) ?
+ mFavoriteBlockedUserData.size() + 2 : 0;
+ return mBlockedUserData.get(position - offset).getName().substring(0, 1).toUpperCase();
+ case VIEW_TYPE_FAVORITE_USER:
+ return mFavoriteBlockedUserData.get(position - 1).getName().substring(0, 1).toUpperCase();
+ default:
+ return "";
+ }
+ }
+
+
+ class UserViewHolder extends RecyclerView.ViewHolder {
+ @BindView(R.id.thing_icon_gif_image_view_item_subscribed_thing)
+ GifImageView iconGifImageView;
+ @BindView(R.id.thing_name_text_view_item_subscribed_thing)
+ TextView userNameTextView;
+
+ UserViewHolder(View itemView) {
+ super(itemView);
+ ButterKnife.bind(this, itemView);
+ if (mActivity.typeface != null) {
+ userNameTextView.setTypeface(mActivity.typeface);
+ }
+ userNameTextView.setTextColor(mPrimaryTextColor);
+
+ itemView.setOnClickListener(view -> {
+ int offset = (mFavoriteBlockedUserData != null && mFavoriteBlockedUserData.size() > 0) ?
+ mFavoriteBlockedUserData.size() + 2 : 0;
+ int position = getBindingAdapterPosition() - offset;
+ if (position >= 0 && mBlockedUserData.size() > position) {
+ Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
+ intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mBlockedUserData.get(position).getName());
+ intent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, mBlockedUserData.get(position).getQualifiedName());
+ mActivity.startActivity(intent);
+ }
+ });
+
+ }
+ }
+
+ class FavoriteUsersDividerViewHolder extends RecyclerView.ViewHolder {
+ @BindView(R.id.divider_text_view_item_favorite_thing_divider)
+ TextView dividerTextView;
+
+ FavoriteUsersDividerViewHolder(@NonNull View itemView) {
+ super(itemView);
+ ButterKnife.bind(this, itemView);
+ if (mActivity.typeface != null) {
+ dividerTextView.setTypeface(mActivity.typeface);
+ }
+ dividerTextView.setText(R.string.favorites);
+ dividerTextView.setTextColor(mSecondaryTextColor);
+ }
+ }
+
+ class AllUsersDividerViewHolder extends RecyclerView.ViewHolder {
+ @BindView(R.id.divider_text_view_item_favorite_thing_divider)
+ TextView dividerTextView;
+
+ AllUsersDividerViewHolder(@NonNull View itemView) {
+ super(itemView);
+ ButterKnife.bind(this, itemView);
+ if (mActivity.typeface != null) {
+ dividerTextView.setTypeface(mActivity.typeface);
+ }
+ dividerTextView.setText(R.string.all);
+ dividerTextView.setTextColor(mSecondaryTextColor);
+ }
+ }
+}
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/navigationdrawer/AccountSectionRecyclerViewAdapter.java b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/navigationdrawer/AccountSectionRecyclerViewAdapter.java
index e0b44dba..7d3a6516 100644
--- a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/navigationdrawer/AccountSectionRecyclerViewAdapter.java
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/navigationdrawer/AccountSectionRecyclerViewAdapter.java
@@ -25,7 +25,7 @@ public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter {
+public class LemmySectionRecyclerViewAdapter extends RecyclerView.Adapter {
private static final int VIEW_TYPE_MENU_GROUP_TITLE = 1;
private static final int VIEW_TYPE_MENU_ITEM = 2;
- private static final int REDDIT_SECTION_ITEMS = 1;
+ private static final int LEMMY_SECTION_ITEMS = 2;
- private static final int REDDIT_SECTION_ANONYMOUS_ITEMS = 2;
+ private static final int LEMMY_SECTION_ANONYMOUS_ITEMS = 1;
private final boolean isLoggedIn;
private BaseActivity baseActivity;
@@ -34,9 +34,9 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter {
if (collapseRedditSection) {
collapseRedditSection = !collapseRedditSection;
- notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, REDDIT_SECTION_ITEMS);
+ notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, isLoggedIn ? LEMMY_SECTION_ITEMS : LEMMY_SECTION_ANONYMOUS_ITEMS);
} else {
collapseRedditSection = !collapseRedditSection;
- notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, REDDIT_SECTION_ITEMS);
+ notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, isLoggedIn ? LEMMY_SECTION_ITEMS : LEMMY_SECTION_ANONYMOUS_ITEMS);
}
notifyItemChanged(holder.getBindingAdapterPosition());
});
@@ -89,12 +89,13 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter communityFollow(@Body FollowCommunityDTO params);
+ @Headers("Content-Type: application/json")
+ @POST("api/v3/community/block")
+ Call communityBlock(@Body BlockCommunityDTO params);
+
@Headers("Content-Type: application/json")
@PUT("api/v3/post/save")
Call postSave(@Body SavePostDTO params);
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/asynctasks/InsertBlockedThings.java b/app/src/main/java/eu/toldi/infinityforlemmy/asynctasks/InsertBlockedThings.java
new file mode 100644
index 00000000..1b40e949
--- /dev/null
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/asynctasks/InsertBlockedThings.java
@@ -0,0 +1,130 @@
+package eu.toldi.infinityforlemmy.asynctasks;
+
+import android.os.Handler;
+
+import androidx.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Executor;
+
+import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
+import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityDao;
+import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityData;
+import eu.toldi.infinityforlemmy.blockeduser.BlockedUserDao;
+import eu.toldi.infinityforlemmy.blockeduser.BlockedUserData;
+
+
+public class InsertBlockedThings {
+
+ public static void insertBlockedThings(Executor executor, Handler handler,
+ RedditDataRoomDatabase redditDataRoomDatabase, @Nullable String accountName,
+ List blockedCommunityDataList,
+ List blockedUserDataDataList,
+
+ InsertBlockedThingListener insertSubscribedThingListener) {
+ executor.execute(() -> {
+ if (accountName != null && redditDataRoomDatabase.accountDao().getAccountData(accountName) == null) {
+ handler.post(insertSubscribedThingListener::insertSuccess);
+ return;
+ }
+
+ BlockedUserDao blockedUserDao = redditDataRoomDatabase.blockedUserDao();
+ BlockedCommunityDao blockedCommunityDao = redditDataRoomDatabase.blockedCommunityDao();
+
+
+ if (blockedCommunityDataList != null) {
+ List existingBlockedCommunityDaoList =
+ blockedCommunityDao.getAllBlockedCommunitiesList(accountName);
+ Collections.sort(blockedCommunityDataList, (subscribedSubredditData, t1) -> subscribedSubredditData.getName().compareToIgnoreCase(t1.getName()));
+ List unsubscribedSubreddits = new ArrayList<>();
+ compareTwoSubscribedSubredditList(blockedCommunityDataList, existingBlockedCommunityDaoList,
+ unsubscribedSubreddits);
+
+ for (String unsubscribed : unsubscribedSubreddits) {
+ blockedCommunityDao.deleteBlockedCommunity(unsubscribed, accountName);
+ }
+
+ for (BlockedCommunityData s : blockedCommunityDataList) {
+ blockedCommunityDao.insert(s);
+ }
+ }
+
+ if (blockedUserDataDataList != null) {
+ List existingBlockedUserDataList =
+ blockedUserDao.getAllBlockedUsersList(accountName);
+ Collections.sort(blockedUserDataDataList, (subscribedUserData, t1) -> subscribedUserData.getName().compareToIgnoreCase(t1.getName()));
+ List unsubscribedUsers = new ArrayList<>();
+ compareTwoSubscribedUserList(blockedUserDataDataList, existingBlockedUserDataList,
+ unsubscribedUsers);
+
+ for (String unsubscribed : unsubscribedUsers) {
+ blockedUserDao.deleteBlockedUser(unsubscribed, accountName);
+ }
+
+ for (BlockedUserData s : blockedUserDataDataList) {
+ blockedUserDao.insert(s);
+ }
+ }
+
+ handler.post(insertSubscribedThingListener::insertSuccess);
+ });
+ }
+
+ private static void compareTwoSubscribedSubredditList(List newSubscribedSubreddits,
+ List oldSubscribedSubreddits,
+ List unsubscribedSubredditNames) {
+ int newIndex = 0;
+ for (int oldIndex = 0; oldIndex < oldSubscribedSubreddits.size(); oldIndex++) {
+ if (newIndex >= newSubscribedSubreddits.size()) {
+ for (; oldIndex < oldSubscribedSubreddits.size(); oldIndex++) {
+ unsubscribedSubredditNames.add(oldSubscribedSubreddits.get(oldIndex).getName());
+ }
+ return;
+ }
+
+ BlockedCommunityData old = oldSubscribedSubreddits.get(oldIndex);
+ for (; newIndex < newSubscribedSubreddits.size(); newIndex++) {
+ if (newSubscribedSubreddits.get(newIndex).getName().compareToIgnoreCase(old.getName()) == 0) {
+ newIndex++;
+ break;
+ }
+ if (newSubscribedSubreddits.get(newIndex).getName().compareToIgnoreCase(old.getName()) > 0) {
+ unsubscribedSubredditNames.add(old.getName());
+ break;
+ }
+ }
+ }
+ }
+
+ private static void compareTwoSubscribedUserList(List newSubscribedUsers,
+ List oldSubscribedUsers,
+ List unsubscribedUserNames) {
+ int newIndex = 0;
+ for (int oldIndex = 0; oldIndex < oldSubscribedUsers.size(); oldIndex++) {
+ if (newIndex >= newSubscribedUsers.size()) {
+ for (; oldIndex < oldSubscribedUsers.size(); oldIndex++) {
+ unsubscribedUserNames.add(oldSubscribedUsers.get(oldIndex).getQualifiedName());
+ }
+ return;
+ }
+
+ BlockedUserData old = oldSubscribedUsers.get(oldIndex);
+ for (; newIndex < newSubscribedUsers.size(); newIndex++) {
+ if (newSubscribedUsers.get(newIndex).getName().compareToIgnoreCase(old.getName()) == 0) {
+ newIndex++;
+ break;
+ }
+ if (newSubscribedUsers.get(newIndex).getName().compareToIgnoreCase(old.getName()) > 0) {
+ unsubscribedUserNames.add(old.getQualifiedName());
+ break;
+ }
+ }
+ }
+ }
+
+ public interface InsertBlockedThingListener {
+ void insertSuccess();
+ }
+}
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/blockedcommunity/BlockedCommunityDao.java b/app/src/main/java/eu/toldi/infinityforlemmy/blockedcommunity/BlockedCommunityDao.java
new file mode 100644
index 00000000..a0845133
--- /dev/null
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/blockedcommunity/BlockedCommunityDao.java
@@ -0,0 +1,30 @@
+package eu.toldi.infinityforlemmy.blockedcommunity;
+
+import androidx.lifecycle.LiveData;
+import androidx.room.Dao;
+import androidx.room.Insert;
+import androidx.room.OnConflictStrategy;
+import androidx.room.Query;
+
+import java.util.List;
+
+@Dao
+public interface BlockedCommunityDao {
+ @Insert(onConflict = OnConflictStrategy.REPLACE)
+ void insert(BlockedCommunityData communityData);
+
+ @Insert(onConflict = OnConflictStrategy.REPLACE)
+ void insertAll(List blockedCommunityDataList);
+
+ @Query("SELECT * FROM blocked_communities WHERE account_name = :accountName AND name LIKE '%' || :searchQuery || '%' COLLATE NOCASE ORDER BY name COLLATE NOCASE ASC")
+ LiveData> getAllBlockedCommunitiesWithSearchQuery(String accountName, String searchQuery);
+
+ @Query("SELECT * FROM blocked_communities WHERE account_name = :accountName COLLATE NOCASE ORDER BY name COLLATE NOCASE ASC")
+ List getAllBlockedCommunitiesList(String accountName);
+
+ @Query("SELECT * FROM blocked_communities WHERE name = :name COLLATE NOCASE AND account_name = :accountName COLLATE NOCASE LIMIT 1")
+ BlockedCommunityData getBlockedCommunity(String name, String accountName);
+
+ @Query("DELETE FROM blocked_communities WHERE name = :name COLLATE NOCASE AND account_name = :accountName COLLATE NOCASE")
+ void deleteBlockedCommunity(String name, String accountName);
+}
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/blockedcommunity/BlockedCommunityData.java b/app/src/main/java/eu/toldi/infinityforlemmy/blockedcommunity/BlockedCommunityData.java
new file mode 100644
index 00000000..316e819b
--- /dev/null
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/blockedcommunity/BlockedCommunityData.java
@@ -0,0 +1,80 @@
+package eu.toldi.infinityforlemmy.blockedcommunity;
+
+import androidx.annotation.NonNull;
+import androidx.room.ColumnInfo;
+import androidx.room.Entity;
+
+import eu.toldi.infinityforlemmy.subreddit.SubredditData;
+import eu.toldi.infinityforlemmy.utils.LemmyUtils;
+
+@Entity(tableName = "blocked_communities", primaryKeys = {"id", "account_name"})
+public class BlockedCommunityData {
+
+ @ColumnInfo(name = "id")
+ private final int id;
+
+ @ColumnInfo(name = "name")
+ private String name;
+
+ @ColumnInfo(name = "qualified_name")
+ private String qualified_name;
+ @ColumnInfo(name = "icon")
+ private String iconUrl;
+
+ @NonNull
+ @ColumnInfo(name = "account_name")
+ private String accountName;
+
+ public BlockedCommunityData(int id, String name, String qualified_name, String iconUrl, @NonNull String accountName) {
+ this.id = id;
+ this.name = name;
+ this.qualified_name = qualified_name;
+ this.iconUrl = iconUrl;
+ this.accountName = accountName;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getQualified_name() {
+ return qualified_name;
+ }
+
+ public String getIconUrl() {
+ return iconUrl;
+ }
+
+ @NonNull
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setQualified_name(String qualified_name) {
+ this.qualified_name = qualified_name;
+ }
+
+ public void setIconUrl(String iconUrl) {
+ this.iconUrl = iconUrl;
+ }
+
+ public void setAccountName(@NonNull String accountName) {
+ this.accountName = accountName;
+ }
+
+ public BlockedCommunityData(SubredditData subredditData, @NonNull String accountName) {
+ this.id = subredditData.getId();
+ this.name = subredditData.getName();
+ this.qualified_name = LemmyUtils.actorID2FullName(subredditData.getActorId());
+ this.iconUrl = subredditData.getIconUrl();
+ this.accountName = accountName;
+ }
+}
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/blockedcommunity/BlockedCommunityRepository.java b/app/src/main/java/eu/toldi/infinityforlemmy/blockedcommunity/BlockedCommunityRepository.java
new file mode 100644
index 00000000..9a72e0ac
--- /dev/null
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/blockedcommunity/BlockedCommunityRepository.java
@@ -0,0 +1,42 @@
+package eu.toldi.infinityforlemmy.blockedcommunity;
+
+import android.os.AsyncTask;
+
+import androidx.lifecycle.LiveData;
+
+import java.util.List;
+
+import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
+
+public class BlockedCommunityRepository {
+ private BlockedCommunityDao blockedCommunityDao;
+ private String mAccountName;
+
+ BlockedCommunityRepository(RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
+ mAccountName = accountName;
+ blockedCommunityDao = redditDataRoomDatabase.blockedCommunityDao();
+ }
+
+ LiveData> getAllSubscribedSubredditsWithSearchQuery(String searchQuery) {
+ return blockedCommunityDao.getAllBlockedCommunitiesWithSearchQuery(mAccountName, searchQuery);
+ }
+
+ public void insert(BlockedCommunityData subscribedSubredditData) {
+ new insertAsyncTask(blockedCommunityDao).execute(subscribedSubredditData);
+ }
+
+ private static class insertAsyncTask extends AsyncTask {
+
+ private BlockedCommunityDao mAsyncTaskDao;
+
+ insertAsyncTask(BlockedCommunityDao dao) {
+ mAsyncTaskDao = dao;
+ }
+
+ @Override
+ protected Void doInBackground(final BlockedCommunityData... params) {
+ mAsyncTaskDao.insert(params[0]);
+ return null;
+ }
+ }
+}
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/blockedcommunity/BlockedCommunityViewModel.java b/app/src/main/java/eu/toldi/infinityforlemmy/blockedcommunity/BlockedCommunityViewModel.java
new file mode 100644
index 00000000..8fe4b86d
--- /dev/null
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/blockedcommunity/BlockedCommunityViewModel.java
@@ -0,0 +1,60 @@
+package eu.toldi.infinityforlemmy.blockedcommunity;
+
+import android.app.Application;
+
+import androidx.annotation.NonNull;
+import androidx.lifecycle.AndroidViewModel;
+import androidx.lifecycle.LiveData;
+import androidx.lifecycle.MutableLiveData;
+import androidx.lifecycle.Transformations;
+import androidx.lifecycle.ViewModel;
+import androidx.lifecycle.ViewModelProvider;
+
+import java.util.List;
+
+import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
+
+public class BlockedCommunityViewModel extends AndroidViewModel {
+ private BlockedCommunityRepository blockedCommunityRepository;
+ private LiveData> mAllBlockedCommunities;
+ private MutableLiveData searchQueryLiveData;
+
+ public BlockedCommunityViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
+ super(application);
+ blockedCommunityRepository = new BlockedCommunityRepository(redditDataRoomDatabase, accountName);
+ searchQueryLiveData = new MutableLiveData<>();
+ searchQueryLiveData.postValue("");
+
+ mAllBlockedCommunities = Transformations.switchMap(searchQueryLiveData, searchQuery -> blockedCommunityRepository.getAllSubscribedSubredditsWithSearchQuery(searchQuery));
+ }
+
+ public LiveData> getAllBlockedCommunities() {
+ return mAllBlockedCommunities;
+ }
+
+ public void insert(BlockedCommunityData subscribedSubredditData) {
+ blockedCommunityRepository.insert(subscribedSubredditData);
+ }
+
+ public void setSearchQuery(String searchQuery) {
+ searchQueryLiveData.postValue(searchQuery);
+ }
+
+ public static class Factory extends ViewModelProvider.NewInstanceFactory {
+ private Application mApplication;
+ private RedditDataRoomDatabase mRedditDataRoomDatabase;
+ private String mAccountName;
+
+ public Factory(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
+ this.mApplication = application;
+ this.mRedditDataRoomDatabase = redditDataRoomDatabase;
+ this.mAccountName = accountName;
+ }
+
+ @NonNull
+ @Override
+ public T create(@NonNull Class modelClass) {
+ return (T) new BlockedCommunityViewModel(mApplication, mRedditDataRoomDatabase, mAccountName);
+ }
+ }
+}
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/blockeduser/BlockedUserDao.java b/app/src/main/java/eu/toldi/infinityforlemmy/blockeduser/BlockedUserDao.java
new file mode 100644
index 00000000..bdb6d478
--- /dev/null
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/blockeduser/BlockedUserDao.java
@@ -0,0 +1,31 @@
+package eu.toldi.infinityforlemmy.blockeduser;
+
+import androidx.lifecycle.LiveData;
+import androidx.room.Dao;
+import androidx.room.Insert;
+import androidx.room.OnConflictStrategy;
+import androidx.room.Query;
+
+import java.util.List;
+
+@Dao
+public interface BlockedUserDao {
+
+ @Insert(onConflict = OnConflictStrategy.REPLACE)
+ void insert(BlockedUserData userData);
+
+ @Insert(onConflict = OnConflictStrategy.REPLACE)
+ void insertAll(List blockedUserDataDataList);
+
+ @Query("SELECT * FROM blocked_users WHERE account_name = :accountName AND name LIKE '%' || :searchQuery || '%' COLLATE NOCASE ORDER BY name COLLATE NOCASE ASC")
+ LiveData> getAllBlockedUsersWithSearchQuery(String accountName, String searchQuery);
+
+ @Query("SELECT * FROM blocked_users WHERE account_name = :accountName COLLATE NOCASE ORDER BY name COLLATE NOCASE ASC")
+ List getAllBlockedUsersList(String accountName);
+
+ @Query("SELECT * FROM blocked_users WHERE name = :name COLLATE NOCASE AND account_name = :accountName COLLATE NOCASE LIMIT 1")
+ BlockedUserData getBlockedUser(String name, String accountName);
+
+ @Query("DELETE FROM blocked_users WHERE name = :name COLLATE NOCASE AND account_name = :accountName COLLATE NOCASE")
+ void deleteBlockedUser(String name, String accountName);
+}
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/blockeduser/BlockedUserData.java b/app/src/main/java/eu/toldi/infinityforlemmy/blockeduser/BlockedUserData.java
new file mode 100644
index 00000000..3eaac145
--- /dev/null
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/blockeduser/BlockedUserData.java
@@ -0,0 +1,80 @@
+package eu.toldi.infinityforlemmy.blockeduser;
+
+import androidx.annotation.NonNull;
+import androidx.room.ColumnInfo;
+import androidx.room.Entity;
+
+import eu.toldi.infinityforlemmy.user.UserData;
+import eu.toldi.infinityforlemmy.utils.LemmyUtils;
+
+@Entity(tableName = "blocked_users", primaryKeys = {"id", "account_name"})
+public class BlockedUserData {
+
+ @ColumnInfo(name = "id")
+ private final int id;
+
+ @ColumnInfo(name = "name")
+ private String name;
+
+ @ColumnInfo(name = "avatar")
+ private String avatar;
+
+ @ColumnInfo(name = "qualified_name")
+ private String qualifiedName;
+
+ @NonNull
+ @ColumnInfo(name = "account_name")
+ private String accountName;
+
+ public BlockedUserData(int id, String name, String avatar, String qualifiedName, String accountName) {
+ this.id = id;
+ this.name = name;
+ this.avatar = avatar;
+ this.qualifiedName = qualifiedName;
+ this.accountName = accountName;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getAvatar() {
+ return avatar;
+ }
+
+ public void setAvatar(String avatar) {
+ this.avatar = avatar;
+ }
+
+ public String getQualifiedName() {
+ return qualifiedName;
+ }
+
+ public void setQualifiedName(String qualifiedName) {
+ this.qualifiedName = qualifiedName;
+ }
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public void setAccountName(String accountName) {
+ this.accountName = accountName;
+ }
+
+ public BlockedUserData(UserData userData, @NonNull String accountName) {
+ this.id = userData.getId();
+ this.name = userData.getName();
+ this.avatar = userData.getAvatar();
+ this.qualifiedName = LemmyUtils.actorID2FullName(userData.getActorId());
+ this.accountName = accountName;
+ }
+}
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/blockeduser/BlockedUserRepository.java b/app/src/main/java/eu/toldi/infinityforlemmy/blockeduser/BlockedUserRepository.java
new file mode 100644
index 00000000..0d6dbbaf
--- /dev/null
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/blockeduser/BlockedUserRepository.java
@@ -0,0 +1,47 @@
+package eu.toldi.infinityforlemmy.blockeduser;
+
+import android.os.AsyncTask;
+
+import androidx.lifecycle.LiveData;
+
+import java.util.List;
+
+import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
+
+public class BlockedUserRepository {
+
+ private BlockedUserDao mBlockedUserDao;
+ private String mAccountName;
+
+ BlockedUserRepository(RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
+ mBlockedUserDao = redditDataRoomDatabase.blockedUserDao();
+ mAccountName = accountName;
+ }
+
+ LiveData> getAllBlockedUsersWithSearchQuery(String searchQuery) {
+ return mBlockedUserDao.getAllBlockedUsersWithSearchQuery(mAccountName, searchQuery);
+ }
+
+ LiveData> getAllFavoriteSubscribedUsersWithSearchQuery(String searchQuery) {
+ return mBlockedUserDao.getAllBlockedUsersWithSearchQuery(mAccountName, searchQuery);
+ }
+
+ public void insert(BlockedUserData BlockedUserData) {
+ new BlockedUserRepository.insertAsyncTask(mBlockedUserDao).execute(BlockedUserData);
+ }
+
+ private static class insertAsyncTask extends AsyncTask {
+
+ private BlockedUserDao mAsyncTaskDao;
+
+ insertAsyncTask(BlockedUserDao dao) {
+ mAsyncTaskDao = dao;
+ }
+
+ @Override
+ protected Void doInBackground(final BlockedUserData... params) {
+ mAsyncTaskDao.insert(params[0]);
+ return null;
+ }
+ }
+}
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/blockeduser/BlockedUserViewModel.java b/app/src/main/java/eu/toldi/infinityforlemmy/blockeduser/BlockedUserViewModel.java
new file mode 100644
index 00000000..6a0ca44a
--- /dev/null
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/blockeduser/BlockedUserViewModel.java
@@ -0,0 +1,61 @@
+package eu.toldi.infinityforlemmy.blockeduser;
+
+import android.app.Application;
+
+import androidx.annotation.NonNull;
+import androidx.lifecycle.AndroidViewModel;
+import androidx.lifecycle.LiveData;
+import androidx.lifecycle.MutableLiveData;
+import androidx.lifecycle.Transformations;
+import androidx.lifecycle.ViewModel;
+import androidx.lifecycle.ViewModelProvider;
+
+import java.util.List;
+
+import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
+
+public class BlockedUserViewModel extends AndroidViewModel {
+ private BlockedUserRepository blockedUserRepository;
+ private LiveData> mAllSubscribedUsers;
+ private MutableLiveData searchQueryLiveData;
+
+ public BlockedUserViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
+ super(application);
+ blockedUserRepository = new BlockedUserRepository(redditDataRoomDatabase, accountName);
+ searchQueryLiveData = new MutableLiveData<>();
+ searchQueryLiveData.postValue("");
+
+ mAllSubscribedUsers = Transformations.switchMap(searchQueryLiveData, searchQuery -> blockedUserRepository.getAllFavoriteSubscribedUsersWithSearchQuery(searchQuery));
+ }
+
+ public LiveData> getAllSubscribedUsers() {
+ return mAllSubscribedUsers;
+ }
+
+
+ public void insert(BlockedUserData BlockedUserData) {
+ blockedUserRepository.insert(BlockedUserData);
+ }
+
+ public void setSearchQuery(String searchQuery) {
+ searchQueryLiveData.postValue(searchQuery);
+ }
+
+ public static class Factory extends ViewModelProvider.NewInstanceFactory {
+ private Application mApplication;
+ private RedditDataRoomDatabase mRedditDataRoomDatabase;
+ private String mAccountName;
+
+ public Factory(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
+ mApplication = application;
+ mRedditDataRoomDatabase = redditDataRoomDatabase;
+ mAccountName = accountName;
+ }
+
+ @NonNull
+ @Override
+ public T create(@NonNull Class modelClass) {
+ return (T) new BlockedUserViewModel(mApplication, mRedditDataRoomDatabase, mAccountName);
+ }
+ }
+}
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/fragments/BlockedCommunitiesListingFragment.java b/app/src/main/java/eu/toldi/infinityforlemmy/fragments/BlockedCommunitiesListingFragment.java
new file mode 100644
index 00000000..8227d82e
--- /dev/null
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/fragments/BlockedCommunitiesListingFragment.java
@@ -0,0 +1,202 @@
+package eu.toldi.infinityforlemmy.fragments;
+
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.res.Resources;
+import android.os.Build;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.Fragment;
+import androidx.lifecycle.ViewModelProvider;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.RequestManager;
+
+import java.util.concurrent.Executor;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import eu.toldi.infinityforlemmy.FragmentCommunicator;
+import eu.toldi.infinityforlemmy.Infinity;
+import eu.toldi.infinityforlemmy.R;
+import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
+import eu.toldi.infinityforlemmy.activities.BaseActivity;
+import eu.toldi.infinityforlemmy.activities.SubscribedThingListingActivity;
+import eu.toldi.infinityforlemmy.adapters.BlockedCommunitiesRecyclerViewAdapter;
+import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityViewModel;
+import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
+import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
+import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
+import me.zhanghai.android.fastscroll.FastScrollerBuilder;
+import retrofit2.Retrofit;
+
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class BlockedCommunitiesListingFragment extends Fragment implements FragmentCommunicator {
+
+ public static final String EXTRA_ACCOUNT_NAME = "EAN";
+ public static final String EXTRA_ACCESS_TOKEN = "EAT";
+ public static final String EXTRA_ACCOUNT_PROFILE_IMAGE_URL = "EAPIU";
+ public static final String EXTRA_IS_SUBREDDIT_SELECTION = "EISS";
+ public static final String EXTRA_EXTRA_CLEAR_SELECTION = "EECS";
+ public static final String EXTRA_ACCOUNT_QUALIFIED_NAME = "EAQN";
+
+ @BindView(R.id.swipe_refresh_layout_subscribed_subreddits_listing_fragment)
+ SwipeRefreshLayout mSwipeRefreshLayout;
+ @BindView(R.id.recycler_view_subscribed_subreddits_listing_fragment)
+ RecyclerView mRecyclerView;
+ @BindView(R.id.no_subscriptions_linear_layout_subreddits_listing_fragment)
+ LinearLayout mLinearLayout;
+ @BindView(R.id.no_subscriptions_image_view_subreddits_listing_fragment)
+ ImageView mImageView;
+ @BindView(R.id.error_text_view_subscribed_subreddits_listing_fragment)
+ TextView mErrorTextView;
+ @Inject
+ @Named("oauth")
+ Retrofit mOauthRetrofit;
+ @Inject
+ @Named("default")
+ SharedPreferences mSharedPreferences;
+ @Inject
+ RedditDataRoomDatabase mRedditDataRoomDatabase;
+ @Inject
+ CustomThemeWrapper mCustomThemeWrapper;
+ @Inject
+ Executor mExecutor;
+ public BlockedCommunityViewModel mSubscribedSubredditViewModel;
+ private BaseActivity mActivity;
+ private RequestManager mGlide;
+ private LinearLayoutManagerBugFixed mLinearLayoutManager;
+
+ public BlockedCommunitiesListingFragment() {
+ // Required empty public constructor
+ }
+
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = inflater.inflate(R.layout.fragment_subscribed_subreddits_listing, container, false);
+
+ ButterKnife.bind(this, rootView);
+
+ ((Infinity) mActivity.getApplication()).getAppComponent().inject(this);
+
+ applyTheme();
+
+ if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) {
+ mRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight());
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
+ && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) {
+ Resources resources = getResources();
+ int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
+ if (navBarResourceId > 0) {
+ mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
+ }
+ }
+
+ String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME, "-");
+ String accountQualifiedName = getArguments().getString(EXTRA_ACCOUNT_QUALIFIED_NAME, "-");
+ String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
+
+ if (accessToken == null) {
+ mSwipeRefreshLayout.setEnabled(false);
+ }
+
+ mGlide = Glide.with(this);
+
+ mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity);
+ mRecyclerView.setLayoutManager(mLinearLayoutManager);
+
+ BlockedCommunitiesRecyclerViewAdapter adapter = new BlockedCommunitiesRecyclerViewAdapter(mActivity, mExecutor, mOauthRetrofit, mRedditDataRoomDatabase,
+ mCustomThemeWrapper, accessToken);
+
+
+ mRecyclerView.setAdapter(adapter);
+ new FastScrollerBuilder(mRecyclerView).useMd2Style().build();
+
+ mSubscribedSubredditViewModel = new ViewModelProvider(this,
+ new BlockedCommunityViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, accountQualifiedName))
+ .get(BlockedCommunityViewModel.class);
+ mSubscribedSubredditViewModel.getAllBlockedCommunities().observe(getViewLifecycleOwner(), subscribedSubredditData -> {
+ mSwipeRefreshLayout.setRefreshing(false);
+ if (subscribedSubredditData == null || subscribedSubredditData.size() == 0) {
+ mRecyclerView.setVisibility(View.GONE);
+ mLinearLayout.setVisibility(View.VISIBLE);
+ mGlide.load(R.drawable.error_image).into(mImageView);
+ } else {
+ mLinearLayout.setVisibility(View.GONE);
+ mRecyclerView.setVisibility(View.VISIBLE);
+ mGlide.clear(mImageView);
+ }
+
+ if (accessToken != null) {
+ adapter.addUser(accountName, getArguments().getString(EXTRA_ACCOUNT_PROFILE_IMAGE_URL));
+ }
+ adapter.setSubscribedSubreddits(subscribedSubredditData);
+ });
+
+ /* mSubscribedSubredditViewModel.getAllFavoriteSubscribedSubreddits().observe(getViewLifecycleOwner(), favoriteSubscribedSubredditData -> {
+ mSwipeRefreshLayout.setRefreshing(false);
+ if (favoriteSubscribedSubredditData != null && favoriteSubscribedSubredditData.size() > 0) {
+ mLinearLayout.setVisibility(View.GONE);
+ mRecyclerView.setVisibility(View.VISIBLE);
+ mGlide.clear(mImageView);
+ }
+
+ adapter.setFavoriteSubscribedSubreddits(favoriteSubscribedSubredditData);
+ });*/
+
+ return rootView;
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ mActivity = (BaseActivity) context;
+ }
+
+ @Override
+ public void stopRefreshProgressbar() {
+ mSwipeRefreshLayout.setRefreshing(false);
+ }
+
+ @Override
+ public void applyTheme() {
+ if (mActivity instanceof SubscribedThingListingActivity) {
+ mSwipeRefreshLayout.setOnRefreshListener(() -> ((SubscribedThingListingActivity) mActivity).loadSubscriptions(true));
+ mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground());
+ mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent());
+ } else {
+ mSwipeRefreshLayout.setEnabled(false);
+ }
+ mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor());
+ if (mActivity.typeface != null) {
+ mErrorTextView.setTypeface(mActivity.contentTypeface);
+ }
+ }
+
+ public void goBackToTop() {
+ if (mLinearLayoutManager != null) {
+ mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
+ }
+ }
+
+ public void changeSearchQuery(String searchQuery) {
+ mSubscribedSubredditViewModel.setSearchQuery(searchQuery);
+ }
+}
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/fragments/BlockedUsersListingFragment.java b/app/src/main/java/eu/toldi/infinityforlemmy/fragments/BlockedUsersListingFragment.java
new file mode 100644
index 00000000..2eef6dbf
--- /dev/null
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/fragments/BlockedUsersListingFragment.java
@@ -0,0 +1,172 @@
+package eu.toldi.infinityforlemmy.fragments;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.res.Resources;
+import android.os.Build;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.Fragment;
+import androidx.lifecycle.ViewModelProvider;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.RequestManager;
+
+import java.util.concurrent.Executor;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import eu.toldi.infinityforlemmy.FragmentCommunicator;
+import eu.toldi.infinityforlemmy.Infinity;
+import eu.toldi.infinityforlemmy.R;
+import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
+import eu.toldi.infinityforlemmy.activities.BaseActivity;
+import eu.toldi.infinityforlemmy.activities.BlockedThingListingActivity;
+import eu.toldi.infinityforlemmy.adapters.BlockedUsersRecyclerViewAdapter;
+import eu.toldi.infinityforlemmy.blockeduser.BlockedUserViewModel;
+import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
+import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
+import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
+import me.zhanghai.android.fastscroll.FastScrollerBuilder;
+import retrofit2.Retrofit;
+
+public class BlockedUsersListingFragment extends Fragment implements FragmentCommunicator {
+ public static final String EXTRA_ACCOUNT_NAME = "EAN";
+ public static final String EXTRA_ACCESS_TOKEN = "EAT";
+
+ @BindView(R.id.swipe_refresh_layout_followed_users_listing_fragment)
+ SwipeRefreshLayout mSwipeRefreshLayout;
+ @BindView(R.id.recycler_view_followed_users_listing_fragment)
+ RecyclerView mRecyclerView;
+ @BindView(R.id.no_subscriptions_linear_layout_followed_users_listing_fragment)
+ LinearLayout mLinearLayout;
+ @BindView(R.id.no_subscriptions_image_view_followed_users_listing_fragment)
+ ImageView mImageView;
+ @BindView(R.id.error_text_view_followed_users_listing_fragment)
+ TextView mErrorTextView;
+ @Inject
+ @Named("oauth")
+ Retrofit mOauthRetrofit;
+ @Inject
+ @Named("default")
+ SharedPreferences mSharedPreferences;
+ @Inject
+ RedditDataRoomDatabase mRedditDataRoomDatabase;
+ @Inject
+ CustomThemeWrapper mCustomThemeWrapper;
+ @Inject
+ Executor mExecutor;
+ BlockedUserViewModel blockedUserViewModel;
+ private BaseActivity mActivity;
+ private RequestManager mGlide;
+ private LinearLayoutManagerBugFixed mLinearLayoutManager;
+
+ public BlockedUsersListingFragment() {
+ // Required empty public constructor
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = inflater.inflate(R.layout.fragment_followed_users_listing, container, false);
+
+ ButterKnife.bind(this, rootView);
+
+ ((Infinity) mActivity.getApplication()).getAppComponent().inject(this);
+
+ applyTheme();
+
+ Resources resources = getResources();
+
+ if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) {
+ mRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight());
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
+ && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) {
+ int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
+ if (navBarResourceId > 0) {
+ mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
+ }
+ }
+
+ mGlide = Glide.with(this);
+
+ String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
+ if (accessToken == null) {
+ mSwipeRefreshLayout.setEnabled(false);
+ }
+ mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity);
+ mRecyclerView.setLayoutManager(mLinearLayoutManager);
+ BlockedUsersRecyclerViewAdapter adapter = new BlockedUsersRecyclerViewAdapter(mActivity,
+ mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, accessToken);
+ mRecyclerView.setAdapter(adapter);
+ new FastScrollerBuilder(mRecyclerView).useMd2Style().build();
+
+ blockedUserViewModel = new ViewModelProvider(this,
+ new BlockedUserViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, getArguments().getString(EXTRA_ACCOUNT_NAME)))
+ .get(BlockedUserViewModel.class);
+
+ blockedUserViewModel.getAllSubscribedUsers().observe(getViewLifecycleOwner(), subscribedUserData -> {
+ mSwipeRefreshLayout.setRefreshing(false);
+ if (subscribedUserData == null || subscribedUserData.size() == 0) {
+ mRecyclerView.setVisibility(View.GONE);
+ mLinearLayout.setVisibility(View.VISIBLE);
+ mGlide.load(R.drawable.error_image).into(mImageView);
+ } else {
+ mLinearLayout.setVisibility(View.GONE);
+ mRecyclerView.setVisibility(View.VISIBLE);
+ mGlide.clear(mImageView);
+ }
+ adapter.setSubscribedUsers(subscribedUserData);
+ });
+
+ return rootView;
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ mActivity = (BaseActivity) context;
+ }
+
+ @Override
+ public void stopRefreshProgressbar() {
+ mSwipeRefreshLayout.setRefreshing(false);
+ }
+
+ @Override
+ public void applyTheme() {
+ if (mActivity instanceof BlockedThingListingActivity) {
+ mSwipeRefreshLayout.setOnRefreshListener(() -> ((BlockedThingListingActivity) mActivity).loadBlocks(true));
+ mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground());
+ mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent());
+ } else {
+ mSwipeRefreshLayout.setEnabled(false);
+ }
+ mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor());
+ if (mActivity.typeface != null) {
+ mErrorTextView.setTypeface(mActivity.typeface);
+ }
+ }
+
+ public void goBackToTop() {
+ if (mLinearLayoutManager != null) {
+ mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
+ }
+ }
+
+ public void changeSearchQuery(String searchQuery) {
+ blockedUserViewModel.setSearchQuery(searchQuery);
+ }
+}
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/subreddit/ParseSubredditData.java b/app/src/main/java/eu/toldi/infinityforlemmy/subreddit/ParseSubredditData.java
index e4b43181..acaac649 100644
--- a/app/src/main/java/eu/toldi/infinityforlemmy/subreddit/ParseSubredditData.java
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/subreddit/ParseSubredditData.java
@@ -27,7 +27,7 @@ public class ParseSubredditData {
}
@Nullable
- private static SubredditData parseSubredditData(JSONObject subredditDataJsonObject, boolean nsfw) throws JSONException {
+ public static SubredditData parseSubredditData(JSONObject subredditDataJsonObject, boolean nsfw) throws JSONException {
JSONObject community = subredditDataJsonObject.getJSONObject("community");
boolean isNSFW = community.getBoolean("nsfw");
if (!nsfw && isNSFW) {
@@ -69,9 +69,10 @@ public class ParseSubredditData {
boolean hidden = community.getBoolean("hidden");
boolean postingRestrictedToMods = community.getBoolean("posting_restricted_to_mods");
int instanceId = community.getInt("instance_id");
- int subscribers = subredditDataJsonObject.getJSONObject("counts").getInt("subscribers");
+ int subscribers = (subredditDataJsonObject.has("counts")) ? subredditDataJsonObject.getJSONObject("counts").getInt("subscribers") : 0;
+ boolean blocked = (subredditDataJsonObject.has("blocked")) ? subredditDataJsonObject.getBoolean("blocked") : true;
- return new SubredditData(id,name,title,description,removed,published,updated,deleted,isNSFW,actorId,local,iconUrl,bannerImageUrl,hidden,postingRestrictedToMods,instanceId,subscribers);
+ return new SubredditData(id, name, title, description, removed, published, updated, deleted, isNSFW, actorId, local, iconUrl, bannerImageUrl, hidden, postingRestrictedToMods, instanceId, subscribers, blocked);
}
interface ParseSubredditDataListener {
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/subreddit/SubredditData.java b/app/src/main/java/eu/toldi/infinityforlemmy/subreddit/SubredditData.java
index a8d02fac..737a09fb 100644
--- a/app/src/main/java/eu/toldi/infinityforlemmy/subreddit/SubredditData.java
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/subreddit/SubredditData.java
@@ -61,6 +61,9 @@ public class SubredditData {
@ColumnInfo(name = "subscribers")
private int subscribers;
+ @ColumnInfo(name = "blocked")
+ private boolean blocked;
+
@Ignore
private boolean isSelected;
@@ -201,7 +204,7 @@ public class SubredditData {
this.subscribers = subscribers;
}
- public SubredditData(int id, String name, String title, String description, boolean removed, String published, String updated, boolean deleted, boolean nsfw, String actorId, boolean local, String icon, String banner, boolean hidden, boolean postingRestrictedToMods, int instanceId, int subscribers) {
+ public SubredditData(int id, String name, String title, String description, boolean removed, String published, String updated, boolean deleted, boolean nsfw, String actorId, boolean local, String icon, String banner, boolean hidden, boolean postingRestrictedToMods, int instanceId, int subscribers, boolean blocked) {
this.id = id;
this.name = name;
this.title = title;
@@ -219,6 +222,7 @@ public class SubredditData {
this.postingRestrictedToMods = postingRestrictedToMods;
this.instanceId = instanceId;
this.subscribers = subscribers;
+ this.blocked = blocked;
}
public boolean isNSFW() {
@@ -250,6 +254,14 @@ public class SubredditData {
}
public void setSelected(boolean b) {
- isSelected =b;
+ isSelected = b;
+ }
+
+ public boolean isBlocked() {
+ return blocked;
+ }
+
+ public void setBlocked(boolean blocked) {
+ this.blocked = blocked;
}
}
diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/user/ParseUserData.java b/app/src/main/java/eu/toldi/infinityforlemmy/user/ParseUserData.java
index 5008c5e8..47ff9e77 100644
--- a/app/src/main/java/eu/toldi/infinityforlemmy/user/ParseUserData.java
+++ b/app/src/main/java/eu/toldi/infinityforlemmy/user/ParseUserData.java
@@ -21,7 +21,7 @@ public class ParseUserData {
new ParseUserListingDataAsyncTask(response, parseUserListingDataListener).execute();
}
- private static UserData parseUserDataBase(JSONObject userDataJson, boolean parseFullKarma) throws JSONException {
+ public static UserData parseUserDataBase(JSONObject userDataJson, boolean parseFullKarma) throws JSONException {
if (userDataJson == null) {
return null;
}
@@ -38,10 +38,7 @@ public class ParseUserData {
if (!personJson.isNull("banner")) {
bannerImageUrl = personJson.getString("banner");
}
- JSONObject countsJson = (userDataJson.has("person_view")) ? userDataJson.getJSONObject("person_view").getJSONObject("counts") : userDataJson.getJSONObject("counts");
- int linkKarma = countsJson.getInt(JSONUtils.POST_SCORE_KEY);
- int commentKarma = countsJson.getInt(JSONUtils.COMMENT_SCORE_KEY);
int account_id = personJson.getInt("id");
int instance_id = personJson.getInt("instance_id");
diff --git a/app/src/main/kotlin/eu/toldi/infinityforlemmy/community/BlockCommunity.kt b/app/src/main/kotlin/eu/toldi/infinityforlemmy/community/BlockCommunity.kt
new file mode 100644
index 00000000..0b09d3d8
--- /dev/null
+++ b/app/src/main/kotlin/eu/toldi/infinityforlemmy/community/BlockCommunity.kt
@@ -0,0 +1,64 @@
+package eu.toldi.infinityforlemmy.community
+
+import eu.toldi.infinityforlemmy.apis.LemmyAPI
+import eu.toldi.infinityforlemmy.dto.BlockCommunityDTO
+import retrofit2.Call
+import retrofit2.Callback
+import retrofit2.Response
+import retrofit2.Retrofit
+
+object BlockCommunity {
+
+ fun blockCommunity(
+ retrofit: Retrofit,
+ communityId: Int,
+ auth: String,
+ blockCommunityListener: BlockCommunityListener
+ ) {
+ val api = retrofit.create(LemmyAPI::class.java)
+ api.communityBlock(BlockCommunityDTO(communityId, true, auth))?.enqueue(
+ object : Callback {
+ override fun onResponse(call: Call, response: Response) {
+ if (response.isSuccessful) {
+ blockCommunityListener.onBlockCommunitySuccess()
+ } else {
+ blockCommunityListener.onBlockCommunityError()
+ }
+ }
+
+ override fun onFailure(call: Call, t: Throwable) {
+ blockCommunityListener.onBlockCommunityError()
+ }
+ }
+ )
+ }
+
+ fun unBlockCommunity(
+ retrofit: Retrofit,
+ communityId: Int,
+ auth: String,
+ blockCommunityListener: BlockCommunityListener
+ ) {
+ val api = retrofit.create(LemmyAPI::class.java)
+ api.communityBlock(BlockCommunityDTO(communityId, false, auth))?.enqueue(
+ object : Callback {
+ override fun onResponse(call: Call, response: Response) {
+ if (response.isSuccessful) {
+ blockCommunityListener.onBlockCommunitySuccess()
+ } else {
+ blockCommunityListener.onBlockCommunityError()
+ }
+ }
+
+ override fun onFailure(call: Call, t: Throwable) {
+ blockCommunityListener.onBlockCommunityError()
+ }
+ }
+ )
+ }
+
+ interface BlockCommunityListener {
+ fun onBlockCommunitySuccess()
+ fun onBlockCommunityError()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/eu/toldi/infinityforlemmy/dto/BlockCommunityDTO.kt b/app/src/main/kotlin/eu/toldi/infinityforlemmy/dto/BlockCommunityDTO.kt
new file mode 100644
index 00000000..6e106138
--- /dev/null
+++ b/app/src/main/kotlin/eu/toldi/infinityforlemmy/dto/BlockCommunityDTO.kt
@@ -0,0 +1,3 @@
+package eu.toldi.infinityforlemmy.dto
+
+data class BlockCommunityDTO(val community_id: Int, val block: Boolean, val auth: String)
diff --git a/app/src/main/res/drawable/ic_baseline_info_24.xml b/app/src/main/res/drawable/ic_baseline_info_24.xml
new file mode 100644
index 00000000..d93eb876
--- /dev/null
+++ b/app/src/main/res/drawable/ic_baseline_info_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/menu/view_subreddit_detail_activity.xml b/app/src/main/res/menu/view_subreddit_detail_activity.xml
index 4b393c54..fd8565fb 100644
--- a/app/src/main/res/menu/view_subreddit_detail_activity.xml
+++ b/app/src/main/res/menu/view_subreddit_detail_activity.xml
@@ -30,9 +30,15 @@
app:showAsAction="never" />
+
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index f0248691..d78d76b8 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1353,4 +1353,13 @@
The username field cannot be left empty.
The password field cannot be left empty.
Separate Up and Down votes
+ Community blocked!
+ Failed to block community
+ Unblock Community
+ Community unblocked!
+ Failed to unblock community
+ Instance Info
+ Blocked Communities
+ Blocked users
+ Blocks