Fix bugs found by Marcel

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2021-04-07 13:13:36 +02:00
parent 1fec3e7635
commit a57253e0df
No known key found for this signature in database
GPG Key ID: 0E00D4D47D0C5AF7
5 changed files with 111 additions and 43 deletions

View File

@ -111,6 +111,7 @@ public class ProfileController extends BaseController {
private UserEntity currentUser;
private boolean edit = false;
private RecyclerView recyclerView;
private UserInfoAdapter adapter;
private UserProfileData userInfo;
private ArrayList<String> editableFields = new ArrayList<>();
@ -143,6 +144,12 @@ public class ProfileController extends BaseController {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.edit).setVisible(editableFields.size() > 0);
if (edit) {
menu.findItem(R.id.edit).setTitle(R.string.save);
} else {
menu.findItem(R.id.edit).setTitle(R.string.edit);
}
}
@Override
@ -158,12 +165,16 @@ public class ProfileController extends BaseController {
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 (currentUser.isAvatarEndpointAvailable()) {
// 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);
}
ncApi.getEditableUserProfileFields(ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken()),
ncApi.getEditableUserProfileFields(
ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken()),
ApiUtils.getUrlForUserFields(currentUser.getBaseUrl()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@ -175,7 +186,7 @@ public class ProfileController extends BaseController {
@Override
public void onNext(@NotNull UserProfileFieldsOverall userProfileFieldsOverall) {
editableFields = userProfileFieldsOverall.getOcs().getData();
recyclerView.getAdapter().notifyDataSetChanged();
adapter.notifyDataSetChanged();
}
@Override
@ -191,9 +202,14 @@ public class ProfileController extends BaseController {
} 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);
}
}
recyclerView.getAdapter().notifyDataSetChanged();
adapter.notifyDataSetChanged();
return true;
@ -207,9 +223,8 @@ public class ProfileController extends BaseController {
super.onAttach(view);
recyclerView = getActivity().findViewById(R.id.userinfo_list);
recyclerView.setAdapter(new UserInfoAdapter(null,
getActivity().getResources().getColor(R.color.colorPrimary),
this));
adapter = new UserInfoAdapter(null, getActivity().getResources().getColor(R.color.colorPrimary), this);
recyclerView.setAdapter(adapter);
recyclerView.setItemViewCacheSize(20);
currentUser = userUtils.getCurrentUser();
@ -291,7 +306,12 @@ public class ProfileController extends BaseController {
((TextView) getActivity().findViewById(R.id.userinfo_fullName)).setText(userInfo.getDisplayName());
}
if (TextUtils.isEmpty(userInfo.getPhone()) &&
getActivity().findViewById(R.id.loading_content).setVisibility(View.VISIBLE);
adapter.setData(createUserInfoDetails(userInfo));
if (TextUtils.isEmpty(userInfo.getDisplayName()) &&
TextUtils.isEmpty(userInfo.getPhone()) &&
TextUtils.isEmpty(userInfo.getEmail()) &&
TextUtils.isEmpty(userInfo.getAddress()) &&
TextUtils.isEmpty(userInfo.getTwitter()) &&
@ -305,15 +325,8 @@ public class ProfileController extends BaseController {
getActivity().getString(R.string.userinfo_no_info_headline),
getActivity().getString(R.string.userinfo_no_info_text), R.drawable.ic_user);
} else {
getActivity().findViewById(R.id.loading_content).setVisibility(View.VISIBLE);
getActivity().findViewById(R.id.emptyList).setVisibility(View.GONE);
RecyclerView recyclerView = getActivity().findViewById(R.id.userinfo_list);
if (recyclerView.getAdapter() instanceof UserInfoAdapter) {
UserInfoAdapter adapter = ((UserInfoAdapter) recyclerView.getAdapter());
adapter.setData(createUserInfoDetails(userInfo));
}
getActivity().findViewById(R.id.loading_content).setVisibility(View.GONE);
getActivity().findViewById(R.id.userinfo_list).setVisibility(View.VISIBLE);
}
@ -334,7 +347,7 @@ public class ProfileController extends BaseController {
editableFields = userProfileFieldsOverall.getOcs().getData();
getActivity().invalidateOptionsMenu();
recyclerView.getAdapter().notifyDataSetChanged();
adapter.notifyDataSetChanged();
}
@Override
@ -414,9 +427,7 @@ public class ProfileController extends BaseController {
}
private void save() {
UserInfoAdapter adapter = (UserInfoAdapter) recyclerView.getAdapter();
for (UserInfoDetailsItem item : adapter.mDisplayList) {
for (UserInfoDetailsItem item : adapter.displayList) {
// Text
if (!item.text.equals(userInfo.getValueByField(item.field))) {
String credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken());
@ -460,6 +471,8 @@ public class ProfileController extends BaseController {
if (item.scope != userInfo.getScopeByField(item.field)) {
saveScope(item, userInfo);
}
adapter.updateFilteredList();
}
}
@ -643,7 +656,8 @@ public class ProfileController extends BaseController {
}
public static class UserInfoAdapter extends RecyclerView.Adapter<UserInfoAdapter.ViewHolder> {
protected List<UserInfoDetailsItem> mDisplayList;
protected List<UserInfoDetailsItem> displayList;
protected List<UserInfoDetailsItem> filteredDisplayList = new LinkedList<>();
@ColorInt
protected int mTintColor;
private final ProfileController controller;
@ -667,16 +681,31 @@ public class ProfileController extends BaseController {
public UserInfoAdapter(List<UserInfoDetailsItem> displayList,
@ColorInt int tintColor,
ProfileController controller) {
mDisplayList = displayList == null ? new LinkedList<>() : displayList;
this.displayList = displayList == null ? new LinkedList<>() : displayList;
mTintColor = tintColor;
this.controller = controller;
}
public void setData(List<UserInfoDetailsItem> displayList) {
mDisplayList = displayList == null ? new LinkedList<>() : displayList;
this.displayList = displayList == null ? new LinkedList<>() : displayList;
updateFilteredList();
notifyDataSetChanged();
}
public void updateFilteredList() {
filteredDisplayList.clear();
if (displayList != null) {
for (UserInfoDetailsItem item : displayList) {
if (!TextUtils.isEmpty(item.text)) {
filteredDisplayList.add(item);
}
}
}
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
@ -687,7 +716,14 @@ public class ProfileController extends BaseController {
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
UserInfoDetailsItem item = mDisplayList.get(position);
UserInfoDetailsItem item;
if (controller.edit) {
item = displayList.get(position);
} else {
item = filteredDisplayList.get(position);
}
if (item.scope == null) {
holder.scope.setVisibility(View.GONE);
@ -719,7 +755,11 @@ public class ProfileController extends BaseController {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
mDisplayList.get(holder.getAdapterPosition()).text = holder.text.getText().toString();
if (controller.edit) {
displayList.get(holder.getAdapterPosition()).text = holder.text.getText().toString();
} else {
filteredDisplayList.get(holder.getAdapterPosition()).text = holder.text.getText().toString();
}
}
@Override
@ -764,11 +804,15 @@ public class ProfileController extends BaseController {
@Override
public int getItemCount() {
return mDisplayList.size();
if (controller.edit) {
return displayList.size();
} else {
return filteredDisplayList.size();
}
}
public void updateScope(int position, Scope scope) {
mDisplayList.get(position).scope = scope;
displayList.get(position).scope = scope;
notifyDataSetChanged();
}
}

View File

@ -1,3 +1,19 @@
<!--
@author Google LLC
Copyright (C) 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16dp"
android:height="16dp"

View File

@ -1,4 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
@author Google LLC
Copyright (C) 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"

View File

@ -38,7 +38,7 @@
<EditText
android:id="@+id/user_info_edit_text"
android:layout_width="259dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/user_info_icon_horizontal_margin"
android:layout_marginEnd="@dimen/standard_margin"
@ -51,8 +51,8 @@
app:layout_constraintEnd_toStartOf="@id/scope"
app:layout_constraintStart_toEndOf="@id/icon"
app:layout_constraintTop_toTopOf="parent"
tools:text="+49 123 456 789 12"
tools:ignore="LabelFor" />
tools:ignore="LabelFor"
tools:text="+49 123 456 789 12" />
<ImageView
android:id="@+id/scope"

View File

@ -168,8 +168,7 @@
<string name="nc_delete_call">Delete conversation</string>
<string name="nc_delete">Delete</string>
<string name="nc_delete_conversation_default">Please confirm your intent to remove the conversation.</string>
<string name="nc_delete_conversation_one2one">If you delete the conversation, it will also be
deleted for %1$s.</string>
<string name="nc_delete_conversation_one2one">If you delete the conversation, it will also be deleted for %1$s.</string>
<string name="nc_delete_conversation_more">If you delete the conversation, it will also be deleted for all other participants.</string>
<string name="nc_new_conversation">New conversation</string>
@ -198,8 +197,7 @@
<string name="nc_incoming_call">Incoming call from</string>
<string name="nc_nick_guest">Guest</string>
<string name="nc_public_call">New public conversation</string>
<string name="nc_public_call_explanation">Public conversations let you invite people from outside through a
specially crafted link.</string>
<string name="nc_public_call_explanation">Public conversations let you invite people from outside through a specially crafted link.</string>
<string name="nc_call_timeout">No response in 45 seconds, tap to try again</string>
<string name="nc_call_reconnecting">Reconnecting…</string>
<string name="nc_offline">Currently offline, please check your connectivity</string>
@ -218,13 +216,11 @@
<string name="nc_mute_calls">Mute calls</string>
<string name="nc_mute_calls_desc">Incoming calls will be silenced</string>
<string name="nc_important_conversation">Important conversation</string>
<string name="nc_important_conversation_desc">Notifications in this conversation will override
Do Not Disturb settings</string>
<string name="nc_important_conversation_desc">Notifications in this conversation will override Do Not Disturb settings</string>
<!-- Bottom sheet menu -->
<string name="nc_failed_to_perform_operation">Sorry, something went wrong!</string>
<string name="nc_failed_signaling_settings">Target server does not support joining public conversations via mobile
phones. You may attempt to join the conversation via web browser.</string>
<string name="nc_failed_signaling_settings">Target server does not support joining public conversations via mobile phones. You may attempt to join the conversation via web browser.</string>
<string name="nc_all_ok_operation">OK, all done!</string>
<string name="nc_ok">OK</string>
<string name="nc_call_name">Conversation name</string>
@ -346,12 +342,10 @@
<!-- Phonebook Integration -->
<string name="nc_settings_phone_book_integration_key" translatable="false">phone_book_integration</string>
<string name="nc_settings_phone_book_integration_desc">Match contacts based on phone number to integrate Talk
shortcut into system contacts app</string>
<string name="nc_settings_phone_book_integration_desc">Match contacts based on phone number to integrate Talk shortcut into system contacts app</string>
<string name="nc_settings_phone_book_integration_title">Phone number integration</string>
<string name="nc_settings_phone_book_integration_phone_number_dialog_title">Phone number</string>
<string name="nc_settings_phone_book_integration_phone_number_dialog_description">You can set your phone number so
other users will be able to find you</string>
<string name="nc_settings_phone_book_integration_phone_number_dialog_description">You can set your phone number so other users will be able to find you</string>
<string name="nc_settings_phone_book_integration_phone_number_dialog_invalid">Invalid phone number</string>
<string name="nc_settings_phone_book_integration_phone_number_dialog_success">Phone number set successfully</string>
<string name="no_phone_book_integration_due_to_permissions">No phone number integration due to missing permissions</string>
@ -391,8 +385,7 @@
<string name="appbar_search_in">Search in %s</string>
<!-- Non-translatable strings -->
<string name="path_password_strike_through" translatable="false"
tools:override="true">M3.27,4.27L19.74,20.74</string>
<string name="path_password_strike_through" translatable="false" tools:override="true">M3.27,4.27L19.74,20.74</string>
<string name="tooManyUnreadMessages" translatable="false">999+</string>
<string name="nc_action_open_main_menu">Open main menu</string>
</resources>