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(); void fetchPostFailed();
} }
static void fetchPost(Retrofit oauthRetrofit, String id, String accessToken, Locale locale, FetchPostListener fetchPostListener) { static void fetchPost(Retrofit retrofit, String id, String accessToken, Locale locale, FetchPostListener fetchPostListener) {
RedditAPI api = oauthRetrofit.create(RedditAPI.class); Call<String> postCall;
Call<String> postCall = api.getPostOauth(id, RedditUtils.getOAuthHeader(accessToken)); 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>() { postCall.enqueue(new Callback<String>() {
@Override @Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {

View File

@ -127,4 +127,8 @@ public interface RedditAPI {
@Multipart @Multipart
@POST(".") @POST(".")
Call<String> uploadMediaToAWS(@PartMap()Map<String, RequestBody> params, @Part() MultipartBody.Part file); 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; package ml.docilealligator.infinityforreddit;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
@ -252,13 +251,15 @@ public class ViewPostDetailActivity extends AppCompatActivity {
private void fetchPostAndCommentsById(String subredditId) { private void fetchPostAndCommentsById(String subredditId) {
mFetchPostInfoLinearLayout.setVisibility(View.GONE); mFetchPostInfoLinearLayout.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);
mGlide.clear(mFetchPostInfoImageView); mGlide.clear(mFetchPostInfoImageView);
String accessToken = getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE) Call<String> postAndComments;
.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, ""); if(mAccessToken == null) {
postAndComments = mRetrofit.create(RedditAPI.class).getPostAndCommentsById(subredditId);
RedditAPI api = mOauthRetrofit.create(RedditAPI.class); } else {
Call<String> postAndComments = api.getPostAndCommentsByIdOauth(subredditId, RedditUtils.getOAuthHeader(accessToken)); postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsByIdOauth(subredditId, RedditUtils.getOAuthHeader(mAccessToken));
}
postAndComments.enqueue(new Callback<String>() { postAndComments.enqueue(new Callback<String>() {
@Override @Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
@ -419,9 +420,13 @@ public class ViewPostDetailActivity extends AppCompatActivity {
fetchComments(); fetchComments();
String accessToken = getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE) Retrofit retrofit;
.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, ""); if(mAccessToken == null) {
FetchPost.fetchPost(mOauthRetrofit, mPost.getId(), accessToken, mLocale, retrofit = mRetrofit;
} else {
retrofit = mOauthRetrofit;
}
FetchPost.fetchPost(retrofit, mPost.getId(), mAccessToken, mLocale,
new FetchPost.FetchPostListener() { new FetchPost.FetchPostListener() {
@Override @Override
public void fetchPostSuccess(Post post) { public void fetchPostSuccess(Post post) {