diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml index 1d145e97..144d0da4 100644 --- a/.idea/assetWizardSettings.xml +++ b/.idea/assetWizardSettings.xml @@ -35,9 +35,9 @@ - + - + diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 7c7ab195..dae89535 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8f7d4e15..fad66b16 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,6 +20,9 @@ android:supportsRtl="true" android:theme="@style/AppTheme" android:usesCleartextTraffic="true"> + = Build.VERSION_CODES.O_MR1 + && (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT + || resources.getBoolean(R.bool.isTablet))) { + Window window = getWindow(); + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + + boolean lightNavBar = false; + if((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + lightNavBar = true; + } + boolean finalLightNavBar = lightNavBar; + + View decorView = window.getDecorView(); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { + @Override + void onStateChanged(AppBarLayout appBarLayout, State state) { + if (state == State.COLLAPSED) { + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + } else if (state == State.EXPANDED) { + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + } + } + }); + + int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); + if (statusBarResourceId > 0) { + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams(); + params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId); + toolbar.setLayoutParams(params); + } + } + + mUserWhere = getIntent().getExtras().getString(EXTRA_USER_WHERE); + if(mUserWhere.equals(PostDataSource.USER_WHERE_UPVOTED)) { + toolbar.setTitle(R.string.upvoted); + } else if(mUserWhere.equals(PostDataSource.USER_WHERE_DOWNVOTED)) { + toolbar.setTitle(R.string.downvoted); + } else if(mUserWhere.equals(PostDataSource.USER_WHERE_SAVED)) { + toolbar.setTitle(R.string.saved); + } else if(mUserWhere.equals(PostDataSource.USER_WHERE_HIDDEN)) { + toolbar.setTitle(R.string.hidden); + } else if(mUserWhere.equals(PostDataSource.USER_WHERE_GILDED)){ + toolbar.setTitle(R.string.gilded); + } + + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + if(savedInstanceState != null) { + mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); + mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE); + mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE); + if(!mNullAccessToken && mAccessToken == null) { + getCurrentAccountAndBindView(); + } else { + mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE); + getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_account_posts_activity, mFragment).commit(); + initializeFragment(); + } + } else { + getCurrentAccountAndBindView(); + } + } + + private void getCurrentAccountAndBindView() { + new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { + if(account == null) { + mNullAccessToken = true; + } else { + mAccessToken = account.getAccessToken(); + mAccountName = account.getUsername(); + } + initializeFragment(); + }).execute(); + } + + private void initializeFragment() { + mFragment = new PostFragment(); + Bundle bundle = new Bundle(); + bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER); + bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName); + bundle.putString(PostFragment.EXTRA_USER_WHERE, mUserWhere); + bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_NEW); + bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER); + bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); + mFragment.setArguments(bundle); + getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_account_posts_activity, mFragment).commit(); + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if(item.getItemId() == android.R.id.home) { + finish(); + return true; + } + return false; + } + + @Override + protected void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + if (mFragment != null) { + getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment); + } + outState.putString(ACCESS_TOKEN_STATE, mAccessToken); + outState.putString(ACCOUNT_NAME_STATE, mAccountName); + outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 95c16c0a..11ced525 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -33,4 +33,5 @@ interface AppComponent { void inject(SubredditSelectionActivity subredditSelectionActivity); void inject(EditPostActivity editPostActivity); void inject(EditCommentActivity editCommentActivity); + void inject(AccountPostsActivity accountPostsActivity); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index 45474c64..da2a7a02 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -279,7 +279,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + Intent intent = new Intent(MainActivity.this, AccountPostsActivity.class); + intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_UPVOTED); + startActivity(intent); + drawer.closeDrawers(); + }); + + downvotedLinearLayout.setOnClickListener(view -> { + Intent intent = new Intent(MainActivity.this, AccountPostsActivity.class); + intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_DOWNVOTED); + startActivity(intent); + drawer.closeDrawers(); + }); + + hiddenLinearLayout.setOnClickListener(view -> { + Intent intent = new Intent(MainActivity.this, AccountPostsActivity.class); + intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_HIDDEN); + startActivity(intent); + drawer.closeDrawers(); + }); + + savedLinearLayout.setOnClickListener(view -> { + Intent intent = new Intent(MainActivity.this, AccountPostsActivity.class); + intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_SAVED); + startActivity(intent); + drawer.closeDrawers(); + }); + + gildedLinearLayout.setOnClickListener(view -> { + Intent intent = new Intent(MainActivity.this, AccountPostsActivity.class); + intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_GILDED); + startActivity(intent); + drawer.closeDrawers(); + }); + settingsLinearLayout.setOnClickListener(view -> { drawer.closeDrawers(); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java index e471435f..8dacfa1d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java @@ -30,6 +30,13 @@ class PostDataSource extends PageKeyedDataSource { static final String SORT_TYPE_RELEVANCE = "relevance"; static final String SORT_TYPE_COMMENTS = "comments"; + static final String USER_WHERE_SUBMITTED = "submitted"; + static final String USER_WHERE_UPVOTED = "upvoted"; + static final String USER_WHERE_DOWNVOTED = "downvoted"; + static final String USER_WHERE_HIDDEN = "hidden"; + static final String USER_WHERE_SAVED = "saved"; + static final String USER_WHERE_GILDED = "gilded"; + private Retrofit retrofit; private String accessToken; private Locale locale; @@ -38,6 +45,7 @@ class PostDataSource extends PageKeyedDataSource { private int postType; private String sortType; private int filter; + private String userWhere; private MutableLiveData paginationNetworkStateLiveData; private MutableLiveData initialLoadStateLiveData; @@ -76,7 +84,7 @@ class PostDataSource extends PageKeyedDataSource { } PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditOrUserName, int postType, - int filter) { + String sortType, String where, int filter) { this.retrofit = retrofit; this.accessToken = accessToken; this.locale = locale; @@ -85,6 +93,8 @@ class PostDataSource extends PageKeyedDataSource { initialLoadStateLiveData = new MutableLiveData<>(); hasPostLiveData = new MutableLiveData<>(); this.postType = postType; + this.sortType = sortType; + userWhere = where; this.filter = filter; } @@ -410,9 +420,10 @@ class PostDataSource extends PageKeyedDataSource { Call getPost; if(accessToken == null) { - getPost = api.getUserBestPosts(subredditOrUserName, lastItem); + getPost = api.getUserBestPosts(subredditOrUserName, lastItem, sortType); } else { - getPost = api.getUserBestPostsOauth(subredditOrUserName, lastItem, RedditUtils.getOAuthHeader(accessToken)); + getPost = api.getUserBestPostsOauth(subredditOrUserName, userWhere, lastItem, sortType, + RedditUtils.getOAuthHeader(accessToken)); } getPost.enqueue(new Callback() { @Override @@ -469,9 +480,10 @@ class PostDataSource extends PageKeyedDataSource { Call getPost; if(accessToken == null) { - getPost = api.getUserBestPosts(subredditOrUserName, after); + getPost = api.getUserBestPosts(subredditOrUserName, after, sortType); } else { - getPost = api.getUserBestPostsOauth(subredditOrUserName, after, RedditUtils.getOAuthHeader(accessToken)); + getPost = api.getUserBestPostsOauth(subredditOrUserName, userWhere, after, sortType, + RedditUtils.getOAuthHeader(accessToken)); } getPost.enqueue(new Callback() { @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java index 8c14ace6..625930e8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java @@ -15,6 +15,7 @@ class PostDataSourceFactory extends DataSource.Factory { private String query; private int postType; private String sortType; + private String userWhere; private int filter; private PostDataSource postDataSource; @@ -44,13 +45,15 @@ class PostDataSourceFactory extends DataSource.Factory { } PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, - int postType, int filter) { + int postType, String sortType, String where, int filter) { this.retrofit = retrofit; this.accessToken = accessToken; this.locale = locale; this.subredditName = subredditName; postDataSourceLiveData = new MutableLiveData<>(); this.postType = postType; + this.sortType = sortType; + userWhere = where; this.filter = filter; } @@ -80,7 +83,7 @@ class PostDataSourceFactory extends DataSource.Factory { sortType, filter); } else { postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, postType, - filter); + sortType, userWhere, filter); } postDataSourceLiveData.postValue(postDataSource); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java index cc1503ae..e9fb7bb2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java @@ -23,7 +23,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; -import androidx.lifecycle.ViewModelProviders; +import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearSmoothScroller; import androidx.recyclerview.widget.RecyclerView; @@ -50,6 +50,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { static final String EXTRA_NAME = "EN"; static final String EXTRA_USER_NAME = "EN"; + static final String EXTRA_USER_WHERE = "EUW"; static final String EXTRA_QUERY = "EQ"; static final String EXTRA_POST_TYPE = "EPT"; static final String EXTRA_SORT_TYPE = "EST"; @@ -256,6 +257,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mFetchPostInfoLinearLayout.setLayoutParams(params); String username = getArguments().getString(EXTRA_USER_NAME); + String where = getArguments().getString(EXTRA_USER_WHERE); mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, redditDataRoomDatabase, accessToken, postType, true, new PostRecyclerViewAdapter.Callback() { @@ -277,10 +279,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if(accessToken == null) { factory = new PostViewModel.Factory(mRetrofit, accessToken, - getResources().getConfiguration().locale, username, postType, sortType, filter); + getResources().getConfiguration().locale, username, postType, sortType, where, filter); } else { factory = new PostViewModel.Factory(mOauthRetrofit, accessToken, - getResources().getConfiguration().locale, username, postType, sortType, filter); + getResources().getConfiguration().locale, username, postType, sortType, where, filter); } } else { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, redditDataRoomDatabase, @@ -307,7 +309,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mPostRecyclerView.setAdapter(mAdapter); - mPostViewModel = ViewModelProviders.of(this, factory).get(PostViewModel.class); + mPostViewModel = new ViewModelProvider(this, factory).get(PostViewModel.class); mPostViewModel.getPosts().observe(this, posts -> mAdapter.submitList(posts)); mPostViewModel.getInitialLoadingState().observe(this, networkState -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index 0b71a15a..6f0cdc24 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -300,7 +300,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter getSubredditBestPosts(@Path("subredditName") String subredditName, @Path("sortType") String sortType, @Query("after") String lastItem); - @GET("user/{username}/submitted.json?raw_json=1&limit=25") - Call getUserBestPostsOauth(@Path("username") String username, @Query("after") String lastItem, - @HeaderMap Map headers); + @GET("user/{username}/{where}.json?&raw_json=1&limit=25") + Call getUserBestPostsOauth(@Path("username") String username, @Path("where") String where, + @Query("after") String lastItem, @Query("sort") String sortType, @HeaderMap Map headers); @GET("user/{username}/submitted.json?raw_json=1&limit=25") - Call getUserBestPosts(@Path("username") String username, @Query("after") String lastItem); + Call getUserBestPosts(@Path("username") String username, @Query("after") String lastItem, + @Query("sort") String sortType); @GET("user/{username}/about.json?raw_json=1") Call getUserData(@Path("username") String username); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java index ad007ae1..cd57a70a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java @@ -531,6 +531,8 @@ public class ViewUserDetailActivity extends AppCompatActivity { Bundle bundle = new Bundle(); bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER); bundle.putString(PostFragment.EXTRA_USER_NAME, username); + bundle.putString(PostFragment.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_SUBMITTED); + bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_NEW); bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER); bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); fragment.setArguments(bundle); diff --git a/app/src/main/res/drawable/ic_outline_bookmarks_24px.xml b/app/src/main/res/drawable/ic_outline_bookmarks_24px.xml new file mode 100644 index 00000000..33ceac3f --- /dev/null +++ b/app/src/main/res/drawable/ic_outline_bookmarks_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_outline_lock_24px.xml b/app/src/main/res/drawable/ic_outline_lock_24px.xml new file mode 100644 index 00000000..f4299e6c --- /dev/null +++ b/app/src/main/res/drawable/ic_outline_lock_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_outline_star_border_24px.xml b/app/src/main/res/drawable/ic_outline_star_border_24px.xml new file mode 100644 index 00000000..0186669d --- /dev/null +++ b/app/src/main/res/drawable/ic_outline_star_border_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_account_posts.xml b/app/src/main/res/layout/activity_account_posts.xml new file mode 100644 index 00000000..ecdda049 --- /dev/null +++ b/app/src/main/res/layout/activity_account_posts.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index b1572144..407c2a1d 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -90,6 +90,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Profile Following Subscriptions + Upvoted + Downvoted + Hidden + Saved + Gilded Settings Subscribers: %1$d Online: %1$d Cannot fetch subreddit info Cannot fetch user info - x%1$d + x%1$d ViewUserDetailActivity Subscribe