aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchPost.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java23
3 files changed, 25 insertions, 12 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPost.java
index b1e7816b..d169cb10 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPost.java
@@ -17,9 +17,13 @@ class FetchPost {
void fetchPostFailed();
}
- static void fetchPost(Retrofit oauthRetrofit, String id, String accessToken, Locale locale, FetchPostListener fetchPostListener) {
- RedditAPI api = oauthRetrofit.create(RedditAPI.class);
- Call<String> postCall = api.getPostOauth(id, RedditUtils.getOAuthHeader(accessToken));
+ static void fetchPost(Retrofit retrofit, String id, String accessToken, Locale locale, FetchPostListener fetchPostListener) {
+ Call<String> postCall;
+ if(accessToken == null) {
+ postCall = retrofit.create(RedditAPI.class).getPost(id);
+ } else {
+ postCall = retrofit.create(RedditAPI.class).getPostOauth(id, RedditUtils.getOAuthHeader(accessToken));
+ }
postCall.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java
index 89d848c1..0412b99e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java
@@ -127,4 +127,8 @@ public interface RedditAPI {
@Multipart
@POST(".")
Call<String> uploadMediaToAWS(@PartMap()Map<String, RequestBody> params, @Part() MultipartBody.Part file);
+
+ @FormUrlEncoded
+ @POST("/api/editusertext")
+ Call<String> editPostOrComment(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index f96301b3..4be80aa7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -1,6 +1,5 @@
package ml.docilealligator.infinityforreddit;
-import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -252,13 +251,15 @@ public class ViewPostDetailActivity extends AppCompatActivity {
private void fetchPostAndCommentsById(String subredditId) {
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
+ mProgressBar.setVisibility(View.VISIBLE);
mGlide.clear(mFetchPostInfoImageView);
- String accessToken = getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE)
- .getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
-
- RedditAPI api = mOauthRetrofit.create(RedditAPI.class);
- Call<String> postAndComments = api.getPostAndCommentsByIdOauth(subredditId, RedditUtils.getOAuthHeader(accessToken));
+ Call<String> postAndComments;
+ if(mAccessToken == null) {
+ postAndComments = mRetrofit.create(RedditAPI.class).getPostAndCommentsById(subredditId);
+ } else {
+ postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsByIdOauth(subredditId, RedditUtils.getOAuthHeader(mAccessToken));
+ }
postAndComments.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
@@ -419,9 +420,13 @@ public class ViewPostDetailActivity extends AppCompatActivity {
fetchComments();
- String accessToken = getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE)
- .getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
- FetchPost.fetchPost(mOauthRetrofit, mPost.getId(), accessToken, mLocale,
+ Retrofit retrofit;
+ if(mAccessToken == null) {
+ retrofit = mRetrofit;
+ } else {
+ retrofit = mOauthRetrofit;
+ }
+ FetchPost.fetchPost(retrofit, mPost.getId(), mAccessToken, mLocale,
new FetchPost.FetchPostListener() {
@Override
public void fetchPostSuccess(Post post) {