Skip to content

Commit

Permalink
Merge branch 'release/1.0.173'
Browse files Browse the repository at this point in the history
  • Loading branch information
Grigory Fedorov committed Apr 10, 2017
2 parents fe744e1 + 665772a commit 06c171e
Show file tree
Hide file tree
Showing 76 changed files with 1,217 additions and 66 deletions.
11 changes: 6 additions & 5 deletions xabber/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 343
versionName '1.0.171'
versionCode 345
versionName '1.0.173'
}

lintOptions {
Expand Down Expand Up @@ -92,9 +92,10 @@ dependencies {
compile project('MemorizingTrustManager')
compile project('emojicon')

compile "org.igniterealtime.smack:smack-android-extensions:4.2.1-20170404.010458-5"
compile "org.igniterealtime.smack:smack-experimental:4.2.1-20170404.010520-5"
compile "org.igniterealtime.smack:smack-tcp:4.2.1-20170404.010559-5"
compile "org.igniterealtime.smack:smack-android-extensions:4.2.1-20170405.080126-7"
compile "org.igniterealtime.smack:smack-experimental:4.2.1-20170405.080149-7"
compile "org.igniterealtime.smack:smack-tcp:4.2.1-20170405.080228-7"
compile "org.igniterealtime.smack:smack-resolver-dnsjava:4.2.1-20170405.080225-7"

compile "com.android.support:design:$supportVersion"
compile "com.android.support:support-v13:$supportVersion"
Expand Down
7 changes: 7 additions & 0 deletions xabber/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
-keep class org.jivesoftware.smack.** { *; }
-keep class org.jivesoftware.smackx.** { *; }

# This dnsjava class uses old Sun API
-dontnote org.xbill.DNS.spi.DNSJavaNameServiceDescriptor
-dontwarn org.xbill.DNS.spi.DNSJavaNameServiceDescriptor

# See http://stackoverflow.com/questions/5701126, happens in dnsjava
-optimizations !code/allocation/variable

# OkHttp
-keepattributes Signature
-keepattributes *Annotation*
Expand Down
35 changes: 33 additions & 2 deletions xabber/src/main/java/com/xabber/android/data/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
import android.net.Uri;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.xabber.android.R;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.StatusMode;
import com.xabber.android.data.connection.NetworkManager;
import com.xabber.android.data.connection.WakeLockManager;
import com.xabber.android.data.entity.AccountJid;
import com.xabber.android.data.extension.attention.AttentionManager;
import com.xabber.android.data.extension.carbons.CarbonManager;
import com.xabber.android.data.extension.otr.OTRManager;
import com.xabber.android.data.log.LogManager;
import com.xabber.android.data.message.MessageManager;
Expand All @@ -40,7 +41,6 @@
import com.xabber.android.ui.adapter.ComparatorByStatus;
import com.xabber.android.ui.color.ColorManager;
import com.xabber.android.utils.Emoticons;
import com.xabber.android.data.extension.carbons.CarbonManager;

import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -427,6 +427,23 @@ public static boolean connectionUseCarbons() {
R.bool.connection_use_carbons_default);
}

public static DnsResolverType connectionDnsResolver() {
String value = getString(R.string.connection_dns_resolver_type_key,
R.string.connection_dns_resolver_type_default);
return getDnsResolverType(value);
}

@NonNull
public static DnsResolverType getDnsResolverType(String value) {
if (Application.getInstance().getString(R.string.connection_dns_resolver_type_dns_java_resolver_value).equals(value)) {
return DnsResolverType.dnsJavaResolver;
} else if (Application.getInstance().getString(R.string.connection_dns_resolver_type_mini_dns_resolver_value).equals(value)) {
return DnsResolverType.miniDnsResolver;
} else {
throw new IllegalStateException("Unknown preference value for DNS resolver type");
}
}

public static boolean connectionUsePlainTextAuth() {
return getBoolean(R.string.connection_use_plain_text_auth_key,
R.bool.connection_use_plain_text_auth_default);
Expand Down Expand Up @@ -741,6 +758,20 @@ public enum InterfaceTheme {

}

public enum DnsResolverType {
/**
* Use DNS resolver based on dnsjava
* http://dnsjava.org/
*/
dnsJavaResolver,

/**
* Use DNS resolver based on MiniDNS - experimental
* https://github.com/rtreffer/minidns
*/
miniDnsResolver
}

public enum EventsMessage {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.support.annotation.NonNull;
import android.util.Log;

import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.AccountErrorEvent;
import com.xabber.android.data.account.AccountItem;
import com.xabber.android.data.log.AndroidLoggingHandler;
Expand All @@ -29,12 +30,13 @@
import org.jivesoftware.smack.sasl.SASLErrorException;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.util.DNSUtil;
import org.jivesoftware.smack.util.dns.dnsjava.DNSJavaResolver;
import org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver;

import java.io.IOException;
import java.util.logging.Level;

import de.measite.minidns.AbstractDNSClient;
import de.measite.minidns.DNSClient;

class ConnectionThread {

Expand Down Expand Up @@ -96,9 +98,16 @@ void connectAndLogin() {
java.util.logging.Logger.getLogger(AbstractXMPPConnection.class.getName()).setLevel(Level.FINEST);
java.util.logging.Logger.getLogger(DNSUtil.class.getName()).setLevel(Level.FINEST);

// TODO: temp solution until MiniDnsClient and Smack will be updated
DNSClient.removeDNSServerLookupMechanism(de.measite.minidns.dnsserverlookup.AndroidUsingExec.INSTANCE);
DNSClient.addDnsServerLookupMechanism(AndroidUsingExec.INSTANCE);
switch (SettingsManager.connectionDnsResolver()) {
case dnsJavaResolver:
LogManager.i(this, "Use DNS Java resolver");
DNSJavaResolver.setup();
break;
case miniDnsResolver:
LogManager.i(this, "Use Mini DNS resolver");
MiniDnsResolver.setup();
break;
}

try {
LogManager.i(this, "Trying to connect and login...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Stanza;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.parts.Resourcepart;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -170,11 +171,17 @@ private Occupant getOccupant(AccountJid account, UserJid user) {
if (userEntityBareJid == null) {
return null;
}

Resourcepart resourcepart = user.getJid().getResourceOrNull();
if (resourcepart == null) {
return null;
}

if (MUCManager.getInstance().hasRoom(account, userEntityBareJid)) {
final Collection<Occupant> occupants = MUCManager.getInstance().getOccupants(account,
userEntityBareJid);
for (Occupant occupant : occupants) {
if (occupant.getNickname().equals(user.getJid().getResourceOrNull())) {
if (occupant.getNickname().equals(resourcepart)) {
return occupant;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.entity.AccountJid;
import com.xabber.android.data.extension.avatar.AvatarManager;
import com.xabber.android.data.log.LogManager;
import com.xabber.android.ui.activity.ManagedActivity;
import com.xabber.android.ui.color.ColorManager;

Expand All @@ -38,6 +39,8 @@

public class AccountListAdapter extends RecyclerView.Adapter {

@SuppressWarnings("WeakerAccess")
static final String LOG_TAG = AccountListAdapter.class.getSimpleName();
@SuppressWarnings("WeakerAccess")
List<AccountItem> accountItems;
@SuppressWarnings("WeakerAccess")
Expand Down Expand Up @@ -116,7 +119,13 @@ private class AccountViewHolder extends RecyclerView.ViewHolder implements View.

@Override
public void onClick(View v) {
AccountItem accountItem = accountItems.get(getAdapterPosition());
int adapterPosition = getAdapterPosition();
if (adapterPosition == RecyclerView.NO_POSITION) {
LogManager.w(LOG_TAG, "onClick: no position");
return;
}

AccountItem accountItem = accountItems.get(adapterPosition);

switch (v.getId()) {
case R.id.item_account_switch:
Expand All @@ -133,7 +142,13 @@ public void onClick(View v) {

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
AccountItem accountItem = accountItems.get(getAdapterPosition());
int adapterPosition = getAdapterPosition();
if (adapterPosition == RecyclerView.NO_POSITION) {
LogManager.w(LOG_TAG, "onCreateContextMenu: no position");
return;
}

AccountItem accountItem = accountItems.get(adapterPosition);

MenuInflater inflater = activity.getMenuInflater();
inflater.inflate(R.menu.item_account, menu);
Expand All @@ -150,7 +165,13 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMen

@Override
public boolean onMenuItemClick(MenuItem item) {
AccountItem accountItem = accountItems.get(getAdapterPosition());
int adapterPosition = getAdapterPosition();
if (adapterPosition == RecyclerView.NO_POSITION) {
LogManager.w(LOG_TAG, "onMenuItemClick: no position");
return false;
}

AccountItem accountItem = accountItems.get(adapterPosition);

switch (item.getItemId()) {
case R.id.action_account_edit_status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

Expand All @@ -15,6 +14,7 @@
import com.xabber.android.data.entity.AccountJid;
import com.xabber.android.data.entity.UserJid;
import com.xabber.android.data.extension.blocking.BlockingManager;
import com.xabber.android.data.log.LogManager;
import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.RosterManager;

Expand Down Expand Up @@ -102,6 +102,7 @@ public void setListener(@Nullable OnBlockedContactClickListener listener) {
private class BlockListItemViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener {

private final String LOG_TAG = BlockListItemViewHolder.class.getSimpleName();
@Nullable
final ImageView avatar;
final TextView name;
Expand All @@ -126,7 +127,13 @@ private class BlockListItemViewHolder extends RecyclerView.ViewHolder

@Override
public void onClick(View v) {
UserJid userJid = blockedContacts.get(getAdapterPosition());
int adapterPosition = getAdapterPosition();
if (adapterPosition == RecyclerView.NO_POSITION) {
LogManager.w(LOG_TAG, "onClick: no position");
return;
}

UserJid userJid = blockedContacts.get(adapterPosition);

if (checkedContacts.contains(userJid)) {
checkedContacts.remove(userJid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.widget.RecyclerView;
Expand Down Expand Up @@ -72,6 +73,7 @@ public class ChatMessageAdapter extends RealmRecyclerViewAdapter<MessageItem, Ch
public static final int VIEW_TYPE_OUTGOING_MESSAGE = 3;
private static final int VIEW_TYPE_HINT = 1;
private static final int VIEW_TYPE_ACTION_MESSAGE = 4;
private static final String LOG_TAG = ChatMessageAdapter.class.getSimpleName();

private final Context context;
private final Message.MessageClickListener messageClickListener;
Expand Down Expand Up @@ -307,6 +309,7 @@ public int getItemCount() {
}
}

@Nullable
public MessageItem getMessageItem(int position) {
if (position == RecyclerView.NO_POSITION) {
return null;
Expand All @@ -319,15 +322,6 @@ public MessageItem getMessageItem(int position) {
}
}

public String getMessageItemId(int position) {
MessageItem messageItem = getMessageItem(position);
if (messageItem == null) {
return null;
} else {
return messageItem.getUniqueId();
}
}

@Override
public BasicMessage onCreateViewHolder(ViewGroup parent, int viewType) {
switch (viewType) {
Expand Down Expand Up @@ -359,6 +353,11 @@ public void onBindViewHolder(BasicMessage holder, int position) {

MessageItem messageItem = getMessageItem(position);

if (messageItem == null) {
LogManager.w(LOG_TAG, "onBindViewHolder Null message item. Position: " + position);
return;
}

switch (viewType) {
case VIEW_TYPE_HINT:
// holder.messageText.setText(hint);
Expand Down Expand Up @@ -395,6 +394,10 @@ public int getItemViewType(int position) {
}

MessageItem messageItem = getMessageItem(position);
if (messageItem == null) {
return 0;
}

if (messageItem.getAction() != null) {
return VIEW_TYPE_ACTION_MESSAGE;
}
Expand Down Expand Up @@ -558,6 +561,7 @@ static class BasicMessage extends RecyclerView.ViewHolder {

public static abstract class Message extends BasicMessage implements View.OnClickListener {

private static final String LOG_TAG = Message.class.getSimpleName();
TextView messageTime;
TextView messageHeader;
TextView messageUnencrypted;
Expand Down Expand Up @@ -588,10 +592,16 @@ public Message(View itemView, MessageClickListener onClickListener, @StyleRes in

@Override
public void onClick(View v) {
int adapterPosition = getAdapterPosition();
if (adapterPosition == RecyclerView.NO_POSITION) {
LogManager.w(LOG_TAG, "onClick: no position");
return;
}

if (v.getId() == R.id.message_image) {
onClickListener.onMessageImageClick(itemView, getAdapterPosition());
onClickListener.onMessageImageClick(itemView, adapterPosition);
} else {
onClickListener.onMessageClick(messageBalloon, getAdapterPosition());
onClickListener.onMessageClick(messageBalloon, adapterPosition);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import android.widget.TextView;

import com.xabber.android.R;
import com.xabber.android.data.log.LogManager;

class AccountOptionViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

private static final String LOG_TAG = AccountOptionViewHolder.class.getSimpleName();
private final AccountOptionClickListener listener;
ImageView icon;
TextView title;
Expand All @@ -30,6 +32,12 @@ class AccountOptionViewHolder extends RecyclerView.ViewHolder implements View.On

@Override
public void onClick(View v) {
listener.onAccountOptionClick(getAdapterPosition());
int adapterPosition = getAdapterPosition();
if (adapterPosition == RecyclerView.NO_POSITION) {
LogManager.w(LOG_TAG, "onClick: no position");
return;
}

listener.onAccountOptionClick(adapterPosition);
}
}
Loading

0 comments on commit 06c171e

Please sign in to comment.