Commit f2119c6e authored by Grigory Fedorov's avatar Grigory Fedorov

Code from next gen branch overadded.

parent 5d6ce742
......@@ -29,7 +29,6 @@ import java.util.concurrent.ThreadFactory;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.Handler;
import com.xabber.android.service.XabberService;
......@@ -42,8 +41,6 @@ import com.xabber.androiddev.R;
*/
public class Application extends android.app.Application {
public static final int SDK_INT = Integer.valueOf(Build.VERSION.SDK);
private static Application instance;
public static Application getInstance() {
......@@ -254,8 +251,7 @@ public class Application extends android.app.Application {
* @return
*/
public boolean isContactsSupported() {
return SDK_INT >= 5
&& checkCallingOrSelfPermission("android.permission.READ_CONTACTS") == PackageManager.PERMISSION_GRANTED;
return checkCallingOrSelfPermission("android.permission.READ_CONTACTS") == PackageManager.PERMISSION_GRANTED;
}
@Override
......
......@@ -16,15 +16,11 @@ package com.xabber.android.data;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.jivesoftware.smack.Connection;
import org.xbill.DNS.Options;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;
/**
......@@ -37,54 +33,12 @@ public class LogManager implements OnLoadListener {
private static final boolean log;
private static final boolean debugable;
private static Method _getApplicationInfo;
static {
initCompatibility();
debugable = (getApplicationInfo(Application.getInstance()).flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
debugable = (Application.getInstance().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
log = debugable && SettingsManager.debugLog();
};
private static void initCompatibility() {
try {
_getApplicationInfo = Context.class.getMethod("getApplicationInfo",
new Class[] {});
} catch (NoSuchMethodException nsme) {
}
}
public static ApplicationInfo getApplicationInfo(Context context) {
ApplicationInfo applicationInfo;
if (_getApplicationInfo != null) {
try {
applicationInfo = (ApplicationInfo) _getApplicationInfo
.invoke(context);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else if (cause instanceof Error) {
throw (Error) cause;
} else {
throw new RuntimeException(e);
}
} catch (IllegalAccessException ie) {
throw new RuntimeException(ie);
}
} else {
try {
applicationInfo = context.getPackageManager()
.getApplicationInfo(context.getPackageName(), 0);
} catch (NameNotFoundException e) {
Log.e("LogManager",
"I can`t find my package in the system. Debug will be disabled.");
applicationInfo = new ApplicationInfo();
applicationInfo.flags = 0;
}
}
return applicationInfo;
}
private final static LogManager instance;
static {
......
......@@ -27,6 +27,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import com.xabber.android.data.Application;
import com.xabber.android.data.OnLoadListener;
......@@ -479,9 +480,9 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener,
}
private int getLauncherLargeIconSize() {
if (Application.SDK_INT < 9)
if (Build.VERSION.SDK_INT < 9)
return BaseShortcutHelper.getLauncherLargeIconSize();
else if (Application.SDK_INT < 11)
else if (Build.VERSION.SDK_INT < 11)
return GingerbreadShortcutHelper.getLauncherLargeIconSize();
else
return HoneycombShortcutHelper.getLauncherLargeIconSize();
......
......@@ -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
......
......@@ -27,6 +27,7 @@ import android.content.Intent;
import android.database.Cursor;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Vibrator;
import android.widget.RemoteViews;
......
......@@ -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);
}
......
......@@ -14,10 +14,6 @@
*/
package com.xabber.android.service;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.app.Notification;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
......@@ -36,9 +32,6 @@ import com.xabber.android.data.notification.NotificationManager;
*/
public class XabberService extends Service {
private Method startForeground;
private Method stopForeground;
private static XabberService instance;
public static XabberService getInstance() {
......@@ -50,27 +43,17 @@ public class XabberService extends Service {
super.onCreate();
instance = this;
LogManager.i(this, "onCreate");
// Try to get methods supported in API Level 5+
try {
startForeground = getClass().getMethod("startForeground",
new Class[] { int.class, Notification.class });
stopForeground = getClass().getMethod("stopForeground",
new Class[] { boolean.class });
} catch (NoSuchMethodException e) {
startForeground = stopForeground = null;
}
changeForeground();
}
public void changeForeground() {
if (SettingsManager.eventsPersistent()
&& Application.getInstance().isInitialized())
startForegroundWrapper(NotificationManager.getInstance()
startForeground(NotificationManager.PERSISTENT_NOTIFICATION_ID,
NotificationManager.getInstance()
.getPersistentNotification());
else
stopForegroundWrapper();
stopForeground(true);
}
@Override
......@@ -83,7 +66,7 @@ public class XabberService extends Service {
public void onDestroy() {
super.onDestroy();
LogManager.i(this, "onDestroy");
stopForegroundWrapper();
stopForeground(true);
Application.getInstance().onServiceDestroy();
}
......@@ -92,56 +75,6 @@ public class XabberService extends Service {
return null;
}
/**
* This is a wrapper around the new startForeground method, using the older
* APIs if it is not available.
*/
void startForegroundWrapper(Notification notification) {
if (startForeground != null) {
Object[] startForegroundArgs = new Object[] {
Integer.valueOf(NotificationManager.PERSISTENT_NOTIFICATION_ID),
notification };
try {
startForeground.invoke(this, startForegroundArgs);
} catch (InvocationTargetException e) {
// Should not happen.
LogManager.w(this, "Unable to invoke startForeground" + e);
} catch (IllegalAccessException e) {
// Should not happen.
LogManager.w(this, "Unable to invoke startForeground" + e);
}
} else {
setForeground(true);
try {
((android.app.NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE))
.notify(NotificationManager.PERSISTENT_NOTIFICATION_ID,
notification);
} catch (SecurityException e) {
}
}
}
/**
* This is a wrapper around the new stopForeground method, using the older
* APIs if it is not available.
*/
void stopForegroundWrapper() {
if (stopForeground != null) {
try {
stopForeground.invoke(this, new Object[] { Boolean.TRUE });
// We don't want to clear notification bar.
} catch (InvocationTargetException e) {
// Should not happen.
LogManager.w(this, "Unable to invoke stopForeground" + e);
} catch (IllegalAccessException e) {
// Should not happen.
LogManager.w(this, "Unable to invoke stopForeground" + e);
}
} else {
setForeground(false);
}
}
public static Intent createIntent(Context context) {
return new Intent(context, XabberService.class);
}
......
......@@ -28,7 +28,6 @@ import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.ui.adapter.AccountListAdapter;
import com.xabber.android.ui.adapter.BaseListEditorAdapter;
import com.xabber.android.ui.adapter.UpdatableAdapter;
import com.xabber.android.ui.helper.BaseListEditor;
import com.xabber.androiddev.R;
......@@ -119,7 +118,7 @@ public class AccountList extends BaseListEditor<String> implements
@Override
public void onAccountsChanged(Collection<String> accounts) {
((UpdatableAdapter) getListAdapter()).onChange();
adapter.onChange();
}
@Override
......
......@@ -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,65 +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) {
super.onAccept(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) {
super.onDecline(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) {
super.onCancel(dialogBuilder);
switch (dialogBuilder.getDialogId()) {
case DIALOG_SUBSCRIPTION_REQUEST_ID:
finish();
break;
}
}
@Override
Collection<String> getInitialGroups() {
String account = (String) accountView.getSelectedItem();
......@@ -283,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);
}
}
......@@ -18,7 +18,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
......@@ -30,9 +29,8 @@ import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.xabber.android.ui.dialog.ConfirmDialogListener;
import com.xabber.android.ui.dialog.DialogBuilder;
import com.xabber.android.ui.dialog.GroupAddDialogBuilder;
import com.xabber.android.ui.dialog.GroupAddDialogFragment;
import com.xabber.android.ui.dialog.GroupAddDialogFragment.OnGroupAddConfirmed;
import com.xabber.android.ui.helper.ManagedListActivity;
import com.xabber.androiddev.R;
......@@ -43,15 +41,13 @@ import com.xabber.androiddev.R;
*
*/
public abstract class GroupListActivity extends ManagedListActivity implements
ConfirmDialogListener, OnItemClickListener {
OnItemClickListener, OnGroupAddConfirmed {
private static final String SAVED_GROUPS = "com.xabber.android.ui.ContactList.SAVED_GROUPS";
private static final String SAVED_SELECTED = "com.xabber.android.ui.ContactList.SAVED_SELECTED";
static final int OPTION_MENU_ADD_GROUP_ID = 1;
static final int DIALOG_ADD_GROUP_ID = 0x10;
private ArrayAdapter<String> arrayAdapter;
private ListView listView;
......@@ -148,29 +144,22 @@ public abstract class GroupListActivity extends ManagedListActivity implements
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case OPTION_MENU_ADD_GROUP_ID:
showDialog(DIALOG_ADD_GROUP_ID);
showGroupAddDialog();
return true;
}
return false;
}
@Override
protected Dialog onCreateDialog(int id) {
super.onCreateDialog(id);
switch (id) {
case DIALOG_ADD_GROUP_ID:
return new GroupAddDialogBuilder(this, DIALOG_ADD_GROUP_ID, this,
getGroups()).create();
default:
return null;
}
private void showGroupAddDialog() {
GroupAddDialogFragment.newInstance(getGroups()).show(
getSupportFragmentManager(), "GROUP-ADD");
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
if (listView.getItemAtPosition(position) == null) // Footer
showDialog(DIALOG_ADD_GROUP_ID);
showGroupAddDialog();
}
/**
......@@ -192,24 +181,12 @@ public abstract class GroupListActivity extends ManagedListActivity implements
}
@Override
public void onAccept(DialogBuilder dialog) {
switch (dialog.getDialogId()) {
case DIALOG_ADD_GROUP_ID:
String group = ((GroupAddDialogBuilder) dialog).getName();
public void onGroupAddConfirmed(String group) {
ArrayList<String> groups = getGroups();
groups.add(group);
ArrayList<String> selected = getSelected();
selected.add(group);
setGroups(groups, selected);
}
}
@Override
public void onDecline(DialogBuilder dialog) {
}
@Override
public void onCancel(DialogBuilder dialog) {
}
}
......@@ -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);
}
}
......@@ -40,7 +40,6 @@ import com.xabber.android.data.account.StatusMode;
import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.ui.adapter.StatusEditorAdapter;
import com.xabber.android.ui.adapter.StatusModeAdapter;
import com.xabber.android.ui.adapter.UpdatableAdapter;
import com.xabber.android.ui.helper.ManagedListActivity;
import com.xabber.androiddev.R;
......@@ -61,6 +60,7 @@ public class StatusEditor extends ManagedListActivity implements
private EditText statusTextView;
private SavedStatus actionWithItem;
private StatusEditorAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -87,7 +87,8 @@ public class StatusEditor extends ManagedListActivity implements
listView.addHeaderView(header, null, false);
listView.setOnItemClickListener(this);
registerForContextMenu(listView);
setListAdapter(new StatusEditorAdapter(this));
adapter = new StatusEditorAdapter(this);
setListAdapter(adapter);
statusTextView = (EditText) header.findViewById(R.id.status_text);
statusModeView = (Spinner) header.findViewById(R.id.status_mode);
......@@ -146,7 +147,7 @@ public class StatusEditor extends ManagedListActivity implements
@Override
protected void onResume() {
super.onResume();
((UpdatableAdapter) getListAdapter()).onChange();
adapter.onChange();
}
@Override
......@@ -164,7 +165,7 @@ public class StatusEditor extends ManagedListActivity implements
switch (item.getItemId()) {
case OPTION_MENU_CLEAR_STATUSES_ID:
AccountManager.getInstance().clearSavedStatuses();
((UpdatableAdapter) getListAdapter()).onChange();
adapter.onChange();
return true;
}
return false;
......@@ -202,7 +203,7 @@ public class StatusEditor extends ManagedListActivity implements
return true;
case CONTEXT_MENU_REMOVE_STATUS_ID:
AccountManager.getInstance().removeSavedStatus(actionWithItem);
((UpdatableAdapter) getListAdapter()).onChange();
adapter.onChange();
return true;
}
return false;
......
......@@ -138,7 +138,7 @@ public class AccountToggleAdapter implements UpdatableAdapter {
* child.
* @return The data for the specified view.
*/
public Object getItemForView(View view) {
public String getItemForView(View view) {
if (view.getId() == R.id.status_mode)
view = (View) view.getParent();
for (int index = 0; index < linearLayout.getChildCount(); index++)
......
......@@ -22,13 +22,9 @@ import java.util.Date;
import java.util.Map.Entry;
import java.util.TreeMap;
import android.app.ListActivity;
import android.app.Activity;
import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ListView;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.AccountManager;
......@@ -42,7 +38,6 @@ import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.GroupManager;
import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.androiddev.R;
/**
* Adapter for contact list in the main activity.
......@@ -59,36 +54,6 @@ public class ContactListAdapter extends
*/
private static final long REFRESH_INTERVAL = 1000;
/**
* View with information shown on empty contact list.
*/
private final View infoView;
/**
* Image view with connected icon.
*/
private View connectedView;
/**
* Image view with disconnected icon.
*/
private View disconnectedView;
/**
* View with help text.
*/
private TextView textView;
/**
* Button to apply help text.
*/
private Button buttonView;
/**
* Animation for disconnected view.
*/
private Animation animation;
/**
* Handler for deferred refresh.
*/
......@@ -114,24 +79,13 @@ public class ContactListAdapter extends
*/
private Date nextRefresh;
public ContactListAdapter(ListActivity activity) {
super(activity, activity.getListView(), new ChatContactInflater(
activity), GroupManager.getInstance());
infoView = activity.findViewById(R.id.info);
if (infoView != null) {
connectedView = infoView.findViewById(R.id.connected);
disconnectedView = infoView.findViewById(R.id.disconnected);
textView = (TextView) infoView.findViewById(R.id.text);
buttonView = (Button) infoView.findViewById(R.id.button);
animation = AnimationUtils.loadAnimation(activity,
R.anim.connection);
} else {
connectedView = null;
disconnectedView = null;
textView = null;
buttonView = null;
animation = null;
}
private final OnContactListChangedListener listener;
public ContactListAdapter(Activity activity, ListView listView,
OnContactListChangedListener listener) {
super(activity, listView, new ChatContactInflater(activity),
GroupManager.getInstance());
this.listener = listener;
handler = new Handler();
refreshLock = new Object();
refreshRequested = false;
......@@ -220,12 +174,12 @@ public class ContactListAdapter extends
/**
* Whether there is at least one contact.
*/
boolean hasContact = false;
boolean hasContacts = false;
/**
* Whether there is at least one visible contact.
*/
boolean hasVisible = false;
boolean hasVisibleContacts = false;
for (String account : AccountManager.getInstance().getAccounts())
accounts.put(account, null);
......@@ -274,7 +228,7 @@ public class ContactListAdapter extends
for (RosterContact rosterContact : rosterContacts) {
if (!rosterContact.isEnabled())
continue;
hasContact = true;
hasContacts = true;
final boolean online = rosterContact.getStatusMode().isOnline();
final String account = rosterContact.getAccount();
final TreeMap<String, AbstractChat> users = abstractChats
......@@ -287,7 +241,7 @@ public class ContactListAdapter extends
if (showActiveChats && abstractChat != null
&& abstractChat.isActive()) {
activeChats.setNotEmpty();
hasVisible = true;
hasVisibleContacts = true;
if (activeChats.isExpanded())
activeChats.addAbstractContact(rosterContact);
activeChats.increment(online);
......@@ -298,7 +252,7 @@ public class ContactListAdapter extends
continue;
if (addContact(rosterContact, online, accounts, groups,
contacts, showAccounts, showGroups, showOffline))
hasVisible = true;
hasVisibleContacts = true;
}
for (TreeMap<String, AbstractChat> users : abstractChats.values())
for (AbstractChat abstractChat : users.values()) {
......@@ -310,7 +264,7 @@ public class ContactListAdapter extends
abstractContact = new ChatContact(abstractChat);
if (showActiveChats && abstractChat.isActive()) {
activeChats.setNotEmpty();
hasVisible = true;
hasVisibleContacts = true;
if (activeChats.isExpanded())
activeChats.addAbstractContact(abstractContact);
activeChats.increment(false);
......@@ -330,14 +284,14 @@ public class ContactListAdapter extends
group = GroupManager.NO_GROUP;
online = false;
}
hasVisible = true;
hasVisibleContacts = true;
addContact(abstractContact, group, online, accounts,
groups, contacts, showAccounts, showGroups);
}
// Remove empty groups, sort and apply structure.
baseEntities.clear();
if (hasVisible) {
if (hasVisibleContacts) {
if (showActiveChats) {
if (!activeChats.isEmpty()) {
if (showAccounts || showGroups)
......@@ -417,89 +371,12 @@ public class ContactListAdapter extends
Collections.sort(baseEntities, comparator);
this.baseEntities.clear();
this.baseEntities.addAll(baseEntities);
hasVisible = baseEntities.size() > 0;
}
if (infoView != null) {
if (hasVisible) {
infoView.setVisibility(View.GONE);
disconnectedView.clearAnimation();
} else {
infoView.setVisibility(View.VISIBLE);
final int text;
final int button;
final ContactListState state;
if (filterString != null) {
if (commonState == CommonState.online)
state = ContactListState.online;
else if (commonState == CommonState.roster
|| commonState == CommonState.connecting)
state = ContactListState.connecting;
else
state = ContactListState.offline;
text = R.string.application_state_no_online;
button = 0;
} else if (hasContact) {
state = ContactListState.online;
text = R.string.application_state_no_online;
button = R.string.application_action_no_online;
} else if (commonState == CommonState.online) {
state = ContactListState.online;
text = R.string.application_state_no_contacts;
button = R.string.application_action_no_contacts;
} else if (commonState == CommonState.roster) {
state = ContactListState.connecting;
text = R.string.application_state_roster;
button = 0;
} else if (commonState == CommonState.connecting) {
state = ContactListState.connecting;
text = R.string.application_state_connecting;
button = 0;
} else if (commonState == CommonState.waiting) {
state = ContactListState.offline;
text = R.string.application_state_waiting;
button = R.string.application_action_waiting;
} else if (commonState == CommonState.offline) {
state = ContactListState.offline;
text = R.string.application_state_offline;
button = R.string.application_action_offline;
} else if (commonState == CommonState.disabled) {
state = ContactListState.offline;
text = R.string.application_state_disabled;
button = R.string.application_action_disabled;
} else if (commonState == CommonState.empty) {
state = ContactListState.offline;
text = R.string.application_state_empty;
button = R.string.application_action_empty;
} else {
throw new IllegalStateException();
}
if (state == ContactListState.offline) {
connectedView.setVisibility(View.INVISIBLE);
disconnectedView.setVisibility(View.VISIBLE);
disconnectedView.clearAnimation();
} else if (state == ContactListState.connecting) {
connectedView.setVisibility(View.VISIBLE);
disconnectedView.setVisibility(View.VISIBLE);
if (disconnectedView.getAnimation() == null)
disconnectedView.startAnimation(animation);
} else if (state == ContactListState.online) {
connectedView.setVisibility(View.VISIBLE);
disconnectedView.setVisibility(View.INVISIBLE);
disconnectedView.clearAnimation();
}
textView.setText(text);
if (button == 0) {
buttonView.setVisibility(View.GONE);
} else {
buttonView.setVisibility(View.VISIBLE);
buttonView.setText(button);
buttonView.setTag(Integer.valueOf(button));
}
}
hasVisibleContacts = baseEntities.size() > 0;
}
super.onChange();
listener.onContactListChanged(commonState, hasContacts, hasVisibleContacts,
filterString != null);
synchronized (refreshLock) {
nextRefresh = new Date(new Date().getTime() + REFRESH_INTERVAL);
......@@ -515,4 +392,17 @@ public class ContactListAdapter extends
onChange();
}
/**
* Listener for contact list appearance changes.
*
* @author alexander.ivanov
*
*/
public interface OnContactListChangedListener {
void onContactListChanged(CommonState commonState, boolean hasContacts,
boolean hasVisibleContacts, boolean isFilterEnabled);
}
}
......@@ -36,4 +36,18 @@ public interface SaveStateAdapter extends Adapter {
*/
void saveState(View view);
/**
* Requests to hide pages indicator.
*
* @param view
*/
void hidePages(View view);
/**
* Show pages indicator.
*
* @param view
*/
void showPages(View view);
}
/**
* 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.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
/**
* Base dialog fragment.
*
* CONVENTION: Subclass should implement <code>newInstance</code> static method.
* Activities or Fragments should use this method to instantiate DialogFragment.
*
* @author alexander.ivanov
*
*/
public abstract class AbstractDialogFragment extends DialogFragment {
private Bundle initArguments() {
Bundle bundle = getArguments();
if (bundle == null) {
bundle = new Bundle();
setArguments(bundle);
}
return bundle;
}
protected AbstractDialogFragment putAgrument(String key, String value) {
initArguments().putString(key, value);
return this;
}
protected AbstractDialogFragment putAgrument(String key,
ArrayList<String> value) {
initArguments().putStringArrayList(key, value);
return this;
}
protected AbstractDialogFragment putAgrument(String key, boolean value) {
initArguments().putBoolean(key, value);
return this;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Builder builder = getBuilder();
return getDialog(builder);
}
/**
* Constructs {@link AlertDialog.Builder} instance.
*
* @return
*/
protected abstract Builder getBuilder();
/**
* Constructs {@link Dialog} instance.
*
* @param builder
* @return
*/
protected Dialog getDialog(Builder builder) {
return builder.create();
}
}
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;
import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.adapter.AccountChooseAdapter;
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 String user;
private String text;
@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) {
String account = (String) adapter.getItem(which);
OnChoosedListener listener = (OnChoosedListener) getActivity();
listener.onChoosed(account, user, text);
}
});
return builder;
}
private class Adapter extends AccountChooseAdapter {
public Adapter(Activity activity) {
super(activity);
ArrayList<String> available = new ArrayList<String>();
for (RosterContact check : RosterManager.getInstance()
.getContacts())
if (check.isEnabled() && check.getUser().equals(user))
available.add(check.getAccount());
if (!available.isEmpty()) {
accounts.clear();
accounts.addAll(available);
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getDropDownView(position, convertView, parent);
}
}
public interface OnChoosedListener {
void onChoosed(String account, String user, String text);
}
}
/**
* 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.io.File;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.androiddev.R;
public class ChatExportDialogFragment extends ConfirmDialogFragment {
private static final String ACCOUNT = "ACCOUNT";
private static final String USER = "USER";
/**
* @param account
* @param user
* @return
*/
public static DialogFragment newInstance(String account, String user) {
return new ChatExportDialogFragment().putAgrument(ACCOUNT, account)
.putAgrument(USER, user);
}
private String account;
private String user;
private EditText nameView;
private CheckBox sendView;
@Override
protected Builder getBuilder() {
account = getArguments().getString(ACCOUNT);
user = getArguments().getString(USER);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.export_chat_title);
View layout = getActivity().getLayoutInflater().inflate(
R.layout.export_chat, null);
nameView = (EditText) layout.findViewById(R.id.name);
sendView = (CheckBox) layout.findViewById(R.id.send);
nameView.setText(getString(R.string.export_chat_mask, AccountManager
.getInstance().getVerboseName(account), RosterManager
.getInstance().getName(account, user)));
builder.setView(layout);
return builder;
}
@Override
protected boolean onPositiveClick() {
String name = nameView.getText().toString();
if ("".equals(name))
return false;
new ChatExportAsyncTask(account, user, name, sendView.isChecked())
.execute();
return true;
}
private class ChatExportAsyncTask extends AsyncTask<Void, Void, File> {
private final String account;
private final String user;
private final String name;
private final boolean send;
public ChatExportAsyncTask(String account, String user, String name,
boolean send) {
this.account = account;
this.user = user;
this.name = name;
this.send = send;
}
@Override
protected File doInBackground(Void... params) {
try {
return MessageManager.getInstance().exportChat(account, user,
name);
} catch (NetworkException e) {
Application.getInstance().onError(e);
return null;
}
}
@Override
public void onPostExecute(File result) {
if (result == null)
return;
// TODO: Use notification bar to notify about success.
if (send) {
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
Uri uri = Uri.fromFile(result);
intent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent,
getString(R.string.export_chat)));
} else {
Toast.makeText(getActivity(), R.string.export_chat_done,
Toast.LENGTH_LONG).show();
}
}
}
}
/**
* 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 android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnShowListener;
import android.os.Build;
import android.view.View;
import android.widget.Button;
/**
* Base yes / no dialog fragment.
*
* Provides callback methods and option to abort dialog dismissing on button
* click (starting from FROYO version).
*
* @author alexander.ivanov
*
*/
public abstract class ConfirmDialogFragment extends AbstractDialogFragment {
private final OnClickListener positiveListener = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (onPositiveClick())
supportDismiss(dialog);
}
};
private final OnClickListener neutralListener = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (onNegativeClicked())
supportDismiss(dialog);
}
};
private final OnClickListener negativeListener = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (onNegativeClicked())
supportDismiss(dialog);
}
};
@Override
protected Dialog getDialog(Builder builder) {
if (hasPositiveButton())
builder.setPositiveButton(getPositiveTextId(), positiveListener);
if (hasNeutralButton())
builder.setNeutralButton(getNeutralTextId(), neutralListener);
if (hasNegativeButton())
builder.setNegativeButton(getNegativeTextId(), negativeListener);
AlertDialog dialog = builder.create();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO)
setOnShowListener(dialog);
return dialog;
}
private void supportDismiss(DialogInterface dialog) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO)
dialog.dismiss();
}
@TargetApi(Build.VERSION_CODES.FROYO)
private void setOnShowListener(final AlertDialog alertDialog) {
alertDialog.setOnShowListener(new OnShowListener() {
private void setListener(final int whichButton,
final OnClickListener listener) {
Button button = alertDialog.getButton(whichButton);
if (button == null)
return;
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
listener.onClick(alertDialog, whichButton);
}
});
}
@Override
public void onShow(DialogInterface dialog) {
setListener(AlertDialog.BUTTON_POSITIVE, positiveListener);
setListener(AlertDialog.BUTTON_NEUTRAL, neutralListener);
setListener(AlertDialog.BUTTON_NEGATIVE, negativeListener);
}
});
}
protected boolean hasPositiveButton() {
return true;
}
protected boolean hasNeutralButton() {
return false;
}
protected boolean hasNegativeButton() {
return true;
}
protected int getPositiveTextId() {
return android.R.string.ok;
}
protected int getNeutralTextId() {
return android.R.string.unknownName;
}
protected int getNegativeTextId() {
return android.R.string.cancel;
}
/**
* Processes positive button click.
*
* @return Whether dialog can be dismissed.
*/
protected boolean onPositiveClick() {
return true;
}
/**
* Processes neutral button click.
*
* @return Whether dialog can be dismissed.
*/
protected boolean onNeutralClicked() {
return true;
}
/**
* Processes negative button click.
*
* @return Whether dialog can be dismissed.
*/
protected boolean onNegativeClicked() {
return true;
}
}
package com.xabber.android.ui.dialog;
import android.app.AlertDialog.Builder;
import android.support.v4.app.DialogFragment;
import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.androiddev.R;
public class ContactDeleteDialogFragment extends ConfirmDialogFragment {
private static final String ACCOUNT = "ACCOUNT";
private static final String USER = "USER";
/**
* @param account
* @param user
* @return
*/
public static DialogFragment newInstance(String account, String user) {
return new ContactDeleteDialogFragment().putAgrument(ACCOUNT, account)
.putAgrument(USER, user);
}
private String user;
private String account;
@Override
protected Builder getBuilder() {
user = getArguments().getString(USER);
account = getArguments().getString(ACCOUNT);
return new Builder(getActivity()).setMessage(getString(
R.string.contact_delete_confirm, RosterManager.getInstance()
.getName(account, user), AccountManager.getInstance()
.getVerboseName(account)));
}
@Override
protected boolean onPositiveClick() {
try {
RosterManager.getInstance().removeContact(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
}
}
package com.xabber.android.ui.dialog;
import android.app.AlertDialog.Builder;
import android.support.v4.app.DialogFragment;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.AccountManager;
import com.xabber.androiddev.R;
public class ContactIntegrationDialogFragment extends ConfirmDialogFragment {
public static DialogFragment newInstance() {
return new ContactIntegrationDialogFragment();
}
@Override
protected Builder getBuilder() {
return new Builder(getActivity())
.setMessage(R.string.contact_integration_suggest);
}
@Override
protected boolean onPositiveClick() {
SettingsManager.setContactIntegrationSuggested();
for (String account : AccountManager.getInstance().getAllAccounts())
AccountManager.getInstance().setSyncable(account, true);
return true;
}
@Override
protected boolean onNegativeClicked() {
SettingsManager.setContactIntegrationSuggested();
return true;
}
}
/**
* 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.AlertDialog;
import android.app.AlertDialog.Builder;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.xabber.androiddev.R;
public class GroupAddDialogFragment extends ConfirmDialogFragment {
private static final String GROUPS = "GROUPS";
/**
* @param account
* can be <code>null</code> to be used for all accounts.
* @param group
* can be <code>null</code> to be used for "no group".
* @return
*/
public static DialogFragment newInstance(ArrayList<String> groups) {
return new GroupAddDialogFragment().putAgrument(GROUPS, groups);
}
private ArrayList<String> groups;
private EditText nameView;
@Override
protected Builder getBuilder() {
groups = getArguments().getStringArrayList(GROUPS);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.group_add);
View layout = getActivity().getLayoutInflater().inflate(
R.layout.group_name, null);
nameView = (EditText) layout.findViewById(R.id.group_name);
builder.setView(layout);
return builder;
}
@Override
protected boolean onPositiveClick() {
String group = nameView.getText().toString();
if ("".equals(group)) {
Toast.makeText(getActivity(), getString(R.string.group_is_empty),
Toast.LENGTH_LONG).show();
return false;
}
if (groups.contains(group)) {
Toast.makeText(getActivity(), getString(R.string.group_exists),
Toast.LENGTH_LONG).show();
return false;
}
((OnGroupAddConfirmed) getActivity()).onGroupAddConfirmed(group);
return true;
}
public interface OnGroupAddConfirmed {
void onGroupAddConfirmed(String group);
}
}
package com.xabber.android.ui.dialog;
import android.app.AlertDialog.Builder;
import android.support.v4.app.DialogFragment;
import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.androiddev.R;
public class GroupDeleteDialogFragment extends ConfirmDialogFragment {
private static final String ACCOUNT = "ACCOUNT";
private static final String GROUP = "GROUP";
/**
* @param account
* can be <code>null</code> to be used for all accounts.
* @param group
* @return
*/
public static DialogFragment newInstance(String account, String group) {
return new GroupDeleteDialogFragment().putAgrument(ACCOUNT, account)
.putAgrument(GROUP, group);
}
private String group;
private String account;
@Override
protected Builder getBuilder() {
group = getArguments().getString(GROUP);
account = getArguments().getString(ACCOUNT);
return new Builder(getActivity()).setMessage(getString(
R.string.group_remove_confirm, group));
}
@Override
protected boolean onPositiveClick() {
try {
if (account == null)
RosterManager.getInstance().removeGroup(group);
else
RosterManager.getInstance().removeGroup(account, group);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
}
}
/**
* 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 android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.androiddev.R;
public class GroupRenameDialogFragment extends ConfirmDialogFragment {
private static final String ACCOUNT = "ACCOUNT";
private static final String GROUP = "GROUP";
/**
* @param account
* can be <code>null</code> to be used for all accounts.
* @param group
* can be <code>null</code> to be used for "no group".
* @return
*/
public static DialogFragment newInstance(String account, String group) {
return new GroupRenameDialogFragment().putAgrument(ACCOUNT, account)
.putAgrument(GROUP, group);
}
private String group;
private String account;
private EditText nameView;
@Override
protected Builder getBuilder() {
group = getArguments().getString(GROUP);
account = getArguments().getString(ACCOUNT);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.group_rename);
View layout = getActivity().getLayoutInflater().inflate(
R.layout.group_name, null);
nameView = (EditText) layout.findViewById(R.id.group_name);
nameView.setText(group == null ? "" : group);
builder.setView(layout);
return builder;
}
@Override
protected boolean onPositiveClick() {
String newName = nameView.getText().toString();
if ("".equals(newName)) {
Toast.makeText(getActivity(), getString(R.string.group_is_empty),
Toast.LENGTH_LONG).show();
return false;
}
try {
if (account == null)
RosterManager.getInstance().renameGroup(group, newName);
else
RosterManager.getInstance()
.renameGroup(account, group, newName);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
}
}
package com.xabber.android.ui.dialog;
import android.app.AlertDialog.Builder;
import android.support.v4.app.DialogFragment;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.notification.NotificationManager;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.androiddev.R;
public class MUCDeleteDialogFragment extends ConfirmDialogFragment {
private static final String ACCOUNT = "ACCOUNT";
private static final String USER = "USER";
/**
* @param account
* @param user
* @return
*/
public static DialogFragment newInstance(String account, String user) {
return new MUCDeleteDialogFragment().putAgrument(ACCOUNT, account)
.putAgrument(USER, user);
}
private String user;
private String account;
@Override
protected Builder getBuilder() {
user = getArguments().getString(USER);
account = getArguments().getString(ACCOUNT);
return new Builder(getActivity()).setMessage(getString(
R.string.muc_delete_confirm, RosterManager.getInstance()
.getName(account, user), AccountManager.getInstance()
.getVerboseName(account)));
}
@Override
protected boolean onPositiveClick() {
MUCManager.getInstance().removeRoom(account, user);
MessageManager.getInstance().closeChat(account, user);
NotificationManager.getInstance().removeMessageNotification(account,
user);
return true;
}
}
package com.xabber.android.ui.dialog;
import android.app.AlertDialog.Builder;
import android.support.v4.app.DialogFragment;
import com.xabber.android.data.SettingsManager;
import com.xabber.androiddev.R;
public class StartAtBootDialogFragment extends ConfirmDialogFragment {
public static DialogFragment newInstance() {
return new StartAtBootDialogFragment();
}
@Override
protected Builder getBuilder() {
return new Builder(getActivity())
.setMessage(R.string.start_at_boot_suggest);
}
@Override
protected boolean onPositiveClick() {
SettingsManager.setStartAtBootSuggested();
SettingsManager.setConnectionStartAtBoot(true);
return true;
}
@Override
protected boolean onNegativeClicked() {
SettingsManager.setStartAtBootSuggested();
return true;
}
}
......@@ -52,7 +52,7 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
private T actionWith;
private BaseListEditorAdapter<T> adapter;
protected BaseListEditorAdapter<T> adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
......
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