aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/ui/ManageAccountActivity.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-04 15:09:50 +0100
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-04 15:09:50 +0100
commit0d80d88736926d06e97f22f9ecc63d4fb696751c (patch)
treed61669953ae47a0c96dcc5dc814bc0f49527c547 /src/de/gultsch/chat/ui/ManageAccountActivity.java
parent14a171b088363d8e39b547eecc181570c4289428 (diff)
reworked account managment. now status display actually works
Diffstat (limited to 'src/de/gultsch/chat/ui/ManageAccountActivity.java')
-rw-r--r--src/de/gultsch/chat/ui/ManageAccountActivity.java108
1 files changed, 66 insertions, 42 deletions
diff --git a/src/de/gultsch/chat/ui/ManageAccountActivity.java b/src/de/gultsch/chat/ui/ManageAccountActivity.java
index c7d6ce58..0a9b03de 100644
--- a/src/de/gultsch/chat/ui/ManageAccountActivity.java
+++ b/src/de/gultsch/chat/ui/ManageAccountActivity.java
@@ -6,7 +6,6 @@ import java.util.List;
import de.gultsch.chat.R;
import de.gultsch.chat.entities.Account;
import de.gultsch.chat.ui.EditAccount.EditAccountListener;
-import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@@ -25,28 +24,72 @@ import android.widget.TextView;
public class ManageAccountActivity extends XmppActivity {
-
protected List<Account> accountList = new ArrayList<Account>();
protected ListView accountListView;
protected ArrayAdapter<Account> accountListViewAdapter;
-
+ protected OnAccountListChangedListener accountChanged = new OnAccountListChangedListener() {
+
+ @Override
+ public void onAccountListChangedListener() {
+ Log.d("xmppService", "ui on account list changed listener");
+ accountList.clear();
+ accountList.addAll(xmppConnectionService.getAccounts());
+ runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ if (accountList.size() == 1) {
+ startActivity(new Intent(getApplicationContext(),
+ NewConversationActivity.class));
+ }
+ accountListViewAdapter.notifyDataSetChanged();
+ }
+ });
+ }
+ };
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.manage_accounts);
-
+
accountListView = (ListView) findViewById(R.id.account_list);
- accountListViewAdapter = new ArrayAdapter<Account>(getApplicationContext(), R.layout.account_row, this.accountList) {
+ accountListViewAdapter = new ArrayAdapter<Account>(
+ getApplicationContext(), R.layout.account_row, this.accountList) {
@Override
public View getView(int position, View view, ViewGroup parent) {
+ Account account = getItem(position);
if (view == null) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = (View) inflater.inflate(R.layout.account_row, null);
}
- ((TextView) view.findViewById(R.id.account_jid)).setText(getItem(position).getJid());
-
+ ((TextView) view.findViewById(R.id.account_jid))
+ .setText(account.getJid());
+ TextView statusView = (TextView) view
+ .findViewById(R.id.account_status);
+ switch (account.getStatus()) {
+ case Account.STATUS_ONLINE:
+ statusView.setText("online");
+ statusView.setTextColor(0xFF83b600);
+ break;
+ case Account.STATUS_OFFLINE:
+ statusView.setText("offline");
+ statusView.setTextColor(0xFFe92727);
+ break;
+ case Account.STATUS_UNAUTHORIZED:
+ statusView.setText("unauthorized");
+ statusView.setTextColor(0xFFe92727);
+ break;
+ case Account.STATUS_SERVER_NOT_FOUND:
+ statusView.setText("server not found");
+ statusView.setTextColor(0xFFe92727);
+ break;
+ default:
+ break;
+ }
+
return view;
}
};
@@ -54,12 +97,12 @@ public class ManageAccountActivity extends XmppActivity {
accountListView.setOnItemClickListener(new OnItemClickListener() {
@Override
- public void onItemClick(AdapterView<?> arg0, View view, int position,
- long arg3) {
+ public void onItemClick(AdapterView<?> arg0, View view,
+ int position, long arg3) {
EditAccount dialog = new EditAccount();
dialog.setAccount(accountList.get(position));
dialog.setEditAccountListener(new EditAccountListener() {
-
+
@Override
public void onAccountEdited(Account account) {
xmppConnectionService.updateAccount(account);
@@ -67,41 +110,27 @@ public class ManageAccountActivity extends XmppActivity {
@Override
public void onAccountDelete(Account account) {
-
- Log.d("gultsch","deleting account:"+account.getJid());
-
xmppConnectionService.deleteAccount(account);
-
- //dont bother finding the right account in the frontend list. just reload
- accountList.clear();
- accountList.addAll(xmppConnectionService.getAccounts());
-
- accountListViewAdapter.notifyDataSetChanged();
-
}
});
- dialog.show(getFragmentManager(),"edit_account");
+ dialog.show(getFragmentManager(), "edit_account");
}
});
}
@Override
- public void onStart() {
- super.onStart();
+ protected void onStop() {
+ super.onStop();
if (xmppConnectionServiceBound) {
- this.accountList.clear();
- this.accountList.addAll(xmppConnectionService
- .getAccounts());
- accountListViewAdapter.notifyDataSetChanged();
- if (this.accountList.size() == 0) {
- getActionBar().setDisplayHomeAsUpEnabled(false);
- }
+ xmppConnectionService.removeOnAccountListChangedListener();
+ unbindService(mConnection);
+ xmppConnectionServiceBound = false;
}
}
-
+
@Override
void onBackendConnected() {
- Log.d("gultsch","called on backend connected");
+ xmppConnectionService.setOnAccountListChangedListener(accountChanged);
this.accountList.clear();
this.accountList.addAll(xmppConnectionService.getAccounts());
accountListViewAdapter.notifyDataSetChanged();
@@ -110,14 +139,14 @@ public class ManageAccountActivity extends XmppActivity {
addAccount();
}
}
-
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.manageaccounts, menu);
return true;
}
-
+
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@@ -137,23 +166,18 @@ public class ManageAccountActivity extends XmppActivity {
final Activity activity = this;
EditAccount dialog = new EditAccount();
dialog.setEditAccountListener(new EditAccountListener() {
-
+
@Override
public void onAccountEdited(Account account) {
xmppConnectionService.createAccount(account);
- accountList.add(account);
- accountListViewAdapter.notifyDataSetChanged();
activity.getActionBar().setDisplayHomeAsUpEnabled(true);
- if (accountList.size() == 1) {
- activity.startActivity(new Intent(activity,NewConversationActivity.class));
- }
}
@Override
public void onAccountDelete(Account account) {
- //this will never be called
+ // this will never be called
}
});
- dialog.show(getFragmentManager(),"add_account");
+ dialog.show(getFragmentManager(), "add_account");
}
}