aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchUserData.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java35
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/LoadUserDataAsyncTask.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java22
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/VoteThing.java15
13 files changed, 103 insertions, 27 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java
index d3f4c9ed..d99fc6c6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java
@@ -201,7 +201,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
}
mLoadSubredditIconAsyncTask = new LoadSubredditIconAsyncTask(
SubredditRoomDatabase.getDatabase(mActivity).subredditDao(), mPost.getSubredditNamePrefixed().substring(2),
- iconImageUrl -> {
+ mRetrofit, iconImageUrl -> {
if(!iconImageUrl.equals("")) {
mGlide.load(iconImageUrl)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchUserData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchUserData.java
index 8eadcd89..060af638 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchUserData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchUserData.java
@@ -22,8 +22,7 @@ public class FetchUserData {
void onFetchUserListingDataFailed();
}
- public static void fetchUserData(final Retrofit retrofit, String userName,
- final FetchUserDataListener fetchUserDataListener) {
+ public static void fetchUserData(Retrofit retrofit, String userName, FetchUserDataListener fetchUserDataListener) {
RedditAPI api = retrofit.create(RedditAPI.class);
Call<String> userInfo = api.getUserData(userName);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java
index 923e657f..db44d980 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java
@@ -2,7 +2,11 @@ package ml.docilealligator.infinityforreddit;
import android.os.AsyncTask;
+import java.util.ArrayList;
+
import SubredditDatabase.SubredditDao;
+import SubredditDatabase.SubredditData;
+import retrofit2.Retrofit;
class LoadSubredditIconAsyncTask extends AsyncTask<Void, Void, Void> {
interface LoadSubredditIconAsyncTaskListener {
@@ -11,22 +15,27 @@ class LoadSubredditIconAsyncTask extends AsyncTask<Void, Void, Void> {
private SubredditDao subredditDao;
private String subredditName;
+ private Retrofit retrofit;
private String iconImageUrl;
+ private boolean hasSubredditInDb;
private LoadSubredditIconAsyncTaskListener loadSubredditIconAsyncTaskListener;
- LoadSubredditIconAsyncTask(SubredditDao subredditDao, String subredditName,
+ LoadSubredditIconAsyncTask(SubredditDao subredditDao, String subredditName, Retrofit retrofit,
LoadSubredditIconAsyncTaskListener loadSubredditIconAsyncTaskListener) {
this.subredditDao = subredditDao;
this.subredditName = subredditName;
+ this.retrofit = retrofit;
this.loadSubredditIconAsyncTaskListener = loadSubredditIconAsyncTaskListener;
}
@Override
protected Void doInBackground(Void... voids) {
- if(subredditDao.getSubredditData(subredditName) != null) {
+ SubredditData subredditData = subredditDao.getSubredditData(subredditName);
+ if(subredditData != null) {
iconImageUrl = subredditDao.getSubredditData(subredditName).getIconUrl();
+ hasSubredditInDb = true;
} else {
- iconImageUrl = "";
+ hasSubredditInDb = false;
}
return null;
}
@@ -35,7 +44,25 @@ class LoadSubredditIconAsyncTask extends AsyncTask<Void, Void, Void> {
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
if(!isCancelled()) {
- loadSubredditIconAsyncTaskListener.loadIconSuccess(iconImageUrl);
+ if(hasSubredditInDb) {
+ loadSubredditIconAsyncTaskListener.loadIconSuccess(iconImageUrl);
+ } else {
+ FetchSubredditData.fetchSubredditData(retrofit, subredditName, new FetchSubredditData.FetchSubredditDataListener() {
+ @Override
+ public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
+ ArrayList<SubredditData> singleSubredditDataList = new ArrayList<>();
+ singleSubredditDataList.add(subredditData);
+ new InsertSubscribedThingsAsyncTask(null, null, subredditDao,
+ null, null, singleSubredditDataList,
+ () -> loadSubredditIconAsyncTaskListener.loadIconSuccess(subredditData.getIconUrl())).execute();
+ }
+
+ @Override
+ public void onFetchSubredditDataFail() {
+ loadSubredditIconAsyncTaskListener.loadIconSuccess(null);
+ }
+ });
+ }
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/LoadUserDataAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/LoadUserDataAsyncTask.java
index 8cb576d2..8ef07e73 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/LoadUserDataAsyncTask.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/LoadUserDataAsyncTask.java
@@ -50,7 +50,7 @@ public class LoadUserDataAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
public void onFetchUserDataFailed() {
- loadUserDataAsyncTaskListener.loadUserDataSuccess("");
+ loadUserDataAsyncTaskListener.loadUserDataSuccess(null);
}
});
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java
index b596fc75..ff6d5a48 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java
@@ -469,7 +469,6 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
getPost.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
- Log.i("initial", call.request().url().toString());
if(response.isSuccessful()) {
ParsePost.parsePosts(response.body(), locale, -1,
new ParsePost.ParsePostsListingListener() {
@@ -518,7 +517,6 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
getPost.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
- Log.i("after", call.request().url().toString());
if(response.isSuccessful()) {
ParsePost.parsePosts(response.body(), locale, -1, new ParsePost.ParsePostsListingListener() {
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
index 6799c04e..a5cd86ff 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
@@ -178,7 +178,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME);
String query = getArguments().getString(EXTRA_QUERY);
- mAdapter = new PostRecyclerViewAdapter(activity, mRetrofit,
+ mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit,
mSharedPreferences, postType, true, () -> mPostViewModel.retryLoadingMore());
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
getResources().getConfiguration().locale, subredditName, query, postType, sortType, new PostDataSource.OnPostFetchedCallback() {
@@ -199,7 +199,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME);
boolean displaySubredditName = subredditName.equals("popular") || subredditName.equals("all");
- mAdapter = new PostRecyclerViewAdapter(activity, mRetrofit,
+ mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit,
mSharedPreferences, postType, displaySubredditName, () -> mPostViewModel.retryLoadingMore());
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
@@ -224,7 +224,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME);
- mAdapter = new PostRecyclerViewAdapter(activity, mRetrofit,
+ mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit,
mSharedPreferences, postType, true, () -> mPostViewModel.retryLoadingMore());
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
@@ -244,7 +244,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
});
} else {
- mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit,
+ mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit,
mSharedPreferences, postType, true, () -> mPostViewModel.retryLoadingMore());
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java
index bc750c2a..cd4e84dc 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java
@@ -98,6 +98,10 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
private FlairBottomSheetFragment flairSelectionBottomSheetFragment;
@Inject
+ @Named("no_oauth")
+ Retrofit mRetrofit;
+
+ @Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@@ -288,7 +292,7 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
private void loadSubredditIcon() {
new LoadSubredditIconAsyncTask(SubredditRoomDatabase.getDatabase(this).subredditDao(),
- subredditName, iconImageUrl -> {
+ subredditName, mRetrofit, iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java
index 3e68a699..af507488 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java
@@ -75,6 +75,10 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
private FlairBottomSheetFragment flairSelectionBottomSheetFragment;
@Inject
+ @Named("no_oauth")
+ Retrofit mRetrofit;
+
+ @Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@@ -215,7 +219,7 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
private void loadSubredditIcon() {
new LoadSubredditIconAsyncTask(SubredditRoomDatabase.getDatabase(this).subredditDao(),
- subredditName, iconImageUrl -> {
+ subredditName, mRetrofit, iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
index 2342fcd1..b84e8a85 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
@@ -59,6 +59,7 @@ import retrofit2.Retrofit;
class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHolder> {
private Context mContext;
private Retrofit mOauthRetrofit;
+ private Retrofit mRetrofit;
private SharedPreferences mSharedPreferences;
private RequestManager glide;
private SubredditDao subredditDao;
@@ -78,12 +79,14 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
void retryLoadingMore();
}
- PostRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, SharedPreferences sharedPreferences, int postType,
- boolean displaySubredditName, RetryLoadingMoreCallback retryLoadingMoreCallback) {
+ PostRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, Retrofit retrofit,
+ SharedPreferences sharedPreferences, int postType, boolean displaySubredditName,
+ RetryLoadingMoreCallback retryLoadingMoreCallback) {
super(DIFF_CALLBACK);
if(context != null) {
mContext = context;
mOauthRetrofit = oauthRetrofit;
+ mRetrofit = retrofit;
mSharedPreferences = sharedPreferences;
this.postType = postType;
this.displaySubredditName = displaySubredditName;
@@ -159,7 +162,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
if(displaySubredditName) {
if(author.equals(subredditNamePrefixed)) {
if(post.getAuthorIconUrl() == null) {
- new LoadUserDataAsyncTask(userDao, post.getAuthor(), mOauthRetrofit, iconImageUrl -> {
+ new LoadUserDataAsyncTask(userDao, post.getAuthor(), mRetrofit, iconImageUrl -> {
if(mContext != null && getItemCount() > 0) {
if(!iconImageUrl.equals("")) {
glide.load(iconImageUrl)
@@ -191,10 +194,12 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
}
} else {
if(post.getSubredditIconUrl() == null) {
- new LoadSubredditIconAsyncTask(subredditDao, subredditName,
+ new LoadSubredditIconAsyncTask(subredditDao, subredditName, mRetrofit,
iconImageUrl -> {
if(mContext != null && getItemCount() > 0) {
- if(!iconImageUrl.equals("")) {
+ if(iconImageUrl == null) {
+
+ } else if(!iconImageUrl.equals("")) {
glide.load(iconImageUrl)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(glide.load(R.drawable.subreddit_default_icon)
@@ -245,7 +250,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
});
} else {
if(post.getAuthorIconUrl() == null) {
- new LoadUserDataAsyncTask(userDao, post.getAuthor(), mOauthRetrofit, iconImageUrl -> {
+ new LoadUserDataAsyncTask(userDao, post.getAuthor(), mRetrofit, iconImageUrl -> {
if(mContext != null && getItemCount() > 0) {
if(!iconImageUrl.equals("")) {
glide.load(iconImageUrl)
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java
index 701c0e8d..1f4abf27 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java
@@ -75,6 +75,10 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh
private FlairBottomSheetFragment flairSelectionBottomSheetFragment;
@Inject
+ @Named("no_oauth")
+ Retrofit mRetrofit;
+
+ @Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@@ -220,7 +224,7 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh
private void loadSubredditIcon() {
new LoadSubredditIconAsyncTask(SubredditRoomDatabase.getDatabase(this).subredditDao(),
- subredditName, iconImageUrl -> {
+ subredditName, mRetrofit, iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java
index 81553663..e57a65c4 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java
@@ -95,6 +95,10 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
private FlairBottomSheetFragment flairSelectionBottomSheetFragment;
@Inject
+ @Named("no_oauth")
+ Retrofit mRetrofit;
+
+ @Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@@ -286,7 +290,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
private void loadSubredditIcon() {
new LoadSubredditIconAsyncTask(SubredditRoomDatabase.getDatabase(this).subredditDao(),
- subredditName, iconImageUrl -> {
+ subredditName, mRetrofit, iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java
index cd828c80..113b9835 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java
@@ -45,6 +45,28 @@ public class SearchActivity extends AppCompatActivity {
setSupportActionBar(toolbar);
+ simpleSearchView.setOnSearchViewListener(new SimpleSearchView.SearchViewListener() {
+ @Override
+ public void onSearchViewShown() {
+
+ }
+
+ @Override
+ public void onSearchViewClosed() {
+ finish();
+ }
+
+ @Override
+ public void onSearchViewShownAnimation() {
+
+ }
+
+ @Override
+ public void onSearchViewClosedAnimation() {
+
+ }
+ });
+
simpleSearchView.setOnQueryTextListener(new SimpleSearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/VoteThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/VoteThing.java
index 175bcf1b..c6f8bc12 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/VoteThing.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/VoteThing.java
@@ -1,9 +1,10 @@
package ml.docilealligator.infinityforreddit;
import android.content.SharedPreferences;
-import androidx.annotation.NonNull;
import android.util.Log;
+import androidx.annotation.NonNull;
+
import java.util.HashMap;
import java.util.Map;
@@ -42,7 +43,11 @@ class VoteThing {
voteThingCall.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
- voteThingListener.onVoteThingSuccess(position);
+ if(response.isSuccessful()) {
+ voteThingListener.onVoteThingSuccess(position);
+ } else {
+ voteThingListener.onVoteThingFail(position);
+ }
}
@Override
@@ -68,7 +73,11 @@ class VoteThing {
voteThingCall.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
- voteThingWithoutPositionListener.onVoteThingSuccess();
+ if(response.isSuccessful()) {
+ voteThingWithoutPositionListener.onVoteThingSuccess();
+ } else {
+ voteThingWithoutPositionListener.onVoteThingFail();
+ }
}
@Override