aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-12 06:42:25 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-12 06:42:25 +0000
commit4df18af91447d7fcd9768f0b5a8f71974f826280 (patch)
treed38fcdc43f8b077a93c588b3e93641106ee78602 /app
parent90b01df2e969bea1fff68cebc4a1775022440181 (diff)
downloadinfinity-for-reddit-4df18af91447d7fcd9768f0b5a8f71974f826280.tar
infinity-for-reddit-4df18af91447d7fcd9768f0b5a8f71974f826280.tar.gz
infinity-for-reddit-4df18af91447d7fcd9768f0b5a8f71974f826280.tar.bz2
infinity-for-reddit-4df18af91447d7fcd9768f0b5a8f71974f826280.tar.lz
infinity-for-reddit-4df18af91447d7fcd9768f0b5a8f71974f826280.tar.xz
infinity-for-reddit-4df18af91447d7fcd9768f0b5a8f71974f826280.tar.zst
infinity-for-reddit-4df18af91447d7fcd9768f0b5a8f71974f826280.zip
Minor bugs fixed.
Diffstat (limited to 'app')
-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) {