Commit f05895d9 authored by Alexander Ivanov's avatar Alexander Ivanov

Use separate activity for subscription request.

parent 52d0e56d
......@@ -170,6 +170,9 @@
android:name="com.xabber.android.ui.OpenSourceViewer"
android:theme="@style/Theme.NoTitleBar"
/>
<activity
android:name="com.xabber.android.ui.ContactSubscription"
/>
<activity
android:name="com.xabber.android.ui.CertificateConfirmation"
/>
......
......@@ -20,7 +20,7 @@ import com.xabber.android.data.Application;
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.ui.ContactAdd;
import com.xabber.android.ui.ContactSubscription;
import com.xabber.androiddev.R;
public class SubscriptionRequest extends BaseEntity implements
......@@ -32,7 +32,7 @@ public class SubscriptionRequest extends BaseEntity implements
@Override
public Intent getIntent() {
return ContactAdd.createSubscriptionIntent(Application.getInstance(),
return ContactSubscription.createIntent(Application.getInstance(),
account, user);
}
......
......@@ -18,7 +18,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
......@@ -39,34 +38,19 @@ import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.data.roster.SubscriptionRequest;
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.androiddev.R;
public class ContactAdd extends GroupListActivity implements
View.OnClickListener, ConfirmDialogListener, OnItemSelectedListener {
/**
* Action for subscription request to be show.
*
* Clear action on dialog dismiss.
*/
private static final String ACTION_SUBSCRIPTION_REQUEST = "com.xabber.android.data.SUBSCRIPTION_REQUEST";
View.OnClickListener, OnItemSelectedListener {
private static final String SAVED_ACCOUNT = "com.xabber.android.ui.ContactAdd.SAVED_ACCOUNT";
private static final String SAVED_USER = "com.xabber.android.ui.ContactAdd.SAVED_USER";
private static final String SAVED_NAME = "com.xabber.android.ui.ContactAdd.SAVED_NAME";
private static final int DIALOG_SUBSCRIPTION_REQUEST_ID = 0x20;
private String account;
private String user;
private SubscriptionRequest subscriptionRequest;
/**
* Views
*/
......@@ -125,17 +109,6 @@ public class ContactAdd extends GroupListActivity implements
userView.setText(user);
if (name != null)
nameView.setText(name);
if (ACTION_SUBSCRIPTION_REQUEST.equals(intent.getAction())) {
subscriptionRequest = PresenceManager.getInstance()
.getSubscriptionRequest(account, user);
if (subscriptionRequest == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
finish();
return;
}
} else {
subscriptionRequest = null;
}
}
@Override
......@@ -147,13 +120,6 @@ public class ContactAdd extends GroupListActivity implements
outState.putString(SAVED_NAME, nameView.getText().toString());
}
@Override
protected void onResume() {
super.onResume();
if (subscriptionRequest != null)
showDialog(DIALOG_SUBSCRIPTION_REQUEST_ID);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
......@@ -188,62 +154,6 @@ public class ContactAdd extends GroupListActivity implements
}
}
@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = super.onCreateDialog(id);
if (dialog != null)
return dialog;
switch (id) {
case DIALOG_SUBSCRIPTION_REQUEST_ID:
return new ConfirmDialogBuilder(this,
DIALOG_SUBSCRIPTION_REQUEST_ID, this).setMessage(
subscriptionRequest.getConfirmation()).create();
default:
return null;
}
}
@Override
public void onAccept(DialogBuilder dialogBuilder) {
switch (dialogBuilder.getDialogId()) {
case DIALOG_SUBSCRIPTION_REQUEST_ID:
try {
PresenceManager.getInstance().acceptSubscription(
subscriptionRequest.getAccount(),
subscriptionRequest.getUser());
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
getIntent().setAction(null);
break;
}
}
@Override
public void onDecline(DialogBuilder dialogBuilder) {
switch (dialogBuilder.getDialogId()) {
case DIALOG_SUBSCRIPTION_REQUEST_ID:
try {
PresenceManager.getInstance().discardSubscription(
subscriptionRequest.getAccount(),
subscriptionRequest.getUser());
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
finish();
break;
}
}
@Override
public void onCancel(DialogBuilder dialogBuilder) {
switch (dialogBuilder.getDialogId()) {
case DIALOG_SUBSCRIPTION_REQUEST_ID:
finish();
break;
}
}
@Override
Collection<String> getInitialGroups() {
String account = (String) accountView.getSelectedItem();
......@@ -280,21 +190,14 @@ public class ContactAdd extends GroupListActivity implements
return createIntent(context, null);
}
private static Intent createIntent(Context context, String account,
String user) {
return new EntityIntentBuilder(context, ContactAdd.class)
.setAccount(account).setUser(user).build();
}
public static Intent createIntent(Context context, String account) {
return createIntent(context, account, null);
}
public static Intent createSubscriptionIntent(Context context,
String account, String user) {
Intent intent = createIntent(context, account, user);
intent.setAction(ACTION_SUBSCRIPTION_REQUEST);
return intent;
public static Intent createIntent(Context context, String account,
String user) {
return new EntityIntentBuilder(context, ContactAdd.class)
.setAccount(account).setUser(user).build();
}
private static String getAccount(Intent 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.NetworkException;
import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.SubscriptionRequest;
import com.xabber.android.ui.helper.ManagedDialog;
import com.xabber.androiddev.R;
public class ContactSubscription extends ManagedDialog {
private String account;
private String user;
private SubscriptionRequest subscriptionRequest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
account = getAccount(intent);
user = getUser(intent);
subscriptionRequest = PresenceManager.getInstance()
.getSubscriptionRequest(account, user);
if (subscriptionRequest == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
finish();
return;
}
setDialogMessage(subscriptionRequest.getConfirmation());
setDialogTitle(R.string.subscription_request_message);
findViewById(android.R.id.button3).setVisibility(View.GONE);
}
@Override
public void onAccept() {
super.onAccept();
try {
PresenceManager.getInstance().acceptSubscription(
subscriptionRequest.getAccount(),
subscriptionRequest.getUser());
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
startActivity(ContactAdd.createIntent(this, account, user));
finish();
}
@Override
public void onDecline() {
super.onDecline();
try {
PresenceManager.getInstance().discardSubscription(
subscriptionRequest.getAccount(),
subscriptionRequest.getUser());
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
finish();
}
public static Intent createIntent(Context context, String account,
String user) {
return new EntityIntentBuilder(context, ContactSubscription.class)
.setAccount(account).setUser(user).build();
}
private static String getAccount(Intent intent) {
return EntityIntentBuilder.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