diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserController.java b/app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserController.java index 16e581041..cec4f5e2a 100644 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserController.java +++ b/app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserController.java @@ -145,13 +145,11 @@ public abstract class BrowserController extends BaseController implements Listin @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.files_selection_done: - onFileSelectionDone(); - return true; - default: - return super.onOptionsItemSelected(item); + if (item.getItemId() == R.id.files_selection_done) { + onFileSelectionDone(); + return true; } + return super.onOptionsItemSelected(item); } @Override diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java index b4a231b9f..83fc55359 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java @@ -436,20 +436,18 @@ public class ContactsController extends BaseController implements SearchView.OnQ @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - getRouter().popCurrentController(); - return true; - case R.id.contacts_selection_done: - selectionDone(); - return true; - default: - return super.onOptionsItemSelected(item); + int itemId = item.getItemId(); + if (itemId == android.R.id.home) { + return getRouter().popCurrentController(); + } else if (itemId == R.id.contacts_selection_done) { + selectionDone(); + return true; } + return super.onOptionsItemSelected(item); } @Override - public void onCreateOptionsMenu(Menu menu, @NonNull MenuInflater inflater) { + public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.menu_contacts, menu); searchItem = menu.findItem(R.id.action_search); diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ProfileController.java b/app/src/main/java/com/nextcloud/talk/controllers/ProfileController.java index 1d146450d..27c57dd93 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ProfileController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ProfileController.java @@ -157,70 +157,67 @@ public class ProfileController extends BaseController { @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.edit: - if (edit) { - save(); + if (item.getItemId() == R.id.edit) { + if (edit) { + save(); + } + + edit = !edit; + + if (edit) { + item.setTitle(R.string.save); + + getActivity().findViewById(R.id.emptyList).setVisibility(View.GONE); + getActivity().findViewById(R.id.userinfo_list).setVisibility(View.VISIBLE); + + if (CapabilitiesUtil.isAvatarEndpointAvailable(currentUser)) { + // TODO later avatar can also be checked via user fields, for now it is in Talk capability + getActivity().findViewById(R.id.avatar_buttons).setVisibility(View.VISIBLE); } - edit = !edit; + ncApi.getEditableUserProfileFields( + ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken()), + ApiUtils.getUrlForUserFields(currentUser.getBaseUrl())) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Observer() { + @Override + public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) { + // unused atm + } - if (edit) { - item.setTitle(R.string.save); + @Override + public void onNext(@io.reactivex.annotations.NonNull UserProfileFieldsOverall userProfileFieldsOverall) { + editableFields = userProfileFieldsOverall.getOcs().getData(); + adapter.notifyDataSetChanged(); + } - getActivity().findViewById(R.id.emptyList).setVisibility(View.GONE); - getActivity().findViewById(R.id.userinfo_list).setVisibility(View.VISIBLE); + @Override + public void onError(@io.reactivex.annotations.NonNull Throwable e) { + Log.e(TAG, "Error loading editable user profile from server", e); + edit = false; + } - if (CapabilitiesUtil.isAvatarEndpointAvailable(currentUser)) { - // TODO later avatar can also be checked via user fields, for now it is in Talk capability - getActivity().findViewById(R.id.avatar_buttons).setVisibility(View.VISIBLE); - } + @Override + public void onComplete() { + // unused atm + } + }); + } else { + item.setTitle(R.string.edit); + getActivity().findViewById(R.id.avatar_buttons).setVisibility(View.INVISIBLE); - ncApi.getEditableUserProfileFields( - ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken()), - ApiUtils.getUrlForUserFields(currentUser.getBaseUrl())) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) { - // unused atm - } - - @Override - public void onNext(@io.reactivex.annotations.NonNull UserProfileFieldsOverall userProfileFieldsOverall) { - editableFields = userProfileFieldsOverall.getOcs().getData(); - adapter.notifyDataSetChanged(); - } - - @Override - public void onError(@io.reactivex.annotations.NonNull Throwable e) { - Log.e(TAG, "Error loading editable user profile from server", e); - edit = false; - } - - @Override - public void onComplete() { - // unused atm - } - }); - } else { - item.setTitle(R.string.edit); - getActivity().findViewById(R.id.avatar_buttons).setVisibility(View.INVISIBLE); - - if (adapter.filteredDisplayList.size() == 0) { - getActivity().findViewById(R.id.emptyList).setVisibility(View.VISIBLE); - getActivity().findViewById(R.id.userinfo_list).setVisibility(View.GONE); - } + if (adapter.filteredDisplayList.size() == 0) { + getActivity().findViewById(R.id.emptyList).setVisibility(View.VISIBLE); + getActivity().findViewById(R.id.userinfo_list).setVisibility(View.GONE); } + } - adapter.notifyDataSetChanged(); + adapter.notifyDataSetChanged(); - return true; - - default: - return super.onOptionsItemSelected(item); + return true; } + return super.onOptionsItemSelected(item); } @Override diff --git a/app/src/main/java/com/nextcloud/talk/controllers/RingtoneSelectionController.java b/app/src/main/java/com/nextcloud/talk/controllers/RingtoneSelectionController.java index f5edc8cf9..6c8e06b92 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/RingtoneSelectionController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/RingtoneSelectionController.java @@ -116,12 +116,10 @@ public class RingtoneSelectionController extends BaseController implements Flexi @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - return getRouter().popCurrentController(); - default: - return super.onOptionsItemSelected(item); + if (item.getItemId() == android.R.id.home) { + return getRouter().popCurrentController(); } + return super.onOptionsItemSelected(item); } private void prepareViews() { diff --git a/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java b/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java index 8353afbfe..7b9ed699e 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java @@ -84,13 +84,11 @@ public abstract class BaseController extends ButterKnifeController { @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - getRouter().popCurrentController(); - return true; - default: - return super.onOptionsItemSelected(item); + if (item.getItemId() == android.R.id.home) { + getRouter().popCurrentController(); + return true; } + return super.onOptionsItemSelected(item); } private void cleanTempCertPreference() {