Austin Huang
4 years ago
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
3 changed files with 79 additions and 132 deletions
-
101app/src/main/java/awais/instagrabber/asyncs/ProfileFetcher.java
-
67app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java
-
19app/src/main/java/awais/instagrabber/viewmodels/AppStateViewModel.java
@ -1,101 +0,0 @@ |
|||
package awais.instagrabber.asyncs; |
|||
|
|||
import android.os.AsyncTask; |
|||
import android.util.Log; |
|||
|
|||
import androidx.annotation.Nullable; |
|||
|
|||
import awais.instagrabber.interfaces.FetchListener; |
|||
import awais.instagrabber.repositories.responses.FriendshipStatus; |
|||
import awais.instagrabber.repositories.responses.User; |
|||
import awais.instagrabber.webservices.GraphQLService; |
|||
import awais.instagrabber.webservices.ServiceCallback; |
|||
import awais.instagrabber.webservices.UserService; |
|||
|
|||
public final class ProfileFetcher extends AsyncTask<Void, Void, Void> { |
|||
private static final String TAG = ProfileFetcher.class.getSimpleName(); |
|||
private final UserService userService; |
|||
private final GraphQLService graphQLService; |
|||
|
|||
private final FetchListener<User> fetchListener; |
|||
private final long myId; |
|||
private final boolean isLoggedIn; |
|||
private final String userName; |
|||
|
|||
public ProfileFetcher(final String userName, |
|||
final long myId, |
|||
final boolean isLoggedIn, |
|||
final FetchListener<User> fetchListener) { |
|||
this.userName = userName; |
|||
this.myId = myId; |
|||
this.isLoggedIn = isLoggedIn; |
|||
this.fetchListener = fetchListener; |
|||
userService = isLoggedIn ? UserService.getInstance() : null; |
|||
graphQLService = isLoggedIn ? null : GraphQLService.getInstance(); |
|||
} |
|||
|
|||
@Nullable |
|||
@Override |
|||
protected Void doInBackground(final Void... voids) { |
|||
if (isLoggedIn && userName != null) { |
|||
userService.getUsernameInfo(userName, new ServiceCallback<User>() { |
|||
@Override |
|||
public void onSuccess(final User user) { |
|||
userService.getUserFriendship(user.getPk(), new ServiceCallback<FriendshipStatus>() { |
|||
@Override |
|||
public void onSuccess(final FriendshipStatus status) { |
|||
user.setFriendshipStatus(status); |
|||
fetchListener.onResult(user); |
|||
} |
|||
|
|||
@Override |
|||
public void onFailure(final Throwable t) { |
|||
Log.e(TAG, "Error", t); |
|||
fetchListener.onFailure(t); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
@Override |
|||
public void onFailure(final Throwable t) { |
|||
Log.e(TAG, "Error", t); |
|||
fetchListener.onFailure(t); |
|||
} |
|||
}); |
|||
} |
|||
else if (isLoggedIn) { |
|||
userService.getUserInfo(myId, new ServiceCallback<User>() { |
|||
@Override |
|||
public void onSuccess(final User user) { |
|||
fetchListener.onResult(user); |
|||
} |
|||
|
|||
@Override |
|||
public void onFailure(final Throwable t) { |
|||
Log.e(TAG, "Error", t); |
|||
fetchListener.onFailure(t); |
|||
} |
|||
}); |
|||
} |
|||
else { |
|||
graphQLService.fetchUser(userName, new ServiceCallback<User>() { |
|||
@Override |
|||
public void onSuccess(final User user) { |
|||
fetchListener.onResult(user); |
|||
} |
|||
|
|||
@Override |
|||
public void onFailure(final Throwable t) { |
|||
Log.e(TAG, "Error", t); |
|||
fetchListener.onFailure(t); |
|||
} |
|||
}); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
protected void onPreExecute() { |
|||
if (fetchListener != null) fetchListener.doBefore(); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue