Browse Source

convert switch back to if-then (auto)

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

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

@ -494,140 +494,130 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
@Override @Override
public boolean onOptionsItemSelected(@NonNull final MenuItem item) { public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
switch (item.getItemId()) { int itemId = item.getItemId();
case R.id.layout: { if (itemId == R.id.layout) {
showPostsLayoutPreferences(); showPostsLayoutPreferences();
return true; return true;
} } else if (itemId == R.id.restrict) {
case R.id.restrict: { if (!isLoggedIn) return false;
if (!isLoggedIn) return false; final String action = profileModel.getFriendshipStatus().isRestricted() ? "Unrestrict" : "Restrict";
final String action = profileModel.getFriendshipStatus().isRestricted() ? "Unrestrict" : "Restrict"; friendshipRepository.toggleRestrict(
friendshipRepository.toggleRestrict( csrfToken,
csrfToken, deviceUuid,
deviceUuid, profileModel.getPk(),
profileModel.getPk(), !profileModel.getFriendshipStatus().isRestricted(),
!profileModel.getFriendshipStatus().isRestricted(), CoroutineUtilsKt.getContinuation((response, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
CoroutineUtilsKt.getContinuation((response, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> { if (throwable != null) {
if (throwable != null) { Log.e(TAG, "Error while performing " + action, throwable);
Log.e(TAG, "Error while performing " + action, throwable); return;
return; }
} // Log.d(TAG, action + " success: " + response);
// Log.d(TAG, action + " success: " + response); fetchProfileDetails();
fetchProfileDetails(); }), Dispatchers.getIO())
}), Dispatchers.getIO()) );
); return true;
return true; } else if (itemId == R.id.block) {
} if (!isLoggedIn) return false;
case R.id.block: { // changeCb
if (!isLoggedIn) return false; friendshipRepository.changeBlock(
// changeCb csrfToken,
friendshipRepository.changeBlock( myId,
csrfToken, deviceUuid,
myId, profileModel.getFriendshipStatus().getBlocking(),
deviceUuid, profileModel.getPk(),
profileModel.getFriendshipStatus().getBlocking(), CoroutineUtilsKt.getContinuation((response, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
profileModel.getPk(), if (throwable != null) {
CoroutineUtilsKt.getContinuation((response, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> { changeCb.onFailure(throwable);
if (throwable != null) { return;
changeCb.onFailure(throwable); }
return; changeCb.onSuccess(response);
} }), Dispatchers.getIO())
changeCb.onSuccess(response); );
}), Dispatchers.getIO()) return true;
); } else if (itemId == R.id.chaining) {
return true; if (!isLoggedIn) return false;
} final Bundle bundle = new Bundle();
case R.id.chaining: { bundle.putString("type", "chaining");
if (!isLoggedIn) return false; bundle.putLong("targetId", profileModel.getPk());
final Bundle bundle = new Bundle(); NavHostFragment.findNavController(this).navigate(R.id.action_global_notificationsViewerFragment, bundle);
bundle.putString("type", "chaining"); return true;
bundle.putLong("targetId", profileModel.getPk()); } else if (itemId == R.id.mute_stories) {
NavHostFragment.findNavController(this).navigate(R.id.action_global_notificationsViewerFragment, bundle); if (!isLoggedIn) return false;
return true; final String action = profileModel.getFriendshipStatus().isMutingReel() ? "Unmute stories" : "Mute stories";
} friendshipRepository.changeMute(
case R.id.mute_stories: { csrfToken,
if (!isLoggedIn) return false; myId,
final String action = profileModel.getFriendshipStatus().isMutingReel() ? "Unmute stories" : "Mute stories"; deviceUuid,
friendshipRepository.changeMute( profileModel.getFriendshipStatus().isMutingReel(),
csrfToken, profileModel.getPk(),
myId, true,
deviceUuid, CoroutineUtilsKt.getContinuation((response, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
profileModel.getFriendshipStatus().isMutingReel(), if (throwable != null) {
profileModel.getPk(), changeCb.onFailure(throwable);
true, return;
CoroutineUtilsKt.getContinuation((response, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> { }
if (throwable != null) { changeCb.onSuccess(response);
changeCb.onFailure(throwable); }), Dispatchers.getIO())
return; );
} return true;
changeCb.onSuccess(response); } else if (itemId == R.id.mute_posts) {
}), Dispatchers.getIO()) if (!isLoggedIn) return false;
); final String action = profileModel.getFriendshipStatus().getMuting() ? "Unmute stories" : "Mute stories";
return true; friendshipRepository.changeMute(
} csrfToken,
case R.id.mute_posts: { myId,
if (!isLoggedIn) return false; deviceUuid,
final String action = profileModel.getFriendshipStatus().getMuting() ? "Unmute stories" : "Mute stories"; profileModel.getFriendshipStatus().getMuting(),
friendshipRepository.changeMute( profileModel.getPk(),
csrfToken, false,
myId, CoroutineUtilsKt.getContinuation((response, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
deviceUuid, if (throwable != null) {
profileModel.getFriendshipStatus().getMuting(), changeCb.onFailure(throwable);
profileModel.getPk(), return;
false, }
CoroutineUtilsKt.getContinuation((response, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> { changeCb.onSuccess(response);
if (throwable != null) { }), Dispatchers.getIO())
changeCb.onFailure(throwable); );
return; return true;
} } else if (itemId == R.id.remove_follower) {
changeCb.onSuccess(response); if (!isLoggedIn) return false;
}), Dispatchers.getIO()) friendshipRepository.removeFollower(
); csrfToken,
return true; myId,
} deviceUuid,
case R.id.remove_follower: { profileModel.getPk(),
if (!isLoggedIn) return false; CoroutineUtilsKt.getContinuation((response, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
friendshipRepository.removeFollower( if (throwable != null) {
csrfToken, changeCb.onFailure(throwable);
myId, return;
deviceUuid, }
profileModel.getPk(), changeCb.onSuccess(response);
CoroutineUtilsKt.getContinuation((response, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> { }), Dispatchers.getIO())
if (throwable != null) { );
changeCb.onFailure(throwable); return true;
return; } else if (itemId == R.id.share_link) {
} final Intent sharingIntent = new Intent(Intent.ACTION_SEND);
changeCb.onSuccess(response); sharingIntent.setType("text/plain");
}), Dispatchers.getIO()) sharingIntent.putExtra(Intent.EXTRA_TEXT, "https://instagram.com/" + profileModel.getUsername());
); startActivity(sharingIntent);
return true; return true;
} } else if (itemId == R.id.share_dm) {
case R.id.share_link: { final UserSearchNavGraphDirections.ActionGlobalUserSearch actionGlobalUserSearch = UserSearchFragmentDirections
final Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); .actionGlobalUserSearch()
sharingIntent.setType("text/plain"); .setTitle(getString(R.string.share))
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "https://instagram.com/" + profileModel.getUsername()); .setActionLabel(getString(R.string.send))
startActivity(sharingIntent); .setShowGroups(true)
return true; .setMultiple(true)
} .setSearchMode(UserSearchFragment.SearchMode.RAVEN);
case R.id.share_dm: { final NavController navController = NavHostFragment.findNavController(ProfileFragment.this);
final UserSearchNavGraphDirections.ActionGlobalUserSearch actionGlobalUserSearch = UserSearchFragmentDirections try {
.actionGlobalUserSearch() navController.navigate(actionGlobalUserSearch);
.setTitle(getString(R.string.share)) } catch (Exception e) {
.setActionLabel(getString(R.string.send)) Log.e(TAG, "setupShare: ", e);
.setShowGroups(true)
.setMultiple(true)
.setSearchMode(UserSearchFragment.SearchMode.RAVEN);
final NavController navController = NavHostFragment.findNavController(ProfileFragment.this);
try {
navController.navigate(actionGlobalUserSearch);
} catch (Exception e) {
Log.e(TAG, "setupShare: ", e);
}
return true;
} }
default: return true;
return super.onOptionsItemSelected(item);
} }
return super.onOptionsItemSelected(item);
} }
@Override @Override

|||||||
100:0
Loading…
Cancel
Save