aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/AndroidManifest.xml5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java78
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/AnonymousSubscriptionsActivity.java102
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java54
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java4
-rw-r--r--app/src/main/res/layout/activity_anonymous_subscriptions.xml41
9 files changed, 237 insertions, 68 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index f3b262b7..97dc80d3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -32,6 +32,10 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:replace="android:label">
+ <activity android:name=".activities.AnonymousSubscriptionsActivity"
+ android:label="@string/subscriptions"
+ android:parentActivityName=".activities.MainActivity"
+ android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.WebViewActivity"
android:label=""
@@ -408,7 +412,6 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
-
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index 8ac039ea..b0506a82 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -5,6 +5,7 @@ import javax.inject.Singleton;
import dagger.Component;
import ml.docilealligator.infinityforreddit.activities.AccountPostsActivity;
import ml.docilealligator.infinityforreddit.activities.AccountSavedThingActivity;
+import ml.docilealligator.infinityforreddit.activities.AnonymousSubscriptionsActivity;
import ml.docilealligator.infinityforreddit.activities.CommentActivity;
import ml.docilealligator.infinityforreddit.activities.CreateMultiRedditActivity;
import ml.docilealligator.infinityforreddit.activities.CustomThemeListingActivity;
@@ -260,4 +261,6 @@ public interface AppComponent {
void inject(WebViewActivity webViewActivity);
void inject(CrashReportsFragment crashReportsFragment);
+
+ void inject(AnonymousSubscriptionsActivity anonymousSubscriptionsActivity);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java
index 8a041e3b..29aace70 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java
@@ -23,50 +23,60 @@ public class FavoriteThing {
RedditDataRoomDatabase redditDataRoomDatabase,
String accessToken, SubscribedSubredditData subscribedSubredditData,
FavoriteThingListener favoriteThingListener) {
- Map<String, String> params = new HashMap<>();
- params.put(APIUtils.SR_NAME_KEY, subscribedSubredditData.getName());
- params.put(APIUtils.MAKE_FAVORITE_KEY, "true");
- oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
- @Override
- public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
- if (response.isSuccessful()) {
- InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, subscribedSubredditData,
- favoriteThingListener::success);
- } else {
- favoriteThingListener.failed();
+ if (accessToken == null) {
+ InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, subscribedSubredditData,
+ favoriteThingListener::success);
+ } else {
+ Map<String, String> params = new HashMap<>();
+ params.put(APIUtils.SR_NAME_KEY, subscribedSubredditData.getName());
+ params.put(APIUtils.MAKE_FAVORITE_KEY, "true");
+ oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ if (response.isSuccessful()) {
+ InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, subscribedSubredditData,
+ favoriteThingListener::success);
+ } else {
+ favoriteThingListener.failed();
+ }
}
- }
- @Override
- public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
- favoriteThingListener.failed();
- }
- });
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ favoriteThingListener.failed();
+ }
+ });
+ }
}
public static void unfavoriteSubreddit(Executor executor, Handler handler, Retrofit oauthRetrofit,
RedditDataRoomDatabase redditDataRoomDatabase,
String accessToken, SubscribedSubredditData subscribedSubredditData,
FavoriteThingListener favoriteThingListener) {
- Map<String, String> params = new HashMap<>();
- params.put(APIUtils.SR_NAME_KEY, subscribedSubredditData.getName());
- params.put(APIUtils.MAKE_FAVORITE_KEY, "false");
- oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
- @Override
- public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
- if (response.isSuccessful()) {
- InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase,
- subscribedSubredditData, favoriteThingListener::success);
- } else {
- favoriteThingListener.failed();
+ if (accessToken == null) {
+ InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase,
+ subscribedSubredditData, favoriteThingListener::success);
+ } else {
+ Map<String, String> params = new HashMap<>();
+ params.put(APIUtils.SR_NAME_KEY, subscribedSubredditData.getName());
+ params.put(APIUtils.MAKE_FAVORITE_KEY, "false");
+ oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ if (response.isSuccessful()) {
+ InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase,
+ subscribedSubredditData, favoriteThingListener::success);
+ } else {
+ favoriteThingListener.failed();
+ }
}
- }
- @Override
- public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
- favoriteThingListener.failed();
- }
- });
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ favoriteThingListener.failed();
+ }
+ });
+ }
}
public static void favoriteUser(Executor executor, Handler handler, Retrofit oauthRetrofit,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AnonymousSubscriptionsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AnonymousSubscriptionsActivity.java
new file mode 100644
index 00000000..2c40b1e8
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AnonymousSubscriptionsActivity.java
@@ -0,0 +1,102 @@
+package ml.docilealligator.infinityforreddit.activities;
+
+import android.content.SharedPreferences;
+import android.os.Build;
+import android.os.Bundle;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+
+import androidx.appcompat.widget.Toolbar;
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+
+import com.google.android.material.appbar.AppBarLayout;
+import com.r0adkll.slidr.Slidr;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.fragments.SubscribedSubredditsListingFragment;
+import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+
+public class AnonymousSubscriptionsActivity extends BaseActivity {
+
+ @BindView(R.id.coordinator_layout_anonymous_subscriptions_activity)
+ CoordinatorLayout coordinatorLayout;
+ @BindView(R.id.appbar_layout_anonymous_subscriptions_activity)
+ AppBarLayout appBarLayout;
+ @BindView(R.id.toolbar_anonymous_subscriptions_activity)
+ Toolbar toolbar;
+ @Inject
+ @Named("default")
+ SharedPreferences mSharedPreferences;
+ @Inject
+ CustomThemeWrapper mCustomThemeWrapper;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+
+ setImmersiveModeNotApplicable();
+
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_anonymous_subscriptions);
+
+ ButterKnife.bind(this);
+
+ applyCustomTheme();
+
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) {
+ 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) {
+ coordinatorLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
+ View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
+ View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
+ } else {
+ window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
+ }
+ adjustToolbar(toolbar);
+ }
+ }
+
+ setSupportActionBar(toolbar);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+
+ SubscribedSubredditsListingFragment mFragment = new SubscribedSubredditsListingFragment();
+ Bundle bundle = new Bundle();
+ bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_NAME, "-");
+ mFragment.setArguments(bundle);
+ getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_anonymous_subscriptions_activity, mFragment).commit();
+ }
+
+ @Override
+ protected SharedPreferences getDefaultSharedPreferences() {
+ return mSharedPreferences;
+ }
+
+ @Override
+ protected CustomThemeWrapper getCustomThemeWrapper() {
+ return mCustomThemeWrapper;
+ }
+
+ @Override
+ protected void applyCustomTheme() {
+ coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
+ applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
index 0ea37503..2b2aa74d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
@@ -733,7 +733,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
intent = new Intent(MainActivity.this, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mAccountName);
} else if (stringId == R.string.subscriptions) {
- intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
+ if (mAccessToken != null) {
+ intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
+ } else {
+ intent = new Intent(MainActivity.this, AnonymousSubscriptionsActivity.class);
+ }
} else if (stringId == R.string.multi_reddit) {
intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java
index d89c0160..2b53c4ca 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java
@@ -483,6 +483,10 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
} else {
switch (position) {
case 1:
+ stringId = R.string.subscriptions;
+ drawableId = R.drawable.ic_subscritptions_bottom_app_bar_24dp;
+ break;
+ case 2:
if ((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
stringId = R.string.dark_theme;
drawableId = R.drawable.ic_dark_theme_24dp;
@@ -491,7 +495,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
drawableId = R.drawable.ic_light_theme_24dp;
}
break;
- case 2:
+ case 3:
setOnClickListener = false;
if (isNSFWEnabled) {
stringId = R.string.disable_nsfw;
@@ -515,7 +519,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
}
});
break;
- case 3:
+ case 4:
stringId = R.string.settings;
drawableId = R.drawable.ic_settings_24dp;
}
@@ -681,7 +685,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
- (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0);
} else {
- return 4;
+ return 5;
}
} else {
if (isLoggedIn) {
@@ -742,7 +746,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
if (isLoggedIn) {
notifyItemChanged(CURRENT_MENU_ITEMS - 3);
} else {
- notifyItemChanged(2);
+ notifyItemChanged(3);
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java
index 3ca11603..d6e13a37 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java
@@ -150,17 +150,17 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
String name;
String iconUrl;
- if (hasClearSelectionRow && viewHolder.getAdapterPosition() == 0) {
+ if (hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 0) {
((SubredditViewHolder) viewHolder).subredditNameTextView.setText(R.string.all_subreddits);
((SubredditViewHolder) viewHolder).favoriteImageView.setVisibility(View.GONE);
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(null, null, false));
return;
- } else if (itemClickListener != null && !hasClearSelectionRow && viewHolder.getAdapterPosition() == 0) {
+ } else if (itemClickListener != null && !hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 0) {
((SubredditViewHolder) viewHolder).favoriteImageView.setVisibility(View.GONE);
name = username;
iconUrl = userIconUrl;
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, true));
- } else if (hasClearSelectionRow && viewHolder.getAdapterPosition() == 1) {
+ } else if (hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 1) {
((SubredditViewHolder) viewHolder).favoriteImageView.setVisibility(View.GONE);
name = username;
iconUrl = userIconUrl;
@@ -182,24 +182,24 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
mFavoriteSubscribedSubredditData.size() + 2 : 0;
}
- name = mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).getName();
- iconUrl = mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).getIconUrl();
- if(mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).isFavorite()) {
+ name = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getName();
+ iconUrl = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getIconUrl();
+ if(mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).isFavorite()) {
((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
} else {
((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
}
((SubredditViewHolder) viewHolder).favoriteImageView.setOnClickListener(view -> {
- if(mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).isFavorite()) {
+ if(mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).isFavorite()) {
((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
- mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).setFavorite(false);
+ mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).setFavorite(false);
FavoriteThing.unfavoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, accessToken,
- mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset),
+ mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset),
new FavoriteThing.FavoriteThingListener() {
@Override
public void success() {
- int position = viewHolder.getAdapterPosition() - offset;
+ int position = viewHolder.getBindingAdapterPosition() - offset;
if(position >= 0 && mSubscribedSubredditData.size() > position) {
mSubscribedSubredditData.get(position).setFavorite(false);
}
@@ -209,7 +209,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
@Override
public void failed() {
Toast.makeText(mContext, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show();
- int position = viewHolder.getAdapterPosition() - offset;
+ int position = viewHolder.getBindingAdapterPosition() - offset;
if(position >= 0 && mSubscribedSubredditData.size() > position) {
mSubscribedSubredditData.get(position).setFavorite(true);
}
@@ -218,14 +218,14 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
});
} else {
((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
- mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).setFavorite(true);
+ mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).setFavorite(true);
FavoriteThing.favoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit,
mRedditDataRoomDatabase, accessToken,
- mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset),
+ mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset),
new FavoriteThing.FavoriteThingListener() {
@Override
public void success() {
- int position = viewHolder.getAdapterPosition() - offset;
+ int position = viewHolder.getBindingAdapterPosition() - offset;
if(position >= 0 && mSubscribedSubredditData.size() > position) {
mSubscribedSubredditData.get(position).setFavorite(true);
}
@@ -235,7 +235,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
@Override
public void failed() {
Toast.makeText(mContext, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show();
- int position = viewHolder.getAdapterPosition() - offset;
+ int position = viewHolder.getBindingAdapterPosition() - offset;
if(position >= 0 && mSubscribedSubredditData.size() > position) {
mSubscribedSubredditData.get(position).setFavorite(false);
}
@@ -281,24 +281,24 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
} else {
offset = 1;
}
- String name = mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).getName();
- String iconUrl = mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).getIconUrl();
- if(mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).isFavorite()) {
+ String name = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getName();
+ String iconUrl = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getIconUrl();
+ if(mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).isFavorite()) {
((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
} else {
((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
}
((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setOnClickListener(view -> {
- if(mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).isFavorite()) {
+ if(mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).isFavorite()) {
((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
- mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).setFavorite(false);
+ mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).setFavorite(false);
FavoriteThing.unfavoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, accessToken,
- mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset),
+ mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset),
new FavoriteThing.FavoriteThingListener() {
@Override
public void success() {
- int position = viewHolder.getAdapterPosition() - 1;
+ int position = viewHolder.getBindingAdapterPosition() - 1;
if(position >= 0 && mFavoriteSubscribedSubredditData.size() > position) {
mFavoriteSubscribedSubredditData.get(position).setFavorite(false);
}
@@ -308,7 +308,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
@Override
public void failed() {
Toast.makeText(mContext, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show();
- int position = viewHolder.getAdapterPosition() - 1;
+ int position = viewHolder.getBindingAdapterPosition() - 1;
if(position >= 0 && mFavoriteSubscribedSubredditData.size() > position) {
mFavoriteSubscribedSubredditData.get(position).setFavorite(true);
}
@@ -317,13 +317,13 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
});
} else {
((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
- mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).setFavorite(true);
+ mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).setFavorite(true);
FavoriteThing.favoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, accessToken,
- mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset),
+ mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset),
new FavoriteThing.FavoriteThingListener() {
@Override
public void success() {
- int position = viewHolder.getAdapterPosition() - 1;
+ int position = viewHolder.getBindingAdapterPosition() - 1;
if(position >= 0 && mFavoriteSubscribedSubredditData.size() > position) {
mFavoriteSubscribedSubredditData.get(position).setFavorite(true);
}
@@ -333,7 +333,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
@Override
public void failed() {
Toast.makeText(mContext, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show();
- int position = viewHolder.getAdapterPosition() - 1;
+ int position = viewHolder.getBindingAdapterPosition() - 1;
if(position >= 0 && mFavoriteSubscribedSubredditData.size() > position) {
mFavoriteSubscribedSubredditData.get(position).setFavorite(false);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java
index 5275cb87..7bb69a76 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java
@@ -146,7 +146,9 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
mGlide.clear(mImageView);
}
- adapter.addUser(accountName, getArguments().getString(EXTRA_ACCOUNT_PROFILE_IMAGE_URL));
+ if (accessToken != null) {
+ adapter.addUser(accountName, getArguments().getString(EXTRA_ACCOUNT_PROFILE_IMAGE_URL));
+ }
adapter.setSubscribedSubreddits(subscribedSubredditData);
});
diff --git a/app/src/main/res/layout/activity_anonymous_subscriptions.xml b/app/src/main/res/layout/activity_anonymous_subscriptions.xml
new file mode 100644
index 00000000..85473583
--- /dev/null
+++ b/app/src/main/res/layout/activity_anonymous_subscriptions.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/coordinator_layout_anonymous_subscriptions_activity"
+ tools:context=".activities.AnonymousSubscriptionsActivity">
+
+ <com.google.android.material.appbar.AppBarLayout
+ android:id="@+id/appbar_layout_anonymous_subscriptions_activity"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:theme="@style/AppTheme.AppBarOverlay">
+
+ <com.google.android.material.appbar.CollapsingToolbarLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layout_scrollFlags="scroll|enterAlways"
+ app:titleEnabled="false"
+ app:toolbarId="@+id/toolbar_subreddit_selection_activity">
+
+ <androidx.appcompat.widget.Toolbar
+ android:id="@+id/toolbar_anonymous_subscriptions_activity"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?attr/actionBarSize"
+ app:popupTheme="@style/AppTheme.PopupOverlay"
+ app:navigationIcon="?attr/homeAsUpIndicator" />
+
+ </com.google.android.material.appbar.CollapsingToolbarLayout>
+
+ </com.google.android.material.appbar.AppBarLayout>
+
+ <FrameLayout
+ android:id="@+id/frame_layout_anonymous_subscriptions_activity"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layout_behavior="@string/appbar_scrolling_view_behavior" />
+
+</androidx.coordinatorlayout.widget.CoordinatorLayout> \ No newline at end of file