diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-07-10 07:59:47 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-07-10 07:59:47 +0000 |
commit | bc91260e8a36524294c635970051f902ed533cfc (patch) | |
tree | 242b21381204700ece2eb6a7e7665633ec3d13b5 /app/src/main | |
parent | 117a33be3b3c112bcde45fce3974851a8ae58c47 (diff) | |
download | infinity-for-reddit-bc91260e8a36524294c635970051f902ed533cfc.tar infinity-for-reddit-bc91260e8a36524294c635970051f902ed533cfc.tar.gz infinity-for-reddit-bc91260e8a36524294c635970051f902ed533cfc.tar.bz2 infinity-for-reddit-bc91260e8a36524294c635970051f902ed533cfc.tar.lz infinity-for-reddit-bc91260e8a36524294c635970051f902ed533cfc.tar.xz infinity-for-reddit-bc91260e8a36524294c635970051f902ed533cfc.tar.zst infinity-for-reddit-bc91260e8a36524294c635970051f902ed533cfc.zip |
Place all the subscribed subreddits and users to SubscribedThingListingActivity instead of the navigation drawer in MainActivity.
Diffstat (limited to 'app/src/main')
20 files changed, 602 insertions, 136 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 744a48ea..c0b81dbf 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,8 +19,17 @@ android:supportsRtl="true" android:theme="@style/AppTheme" android:usesCleartextTraffic="true"> - <activity android:name=".PostTextActivity" - android:label="@string/post_text_activity" + <activity android:name=".SubscribedThingListingActivity" + android:label="@string/subscriptions" + android:parentActivityName=".MainActivity" + android:theme="@style/AppTheme.NoActionBar" /> + <activity + android:name=".SubredditSelectionActivity" + android:label="@string/subreddit_selection_activity_label" + android:parentActivityName=".MainActivity" /> + <activity + android:name=".PostTextActivity" + android:label="@string/post_text_activity_label" android:parentActivityName=".MainActivity" /> <activity android:name=".CommentActivity" 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()) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index f0ba107e..6c30dbc2 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -58,36 +58,62 @@ </LinearLayout> + <LinearLayout + android:id="@+id/subscriptions_linear_layout_main_activity" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="?attr/selectableItemBackground" + android:clickable="true" + android:focusable="true" + android:padding="16dp"> + + <ImageView + android:layout_width="24dp" + android:layout_height="24dp" + android:layout_gravity="center_vertical" + android:layout_marginEnd="32dp" + android:src="@drawable/ic_outline_account_circle_24px" + android:tint="@color/primaryTextColor"/> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:text="@string/subscriptions" + android:textColor="@color/primaryTextColor" /> + + </LinearLayout> + <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/dividerColor" /> - <TextView - android:id="@+id/following_label_main_activity" - android:layout_width="wrap_content" + <LinearLayout + android:id="@+id/settings_linear_layout_main_activity" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_margin="16dp" - android:text="@string/following" - android:visibility="gone" /> + android:background="?attr/selectableItemBackground" + android:clickable="true" + android:focusable="true" + android:padding="16dp"> - <androidx.recyclerview.widget.RecyclerView - android:id="@+id/subscribed_user_recycler_view_main_activity" - android:layout_width="match_parent" - android:layout_height="wrap_content" /> + <ImageView + android:layout_width="24dp" + android:layout_height="24dp" + android:layout_gravity="center_vertical" + android:layout_marginEnd="32dp" + android:src="@drawable/ic_outline_account_circle_24px" + android:tint="@color/primaryTextColor"/> - <TextView - android:id="@+id/subscriptions_label_main_activity" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_margin="16dp" - android:text="@string/subscriptions" - android:visibility="gone" /> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:text="@string/settings" + android:textColor="@color/primaryTextColor" /> - <androidx.recyclerview.widget.RecyclerView - android:id="@+id/subscribed_subreddit_recycler_view_main_activity" - android:layout_width="match_parent" - android:layout_height="wrap_content" /> + </LinearLayout> </LinearLayout> diff --git a/app/src/main/res/layout/activity_post_text.xml b/app/src/main/res/layout/activity_post_text.xml index cb08e1f2..9bc76c10 100644 --- a/app/src/main/res/layout/activity_post_text.xml +++ b/app/src/main/res/layout/activity_post_text.xml @@ -8,7 +8,8 @@ <androidx.core.widget.NestedScrollView android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:fillViewport="true"> <LinearLayout android:layout_width="match_parent" @@ -28,8 +29,7 @@ android:layout_width="24dp" android:layout_height="24dp" android:layout_alignParentStart="true" - android:layout_centerVertical="true" - android:src="@drawable/subreddit_default_icon" /> + android:layout_centerVertical="true" /> <TextView android:id="@+id/subreddit_name_text_view_post_text_activity" @@ -78,7 +78,7 @@ <EditText android:id="@+id/post_text_content_edit_text_post_text_activity" android:layout_width="match_parent" - android:layout_height="wrap_content" + android:layout_height="match_parent" android:gravity="top" android:padding="16dp" android:hint="@string/post_text_content_hint" diff --git a/app/src/main/res/layout/activity_subreddit_selection.xml b/app/src/main/res/layout/activity_subreddit_selection.xml new file mode 100644 index 00000000..bb8b13b8 --- /dev/null +++ b/app/src/main/res/layout/activity_subreddit_selection.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.constraintlayout.widget.ConstraintLayout 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" + tools:context=".SubredditSelectionActivity"> + + <androidx.recyclerview.widget.RecyclerView + android:id="@+id/recycler_view_subreddit_selection_activity" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + +</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/activity_subscribed_thing_listing.xml b/app/src/main/res/layout/activity_subscribed_thing_listing.xml new file mode 100644 index 00000000..e0d3c8ee --- /dev/null +++ b/app/src/main/res/layout/activity_subscribed_thing_listing.xml @@ -0,0 +1,45 @@ +<?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" + tools:context=".SubscribedThingListingActivity"> + + <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar_subscribed_thing_listing_activity" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:theme="@style/AppTheme.AppBarOverlay"> + + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar_subscribed_thing_listing_activity" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + android:background="?attr/colorPrimary" + app:popupTheme="@style/AppTheme.PopupOverlay" /> + + <com.google.android.material.tabs.TabLayout + android:id="@+id/tab_layout_subscribed_thing_listing_activity" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@color/colorPrimary" + app:tabGravity="fill" + app:tabMode="fixed" + app:tabIndicatorColor="@android:color/white" + app:tabIndicatorHeight="3dp" + app:tabSelectedTextColor="@android:color/white" + app:tabTextColor="@android:color/white" + app:tabRippleColor="?attr/colorControlHighlight" + app:tabUnboundedRipple="false" /> + + </com.google.android.material.appbar.AppBarLayout> + + <androidx.viewpager.widget.ViewPager + android:id="@+id/view_pager_subscribed_thing_listing_activity" + android:layout_width="match_parent" + android:layout_height="match_parent" + app:layout_behavior="@string/appbar_scrolling_view_behavior" + tools:context=".SubscribedThingListingActivity" /> + +</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/fragment_followed_users_listing.xml b/app/src/main/res/layout/fragment_followed_users_listing.xml new file mode 100644 index 00000000..7e0c58f3 --- /dev/null +++ b/app/src/main/res/layout/fragment_followed_users_listing.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".FollowedUsersListingFragment"> + + <androidx.recyclerview.widget.RecyclerView + android:id="@+id/recycler_view_followed_users_listing_fragment" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + + <LinearLayout + android:id="@+id/no_subscriptions_linear_layout_followed_users_listing_fragment" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center" + android:orientation="vertical" + android:visibility="gone"> + + <ImageView + android:id="@+id/no_subscriptions_image_view_followed_users_listing_fragment" + android:layout_width="150dp" + android:layout_height="wrap_content" /> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="16dp" + android:gravity="center" /> + + </LinearLayout> + +</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/fragment_subscribed_subreddits_listing.xml b/app/src/main/res/layout/fragment_subscribed_subreddits_listing.xml new file mode 100644 index 00000000..b493d50b --- /dev/null +++ b/app/src/main/res/layout/fragment_subscribed_subreddits_listing.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".SubscribedSubredditsListingFragment"> + + <androidx.recyclerview.widget.RecyclerView + android:id="@+id/recycler_view_subscribed_subreddits_listing_fragment" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + + <LinearLayout + android:id="@+id/no_subscriptions_linear_layout_subreddits_listing_fragment" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center" + android:orientation="vertical" + android:visibility="gone"> + + <ImageView + android:id="@+id/no_subscriptions_image_view_subreddits_listing_fragment" + android:layout_width="150dp" + android:layout_height="wrap_content" /> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="16dp" + android:gravity="center" /> + + </LinearLayout> + +</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/item_subscribed_thing.xml b/app/src/main/res/layout/item_subscribed_thing.xml index 0f4afc20..d7ede059 100644 --- a/app/src/main/res/layout/item_subscribed_thing.xml +++ b/app/src/main/res/layout/item_subscribed_thing.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <LinearLayout - xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:clickable="true" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 726e34b6..effd81dc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,7 +4,8 @@ <string name="search_activity_label">Search</string> <string name="comment_activity_label">Add Comment</string> <string name="comment_activity_label_is_replying">Reply</string> - <string name="post_text_activity">Text Post</string> + <string name="post_text_activity_label">Text Post</string> + <string name="subreddit_selection_activity_label">Select a Subreddit</string> <string name="navigation_drawer_open">Open navigation drawer</string> <string name="navigation_drawer_close">Close navigation drawer</string> @@ -41,6 +42,7 @@ <string name="profile">Profile</string> <string name="following">Following</string> <string name="subscriptions">Subscriptions</string> + <string name="settings">Settings</string> <string name="subscribers_number_detail">Subscribers: %1$d</string> <string name="online_subscribers_number_detail">Online: %1$d</string> <string name="cannot_fetch_subreddit_info">Cannot fetch subreddit info</string> @@ -91,4 +93,7 @@ <string name="post_url_hint">URL</string> <string name="choose_a_subreddit">Choose a subreddit</string> <string name="rules">Rules</string> + + <string name="subreddits">Subreddits</string> + <string name="users">Users</string> </resources> |