diff options
Diffstat (limited to '')
21 files changed, 466 insertions, 24 deletions
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 @@ <map> <entry key="assetSourceType" value="FILE" /> <entry key="color" value="ffffff" /> - <entry key="outputName" value="ic_outline_edit_24px" /> + <entry key="outputName" value="ic_outline_star_border_24px" /> <entry key="overrideSize" value="true" /> - <entry key="sourceFile" value="$USER_HOME$/Downloads/outline-edit-24px.svg" /> + <entry key="sourceFile" value="$USER_HOME$/Downloads/outline-star_border-24px.svg" /> </map> </option> </PersistentState> diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser Binary files differindex 7c7ab195..dae89535 100644 --- a/.idea/caches/build_file_checksums.ser +++ b/.idea/caches/build_file_checksums.ser 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"> + <activity android:name=".AccountPostsActivity" + android:parentActivityName=".MainActivity" + android:theme="@style/AppTheme.NoActionBar" /> <activity android:name=".EditCommentActivity" android:label="@string/edit_comment_activity_label" diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java new file mode 100644 index 00000000..9524fd47 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java @@ -0,0 +1,173 @@ +package ml.docilealligator.infinityforreddit; + +import android.content.res.Configuration; +import android.content.res.Resources; +import android.os.Build; +import android.os.Bundle; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; + +import com.google.android.material.appbar.AppBarLayout; + +import javax.inject.Inject; + +import butterknife.BindView; +import butterknife.ButterKnife; + +public class AccountPostsActivity extends AppCompatActivity { + + static final String EXTRA_USER_WHERE = "EUW"; + + private static final String NULL_ACCESS_TOKEN_STATE = "NATS"; + private static final String ACCESS_TOKEN_STATE = "ATS"; + private static final String ACCOUNT_NAME_STATE = "ANS"; + private static final String FRAGMENT_OUT_STATE = "FOS"; + + @BindView(R.id.appbar_layout_account_posts_activity) AppBarLayout appBarLayout; + @BindView(R.id.toolbar_account_posts_activity) Toolbar toolbar; + + private boolean mNullAccessToken = false; + private String mAccessToken; + private String mAccountName; + private String mUserWhere; + + private Fragment mFragment; + + @Inject + RedditDataRoomDatabase mRedditDataRoomDatabase; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_account_posts); + + ButterKnife.bind(this); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + Resources resources = getResources(); + + if (Build.VERSION.SDK_INT >= 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<RecyclerVie ((PostDetailViewHolder) holder).mGildedImageView.setVisibility(View.VISIBLE); mGlide.load(R.drawable.gold).into(((PostDetailViewHolder) holder).mGildedImageView); ((PostDetailViewHolder) holder).mGildedNumberTextView.setVisibility(View.VISIBLE); - String gildedNumber = mActivity.getResources().getString(R.string.gilded, mPost.getGilded()); + String gildedNumber = mActivity.getResources().getString(R.string.gilded_count, mPost.getGilded()); ((PostDetailViewHolder) holder).mGildedNumberTextView.setText(gildedNumber); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java index 0ee3a216..e0f2bcf2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java @@ -258,6 +258,7 @@ public class FilteredPostsActivity extends AppCompatActivity implements SortType getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment); } outState.putString(ACCESS_TOKEN_STATE, mAccessToken); + outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java index 9b44e82b..753cc9ed 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java @@ -76,6 +76,11 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe @BindView(R.id.all_drawer_items_linear_layout_main_activity) LinearLayout allDrawerItemsLinearLayout; @BindView(R.id.profile_linear_layout_main_activity) LinearLayout profileLinearLayout; @BindView(R.id.subscriptions_linear_layout_main_activity) LinearLayout subscriptionLinearLayout; + @BindView(R.id.upvoted_linear_layout_main_activity) LinearLayout upvotedLinearLayout; + @BindView(R.id.downvoted_linear_layout_main_activity) LinearLayout downvotedLinearLayout; + @BindView(R.id.hidden_linear_layout_main_activity) LinearLayout hiddenLinearLayout; + @BindView(R.id.saved_linear_layout_main_activity) LinearLayout savedLinearLayout; + @BindView(R.id.gilded_linear_layout_main_activity) LinearLayout gildedLinearLayout; @BindView(R.id.divider_main_activity) View divider; @BindView(R.id.settings_linear_layout_main_activity) LinearLayout settingsLinearLayout; @BindView(R.id.account_recycler_view_main_activity) RecyclerView accountRecyclerView; @@ -386,6 +391,41 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe drawer.closeDrawers(); }); + upvotedLinearLayout.setOnClickListener(view -> { + 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<String, Post> { 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<String, Post> { private int postType; private String sortType; private int filter; + private String userWhere; private MutableLiveData<NetworkState> paginationNetworkStateLiveData; private MutableLiveData<NetworkState> initialLoadStateLiveData; @@ -76,7 +84,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> { } 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<String, Post> { 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<String, Post> { Call<String> 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<String>() { @Override @@ -469,9 +480,10 @@ class PostDataSource extends PageKeyedDataSource<String, Post> { Call<String> 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<String>() { @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<Post, RecyclerView.ViewHo ((DataViewHolder) holder).gildedImageView.setVisibility(View.VISIBLE); mGlide.load(R.drawable.gold).into(((DataViewHolder) holder).gildedImageView); ((DataViewHolder) holder).gildedNumberTextView.setVisibility(View.VISIBLE); - String gildedNumber = mContext.getResources().getString(R.string.gilded, gilded); + String gildedNumber = mContext.getResources().getString(R.string.gilded_count, gilded); ((DataViewHolder) holder).gildedNumberTextView.setText(gildedNumber); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java index 62ec3e7f..f423fbec 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java @@ -87,9 +87,9 @@ public class PostViewModel extends ViewModel { } public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType, - int filter) { + String sortType, String where, int filter) { postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName, - postType, filter); + postType, sortType, where, filter); initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(), PostDataSource::getInitialLoadStateLiveData); @@ -190,6 +190,7 @@ public class PostViewModel extends ViewModel { private String query; private int postType; private String sortType; + private String userWhere; private int filter; public Factory(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType, @@ -214,12 +215,14 @@ public class PostViewModel extends ViewModel { } public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType, - int filter) { + String sortType, String where, int filter) { this.retrofit = retrofit; this.accessToken = accessToken; this.locale = locale; this.subredditName = subredditName; this.postType = postType; + this.sortType = sortType; + userWhere = where; this.filter = filter; } @@ -245,7 +248,7 @@ public class PostViewModel extends ViewModel { } else if(postType == PostDataSource.TYPE_SUBREDDIT) { return (T) new PostViewModel(retrofit, accessToken, locale, subredditName, postType, sortType, filter); } else { - return (T) new PostViewModel(retrofit, accessToken, locale, subredditName, postType, filter); + return (T) new PostViewModel(retrofit, accessToken, locale, subredditName, postType, sortType, userWhere, filter); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java index 2f25001a..a3abf798 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java @@ -55,12 +55,13 @@ public interface RedditAPI { Call<String> getSubredditBestPosts(@Path("subredditName") String subredditName, @Path("sortType") String sortType, @Query("after") String lastItem); - @GET("user/{username}/submitted.json?raw_json=1&limit=25") - Call<String> getUserBestPostsOauth(@Path("username") String username, @Query("after") String lastItem, - @HeaderMap Map<String, String> headers); + @GET("user/{username}/{where}.json?&raw_json=1&limit=25") + Call<String> getUserBestPostsOauth(@Path("username") String username, @Path("where") String where, + @Query("after") String lastItem, @Query("sort") String sortType, @HeaderMap Map<String, String> headers); @GET("user/{username}/submitted.json?raw_json=1&limit=25") - Call<String> getUserBestPosts(@Path("username") String username, @Query("after") String lastItem); + Call<String> getUserBestPosts(@Path("username") String username, @Query("after") String lastItem, + @Query("sort") String sortType); @GET("user/{username}/about.json?raw_json=1") Call<String> 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 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#FF000000" + android:pathData="M15,7v12.97l-4.21,-1.81 -0.79,-0.34 -0.79,0.34L5,19.97L5,7h10m4,-6L8.99,1C7.89,1 7,1.9 7,3h10c1.1,0 2,0.9 2,2v13l2,1L21,3c0,-1.1 -0.9,-2 -2,-2zM15,5L5,5c-1.1,0 -2,0.9 -2,2v16l7,-3 7,3L17,7c0,-1.1 -0.9,-2 -2,-2z"/> +</vector> 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 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#FF000000" + android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM9,6c0,-1.66 1.34,-3 3,-3s3,1.34 3,3v2L9,8L9,6zM18,20L6,20L6,10h12v10zM12,17c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2z"/> +</vector> 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 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#FF000000" + android:pathData="M22,9.24l-7.19,-0.62L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21 12,17.27 18.18,21l-1.63,-7.03L22,9.24zM12,15.4l-3.76,2.27 1,-4.28 -3.32,-2.88 4.38,-0.38L12,6.1l1.71,4.04 4.38,0.38 -3.32,2.88 1,4.28L12,15.4z"/> +</vector> 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 @@ +<?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=".AccountPostsActivity"> + + <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar_layout_account_posts_activity" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:theme="@style/AppTheme.AppBarOverlay"> + + <com.google.android.material.appbar.CollapsingToolbarLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|enterAlways" + app:titleEnabled="false" + app:toolbarId="@+id/toolbar_account_posts_activity"> + + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar_account_posts_activity" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + app:popupTheme="@style/AppTheme.PopupOverlay" + app:navigationIcon="?attr/homeAsUpIndicator" /> + + </com.google.android.material.appbar.CollapsingToolbarLayout> + + </com.google.android.material.appbar.AppBarLayout> + + <FrameLayout + android:id="@+id/frame_layout_account_posts_activity" + android:layout_width="match_parent" + android:layout_height="match_parent" + app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + +</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file 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 @@ </LinearLayout> + <LinearLayout + android:id="@+id/upvoted_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_arrow_upward_black_24dp" + android:tint="@color/primaryTextColor"/> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:text="@string/upvoted" + android:textColor="@color/primaryTextColor" /> + + </LinearLayout> + + <LinearLayout + android:id="@+id/downvoted_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_arrow_downward_black_24dp" + android:tint="@color/primaryTextColor"/> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:text="@string/downvoted" + android:textColor="@color/primaryTextColor" /> + + </LinearLayout> + + <LinearLayout + android:id="@+id/hidden_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_lock_24px" + android:tint="@color/primaryTextColor"/> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:text="@string/hidden" + android:textColor="@color/primaryTextColor" /> + + </LinearLayout> + + <LinearLayout + android:id="@+id/saved_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_bookmarks_24px" + android:tint="@color/primaryTextColor"/> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:text="@string/saved" + android:textColor="@color/primaryTextColor" /> + + </LinearLayout> + + <LinearLayout + android:id="@+id/gilded_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_star_border_24px" + android:tint="@color/primaryTextColor"/> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:text="@string/gilded" + android:textColor="@color/primaryTextColor" /> + + </LinearLayout> + <View android:id="@+id/divider_main_activity" android:layout_width="match_parent" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 86af0755..742706ea 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -63,13 +63,18 @@ <string name="profile">Profile</string> <string name="following">Following</string> <string name="subscriptions">Subscriptions</string> + <string name="upvoted">Upvoted</string> + <string name="downvoted">Downvoted</string> + <string name="hidden">Hidden</string> + <string name="saved">Saved</string> + <string name="gilded">Gilded</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> <string name="cannot_fetch_user_info">Cannot fetch user info</string> - <string name="gilded">x%1$d</string> + <string name="gilded_count">x%1$d</string> <string name="title_activity_view_user_detail">ViewUserDetailActivity</string> <string name="subscribe">Subscribe</string> |