Remove ParseAndSaveAccountInfo and move the code to FetchMyInfo. Move some classes to packages.

This commit is contained in:
Alex Ning 2020-07-06 12:19:21 +08:00
parent 5e02a43ba7
commit 4654090b31
51 changed files with 169 additions and 201 deletions

View File

@ -31,13 +31,12 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.API.RedditAPI;
import ml.docilealligator.infinityforreddit.AsyncTask.ParseAndInsertNewAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.FetchMyInfo;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.ParseAndSaveAccountInfo;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.API.RedditAPI;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Utils.APIUtils;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
@ -144,12 +143,10 @@ public class LoginActivity extends BaseActivity {
String accessToken = responseJSON.getString(APIUtils.ACCESS_TOKEN_KEY);
String refreshToken = responseJSON.getString(APIUtils.REFRESH_TOKEN_KEY);
FetchMyInfo.fetchAccountInfo(mOauthRetrofit, accessToken, new FetchMyInfo.FetchUserMyListener() {
FetchMyInfo.fetchAccountInfo(mOauthRetrofit, mRedditDataRoomDatabase,
accessToken, new FetchMyInfo.FetchMyInfoListener() {
@Override
public void onFetchMyInfoSuccess(String response) {
ParseAndSaveAccountInfo.parseAndSaveAccountInfo(response, mRedditDataRoomDatabase, new ParseAndSaveAccountInfo.ParseAndSaveAccountInfoListener() {
@Override
public void onParseMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma) {
public void onFetchMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma) {
new ParseAndInsertNewAccountAsyncTask(name, accessToken, refreshToken, profileImageUrl, bannerImageUrl,
karma, authCode, mRedditDataRoomDatabase.accountDao(),
() -> {
@ -160,16 +157,13 @@ public class LoginActivity extends BaseActivity {
}
@Override
public void onParseMyInfoFail() {
public void onFetchMyInfoFailed(boolean parseFailed) {
if (parseFailed) {
Toast.makeText(LoginActivity.this, R.string.parse_user_info_error, Toast.LENGTH_SHORT).show();
finish();
}
});
} else {
Toast.makeText(LoginActivity.this, R.string.cannot_fetch_user_info, Toast.LENGTH_SHORT).show();
}
@Override
public void onFetchMyInfoFail() {
Toast.makeText(LoginActivity.this, R.string.cannot_fetch_user_info, Toast.LENGTH_SHORT).show();
finish();
}
});

View File

@ -78,17 +78,16 @@ import ml.docilealligator.infinityforreddit.FetchMyInfo;
import ml.docilealligator.infinityforreddit.FetchSubscribedThing;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.ParseAndSaveAccountInfo;
import ml.docilealligator.infinityforreddit.Message.ReadMessage;
import ml.docilealligator.infinityforreddit.Post.PostDataSource;
import ml.docilealligator.infinityforreddit.PullNotificationWorker;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Message.ReadMessage;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditViewModel;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditViewModel;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
@ -673,12 +672,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private void loadUserData() {
if (!mFetchUserInfoSuccess) {
FetchMyInfo.fetchAccountInfo(mOauthRetrofit, mAccessToken, new FetchMyInfo.FetchUserMyListener() {
FetchMyInfo.fetchAccountInfo(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
new FetchMyInfo.FetchMyInfoListener() {
@Override
public void onFetchMyInfoSuccess(String response) {
ParseAndSaveAccountInfo.parseAndSaveAccountInfo(response, mRedditDataRoomDatabase, new ParseAndSaveAccountInfo.ParseAndSaveAccountInfoListener() {
@Override
public void onParseMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma) {
public void onFetchMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma) {
mAccountName = name;
mProfileImageUrl = profileImageUrl;
mBannerImageUrl = bannerImageUrl;
@ -687,14 +684,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
@Override
public void onParseMyInfoFail() {
mFetchUserInfoSuccess = false;
}
});
}
@Override
public void onFetchMyInfoFail() {
public void onFetchMyInfoFailed(boolean parseFailed) {
mFetchUserInfoSuccess = false;
}
});

View File

@ -42,7 +42,7 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditViewModel;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditViewModel;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;

View File

@ -39,8 +39,8 @@ import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListing
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;

View File

@ -52,8 +52,8 @@ import ml.docilealligator.infinityforreddit.MultiReddit.FetchMyMultiReddits;
import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;

View File

@ -73,8 +73,8 @@ import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToDetailActivit
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.Comment.FetchComment;
import ml.docilealligator.infinityforreddit.FetchRemovedComment;
import ml.docilealligator.infinityforreddit.FetchRemovedPost;
import ml.docilealligator.infinityforreddit.Comment.FetchRemovedComment;
import ml.docilealligator.infinityforreddit.Post.FetchRemovedPost;
import ml.docilealligator.infinityforreddit.Flair;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.Comment.ParseComment;

View File

@ -66,7 +66,7 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
import ml.docilealligator.infinityforreddit.Event.GoBackToMainPageEvent;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.FetchSubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.FetchSubredditData;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.Fragment.SidebarFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
@ -77,9 +77,9 @@ import ml.docilealligator.infinityforreddit.Message.ReadMessage;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel;
import ml.docilealligator.infinityforreddit.SubredditSubscription;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditViewModel;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditSubscription;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.Utils.Utils;
import pl.droidsonroids.gif.GifImageView;

View File

@ -60,7 +60,7 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.DeleteThing;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.FetchUserData;
import ml.docilealligator.infinityforreddit.User.FetchUserData;
import ml.docilealligator.infinityforreddit.Fragment.CommentsListingFragment;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostLayoutBottomSheetFragment;
@ -78,7 +78,7 @@ import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUse
import ml.docilealligator.infinityforreddit.User.UserDao;
import ml.docilealligator.infinityforreddit.User.UserData;
import ml.docilealligator.infinityforreddit.User.UserViewModel;
import ml.docilealligator.infinityforreddit.UserFollowing;
import ml.docilealligator.infinityforreddit.User.UserFollowing;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.Utils.Utils;
import pl.droidsonroids.gif.GifImageView;

View File

@ -25,7 +25,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.Account.Account;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
import pl.droidsonroids.gif.GifImageView;
public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

View File

@ -30,8 +30,8 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubredditSubscription;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditSubscription;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;

View File

@ -23,8 +23,8 @@ import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.SubredditWithSelection;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditWithSelection;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
import pl.droidsonroids.gif.GifImageView;
public class SubredditMultiselectionRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

View File

@ -27,7 +27,7 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.FavoriteThing;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;

View File

@ -33,7 +33,7 @@ import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserDao;
import ml.docilealligator.infinityforreddit.User.UserData;
import ml.docilealligator.infinityforreddit.UserFollowing;
import ml.docilealligator.infinityforreddit.User.UserFollowing;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;

View File

@ -3,7 +3,7 @@ package ml.docilealligator.infinityforreddit.AsyncTask;
import android.os.AsyncTask;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
public class CheckIsSubscribedToSubredditAsyncTask extends AsyncTask<Void, Void, Void> {

View File

@ -3,8 +3,8 @@ package ml.docilealligator.infinityforreddit.AsyncTask;
import android.os.AsyncTask;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditDao;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditDao;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
public class InsertSubredditDataAsyncTask extends AsyncTask<Void, Void, Void> {
private SubredditDao mSubredditDao;

View File

@ -9,10 +9,10 @@ import java.util.Collections;
import java.util.List;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditDao;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditDao;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditDao;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditDao;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserDao;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;

View File

@ -4,10 +4,10 @@ import android.os.AsyncTask;
import java.util.ArrayList;
import ml.docilealligator.infinityforreddit.FetchSubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.FetchSubredditData;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditDao;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditDao;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
import retrofit2.Retrofit;
public class LoadSubredditIconAsyncTask extends AsyncTask<Void, Void, Void> {

View File

@ -2,7 +2,7 @@ package ml.docilealligator.infinityforreddit.AsyncTask;
import android.os.AsyncTask;
import ml.docilealligator.infinityforreddit.FetchUserData;
import ml.docilealligator.infinityforreddit.User.FetchUserData;
import ml.docilealligator.infinityforreddit.User.UserDao;
import ml.docilealligator.infinityforreddit.User.UserData;
import retrofit2.Retrofit;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit;
package ml.docilealligator.infinityforreddit.Comment;
import android.os.AsyncTask;

View File

@ -7,7 +7,7 @@ import java.util.Map;
import ml.docilealligator.infinityforreddit.API.RedditAPI;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import ml.docilealligator.infinityforreddit.Utils.APIUtils;
import retrofit2.Call;

View File

@ -1,17 +1,24 @@
package ml.docilealligator.infinityforreddit;
import android.os.AsyncTask;
import android.text.Html;
import androidx.annotation.NonNull;
import org.json.JSONException;
import org.json.JSONObject;
import ml.docilealligator.infinityforreddit.API.RedditAPI;
import ml.docilealligator.infinityforreddit.Utils.APIUtils;
import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
public class FetchMyInfo {
public static void fetchAccountInfo(final Retrofit retrofit, String accessToken,
final FetchUserMyListener fetchUserMyListener) {
public static void fetchAccountInfo(final Retrofit retrofit, RedditDataRoomDatabase redditDataRoomDatabase,
String accessToken, final FetchMyInfoListener fetchMyInfoListener) {
RedditAPI api = retrofit.create(RedditAPI.class);
Call<String> userInfo = api.getMyInfo(APIUtils.getOAuthHeader(accessToken));
@ -19,22 +26,74 @@ public class FetchMyInfo {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
fetchUserMyListener.onFetchMyInfoSuccess(response.body());
new ParseAndSaveAccountInfoAsyncTask(response.body(), redditDataRoomDatabase, fetchMyInfoListener).execute();
} else {
fetchUserMyListener.onFetchMyInfoFail();
fetchMyInfoListener.onFetchMyInfoFailed(false);
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
fetchUserMyListener.onFetchMyInfoFail();
fetchMyInfoListener.onFetchMyInfoFailed(false);
}
});
}
public interface FetchUserMyListener {
void onFetchMyInfoSuccess(String response);
public interface FetchMyInfoListener {
void onFetchMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma);
void onFetchMyInfoFail();
void onFetchMyInfoFailed(boolean parseFailed);
}
private static class ParseAndSaveAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
private JSONObject jsonResponse;
private RedditDataRoomDatabase redditDataRoomDatabase;
private FetchMyInfoListener fetchMyInfoListener;
private boolean parseFailed;
private String name;
private String profileImageUrl;
private String bannerImageUrl;
private int karma;
ParseAndSaveAccountInfoAsyncTask(String response, RedditDataRoomDatabase redditDataRoomDatabase,
FetchMyInfoListener fetchMyInfoListener) {
try {
jsonResponse = new JSONObject(response);
this.redditDataRoomDatabase = redditDataRoomDatabase;
this.fetchMyInfoListener = fetchMyInfoListener;
parseFailed = false;
} catch (JSONException e) {
fetchMyInfoListener.onFetchMyInfoFailed(true);
}
}
@Override
protected Void doInBackground(Void... voids) {
try {
name = jsonResponse.getString(JSONUtils.NAME_KEY);
profileImageUrl = Html.fromHtml(jsonResponse.getString(JSONUtils.ICON_IMG_KEY)).toString();
if (!jsonResponse.isNull(JSONUtils.SUBREDDIT_KEY)) {
bannerImageUrl = Html.fromHtml(jsonResponse.getJSONObject(JSONUtils.SUBREDDIT_KEY).getString(JSONUtils.BANNER_IMG_KEY)).toString();
}
int linkKarma = jsonResponse.getInt(JSONUtils.LINK_KARMA_KEY);
int commentKarma = jsonResponse.getInt(JSONUtils.COMMENT_KARMA_KEY);
karma = linkKarma + commentKarma;
redditDataRoomDatabase.accountDao().updateAccountInfo(name, profileImageUrl, bannerImageUrl, karma);
} catch (JSONException e) {
parseFailed = true;
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
if (!parseFailed) {
fetchMyInfoListener.onFetchMyInfoSuccess(name, profileImageUrl, bannerImageUrl, karma);
} else {
fetchMyInfoListener.onFetchMyInfoFailed(true);
}
}
}
}

View File

@ -5,8 +5,8 @@ import androidx.annotation.NonNull;
import java.util.ArrayList;
import ml.docilealligator.infinityforreddit.API.RedditAPI;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import ml.docilealligator.infinityforreddit.Utils.APIUtils;
import retrofit2.Call;

View File

@ -43,12 +43,12 @@ import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubredditDataAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.FetchSubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.FetchSubredditData;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditViewModel;
import retrofit2.Retrofit;
public class SidebarFragment extends Fragment {

View File

@ -41,9 +41,8 @@ import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SubredditListingViewModel;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditListingViewModel;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.Utils.Utils;
import retrofit2.Retrofit;

View File

@ -39,7 +39,7 @@ import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditViewModel;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditViewModel;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;

View File

@ -38,9 +38,8 @@ import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.UserListingViewModel;
import ml.docilealligator.infinityforreddit.User.UserListingViewModel;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.Utils.Utils;
import retrofit2.Retrofit;

View File

@ -1,74 +0,0 @@
package ml.docilealligator.infinityforreddit;
import android.os.AsyncTask;
import android.text.Html;
import org.json.JSONException;
import org.json.JSONObject;
import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
public class ParseAndSaveAccountInfo {
public static void parseAndSaveAccountInfo(String response, RedditDataRoomDatabase redditDataRoomDatabase,
ParseAndSaveAccountInfoListener parseAndSaveAccountInfoListener) {
new ParseAndSaveAccountInfoAsyncTask(response, redditDataRoomDatabase, parseAndSaveAccountInfoListener).execute();
}
public interface ParseAndSaveAccountInfoListener {
void onParseMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma);
void onParseMyInfoFail();
}
private static class ParseAndSaveAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
private JSONObject jsonResponse;
private RedditDataRoomDatabase redditDataRoomDatabase;
private ParseAndSaveAccountInfoListener parseAndSaveAccountInfoListener;
private boolean parseFailed;
private String name;
private String profileImageUrl;
private String bannerImageUrl;
private int karma;
ParseAndSaveAccountInfoAsyncTask(String response, RedditDataRoomDatabase redditDataRoomDatabase,
ParseAndSaveAccountInfoListener parseAndSaveAccountInfoListener) {
try {
jsonResponse = new JSONObject(response);
this.redditDataRoomDatabase = redditDataRoomDatabase;
this.parseAndSaveAccountInfoListener = parseAndSaveAccountInfoListener;
parseFailed = false;
} catch (JSONException e) {
parseAndSaveAccountInfoListener.onParseMyInfoFail();
}
}
@Override
protected Void doInBackground(Void... voids) {
try {
name = jsonResponse.getString(JSONUtils.NAME_KEY);
profileImageUrl = Html.fromHtml(jsonResponse.getString(JSONUtils.ICON_IMG_KEY)).toString();
if (!jsonResponse.isNull(JSONUtils.SUBREDDIT_KEY)) {
bannerImageUrl = Html.fromHtml(jsonResponse.getJSONObject(JSONUtils.SUBREDDIT_KEY).getString(JSONUtils.BANNER_IMG_KEY)).toString();
}
int linkKarma = jsonResponse.getInt(JSONUtils.LINK_KARMA_KEY);
int commentKarma = jsonResponse.getInt(JSONUtils.COMMENT_KARMA_KEY);
karma = linkKarma + commentKarma;
redditDataRoomDatabase.accountDao().updateAccountInfo(name, profileImageUrl, bannerImageUrl, karma);
} catch (JSONException e) {
parseFailed = true;
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
if (!parseFailed) {
parseAndSaveAccountInfoListener.onParseMyInfoSuccess(name, profileImageUrl, bannerImageUrl, karma);
} else {
parseAndSaveAccountInfoListener.onParseMyInfoFail();
}
}
}
}

View File

@ -8,8 +8,8 @@ import org.json.JSONObject;
import java.util.ArrayList;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import ml.docilealligator.infinityforreddit.Utils.JSONUtils;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit;
package ml.docilealligator.infinityforreddit.Post;
import android.net.Uri;
import android.os.AsyncTask;

View File

@ -16,10 +16,10 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeDao;
import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit;
import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditDao;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditDao;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditDao;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditDao;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditDao;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserDao;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import ml.docilealligator.infinityforreddit.User.UserDao;

View File

@ -1,11 +1,10 @@
package ml.docilealligator.infinityforreddit;
package ml.docilealligator.infinityforreddit.Subreddit;
import androidx.annotation.NonNull;
import java.util.ArrayList;
import ml.docilealligator.infinityforreddit.API.RedditAPI;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit;
package ml.docilealligator.infinityforreddit.Subreddit;
import android.os.AsyncTask;
@ -8,7 +8,7 @@ import org.json.JSONObject;
import java.util.ArrayList;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
import ml.docilealligator.infinityforreddit.Utils.Utils;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit.SubredditDatabase;
package ml.docilealligator.infinityforreddit.Subreddit;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit.SubredditDatabase;
package ml.docilealligator.infinityforreddit.Subreddit;
import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit;
package ml.docilealligator.infinityforreddit.Subreddit;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
@ -6,7 +6,8 @@ import androidx.paging.PageKeyedDataSource;
import java.util.ArrayList;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.SortType;
import retrofit2.Retrofit;
public class SubredditListingDataSource extends PageKeyedDataSource<String, SubredditData> {

View File

@ -1,9 +1,10 @@
package ml.docilealligator.infinityforreddit;
package ml.docilealligator.infinityforreddit.Subreddit;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import androidx.paging.DataSource;
import ml.docilealligator.infinityforreddit.SortType;
import retrofit2.Retrofit;
public class SubredditListingDataSourceFactory extends DataSource.Factory {

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit;
package ml.docilealligator.infinityforreddit.Subreddit;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
@ -9,7 +9,8 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.SortType;
import retrofit2.Retrofit;
public class SubredditListingViewModel extends ViewModel {

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit.SubredditDatabase;
package ml.docilealligator.infinityforreddit.Subreddit;
import android.os.AsyncTask;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit;
package ml.docilealligator.infinityforreddit.Subreddit;
import android.os.AsyncTask;
@ -8,8 +8,8 @@ import java.util.HashMap;
import java.util.Map;
import ml.docilealligator.infinityforreddit.API.RedditAPI;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.Utils.APIUtils;
import retrofit2.Call;
import retrofit2.Callback;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit.SubredditDatabase;
package ml.docilealligator.infinityforreddit.Subreddit;
import android.app.Application;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit;
package ml.docilealligator.infinityforreddit.Subreddit;
import android.os.Parcel;
import android.os.Parcelable;
@ -8,8 +8,7 @@ import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
public class SubredditWithSelection implements Parcelable {
private String name;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase;
package ml.docilealligator.infinityforreddit.SubscribedSubreddit;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase;
package ml.docilealligator.infinityforreddit.SubscribedSubreddit;
import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase;
package ml.docilealligator.infinityforreddit.SubscribedSubreddit;
import android.os.AsyncTask;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase;
package ml.docilealligator.infinityforreddit.SubscribedSubreddit;
import android.app.Application;

View File

@ -1,11 +1,10 @@
package ml.docilealligator.infinityforreddit;
package ml.docilealligator.infinityforreddit.User;
import androidx.annotation.NonNull;
import java.util.ArrayList;
import ml.docilealligator.infinityforreddit.API.RedditAPI;
import ml.docilealligator.infinityforreddit.User.UserData;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit;
package ml.docilealligator.infinityforreddit.User;
import android.os.AsyncTask;
@ -8,7 +8,6 @@ import org.json.JSONObject;
import java.util.ArrayList;
import ml.docilealligator.infinityforreddit.User.UserData;
import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
public class ParseUserData {

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit;
package ml.docilealligator.infinityforreddit.User;
import android.os.AsyncTask;
@ -10,7 +10,6 @@ import java.util.Map;
import ml.docilealligator.infinityforreddit.API.RedditAPI;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserDao;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import ml.docilealligator.infinityforreddit.User.UserData;
import ml.docilealligator.infinityforreddit.Utils.APIUtils;
import retrofit2.Call;
import retrofit2.Callback;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit;
package ml.docilealligator.infinityforreddit.User;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
@ -6,7 +6,8 @@ import androidx.paging.PageKeyedDataSource;
import java.util.ArrayList;
import ml.docilealligator.infinityforreddit.User.UserData;
import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.SortType;
import retrofit2.Retrofit;
public class UserListingDataSource extends PageKeyedDataSource<String, UserData> {

View File

@ -1,9 +1,10 @@
package ml.docilealligator.infinityforreddit;
package ml.docilealligator.infinityforreddit.User;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import androidx.paging.DataSource;
import ml.docilealligator.infinityforreddit.SortType;
import retrofit2.Retrofit;
public class UserListingDataSourceFactory extends DataSource.Factory {

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit;
package ml.docilealligator.infinityforreddit.User;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
@ -9,7 +9,8 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList;
import ml.docilealligator.infinityforreddit.User.UserData;
import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.SortType;
import retrofit2.Retrofit;
public class UserListingViewModel extends ViewModel {