Commit a977f78f authored by Alexander Ivanov's avatar Alexander Ivanov

Use separate activity for MUC invite.

parent f05895d9
......@@ -173,6 +173,9 @@
<activity
android:name="com.xabber.android.ui.ContactSubscription"
/>
<activity
android:name="com.xabber.android.ui.MUCInvite"
/>
<activity
android:name="com.xabber.android.ui.CertificateConfirmation"
/>
......
......@@ -21,7 +21,7 @@ import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.notification.EntityNotificationItem;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.MUCEditor;
import com.xabber.android.ui.MUCInvite;
import com.xabber.androiddev.R;
/**
......@@ -57,8 +57,7 @@ public class RoomInvite extends BaseEntity implements EntityNotificationItem {
@Override
public Intent getIntent() {
return MUCEditor.createInviteIntent(Application.getInstance(), account,
user);
return MUCInvite.createIntent(Application.getInstance(), account, user);
}
@Override
......
......@@ -18,7 +18,6 @@ import java.util.Collection;
import org.jivesoftware.smack.util.StringUtils;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
......@@ -31,7 +30,6 @@ import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.extension.muc.RoomInvite;
......@@ -40,27 +38,15 @@ import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.notification.NotificationManager;
import com.xabber.android.ui.adapter.AccountChooseAdapter;
import com.xabber.android.ui.dialog.ConfirmDialogBuilder;
import com.xabber.android.ui.dialog.ConfirmDialogListener;
import com.xabber.android.ui.dialog.DialogBuilder;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
public class MUCEditor extends ManagedActivity implements View.OnClickListener,
OnItemSelectedListener, ConfirmDialogListener {
/**
* Action for MUC invitation to be show.
*
* Clear action on dialog dismiss.
*/
private static final String ACTION_MUC_INVITE = "com.xabber.android.data.MUC_INVITE";
OnItemSelectedListener {
private static final String SAVED_ACCOUNT = "com.xabber.android.ui.MUCEditor.SAVED_ACCOUNT";
private static final String SAVED_ROOM = "com.xabber.android.ui.MUCEditor.SAVED_ROOM";
private static final int DIALOG_MUC_INVITE_ID = 100;
private String account;
private String room;
......@@ -69,11 +55,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
*/
private int selectedAccount;
/**
* Invite intent.
*/
private RoomInvite roomInvite;
/**
* Views.
*/
......@@ -117,8 +98,15 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
.removeAuthorizationError(account, room);
nickView.setText(MUCManager.getInstance().getNickname(account,
room));
passwordView.setText(MUCManager.getInstance().getPassword(
account, room));
String password;
RoomInvite roomInvite = MUCManager.getInstance().getInvite(
account, room);
if (roomInvite != null)
password = roomInvite.getPassword();
else
password = MUCManager.getInstance().getPassword(account,
room);
passwordView.setText(password);
}
}
if (account == null) {
......@@ -137,17 +125,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
if ("".equals(nickView.getText().toString()))
nickView.setText(getNickname(((String) accountView
.getSelectedItem())));
if (ACTION_MUC_INVITE.equals(intent.getAction())) {
roomInvite = MUCManager.getInstance().getInvite(account, room);
if (roomInvite == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
finish();
return;
}
passwordView.setText(roomInvite.getPassword());
} else {
roomInvite = null;
}
}
@Override
......@@ -162,8 +139,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
protected void onResume() {
super.onResume();
selectedAccount = accountView.getSelectedItemPosition();
if (roomInvite != null)
showDialog(DIALOG_MUC_INVITE_ID);
}
@Override
......@@ -199,14 +174,15 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
room = room + "@" + server;
if (this.account != null && this.room != null)
if (!account.equals(this.account) || !room.equals(this.room)) {
MUCManager.getInstance().removeRoom(this.account, this.room);
MUCManager.getInstance()
.removeRoom(this.account, this.room);
MessageManager.getInstance().closeChat(this.account,
this.room);
NotificationManager.getInstance()
.removeMessageNotification(this.account, this.room);
}
MUCManager.getInstance()
.createRoom(account, room, nick, password, join);
MUCManager.getInstance().createRoom(account, room, nick, password,
join);
finish();
break;
default:
......@@ -229,18 +205,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
return name;
}
@Override
protected Dialog onCreateDialog(int id) {
super.onCreateDialog(id);
switch (id) {
case DIALOG_MUC_INVITE_ID:
return new ConfirmDialogBuilder(this, DIALOG_MUC_INVITE_ID, this)
.setMessage(roomInvite.getConfirmation()).create();
default:
return null;
}
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
......@@ -261,37 +225,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
selectedAccount = accountView.getSelectedItemPosition();
}
@Override
public void onAccept(DialogBuilder dialogBuilder) {
switch (dialogBuilder.getDialogId()) {
case DIALOG_MUC_INVITE_ID:
MUCManager.getInstance().removeInvite(roomInvite);
getIntent().setAction(null);
account = null;
room = null;
break;
}
}
@Override
public void onDecline(DialogBuilder dialogBuilder) {
switch (dialogBuilder.getDialogId()) {
case DIALOG_MUC_INVITE_ID:
MUCManager.getInstance().removeInvite(roomInvite);
finish();
break;
}
}
@Override
public void onCancel(DialogBuilder dialogBuilder) {
switch (dialogBuilder.getDialogId()) {
case DIALOG_MUC_INVITE_ID:
finish();
break;
}
}
public static Intent createIntent(Context context) {
return MUCEditor.createIntent(context, null, null);
}
......@@ -302,13 +235,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
.setAccount(account).setUser(room).build();
}
public static Intent createInviteIntent(Context context, String account,
String user) {
Intent intent = createIntent(context, account, user);
intent.setAction(ACTION_MUC_INVITE);
return intent;
}
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
......
/**
* 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;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import com.xabber.android.data.Application;
import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.extension.muc.RoomInvite;
import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.ui.helper.ManagedDialog;
import com.xabber.androiddev.R;
public class MUCInvite extends ManagedDialog {
private String account;
private String room;
private RoomInvite roomInvite;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
account = getAccount(intent);
room = getUser(intent);
roomInvite = MUCManager.getInstance().getInvite(account, room);
if (roomInvite == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
finish();
return;
}
setDialogMessage(roomInvite.getConfirmation());
setDialogTitle(R.string.subscription_request_message);
findViewById(android.R.id.button3).setVisibility(View.GONE);
}
@Override
public void onAccept() {
super.onAccept();
startActivity(MUCEditor.createIntent(this, account, room));
finish();
}
@Override
public void onDecline() {
super.onDecline();
MUCManager.getInstance().removeInvite(roomInvite);
finish();
}
public static Intent createIntent(Context context, String account,
String room) {
return new EntityIntentBuilder(context, MUCInvite.class)
.setAccount(account).setUser(room).build();
}
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
}
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