Browse Source

proper self-profile handling when offline; close #1328

renovate/org.robolectric-robolectric-4.x
Austin Huang 4 years ago
parent
commit
f657f61aa7
No known key found for this signature in database GPG Key ID: 84C23AA04587A91F
  1. 7
      app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java
  2. 7
      app/src/main/java/awais/instagrabber/viewmodels/AppStateViewModel.java

7
app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java

@ -692,6 +692,11 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (userResource == null) return; if (userResource == null) return;
final User user = userResource.data; final User user = userResource.data;
if (user == null) return; if (user == null) return;
username = user.getUsername();
if (TextUtils.isEmpty(username)) {
appStateViewModel.fetchProfileDetails();
return;
}
profileModel = user; profileModel = user;
username = profileModel.getUsername(); username = profileModel.getUsername();
setUsernameDelayed(); setUsernameDelayed();
@ -1099,7 +1104,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
} }
private void updateAccountInfo() { private void updateAccountInfo() {
if (profileModel == null) return;
if (profileModel == null || TextUtils.isEmpty(profileModel.getUsername())) return;
accountRepository.insertOrUpdateAccount( accountRepository.insertOrUpdateAccount(
profileModel.getPk(), profileModel.getPk(),
profileModel.getUsername(), profileModel.getUsername(),

7
app/src/main/java/awais/instagrabber/viewmodels/AppStateViewModel.java

@ -51,7 +51,7 @@ public class AppStateViewModel extends AndroidViewModel {
return currentUser; return currentUser;
} }
private void fetchProfileDetails() {
public void fetchProfileDetails() {
currentUser.postValue(Resource.loading(null)); currentUser.postValue(Resource.loading(null));
final long uid = CookieUtils.getUserIdFromCookie(cookie); final long uid = CookieUtils.getUserIdFromCookie(cookie);
if (userRepository == null) { if (userRepository == null) {
@ -61,7 +61,10 @@ public class AppStateViewModel extends AndroidViewModel {
userRepository.getUserInfo(uid, CoroutineUtilsKt.getContinuation((user, throwable) -> { userRepository.getUserInfo(uid, CoroutineUtilsKt.getContinuation((user, throwable) -> {
if (throwable != null) { if (throwable != null) {
Log.e(TAG, "onFailure: ", throwable); Log.e(TAG, "onFailure: ", throwable);
currentUser.postValue(Resource.error(throwable.getMessage(), null));
final User backup = currentUser.getValue().data != null ?
currentUser.getValue().data :
new User(uid);
currentUser.postValue(Resource.error(throwable.getMessage(), backup));
return; return;
} }
currentUser.postValue(Resource.success(user)); currentUser.postValue(Resource.success(user));

Loading…
Cancel
Save