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;
import com.xabber.android.ui.adapter.AccountToggleAdapter;
import com.xabber.android.ui.adapter.ContactListAdapter;
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.ContactDeleteDialogFragment;
import com.xabber.android.ui.dialog.ContactIntegrationDialogFragment;
......@@ -101,7 +102,7 @@ import com.xabber.xmpp.uri.XMPPUri;
public class ContactList extends ManagedListActivity implements
OnContactChangedListener, OnAccountChangedListener,
OnChatChangedListener, View.OnClickListener, ConfirmDialogListener,
OnItemClickListener, OnLongClickListener {
OnItemClickListener, OnLongClickListener, OnChoosedListener {
/**
* Select contact to be invited to the room was requested.
......@@ -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_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_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_STATUS_EDITOR_ID = 0x04;
......@@ -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_NEVER_ID = 0x43;
private static final int DIALOG_OPEN_WITH_ACCOUNT_ID = 0x55;
private static final int DIALOG_CLOSE_APPLICATION_ID = 0x57;
/**
......@@ -178,8 +176,6 @@ public class ContactList extends ManagedListActivity implements
private String actionWithGroup;
private String actionWithUser;
private String sendText;
private String openDialogUser;
private String openDialogText;
/**
* Title view.
......@@ -240,18 +236,12 @@ public class ContactList extends ManagedListActivity implements
actionWithUser = savedInstanceState
.getString(SAVED_ACTION_WITH_USER);
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);
} else {
actionWithAccount = null;
actionWithGroup = null;
actionWithUser = null;
sendText = null;
openDialogUser = null;
openDialogText = null;
action = getIntent().getAction();
}
getIntent().setAction(null);
......@@ -273,8 +263,6 @@ public class ContactList extends ManagedListActivity implements
outState.putString(SAVED_ACTION_WITH_GROUP, actionWithGroup);
outState.putString(SAVED_ACTION_WITH_USER, actionWithUser);
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
text);
return;
}
openDialogUser = bareAddress;
openDialogText = text;
showDialog(DIALOG_OPEN_WITH_ACCOUNT_ID);
AccountChooseDialogFragment.newInstance(bareAddress, text).show(
getSupportFragmentManager(), "OPEN_WITH_ACCOUNT");
}
/**
......@@ -783,9 +770,6 @@ public class ContactList extends ManagedListActivity implements
protected Dialog onCreateDialog(int id) {
super.onCreateDialog(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:
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog
......@@ -997,15 +981,12 @@ public class ContactList extends ManagedListActivity implements
}
@Override
public void onAccept(DialogBuilder dialogBuilder) {
switch (dialogBuilder.getDialogId()) {
case DIALOG_OPEN_WITH_ACCOUNT_ID:
BaseEntity baseEntity = new BaseEntity(
((AccountChooseDialogBuilder) dialogBuilder).getSelected(),
openDialogUser);
openChat(baseEntity, openDialogText);
break;
public void onChoosed(String account, String user, String text) {
openChat(new BaseEntity(account, user), text);
}
@Override
public void onAccept(DialogBuilder dialogBuilder) {
}
@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;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.view.ViewGroup;
......@@ -26,34 +14,39 @@ import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager;
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 selected;
private String user;
private String text;
public AccountChooseDialogBuilder(Activity activity, int dialogId,
final ConfirmDialogListener listener, String user) {
super(activity, dialogId);
this.user = user;
this.selected = null;
setOnCancelListener(listener);
setOnDeclineListener(listener);
final Adapter adapter = new Adapter(activity);
setSingleChoiceItems(adapter, -1, new OnClickListener() {
@Override
protected Builder getBuilder() {
user = getArguments().getString(USER);
text = getArguments().getString(TEXT);
final Adapter adapter = new Adapter(getActivity());
Builder builder = new Builder(getActivity());
builder.setSingleChoiceItems(adapter, -1, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
selected = (String) adapter.getItem(which);
dialog.dismiss();
listener.onAccept(AccountChooseDialogBuilder.this);
String account = (String) adapter.getItem(which);
OnChoosedListener listener = (OnChoosedListener) getActivity();
listener.onChoosed(account, user, text);
}
});
}
/**
* @return <code>null</code> can be returned.
*/
public String getSelected() {
return selected;
return builder;
}
private class Adapter extends AccountChooseAdapter {
......@@ -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