mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-25 02:18:23 +01:00
Add a search button in ViewSubredditDetailActivity and ViewUserDetailActivity. Search posts in a specific subreddit is available. Rename SearchActivity to SearchResultActivity. Add SearchActivity for searching instead of searching in MainActivity.
This commit is contained in:
parent
611d6a90ec
commit
216228cf02
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
BIN
.idea/caches/gradle_models.ser
generated
BIN
.idea/caches/gradle_models.ser
generated
Binary file not shown.
@ -19,6 +19,11 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
android:usesCleartextTraffic="true">
|
||||
<activity
|
||||
android:name=".SearchActivity"
|
||||
android:label="@string/search_activity_label"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
<activity
|
||||
android:name=".RulesActivity"
|
||||
android:label="@string/rules_activity_label"
|
||||
@ -58,7 +63,7 @@
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:windowSoftInputMode="adjustResize" />
|
||||
<activity
|
||||
android:name=".SearchActivity"
|
||||
android:name=".SearchResultActivity"
|
||||
android:label="@string/search_activity_label"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
|
@ -23,7 +23,6 @@ import androidx.fragment.app.Fragment;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.RequestManager;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.ferfalk.simplesearchview.SimpleSearchView;
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
@ -48,8 +47,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@BindView(R.id.drawer_layout) DrawerLayout drawer;
|
||||
@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.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;
|
||||
@ -117,50 +114,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
|
||||
|
||||
transparentOverlay.setOnClickListener(view -> simpleSearchView.onBackPressed());
|
||||
|
||||
simpleSearchView.setOnQueryTextListener(new SimpleSearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
Intent intent = new Intent(MainActivity.this, SearchActivity.class);
|
||||
intent.putExtra(SearchActivity.QUERY_KEY, query);
|
||||
startActivity(intent);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextCleared() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
simpleSearchView.setOnSearchViewListener(new SimpleSearchView.SearchViewListener() {
|
||||
@Override
|
||||
public void onSearchViewShown() {
|
||||
transparentOverlay.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchViewClosed() {
|
||||
transparentOverlay.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchViewShownAnimation() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchViewClosedAnimation() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
String accessToken = getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE).getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
|
||||
if (accessToken.equals("")) {
|
||||
Intent loginIntent = new Intent(this, LoginActivity.class);
|
||||
@ -169,7 +122,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (savedInstanceState == null) {
|
||||
mFragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.POST_TYPE_KEY, PostDataSource.TYPE_FRONT_PAGE);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE_KEY, PostDataSource.TYPE_FRONT_PAGE);
|
||||
mFragment.setArguments(bundle);
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_content_main, mFragment).commit();
|
||||
} else {
|
||||
@ -316,9 +269,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (simpleSearchView.onActivityResult(requestCode, resultCode, data)) {
|
||||
return;
|
||||
}
|
||||
if(requestCode == LOGIN_ACTIVITY_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
|
||||
Intent intent = getIntent();
|
||||
finish();
|
||||
@ -333,7 +283,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main_activity, menu);
|
||||
mMenu = menu;
|
||||
simpleSearchView.setMenuItem(mMenu.findItem(R.id.action_search_main_activity));
|
||||
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_main_activity);
|
||||
if(isInLazyMode) {
|
||||
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
||||
@ -352,6 +301,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (mFragment instanceof FragmentCommunicator) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_search_main_activity:
|
||||
Intent intent = new Intent(this, SearchActivity.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.action_refresh_main_activity:
|
||||
((FragmentCommunicator) mFragment).refresh();
|
||||
mFetchUserInfoSuccess = false;
|
||||
@ -384,10 +337,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
} else {
|
||||
if (simpleSearchView.onBackPressed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class ParseSubredditData {
|
||||
JSONObject data = jsonResponse.getJSONObject(JSONUtils.DATA_KEY);
|
||||
mNCurrentOnlineSubscribers = data.getInt(JSONUtils.ACTIVE_USER_COUNT_KEY);
|
||||
subredditData = parseSubredditData(data);
|
||||
/*String id = data.getString(JSONUtils.NAME_KEY);
|
||||
/*String id = data.getString(JSONUtils.EXTRA_SUBREDDIT_NAME_KEY);
|
||||
String subredditFullName = data.getString(JSONUtils.DISPLAY_NAME);
|
||||
String description = data.getString(JSONUtils.PUBLIC_DESCRIPTION_KEY).trim();
|
||||
|
||||
|
@ -27,7 +27,8 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
private Retrofit retrofit;
|
||||
private String accessToken;
|
||||
private Locale locale;
|
||||
private String name;
|
||||
private String subredditName;
|
||||
private String query;
|
||||
private int postType;
|
||||
private OnPostFetchedCallback onPostFetchedCallback;
|
||||
|
||||
@ -53,7 +54,20 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.locale = locale;
|
||||
this.name = subredditName;
|
||||
this.subredditName = subredditName;
|
||||
paginationNetworkStateLiveData = new MutableLiveData();
|
||||
initialLoadStateLiveData = new MutableLiveData();
|
||||
this.postType = postType;
|
||||
this.onPostFetchedCallback = onPostFetchedCallback;
|
||||
}
|
||||
|
||||
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditName, String query,
|
||||
int postType, OnPostFetchedCallback onPostFetchedCallback) {
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.locale = locale;
|
||||
this.subredditName = subredditName;
|
||||
this.query = query;
|
||||
paginationNetworkStateLiveData = new MutableLiveData();
|
||||
initialLoadStateLiveData = new MutableLiveData();
|
||||
this.postType = postType;
|
||||
@ -202,7 +216,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
|
||||
private void loadSubredditPostsInitial(@NonNull final LoadInitialCallback<String, Post> callback) {
|
||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||
Call<String> getPost = api.getSubredditBestPosts(name, null, RedditUtils.getOAuthHeader(accessToken));
|
||||
Call<String> getPost = api.getSubredditBestPosts(subredditName, null, RedditUtils.getOAuthHeader(accessToken));
|
||||
getPost.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||
@ -243,7 +257,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
|
||||
private void loadSubredditPostsAfter(@NonNull LoadParams<String> params, @NonNull final LoadCallback<String, Post> callback) {
|
||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||
Call<String> getPost = api.getSubredditBestPosts(name, params.key, RedditUtils.getOAuthHeader(accessToken));
|
||||
Call<String> getPost = api.getSubredditBestPosts(subredditName, params.key, RedditUtils.getOAuthHeader(accessToken));
|
||||
getPost.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||
@ -277,7 +291,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
|
||||
private void loadUserPostsInitial(@NonNull final LoadInitialCallback<String, Post> callback, String lastItem) {
|
||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||
Call<String> getPost = api.getUserBestPosts(name, lastItem, RedditUtils.getOAuthHeader(accessToken));
|
||||
Call<String> getPost = api.getUserBestPosts(subredditName, lastItem, RedditUtils.getOAuthHeader(accessToken));
|
||||
getPost.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||
@ -323,7 +337,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
String after = lastItem == null ? params.key : lastItem;
|
||||
|
||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||
Call<String> getPost = api.getUserBestPosts(name, after, RedditUtils.getOAuthHeader(accessToken));
|
||||
Call<String> getPost = api.getUserBestPosts(subredditName, after, RedditUtils.getOAuthHeader(accessToken));
|
||||
getPost.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||
@ -361,7 +375,14 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
|
||||
private void loadSearchPostsInitial(@NonNull final LoadInitialCallback<String, Post> callback) {
|
||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||
Call<String> getPost = api.searchPosts(name, null, RedditUtils.getOAuthHeader(accessToken));
|
||||
Call<String> getPost;
|
||||
|
||||
if(subredditName == null) {
|
||||
getPost = api.searchPosts(subredditName, null, RedditUtils.getOAuthHeader(accessToken));
|
||||
} else {
|
||||
getPost = api.searchPostsInSpecificSubreddit(subredditName, query, null, RedditUtils.getOAuthHeader(accessToken));
|
||||
}
|
||||
|
||||
getPost.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||
@ -402,7 +423,14 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
|
||||
private void loadSearchPostsAfter(@NonNull LoadParams<String> params, @NonNull final LoadCallback<String, Post> callback) {
|
||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||
Call<String> getPost = api.searchPosts(name, params.key, RedditUtils.getOAuthHeader(accessToken));
|
||||
Call<String> getPost;
|
||||
|
||||
if(subredditName == null) {
|
||||
getPost = api.searchPosts(subredditName, params.key, RedditUtils.getOAuthHeader(accessToken));
|
||||
} else {
|
||||
getPost = api.searchPostsInSpecificSubreddit(subredditName, query, params.key, RedditUtils.getOAuthHeader(accessToken));
|
||||
}
|
||||
|
||||
getPost.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||
|
@ -12,6 +12,7 @@ class PostDataSourceFactory extends DataSource.Factory {
|
||||
private String accessToken;
|
||||
private Locale locale;
|
||||
private String subredditName;
|
||||
private String query;
|
||||
private int postType;
|
||||
private PostDataSource.OnPostFetchedCallback onPostFetchedCallback;
|
||||
|
||||
@ -28,8 +29,8 @@ class PostDataSourceFactory extends DataSource.Factory {
|
||||
this.onPostFetchedCallback = onPostFetchedCallback;
|
||||
}
|
||||
|
||||
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
|
||||
PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
|
||||
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
|
||||
int postType, PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.locale = locale;
|
||||
@ -39,10 +40,24 @@ class PostDataSourceFactory extends DataSource.Factory {
|
||||
this.onPostFetchedCallback = onPostFetchedCallback;
|
||||
}
|
||||
|
||||
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
|
||||
String query, int postType, PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.locale = locale;
|
||||
this.subredditName = subredditName;
|
||||
this.query = query;
|
||||
postDataSourceLiveData = new MutableLiveData<>();
|
||||
this.postType = postType;
|
||||
this.onPostFetchedCallback = onPostFetchedCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSource create() {
|
||||
if(postType == PostDataSource.TYPE_FRONT_PAGE) {
|
||||
postDataSource = new PostDataSource(retrofit, accessToken, locale, postType, onPostFetchedCallback);
|
||||
} else if(postType == PostDataSource.TYPE_SEARCH) {
|
||||
postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, query, postType, onPostFetchedCallback);
|
||||
} else {
|
||||
postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, postType, onPostFetchedCallback);
|
||||
}
|
||||
|
@ -45,8 +45,10 @@ import retrofit2.Retrofit;
|
||||
*/
|
||||
public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
|
||||
static final String NAME_KEY = "NK";
|
||||
static final String POST_TYPE_KEY = "PTK";
|
||||
static final String EXTRA_SUBREDDIT_NAME_KEY = "ENK";
|
||||
static final String EXTRA_QUERY_KEY = "EQK";
|
||||
static final String EXTRA_POST_TYPE_KEY = "EPTK";
|
||||
|
||||
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
||||
|
||||
@BindView(R.id.coordinator_layout_post_fragment) CoordinatorLayout mCoordinatorLayout;
|
||||
@ -163,21 +165,43 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
return false;
|
||||
});
|
||||
|
||||
int postType = getArguments().getInt(POST_TYPE_KEY);
|
||||
int postType = getArguments().getInt(EXTRA_POST_TYPE_KEY);
|
||||
|
||||
String accessToken = activity.getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE)
|
||||
.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
|
||||
|
||||
PostViewModel.Factory factory;
|
||||
|
||||
if(postType != PostDataSource.TYPE_FRONT_PAGE) {
|
||||
String name = getArguments().getString(NAME_KEY);
|
||||
if(postType == PostDataSource.TYPE_SEARCH) {
|
||||
String subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME_KEY);
|
||||
String query = getArguments().getString(EXTRA_QUERY_KEY);
|
||||
|
||||
mAdapter = new PostRecyclerViewAdapter(activity, mRetrofit,
|
||||
mSharedPreferences, postType, () -> mPostViewModel.retryLoadingMore());
|
||||
|
||||
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
|
||||
getResources().getConfiguration().locale, name, postType, new PostDataSource.OnPostFetchedCallback() {
|
||||
getResources().getConfiguration().locale, subredditName, query, postType, new PostDataSource.OnPostFetchedCallback() {
|
||||
@Override
|
||||
public void hasPost() {
|
||||
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noPost() {
|
||||
mFetchPostInfoLinearLayout.setOnClickListener(view -> {
|
||||
//Do nothing
|
||||
});
|
||||
showErrorView(R.string.no_posts);
|
||||
}
|
||||
});
|
||||
} else if(postType != PostDataSource.TYPE_FRONT_PAGE) {
|
||||
String subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME_KEY);
|
||||
|
||||
mAdapter = new PostRecyclerViewAdapter(activity, mRetrofit,
|
||||
mSharedPreferences, postType, () -> mPostViewModel.retryLoadingMore());
|
||||
|
||||
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
|
||||
getResources().getConfiguration().locale, subredditName, postType, new PostDataSource.OnPostFetchedCallback() {
|
||||
@Override
|
||||
public void hasPost() {
|
||||
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
||||
|
@ -411,10 +411,10 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if(requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if(resultCode == RESULT_OK) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME_KEY);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL_KEY);
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER_KEY);
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
|
||||
subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor));
|
||||
subreditNameTextView.setText(subredditName);
|
||||
|
@ -52,7 +52,7 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
|
||||
|
||||
@BindView(R.id.coordinator_layout_post_link_activity) CoordinatorLayout coordinatorLayout;
|
||||
@BindView(R.id.subreddit_icon_gif_image_view_post_link_activity) GifImageView iconGifImageView;
|
||||
@BindView(R.id.subreddit_name_text_view_post_link_activity) TextView subreditNameTextView;
|
||||
@BindView(R.id.subreddit_name_text_view_post_link_activity) TextView subredditNameTextView;
|
||||
@BindView(R.id.rules_button_post_link_activity) Button rulesButton;
|
||||
@BindView(R.id.flair_custom_text_view_post_link_activity) CustomTextView flairTextView;
|
||||
@BindView(R.id.spoiler_custom_text_view_post_link_activity) CustomTextView spoilerTextView;
|
||||
@ -109,7 +109,7 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
|
||||
isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE);
|
||||
|
||||
if(subredditName != null) {
|
||||
subreditNameTextView.setText(subredditName);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
if(!loadSubredditIconSuccessful) {
|
||||
loadSubredditIcon();
|
||||
@ -130,7 +130,7 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
|
||||
} else {
|
||||
if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||
subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME);
|
||||
subreditNameTextView.setText(subredditName);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
loadSubredditIcon();
|
||||
} else {
|
||||
@ -145,7 +145,7 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
|
||||
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
|
||||
});
|
||||
|
||||
subreditNameTextView.setOnClickListener(view -> {
|
||||
subredditNameTextView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(this, SubredditSelectionActivity.class);
|
||||
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
|
||||
});
|
||||
@ -247,9 +247,9 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
|
||||
|
||||
String subredditName;
|
||||
if(subredditIsUser) {
|
||||
subredditName = "u_" + subreditNameTextView.getText().toString();
|
||||
subredditName = "u_" + subredditNameTextView.getText().toString();
|
||||
} else {
|
||||
subredditName = subreditNameTextView.getText().toString();
|
||||
subredditName = subredditNameTextView.getText().toString();
|
||||
}
|
||||
|
||||
SubmitPost.submitTextOrLinkPost(mOauthRetrofit, sharedPreferences, mLocale, subredditName,
|
||||
@ -299,13 +299,13 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if(requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if(resultCode == RESULT_OK) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME_KEY);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL_KEY);
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER_KEY);
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
|
||||
subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor));
|
||||
subreditNameTextView.setText(subredditName);
|
||||
subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor));
|
||||
subredditNameTextView.setText(subredditName);
|
||||
displaySubredditIcon();
|
||||
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
|
@ -51,8 +51,8 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh
|
||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||
|
||||
@BindView(R.id.coordinator_layout_post_text_activity) CoordinatorLayout coordinatorLayout;
|
||||
@BindView(R.id.subreddit_icon_gif_image_view_post_text_activity) GifImageView iconGifImageView;
|
||||
@BindView(R.id.subreddit_name_text_view_post_text_activity) TextView subreditNameTextView;
|
||||
@BindView(R.id.subreddit_icon_gif_image_view_search_activity) GifImageView iconGifImageView;
|
||||
@BindView(R.id.subreddit_name_text_view_search_activity) TextView subreditNameTextView;
|
||||
@BindView(R.id.rules_button_post_text_activity) Button rulesButton;
|
||||
@BindView(R.id.flair_custom_text_view_post_text_activity) CustomTextView flairTextView;
|
||||
@BindView(R.id.spoiler_custom_text_view_post_text_activity) CustomTextView spoilerTextView;
|
||||
@ -304,10 +304,10 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if(requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if(resultCode == RESULT_OK) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME_KEY);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL_KEY);
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER_KEY);
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
|
||||
subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor));
|
||||
subreditNameTextView.setText(subredditName);
|
||||
|
@ -392,10 +392,10 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if(requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if(resultCode == RESULT_OK) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME_KEY);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL_KEY);
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER_KEY);
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
|
||||
subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor));
|
||||
subreditNameTextView.setText(subredditName);
|
||||
|
@ -1,7 +1,5 @@
|
||||
package ml.docilealligator.infinityforreddit;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.arch.core.util.Function;
|
||||
import androidx.lifecycle.LiveData;
|
||||
@ -10,6 +8,9 @@ import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.paging.LivePagedListBuilder;
|
||||
import androidx.paging.PagedList;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class PostViewModel extends ViewModel {
|
||||
@ -53,6 +54,25 @@ public class PostViewModel extends ViewModel {
|
||||
posts = (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
||||
}
|
||||
|
||||
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, String query,
|
||||
int postType, PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
|
||||
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName,
|
||||
query, postType, onPostFetchedCallback);
|
||||
|
||||
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||
dataSource -> dataSource.getInitialLoadStateLiveData());
|
||||
paginationNetworkState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||
dataSource -> dataSource.getPaginationNetworkStateLiveData());
|
||||
|
||||
PagedList.Config pagedListConfig =
|
||||
(new PagedList.Config.Builder())
|
||||
.setEnablePlaceholders(false)
|
||||
.setPageSize(25)
|
||||
.build();
|
||||
|
||||
posts = (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
||||
}
|
||||
|
||||
LiveData<PagedList<Post>> getPosts() {
|
||||
return posts;
|
||||
}
|
||||
@ -82,6 +102,7 @@ public class PostViewModel extends ViewModel {
|
||||
private String accessToken;
|
||||
private Locale locale;
|
||||
private String subredditName;
|
||||
private String query;
|
||||
private int postType;
|
||||
private PostDataSource.OnPostFetchedCallback onPostFetchedCallback;
|
||||
|
||||
@ -104,11 +125,24 @@ public class PostViewModel extends ViewModel {
|
||||
this.onPostFetchedCallback = onPostFetchedCallback;
|
||||
}
|
||||
|
||||
public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, String query,
|
||||
int postType, PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.locale = locale;
|
||||
this.subredditName = subredditName;
|
||||
this.query = query;
|
||||
this.postType = postType;
|
||||
this.onPostFetchedCallback = onPostFetchedCallback;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
if(postType == PostDataSource.TYPE_FRONT_PAGE) {
|
||||
return (T) new PostViewModel(retrofit, accessToken, locale, postType, onPostFetchedCallback);
|
||||
} else if(postType == PostDataSource.TYPE_SEARCH){
|
||||
return (T) new PostViewModel(retrofit, accessToken, locale, subredditName, query, postType, onPostFetchedCallback);
|
||||
} else {
|
||||
return (T) new PostViewModel(retrofit, accessToken, locale, subredditName, postType, onPostFetchedCallback);
|
||||
}
|
||||
|
@ -65,16 +65,16 @@ public interface RedditAPI {
|
||||
@GET("subreddits/search.json?raw_json=1&include_over_18=on")
|
||||
Call<String> searchSubreddits(@Query("q") String subredditName, @Query("after") String after);
|
||||
|
||||
@GET("search.json?raw_json=1&type=user")
|
||||
@GET("search.json?raw_json=1&type=user&include_over_18=on")
|
||||
Call<String> searchUsers(@Query("q") String profileName, @Query("after") String after);
|
||||
|
||||
@GET("search.json?raw_json=1&type=link")
|
||||
@GET("search.json?raw_json=1&type=link&include_over_18=on")
|
||||
Call<String> searchPosts(@Query("q") String query, @Query("after") String after,
|
||||
@HeaderMap Map<String, String> headers);
|
||||
|
||||
@GET("r/{subredditName}/search.json?raw_json=1&type=link&restrict_sr=true")
|
||||
Call<String> searchPostsInSpecificSubreddit(@Query("q") String query, @Query("after") String after,
|
||||
@HeaderMap Map<String, String> headers);
|
||||
@GET("r/{subredditName}/search.json?raw_json=1&type=link&restrict_sr=true&include_over_18=on")
|
||||
Call<String> searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName, @Query("q") String query,
|
||||
@Query("after") String after, @HeaderMap Map<String, String> headers);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("api/comment")
|
||||
|
@ -4,35 +4,36 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
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.ferfalk.simplesearchview.SimpleSearchView;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class SearchActivity extends AppCompatActivity {
|
||||
static final String QUERY_KEY = "QK";
|
||||
|
||||
private String mQuery;
|
||||
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||
static final String EXTRA_SUBREDDIT_IS_USER = "ESIU";
|
||||
|
||||
@BindView(R.id.toolbar_search_activity) Toolbar toolbar;
|
||||
private static final String SUBREDDIT_NAME_STATE = "SNS";
|
||||
private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
|
||||
|
||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||
|
||||
@BindView(R.id.toolbar) Toolbar toolbar;
|
||||
@BindView(R.id.search_view_search_activity) SimpleSearchView simpleSearchView;
|
||||
@BindView(R.id.tab_layout_search_activity) TabLayout tabLayout;
|
||||
@BindView(R.id.transparent_overlay_search_activity) View transparentOverlay;
|
||||
@BindView(R.id.view_pager_search_activity) ViewPager viewPager;
|
||||
@BindView(R.id.subreddit_name_relative_layout_search_activity) RelativeLayout subredditNameRelativeLayout;
|
||||
@BindView(R.id.subreddit_name_text_view_search_activity) TextView subredditNameTextView;
|
||||
|
||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||
private String subredditName;
|
||||
private boolean subredditIsUser;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -42,23 +43,22 @@ public class SearchActivity extends AppCompatActivity {
|
||||
ButterKnife.bind(this);
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||
viewPager.setAdapter(sectionsPagerAdapter);
|
||||
viewPager.setOffscreenPageLimit(2);
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
|
||||
transparentOverlay.setOnClickListener(view -> simpleSearchView.onBackPressed());
|
||||
|
||||
simpleSearchView.setOnQueryTextListener(new SimpleSearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
Intent intent = getIntent();
|
||||
intent.putExtra(SearchActivity.QUERY_KEY, query);
|
||||
Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class);
|
||||
intent.putExtra(SearchResultActivity.EXTRA_QUERY, query);
|
||||
if(subredditName != null) {
|
||||
if(subredditIsUser) {
|
||||
intent.putExtra(SearchResultActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||
} else {
|
||||
intent.putExtra(SearchResultActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
}
|
||||
}
|
||||
|
||||
finish();
|
||||
startActivity(intent);
|
||||
overridePendingTransition(0, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -73,66 +73,68 @@ public class SearchActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
simpleSearchView.setOnSearchViewListener(new SimpleSearchView.SearchViewListener() {
|
||||
@Override
|
||||
public void onSearchViewShown() {
|
||||
transparentOverlay.setVisibility(View.VISIBLE);
|
||||
if(savedInstanceState != null) {
|
||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||
subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE);
|
||||
|
||||
if(subredditName == null) {
|
||||
subredditNameTextView.setText(R.string.all_subreddits);
|
||||
} else {
|
||||
subredditNameTextView.setText(subredditName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchViewClosed() {
|
||||
transparentOverlay.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchViewShownAnimation() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchViewClosedAnimation() {
|
||||
|
||||
}
|
||||
subredditNameRelativeLayout.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(this, SubredditSelectionActivity.class);
|
||||
intent.putExtra(SubredditSelectionActivity.EXTRA_EXTRA_CLEAR_SELECTION, true);
|
||||
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
|
||||
});
|
||||
|
||||
// Get the intent, verify the action and get the query
|
||||
Intent intent = getIntent();
|
||||
String query = intent.getExtras().getString(QUERY_KEY);
|
||||
if(query != null) {
|
||||
mQuery = query;
|
||||
setTitle(query);
|
||||
if(intent.hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||
subredditName = intent.getExtras().getString(EXTRA_SUBREDDIT_NAME);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
subredditIsUser = intent.getExtras().getBoolean(EXTRA_SUBREDDIT_IS_USER);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
if (simpleSearchView.onActivityResult(requestCode, resultCode, data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if(resultCode == RESULT_OK) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
|
||||
if(subredditName == null) {
|
||||
subredditNameTextView.setText(R.string.all_subreddits);
|
||||
} else {
|
||||
subredditNameTextView.setText(subredditName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main_activity, menu);
|
||||
|
||||
simpleSearchView.setMenuItem(menu.findItem(R.id.action_search_main_activity));
|
||||
|
||||
getMenuInflater().inflate(R.menu.search_activity, menu);
|
||||
simpleSearchView.setMenuItem(menu.findItem(R.id.action_search_search_activity));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
case R.id.action_refresh_main_activity:
|
||||
sectionsPagerAdapter.refresh();
|
||||
return true;
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if(item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -143,97 +145,10 @@ public class SearchActivity extends AppCompatActivity {
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
private class SectionsPagerAdapter extends FragmentPagerAdapter {
|
||||
private PostFragment postFragment;
|
||||
private SubredditListingFragment subredditListingFragment;
|
||||
private UserListingFragment userListingFragment;
|
||||
|
||||
public SectionsPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
switch (position) {
|
||||
case 0: {
|
||||
PostFragment mFragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.POST_TYPE_KEY, PostDataSource.TYPE_SEARCH);
|
||||
bundle.putString(PostFragment.NAME_KEY, mQuery);
|
||||
mFragment.setArguments(bundle);
|
||||
return mFragment;
|
||||
}
|
||||
case 1: {
|
||||
SubredditListingFragment mFragment = new SubredditListingFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(SubredditListingFragment.QUERY_KEY, mQuery);
|
||||
mFragment.setArguments(bundle);
|
||||
return mFragment;
|
||||
}
|
||||
default:
|
||||
{
|
||||
UserListingFragment mFragment = new UserListingFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(UserListingFragment.QUERY_KEY, mQuery);
|
||||
mFragment.setArguments(bundle);
|
||||
return mFragment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return "Posts";
|
||||
case 1:
|
||||
return "Subreddits";
|
||||
case 2:
|
||||
return "Users";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Object instantiateItem(@NonNull ViewGroup container, int position) {
|
||||
Fragment fragment = (Fragment) super.instantiateItem(container, position);
|
||||
switch (position) {
|
||||
case 0:
|
||||
postFragment = (PostFragment) fragment;
|
||||
break;
|
||||
case 1:
|
||||
subredditListingFragment = (SubredditListingFragment) fragment;
|
||||
break;
|
||||
case 2:
|
||||
userListingFragment = (UserListingFragment) fragment;
|
||||
break;
|
||||
}
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
if(postFragment != null) {
|
||||
((FragmentCommunicator) postFragment).refresh();
|
||||
}
|
||||
if(subredditListingFragment != null) {
|
||||
((FragmentCommunicator) subredditListingFragment).refresh();
|
||||
}
|
||||
if (userListingFragment != null) {
|
||||
((FragmentCommunicator) userListingFragment).refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void newSearch() {
|
||||
getItem(0);
|
||||
getItem(1);
|
||||
getItem(2);
|
||||
}
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||
outState.putBoolean(SUBREDDIT_IS_USER_STATE, subredditIsUser);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,182 @@
|
||||
package ml.docilealligator.infinityforreddit;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
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 butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class SearchResultActivity extends AppCompatActivity {
|
||||
static final String EXTRA_QUERY = "QK";
|
||||
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||
|
||||
private String mQuery;
|
||||
private String mSubredditName;
|
||||
|
||||
@BindView(R.id.toolbar_search_result_activity) Toolbar toolbar;
|
||||
@BindView(R.id.tab_layout_search_result_activity) TabLayout tabLayout;
|
||||
@BindView(R.id.view_pager_search_result_activity) ViewPager viewPager;
|
||||
|
||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_search_result);
|
||||
|
||||
ButterKnife.bind(this);
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||
viewPager.setAdapter(sectionsPagerAdapter);
|
||||
viewPager.setOffscreenPageLimit(2);
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
|
||||
// Get the intent, verify the action and get the query
|
||||
Intent intent = getIntent();
|
||||
String query = intent.getExtras().getString(EXTRA_QUERY);
|
||||
|
||||
if(intent.hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||
mSubredditName = intent.getExtras().getString(EXTRA_SUBREDDIT_NAME);
|
||||
}
|
||||
|
||||
if(query != null) {
|
||||
mQuery = query;
|
||||
setTitle(query);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.search_result_activity, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
case R.id.action_search_search_result_activity:
|
||||
Intent intent = new Intent(this, SearchActivity.class);
|
||||
finish();
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.action_refresh_search_result_activity:
|
||||
sectionsPagerAdapter.refresh();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private class SectionsPagerAdapter extends FragmentPagerAdapter {
|
||||
private PostFragment postFragment;
|
||||
private SubredditListingFragment subredditListingFragment;
|
||||
private UserListingFragment userListingFragment;
|
||||
|
||||
public SectionsPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
switch (position) {
|
||||
case 0: {
|
||||
PostFragment mFragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE_KEY, PostDataSource.TYPE_SEARCH);
|
||||
bundle.putString(PostFragment.EXTRA_SUBREDDIT_NAME_KEY, mSubredditName);
|
||||
bundle.putString(PostFragment.EXTRA_QUERY_KEY, mQuery);
|
||||
mFragment.setArguments(bundle);
|
||||
return mFragment;
|
||||
}
|
||||
case 1: {
|
||||
SubredditListingFragment mFragment = new SubredditListingFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(SubredditListingFragment.QUERY_KEY, mQuery);
|
||||
mFragment.setArguments(bundle);
|
||||
return mFragment;
|
||||
}
|
||||
default:
|
||||
{
|
||||
UserListingFragment mFragment = new UserListingFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(UserListingFragment.QUERY_KEY, mQuery);
|
||||
mFragment.setArguments(bundle);
|
||||
return mFragment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return "Posts";
|
||||
case 1:
|
||||
return "Subreddits";
|
||||
case 2:
|
||||
return "Users";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Object instantiateItem(@NonNull ViewGroup container, int position) {
|
||||
Fragment fragment = (Fragment) super.instantiateItem(container, position);
|
||||
switch (position) {
|
||||
case 0:
|
||||
postFragment = (PostFragment) fragment;
|
||||
break;
|
||||
case 1:
|
||||
subredditListingFragment = (SubredditListingFragment) fragment;
|
||||
break;
|
||||
case 2:
|
||||
userListingFragment = (UserListingFragment) fragment;
|
||||
break;
|
||||
}
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
if(postFragment != null) {
|
||||
((FragmentCommunicator) postFragment).refresh();
|
||||
}
|
||||
if(subredditListingFragment != null) {
|
||||
((FragmentCommunicator) subredditListingFragment).refresh();
|
||||
}
|
||||
if (userListingFragment != null) {
|
||||
((FragmentCommunicator) userListingFragment).refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void newSearch() {
|
||||
getItem(0);
|
||||
getItem(1);
|
||||
getItem(2);
|
||||
}
|
||||
}
|
||||
}
|
@ -14,9 +14,10 @@ import butterknife.ButterKnife;
|
||||
|
||||
public class SubredditSelectionActivity extends AppCompatActivity {
|
||||
|
||||
static final String EXTRA_RETURN_SUBREDDIT_NAME_KEY = "ERSNK";
|
||||
static final String EXTRA_RETURN_SUBREDDIT_ICON_URL_KEY = "ERSIURLK";
|
||||
static final String EXTRA_RETURN_SUBREDDIT_IS_USER_KEY = "ERSIUK";
|
||||
static final String EXTRA_EXTRA_CLEAR_SELECTION = "EECS";
|
||||
static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
|
||||
static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIURL";
|
||||
static final String EXTRA_RETURN_SUBREDDIT_IS_USER = "ERSIU";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -32,6 +33,10 @@ public class SubredditSelectionActivity extends AppCompatActivity {
|
||||
SubscribedSubredditsListingFragment fragment = new SubscribedSubredditsListingFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBoolean(SubscribedSubredditsListingFragment.EXTRA_IS_SUBREDDIT_SELECTION, true);
|
||||
if(getIntent().hasExtra(EXTRA_EXTRA_CLEAR_SELECTION)) {
|
||||
bundle.putBoolean(SubscribedSubredditsListingFragment.EXTRA_EXTRA_CLEAR_SELECTION,
|
||||
getIntent().getExtras().getBoolean(EXTRA_EXTRA_CLEAR_SELECTION));
|
||||
}
|
||||
fragment.setArguments(bundle);
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_subreddit_selection_activity, fragment).commit();
|
||||
}
|
||||
@ -49,9 +54,9 @@ public class SubredditSelectionActivity extends AppCompatActivity {
|
||||
|
||||
void getSelectedSubreddit(String name, String iconUrl, boolean subredditIsUser) {
|
||||
Intent returnIntent = new Intent();
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME_KEY, name);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL_KEY, iconUrl);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_IS_USER_KEY, subredditIsUser);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, name);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, iconUrl);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_IS_USER, subredditIsUser);
|
||||
setResult(Activity.RESULT_OK, returnIntent);
|
||||
finish();
|
||||
}
|
||||
|
@ -31,7 +31,8 @@ import butterknife.ButterKnife;
|
||||
*/
|
||||
public class SubscribedSubredditsListingFragment extends Fragment {
|
||||
|
||||
static final String EXTRA_IS_SUBREDDIT_SELECTION = "EISSK";
|
||||
static final String EXTRA_IS_SUBREDDIT_SELECTION = "EISS";
|
||||
static final String EXTRA_EXTRA_CLEAR_SELECTION = "EECS";
|
||||
|
||||
@BindView(R.id.recycler_view_subscribed_subreddits_listing_fragment) RecyclerView mRecyclerView;
|
||||
@BindView(R.id.no_subscriptions_linear_layout_subreddits_listing_fragment) LinearLayout mLinearLayout;
|
||||
@ -43,8 +44,6 @@ public class SubscribedSubredditsListingFragment extends Fragment {
|
||||
|
||||
private SubscribedSubredditViewModel mSubscribedSubredditViewModel;
|
||||
|
||||
private boolean mInsertSuccess = false;
|
||||
|
||||
@Inject
|
||||
@Named("user_info")
|
||||
SharedPreferences sharedPreferences;
|
||||
@ -73,7 +72,7 @@ public class SubscribedSubredditsListingFragment extends Fragment {
|
||||
|
||||
SubscribedSubredditsRecyclerViewAdapter adapter;
|
||||
if(getArguments().getBoolean(EXTRA_IS_SUBREDDIT_SELECTION)) {
|
||||
adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity,
|
||||
adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity, getArguments().getBoolean(EXTRA_EXTRA_CLEAR_SELECTION),
|
||||
(name, iconUrl, subredditIsUser) -> ((SubredditSelectionActivity) mActivity).getSelectedSubreddit(name, iconUrl, subredditIsUser));
|
||||
} else {
|
||||
adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity);
|
||||
|
@ -28,6 +28,7 @@ class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
|
||||
private String username;
|
||||
private String userIconUrl;
|
||||
private boolean hasClearSelectionRow;
|
||||
|
||||
interface ItemClickListener {
|
||||
void onClick(String name, String iconUrl, boolean subredditIsUser);
|
||||
@ -38,8 +39,9 @@ class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
glide = Glide.with(context.getApplicationContext());
|
||||
}
|
||||
|
||||
SubscribedSubredditsRecyclerViewAdapter(Context context, ItemClickListener itemClickListener) {
|
||||
SubscribedSubredditsRecyclerViewAdapter(Context context, boolean hasClearSelectionRow, ItemClickListener itemClickListener) {
|
||||
mContext = context;
|
||||
this.hasClearSelectionRow = hasClearSelectionRow;
|
||||
glide = Glide.with(context.getApplicationContext());
|
||||
this.itemClickListener = itemClickListener;
|
||||
}
|
||||
@ -56,21 +58,31 @@ class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
String iconUrl;
|
||||
|
||||
if(itemClickListener != null) {
|
||||
if(viewHolder.getAdapterPosition() == 0) {
|
||||
name = username;
|
||||
iconUrl = userIconUrl;
|
||||
} else {
|
||||
name = mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 1).getName();
|
||||
iconUrl = mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 1).getIconUrl();
|
||||
}
|
||||
|
||||
viewHolder.itemView.setOnClickListener(view -> {
|
||||
if(hasClearSelectionRow) {
|
||||
if(viewHolder.getAdapterPosition() == 0) {
|
||||
itemClickListener.onClick(name, iconUrl, true);
|
||||
((SubredditViewHolder) viewHolder).subredditNameTextView.setText(R.string.all_subreddits);
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(null, null, false));
|
||||
return;
|
||||
} else if(viewHolder.getAdapterPosition() == 1) {
|
||||
name = username;
|
||||
iconUrl = userIconUrl;
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, true));
|
||||
} else {
|
||||
itemClickListener.onClick(name, iconUrl, false);
|
||||
name = mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 2).getName();
|
||||
iconUrl = mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 2).getIconUrl();
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, false));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if(viewHolder.getAdapterPosition() == 0) {
|
||||
name = username;
|
||||
iconUrl = userIconUrl;
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, true));
|
||||
} else {
|
||||
name = mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 1).getName();
|
||||
iconUrl = mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 1).getIconUrl();
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, false));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
name = mSubscribedSubredditData.get(viewHolder.getAdapterPosition()).getName();
|
||||
iconUrl = mSubscribedSubredditData.get(viewHolder.getAdapterPosition()).getIconUrl();
|
||||
@ -100,7 +112,11 @@ class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
public int getItemCount() {
|
||||
if(mSubscribedSubredditData != null) {
|
||||
if(itemClickListener != null) {
|
||||
return mSubscribedSubredditData.size() + 1;
|
||||
if(hasClearSelectionRow) {
|
||||
return mSubscribedSubredditData.size() + 2;
|
||||
} else {
|
||||
return mSubscribedSubredditData.size() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return mSubscribedSubredditData.size();
|
||||
|
@ -53,6 +53,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
|
||||
@BindView(R.id.coordinator_layout_view_subreddit_detail_activity) CoordinatorLayout coordinatorLayout;
|
||||
@BindView(R.id.appbar_layout_view_subreddit_detail) AppBarLayout appBarLayout;
|
||||
@BindView(R.id.collapsing_toolbar_layout_view_subreddit_detail_activity) CollapsingToolbarLayout collapsingToolbarLayout;
|
||||
@BindView(R.id.toolbar) Toolbar toolbar;
|
||||
@BindView(R.id.banner_image_view_view_subreddit_detail_activity) GifImageView bannerImageView;
|
||||
@BindView(R.id.icon_gif_image_view_view_subreddit_detail_activity) GifImageView iconGifImageView;
|
||||
@BindView(R.id.subscribe_subreddit_chip_view_subreddit_detail_activity) Chip subscribeSubredditChip;
|
||||
@ -62,6 +63,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
|
||||
@BindView(R.id.description_text_view_view_subreddit_detail_activity) TextView descriptionTextView;
|
||||
@BindView(R.id.fab_view_subreddit_detail_activity) FloatingActionButton fab;
|
||||
|
||||
private String subredditName;
|
||||
private boolean subscriptionReady = false;
|
||||
private boolean isInLazyMode = false;
|
||||
|
||||
@ -113,11 +115,10 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
|
||||
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
|
||||
String subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME_KEY);
|
||||
subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME_KEY);
|
||||
String title = "r/" + subredditName;
|
||||
subredditNameTextView.setText(title);
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
toolbar.setTitle(title);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
@ -260,8 +261,8 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
|
||||
if(savedInstanceState == null) {
|
||||
mFragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(PostFragment.NAME_KEY, subredditName);
|
||||
bundle.putInt(PostFragment.POST_TYPE_KEY, PostDataSource.TYPE_SUBREDDIT);
|
||||
bundle.putString(PostFragment.EXTRA_SUBREDDIT_NAME_KEY, subredditName);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE_KEY, PostDataSource.TYPE_SUBREDDIT);
|
||||
mFragment.setArguments(bundle);
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit();
|
||||
} else {
|
||||
@ -269,8 +270,8 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
|
||||
if(mFragment == null) {
|
||||
mFragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(PostFragment.NAME_KEY, subredditName);
|
||||
bundle.putInt(PostFragment.POST_TYPE_KEY, PostDataSource.TYPE_SUBREDDIT);
|
||||
bundle.putString(PostFragment.EXTRA_SUBREDDIT_NAME_KEY, subredditName);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE_KEY, PostDataSource.TYPE_SUBREDDIT);
|
||||
mFragment.setArguments(bundle);
|
||||
}
|
||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
||||
@ -334,6 +335,12 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
case R.id.action_search_view_subreddit_detail_activity:
|
||||
Intent intent = new Intent(this, SearchActivity.class);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_IS_USER, false);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case R.id.action_refresh_view_subreddit_detail_activity:
|
||||
if(mFragment instanceof FragmentCommunicator) {
|
||||
((FragmentCommunicator) mFragment).refresh();
|
||||
|
@ -63,6 +63,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
||||
private Menu mMenu;
|
||||
private AppBarLayout.LayoutParams params;
|
||||
|
||||
private String userName;
|
||||
private boolean subscriptionReady = false;
|
||||
private boolean isInLazyMode = false;
|
||||
|
||||
@ -96,7 +97,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
||||
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
|
||||
String userName = getIntent().getExtras().getString(EXTRA_USER_NAME_KEY);
|
||||
userName = getIntent().getExtras().getString(EXTRA_USER_NAME_KEY);
|
||||
String title = "u/" + userName;
|
||||
userNameTextView.setText(title);
|
||||
|
||||
@ -239,8 +240,8 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
||||
if(savedInstanceState == null) {
|
||||
mFragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(PostFragment.NAME_KEY, userName);
|
||||
bundle.putInt(PostFragment.POST_TYPE_KEY, PostDataSource.TYPE_USER);
|
||||
bundle.putString(PostFragment.EXTRA_SUBREDDIT_NAME_KEY, userName);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE_KEY, PostDataSource.TYPE_USER);
|
||||
mFragment.setArguments(bundle);
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_user_detail_activity, mFragment).commit();
|
||||
} else {
|
||||
@ -248,8 +249,8 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
||||
if(mFragment == null) {
|
||||
mFragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(PostFragment.NAME_KEY, userName);
|
||||
bundle.putInt(PostFragment.POST_TYPE_KEY, PostDataSource.TYPE_USER);
|
||||
bundle.putString(PostFragment.EXTRA_SUBREDDIT_NAME_KEY, userName);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE_KEY, PostDataSource.TYPE_USER);
|
||||
mFragment.setArguments(bundle);
|
||||
}
|
||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
||||
@ -282,6 +283,12 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
case R.id.action_search_view_user_detail_activity:
|
||||
Intent intent = new Intent(this, SearchActivity.class);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, userName);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_IS_USER, true);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case R.id.action_refresh_view_user_detail_activity:
|
||||
if (mFragment instanceof FragmentCommunicator) {
|
||||
((FragmentCommunicator) mFragment).refresh();
|
||||
|
@ -26,18 +26,18 @@
|
||||
android:paddingEnd="16dp">
|
||||
|
||||
<pl.droidsonroids.gif.GifImageView
|
||||
android:id="@+id/subreddit_icon_gif_image_view_post_text_activity"
|
||||
android:id="@+id/subreddit_icon_gif_image_view_search_activity"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/subreddit_name_text_view_post_text_activity"
|
||||
android:id="@+id/subreddit_name_text_view_search_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toStartOf="@id/rules_button_post_text_activity"
|
||||
android:layout_toEndOf="@id/subreddit_icon_gif_image_view_post_text_activity"
|
||||
android:layout_toEndOf="@id/subreddit_icon_gif_image_view_search_activity"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
|
@ -3,70 +3,87 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".SearchActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appbar_search_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<FrameLayout
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
android:id="@+id/collapsing_toolbar_layout_search_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="match_parent"
|
||||
app:titleEnabled="false"
|
||||
app:toolbarId="@+id/toolbar">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar_search_activity"
|
||||
<FrameLayout
|
||||
android:id="@+id/toolbar_frame_layout_search_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.ferfalk.simplesearchview.SimpleSearchView
|
||||
android:id="@+id/search_view_search_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textColor="@android:color/white"
|
||||
app:voiceSearch="true"
|
||||
app:searchBackground="@color/colorPrimary"
|
||||
app:cursorColor="@android:color/white"
|
||||
app:hintColor="#E0E0E0"
|
||||
app:iconsTint="@android:color/white"
|
||||
app:backIconTint="@android:color/white"
|
||||
app:iconsAlpha="1"
|
||||
app:backIconAlpha="1" />
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
app:navigationIcon="?attr/homeAsUpIndicator"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||
|
||||
</FrameLayout>
|
||||
<com.ferfalk.simplesearchview.SimpleSearchView
|
||||
android:id="@+id/search_view_search_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textColor="@android:color/white"
|
||||
app:backIconAlpha="1"
|
||||
app:backIconTint="@android:color/white"
|
||||
app:cursorColor="@android:color/white"
|
||||
app:hintColor="#E0E0E0"
|
||||
app:iconsAlpha="1"
|
||||
app:iconsTint="@android:color/white"
|
||||
app:searchBackground="@color/colorPrimary"
|
||||
app:voiceSearch="true" />
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tab_layout_search_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"/>
|
||||
</FrameLayout>
|
||||
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/transparent_overlay_search_activity"
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#40000000"
|
||||
android:elevation="1dp"
|
||||
android:visibility="gone"/>
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:id="@+id/view_pager_search_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context=".SearchActivity" />
|
||||
<RelativeLayout
|
||||
android:id="@+id/subreddit_name_relative_layout_search_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?attr/selectableItemBackground">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/search_in_text_view_search_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/search_in"
|
||||
android:textColor="@color/colorAccent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/subreddit_name_text_view_search_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_toEndOf="@id/search_in_text_view_search_activity"
|
||||
android:text="@string/all_subreddits"
|
||||
android:textColor="@color/primaryTextColor" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
72
app/src/main/res/layout/activity_search_result.xml
Normal file
72
app/src/main/res/layout/activity_search_result.xml
Normal file
@ -0,0 +1,72 @@
|
||||
<?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">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appbar_search_result_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar_search_result_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||
|
||||
<com.ferfalk.simplesearchview.SimpleSearchView
|
||||
android:id="@+id/search_view_search_result_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textColor="@android:color/white"
|
||||
app:voiceSearch="true"
|
||||
app:searchBackground="@color/colorPrimary"
|
||||
app:cursorColor="@android:color/white"
|
||||
app:hintColor="#E0E0E0"
|
||||
app:iconsTint="@android:color/white"
|
||||
app:backIconTint="@android:color/white"
|
||||
app:iconsAlpha="1"
|
||||
app:backIconAlpha="1" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tab_layout_search_result_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>
|
||||
|
||||
<View
|
||||
android:id="@+id/transparent_overlay_search_result_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#40000000"
|
||||
android:elevation="1dp"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:id="@+id/view_pager_search_result_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context=".SearchResultActivity" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -1,10 +1,11 @@
|
||||
<menu 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"
|
||||
tools:context="ml.docilealligator.infinityforreddit.SearchActivity">
|
||||
tools:context="ml.docilealligator.infinityforreddit.SearchResultActivity">
|
||||
<item
|
||||
android:id="@+id/action_search_search_activity"
|
||||
android:orderInCategory="1"
|
||||
android:title="@string/action_search"
|
||||
app:showAsAction="always" />
|
||||
android:icon="@drawable/ic_search_white_24dp"
|
||||
app:showAsAction="ifRoom" />
|
||||
</menu>
|
||||
|
12
app/src/main/res/menu/search_activity.xml
Normal file
12
app/src/main/res/menu/search_activity.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu 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"
|
||||
tools:context="ml.docilealligator.infinityforreddit.SearchResultActivity">
|
||||
<item
|
||||
android:id="@+id/action_search_search_activity"
|
||||
android:orderInCategory="1"
|
||||
android:title="@string/action_search"
|
||||
android:icon="@drawable/ic_search_white_24dp"
|
||||
app:showAsAction="ifRoom" />
|
||||
</menu>
|
16
app/src/main/res/menu/search_result_activity.xml
Normal file
16
app/src/main/res/menu/search_result_activity.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_search_search_result_activity"
|
||||
android:orderInCategory="1"
|
||||
android:title="@string/action_search"
|
||||
android:icon="@drawable/ic_search_white_24dp"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_refresh_search_result_activity"
|
||||
android:orderInCategory="2"
|
||||
android:title="@string/action_refresh"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
@ -4,15 +4,21 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="ml.docilealligator.infinityforreddit.ViewSubredditDetailActivity">
|
||||
<item
|
||||
android:id="@+id/action_refresh_view_subreddit_detail_activity"
|
||||
android:id="@+id/action_search_view_subreddit_detail_activity"
|
||||
android:orderInCategory="1"
|
||||
android:title="@string/action_search"
|
||||
android:icon="@drawable/ic_search_white_24dp"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/action_refresh_view_subreddit_detail_activity"
|
||||
android:orderInCategory="2"
|
||||
android:title="@string/action_refresh"
|
||||
android:icon="@drawable/ic_refresh_white_24dp"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_lazy_mode_view_subreddit_detail_activity"
|
||||
android:orderInCategory="2"
|
||||
android:orderInCategory="3"
|
||||
android:title="@string/action_start_lazy_mode"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
@ -3,15 +3,21 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="ml.docilealligator.infinityforreddit.ViewUserDetailActivity">
|
||||
<item
|
||||
android:id="@+id/action_refresh_view_user_detail_activity"
|
||||
android:id="@+id/action_search_view_user_detail_activity"
|
||||
android:orderInCategory="1"
|
||||
android:title="@string/action_search"
|
||||
android:icon="@drawable/ic_search_white_24dp"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/action_refresh_view_user_detail_activity"
|
||||
android:orderInCategory="2"
|
||||
android:title="@string/action_refresh"
|
||||
android:icon="@drawable/ic_refresh_white_24dp"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_lazy_mode_view_user_detail_activity"
|
||||
android:orderInCategory="2"
|
||||
android:orderInCategory="3"
|
||||
android:title="@string/action_start_lazy_mode"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
|
@ -128,4 +128,7 @@
|
||||
|
||||
<string name="no_rule">No rule</string>
|
||||
<string name="error_loading_rules">Error loading rules.\nTap to retry.</string>
|
||||
|
||||
<string name="search_in">Search in</string>
|
||||
<string name="all_subreddits">All subreddits</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user