optimized layout adding username + account-url

This commit is contained in:
AndyScherzinger 2016-10-11 16:07:20 +02:00
parent 8c9e2206cb
commit e89531fc1a
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
3 changed files with 156 additions and 97 deletions

View file

@ -16,7 +16,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="@dimen/account_item_layout_height"
@ -24,65 +24,101 @@
android:weightSum="1">
<FrameLayout
android:id="@+id/avatar_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/user_icon"
android:layout_width="@dimen/user_icon_size"
android:layout_height="@dimen/user_icon_size"
android:layout_gravity="top|left"
android:layout_marginBottom="@dimen/alternate_half_margin"
android:layout_marginLeft="@dimen/standard_margin"
android:layout_marginRight="@dimen/alternate_half_margin"
android:layout_marginTop="@dimen/alternate_half_margin"
android:layout_marginBottom="@dimen/alternate_half_margin"
android:src="@drawable/ic_menu_archive"/>
<ImageView
android:id="@+id/ticker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_account_circle_white_18dp"
android:tint="@color/actionbar_start_color"
android:layout_gravity="bottom|right"
android:background="@drawable/round_bgnd"/>
android:background="@drawable/round_bgnd"
android:src="@drawable/ic_account_circle_white_18dp"
android:tint="@color/actionbar_start_color"/>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_toEndOf="@id/avatar_container"
android:layout_toLeftOf="@+id/passwordButton"
android:layout_toRightOf="@id/avatar_container"
android:layout_toStartOf="@id/passwordButton"
android:orientation="vertical">
<TextView
android:id="@+id/user_name"
android:layout_width="@dimen/zero"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/standard_half_margin"
android:layout_marginLeft="@dimen/standard_margin"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingRight="@dimen/standard_padding"
android:layout_marginRight="@dimen/standard_half_margin"
android:layout_marginStart="@dimen/standard_margin"
android:layout_marginTop="4dp"
android:ellipsize="end"
android:gravity="bottom"
android:maxLines="1"
android:text="@string/placeholder_filename"
android:textColor="@color/textColor"
android:textSize="@dimen/two_line_primary_text_size"/>
android:textAppearance="?attr/textAppearanceListItem"/>
<ImageButton
<TextView
android:id="@+id/account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginEnd="@dimen/standard_half_margin"
android:layout_marginLeft="@dimen/standard_margin"
android:layout_marginRight="@dimen/standard_half_margin"
android:layout_marginStart="@dimen/standard_margin"
android:ellipsize="end"
android:gravity="top"
android:maxLines="2"
android:text="@string/placeholder_sentence"
android:textColor="?android:attr/textColorSecondary"/>
</LinearLayout>
<ImageView
android:id="@+id/passwordButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical"
android:paddingLeft="@dimen/standard_half_padding"
android:paddingTop="@dimen/standard_padding"
android:layout_toLeftOf="@+id/removeButton"
android:layout_toStartOf="@id/removeButton"
android:paddingBottom="@dimen/standard_padding"
android:paddingLeft="@dimen/standard_half_padding"
android:paddingRight="@dimen/standard_half_padding"
android:background="?android:selectableItemBackground"
android:paddingTop="@dimen/standard_padding"
android:src="@drawable/ic_key"/>
<ImageButton
<ImageView
android:id="@+id/removeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical"
android:paddingLeft="@dimen/standard_half_padding"
android:paddingTop="@dimen/standard_padding"
android:paddingBottom="@dimen/standard_padding"
android:paddingLeft="@dimen/standard_half_padding"
android:paddingRight="@dimen/standard_padding"
android:background="?android:selectableItemBackground"
android:paddingTop="@dimen/standard_padding"
android:src="@drawable/ic_action_delete_grey"/>
</LinearLayout>
</RelativeLayout>

View file

@ -108,6 +108,13 @@ public class ManageAccountsActivity extends FileActivity
mListView.setAdapter(mAccountListAdapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switchAccount(mAccountListAdapter.getItem(position).getAccount());
}
});
initializeComponentGetters();
}
@ -263,7 +270,6 @@ public class ManageAccountsActivity extends FileActivity
}, mHandler);
}
@Override
public void switchAccount(Account account) {
if (getAccount().name.equals(account.name)) {
// current account selected, just go back

View file

@ -21,16 +21,17 @@ package com.owncloud.android.ui.adapter;
import android.accounts.Account;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.ui.activity.BaseActivity;
import com.owncloud.android.utils.DisplayUtils;
@ -69,9 +70,10 @@ public class AccountListAdapter extends ArrayAdapter<AccountListItem> implements
viewHolder.imageViewItem = (ImageView) convertView.findViewById(R.id.user_icon);
viewHolder.checkViewItem = (ImageView) convertView.findViewById(R.id.ticker);
viewHolder.checkViewItem.setImageDrawable(mTintedCheck);
viewHolder.accountViewItem = (TextView) convertView.findViewById(R.id.user_name);
viewHolder.passwordButtonItem = (ImageButton) convertView.findViewById(R.id.passwordButton);
viewHolder.removeButtonItem = (ImageButton) convertView.findViewById(R.id.removeButton);
viewHolder.usernameViewItem = (TextView) convertView.findViewById(R.id.user_name);
viewHolder.accountViewItem = (TextView) convertView.findViewById(R.id.account);
viewHolder.passwordButtonItem = (ImageView) convertView.findViewById(R.id.passwordButton);
viewHolder.removeButtonItem = (ImageView) convertView.findViewById(R.id.removeButton);
convertView.setTag(viewHolder);
} else {
@ -85,38 +87,44 @@ public class AccountListAdapter extends ArrayAdapter<AccountListItem> implements
// create account item
if (AccountListItem.TYPE_ACCOUNT == accountListItem.getType()) {
Account account = accountListItem.getAccount();
viewHolder.accountViewItem.setText(account.name);
setAccount(viewHolder, account);
setUsername(viewHolder, account);
setAvatar(viewHolder, account);
setCurrentlyActiveState(viewHolder, account);
setupListeners(position, viewHolder);
} // create add account action item
else if (AccountListItem.TYPE_ACTION_ADD == accountListItem.getType()) {
return setupAddAccountListItem(parent);
}
}
return convertView;
}
@NonNull
private View setupAddAccountListItem(ViewGroup parent) {
LayoutInflater inflater = mContext.getLayoutInflater();
View actionView = inflater.inflate(R.layout.account_action, parent, false);
((TextView) actionView.findViewById(R.id.user_name)).setText(R.string.prefs_add_account);
((ImageView) actionView.findViewById(R.id.user_icon)).setImageResource(R.drawable.ic_account_plus);
// bind action listener
actionView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.createAccount();
}
});
return actionView;
}
private void setAccount(AccountViewHolderItem viewHolder, Account account) {
viewHolder.accountViewItem.setText(DisplayUtils.convertIdn(account.name, false));
viewHolder.accountViewItem.setTag(account.name);
try {
DisplayUtils.setAvatar(account, this, mAccountAvatarRadiusDimension,
mContext.getResources(), mContext.getStorageManager(), viewHolder.imageViewItem);
} catch (Exception e) {
Log_OC.e(TAG, "Error calculating RGB value for account list item.", e);
// use user icon as a fallback
viewHolder.imageViewItem.setImageResource(R.drawable.ic_user);
}
if (AccountUtils.getCurrentOwnCloudAccount(getContext()).name.equals(account.name)) {
viewHolder.checkViewItem.setVisibility(View.VISIBLE);
} else {
viewHolder.checkViewItem.setVisibility(View.INVISIBLE);
}
viewHolder.imageViewItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.switchAccount(mValues.get(position).getAccount());
}
});
viewHolder.accountViewItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.switchAccount(mValues.get(position).getAccount());
}
});
private void setupListeners(final int position, AccountViewHolderItem viewHolder) {
/// bind listener to change password
viewHolder.passwordButtonItem.setOnClickListener(new View.OnClickListener() {
@Override
@ -132,26 +140,36 @@ public class AccountListAdapter extends ArrayAdapter<AccountListItem> implements
mListener.performAccountRemoval(mValues.get(position).getAccount());
}
});
} // create add account action item
else if (AccountListItem.TYPE_ACTION_ADD == accountListItem.getType()) {
LayoutInflater inflater = mContext.getLayoutInflater();
View actionView = inflater.inflate(R.layout.account_action, parent, false);
((TextView) actionView.findViewById(R.id.user_name)).setText(R.string.prefs_add_account);
((ImageView) actionView.findViewById(R.id.user_icon)).setImageResource(R.drawable.ic_account_plus);
// bind action listener
actionView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.createAccount();
}
});
return actionView;
private void setCurrentlyActiveState(AccountViewHolderItem viewHolder, Account account) {
if (AccountUtils.getCurrentOwnCloudAccount(getContext()).name.equals(account.name)) {
viewHolder.checkViewItem.setVisibility(View.VISIBLE);
} else {
viewHolder.checkViewItem.setVisibility(View.INVISIBLE);
}
}
return convertView;
private void setAvatar(AccountViewHolderItem viewHolder, Account account) {
try {
DisplayUtils.setAvatar(account, this, mAccountAvatarRadiusDimension,
mContext.getResources(), mContext.getStorageManager(), viewHolder.imageViewItem);
} catch (Exception e) {
Log_OC.e(TAG, "Error calculating RGB value for account list item.", e);
// use user icon as a fallback
viewHolder.imageViewItem.setImageResource(R.drawable.ic_user);
}
}
private void setUsername(AccountViewHolderItem viewHolder, Account account) {
try {
OwnCloudAccount oca = new OwnCloudAccount(account, mContext);
viewHolder.usernameViewItem.setText(oca.getDisplayName());
} catch (Exception e) {
Log_OC.w(TAG, "Account not found right after being read; using account name instead");
viewHolder.usernameViewItem.setText(AccountUtils.getAccountUsername(account.name));
}
viewHolder.usernameViewItem.setTag(account.name);
}
@Override
@ -173,8 +191,6 @@ public class AccountListAdapter extends ArrayAdapter<AccountListItem> implements
void changePasswordOfAccount(Account account);
void createAccount();
void switchAccount(Account account);
}
/**
@ -184,9 +200,10 @@ public class AccountListAdapter extends ArrayAdapter<AccountListItem> implements
ImageView imageViewItem;
ImageView checkViewItem;
TextView usernameViewItem;
TextView accountViewItem;
ImageButton passwordButtonItem;
ImageButton removeButtonItem;
ImageView passwordButtonItem;
ImageView removeButtonItem;
}
}