allow to temporarily disable accounts

This commit is contained in:
Daniel Gultsch 2014-02-04 21:44:16 +01:00
parent 0d80d88736
commit 4fd8620c6c
17 changed files with 183 additions and 33 deletions

View file

@ -11,6 +11,7 @@ public final class R {
public static final class array { public static final class array {
public static final int conversation_encryption_type_entries=0x7f050000; public static final int conversation_encryption_type_entries=0x7f050000;
public static final int conversation_encryption_type_values=0x7f050001; public static final int conversation_encryption_type_values=0x7f050001;
public static final int manage_account_options=0x7f050002;
} }
public static final class attr { public static final class attr {
} }
@ -28,17 +29,20 @@ public final class R {
public static final int es_slidingpane_shadow=0x7f020000; public static final int es_slidingpane_shadow=0x7f020000;
public static final int ic_action_add=0x7f020001; public static final int ic_action_add=0x7f020001;
public static final int ic_action_add_person=0x7f020002; public static final int ic_action_add_person=0x7f020002;
public static final int ic_action_send=0x7f020003; public static final int ic_action_delete=0x7f020003;
public static final int ic_action_send_now=0x7f020004; public static final int ic_action_send=0x7f020004;
public static final int ic_action_unsecure=0x7f020005; public static final int ic_action_send_now=0x7f020005;
public static final int ic_launcher=0x7f020006; public static final int ic_action_unsecure=0x7f020006;
public static final int ic_profile=0x7f020007; public static final int ic_launcher=0x7f020007;
public static final int message_border=0x7f020008; public static final int ic_profile=0x7f020008;
public static final int notification=0x7f020009; public static final int message_border=0x7f020009;
public static final int section_header=0x7f02000a; public static final int notification=0x7f02000a;
public static final int section_header=0x7f02000b;
} }
public static final class id { public static final class id {
public static final int account_confirm_password_desc=0x7f0a0011; public static final int account_confirm_password_desc=0x7f0a0011;
public static final int account_disable=0x7f0a002c;
public static final int account_enable=0x7f0a002d;
public static final int account_jid=0x7f0a0000; public static final int account_jid=0x7f0a0000;
public static final int account_list=0x7f0a0021; public static final int account_list=0x7f0a0021;
public static final int account_password=0x7f0a000f; public static final int account_password=0x7f0a000f;
@ -98,7 +102,8 @@ public final class R {
public static final class menu { public static final class menu {
public static final int conversations=0x7f090000; public static final int conversations=0x7f090000;
public static final int manageaccounts=0x7f090001; public static final int manageaccounts=0x7f090001;
public static final int newconversation=0x7f090002; public static final int manageaccounts_context=0x7f090002;
public static final int newconversation=0x7f090003;
} }
public static final class string { public static final class string {
public static final int action_accounts=0x7f070003; public static final int action_accounts=0x7f070003;

Binary file not shown.

After

Width:  |  Height:  |  Size: 679 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 513 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 884 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -2,7 +2,8 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="8dp"> android:padding="8dp"
android:background="?android:attr/activatedBackgroundIndicator">

View file

@ -2,7 +2,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" > <menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/action_add_account" <item android:id="@+id/action_add_account"
android:showAsAction="always" android:showAsAction="always"
android:title="@string/action_add_account"/> android:title="@string/action_add_account"
android:icon="@drawable/ic_action_add_person"/>
<item <item
android:id="@+id/action_settings" android:id="@+id/action_settings"
android:orderInCategory="100" android:orderInCategory="100"

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:icon="@drawable/ic_action_delete"
android:title="Delete"
android:showAsAction="always"
/>
<item
android:id="@+id/account_disable"
android:title="Temporarily disable"
android:showAsAction="always"/>
<item
android:id="@+id/account_enable"
android:title="Enable"
android:showAsAction="always"
android:visible="false"/>
</menu>

View file

@ -10,4 +10,8 @@
<item>pgp</item> <item>pgp</item>
<item>otr</item> <item>otr</item>
</array> </array>
<array name="manage_account_options">
<item>Delete</item>
<item>Disable</item>
</array>
</resources> </resources>

View file

@ -17,7 +17,9 @@ public class Account extends AbstractEntity{
public static final String ROSTERVERSION = "rosterversion"; public static final String ROSTERVERSION = "rosterversion";
public static final int OPTION_USETLS = 0; public static final int OPTION_USETLS = 0;
public static final int OPTION_DISABLED = 1;
public static final int STATUS_DISABLED = -1;
public static final int STATUS_OFFLINE = 0; public static final int STATUS_OFFLINE = 0;
public static final int STATUS_ONLINE = 1; public static final int STATUS_ONLINE = 1;
public static final int STATUS_UNAUTHORIZED = 2; public static final int STATUS_UNAUTHORIZED = 2;
@ -55,6 +57,20 @@ public class Account extends AbstractEntity{
return ((options & (1 << option)) != 0); return ((options & (1 << option)) != 0);
} }
public void setOption(int option, boolean value) {
if (value) {
Log.d("xmppService","options: "+options);
this.options = (this.options | 1 << option);
Log.d("xmppService","setting option "+option+" to 1");
Log.d("xmppService","options: "+options);
} else {
Log.d("xmppService","options: "+options);
Log.d("xmppService","setting option "+option+" to 0");
this.options = (this.options ^ 1 << option);
Log.d("xmppService","options: "+options);
}
}
public String getUsername() { public String getUsername() {
return username; return username;
} }
@ -84,7 +100,11 @@ public class Account extends AbstractEntity{
} }
public int getStatus() { public int getStatus() {
return this.status; if (isOptionSet(OPTION_DISABLED)) {
return STATUS_DISABLED;
} else {
return this.status;
}
} }
public void setResource(String resource) { public void setResource(String resource) {
@ -102,6 +122,7 @@ public class Account extends AbstractEntity{
values.put(USERNAME, username); values.put(USERNAME, username);
values.put(SERVER, server); values.put(SERVER, server);
values.put(PASSWORD, password); values.put(PASSWORD, password);
values.put(OPTIONS,options);
return values; return values;
} }

View file

@ -95,8 +95,11 @@ public class XmppConnectionService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
for (Account account : accounts) { for (Account account : accounts) {
if (!connections.containsKey(account)) { if (!connections.containsKey(account)) {
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
this.connections.put(account, this.createConnection(account)); this.connections.put(account, this.createConnection(account));
} else {
Log.d(LOGTAG,account.getJid()+": not starting because it's disabled");
}
} }
} }
return START_STICKY; return START_STICKY;
@ -253,7 +256,11 @@ public class XmppConnectionService extends Service {
connection.disconnect(); connection.disconnect();
this.connections.remove(account); this.connections.remove(account);
} }
this.connections.put(account, this.createConnection(account)); if (!account.isOptionSet(Account.OPTION_DISABLED)) {
this.connections.put(account, this.createConnection(account));
} else {
Log.d(LOGTAG,account.getJid()+": not starting because it's disabled");
}
if (accountChangedListener!=null) accountChangedListener.onAccountListChangedListener(); if (accountChangedListener!=null) accountChangedListener.onAccountListChangedListener();
} }

View file

@ -92,7 +92,7 @@ public class EditAccount extends DialogFragment {
usernameText.setText(account.getUsername()); usernameText.setText(account.getUsername());
serverText.setText(account.getServer()); serverText.setText(account.getServer());
okButtonDesc = "Edit"; okButtonDesc = "Edit";
builder.setNegativeButton("Delete Account", new OnClickListener() { /*builder.setNegativeButton("Delete Account", new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -112,7 +112,7 @@ public class EditAccount extends DialogFragment {
builder.setNegativeButton("Cancel",null); builder.setNegativeButton("Cancel",null);
builder.create().show(); builder.create().show();
} }
}); });*/
} else { } else {
builder.setTitle("Add account"); builder.setTitle("Add account");
okButtonDesc = "Add"; okButtonDesc = "Add";

View file

@ -7,23 +7,32 @@ import de.gultsch.chat.R;
import de.gultsch.chat.entities.Account; import de.gultsch.chat.entities.Account;
import de.gultsch.chat.ui.EditAccount.EditAccountListener; import de.gultsch.chat.ui.EditAccount.EditAccountListener;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.ActionMode;
import android.view.ActionMode.Callback;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
public class ManageAccountActivity extends XmppActivity { public class ManageAccountActivity extends XmppActivity implements ActionMode.Callback {
protected boolean isActionMode = false;
protected ActionMode actionMode;
protected Account selectedAccountForActionMode = null;
protected List<Account> accountList = new ArrayList<Account>(); protected List<Account> accountList = new ArrayList<Account>();
protected ListView accountListView; protected ListView accountListView;
protected ArrayAdapter<Account> accountListViewAdapter; protected ArrayAdapter<Account> accountListViewAdapter;
@ -70,6 +79,10 @@ public class ManageAccountActivity extends XmppActivity {
TextView statusView = (TextView) view TextView statusView = (TextView) view
.findViewById(R.id.account_status); .findViewById(R.id.account_status);
switch (account.getStatus()) { switch (account.getStatus()) {
case Account.STATUS_DISABLED:
statusView.setText("temporarily disabled");
statusView.setTextColor(0xFF1da9da);
break;
case Account.STATUS_ONLINE: case Account.STATUS_ONLINE:
statusView.setText("online"); statusView.setText("online");
statusView.setTextColor(0xFF83b600); statusView.setTextColor(0xFF83b600);
@ -93,27 +106,49 @@ public class ManageAccountActivity extends XmppActivity {
return view; return view;
} }
}; };
final Activity activity = this;
accountListView.setAdapter(this.accountListViewAdapter); accountListView.setAdapter(this.accountListViewAdapter);
accountListView.setOnItemClickListener(new OnItemClickListener() { accountListView.setOnItemClickListener(new OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> arg0, View view, public void onItemClick(AdapterView<?> arg0, View view,
int position, long arg3) { int position, long arg3) {
EditAccount dialog = new EditAccount(); if (!isActionMode) {
dialog.setAccount(accountList.get(position)); EditAccount dialog = new EditAccount();
dialog.setEditAccountListener(new EditAccountListener() { dialog.setAccount(accountList.get(position));
dialog.setEditAccountListener(new EditAccountListener() {
@Override
public void onAccountEdited(Account account) {
xmppConnectionService.updateAccount(account);
}
@Override
public void onAccountDelete(Account account) {
xmppConnectionService.deleteAccount(account);
}
});
dialog.show(getFragmentManager(), "edit_account");
} else {
selectedAccountForActionMode = accountList.get(position);
actionMode.invalidate();
}
}
});
accountListView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override @Override
public void onAccountEdited(Account account) { public boolean onItemLongClick(AdapterView<?> arg0, View view,
xmppConnectionService.updateAccount(account); int position, long arg3) {
} if (!isActionMode) {
accountListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
@Override accountListView.setItemChecked(position,true);
public void onAccountDelete(Account account) { selectedAccountForActionMode = accountList.get(position);
xmppConnectionService.deleteAccount(account); actionMode = activity.startActionMode((Callback) activity);
} return true;
}); } else {
dialog.show(getFragmentManager(), "edit_account"); return false;
}
} }
}); });
} }
@ -180,4 +215,63 @@ public class ManageAccountActivity extends XmppActivity {
}); });
dialog.show(getFragmentManager(), "add_account"); dialog.show(getFragmentManager(), "add_account");
} }
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (item.getItemId()==R.id.account_disable) {
selectedAccountForActionMode.setOption(Account.OPTION_DISABLED, true);
xmppConnectionService.updateAccount(selectedAccountForActionMode);
mode.finish();
} else if (item.getItemId()==R.id.account_enable) {
selectedAccountForActionMode.setOption(Account.OPTION_DISABLED, false);
xmppConnectionService.updateAccount(selectedAccountForActionMode);
mode.finish();
}
return true;
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.manageaccounts_context, menu);
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
// TODO Auto-generated method stub
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
if (selectedAccountForActionMode.isOptionSet(Account.OPTION_DISABLED)) {
menu.findItem(R.id.account_enable).setVisible(true);
menu.findItem(R.id.account_disable).setVisible(false);
} else {
menu.findItem(R.id.account_disable).setVisible(true);
menu.findItem(R.id.account_enable).setVisible(false);
}
return true;
}
@Override
public void onActionModeStarted(ActionMode mode) {
super.onActionModeStarted(mode);
this.isActionMode = true;
}
@Override
public void onActionModeFinished(ActionMode mode) {
super.onActionModeFinished(mode);
this.isActionMode = false;
accountListView.clearChoices();
accountListView.requestLayout();
accountListView.post(new Runnable() {
@Override
public void run() {
accountListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
}
});
}
} }

View file

@ -185,7 +185,7 @@ public class NewConversationActivity extends XmppActivity {
AlertDialog.Builder builder = new AlertDialog.Builder(activity); AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("Choose account"); builder.setTitle("Choose account");
builder.setSingleChoiceItems(accountList,0,new OnClickListener() { builder.setItems(accountList,new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {