mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-07 03:07:26 +01:00
parent
2bb1189e15
commit
8c758460bc
@ -25,7 +25,6 @@ import org.greenrobot.eventbus.Subscribe;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
@ -33,7 +32,6 @@ import javax.inject.Named;
|
|||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import eu.toldi.infinityforlemmy.ActivityToolbarInterface;
|
import eu.toldi.infinityforlemmy.ActivityToolbarInterface;
|
||||||
import eu.toldi.infinityforlemmy.AnyAccountAccessTokenAuthenticator;
|
|
||||||
import eu.toldi.infinityforlemmy.FetchSubscribedThing;
|
import eu.toldi.infinityforlemmy.FetchSubscribedThing;
|
||||||
import eu.toldi.infinityforlemmy.Infinity;
|
import eu.toldi.infinityforlemmy.Infinity;
|
||||||
import eu.toldi.infinityforlemmy.R;
|
import eu.toldi.infinityforlemmy.R;
|
||||||
@ -49,9 +47,6 @@ import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
|||||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||||
import eu.toldi.infinityforlemmy.subscribeduser.SubscribedUserData;
|
import eu.toldi.infinityforlemmy.subscribeduser.SubscribedUserData;
|
||||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||||
import okhttp3.ConnectionPool;
|
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import retrofit2.Retrofit;
|
|
||||||
|
|
||||||
public class SubredditSelectionActivity extends BaseActivity implements ActivityToolbarInterface {
|
public class SubredditSelectionActivity extends BaseActivity implements ActivityToolbarInterface {
|
||||||
|
|
||||||
@ -77,9 +72,6 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
|||||||
@Named("no_oauth")
|
@Named("no_oauth")
|
||||||
RetrofitHolder mRetrofit;
|
RetrofitHolder mRetrofit;
|
||||||
@Inject
|
@Inject
|
||||||
@Named("oauth")
|
|
||||||
Retrofit mOauthRetrofit;
|
|
||||||
@Inject
|
|
||||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
@Inject
|
@Inject
|
||||||
@Named("default")
|
@Named("default")
|
||||||
@ -142,21 +134,14 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
|||||||
mAccountName = specifiedAccount.getAccountName();
|
mAccountName = specifiedAccount.getAccountName();
|
||||||
mAccountProfileImageUrl = specifiedAccount.getProfileImageUrl();
|
mAccountProfileImageUrl = specifiedAccount.getProfileImageUrl();
|
||||||
|
|
||||||
mOauthRetrofit = mOauthRetrofit.newBuilder().client(new OkHttpClient.Builder().authenticator(new AnyAccountAccessTokenAuthenticator(mRetrofit.getRetrofit(), mRedditDataRoomDatabase, specifiedAccount, mCurrentAccountSharedPreferences))
|
|
||||||
.connectTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.writeTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.connectionPool(new ConnectionPool(0, 1, TimeUnit.NANOSECONDS))
|
|
||||||
.build())
|
|
||||||
.build();
|
|
||||||
} else {
|
} else {
|
||||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||||
mAccountProfileImageUrl = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, null);
|
mAccountProfileImageUrl = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||||
mAccountProfileImageUrl = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, null);
|
mAccountProfileImageUrl = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,6 +183,7 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
|||||||
mFragment = new SubscribedSubredditsListingFragment();
|
mFragment = new SubscribedSubredditsListingFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||||
|
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_QUALIFIED_NAME, mAccountName);
|
||||||
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_PROFILE_IMAGE_URL, mAccountProfileImageUrl);
|
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_PROFILE_IMAGE_URL, mAccountProfileImageUrl);
|
||||||
bundle.putBoolean(SubscribedSubredditsListingFragment.EXTRA_IS_SUBREDDIT_SELECTION, true);
|
bundle.putBoolean(SubscribedSubredditsListingFragment.EXTRA_IS_SUBREDDIT_SELECTION, true);
|
||||||
|
@ -151,30 +151,8 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
|
|||||||
((SubredditViewHolder) viewHolder).subredditNameTextView.setText(R.string.all_communities);
|
((SubredditViewHolder) viewHolder).subredditNameTextView.setText(R.string.all_communities);
|
||||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(null, null, false));
|
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(null, null, false));
|
||||||
return;
|
return;
|
||||||
} else if (itemClickListener != null && !hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 0) {
|
|
||||||
name = username;
|
|
||||||
iconUrl = userIconUrl;
|
|
||||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, true));
|
|
||||||
} else if (hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 1) {
|
|
||||||
name = username;
|
|
||||||
iconUrl = userIconUrl;
|
|
||||||
if (itemClickListener != null) {
|
|
||||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, true));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
int offset;
|
int offset = hasClearSelectionRow ? 1 : 0;
|
||||||
if (itemClickListener != null) {
|
|
||||||
if (hasClearSelectionRow) {
|
|
||||||
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
|
|
||||||
mFavoriteSubscribedSubredditData.size() + 4 : 2;
|
|
||||||
} else {
|
|
||||||
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
|
|
||||||
mFavoriteSubscribedSubredditData.size() + 3 : 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
|
|
||||||
mFavoriteSubscribedSubredditData.size() + 2 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
name = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getName();
|
name = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getName();
|
||||||
fullname = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getQualified_name();
|
fullname = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getQualified_name();
|
||||||
@ -250,23 +228,10 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
|
|||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
if (mSubscribedSubredditData != null) {
|
if (mSubscribedSubredditData != null) {
|
||||||
if(mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) {
|
|
||||||
if (itemClickListener != null) {
|
|
||||||
if (hasClearSelectionRow) {
|
|
||||||
return mSubscribedSubredditData.size() > 0 ?
|
|
||||||
mFavoriteSubscribedSubredditData.size() + mSubscribedSubredditData.size() + 4 : 0;
|
|
||||||
} else {
|
|
||||||
return mSubscribedSubredditData.size() > 0 ?
|
|
||||||
mFavoriteSubscribedSubredditData.size() + mSubscribedSubredditData.size() + 3 : 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return mSubscribedSubredditData.size() > 0 ?
|
|
||||||
mFavoriteSubscribedSubredditData.size() + mSubscribedSubredditData.size() + 2 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (itemClickListener != null) {
|
if (itemClickListener != null) {
|
||||||
if (hasClearSelectionRow) {
|
if (hasClearSelectionRow) {
|
||||||
return mSubscribedSubredditData.size() > 0 ? mSubscribedSubredditData.size() + 2 : 0;
|
return mSubscribedSubredditData.size() > 0 ? mSubscribedSubredditData.size() + 1 : 0;
|
||||||
} else {
|
} else {
|
||||||
return mSubscribedSubredditData.size() > 0 ? mSubscribedSubredditData.size() + 1 : 0;
|
return mSubscribedSubredditData.size() > 0 ? mSubscribedSubredditData.size() + 1 : 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user