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; ...@@ -29,7 +29,6 @@ import java.util.concurrent.ThreadFactory;
import android.app.Activity; import android.app.Activity;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.os.Build;
import android.os.Handler; import android.os.Handler;
import com.xabber.android.service.XabberService; import com.xabber.android.service.XabberService;
...@@ -42,8 +41,6 @@ import com.xabber.androiddev.R; ...@@ -42,8 +41,6 @@ import com.xabber.androiddev.R;
*/ */
public class Application extends android.app.Application { public class Application extends android.app.Application {
public static final int SDK_INT = Integer.valueOf(Build.VERSION.SDK);
private static Application instance; private static Application instance;
public static Application getInstance() { public static Application getInstance() {
...@@ -254,8 +251,7 @@ public class Application extends android.app.Application { ...@@ -254,8 +251,7 @@ public class Application extends android.app.Application {
* @return * @return
*/ */
public boolean isContactsSupported() { public boolean isContactsSupported() {
return SDK_INT >= 5 return checkCallingOrSelfPermission("android.permission.READ_CONTACTS") == PackageManager.PERMISSION_GRANTED;
&& checkCallingOrSelfPermission("android.permission.READ_CONTACTS") == PackageManager.PERMISSION_GRANTED;
} }
@Override @Override
......
...@@ -16,15 +16,11 @@ package com.xabber.android.data; ...@@ -16,15 +16,11 @@ package com.xabber.android.data;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.jivesoftware.smack.Connection; import org.jivesoftware.smack.Connection;
import org.xbill.DNS.Options; import org.xbill.DNS.Options;
import android.content.Context;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log; import android.util.Log;
/** /**
...@@ -37,54 +33,12 @@ public class LogManager implements OnLoadListener { ...@@ -37,54 +33,12 @@ public class LogManager implements OnLoadListener {
private static final boolean log; private static final boolean log;
private static final boolean debugable; private static final boolean debugable;
private static Method _getApplicationInfo;
static { static {
initCompatibility(); debugable = (Application.getInstance().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
debugable = (getApplicationInfo(Application.getInstance()).flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
log = debugable && SettingsManager.debugLog(); 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; private final static LogManager instance;
static { static {
......
...@@ -27,6 +27,7 @@ import android.graphics.Bitmap; ...@@ -27,6 +27,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.OnLoadListener; import com.xabber.android.data.OnLoadListener;
...@@ -479,9 +480,9 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, ...@@ -479,9 +480,9 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener,
} }
private int getLauncherLargeIconSize() { private int getLauncherLargeIconSize() {
if (Application.SDK_INT < 9) if (Build.VERSION.SDK_INT < 9)
return BaseShortcutHelper.getLauncherLargeIconSize(); return BaseShortcutHelper.getLauncherLargeIconSize();
else if (Application.SDK_INT < 11) else if (Build.VERSION.SDK_INT < 11)
return GingerbreadShortcutHelper.getLauncherLargeIconSize(); return GingerbreadShortcutHelper.getLauncherLargeIconSize();
else else
return HoneycombShortcutHelper.getLauncherLargeIconSize(); return HoneycombShortcutHelper.getLauncherLargeIconSize();
......
...@@ -21,7 +21,7 @@ import com.xabber.android.data.account.AccountManager; ...@@ -21,7 +21,7 @@ import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.entity.BaseEntity; import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.notification.EntityNotificationItem; import com.xabber.android.data.notification.EntityNotificationItem;
import com.xabber.android.data.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.MUCEditor; import com.xabber.android.ui.MUCInvite;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
/** /**
...@@ -57,8 +57,7 @@ public class RoomInvite extends BaseEntity implements EntityNotificationItem { ...@@ -57,8 +57,7 @@ public class RoomInvite extends BaseEntity implements EntityNotificationItem {
@Override @Override
public Intent getIntent() { public Intent getIntent() {
return MUCEditor.createInviteIntent(Application.getInstance(), account, return MUCInvite.createIntent(Application.getInstance(), account, user);
user);
} }
@Override @Override
......
...@@ -27,6 +27,7 @@ import android.content.Intent; ...@@ -27,6 +27,7 @@ import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.os.Vibrator; import android.os.Vibrator;
import android.widget.RemoteViews; import android.widget.RemoteViews;
......
...@@ -20,7 +20,7 @@ import com.xabber.android.data.Application; ...@@ -20,7 +20,7 @@ import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountManager; import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.entity.BaseEntity; import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.notification.EntityNotificationItem; import com.xabber.android.data.notification.EntityNotificationItem;
import com.xabber.android.ui.ContactAdd; import com.xabber.android.ui.ContactSubscription;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class SubscriptionRequest extends BaseEntity implements public class SubscriptionRequest extends BaseEntity implements
...@@ -32,7 +32,7 @@ public class SubscriptionRequest extends BaseEntity implements ...@@ -32,7 +32,7 @@ public class SubscriptionRequest extends BaseEntity implements
@Override @Override
public Intent getIntent() { public Intent getIntent() {
return ContactAdd.createSubscriptionIntent(Application.getInstance(), return ContactSubscription.createIntent(Application.getInstance(),
account, user); account, user);
} }
......
...@@ -14,10 +14,6 @@ ...@@ -14,10 +14,6 @@
*/ */
package com.xabber.android.service; 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.app.Service;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
...@@ -36,9 +32,6 @@ import com.xabber.android.data.notification.NotificationManager; ...@@ -36,9 +32,6 @@ import com.xabber.android.data.notification.NotificationManager;
*/ */
public class XabberService extends Service { public class XabberService extends Service {
private Method startForeground;
private Method stopForeground;
private static XabberService instance; private static XabberService instance;
public static XabberService getInstance() { public static XabberService getInstance() {
...@@ -50,27 +43,17 @@ public class XabberService extends Service { ...@@ -50,27 +43,17 @@ public class XabberService extends Service {
super.onCreate(); super.onCreate();
instance = this; instance = this;
LogManager.i(this, "onCreate"); 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(); changeForeground();
} }
public void changeForeground() { public void changeForeground() {
if (SettingsManager.eventsPersistent() if (SettingsManager.eventsPersistent()
&& Application.getInstance().isInitialized()) && Application.getInstance().isInitialized())
startForegroundWrapper(NotificationManager.getInstance() startForeground(NotificationManager.PERSISTENT_NOTIFICATION_ID,
.getPersistentNotification()); NotificationManager.getInstance()
.getPersistentNotification());
else else
stopForegroundWrapper(); stopForeground(true);
} }
@Override @Override
...@@ -83,7 +66,7 @@ public class XabberService extends Service { ...@@ -83,7 +66,7 @@ public class XabberService extends Service {
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
LogManager.i(this, "onDestroy"); LogManager.i(this, "onDestroy");
stopForegroundWrapper(); stopForeground(true);
Application.getInstance().onServiceDestroy(); Application.getInstance().onServiceDestroy();
} }
...@@ -92,56 +75,6 @@ public class XabberService extends Service { ...@@ -92,56 +75,6 @@ public class XabberService extends Service {
return null; 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) { public static Intent createIntent(Context context) {
return new Intent(context, XabberService.class); return new Intent(context, XabberService.class);
} }
......
...@@ -28,7 +28,6 @@ import com.xabber.android.data.account.AccountManager; ...@@ -28,7 +28,6 @@ import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.OnAccountChangedListener; import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.ui.adapter.AccountListAdapter; import com.xabber.android.ui.adapter.AccountListAdapter;
import com.xabber.android.ui.adapter.BaseListEditorAdapter; import com.xabber.android.ui.adapter.BaseListEditorAdapter;
import com.xabber.android.ui.adapter.UpdatableAdapter;
import com.xabber.android.ui.helper.BaseListEditor; import com.xabber.android.ui.helper.BaseListEditor;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -119,7 +118,7 @@ public class AccountList extends BaseListEditor<String> implements ...@@ -119,7 +118,7 @@ public class AccountList extends BaseListEditor<String> implements
@Override @Override
public void onAccountsChanged(Collection<String> accounts) { public void onAccountsChanged(Collection<String> accounts) {
((UpdatableAdapter) getListAdapter()).onChange(); adapter.onChange();
} }
@Override @Override
......
...@@ -18,7 +18,6 @@ import java.util.Collection; ...@@ -18,7 +18,6 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
...@@ -39,34 +38,19 @@ import com.xabber.android.data.intent.EntityIntentBuilder; ...@@ -39,34 +38,19 @@ import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.message.MessageManager; import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.roster.PresenceManager; import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.RosterManager; 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.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; import com.xabber.androiddev.R;
public class ContactAdd extends GroupListActivity implements public class ContactAdd extends GroupListActivity implements
View.OnClickListener, ConfirmDialogListener, OnItemSelectedListener { View.OnClickListener, 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";
private static final String SAVED_ACCOUNT = "com.xabber.android.ui.ContactAdd.SAVED_ACCOUNT"; 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_USER = "com.xabber.android.ui.ContactAdd.SAVED_USER";
private static final String SAVED_NAME = "com.xabber.android.ui.ContactAdd.SAVED_NAME"; 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 account;
private String user; private String user;
private SubscriptionRequest subscriptionRequest;
/** /**
* Views * Views
*/ */
...@@ -125,17 +109,6 @@ public class ContactAdd extends GroupListActivity implements ...@@ -125,17 +109,6 @@ public class ContactAdd extends GroupListActivity implements
userView.setText(user); userView.setText(user);
if (name != null) if (name != null)
nameView.setText(name); 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 @Override
...@@ -147,13 +120,6 @@ public class ContactAdd extends GroupListActivity implements ...@@ -147,13 +120,6 @@ public class ContactAdd extends GroupListActivity implements
outState.putString(SAVED_NAME, nameView.getText().toString()); outState.putString(SAVED_NAME, nameView.getText().toString());
} }
@Override
protected void onResume() {
super.onResume();
if (subscriptionRequest != null)
showDialog(DIALOG_SUBSCRIPTION_REQUEST_ID);
}
@Override @Override
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
...@@ -188,65 +154,6 @@ public class ContactAdd extends GroupListActivity implements ...@@ -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 @Override
Collection<String> getInitialGroups() { Collection<String> getInitialGroups() {
String account = (String) accountView.getSelectedItem(); String account = (String) accountView.getSelectedItem();
...@@ -283,21 +190,14 @@ public class ContactAdd extends GroupListActivity implements ...@@ -283,21 +190,14 @@ public class ContactAdd extends GroupListActivity implements
return createIntent(context, null); 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) { public static Intent createIntent(Context context, String account) {
return createIntent(context, account, null); return createIntent(context, account, null);
} }
public static Intent createSubscriptionIntent(Context context, public static Intent createIntent(Context context, String account,
String account, String user) { String user) {
Intent intent = createIntent(context, account, user); return new EntityIntentBuilder(context, ContactAdd.class)
intent.setAction(ACTION_SUBSCRIPTION_REQUEST); .setAccount(account).setUser(user).build();
return intent;
} }
private static String getAccount(Intent intent) { 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; ...@@ -18,7 +18,6 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import android.app.Dialog;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
...@@ -30,9 +29,8 @@ import android.widget.ArrayAdapter; ...@@ -30,9 +29,8 @@ import android.widget.ArrayAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import com.xabber.android.ui.dialog.ConfirmDialogListener; import com.xabber.android.ui.dialog.GroupAddDialogFragment;
import com.xabber.android.ui.dialog.DialogBuilder; import com.xabber.android.ui.dialog.GroupAddDialogFragment.OnGroupAddConfirmed;
import com.xabber.android.ui.dialog.GroupAddDialogBuilder;
import com.xabber.android.ui.helper.ManagedListActivity; import com.xabber.android.ui.helper.ManagedListActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -43,15 +41,13 @@ import com.xabber.androiddev.R; ...@@ -43,15 +41,13 @@ import com.xabber.androiddev.R;
* *
*/ */
public abstract class GroupListActivity extends ManagedListActivity implements 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_GROUPS = "com.xabber.android.ui.ContactList.SAVED_GROUPS";
private static final String SAVED_SELECTED = "com.xabber.android.ui.ContactList.SAVED_SELECTED"; 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 OPTION_MENU_ADD_GROUP_ID = 1;
static final int DIALOG_ADD_GROUP_ID = 0x10;
private ArrayAdapter<String> arrayAdapter; private ArrayAdapter<String> arrayAdapter;
private ListView listView; private ListView listView;
...@@ -148,29 +144,22 @@ public abstract class GroupListActivity extends ManagedListActivity implements ...@@ -148,29 +144,22 @@ public abstract class GroupListActivity extends ManagedListActivity implements
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case OPTION_MENU_ADD_GROUP_ID: case OPTION_MENU_ADD_GROUP_ID:
showDialog(DIALOG_ADD_GROUP_ID); showGroupAddDialog();
return true; return true;
} }
return false; return false;
} }
@Override private void showGroupAddDialog() {
protected Dialog onCreateDialog(int id) { GroupAddDialogFragment.newInstance(getGroups()).show(
super.onCreateDialog(id); getSupportFragmentManager(), "GROUP-ADD");
switch (id) {
case DIALOG_ADD_GROUP_ID:
return new GroupAddDialogBuilder(this, DIALOG_ADD_GROUP_ID, this,
getGroups()).create();
default:
return null;
}
} }
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, public void onItemClick(AdapterView<?> parent, View view, int position,
long id) { long id) {
if (listView.getItemAtPosition(position) == null) // Footer if (listView.getItemAtPosition(position) == null) // Footer
showDialog(DIALOG_ADD_GROUP_ID); showGroupAddDialog();
} }
/** /**
...@@ -192,24 +181,12 @@ public abstract class GroupListActivity extends ManagedListActivity implements ...@@ -192,24 +181,12 @@ public abstract class GroupListActivity extends ManagedListActivity implements
} }
@Override @Override
public void onAccept(DialogBuilder dialog) { public void onGroupAddConfirmed(String group) {
switch (dialog.getDialogId()) { ArrayList<String> groups = getGroups();
case DIALOG_ADD_GROUP_ID: groups.add(group);
String group = ((GroupAddDialogBuilder) dialog).getName(); ArrayList<String> selected = getSelected();
ArrayList<String> groups = getGroups(); selected.add(group);
groups.add(group); setGroups(groups, selected);
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; ...@@ -18,7 +18,6 @@ import java.util.Collection;
import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.StringUtils;
import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
...@@ -31,7 +30,6 @@ import android.widget.EditText; ...@@ -31,7 +30,6 @@ import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.Toast; import android.widget.Toast;
import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountManager; import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.extension.muc.MUCManager; import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.extension.muc.RoomInvite; import com.xabber.android.data.extension.muc.RoomInvite;
...@@ -40,27 +38,15 @@ import com.xabber.android.data.intent.EntityIntentBuilder; ...@@ -40,27 +38,15 @@ import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.message.MessageManager; import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.notification.NotificationManager; import com.xabber.android.data.notification.NotificationManager;
import com.xabber.android.ui.adapter.AccountChooseAdapter; 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.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class MUCEditor extends ManagedActivity implements View.OnClickListener, public class MUCEditor extends ManagedActivity implements View.OnClickListener,
OnItemSelectedListener, ConfirmDialogListener { OnItemSelectedListener {
/**
* 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";
private static final String SAVED_ACCOUNT = "com.xabber.android.ui.MUCEditor.SAVED_ACCOUNT"; 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 String SAVED_ROOM = "com.xabber.android.ui.MUCEditor.SAVED_ROOM";
private static final int DIALOG_MUC_INVITE_ID = 100;
private String account; private String account;
private String room; private String room;
...@@ -69,11 +55,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener, ...@@ -69,11 +55,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
*/ */
private int selectedAccount; private int selectedAccount;
/**
* Invite intent.
*/
private RoomInvite roomInvite;
/** /**
* Views. * Views.
*/ */
...@@ -117,8 +98,15 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener, ...@@ -117,8 +98,15 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
.removeAuthorizationError(account, room); .removeAuthorizationError(account, room);
nickView.setText(MUCManager.getInstance().getNickname(account, nickView.setText(MUCManager.getInstance().getNickname(account,
room)); room));
passwordView.setText(MUCManager.getInstance().getPassword( String password;
account, room)); 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) { if (account == null) {
...@@ -137,17 +125,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener, ...@@ -137,17 +125,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
if ("".equals(nickView.getText().toString())) if ("".equals(nickView.getText().toString()))
nickView.setText(getNickname(((String) accountView nickView.setText(getNickname(((String) accountView
.getSelectedItem()))); .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 @Override
...@@ -162,8 +139,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener, ...@@ -162,8 +139,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
selectedAccount = accountView.getSelectedItemPosition(); selectedAccount = accountView.getSelectedItemPosition();
if (roomInvite != null)
showDialog(DIALOG_MUC_INVITE_ID);
} }
@Override @Override
...@@ -199,14 +174,15 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener, ...@@ -199,14 +174,15 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
room = room + "@" + server; room = room + "@" + server;
if (this.account != null && this.room != null) if (this.account != null && this.room != null)
if (!account.equals(this.account) || !room.equals(this.room)) { 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, MessageManager.getInstance().closeChat(this.account,
this.room); this.room);
NotificationManager.getInstance() NotificationManager.getInstance()
.removeMessageNotification(this.account, this.room); .removeMessageNotification(this.account, this.room);
} }
MUCManager.getInstance() MUCManager.getInstance().createRoom(account, room, nick, password,
.createRoom(account, room, nick, password, join); join);
finish(); finish();
break; break;
default: default:
...@@ -229,18 +205,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener, ...@@ -229,18 +205,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
return name; 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 @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) { long id) {
...@@ -261,37 +225,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener, ...@@ -261,37 +225,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
selectedAccount = accountView.getSelectedItemPosition(); 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) { public static Intent createIntent(Context context) {
return MUCEditor.createIntent(context, null, null); return MUCEditor.createIntent(context, null, null);
} }
...@@ -302,13 +235,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener, ...@@ -302,13 +235,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
.setAccount(account).setUser(room).build(); .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) { private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(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; ...@@ -40,7 +40,6 @@ import com.xabber.android.data.account.StatusMode;
import com.xabber.android.data.intent.AccountIntentBuilder; import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.ui.adapter.StatusEditorAdapter; import com.xabber.android.ui.adapter.StatusEditorAdapter;
import com.xabber.android.ui.adapter.StatusModeAdapter; import com.xabber.android.ui.adapter.StatusModeAdapter;
import com.xabber.android.ui.adapter.UpdatableAdapter;
import com.xabber.android.ui.helper.ManagedListActivity; import com.xabber.android.ui.helper.ManagedListActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -61,6 +60,7 @@ public class StatusEditor extends ManagedListActivity implements ...@@ -61,6 +60,7 @@ public class StatusEditor extends ManagedListActivity implements
private EditText statusTextView; private EditText statusTextView;
private SavedStatus actionWithItem; private SavedStatus actionWithItem;
private StatusEditorAdapter adapter;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -87,7 +87,8 @@ public class StatusEditor extends ManagedListActivity implements ...@@ -87,7 +87,8 @@ public class StatusEditor extends ManagedListActivity implements
listView.addHeaderView(header, null, false); listView.addHeaderView(header, null, false);
listView.setOnItemClickListener(this); listView.setOnItemClickListener(this);
registerForContextMenu(listView); registerForContextMenu(listView);
setListAdapter(new StatusEditorAdapter(this)); adapter = new StatusEditorAdapter(this);
setListAdapter(adapter);
statusTextView = (EditText) header.findViewById(R.id.status_text); statusTextView = (EditText) header.findViewById(R.id.status_text);
statusModeView = (Spinner) header.findViewById(R.id.status_mode); statusModeView = (Spinner) header.findViewById(R.id.status_mode);
...@@ -146,7 +147,7 @@ public class StatusEditor extends ManagedListActivity implements ...@@ -146,7 +147,7 @@ public class StatusEditor extends ManagedListActivity implements
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
((UpdatableAdapter) getListAdapter()).onChange(); adapter.onChange();
} }
@Override @Override
...@@ -164,7 +165,7 @@ public class StatusEditor extends ManagedListActivity implements ...@@ -164,7 +165,7 @@ public class StatusEditor extends ManagedListActivity implements
switch (item.getItemId()) { switch (item.getItemId()) {
case OPTION_MENU_CLEAR_STATUSES_ID: case OPTION_MENU_CLEAR_STATUSES_ID:
AccountManager.getInstance().clearSavedStatuses(); AccountManager.getInstance().clearSavedStatuses();
((UpdatableAdapter) getListAdapter()).onChange(); adapter.onChange();
return true; return true;
} }
return false; return false;
...@@ -202,7 +203,7 @@ public class StatusEditor extends ManagedListActivity implements ...@@ -202,7 +203,7 @@ public class StatusEditor extends ManagedListActivity implements
return true; return true;
case CONTEXT_MENU_REMOVE_STATUS_ID: case CONTEXT_MENU_REMOVE_STATUS_ID:
AccountManager.getInstance().removeSavedStatus(actionWithItem); AccountManager.getInstance().removeSavedStatus(actionWithItem);
((UpdatableAdapter) getListAdapter()).onChange(); adapter.onChange();
return true; return true;
} }
return false; return false;
......
...@@ -138,7 +138,7 @@ public class AccountToggleAdapter implements UpdatableAdapter { ...@@ -138,7 +138,7 @@ public class AccountToggleAdapter implements UpdatableAdapter {
* child. * child.
* @return The data for the specified view. * @return The data for the specified view.
*/ */
public Object getItemForView(View view) { public String getItemForView(View view) {
if (view.getId() == R.id.status_mode) if (view.getId() == R.id.status_mode)
view = (View) view.getParent(); view = (View) view.getParent();
for (int index = 0; index < linearLayout.getChildCount(); index++) for (int index = 0; index < linearLayout.getChildCount(); index++)
......
...@@ -22,13 +22,9 @@ import java.util.Date; ...@@ -22,13 +22,9 @@ import java.util.Date;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.TreeMap; import java.util.TreeMap;
import android.app.ListActivity; import android.app.Activity;
import android.os.Handler; import android.os.Handler;
import android.view.View; import android.widget.ListView;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.AccountManager; import com.xabber.android.data.account.AccountManager;
...@@ -42,7 +38,6 @@ import com.xabber.android.data.roster.AbstractContact; ...@@ -42,7 +38,6 @@ import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.GroupManager; import com.xabber.android.data.roster.GroupManager;
import com.xabber.android.data.roster.RosterContact; import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
import com.xabber.androiddev.R;
/** /**
* Adapter for contact list in the main activity. * Adapter for contact list in the main activity.
...@@ -59,36 +54,6 @@ public class ContactListAdapter extends ...@@ -59,36 +54,6 @@ public class ContactListAdapter extends
*/ */
private static final long REFRESH_INTERVAL = 1000; 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. * Handler for deferred refresh.
*/ */
...@@ -114,24 +79,13 @@ public class ContactListAdapter extends ...@@ -114,24 +79,13 @@ public class ContactListAdapter extends
*/ */
private Date nextRefresh; private Date nextRefresh;
public ContactListAdapter(ListActivity activity) { private final OnContactListChangedListener listener;
super(activity, activity.getListView(), new ChatContactInflater(
activity), GroupManager.getInstance()); public ContactListAdapter(Activity activity, ListView listView,
infoView = activity.findViewById(R.id.info); OnContactListChangedListener listener) {
if (infoView != null) { super(activity, listView, new ChatContactInflater(activity),
connectedView = infoView.findViewById(R.id.connected); GroupManager.getInstance());
disconnectedView = infoView.findViewById(R.id.disconnected); this.listener = listener;
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;
}
handler = new Handler(); handler = new Handler();
refreshLock = new Object(); refreshLock = new Object();
refreshRequested = false; refreshRequested = false;
...@@ -220,12 +174,12 @@ public class ContactListAdapter extends ...@@ -220,12 +174,12 @@ public class ContactListAdapter extends
/** /**
* Whether there is at least one contact. * Whether there is at least one contact.
*/ */
boolean hasContact = false; boolean hasContacts = false;
/** /**
* Whether there is at least one visible contact. * Whether there is at least one visible contact.
*/ */
boolean hasVisible = false; boolean hasVisibleContacts = false;
for (String account : AccountManager.getInstance().getAccounts()) for (String account : AccountManager.getInstance().getAccounts())
accounts.put(account, null); accounts.put(account, null);
...@@ -274,7 +228,7 @@ public class ContactListAdapter extends ...@@ -274,7 +228,7 @@ public class ContactListAdapter extends
for (RosterContact rosterContact : rosterContacts) { for (RosterContact rosterContact : rosterContacts) {
if (!rosterContact.isEnabled()) if (!rosterContact.isEnabled())
continue; continue;
hasContact = true; hasContacts = true;
final boolean online = rosterContact.getStatusMode().isOnline(); final boolean online = rosterContact.getStatusMode().isOnline();
final String account = rosterContact.getAccount(); final String account = rosterContact.getAccount();
final TreeMap<String, AbstractChat> users = abstractChats final TreeMap<String, AbstractChat> users = abstractChats
...@@ -287,7 +241,7 @@ public class ContactListAdapter extends ...@@ -287,7 +241,7 @@ public class ContactListAdapter extends
if (showActiveChats && abstractChat != null if (showActiveChats && abstractChat != null
&& abstractChat.isActive()) { && abstractChat.isActive()) {
activeChats.setNotEmpty(); activeChats.setNotEmpty();
hasVisible = true; hasVisibleContacts = true;
if (activeChats.isExpanded()) if (activeChats.isExpanded())
activeChats.addAbstractContact(rosterContact); activeChats.addAbstractContact(rosterContact);
activeChats.increment(online); activeChats.increment(online);
...@@ -298,7 +252,7 @@ public class ContactListAdapter extends ...@@ -298,7 +252,7 @@ public class ContactListAdapter extends
continue; continue;
if (addContact(rosterContact, online, accounts, groups, if (addContact(rosterContact, online, accounts, groups,
contacts, showAccounts, showGroups, showOffline)) contacts, showAccounts, showGroups, showOffline))
hasVisible = true; hasVisibleContacts = true;
} }
for (TreeMap<String, AbstractChat> users : abstractChats.values()) for (TreeMap<String, AbstractChat> users : abstractChats.values())
for (AbstractChat abstractChat : users.values()) { for (AbstractChat abstractChat : users.values()) {
...@@ -310,7 +264,7 @@ public class ContactListAdapter extends ...@@ -310,7 +264,7 @@ public class ContactListAdapter extends
abstractContact = new ChatContact(abstractChat); abstractContact = new ChatContact(abstractChat);
if (showActiveChats && abstractChat.isActive()) { if (showActiveChats && abstractChat.isActive()) {
activeChats.setNotEmpty(); activeChats.setNotEmpty();
hasVisible = true; hasVisibleContacts = true;
if (activeChats.isExpanded()) if (activeChats.isExpanded())
activeChats.addAbstractContact(abstractContact); activeChats.addAbstractContact(abstractContact);
activeChats.increment(false); activeChats.increment(false);
...@@ -330,14 +284,14 @@ public class ContactListAdapter extends ...@@ -330,14 +284,14 @@ public class ContactListAdapter extends
group = GroupManager.NO_GROUP; group = GroupManager.NO_GROUP;
online = false; online = false;
} }
hasVisible = true; hasVisibleContacts = true;
addContact(abstractContact, group, online, accounts, addContact(abstractContact, group, online, accounts,
groups, contacts, showAccounts, showGroups); groups, contacts, showAccounts, showGroups);
} }
// Remove empty groups, sort and apply structure. // Remove empty groups, sort and apply structure.
baseEntities.clear(); baseEntities.clear();
if (hasVisible) { if (hasVisibleContacts) {
if (showActiveChats) { if (showActiveChats) {
if (!activeChats.isEmpty()) { if (!activeChats.isEmpty()) {
if (showAccounts || showGroups) if (showAccounts || showGroups)
...@@ -417,89 +371,12 @@ public class ContactListAdapter extends ...@@ -417,89 +371,12 @@ public class ContactListAdapter extends
Collections.sort(baseEntities, comparator); Collections.sort(baseEntities, comparator);
this.baseEntities.clear(); this.baseEntities.clear();
this.baseEntities.addAll(baseEntities); this.baseEntities.addAll(baseEntities);
hasVisible = baseEntities.size() > 0; hasVisibleContacts = 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));
}
}
} }
super.onChange(); super.onChange();
listener.onContactListChanged(commonState, hasContacts, hasVisibleContacts,
filterString != null);
synchronized (refreshLock) { synchronized (refreshLock) {
nextRefresh = new Date(new Date().getTime() + REFRESH_INTERVAL); nextRefresh = new Date(new Date().getTime() + REFRESH_INTERVAL);
...@@ -515,4 +392,17 @@ public class ContactListAdapter extends ...@@ -515,4 +392,17 @@ public class ContactListAdapter extends
onChange(); 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 { ...@@ -36,4 +36,18 @@ public interface SaveStateAdapter extends Adapter {
*/ */
void saveState(View view); 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.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 ...@@ -52,7 +52,7 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
private T actionWith; private T actionWith;
private BaseListEditorAdapter<T> adapter; protected BaseListEditorAdapter<T> adapter;
@Override @Override
public void onCreate(Bundle savedInstanceState) { 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