mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-01 13:57:10 +01:00
Display search history in SearchActivity. Save suggested sort type and nsfw info in database for SubredditData. Fix an issue in parsing posts.
This commit is contained in:
parent
8dd4759035
commit
6e4519ef93
@ -17,6 +17,9 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.ferfalk.simplesearchview.SimpleSearchView;
|
import com.ferfalk.simplesearchview.SimpleSearchView;
|
||||||
import com.google.android.material.appbar.AppBarLayout;
|
import com.google.android.material.appbar.AppBarLayout;
|
||||||
@ -30,10 +33,14 @@ import javax.inject.Named;
|
|||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
import ml.docilealligator.infinityforreddit.Adapter.SearchActivityRecyclerViewAdapter;
|
||||||
|
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
|
import ml.docilealligator.infinityforreddit.RecentSearchQuery.RecentSearchQueryViewModel;
|
||||||
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
|
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
|
||||||
|
|
||||||
public class SearchActivity extends BaseActivity {
|
public class SearchActivity extends BaseActivity {
|
||||||
@ -45,6 +52,8 @@ public class SearchActivity extends BaseActivity {
|
|||||||
static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
|
static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
|
||||||
static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIURL";
|
static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIURL";
|
||||||
|
|
||||||
|
private static final String NULL_ACCOUNT_NAME_STATE = "NANS";
|
||||||
|
private static final String ACCOUNT_NAME_STATE = "ANS";
|
||||||
private static final String SUBREDDIT_NAME_STATE = "SNS";
|
private static final String SUBREDDIT_NAME_STATE = "SNS";
|
||||||
private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
|
private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
|
||||||
|
|
||||||
@ -65,14 +74,27 @@ public class SearchActivity extends BaseActivity {
|
|||||||
TextView searchInTextView;
|
TextView searchInTextView;
|
||||||
@BindView(R.id.subreddit_name_text_view_search_activity)
|
@BindView(R.id.subreddit_name_text_view_search_activity)
|
||||||
TextView subredditNameTextView;
|
TextView subredditNameTextView;
|
||||||
|
@BindView(R.id.divider_search_activity)
|
||||||
|
View divider;
|
||||||
|
@BindView(R.id.recent_summary_text_view_search_activity)
|
||||||
|
TextView recentSummaryTextView;
|
||||||
|
@BindView(R.id.recycler_view_search_activity)
|
||||||
|
RecyclerView recyclerView;
|
||||||
|
@Inject
|
||||||
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
@Inject
|
@Inject
|
||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
|
private boolean mNullAccountName = false;
|
||||||
|
private String mAccountName;
|
||||||
private String query;
|
private String query;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
private boolean subredditIsUser;
|
private boolean subredditIsUser;
|
||||||
|
private boolean searchOnlySubreddits;
|
||||||
|
private SearchActivityRecyclerViewAdapter adapter;
|
||||||
|
RecentSearchQueryViewModel mRecentSearchQueryViewModel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -96,7 +118,7 @@ public class SearchActivity extends BaseActivity {
|
|||||||
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
boolean searchOnlySubreddits = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_SUBREDDITS, false);
|
searchOnlySubreddits = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_SUBREDDITS, false);
|
||||||
|
|
||||||
simpleSearchView.setOnSearchViewListener(new SimpleSearchView.SearchViewListener() {
|
simpleSearchView.setOnSearchViewListener(new SimpleSearchView.SearchViewListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -123,23 +145,7 @@ public class SearchActivity extends BaseActivity {
|
|||||||
simpleSearchView.setOnQueryTextListener(new SimpleSearchView.OnQueryTextListener() {
|
simpleSearchView.setOnQueryTextListener(new SimpleSearchView.OnQueryTextListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextSubmit(String query) {
|
public boolean onQueryTextSubmit(String query) {
|
||||||
if (searchOnlySubreddits) {
|
search(query);
|
||||||
Intent intent = new Intent(SearchActivity.this, SearchSubredditsResultActivity.class);
|
|
||||||
intent.putExtra(SearchSubredditsResultActivity.EXTRA_QUERY, query);
|
|
||||||
startActivityForResult(intent, SUBREDDIT_SEARCH_REQUEST_CODE);
|
|
||||||
} else {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
startActivity(intent);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,6 +161,8 @@ public class SearchActivity extends BaseActivity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
|
mNullAccountName = savedInstanceState.getBoolean(NULL_ACCOUNT_NAME_STATE);
|
||||||
|
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
||||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||||
subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE);
|
subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE);
|
||||||
|
|
||||||
@ -163,8 +171,15 @@ public class SearchActivity extends BaseActivity {
|
|||||||
} else {
|
} else {
|
||||||
subredditNameTextView.setText(subredditName);
|
subredditNameTextView.setText(subredditName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mNullAccountName && mAccountName == null) {
|
||||||
|
getCurrentAccountAndInitializeViewPager();
|
||||||
|
} else {
|
||||||
|
bindView();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
query = getIntent().getStringExtra(EXTRA_QUERY);
|
query = getIntent().getStringExtra(EXTRA_QUERY);
|
||||||
|
getCurrentAccountAndInitializeViewPager();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (searchOnlySubreddits) {
|
if (searchOnlySubreddits) {
|
||||||
@ -185,6 +200,60 @@ public class SearchActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getCurrentAccountAndInitializeViewPager() {
|
||||||
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
|
if (account == null) {
|
||||||
|
mNullAccountName = true;
|
||||||
|
} else {
|
||||||
|
mAccountName = account.getUsername();
|
||||||
|
}
|
||||||
|
bindView();
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindView() {
|
||||||
|
if (mAccountName != null) {
|
||||||
|
adapter = new SearchActivityRecyclerViewAdapter(this, mCustomThemeWrapper, this::search);
|
||||||
|
recyclerView.setNestedScrollingEnabled(false);
|
||||||
|
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
|
mRecentSearchQueryViewModel = new ViewModelProvider(this,
|
||||||
|
new RecentSearchQueryViewModel.Factory(mRedditDataRoomDatabase, mAccountName))
|
||||||
|
.get(RecentSearchQueryViewModel.class);
|
||||||
|
|
||||||
|
mRecentSearchQueryViewModel.getAllRecentSearchQueries().observe(this, recentSearchQueries -> {
|
||||||
|
if (recentSearchQueries != null && !recentSearchQueries.isEmpty()) {
|
||||||
|
divider.setVisibility(View.VISIBLE);
|
||||||
|
recentSummaryTextView.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
divider.setVisibility(View.GONE);
|
||||||
|
recentSummaryTextView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
adapter.setRecentSearchQueries(recentSearchQueries);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void search(String query) {
|
||||||
|
if (searchOnlySubreddits) {
|
||||||
|
Intent intent = new Intent(SearchActivity.this, SearchSubredditsResultActivity.class);
|
||||||
|
intent.putExtra(SearchSubredditsResultActivity.EXTRA_QUERY, query);
|
||||||
|
startActivityForResult(intent, SUBREDDIT_SEARCH_REQUEST_CODE);
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SharedPreferences getDefaultSharedPreferences() {
|
public SharedPreferences getDefaultSharedPreferences() {
|
||||||
return mSharedPreferences;
|
return mSharedPreferences;
|
||||||
@ -205,8 +274,11 @@ public class SearchActivity extends BaseActivity {
|
|||||||
simpleSearchView.setTextColor(toolbarPrimaryTextAndIconColorColor);
|
simpleSearchView.setTextColor(toolbarPrimaryTextAndIconColorColor);
|
||||||
simpleSearchView.setBackIconColor(toolbarPrimaryTextAndIconColorColor);
|
simpleSearchView.setBackIconColor(toolbarPrimaryTextAndIconColorColor);
|
||||||
simpleSearchView.setHintTextColor(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor());
|
simpleSearchView.setHintTextColor(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor());
|
||||||
searchInTextView.setTextColor(mCustomThemeWrapper.getColorAccent());
|
int colorAccent = mCustomThemeWrapper.getColorAccent();
|
||||||
|
searchInTextView.setTextColor(colorAccent);
|
||||||
subredditNameTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
|
subredditNameTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
|
||||||
|
divider.setBackgroundColor(mCustomThemeWrapper.getDividerColor());
|
||||||
|
recentSummaryTextView.setTextColor(colorAccent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -288,6 +360,8 @@ public class SearchActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putBoolean(NULL_ACCOUNT_NAME_STATE, mNullAccountName);
|
||||||
|
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
||||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||||
outState.putBoolean(SUBREDDIT_IS_USER_STATE, subredditIsUser);
|
outState.putBoolean(SUBREDDIT_IS_USER_STATE, subredditIsUser);
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
|||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.Post.PostDataSource;
|
import ml.docilealligator.infinityforreddit.Post.PostDataSource;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
|
import ml.docilealligator.infinityforreddit.RecentSearchQuery.InsertRecentSearchQuery;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SortType;
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
||||||
@ -65,6 +66,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
||||||
private static final String ACCESS_TOKEN_STATE = "ATS";
|
private static final String ACCESS_TOKEN_STATE = "ATS";
|
||||||
private static final String ACCOUNT_NAME_STATE = "ANS";
|
private static final String ACCOUNT_NAME_STATE = "ANS";
|
||||||
|
private static final String INSERT_SEARCH_QUERY_SUCCESS_STATE = "ISQSS";
|
||||||
@BindView(R.id.coordinator_layout_search_result_activity)
|
@BindView(R.id.coordinator_layout_search_result_activity)
|
||||||
CoordinatorLayout coordinatorLayout;
|
CoordinatorLayout coordinatorLayout;
|
||||||
@BindView(R.id.appbar_layout_search_result_activity)
|
@BindView(R.id.appbar_layout_search_result_activity)
|
||||||
@ -93,6 +95,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private String mQuery;
|
private String mQuery;
|
||||||
private String mSubredditName;
|
private String mSubredditName;
|
||||||
|
private boolean mInsertSearchQuerySuccess;
|
||||||
private FragmentManager fragmentManager;
|
private FragmentManager fragmentManager;
|
||||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||||
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
|
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
|
||||||
@ -142,6 +145,17 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
setToolbarGoToTop(toolbar);
|
setToolbarGoToTop(toolbar);
|
||||||
|
|
||||||
|
// Get the intent, verify the action and get the query
|
||||||
|
Intent intent = getIntent();
|
||||||
|
String query = intent.getStringExtra(EXTRA_QUERY);
|
||||||
|
|
||||||
|
mSubredditName = intent.getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||||
|
|
||||||
|
if (query != null) {
|
||||||
|
mQuery = query;
|
||||||
|
setTitle(query);
|
||||||
|
}
|
||||||
|
|
||||||
fragmentManager = getSupportFragmentManager();
|
fragmentManager = getSupportFragmentManager();
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
@ -150,6 +164,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
||||||
|
mInsertSearchQuerySuccess = savedInstanceState.getBoolean(INSERT_SEARCH_QUERY_SUCCESS_STATE);
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
if (!mNullAccessToken && mAccessToken == null) {
|
||||||
getCurrentAccountAndInitializeViewPager();
|
getCurrentAccountAndInitializeViewPager();
|
||||||
} else {
|
} else {
|
||||||
@ -166,17 +181,6 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
searchUserAndSubredditSortTypeBottomSheetFragment = new SearchUserAndSubredditSortTypeBottomSheetFragment();
|
searchUserAndSubredditSortTypeBottomSheetFragment = new SearchUserAndSubredditSortTypeBottomSheetFragment();
|
||||||
|
|
||||||
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
|
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
|
||||||
|
|
||||||
// Get the intent, verify the action and get the query
|
|
||||||
Intent intent = getIntent();
|
|
||||||
String query = intent.getStringExtra(EXTRA_QUERY);
|
|
||||||
|
|
||||||
mSubredditName = intent.getStringExtra(EXTRA_SUBREDDIT_NAME);
|
|
||||||
|
|
||||||
if (query != null) {
|
|
||||||
mQuery = query;
|
|
||||||
setTitle(query);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -245,6 +249,10 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}).attach();
|
}).attach();
|
||||||
|
if (mAccountName != null && !mInsertSearchQuerySuccess && mQuery != null) {
|
||||||
|
InsertRecentSearchQuery.insertRecentSearchQueryListener(mRedditDataRoomDatabase, mAccountName,
|
||||||
|
mQuery, () -> mInsertSearchQuerySuccess = true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -300,6 +308,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
||||||
|
outState.putBoolean(INSERT_SEARCH_QUERY_SUCCESS_STATE, mInsertSearchQuerySuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,7 +65,7 @@ public class MarkdownBottomBarRecyclerViewAdapter extends RecyclerView.Adapter<R
|
|||||||
((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_strikethrough_black_24dp);
|
((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_strikethrough_black_24dp);
|
||||||
break;
|
break;
|
||||||
case HEADER:
|
case HEADER:
|
||||||
((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_header_hashtag_black_24dp);
|
((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_title_24dp);
|
||||||
break;
|
break;
|
||||||
case ORDERED_LIST:
|
case ORDERED_LIST:
|
||||||
((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_ordered_list_black_24dp);
|
((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_ordered_list_black_24dp);
|
||||||
|
@ -0,0 +1,83 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit.Adapter;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
||||||
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
|
import ml.docilealligator.infinityforreddit.RecentSearchQuery.RecentSearchQuery;
|
||||||
|
import ml.docilealligator.infinityforreddit.Utils.Utils;
|
||||||
|
|
||||||
|
public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
private List<RecentSearchQuery> recentSearchQueries;
|
||||||
|
private int primaryTextColor;
|
||||||
|
private Drawable historyIcon;
|
||||||
|
private ItemOnClickListener itemOnClickListener;
|
||||||
|
|
||||||
|
public interface ItemOnClickListener {
|
||||||
|
void onClick(String query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SearchActivityRecyclerViewAdapter(Activity activity, CustomThemeWrapper customThemeWrapper,
|
||||||
|
ItemOnClickListener itemOnClickListener) {
|
||||||
|
this.primaryTextColor = customThemeWrapper.getPrimaryTextColor();
|
||||||
|
this.historyIcon = Utils.getTintedDrawable(activity, R.drawable.ic_history_24dp, customThemeWrapper.getPrimaryIconColor());
|
||||||
|
this.itemOnClickListener = itemOnClickListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
return new RecentSearchQueryViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recent_search_query, parent, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||||
|
if (holder instanceof RecentSearchQueryViewHolder) {
|
||||||
|
if (recentSearchQueries != null && !recentSearchQueries.isEmpty() && position < recentSearchQueries.size()) {
|
||||||
|
((RecentSearchQueryViewHolder) holder).recentSearchQueryTextView.setText(recentSearchQueries.get(position).getSearchQuery());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return recentSearchQueries == null ? 0 : recentSearchQueries.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRecentSearchQueries(List<RecentSearchQuery> recentSearchQueries) {
|
||||||
|
this.recentSearchQueries = recentSearchQueries;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
class RecentSearchQueryViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
@BindView(R.id.recent_search_query_text_view_item_recent_search_query)
|
||||||
|
TextView recentSearchQueryTextView;
|
||||||
|
|
||||||
|
public RecentSearchQueryViewHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
ButterKnife.bind(this, itemView);
|
||||||
|
|
||||||
|
recentSearchQueryTextView.setTextColor(primaryTextColor);
|
||||||
|
recentSearchQueryTextView.setCompoundDrawablesWithIntrinsicBounds(historyIcon, null, null, null);
|
||||||
|
|
||||||
|
itemView.setOnClickListener(view -> {
|
||||||
|
if (recentSearchQueries != null && !recentSearchQueries.isEmpty()) {
|
||||||
|
itemOnClickListener.onClick(recentSearchQueries.get(getAdapterPosition()).getSearchQuery());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -100,9 +100,12 @@ class ParseSubscribedThing {
|
|||||||
String sidebarDescription = data.getString(JSONUtils.DESCRIPTION_KEY);
|
String sidebarDescription = data.getString(JSONUtils.DESCRIPTION_KEY);
|
||||||
int nSubscribers = data.getInt(JSONUtils.SUBSCRIBERS_KEY);
|
int nSubscribers = data.getInt(JSONUtils.SUBSCRIBERS_KEY);
|
||||||
long createdUTC = data.getLong(JSONUtils.CREATED_UTC_KEY);
|
long createdUTC = data.getLong(JSONUtils.CREATED_UTC_KEY);
|
||||||
|
String suggestedCommentSort = data.getString(JSONUtils.SUGGESTED_COMMENT_SORT_KEY);
|
||||||
|
boolean isNSFW = data.getBoolean(JSONUtils.OVER18_KEY);
|
||||||
newSubscribedSubredditData.add(new SubscribedSubredditData(id, name, iconUrl, accountName, isFavorite));
|
newSubscribedSubredditData.add(new SubscribedSubredditData(id, name, iconUrl, accountName, isFavorite));
|
||||||
newSubredditData.add(new SubredditData(id, subredditFullName, iconUrl,
|
newSubredditData.add(new SubredditData(id, subredditFullName, iconUrl,
|
||||||
bannerImageUrl, description, sidebarDescription, nSubscribers, createdUTC));
|
bannerImageUrl, description, sidebarDescription, nSubscribers, createdUTC,
|
||||||
|
suggestedCommentSort, isNSFW));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastItem = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY);
|
lastItem = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY);
|
||||||
|
@ -118,7 +118,7 @@ public class ParsePost {
|
|||||||
|
|
||||||
JSONArray thumbnailPreviews = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY);
|
JSONArray thumbnailPreviews = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY);
|
||||||
for (int i = 0; i < thumbnailPreviews.length(); i++) {
|
for (int i = 0; i < thumbnailPreviews.length(); i++) {
|
||||||
JSONObject thumbnailPreview = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY).getJSONObject(2);
|
JSONObject thumbnailPreview = thumbnailPreviews.getJSONObject(i);
|
||||||
String thumbnailPreviewUrl = thumbnailPreview.getString(JSONUtils.URL_KEY);
|
String thumbnailPreviewUrl = thumbnailPreview.getString(JSONUtils.URL_KEY);
|
||||||
int thumbnailPreviewWidth = thumbnailPreview.getInt(JSONUtils.WIDTH_KEY);
|
int thumbnailPreviewWidth = thumbnailPreview.getInt(JSONUtils.WIDTH_KEY);
|
||||||
int thumbnailPreviewHeight = thumbnailPreview.getInt(JSONUtils.HEIGHT_KEY);
|
int thumbnailPreviewHeight = thumbnailPreview.getInt(JSONUtils.HEIGHT_KEY);
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit.RecentSearchQuery;
|
||||||
|
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
|
||||||
|
public class InsertRecentSearchQuery {
|
||||||
|
public interface InsertRecentSearchQueryListener {
|
||||||
|
void success();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void insertRecentSearchQueryListener(RedditDataRoomDatabase redditDataRoomDatabase, String username,
|
||||||
|
String recentSearchQuery, InsertRecentSearchQueryListener insertRecentSearchQueryListener) {
|
||||||
|
new InsertRecentSearchQueryAsyncTask(redditDataRoomDatabase, username, recentSearchQuery, insertRecentSearchQueryListener).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class InsertRecentSearchQueryAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
|
private RecentSearchQueryDao recentSearchQueryDao;
|
||||||
|
private String username;
|
||||||
|
private String recentSearchQuery;
|
||||||
|
private InsertRecentSearchQueryListener insertRecentSearchQueryListener;
|
||||||
|
|
||||||
|
public InsertRecentSearchQueryAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String username,
|
||||||
|
String recentSearchQuery, InsertRecentSearchQueryListener insertRecentSearchQueryListener) {
|
||||||
|
this.recentSearchQueryDao = redditDataRoomDatabase.recentSearchQueryDao();
|
||||||
|
this.username = username;
|
||||||
|
this.recentSearchQuery = recentSearchQuery;
|
||||||
|
this.insertRecentSearchQueryListener = insertRecentSearchQueryListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... voids) {
|
||||||
|
List<RecentSearchQuery> recentSearchQueries = recentSearchQueryDao.getAllRecentSearchQueries(username);
|
||||||
|
if (recentSearchQueries.size() >= 5) {
|
||||||
|
for (int i = 4; i < recentSearchQueries.size(); i++) {
|
||||||
|
recentSearchQueryDao.deleteRecentSearchQueries(recentSearchQueries.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
recentSearchQueryDao.insert(new RecentSearchQuery(username, recentSearchQuery));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void aVoid) {
|
||||||
|
super.onPostExecute(aVoid);
|
||||||
|
insertRecentSearchQueryListener.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit.RecentSearchQuery;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.room.ColumnInfo;
|
||||||
|
import androidx.room.Entity;
|
||||||
|
import androidx.room.ForeignKey;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.Account.Account;
|
||||||
|
|
||||||
|
@Entity(tableName = "recent_search_queries", primaryKeys = {"username", "search_query"},
|
||||||
|
foreignKeys = @ForeignKey(entity = Account.class, parentColumns = "username",
|
||||||
|
childColumns = "username", onDelete = ForeignKey.CASCADE))
|
||||||
|
public class RecentSearchQuery {
|
||||||
|
@NonNull
|
||||||
|
@ColumnInfo(name = "username")
|
||||||
|
private String username;
|
||||||
|
@NonNull
|
||||||
|
@ColumnInfo(name = "search_query")
|
||||||
|
private String searchQuery;
|
||||||
|
|
||||||
|
public RecentSearchQuery(@NonNull String username, @NonNull String searchQuery) {
|
||||||
|
this.username = username;
|
||||||
|
this.searchQuery = searchQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(@NonNull String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public String getSearchQuery() {
|
||||||
|
return searchQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSearchQuery(@NonNull String searchQuery) {
|
||||||
|
this.searchQuery = searchQuery;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit.RecentSearchQuery;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.room.Dao;
|
||||||
|
import androidx.room.Delete;
|
||||||
|
import androidx.room.Insert;
|
||||||
|
import androidx.room.OnConflictStrategy;
|
||||||
|
import androidx.room.Query;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
public interface RecentSearchQueryDao {
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
void insert(RecentSearchQuery recentSearchQuery);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM recent_search_queries WHERE username = :username")
|
||||||
|
LiveData<List<RecentSearchQuery>> getAllRecentSearchQueriesLiveData(String username);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM recent_search_queries WHERE username = :username")
|
||||||
|
List<RecentSearchQuery> getAllRecentSearchQueries(String username);
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
void deleteRecentSearchQueries(RecentSearchQuery recentSearchQuery);
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit.RecentSearchQuery;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
|
||||||
|
public class RecentSearchQueryRepository {
|
||||||
|
private LiveData<List<RecentSearchQuery>> mAllRecentSearchQueries;
|
||||||
|
|
||||||
|
RecentSearchQueryRepository(RedditDataRoomDatabase redditDataRoomDatabase, String username) {
|
||||||
|
mAllRecentSearchQueries = redditDataRoomDatabase.recentSearchQueryDao().getAllRecentSearchQueriesLiveData(username);
|
||||||
|
}
|
||||||
|
|
||||||
|
LiveData<List<RecentSearchQuery>> getAllRecentSearchQueries() {
|
||||||
|
return mAllRecentSearchQueries;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit.RecentSearchQuery;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.ViewModel;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
|
||||||
|
public class RecentSearchQueryViewModel extends ViewModel {
|
||||||
|
private LiveData<List<RecentSearchQuery>> mAllRecentSearchQueries;
|
||||||
|
|
||||||
|
public RecentSearchQueryViewModel(RedditDataRoomDatabase redditDataRoomDatabase, String username) {
|
||||||
|
mAllRecentSearchQueries = new RecentSearchQueryRepository(redditDataRoomDatabase, username).getAllRecentSearchQueries();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<List<RecentSearchQuery>> getAllRecentSearchQueries() {
|
||||||
|
return mAllRecentSearchQueries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Factory extends ViewModelProvider.NewInstanceFactory {
|
||||||
|
private RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
private String mUsername;
|
||||||
|
|
||||||
|
public Factory(RedditDataRoomDatabase redditDataRoomDatabase, String username) {
|
||||||
|
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
|
mUsername = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||||
|
return (T) new RecentSearchQueryViewModel(mRedditDataRoomDatabase, mUsername);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,8 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme;
|
|||||||
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeDao;
|
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeDao;
|
||||||
import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit;
|
import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit;
|
||||||
import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditDao;
|
import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditDao;
|
||||||
|
import ml.docilealligator.infinityforreddit.RecentSearchQuery.RecentSearchQuery;
|
||||||
|
import ml.docilealligator.infinityforreddit.RecentSearchQuery.RecentSearchQueryDao;
|
||||||
import ml.docilealligator.infinityforreddit.Subreddit.SubredditDao;
|
import ml.docilealligator.infinityforreddit.Subreddit.SubredditDao;
|
||||||
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
|
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
|
||||||
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditDao;
|
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditDao;
|
||||||
@ -26,7 +28,7 @@ import ml.docilealligator.infinityforreddit.User.UserDao;
|
|||||||
import ml.docilealligator.infinityforreddit.User.UserData;
|
import ml.docilealligator.infinityforreddit.User.UserData;
|
||||||
|
|
||||||
@Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class,
|
@Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class,
|
||||||
SubscribedUserData.class, MultiReddit.class, CustomTheme.class}, version = 9)
|
SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class}, version = 10)
|
||||||
public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||||
private static RedditDataRoomDatabase INSTANCE;
|
private static RedditDataRoomDatabase INSTANCE;
|
||||||
|
|
||||||
@ -37,7 +39,8 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
|||||||
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
|
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
|
||||||
RedditDataRoomDatabase.class, "reddit_data")
|
RedditDataRoomDatabase.class, "reddit_data")
|
||||||
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5,
|
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5,
|
||||||
MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9)
|
MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9,
|
||||||
|
MIGRATION_9_10)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,6 +62,8 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
|||||||
|
|
||||||
public abstract CustomThemeDao customThemeDao();
|
public abstract CustomThemeDao customThemeDao();
|
||||||
|
|
||||||
|
public abstract RecentSearchQueryDao recentSearchQueryDao();
|
||||||
|
|
||||||
private static final Migration MIGRATION_1_2 = new Migration(1, 2) {
|
private static final Migration MIGRATION_1_2 = new Migration(1, 2) {
|
||||||
@Override
|
@Override
|
||||||
public void migrate(SupportSQLiteDatabase database) {
|
public void migrate(SupportSQLiteDatabase database) {
|
||||||
@ -209,4 +214,19 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static final Migration MIGRATION_9_10 = new Migration(9, 10) {
|
||||||
|
@Override
|
||||||
|
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||||
|
database.execSQL("CREATE TABLE recent_search_queries" +
|
||||||
|
"(username TEXT NOT NULL, search_query TEXT NOT NULL, PRIMARY KEY(username, search_query), " +
|
||||||
|
"FOREIGN KEY(username) REFERENCES accounts(username) ON DELETE CASCADE)");
|
||||||
|
|
||||||
|
database.execSQL("ALTER TABLE subreddits"
|
||||||
|
+ " ADD COLUMN suggested_comment_sort TEXT");
|
||||||
|
|
||||||
|
database.execSQL("ALTER TABLE subreddits"
|
||||||
|
+ " ADD COLUMN over18 INTEGER DEFAULT 0 NOT NULL");
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
|
|
||||||
import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
|
import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
|
||||||
import ml.docilealligator.infinityforreddit.Utils.Utils;
|
import ml.docilealligator.infinityforreddit.Utils.Utils;
|
||||||
|
|
||||||
@ -27,6 +26,8 @@ class ParseSubredditData {
|
|||||||
String description = subredditDataJsonObject.getString(JSONUtils.PUBLIC_DESCRIPTION_KEY).trim();
|
String description = subredditDataJsonObject.getString(JSONUtils.PUBLIC_DESCRIPTION_KEY).trim();
|
||||||
String sidebarDescription = Utils.modifyMarkdown(subredditDataJsonObject.getString(JSONUtils.DESCRIPTION_KEY).trim());
|
String sidebarDescription = Utils.modifyMarkdown(subredditDataJsonObject.getString(JSONUtils.DESCRIPTION_KEY).trim());
|
||||||
long createdUTC = subredditDataJsonObject.getLong(JSONUtils.CREATED_UTC_KEY) * 1000;
|
long createdUTC = subredditDataJsonObject.getLong(JSONUtils.CREATED_UTC_KEY) * 1000;
|
||||||
|
String suggestedCommentSort = subredditDataJsonObject.getString(JSONUtils.SUGGESTED_COMMENT_SORT_KEY);
|
||||||
|
boolean isNSFW = subredditDataJsonObject.getBoolean(JSONUtils.OVER18_KEY);
|
||||||
|
|
||||||
String bannerImageUrl;
|
String bannerImageUrl;
|
||||||
if (subredditDataJsonObject.isNull(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY)) {
|
if (subredditDataJsonObject.isNull(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY)) {
|
||||||
@ -54,7 +55,7 @@ class ParseSubredditData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new SubredditData(id, subredditFullName, iconUrl, bannerImageUrl, description,
|
return new SubredditData(id, subredditFullName, iconUrl, bannerImageUrl, description,
|
||||||
sidebarDescription, nSubscribers, createdUTC);
|
sidebarDescription, nSubscribers, createdUTC, suggestedCommentSort, isNSFW);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ParseSubredditDataListener {
|
interface ParseSubredditDataListener {
|
||||||
|
@ -25,9 +25,14 @@ public class SubredditData {
|
|||||||
private int nSubscribers;
|
private int nSubscribers;
|
||||||
@ColumnInfo(name = "created_utc")
|
@ColumnInfo(name = "created_utc")
|
||||||
private long createdUTC;
|
private long createdUTC;
|
||||||
|
@ColumnInfo(name = "suggested_comment_sort")
|
||||||
|
private String suggestedCommentSort;
|
||||||
|
@ColumnInfo(name = "over18")
|
||||||
|
private boolean isNSFW;
|
||||||
|
|
||||||
public SubredditData(@NonNull String id, String name, String iconUrl, String bannerUrl,
|
public SubredditData(@NonNull String id, String name, String iconUrl, String bannerUrl,
|
||||||
String description, String sidebarDescription, int nSubscribers, long createdUTC) {
|
String description, String sidebarDescription, int nSubscribers, long createdUTC,
|
||||||
|
String suggestedCommentSort, boolean isNSFW) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.iconUrl = iconUrl;
|
this.iconUrl = iconUrl;
|
||||||
@ -36,6 +41,8 @@ public class SubredditData {
|
|||||||
this.sidebarDescription = sidebarDescription;
|
this.sidebarDescription = sidebarDescription;
|
||||||
this.nSubscribers = nSubscribers;
|
this.nSubscribers = nSubscribers;
|
||||||
this.createdUTC = createdUTC;
|
this.createdUTC = createdUTC;
|
||||||
|
this.suggestedCommentSort = suggestedCommentSort;
|
||||||
|
this.isNSFW = isNSFW;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -70,4 +77,12 @@ public class SubredditData {
|
|||||||
public long getCreatedUTC() {
|
public long getCreatedUTC() {
|
||||||
return createdUTC;
|
return createdUTC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSuggestedCommentSort() {
|
||||||
|
return suggestedCommentSort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNSFW() {
|
||||||
|
return isNSFW;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,4 +125,6 @@ public class JSONUtils {
|
|||||||
public static final String GIF_KEY = "gif";
|
public static final String GIF_KEY = "gif";
|
||||||
public static final String MAX_EMOJIS_KEY = "max_emojis";
|
public static final String MAX_EMOJIS_KEY = "max_emojis";
|
||||||
public static final String RICHTEXT_KEY = "richtext";
|
public static final String RICHTEXT_KEY = "richtext";
|
||||||
|
public static final String SUGGESTED_COMMENT_SORT_KEY = "suggested_comment_sort";
|
||||||
|
public static final String OVER18_KEY = "over18";
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="24dp"
|
|
||||||
android:height="24dp"
|
|
||||||
android:viewportWidth="48"
|
|
||||||
android:viewportHeight="48">
|
|
||||||
<path
|
|
||||||
android:pathData="M35.4182,18.3369c-0.2456,-0.3018 -0.6104,-0.4678 -1.0273,-0.4678H31.0766l0.9194,-4.4711c0.0864,-0.4199 -0.0063,-0.8359 -0.2549,-1.1406c-0.2461,-0.3008 -0.6108,-0.4668 -1.0278,-0.4668c-0.8237,0 -1.6011,0.6435 -1.77,1.4668l-0.2498,1.2147c-0.0082,0.0305 -0.0214,0.0594 -0.0277,0.0903l-0.6794,3.3066h-5.5789l0.9194,-4.4711c0.0864,-0.4199 -0.0063,-0.8359 -0.2549,-1.1406c-0.2461,-0.3008 -0.6108,-0.4668 -1.0278,-0.4668c-0.8237,0 -1.6011,0.6435 -1.77,1.4668l-0.2601,1.2647c-0.0032,0.0137 -0.0095,0.0266 -0.0124,0.0403l-0.6799,3.3066h-3.6087c-0.8237,0 -1.6016,0.6435 -1.7705,1.4658c-0.0864,0.4209 0.0068,0.8359 0.2554,1.1406c0.2461,0.3018 0.6108,0.4668 1.0273,0.4668h3.4649l-0.9841,4.7861h-3.6087c-0.8237,0 -1.6016,0.6435 -1.7705,1.4668c-0.0864,0.4189 0.0063,0.835 0.2544,1.1387c0.2461,0.3018 0.6113,0.4678 1.0283,0.4678h3.4649l-0.9244,4.4951c-0.0864,0.4199 0.0063,0.8359 0.2549,1.1406c0.2456,0.3008 0.6108,0.4668 1.0273,0.4668c0.8237,0 1.6016,-0.6435 1.7705,-1.4668l0.9533,-4.6357h5.5824l-0.9244,4.4951c-0.0864,0.4199 0.0063,0.8359 0.2549,1.1406c0.2461,0.3008 0.6108,0.4668 1.0278,0.4668c0.8237,0 1.6011,-0.6435 1.77,-1.4668l0.9533,-4.6357h3.4666c0.8237,0 1.6016,-0.6435 1.7705,-1.4658c0.0884,-0.4287 -0.001,-0.834 -0.2515,-1.1416c-0.2451,-0.3008 -0.6113,-0.4658 -1.0308,-0.4658h-3.3229l0.9837,-4.7861h3.4666c0.8237,0 1.6016,-0.6435 1.7705,-1.4668C35.7595,19.0566 35.6667,18.6406 35.4182,18.3369zM20.7882,25.7285l0.9837,-4.7861h5.5824l-0.9841,4.7861H20.7882z"
|
|
||||||
android:fillColor="#303030"/>
|
|
||||||
</vector>
|
|
9
app/src/main/res/drawable/ic_history_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_history_24dp.xml
Normal file
@ -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:pathData="M13,3c-4.97,0 -9,4.03 -9,9L1,12l3.89,3.89 0.07,0.14L9,12L6,12c0,-3.87 3.13,-7 7,-7s7,3.13 7,7 -3.13,7 -7,7c-1.93,0 -3.68,-0.79 -4.94,-2.06l-1.42,1.42C8.27,19.99 10.51,21 13,21c4.97,0 9,-4.03 9,-9s-4.03,-9 -9,-9zM12,8v5l4.28,2.54 0.72,-1.21 -3.5,-2.08L13.5,8L12,8z"
|
||||||
|
android:fillColor="#000000"/>
|
||||||
|
</vector>
|
9
app/src/main/res/drawable/ic_title_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_title_24dp.xml
Normal file
@ -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:pathData="M5,5.5C5,6.33 5.67,7 6.5,7h4v10.5c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5V7h4c0.83,0 1.5,-0.67 1.5,-1.5S18.33,4 17.5,4h-11C5.67,4 5,4.67 5,5.5z"
|
||||||
|
android:fillColor="#000000"/>
|
||||||
|
</vector>
|
@ -48,38 +48,64 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
|
|
||||||
<RelativeLayout
|
<LinearLayout
|
||||||
android:id="@+id/subreddit_name_relative_layout_search_activity"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:orientation="vertical">
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true"
|
<RelativeLayout
|
||||||
android:padding="16dp">
|
android:id="@+id/subreddit_name_relative_layout_search_activity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<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="?attr/colorAccent"
|
||||||
|
android:textSize="?attr/font_default"
|
||||||
|
android:fontFamily="?attr/font_family" />
|
||||||
|
|
||||||
|
<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="?attr/primaryTextColor"
|
||||||
|
android:textSize="?attr/font_default"
|
||||||
|
android:fontFamily="?attr/font_family" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/divider_search_activity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/search_in_text_view_search_activity"
|
android:id="@+id/recent_summary_text_view_search_activity"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/search_in"
|
android:padding="16dp"
|
||||||
android:textColor="?attr/colorAccent"
|
android:text="@string/recent_searches"
|
||||||
android:textSize="?attr/font_default"
|
android:fontFamily="?attr/font_family"
|
||||||
android:fontFamily="?attr/font_family" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<TextView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/subreddit_name_text_view_search_activity"
|
android:id="@+id/recycler_view_search_activity"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="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="?attr/primaryTextColor"
|
|
||||||
android:textSize="?attr/font_default"
|
|
||||||
android:fontFamily="?attr/font_family" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
||||||
|
19
app/src/main/res/layout/item_recent_search_query.xml
Normal file
19
app/src/main/res/layout/item_recent_search_query.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:background="?attr/selectableItemBackground">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/recent_search_query_text_view_item_recent_search_query"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:fontFamily="?attr/font_family"
|
||||||
|
android:textSize="?attr/font_default"
|
||||||
|
android:drawablePadding="16dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -912,4 +912,6 @@
|
|||||||
<string name="give_award_success">Award given</string>
|
<string name="give_award_success">Award given</string>
|
||||||
<string name="give_award_failed">Failed</string>
|
<string name="give_award_failed">Failed</string>
|
||||||
|
|
||||||
|
<string name="recent_searches">Recent searches</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user