ui flow for first startup with no existing account
This commit is contained in:
parent
efba73ffd0
commit
76cfab03ec
|
@ -280,7 +280,10 @@ public class ConversationActivity extends XmppActivity {
|
||||||
swapConversationFragment();
|
swapConversationFragment();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (conversationList.size() <= 0) {
|
if (xmppConnectionService.getAccounts().size() == 0) {
|
||||||
|
startActivity(new Intent(this, ManageAccountActivity.class));
|
||||||
|
finish();
|
||||||
|
} else if (conversationList.size() <= 0) {
|
||||||
//add no history
|
//add no history
|
||||||
startActivity(new Intent(this, NewConversationActivity.class));
|
startActivity(new Intent(this, NewConversationActivity.class));
|
||||||
finish();
|
finish();
|
||||||
|
|
|
@ -6,6 +6,8 @@ import java.util.List;
|
||||||
import de.gultsch.chat.R;
|
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.ActionBar;
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -87,11 +89,13 @@ public class ManageAccountActivity extends XmppActivity {
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
if (xmppConnectionServiceBound) {
|
if (xmppConnectionServiceBound) {
|
||||||
Log.d("gultsch","already bound");
|
|
||||||
this.accountList.clear();
|
this.accountList.clear();
|
||||||
this.accountList.addAll(xmppConnectionService
|
this.accountList.addAll(xmppConnectionService
|
||||||
.getAccounts());
|
.getAccounts());
|
||||||
accountListViewAdapter.notifyDataSetChanged();
|
accountListViewAdapter.notifyDataSetChanged();
|
||||||
|
if (this.accountList.size() == 0) {
|
||||||
|
getActionBar().setDisplayHomeAsUpEnabled(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +105,10 @@ public class ManageAccountActivity extends XmppActivity {
|
||||||
this.accountList.clear();
|
this.accountList.clear();
|
||||||
this.accountList.addAll(xmppConnectionService.getAccounts());
|
this.accountList.addAll(xmppConnectionService.getAccounts());
|
||||||
accountListViewAdapter.notifyDataSetChanged();
|
accountListViewAdapter.notifyDataSetChanged();
|
||||||
|
if (this.accountList.size() == 0) {
|
||||||
|
getActionBar().setDisplayHomeAsUpEnabled(false);
|
||||||
|
addAccount();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -117,26 +125,35 @@ public class ManageAccountActivity extends XmppActivity {
|
||||||
startActivity(new Intent(this, SettingsActivity.class));
|
startActivity(new Intent(this, SettingsActivity.class));
|
||||||
break;
|
break;
|
||||||
case R.id.action_add_account:
|
case R.id.action_add_account:
|
||||||
EditAccount dialog = new EditAccount();
|
addAccount();
|
||||||
dialog.setEditAccountListener(new EditAccountListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAccountEdited(Account account) {
|
|
||||||
xmppConnectionService.createAccount(account);
|
|
||||||
accountList.add(account);
|
|
||||||
accountListViewAdapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAccountDelete(Account account) {
|
|
||||||
//this will never be called
|
|
||||||
}
|
|
||||||
});
|
|
||||||
dialog.show(getFragmentManager(),"add_account");
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void addAccount() {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialog.show(getFragmentManager(),"add_account");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,12 @@ import android.widget.EditText;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.CursorLoader;
|
import android.content.CursorLoader;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.DialogInterface.OnClickListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.Loader;
|
import android.content.Loader;
|
||||||
import android.content.Loader.OnLoadCompleteListener;
|
import android.content.Loader.OnLoadCompleteListener;
|
||||||
|
@ -152,35 +156,57 @@ public class NewConversationActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
contactsView.setAdapter(contactsAdapter);
|
contactsView.setAdapter(contactsAdapter);
|
||||||
|
final Activity activity = this;
|
||||||
contactsView.setOnItemClickListener(new OnItemClickListener() {
|
contactsView.setOnItemClickListener(new OnItemClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> arg0, View view, int pos,
|
public void onItemClick(AdapterView<?> arg0, final View view, int pos,
|
||||||
long arg3) {
|
long arg3) {
|
||||||
Contact clickedContact = aggregatedContacts.get(pos);
|
final Contact clickedContact = aggregatedContacts.get(pos);
|
||||||
Log.d("gultsch",
|
Log.d("gultsch",
|
||||||
"clicked on " + clickedContact.getDisplayName());
|
"clicked on " + clickedContact.getDisplayName());
|
||||||
|
|
||||||
Account account = new Account();
|
final List<Account> accounts = xmppConnectionService.getAccounts();
|
||||||
|
if (accounts.size() == 1) {
|
||||||
|
startConversation(clickedContact, accounts.get(0));
|
||||||
|
} else {
|
||||||
|
String[] accountList = new String[accounts.size()];
|
||||||
|
for(int i = 0; i < accounts.size(); ++i) {
|
||||||
|
accountList[i] = accounts.get(i).getJid();
|
||||||
|
}
|
||||||
|
|
||||||
Conversation conversation = xmppConnectionService
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||||
.findOrCreateConversation(account, clickedContact);
|
builder.setTitle("Choose account");
|
||||||
|
builder.setSingleChoiceItems(accountList,0,new OnClickListener() {
|
||||||
|
|
||||||
Intent viewConversationIntent = new Intent(view.getContext(),
|
@Override
|
||||||
ConversationActivity.class);
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
viewConversationIntent.setAction(Intent.ACTION_VIEW);
|
Account account = accounts.get(which);
|
||||||
viewConversationIntent.putExtra(
|
startConversation(clickedContact, account);
|
||||||
ConversationActivity.CONVERSATION,
|
}
|
||||||
conversation.getUuid());
|
});
|
||||||
viewConversationIntent
|
builder.create().show();
|
||||||
.setType(ConversationActivity.VIEW_CONVERSATION);
|
}
|
||||||
viewConversationIntent.setFlags(viewConversationIntent
|
|
||||||
.getFlags() | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
startActivity(viewConversationIntent);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void startConversation(Contact contact, Account account) {
|
||||||
|
Conversation conversation = xmppConnectionService
|
||||||
|
.findOrCreateConversation(account, contact);
|
||||||
|
|
||||||
|
Intent viewConversationIntent = new Intent(this,ConversationActivity.class);
|
||||||
|
viewConversationIntent.setAction(Intent.ACTION_VIEW);
|
||||||
|
viewConversationIntent.putExtra(
|
||||||
|
ConversationActivity.CONVERSATION,
|
||||||
|
conversation.getUuid());
|
||||||
|
viewConversationIntent
|
||||||
|
.setType(ConversationActivity.VIEW_CONVERSATION);
|
||||||
|
viewConversationIntent.setFlags(viewConversationIntent
|
||||||
|
.getFlags() | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
startActivity(viewConversationIntent);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
|
Loading…
Reference in a new issue