Merge branch 'BrianBlade-account_state_switch' into development

This commit is contained in:
iNPUTmice 2015-04-01 23:46:54 +02:00
commit ef68084098
3 changed files with 49 additions and 17 deletions

View file

@ -168,6 +168,14 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
} }
} }
public void onClickTglAccountState(Account account) {
if (account.isOptionSet(Account.OPTION_DISABLED)) {
enableAccount(account);
} else {
disableAccount(account);
}
}
private void publishAvatar(Account account) { private void publishAvatar(Account account) {
Intent intent = new Intent(getApplicationContext(), Intent intent = new Intent(getApplicationContext(),
PublishProfilePictureActivity.class); PublishProfilePictureActivity.class);

View file

@ -5,6 +5,7 @@ import java.util.List;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.ui.XmppActivity;
import eu.siacs.conversations.ui.ManageAccountActivity;
import android.content.Context; import android.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -12,6 +13,7 @@ import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Switch;
public class AccountAdapter extends ArrayAdapter<Account> { public class AccountAdapter extends ArrayAdapter<Account> {
@ -24,7 +26,7 @@ public class AccountAdapter extends ArrayAdapter<Account> {
@Override @Override
public View getView(int position, View view, ViewGroup parent) { public View getView(int position, View view, ViewGroup parent) {
Account account = getItem(position); final Account account = getItem(position);
if (view == null) { if (view == null) {
LayoutInflater inflater = (LayoutInflater) getContext() LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@ -34,8 +36,7 @@ public class AccountAdapter extends ArrayAdapter<Account> {
jid.setText(account.getJid().toBareJid().toString()); jid.setText(account.getJid().toBareJid().toString());
TextView statusView = (TextView) view.findViewById(R.id.account_status); TextView statusView = (TextView) view.findViewById(R.id.account_status);
ImageView imageView = (ImageView) view.findViewById(R.id.account_image); ImageView imageView = (ImageView) view.findViewById(R.id.account_image);
imageView.setImageBitmap(activity.avatarService().get(account, imageView.setImageBitmap(activity.avatarService().get(account, activity.getPixel(48)));
activity.getPixel(48)));
statusView.setText(getContext().getString(account.getStatus().getReadableId())); statusView.setText(getContext().getString(account.getStatus().getReadableId()));
switch (account.getStatus()) { switch (account.getStatus()) {
case ONLINE: case ONLINE:
@ -49,6 +50,18 @@ public class AccountAdapter extends ArrayAdapter<Account> {
statusView.setTextColor(activity.getWarningTextColor()); statusView.setTextColor(activity.getWarningTextColor());
break; break;
} }
final Switch tglAccountState = (Switch) view.findViewById(R.id.tgl_account_status);
boolean isDisabled = (account.getStatus() == Account.State.DISABLED) ? true : false;
tglAccountState.setChecked(!isDisabled);
tglAccountState.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (activity instanceof ManageAccountActivity) {
((ManageAccountActivity) activity).onClickTglAccountState(account);
tglAccountState.toggle();
}
}
});
return view; return view;
} }
} }

View file

@ -20,7 +20,10 @@
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_toRightOf="@+id/account_image" android:layout_toRightOf="@+id/account_image"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="8dp" > android:paddingLeft="8dp"
android:paddingRight="8dp"
android:layout_toLeftOf="@+id/tgl_account_status"
android:layout_toStartOf="@+id/tgl_account_status">
<TextView <TextView
android:id="@+id/account_jid" android:id="@+id/account_jid"
@ -41,4 +44,12 @@
android:textStyle="bold" /> android:textStyle="bold" />
</LinearLayout> </LinearLayout>
<Switch
android:id="@+id/tgl_account_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:focusable="false"/>
</RelativeLayout> </RelativeLayout>