Sorting posts is now available. Minor bugs fixed.

This commit is contained in:
Alex Ning 2019-07-26 10:50:32 +08:00
parent 66ed3d8f16
commit 1fc8423906
23 changed files with 635 additions and 137 deletions

View File

@ -35,9 +35,9 @@
<map>
<entry key="assetSourceType" value="FILE" />
<entry key="color" value="ffffff" />
<entry key="outputName" value="ic_outline_add_photo_24px" />
<entry key="outputName" value="ic_outline_sort_24px" />
<entry key="overrideSize" value="true" />
<entry key="sourceFile" value="$USER_HOME$/Downloads/outline-add_photo_alternate-24px.svg" />
<entry key="sourceFile" value="$USER_HOME$/Downloads/outline-sort-24px.svg" />
</map>
</option>
</PersistentState>

Binary file not shown.

Binary file not shown.

View File

@ -37,7 +37,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback {
private static final String FRAGMENT_OUT_STATE = "FOS";
private static final String FETCH_USER_INFO_STATE = "FUIS";
@ -52,8 +52,6 @@ public class MainActivity extends AppCompatActivity {
@BindView(R.id.settings_linear_layout_main_activity) LinearLayout settingsLinearLayout;
@BindView(R.id.fab_main_activity) FloatingActionButton fab;
private BottomSheetDialog dialog;
private TextView mNameTextView;
private TextView mKarmaTextView;
private GifImageView mProfileImageView;
@ -62,6 +60,8 @@ public class MainActivity extends AppCompatActivity {
private Fragment mFragment;
private RequestManager glide;
private AppBarLayout.LayoutParams params;
private BottomSheetDialog postTypedialog;
private SortTypeBottomSheetFragment sortTypeBottomSheetFragment;
private String mName;
private String mProfileImageUrl;
@ -92,17 +92,19 @@ public class MainActivity extends AppCompatActivity {
ButterKnife.bind(this);
View dialogView = View.inflate(this, R.layout.post_type_bottom_sheet, null);
LinearLayout textTypeLinearLayout = dialogView.findViewById(R.id.text_type_linear_layout_post_type_bottom_sheet);
LinearLayout linkTypeLinearLayout = dialogView.findViewById(R.id.link_type_linear_layout_post_type_bottom_sheet);
LinearLayout imageTypeLinearLayout = dialogView.findViewById(R.id.image_type_linear_layout_post_type_bottom_sheet);
LinearLayout videoTypeLinearLayout = dialogView.findViewById(R.id.video_type_linear_layout_post_type_bottom_sheet);
dialog = new BottomSheetDialog(this);
dialog.setContentView(dialogView);
((Infinity) getApplication()).getmAppComponent().inject(this);
View postTypeDialogView = View.inflate(this, R.layout.post_type_bottom_sheet, null);
LinearLayout textTypeLinearLayout = postTypeDialogView.findViewById(R.id.text_type_linear_layout_post_type_bottom_sheet);
LinearLayout linkTypeLinearLayout = postTypeDialogView.findViewById(R.id.link_type_linear_layout_post_type_bottom_sheet);
LinearLayout imageTypeLinearLayout = postTypeDialogView.findViewById(R.id.image_type_linear_layout_post_type_bottom_sheet);
LinearLayout videoTypeLinearLayout = postTypeDialogView.findViewById(R.id.video_type_linear_layout_post_type_bottom_sheet);
postTypedialog = new BottomSheetDialog(this);
postTypedialog.setContentView(postTypeDialogView);
sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
@ -120,11 +122,7 @@ public class MainActivity extends AppCompatActivity {
startActivityForResult(loginIntent, LOGIN_ACTIVITY_REQUEST_CODE);
} else {
if (savedInstanceState == null) {
mFragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE);
mFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_content_main, mFragment).commit();
replaceFragment(PostDataSource.SORT_TYPE_BEST);
} else {
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_content_main, mFragment).commit();
@ -186,30 +184,37 @@ public class MainActivity extends AppCompatActivity {
textTypeLinearLayout.setOnClickListener(view -> {
Intent intent = new Intent(MainActivity.this, PostTextActivity.class);
startActivity(intent);
dialog.dismiss();
postTypedialog.dismiss();
});
linkTypeLinearLayout.setOnClickListener(view -> {
Intent intent = new Intent(MainActivity.this, PostLinkActivity.class);
startActivity(intent);
dialog.dismiss();
postTypedialog.dismiss();
});
imageTypeLinearLayout.setOnClickListener(view -> {
Intent intent = new Intent(MainActivity.this, PostImageActivity.class);
startActivity(intent);
dialog.dismiss();
postTypedialog.dismiss();
});
videoTypeLinearLayout.setOnClickListener(view -> {
Intent intent = new Intent(MainActivity.this, PostVideoActivity.class);
startActivity(intent);
dialog.dismiss();
postTypedialog.dismiss();
});
fab.setOnClickListener(view -> {
dialog.show();
});
fab.setOnClickListener(view -> postTypedialog.show());
}
private void replaceFragment(String sortType) {
mFragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE);
bundle.putString(PostFragment.EXTRA_SORT_TYPE, sortType);
mFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_content_main, mFragment).commit();
}
private void loadUserData() {
@ -301,6 +306,9 @@ public class MainActivity extends AppCompatActivity {
public boolean onOptionsItemSelected(MenuItem item) {
if (mFragment instanceof FragmentCommunicator) {
switch (item.getItemId()) {
case R.id.action_sort_main_activity:
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag());
return true;
case R.id.action_search_main_activity:
Intent intent = new Intent(this, SearchActivity.class);
startActivity(intent);
@ -351,4 +359,9 @@ public class MainActivity extends AppCompatActivity {
outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess);
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
}
@Override
public void sortTypeSelected(String sortType) {
replaceFragment(sortType);
}
}

View File

@ -1,6 +1,7 @@
package ml.docilealligator.infinityforreddit;
import android.os.AsyncTask;
import android.text.Html;
import android.util.Log;
import androidx.annotation.Nullable;
@ -223,7 +224,7 @@ class ParseComment {
if(!singleCommentData.isNull(JSONUtils.BODY_HTML_KEY)) {
commentContent = singleCommentData.getString(JSONUtils.BODY_HTML_KEY).trim();
}
String permalink = singleCommentData.getString(JSONUtils.PERMALINK_KEY);
String permalink = Html.fromHtml(singleCommentData.getString(JSONUtils.PERMALINK_KEY)).toString();
int score = singleCommentData.getInt(JSONUtils.SCORE_KEY);
long submitTime = singleCommentData.getLong(JSONUtils.CREATED_UTC_KEY) * 1000;
boolean scoreHidden = singleCommentData.getBoolean(JSONUtils.SCORE_HIDDEN_KEY);

View File

@ -1,6 +1,7 @@
package ml.docilealligator.infinityforreddit;
import android.os.AsyncTask;
import android.text.Html;
import android.util.Log;
import org.json.JSONArray;
@ -122,7 +123,7 @@ class ParsePost {
parsePostListener.onParsePostSuccess(post);
}
} else {
if(newPosts != null) {
if(parsePostsListingListener != null) {
parsePostsListingListener.onParsePostsListingFail();
} else {
parsePostListener.onParsePostFail();
@ -160,7 +161,7 @@ class ParsePost {
postTimeCalendar.setTimeInMillis(postTime);
String formattedPostTime = new SimpleDateFormat("MMM d, YYYY, HH:mm",
locale).format(postTimeCalendar.getTime());
String permalink = data.getString(JSONUtils.PERMALINK_KEY);
String permalink = Html.fromHtml(data.getString(JSONUtils.PERMALINK_KEY)).toString();
String previewUrl = "";
int previewWidth = -1;
@ -194,7 +195,7 @@ class ParsePost {
Post post;
boolean isVideo = data.getBoolean(JSONUtils.IS_VIDEO_KEY);
String url = data.getString(JSONUtils.URL_KEY);
String url = Html.fromHtml(data.getString(JSONUtils.URL_KEY)).toString();
if(!data.has(JSONUtils.PREVIEW_KEY) && previewUrl.equals("")) {
if(url.contains(permalink)) {
@ -224,8 +225,8 @@ class ParsePost {
}
} else {
if(previewUrl.equals("")) {
previewUrl = data.getJSONObject(JSONUtils.PREVIEW_KEY).getJSONArray(JSONUtils.IMAGES_KEY).getJSONObject(0)
.getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
previewUrl = Html.fromHtml(data.getJSONObject(JSONUtils.PREVIEW_KEY).getJSONArray(JSONUtils.IMAGES_KEY).getJSONObject(0)
.getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY)).toString();
}
if(isVideo) {
@ -233,7 +234,7 @@ class ParsePost {
Log.i("video", Integer.toString(i));
JSONObject redditVideoObject = data.getJSONObject(JSONUtils.MEDIA_KEY).getJSONObject(JSONUtils.REDDIT_VIDEO_KEY);
int postType = Post.VIDEO_TYPE;
String videoUrl = redditVideoObject.getString(JSONUtils.DASH_URL_KEY);
String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.DASH_URL_KEY)).toString();
post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime,
title, previewUrl, permalink, score, postType, voteType,
@ -249,8 +250,8 @@ class ParsePost {
//Gif video post (MP4)
Log.i("gif video mp4", Integer.toString(i));
int postType = Post.GIF_VIDEO_TYPE;
String videoUrl = variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.MP4_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
String gifDownloadUrl = variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.GIF_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
String videoUrl = Html.fromHtml(variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.MP4_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY)).toString();
String gifDownloadUrl = Html.fromHtml(variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.GIF_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY)).toString();
post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title,
previewUrl, permalink, score, postType, voteType,
@ -264,8 +265,8 @@ class ParsePost {
//Gif video post (Dash)
Log.i("gif video dash", Integer.toString(i));
int postType = Post.GIF_VIDEO_TYPE;
String videoUrl = data.getJSONObject(JSONUtils.PREVIEW_KEY)
.getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.DASH_URL_KEY);
String videoUrl = Html.fromHtml(data.getJSONObject(JSONUtils.PREVIEW_KEY)
.getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.DASH_URL_KEY)).toString();
post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title,
previewUrl, permalink, score, postType, voteType,

View File

@ -24,12 +24,21 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
static final int TYPE_USER = 2;
static final int TYPE_SEARCH = 3;
static final String SORT_TYPE_BEST = "best";
static final String SORT_TYPE_HOT = "hot";
static final String SORT_TYPE_NEW = "new";
static final String SORT_TYPE_RANDOM = "random";
static final String SORT_TYPE_RISING = "rising";
static final String SORT_TYPE_TOP = "top";
static final String SORT_TYPE_CONTROVERSIAL = "controversial";
private Retrofit retrofit;
private String accessToken;
private Locale locale;
private String subredditName;
private String query;
private int postType;
private String sortType;
private OnPostFetchedCallback onPostFetchedCallback;
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
@ -40,17 +49,33 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
private LoadParams<String> params;
private LoadCallback<String, Post> callback;
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, int postType, OnPostFetchedCallback onPostFetchedCallback) {
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
OnPostFetchedCallback onPostFetchedCallback) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
paginationNetworkStateLiveData = new MutableLiveData();
initialLoadStateLiveData = new MutableLiveData();
this.postType = postType;
this.sortType = sortType;
this.onPostFetchedCallback = onPostFetchedCallback;
}
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType, OnPostFetchedCallback onPostFetchedCallback) {
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
String sortType, OnPostFetchedCallback onPostFetchedCallback) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
this.subredditName = subredditName;
paginationNetworkStateLiveData = new MutableLiveData();
initialLoadStateLiveData = new MutableLiveData();
this.postType = postType;
this.sortType = sortType;
this.onPostFetchedCallback = onPostFetchedCallback;
}
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
OnPostFetchedCallback onPostFetchedCallback) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
@ -62,7 +87,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
}
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditName, String query,
int postType, OnPostFetchedCallback onPostFetchedCallback) {
int postType, String sortType, OnPostFetchedCallback onPostFetchedCallback) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
@ -71,6 +96,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
paginationNetworkStateLiveData = new MutableLiveData();
initialLoadStateLiveData = new MutableLiveData();
this.postType = postType;
this.sortType = sortType;
this.onPostFetchedCallback = onPostFetchedCallback;
}
@ -140,35 +166,54 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
private void loadBestPostsInitial(@NonNull final LoadInitialCallback<String, Post> callback) {
RedditAPI api = retrofit.create(RedditAPI.class);
Call<String> bestPost = api.getBestPosts(null, RedditUtils.getOAuthHeader(accessToken));
Call<String> bestPost = api.getBestPosts(sortType, null, RedditUtils.getOAuthHeader(accessToken));
bestPost.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
ParsePost.parsePosts(response.body(), locale, -1,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
if(newPosts.size() == 0) {
onPostFetchedCallback.noPost();
} else {
onPostFetchedCallback.hasPost();
if(sortType.equals(SORT_TYPE_RANDOM)) {
ParsePost.parsePost(response.body(), locale, new ParsePost.ParsePostListener() {
@Override
public void onParsePostSuccess(Post post) {
ArrayList<Post> singlePostList = new ArrayList<>();
singlePostList.add(post);
onPostFetchedCallback.hasPost();
callback.onResult(singlePostList, null, null);
initialLoadStateLiveData.postValue(NetworkState.LOADED);
}
@Override
public void onParsePostFail() {
Log.i("Post fetch error", "Error parsing data");
initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing data"));
}
});
} else {
ParsePost.parsePosts(response.body(), locale, -1,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
if(newPosts.size() == 0) {
onPostFetchedCallback.noPost();
} else {
onPostFetchedCallback.hasPost();
}
if(lastItem == null || lastItem.equals("") || lastItem.equals("null")) {
callback.onResult(newPosts, null, null);
} else {
callback.onResult(newPosts, null, lastItem);
}
initialLoadStateLiveData.postValue(NetworkState.LOADED);
}
if(lastItem == null || lastItem.equals("") || lastItem.equals("null")) {
callback.onResult(newPosts, null, null);
} else {
callback.onResult(newPosts, null, lastItem);
@Override
public void onParsePostsListingFail() {
Log.i("Post fetch error", "Error parsing data");
initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing data"));
}
initialLoadStateLiveData.postValue(NetworkState.LOADED);
}
@Override
public void onParsePostsListingFail() {
Log.i("Post fetch error", "Error parsing data");
initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing data"));
}
});
});
}
} else {
Log.i("Post fetch error", response.message());
initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, response.message()));
@ -185,7 +230,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
private void loadBestPostsAfter(@NonNull LoadParams<String> params, @NonNull final LoadCallback<String, Post> callback) {
RedditAPI api = retrofit.create(RedditAPI.class);
Call<String> bestPost = api.getBestPosts(params.key, RedditUtils.getOAuthHeader(accessToken));
Call<String> bestPost = api.getBestPosts(sortType, params.key, RedditUtils.getOAuthHeader(accessToken));
bestPost.enqueue(new Callback<String>() {
@Override
@ -224,35 +269,54 @@ 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(subredditName, null, RedditUtils.getOAuthHeader(accessToken));
Call<String> getPost = api.getSubredditBestPosts(subredditName, sortType, null, RedditUtils.getOAuthHeader(accessToken));
getPost.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if(response.isSuccessful()) {
ParsePost.parsePosts(response.body(), locale, -1,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
if(newPosts.size() == 0) {
onPostFetchedCallback.noPost();
} else {
onPostFetchedCallback.hasPost();
if(sortType.equals(SORT_TYPE_RANDOM)) {
ParsePost.parsePost(response.body(), locale, new ParsePost.ParsePostListener() {
@Override
public void onParsePostSuccess(Post post) {
ArrayList<Post> singlePostList = new ArrayList<>();
singlePostList.add(post);
onPostFetchedCallback.hasPost();
callback.onResult(singlePostList, null, null);
initialLoadStateLiveData.postValue(NetworkState.LOADED);
}
@Override
public void onParsePostFail() {
Log.i("Post fetch error", "Error parsing data");
initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing data"));
}
});
} else {
ParsePost.parsePosts(response.body(), locale, -1,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
if(newPosts.size() == 0) {
onPostFetchedCallback.noPost();
} else {
onPostFetchedCallback.hasPost();
}
if(lastItem == null || lastItem.equals("") || lastItem.equals("null")) {
callback.onResult(newPosts, null, null);
} else {
callback.onResult(newPosts, null, lastItem);
}
initialLoadStateLiveData.postValue(NetworkState.LOADED);
}
if(lastItem == null || lastItem.equals("") || lastItem.equals("null")) {
callback.onResult(newPosts, null, null);
} else {
callback.onResult(newPosts, null, lastItem);
@Override
public void onParsePostsListingFail() {
Log.i("Post fetch error", "Error parsing data");
initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing data"));
}
initialLoadStateLiveData.postValue(NetworkState.LOADED);
}
@Override
public void onParsePostsListingFail() {
Log.i("Post fetch error", "Error parsing data");
initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing data"));
}
});
});
}
} else {
Log.i("Post fetch error", response.message());
initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, response.message()));
@ -269,7 +333,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(subredditName, params.key, RedditUtils.getOAuthHeader(accessToken));
Call<String> getPost = api.getSubredditBestPosts(subredditName, sortType, params.key, RedditUtils.getOAuthHeader(accessToken));
getPost.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {

View File

@ -14,18 +14,32 @@ class PostDataSourceFactory extends DataSource.Factory {
private String subredditName;
private String query;
private int postType;
private String sortType;
private PostDataSource.OnPostFetchedCallback onPostFetchedCallback;
private PostDataSource postDataSource;
private MutableLiveData<PostDataSource> postDataSourceLiveData;
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, int postType,
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
postDataSourceLiveData = new MutableLiveData<>();
this.postType = postType;
this.sortType = sortType;
this.onPostFetchedCallback = onPostFetchedCallback;
}
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
int postType, String sortType, PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
this.subredditName = subredditName;
postDataSourceLiveData = new MutableLiveData<>();
this.postType = postType;
this.sortType = sortType;
this.onPostFetchedCallback = onPostFetchedCallback;
}
@ -41,7 +55,7 @@ class PostDataSourceFactory extends DataSource.Factory {
}
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
String query, int postType, PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
String query, int postType, String sortType, PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
@ -49,15 +63,18 @@ class PostDataSourceFactory extends DataSource.Factory {
this.query = query;
postDataSourceLiveData = new MutableLiveData<>();
this.postType = postType;
this.sortType = sortType;
this.onPostFetchedCallback = onPostFetchedCallback;
}
@Override
public DataSource create() {
if(postType == PostDataSource.TYPE_FRONT_PAGE) {
postDataSource = new PostDataSource(retrofit, accessToken, locale, postType, onPostFetchedCallback);
postDataSource = new PostDataSource(retrofit, accessToken, locale, postType, sortType, onPostFetchedCallback);
} else if(postType == PostDataSource.TYPE_SEARCH) {
postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, query, postType, onPostFetchedCallback);
postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, query, postType, sortType, onPostFetchedCallback);
} else if(postType == PostDataSource.TYPE_SUBREDDIT) {
postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, postType, sortType, onPostFetchedCallback);
} else {
postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, postType, onPostFetchedCallback);
}

View File

@ -48,6 +48,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
static final String EXTRA_SUBREDDIT_NAME = "EN";
static final String EXTRA_QUERY = "EQ";
static final String EXTRA_POST_TYPE = "EPT";
static final String EXTRA_SORT_TYPE = "EST";
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
@ -166,6 +167,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
});
int postType = getArguments().getInt(EXTRA_POST_TYPE);
String sortType = getArguments().getString(EXTRA_SORT_TYPE);
String accessToken = activity.getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE)
.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
@ -178,9 +180,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mRetrofit,
mSharedPreferences, postType, () -> mPostViewModel.retryLoadingMore());
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
getResources().getConfiguration().locale, subredditName, query, postType, new PostDataSource.OnPostFetchedCallback() {
getResources().getConfiguration().locale, subredditName, query, postType, sortType, new PostDataSource.OnPostFetchedCallback() {
@Override
public void hasPost() {
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
@ -194,12 +195,31 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
showErrorView(R.string.no_posts);
}
});
} else if(postType != PostDataSource.TYPE_FRONT_PAGE) {
if(postType == PostDataSource.TYPE_USER) {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mFetchPostInfoLinearLayout.getLayoutParams();
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
mFetchPostInfoLinearLayout.setLayoutParams(params);
}
} else if(postType == PostDataSource.TYPE_SUBREDDIT) {
String subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME);
mAdapter = new PostRecyclerViewAdapter(activity, mRetrofit,
mSharedPreferences, postType, () -> mPostViewModel.retryLoadingMore());
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
getResources().getConfiguration().locale, subredditName, postType, sortType, 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_USER) {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mFetchPostInfoLinearLayout.getLayoutParams();
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
mFetchPostInfoLinearLayout.setLayoutParams(params);
String subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME);
@ -207,7 +227,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mSharedPreferences, postType, () -> mPostViewModel.retryLoadingMore());
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
getResources().getConfiguration().locale, subredditName, postType, new PostDataSource.OnPostFetchedCallback() {
getResources().getConfiguration().locale, subredditName, postType, sortType,
new PostDataSource.OnPostFetchedCallback() {
@Override
public void hasPost() {
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
@ -226,7 +247,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mSharedPreferences, postType, () -> mPostViewModel.retryLoadingMore());
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
getResources().getConfiguration().locale, postType, new PostDataSource.OnPostFetchedCallback() {
getResources().getConfiguration().locale, postType, sortType, new PostDataSource.OnPostFetchedCallback() {
@Override
public void hasPost() {
mFetchPostInfoLinearLayout.setVisibility(View.GONE);

View File

@ -260,6 +260,7 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
imageUri = null;
selectAgainTextView.setVisibility(View.GONE);
mGlide.clear(imageView);
imageView.setVisibility(View.GONE);
constraintLayout.setVisibility(View.VISIBLE);
});
}

View File

@ -13,9 +13,9 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -77,7 +77,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
@BindView(R.id.capture_fab_post_video_activity) FloatingActionButton captureFab;
@BindView(R.id.select_from_library_fab_post_video_activity) FloatingActionButton selectFromLibraryFab;
@BindView(R.id.select_again_text_view_post_video_activity) TextView selectAgainTextView;
@BindView(R.id.image_view_post_video_activity) ImageView imageView;
@BindView(R.id.video_view_post_video_activity) VideoView videoView;
private String iconUrl;
private String subredditName;
@ -248,19 +248,26 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
startActivityForResult(Intent.createChooser(intent,getResources().getString(R.string.select_from_gallery)), PICK_VIDEO_REQUEST_CODE);
});
videoView.setOnPreparedListener(mediaPlayer -> {
mediaPlayer.setLooping(true);
mediaPlayer.setVolume(0, 0);
});
selectAgainTextView.setOnClickListener(view -> {
videoUri = null;
selectAgainTextView.setVisibility(View.GONE);
mGlide.clear(imageView);
videoView.stopPlayback();
videoView.setVisibility(View.GONE);
constraintLayout.setVisibility(View.VISIBLE);
});
}
private void loadImage() {
constraintLayout.setVisibility(View.GONE);
imageView.setVisibility(View.VISIBLE);
videoView.setVisibility(View.VISIBLE);
selectAgainTextView.setVisibility(View.VISIBLE);
mGlide.asBitmap().load(videoUri).into(imageView);
videoView.setVideoURI(videoUri);
videoView.start();
}
private void displaySubredditIcon() {
@ -376,6 +383,12 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
return false;
}
@Override
protected void onStop() {
super.onStop();
videoView.stopPlayback();
}
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);

View File

@ -19,9 +19,9 @@ public class PostViewModel extends ViewModel {
private LiveData<NetworkState> initialLoadingState;
private LiveData<PagedList<Post>> posts;
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, int postType,
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, postType, onPostFetchedCallback);
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, postType, sortType, onPostFetchedCallback);
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
(Function<PostDataSource, LiveData<NetworkState>>) PostDataSource::getInitialLoadStateLiveData);
@ -36,6 +36,24 @@ public class PostViewModel extends ViewModel {
posts = (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
}
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
String sortType, PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName, postType, sortType, 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();
}
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName, postType, onPostFetchedCallback);
@ -55,9 +73,9 @@ public class PostViewModel extends ViewModel {
}
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, String query,
int postType, PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
int postType, String sortType, PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName,
query, postType, onPostFetchedCallback);
query, postType, sortType, onPostFetchedCallback);
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
dataSource -> dataSource.getInitialLoadStateLiveData());
@ -104,14 +122,27 @@ public class PostViewModel extends ViewModel {
private String subredditName;
private String query;
private int postType;
private String sortType;
private PostDataSource.OnPostFetchedCallback onPostFetchedCallback;
public Factory(Retrofit retrofit, String accessToken, Locale locale, int postType,
public Factory(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
this.postType = postType;
this.sortType = sortType;
this.onPostFetchedCallback = onPostFetchedCallback;
}
public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
String sortType, PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
this.subredditName = subredditName;
this.postType = postType;
this.sortType = sortType;
this.onPostFetchedCallback = onPostFetchedCallback;
}
@ -126,13 +157,14 @@ public class PostViewModel extends ViewModel {
}
public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, String query,
int postType, PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
int postType, String sortType, PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
this.subredditName = subredditName;
this.query = query;
this.postType = postType;
this.sortType = sortType;
this.onPostFetchedCallback = onPostFetchedCallback;
}
@ -140,9 +172,11 @@ public class PostViewModel extends ViewModel {
@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);
return (T) new PostViewModel(retrofit, accessToken, locale, postType, sortType, onPostFetchedCallback);
} else if(postType == PostDataSource.TYPE_SEARCH){
return (T) new PostViewModel(retrofit, accessToken, locale, subredditName, query, postType, onPostFetchedCallback);
return (T) new PostViewModel(retrofit, accessToken, locale, subredditName, query, postType, sortType, onPostFetchedCallback);
} else if(postType == PostDataSource.TYPE_SUBREDDIT) {
return (T) new PostViewModel(retrofit, accessToken, locale, subredditName, postType, sortType, onPostFetchedCallback);
} else {
return (T) new PostViewModel(retrofit, accessToken, locale, subredditName, postType, onPostFetchedCallback);
}

View File

@ -41,12 +41,12 @@ public interface RedditAPI {
@GET("comments/{id}.json?raw_json=1")
Call<String> getPost(@Path("id") String id, @HeaderMap Map<String, String> headers);
@GET("best?raw_json=1")
Call<String> getBestPosts(@Query("after") String lastItem, @HeaderMap Map<String, String> headers);
@GET("{sortType}?raw_json=1")
Call<String> getBestPosts(@Path("sortType") String sortType, @Query("after") String lastItem, @HeaderMap Map<String, String> headers);
@GET("r/{subredditName}.json?raw_json=1&limit=25")
Call<String> getSubredditBestPosts(@Path("subredditName") String subredditName, @Query("after") String lastItem,
@HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25")
Call<String> getSubredditBestPosts(@Path("subredditName") String subredditName, @Path("sortType") String sortType,
@Query("after") String lastItem, @HeaderMap Map<String, String> headers);
@GET("user/{username}/submitted.json?raw_json=1&limit=25")
Call<String> getUserBestPosts(@Path("username") String username, @Query("after") String lastItem,

View File

@ -102,6 +102,7 @@ public class SearchResultActivity extends AppCompatActivity {
PostFragment mFragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SEARCH);
bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_BEST);
bundle.putString(PostFragment.EXTRA_SUBREDDIT_NAME, mSubredditName);
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
mFragment.setArguments(bundle);

View File

@ -0,0 +1,88 @@
package ml.docilealligator.infinityforreddit;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* A simple {@link Fragment} subclass.
*/
public class SortTypeBottomSheetFragment extends BottomSheetDialogFragment {
interface SortTypeSelectionCallback {
void sortTypeSelected(String sortType);
}
@BindView(R.id.best_type_text_view_sort_type_bottom_sheet_fragment) TextView bestTypeTextView;
@BindView(R.id.hot_type_text_view_sort_type_bottom_sheet_fragment) TextView hotTypeTextView;
@BindView(R.id.new_type_text_view_sort_type_bottom_sheet_fragment) TextView newTypeTextView;
@BindView(R.id.random_type_text_view_sort_type_bottom_sheet_fragment) TextView randomTypeTextView;
@BindView(R.id.rising_type_text_view_sort_type_bottom_sheet_fragment) TextView risingTypeTextView;
@BindView(R.id.top_type_text_view_sort_type_bottom_sheet_fragment) TextView topTypeTextView;
@BindView(R.id.controversial_type_text_view_sort_type_bottom_sheet_fragment) TextView controversialTypeTextView;
public SortTypeBottomSheetFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_sort_type_bottom_sheet, container, false);
ButterKnife.bind(this, rootView);
Activity activity = getActivity();
bestTypeTextView.setOnClickListener(view -> {
((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_BEST);
dismiss();
});
hotTypeTextView.setOnClickListener(view -> {
((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_HOT);
dismiss();
});
newTypeTextView.setOnClickListener(view -> {
((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_NEW);
dismiss();
});
randomTypeTextView.setOnClickListener(view -> {
((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_RANDOM);
dismiss();
});
risingTypeTextView.setOnClickListener(view -> {
((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_RISING);
dismiss();
});
topTypeTextView.setOnClickListener(view -> {
((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_TOP);
dismiss();
});
controversialTypeTextView.setOnClickListener(view -> {
((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_BEST);
dismiss();
});
return rootView;
}
}

View File

@ -43,7 +43,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
public class ViewSubredditDetailActivity extends AppCompatActivity {
public class ViewSubredditDetailActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback {
public static final String EXTRA_SUBREDDIT_NAME_KEY = "ESN";
@ -72,6 +72,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
private Menu mMenu;
private AppBarLayout.LayoutParams params;
private BottomSheetDialog dialog;
private SortTypeBottomSheetFragment sortTypeBottomSheetFragment;
private SubscribedSubredditDao subscribedSubredditDao;
private SubredditViewModel mSubredditViewModel;
@ -95,6 +96,8 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
ButterKnife.bind(this);
((Infinity) getApplication()).getmAppComponent().inject(this);
View dialogView = View.inflate(this, R.layout.post_type_bottom_sheet, null);
LinearLayout textTypeLinearLayout = dialogView.findViewById(R.id.text_type_linear_layout_post_type_bottom_sheet);
LinearLayout linkTypeLinearLayout = dialogView.findViewById(R.id.link_type_linear_layout_post_type_bottom_sheet);
@ -104,7 +107,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
dialog = new BottomSheetDialog(this);
dialog.setContentView(dialogView);
((Infinity) getApplication()).getmAppComponent().inject(this);
sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
@ -259,12 +262,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
});
if(savedInstanceState == null) {
mFragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putString(PostFragment.EXTRA_SUBREDDIT_NAME, subredditName);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
mFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit();
replaceFragment(PostDataSource.SORT_TYPE_BEST);
} else {
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY);
if(mFragment == null) {
@ -272,6 +270,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
Bundle bundle = new Bundle();
bundle.putString(PostFragment.EXTRA_SUBREDDIT_NAME, subredditName);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_BEST);
mFragment.setArguments(bundle);
}
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
@ -335,6 +334,9 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
case android.R.id.home:
finish();
return true;
case R.id.action_sort_view_subreddit_detail_activity:
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag());
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);
@ -367,6 +369,16 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
return false;
}
private void replaceFragment(String sortType) {
mFragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putString(PostFragment.EXTRA_SUBREDDIT_NAME, subredditName);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
bundle.putString(PostFragment.EXTRA_SORT_TYPE, sortType);
mFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit();
}
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
@ -378,6 +390,11 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
Snackbar.make(coordinatorLayout, resId, Snackbar.LENGTH_SHORT).show();
}
@Override
public void sortTypeSelected(String sortType) {
replaceFragment(sortType);
}
private static class InsertSubredditDataAsyncTask extends AsyncTask<Void, Void, Void> {
private SubredditDao mSubredditDao;

View 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:fillColor="#FFFFFF"
android:pathData="M3,18h6v-2L3,16v2zM3,6v2h18L21,6L3,6zM3,13h12v-2L3,11v2z"/>
</vector>

View File

@ -166,13 +166,11 @@
android:textColor="@color/colorAccent"
android:visibility="gone" />
<ImageView
android:id="@+id/image_view_post_video_activity"
<VideoView
android:id="@+id/video_view_post_video_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:visibility="gone" />
android:visibility="gone"/>
</LinearLayout>

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/sort"
android:textSize="18sp" />
<TextView
android:id="@+id/best_type_text_view_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_best"
android:textColor="@color/primaryTextColor"
android:textSize="18sp"
android:padding="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/hot_type_text_view_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_hot"
android:textColor="@color/primaryTextColor"
android:textSize="18sp"
android:padding="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/new_type_text_view_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_new"
android:textColor="@color/primaryTextColor"
android:textSize="18sp"
android:padding="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/random_type_text_view_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_random"
android:textColor="@color/primaryTextColor"
android:textSize="18sp"
android:padding="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/rising_type_text_view_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_rising"
android:textColor="@color/primaryTextColor"
android:textSize="18sp"
android:padding="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/top_type_text_view_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_top"
android:textColor="@color/primaryTextColor"
android:textSize="18sp"
android:padding="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/controversial_type_text_view_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_rising"
android:textColor="@color/primaryTextColor"
android:textSize="18sp"
android:padding="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
</LinearLayout>

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/sort"
android:textSize="18sp" />
<TextView
android:id="@+id/best_type_text_view_sort_type_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_best"
android:textColor="@color/primaryTextColor"
android:textSize="18sp"
android:padding="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/hot_type_text_view_sort_type_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_hot"
android:textColor="@color/primaryTextColor"
android:textSize="18sp"
android:padding="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/new_type_text_view_sort_type_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_new"
android:textColor="@color/primaryTextColor"
android:textSize="18sp"
android:padding="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/random_type_text_view_sort_type_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_random"
android:textColor="@color/primaryTextColor"
android:textSize="18sp"
android:padding="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/rising_type_text_view_sort_type_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_rising"
android:textColor="@color/primaryTextColor"
android:textSize="18sp"
android:padding="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/top_type_text_view_sort_type_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_top"
android:textColor="@color/primaryTextColor"
android:textSize="18sp"
android:padding="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/controversial_type_text_view_sort_type_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_rising"
android:textColor="@color/primaryTextColor"
android:textSize="18sp"
android:padding="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
</LinearLayout>

View File

@ -4,21 +4,28 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context="ml.docilealligator.infinityforreddit.MainActivity">
<item
android:id="@+id/action_search_main_activity"
android:id="@+id/action_sort_main_activity"
android:orderInCategory="1"
android:title="@string/action_search"
android:icon="@drawable/ic_outline_sort_24px"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_search_main_activity"
android:orderInCategory="2"
android:title="@string/action_search"
android:icon="@drawable/ic_search_white_24dp"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_refresh_main_activity"
android:orderInCategory="2"
android:orderInCategory="3"
android:title="@string/action_refresh"
app:showAsAction="never" />
<item
android:id="@+id/action_lazy_mode_main_activity"
android:orderInCategory="3"
android:orderInCategory="4"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
</menu>

View File

@ -4,21 +4,28 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context="ml.docilealligator.infinityforreddit.ViewSubredditDetailActivity">
<item
android:id="@+id/action_search_view_subreddit_detail_activity"
android:id="@+id/action_sort_view_subreddit_detail_activity"
android:orderInCategory="1"
android:title="@string/action_search"
android:icon="@drawable/ic_outline_sort_24px"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_search_view_subreddit_detail_activity"
android:orderInCategory="2"
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:orderInCategory="3"
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="3"
android:orderInCategory="4"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
</menu>

View File

@ -133,4 +133,16 @@
<string name="all_subreddits">All subreddits</string>
<string name="error_loading_post">Error loading this post.\nTap to retry.</string>
<string name="sort">Sort</string>
<string name="sort_best">Best</string>
<string name="sort_hot">Hot</string>
<string name="sort_new">New</string>
<string name="sort_random">Random</string>
<string name="sort_rising">Rising</string>
<string name="sort_top">Top</string>
<string name="sort_controversial">Controversial</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>