Commit e7ed2237 authored by Alexander Ivanov's avatar Alexander Ivanov

Use dialog fragment in account chooser for send-to feature.

parent 2f5263cb
...@@ -79,7 +79,8 @@ import com.xabber.android.ui.adapter.AccountConfiguration; ...@@ -79,7 +79,8 @@ import com.xabber.android.ui.adapter.AccountConfiguration;
import com.xabber.android.ui.adapter.AccountToggleAdapter; import com.xabber.android.ui.adapter.AccountToggleAdapter;
import com.xabber.android.ui.adapter.ContactListAdapter; import com.xabber.android.ui.adapter.ContactListAdapter;
import com.xabber.android.ui.adapter.GroupConfiguration; import com.xabber.android.ui.adapter.GroupConfiguration;
import com.xabber.android.ui.dialog.AccountChooseDialogBuilder; import com.xabber.android.ui.dialog.AccountChooseDialogFragment;
import com.xabber.android.ui.dialog.AccountChooseDialogFragment.OnChoosedListener;
import com.xabber.android.ui.dialog.ConfirmDialogListener; import com.xabber.android.ui.dialog.ConfirmDialogListener;
import com.xabber.android.ui.dialog.ContactDeleteDialogFragment; import com.xabber.android.ui.dialog.ContactDeleteDialogFragment;
import com.xabber.android.ui.dialog.ContactIntegrationDialogFragment; import com.xabber.android.ui.dialog.ContactIntegrationDialogFragment;
...@@ -101,7 +102,7 @@ import com.xabber.xmpp.uri.XMPPUri; ...@@ -101,7 +102,7 @@ import com.xabber.xmpp.uri.XMPPUri;
public class ContactList extends ManagedListActivity implements public class ContactList extends ManagedListActivity implements
OnContactChangedListener, OnAccountChangedListener, OnContactChangedListener, OnAccountChangedListener,
OnChatChangedListener, View.OnClickListener, ConfirmDialogListener, OnChatChangedListener, View.OnClickListener, ConfirmDialogListener,
OnItemClickListener, OnLongClickListener { OnItemClickListener, OnLongClickListener, OnChoosedListener {
/** /**
* Select contact to be invited to the room was requested. * Select contact to be invited to the room was requested.
...@@ -115,8 +116,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -115,8 +116,6 @@ public class ContactList extends ManagedListActivity implements
private static final String SAVED_ACTION_WITH_GROUP = "com.xabber.android.ui.ContactList.SAVED_ACTION_WITH_GROUP"; private static final String SAVED_ACTION_WITH_GROUP = "com.xabber.android.ui.ContactList.SAVED_ACTION_WITH_GROUP";
private static final String SAVED_ACTION_WITH_USER = "com.xabber.android.ui.ContactList.SAVED_ACTION_WITH_USER"; private static final String SAVED_ACTION_WITH_USER = "com.xabber.android.ui.ContactList.SAVED_ACTION_WITH_USER";
private static final String SAVED_SEND_TEXT = "com.xabber.android.ui.ContactList.SAVED_SEND_TEXT"; private static final String SAVED_SEND_TEXT = "com.xabber.android.ui.ContactList.SAVED_SEND_TEXT";
private static final String SAVED_OPEN_DIALOG_USER = "com.xabber.android.ui.ContactList.SAVED_OPEN_DIALOG_USER";
private static final String SAVED_OPEN_DIALOG_TEXT = "com.xabber.android.ui.ContactList.SAVED_OPEN_DIALOG_TEXT";
private static final int OPTION_MENU_ADD_CONTACT_ID = 0x02; private static final int OPTION_MENU_ADD_CONTACT_ID = 0x02;
private static final int OPTION_MENU_STATUS_EDITOR_ID = 0x04; private static final int OPTION_MENU_STATUS_EDITOR_ID = 0x04;
...@@ -153,7 +152,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -153,7 +152,6 @@ public class ContactList extends ManagedListActivity implements
private static final int CONTEXT_MENU_SHOW_OFFLINE_NORMAL_ID = 0x42; private static final int CONTEXT_MENU_SHOW_OFFLINE_NORMAL_ID = 0x42;
private static final int CONTEXT_MENU_SHOW_OFFLINE_NEVER_ID = 0x43; private static final int CONTEXT_MENU_SHOW_OFFLINE_NEVER_ID = 0x43;
private static final int DIALOG_OPEN_WITH_ACCOUNT_ID = 0x55;
private static final int DIALOG_CLOSE_APPLICATION_ID = 0x57; private static final int DIALOG_CLOSE_APPLICATION_ID = 0x57;
/** /**
...@@ -178,8 +176,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -178,8 +176,6 @@ public class ContactList extends ManagedListActivity implements
private String actionWithGroup; private String actionWithGroup;
private String actionWithUser; private String actionWithUser;
private String sendText; private String sendText;
private String openDialogUser;
private String openDialogText;
/** /**
* Title view. * Title view.
...@@ -240,18 +236,12 @@ public class ContactList extends ManagedListActivity implements ...@@ -240,18 +236,12 @@ public class ContactList extends ManagedListActivity implements
actionWithUser = savedInstanceState actionWithUser = savedInstanceState
.getString(SAVED_ACTION_WITH_USER); .getString(SAVED_ACTION_WITH_USER);
sendText = savedInstanceState.getString(SAVED_SEND_TEXT); sendText = savedInstanceState.getString(SAVED_SEND_TEXT);
openDialogUser = savedInstanceState
.getString(SAVED_OPEN_DIALOG_USER);
openDialogText = savedInstanceState
.getString(SAVED_OPEN_DIALOG_TEXT);
action = savedInstanceState.getString(SAVED_ACTION); action = savedInstanceState.getString(SAVED_ACTION);
} else { } else {
actionWithAccount = null; actionWithAccount = null;
actionWithGroup = null; actionWithGroup = null;
actionWithUser = null; actionWithUser = null;
sendText = null; sendText = null;
openDialogUser = null;
openDialogText = null;
action = getIntent().getAction(); action = getIntent().getAction();
} }
getIntent().setAction(null); getIntent().setAction(null);
...@@ -273,8 +263,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -273,8 +263,6 @@ public class ContactList extends ManagedListActivity implements
outState.putString(SAVED_ACTION_WITH_GROUP, actionWithGroup); outState.putString(SAVED_ACTION_WITH_GROUP, actionWithGroup);
outState.putString(SAVED_ACTION_WITH_USER, actionWithUser); outState.putString(SAVED_ACTION_WITH_USER, actionWithUser);
outState.putString(SAVED_SEND_TEXT, sendText); outState.putString(SAVED_SEND_TEXT, sendText);
outState.putString(SAVED_OPEN_DIALOG_USER, openDialogUser);
outState.putString(SAVED_OPEN_DIALOG_TEXT, openDialogText);
} }
/** /**
...@@ -313,9 +301,8 @@ public class ContactList extends ManagedListActivity implements ...@@ -313,9 +301,8 @@ public class ContactList extends ManagedListActivity implements
text); text);
return; return;
} }
openDialogUser = bareAddress; AccountChooseDialogFragment.newInstance(bareAddress, text).show(
openDialogText = text; getSupportFragmentManager(), "OPEN_WITH_ACCOUNT");
showDialog(DIALOG_OPEN_WITH_ACCOUNT_ID);
} }
/** /**
...@@ -783,9 +770,6 @@ public class ContactList extends ManagedListActivity implements ...@@ -783,9 +770,6 @@ public class ContactList extends ManagedListActivity implements
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
super.onCreateDialog(id); super.onCreateDialog(id);
switch (id) { switch (id) {
case DIALOG_OPEN_WITH_ACCOUNT_ID:
return new AccountChooseDialogBuilder(this,
DIALOG_OPEN_WITH_ACCOUNT_ID, this, openDialogUser).create();
case DIALOG_CLOSE_APPLICATION_ID: case DIALOG_CLOSE_APPLICATION_ID:
ProgressDialog progressDialog = new ProgressDialog(this); ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog progressDialog
...@@ -997,15 +981,12 @@ public class ContactList extends ManagedListActivity implements ...@@ -997,15 +981,12 @@ public class ContactList extends ManagedListActivity implements
} }
@Override @Override
public void onAccept(DialogBuilder dialogBuilder) { public void onChoosed(String account, String user, String text) {
switch (dialogBuilder.getDialogId()) { openChat(new BaseEntity(account, user), text);
case DIALOG_OPEN_WITH_ACCOUNT_ID:
BaseEntity baseEntity = new BaseEntity(
((AccountChooseDialogBuilder) dialogBuilder).getSelected(),
openDialogUser);
openChat(baseEntity, openDialogText);
break;
} }
@Override
public void onAccept(DialogBuilder dialogBuilder) {
} }
@Override @Override
......
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui.dialog; package com.xabber.android.ui.dialog;
import java.util.ArrayList; import java.util.ArrayList;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.support.v4.app.DialogFragment;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -26,34 +14,39 @@ import com.xabber.android.data.roster.RosterContact; ...@@ -26,34 +14,39 @@ import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.adapter.AccountChooseAdapter; import com.xabber.android.ui.adapter.AccountChooseAdapter;
public class AccountChooseDialogBuilder extends ListenableDialogBuilder { public class AccountChooseDialogFragment extends AbstractDialogFragment {
private static final String USER = "USER";
private static final String TEXT = "TEXT";
/**
* @param user
* @param text
* @return
*/
public static DialogFragment newInstance(String user, String text) {
return new AccountChooseDialogFragment().putAgrument(USER, user)
.putAgrument(TEXT, text);
}
private final String user; private String user;
private String selected; private String text;
public AccountChooseDialogBuilder(Activity activity, int dialogId, @Override
final ConfirmDialogListener listener, String user) { protected Builder getBuilder() {
super(activity, dialogId); user = getArguments().getString(USER);
this.user = user; text = getArguments().getString(TEXT);
this.selected = null; final Adapter adapter = new Adapter(getActivity());
setOnCancelListener(listener); Builder builder = new Builder(getActivity());
setOnDeclineListener(listener); builder.setSingleChoiceItems(adapter, -1, new OnClickListener() {
final Adapter adapter = new Adapter(activity);
setSingleChoiceItems(adapter, -1, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
selected = (String) adapter.getItem(which); String account = (String) adapter.getItem(which);
dialog.dismiss(); OnChoosedListener listener = (OnChoosedListener) getActivity();
listener.onAccept(AccountChooseDialogBuilder.this); listener.onChoosed(account, user, text);
} }
}); });
} return builder;
/**
* @return <code>null</code> can be returned.
*/
public String getSelected() {
return selected;
} }
private class Adapter extends AccountChooseAdapter { private class Adapter extends AccountChooseAdapter {
...@@ -78,4 +71,10 @@ public class AccountChooseDialogBuilder extends ListenableDialogBuilder { ...@@ -78,4 +71,10 @@ public class AccountChooseDialogBuilder extends ListenableDialogBuilder {
} }
public interface OnChoosedListener {
void onChoosed(String account, String user, String text);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment