mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-23 05:25:31 +03:00
replace menu switch statements with if/else
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
3c0ef1d1e0
commit
45a88c0722
5 changed files with 70 additions and 81 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<UserProfileFieldsOverall>() {
|
||||
@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<UserProfileFieldsOverall>() {
|
||||
@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
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue