aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FollowedUsersListingFragment.java76
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java90
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java19
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java53
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsListingFragment.java77
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsRecyclerViewAdapter.java (renamed from app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRecyclerViewAdapter.java)18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java153
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java9
11 files changed, 405 insertions, 107 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index e496140a..aa906d2a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -16,4 +16,5 @@ interface AppComponent {
void inject(ViewSubredditDetailActivity viewSubredditDetailActivity);
void inject(ViewUserDetailActivity viewUserDetailActivity);
void inject(CommentActivity commentActivity);
+ void inject(SubscribedThingListingActivity subscribedThingListingActivity);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FollowedUsersListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FollowedUsersListingFragment.java
new file mode 100644
index 00000000..9e64ae04
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FollowedUsersListingFragment.java
@@ -0,0 +1,76 @@
+package ml.docilealligator.infinityforreddit;
+
+
+import android.app.Activity;
+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 androidx.fragment.app.Fragment;
+import androidx.lifecycle.ViewModelProviders;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.RequestManager;
+
+import SubscribedUserDatabase.SubscribedUserViewModel;
+import butterknife.BindView;
+import butterknife.ButterKnife;
+
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class FollowedUsersListingFragment extends Fragment {
+
+ @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;
+
+ private Activity mActivity;
+
+ private RequestManager mGlide;
+
+ private SubscribedUserViewModel mSubscribedUserViewModel;
+
+ public FollowedUsersListingFragment() {
+ // 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);
+
+ mActivity = getActivity();
+
+ mGlide = Glide.with(this);
+
+ mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
+ SubscribedUserRecyclerViewAdapter adapter = new SubscribedUserRecyclerViewAdapter(mActivity);
+ mRecyclerView.setAdapter(adapter);
+
+ mSubscribedUserViewModel = ViewModelProviders.of(this).get(SubscribedUserViewModel.class);
+ mSubscribedUserViewModel.getAllSubscribedUsers().observe(this, subscribedUserData -> {
+ if (subscribedUserData == null || subscribedUserData.size() == 0) {
+ mRecyclerView.setVisibility(View.GONE);
+ mLinearLayout.setVisibility(View.VISIBLE);
+ mGlide.load(R.drawable.load_post_error_indicator).into(mImageView);
+ } else {
+ mLinearLayout.setVisibility(View.GONE);
+ mRecyclerView.setVisibility(View.VISIBLE);
+ }
+ adapter.setSubscribedUsers(subscribedUserData);
+ });
+
+ return rootView;
+ }
+
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
index 4bc6870d..a711091c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
@@ -19,9 +19,6 @@ import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
-import androidx.lifecycle.ViewModelProviders;
-import androidx.recyclerview.widget.LinearLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
@@ -31,19 +28,9 @@ import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
-import java.util.ArrayList;
-
import javax.inject.Inject;
import javax.inject.Named;
-import SubredditDatabase.SubredditData;
-import SubredditDatabase.SubredditRoomDatabase;
-import SubscribedSubredditDatabase.SubscribedSubredditData;
-import SubscribedSubredditDatabase.SubscribedSubredditRoomDatabase;
-import SubscribedSubredditDatabase.SubscribedSubredditViewModel;
-import SubscribedUserDatabase.SubscribedUserData;
-import SubscribedUserDatabase.SubscribedUserRoomDatabase;
-import SubscribedUserDatabase.SubscribedUserViewModel;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
@@ -63,11 +50,9 @@ public class MainActivity extends AppCompatActivity {
@BindView(R.id.collapsing_toolbar_layout_main_activity) CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.search_view_main_activity) SimpleSearchView simpleSearchView;
@BindView(R.id.transparent_overlay_main_activity) View transparentOverlay;
- @BindView(R.id.subscribed_subreddit_recycler_view_main_activity) RecyclerView subscribedSubredditRecyclerView;
- @BindView(R.id.subscriptions_label_main_activity) TextView subscriptionsLabelTextView;
- @BindView(R.id.subscribed_user_recycler_view_main_activity) RecyclerView subscribedUserRecyclerView;
- @BindView(R.id.following_label_main_activity) TextView followingLabelTextView;
@BindView(R.id.profile_linear_layout_main_activity) LinearLayout profileLinearLayout;
+ @BindView(R.id.subscriptions_linear_layout_main_activity) LinearLayout subscriptionLinearLayout;
+ @BindView(R.id.settings_linear_layout_main_activity) LinearLayout settingsLinearLayout;
@BindView(R.id.fab_main_activity) FloatingActionButton fab;
private TextView mNameTextView;
@@ -84,13 +69,9 @@ public class MainActivity extends AppCompatActivity {
private String mBannerImageUrl;
private String mKarma;
private boolean mFetchUserInfoSuccess = false;
- private boolean mInsertSuccess = false;
private Menu mMenu;
- private SubscribedSubredditViewModel mSubscribedSubredditViewModel;
- private SubscribedUserViewModel mSubscribedUserViewModel;
-
private boolean isInLazyMode = false;
@Inject
@@ -109,6 +90,7 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+
ButterKnife.bind(this);
((Infinity) getApplication()).getmAppComponent().inject(this);
@@ -184,7 +166,6 @@ public class MainActivity extends AppCompatActivity {
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_content_main, mFragment).commit();
mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE);
- mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE);
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
}
@@ -198,12 +179,6 @@ public class MainActivity extends AppCompatActivity {
loadUserData();
- subscribedSubredditRecyclerView.setLayoutManager(new LinearLayoutManager(this));
- subscribedSubredditRecyclerView.setNestedScrollingEnabled(false);
-
- subscribedUserRecyclerView.setLayoutManager(new LinearLayoutManager(this));
- subscribedUserRecyclerView.setNestedScrollingEnabled(false);
-
mName = getSharedPreferences(SharedPreferencesUtils.USER_INFO_FILE_KEY, Context.MODE_PRIVATE).getString(SharedPreferencesUtils.USER_KEY, "");
mProfileImageUrl = getSharedPreferences(SharedPreferencesUtils.USER_INFO_FILE_KEY, Context.MODE_PRIVATE).getString(SharedPreferencesUtils.PROFILE_IMAGE_URL_KEY, "");
mBannerImageUrl = getSharedPreferences(SharedPreferencesUtils.USER_INFO_FILE_KEY, Context.MODE_PRIVATE).getString(SharedPreferencesUtils.BANNER_IMAGE_URL_KEY, "");
@@ -229,37 +204,18 @@ public class MainActivity extends AppCompatActivity {
}
profileLinearLayout.setOnClickListener(view -> {
- Intent intent = new Intent(MainActivity.this, ViewUserDetailActivity.class);
+ Intent intent = new Intent(this, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mName);
startActivity(intent);
});
- final SubscribedSubredditRecyclerViewAdapter subredditadapter =
- new SubscribedSubredditRecyclerViewAdapter(this, drawer::closeDrawers);
- subscribedSubredditRecyclerView.setAdapter(subredditadapter);
-
- mSubscribedSubredditViewModel = ViewModelProviders.of(this).get(SubscribedSubredditViewModel.class);
- mSubscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this, subscribedSubredditData -> {
- if (subscribedSubredditData == null || subscribedSubredditData.size() == 0) {
- subscriptionsLabelTextView.setVisibility(View.GONE);
- } else {
- subscriptionsLabelTextView.setVisibility(View.VISIBLE);
- }
-
- subredditadapter.setSubscribedSubreddits(subscribedSubredditData);
+ subscriptionLinearLayout.setOnClickListener(view -> {
+ Intent intent = new Intent(this, SubscribedThingListingActivity.class);
+ startActivity(intent);
});
- final SubscribedUserRecyclerViewAdapter userAdapter =
- new SubscribedUserRecyclerViewAdapter(this, drawer::closeDrawers);
- subscribedUserRecyclerView.setAdapter(userAdapter);
- mSubscribedUserViewModel = ViewModelProviders.of(this).get(SubscribedUserViewModel.class);
- mSubscribedUserViewModel.getAllSubscribedUsers().observe(this, subscribedUserData -> {
- if (subscribedUserData == null || subscribedUserData.size() == 0) {
- followingLabelTextView.setVisibility(View.GONE);
- } else {
- followingLabelTextView.setVisibility(View.VISIBLE);
- }
- userAdapter.setSubscribedUsers(subscribedUserData);
+ settingsLinearLayout.setOnClickListener(view -> {
+
});
}
@@ -322,32 +278,6 @@ public class MainActivity extends AppCompatActivity {
}
});
}
-
- if (!mInsertSuccess) {
- FetchSubscribedThing.fetchSubscribedThing(mOauthRetrofit, mAuthInfoSharedPreferences, null,
- new ArrayList<>(), new ArrayList<>(),
- new ArrayList<>(),
- new FetchSubscribedThing.FetchSubscribedThingListener() {
- @Override
- public void onFetchSubscribedThingSuccess(ArrayList<SubscribedSubredditData> subscribedSubredditData,
- ArrayList<SubscribedUserData> subscribedUserData,
- ArrayList<SubredditData> subredditData) {
- new InsertSubscribedThingsAsyncTask(
- SubscribedSubredditRoomDatabase.getDatabase(MainActivity.this).subscribedSubredditDao(),
- SubscribedUserRoomDatabase.getDatabase(MainActivity.this).subscribedUserDao(),
- SubredditRoomDatabase.getDatabase(MainActivity.this).subredditDao(),
- subscribedSubredditData,
- subscribedUserData,
- subredditData,
- () -> mInsertSuccess = true).execute();
- }
-
- @Override
- public void onFetchSubscribedThingFail() {
- mInsertSuccess = false;
- }
- });
- }
}
@Override
@@ -391,7 +321,6 @@ public class MainActivity extends AppCompatActivity {
case R.id.action_refresh_main_activity:
((FragmentCommunicator) mFragment).refresh();
mFetchUserInfoSuccess = false;
- mInsertSuccess = false;
loadUserData();
return true;
case R.id.action_lazy_mode_main_activity:
@@ -437,7 +366,6 @@ public class MainActivity extends AppCompatActivity {
}
outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess);
- outState.putBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE, mInsertSuccess);
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
index d14944c1..e91d2ab9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
@@ -25,7 +25,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.RecyclerView;
-import com.bumptech.glide.Glide;
+import com.bumptech.glide.RequestManager;
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
import org.greenrobot.eventbus.EventBus;
@@ -55,6 +55,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@BindView(R.id.fetch_post_info_image_view_post_fragment) ImageView mFetchPostInfoImageView;
@BindView(R.id.fetch_post_info_text_view_post_fragment) TextView mFetchPostInfoTextView;
+ private RequestManager glide;
+
private Activity activity;
private LinearLayoutManager mLinearLayoutManager;
@@ -253,7 +255,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if(activity != null && isAdded()) {
mFetchPostInfoLinearLayout.setVisibility(View.VISIBLE);
mFetchPostInfoTextView.setText(stringResId);
- Glide.with(this).load(R.drawable.load_post_error_indicator).into(mFetchPostInfoImageView);
+ glide.load(R.drawable.load_post_error_indicator).into(mFetchPostInfoImageView);
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java
index d7aa6e1d..d499dae4 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java
@@ -1,5 +1,6 @@
package ml.docilealligator.infinityforreddit;
+import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.MenuItem;
@@ -11,8 +12,13 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.RequestManager;
+import com.bumptech.glide.request.RequestOptions;
+
import butterknife.BindView;
import butterknife.ButterKnife;
+import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import pl.droidsonroids.gif.GifImageView;
public class PostTextActivity extends AppCompatActivity {
@@ -25,6 +31,8 @@ public class PostTextActivity extends AppCompatActivity {
@BindView(R.id.post_title_edit_text_post_text_activity) EditText titleEditText;
@BindView(R.id.post_text_content_edit_text_post_text_activity) EditText contentEditText;
+ private RequestManager mGlide;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -36,9 +44,20 @@ public class PostTextActivity extends AppCompatActivity {
Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
actionBar.setHomeAsUpIndicator(upArrow);
+ mGlide = Glide.with(this);
+
if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
subreditNameTextView.setText(getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME));
+ } else {
+ mGlide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .into(iconGifImageView);
}
+
+ subreditNameTextView.setOnClickListener(view -> {
+ Intent intent = new Intent(this, SubredditSelectionActivity.class);
+ startActivity(intent);
+ });
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java
index 51244e44..38147cb7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java
@@ -7,9 +7,6 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import com.ferfalk.simplesearchview.SimpleSearchView;
-import com.google.android.material.tabs.TabLayout;
-
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
@@ -17,6 +14,10 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
+
+import com.ferfalk.simplesearchview.SimpleSearchView;
+import com.google.android.material.tabs.TabLayout;
+
import butterknife.BindView;
import butterknife.ButterKnife;
@@ -37,6 +38,7 @@ public class SearchActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
+
ButterKnife.bind(this);
setSupportActionBar(toolbar);
@@ -141,7 +143,7 @@ public class SearchActivity extends AppCompatActivity {
super.onBackPressed();
}
- public class SectionsPagerAdapter extends FragmentPagerAdapter {
+ private class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment postFragment;
private SubredditListingFragment subredditListingFragment;
private UserListingFragment userListingFragment;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java
new file mode 100644
index 00000000..25569eb5
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java
@@ -0,0 +1,53 @@
+package ml.docilealligator.infinityforreddit;
+
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.view.MenuItem;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.lifecycle.ViewModelProviders;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import SubscribedSubredditDatabase.SubscribedSubredditViewModel;
+import butterknife.BindView;
+import butterknife.ButterKnife;
+
+public class SubredditSelectionActivity extends AppCompatActivity {
+
+ @BindView(R.id.recycler_view_subreddit_selection_activity) RecyclerView recyclerView;
+
+ private SubscribedSubredditViewModel mSubscribedSubredditViewModel;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_subreddit_selection);
+
+ ButterKnife.bind(this);
+
+ ActionBar actionBar = getSupportActionBar();
+ Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
+ actionBar.setHomeAsUpIndicator(upArrow);
+
+ recyclerView.setLayoutManager(new LinearLayoutManager(this));
+ SubscribedSubredditsRecyclerViewAdapter adapter = new SubscribedSubredditsRecyclerViewAdapter(this);
+ recyclerView.setAdapter(adapter);
+
+ mSubscribedSubredditViewModel = ViewModelProviders.of(this).get(SubscribedSubredditViewModel.class);
+ mSubscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this, adapter::setSubscribedSubreddits);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ return true;
+ }
+
+ return false;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsListingFragment.java
new file mode 100644
index 00000000..6dd8d4fa
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsListingFragment.java
@@ -0,0 +1,77 @@
+package ml.docilealligator.infinityforreddit;
+
+
+import android.app.Activity;
+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 androidx.fragment.app.Fragment;
+import androidx.lifecycle.ViewModelProviders;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.RequestManager;
+
+import SubscribedSubredditDatabase.SubscribedSubredditViewModel;
+import butterknife.BindView;
+import butterknife.ButterKnife;
+
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class SubscribedSubredditsListingFragment extends Fragment {
+
+ @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;
+
+ private Activity mActivity;
+
+ private RequestManager mGlide;
+
+ private SubscribedSubredditViewModel mSubscribedSubredditViewModel;
+
+ private boolean mInsertSuccess = false;
+
+ public SubscribedSubredditsListingFragment() {
+ // Required empty public constructor
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = inflater.inflate(R.layout.fragment_subscribed_subreddits_listing, container, false);
+
+ ButterKnife.bind(this, rootView);
+
+ mActivity = getActivity();
+
+ mGlide = Glide.with(this);
+
+ mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
+ SubscribedSubredditsRecyclerViewAdapter adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity);
+ mRecyclerView.setAdapter(adapter);
+
+ mSubscribedSubredditViewModel = ViewModelProviders.of(this).get(SubscribedSubredditViewModel.class);
+ mSubscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this, subscribedSubredditData -> {
+ if (subscribedSubredditData == null || subscribedSubredditData.size() == 0) {
+ mRecyclerView.setVisibility(View.GONE);
+ mLinearLayout.setVisibility(View.VISIBLE);
+ mGlide.load(R.drawable.load_post_error_indicator).into(mImageView);
+ } else {
+ mLinearLayout.setVisibility(View.GONE);
+ mRecyclerView.setVisibility(View.VISIBLE);
+ }
+
+ adapter.setSubscribedSubreddits(subscribedSubredditData);
+ });
+
+ return rootView;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsRecyclerViewAdapter.java
index 521086da..f3bdb63b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsRecyclerViewAdapter.java
@@ -7,6 +7,9 @@ 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;
@@ -14,25 +17,17 @@ import com.bumptech.glide.request.RequestOptions;
import java.util.List;
import SubscribedSubredditDatabase.SubscribedSubredditData;
-import androidx.annotation.NonNull;
-import androidx.recyclerview.widget.RecyclerView;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import pl.droidsonroids.gif.GifImageView;
-class SubscribedSubredditRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
+class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context mContext;
private List<SubscribedSubredditData> mSubscribedSubredditData;
private RequestManager glide;
- private OnItemClickListener mOnItemClickListener;
-
- interface OnItemClickListener {
- void onClick();
- }
- SubscribedSubredditRecyclerViewAdapter(Context context, OnItemClickListener onItemClickListener) {
+ SubscribedSubredditsRecyclerViewAdapter(Context context) {
mContext = context;
glide = Glide.with(context.getApplicationContext());
- mOnItemClickListener = onItemClickListener;
}
@NonNull
@@ -45,7 +40,6 @@ class SubscribedSubredditRecyclerViewAdapter extends RecyclerView.Adapter<Recycl
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, final int i) {
viewHolder.itemView.setOnClickListener(view -> {
if(viewHolder.getAdapterPosition() >= 0) {
- mOnItemClickListener.onClick();
Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, mSubscribedSubredditData.get(viewHolder.getAdapterPosition()).getName());
mContext.startActivity(intent);
@@ -88,7 +82,7 @@ class SubscribedSubredditRecyclerViewAdapter extends RecyclerView.Adapter<Recycl
private final GifImageView iconGifImageView;
private final TextView subredditNameTextView;
- public SubredditViewHolder(View itemView) {
+ SubredditViewHolder(View itemView) {
super(itemView);
iconGifImageView = itemView.findViewById(R.id.subreddit_icon_gif_image_view_item_subscribed_subreddit);
subredditNameTextView = itemView.findViewById(R.id.subreddit_name_text_view_item_subscribed_subreddit);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java
new file mode 100644
index 00000000..1ae1327e
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java
@@ -0,0 +1,153 @@
+package ml.docilealligator.infinityforreddit;
+
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.widget.Toolbar;
+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.tabs.TabLayout;
+
+import java.util.ArrayList;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import SubredditDatabase.SubredditData;
+import SubredditDatabase.SubredditRoomDatabase;
+import SubscribedSubredditDatabase.SubscribedSubredditData;
+import SubscribedSubredditDatabase.SubscribedSubredditRoomDatabase;
+import SubscribedUserDatabase.SubscribedUserData;
+import SubscribedUserDatabase.SubscribedUserRoomDatabase;
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import retrofit2.Retrofit;
+
+public class SubscribedThingListingActivity extends AppCompatActivity {
+
+ private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
+
+ @BindView(R.id.toolbar_subscribed_thing_listing_activity) Toolbar toolbar;
+ @BindView(R.id.tab_layout_subscribed_thing_listing_activity) TabLayout tabLayout;
+ @BindView(R.id.view_pager_subscribed_thing_listing_activity) ViewPager viewPager;
+
+ private boolean mInsertSuccess = false;
+
+ private SectionsPagerAdapter sectionsPagerAdapter;
+
+ @Inject
+ @Named("auth_info")
+ SharedPreferences mAuthInfoSharedPreferences;
+
+ @Inject
+ @Named("oauth")
+ Retrofit mOauthRetrofit;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_subscribed_thing_listing);
+
+ ButterKnife.bind(this);
+
+ ((Infinity) getApplication()).getmAppComponent().inject(this);
+
+ setSupportActionBar(toolbar);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+
+ sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
+ viewPager.setAdapter(sectionsPagerAdapter);
+ viewPager.setOffscreenPageLimit(2);
+ tabLayout.setupWithViewPager(viewPager);
+
+ if(savedInstanceState != null) {
+ mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE);
+ }
+
+ loadSubscriptions();
+ }
+
+ @Override
+ protected void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE, mInsertSuccess);
+ }
+
+ private void loadSubscriptions() {
+ if (!mInsertSuccess) {
+ FetchSubscribedThing.fetchSubscribedThing(mOauthRetrofit, mAuthInfoSharedPreferences, null,
+ new ArrayList<>(), new ArrayList<>(),
+ new ArrayList<>(),
+ new FetchSubscribedThing.FetchSubscribedThingListener() {
+ @Override
+ public void onFetchSubscribedThingSuccess(ArrayList<SubscribedSubredditData> subscribedSubredditData,
+ ArrayList<SubscribedUserData> subscribedUserData,
+ ArrayList<SubredditData> subredditData) {
+ new InsertSubscribedThingsAsyncTask(
+ SubscribedSubredditRoomDatabase.getDatabase(SubscribedThingListingActivity.this).subscribedSubredditDao(),
+ SubscribedUserRoomDatabase.getDatabase(SubscribedThingListingActivity.this).subscribedUserDao(),
+ SubredditRoomDatabase.getDatabase(SubscribedThingListingActivity.this).subredditDao(),
+ subscribedSubredditData,
+ subscribedUserData,
+ subredditData,
+ () -> mInsertSuccess = true).execute();
+ }
+
+ @Override
+ public void onFetchSubscribedThingFail() {
+ mInsertSuccess = false;
+ }
+ });
+ }
+ }
+
+ private class SectionsPagerAdapter extends FragmentPagerAdapter {
+
+ public SectionsPagerAdapter(FragmentManager fm) {
+ super(fm);
+ }
+
+ @NonNull
+ @Override
+ public Fragment getItem(int position) {
+ switch (position) {
+ case 0: {
+ return new SubscribedSubredditsListingFragment();
+ }
+ default:
+ {
+ return new FollowedUsersListingFragment();
+ }
+ }
+ }
+
+ @Override
+ public int getCount() {
+ return 2;
+ }
+
+ @Override
+ public CharSequence getPageTitle(int position) {
+ switch (position) {
+ case 0:
+ return getString(R.string.subreddits);
+ case 1:
+ return getString(R.string.users);
+ }
+
+ return null;
+ }
+
+ @NonNull
+ @Override
+ public Object instantiateItem(@NonNull ViewGroup container, int position) {
+ return super.instantiateItem(container, position);
+ }
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java
index 84e70cbd..68c040b0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java
@@ -24,16 +24,10 @@ public class SubscribedUserRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private List<SubscribedUserData> mSubscribedUserData;
private Context mContext;
private RequestManager glide;
- private OnItemClickListener mOnItemClickListener;
- public interface OnItemClickListener {
- void onClick();
- }
-
- SubscribedUserRecyclerViewAdapter(Context context, OnItemClickListener onItemClickListener) {
+ SubscribedUserRecyclerViewAdapter(Context context) {
mContext = context;
glide = Glide.with(context.getApplicationContext());
- mOnItemClickListener = onItemClickListener;
}
@NonNull
@@ -48,7 +42,6 @@ public class SubscribedUserRecyclerViewAdapter extends RecyclerView.Adapter<Recy
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mSubscribedUserData.get(viewHolder.getAdapterPosition()).getName());
mContext.startActivity(intent);
- mOnItemClickListener.onClick();
});
if(!mSubscribedUserData.get(i).getIconUrl().equals("")) {
glide.load(mSubscribedUserData.get(i).getIconUrl())