Minor bugs fixed.

This commit is contained in:
Alex Ning 2019-08-12 14:42:25 +08:00
parent 90b01df2e9
commit 4df18af914
3 changed files with 25 additions and 12 deletions

View File

@ -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) {

View File

@ -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);
}

View File

@ -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) {