Commit 20cca199 authored by jianglx's avatar jianglx

im的再次提交

parent b77dfc8a
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// smack
implementation 'org.igniterealtime.smack:smack-android-extensions:4.3.0'
implementation 'org.igniterealtime.smack:smack-experimental:4.3.0'
implementation 'org.igniterealtime.smack:smack-tcp:4.3.0'
implementation files('libs/ormlite-android-4.48.jar')
implementation files('libs/ormlite-core-4.48.jar')
implementation files('libs/fastjson-1.2.40.jar')
// bugly上报,没配置自动上传mapping,因为测试时自动上传mapping失败,
implementation 'com.tencent.bugly:crashreport:2.6.6'
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxfc.rv" />
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
package com.xxfc.rv;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import com.tencent.bugly.crashreport.CrashReport;
import com.xxfc.rv.utils.CrashHandler;
import java.net.UnknownHostException;
/**
* 封装异常上报,
* 当前使用,腾讯的bugly,
* <p>
* 要在Application.onCreate中调用init方法初始化,
*
* @author linenlian
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public class Reporter {
private static final String TAG = "Reporter";
@SuppressLint("StaticFieldLeak")
private static Context ctx;
private Reporter() {
}
public static void init(Context ctx) {
Reporter.ctx = ctx.getApplicationContext();
// 后初始化bugly, 崩溃发生时会先执行bugly的操作,然后bugly会调用先初始化的CrashHandler的Handler,
// 如果反过来,CrashHandler不会调用先初始化的Handler,
initLocalLog();
initBugly();
}
private static void initLocalLog() {
// 将错误日志写入本地
CrashHandler.getInstance().init(ctx);
}
private static void initBugly() {
}
/**
* 设置上报到bugly用户ID,
* 登录前是设备唯一码,登录后是手机号,
*/
public static void setUserId(String userId) {
CrashReport.setUserId(userId);
}
/**
* 保存用户信息,最多9对,
* <p>
* Bugly对键值对的限制,
* 最多可以有9对自定义的key-value(超过则添加失败);
* key限长50字节,value限长200字节,过长截断;
* key必须匹配正则:[a-zA-Z[0-9]]+。
*/
public static void putUserData(String key, String value) {
CrashReport.putUserData(ctx, key, value);
CrashHandler.getInstance().putUserData(key, value);
}
private static void debug(String message, Throwable t) {
if (BuildConfig.DEBUG) {
Log.w(TAG, message, t);
}
}
/**
* 对不可空的参数调用该方法,上报参数异常并抛出,
*/
public static <E> E notNullOrReport(E e, String value) {
if (e == null) {
String message = value + "不可空,";
RuntimeException t = new IllegalArgumentException(message);
post(message, t);
throw t;
}
return e;
}
/**
* 无法到达的代码块调用这个方法,
* 以防万一到达了可以看到,
*/
public static void unreachable() {
post("不可到达,");
}
/**
* 无法到达的代码块调用这个方法,
* 以防万一到达了可以看到,
*/
public static void unreachable(Throwable t) {
post("不可到达,", t);
}
public static void post(String message) {
if (message == null) {
message = "null";
}
Throwable t = new IllegalStateException(message);
debug(message, t);
postException(t);
}
public static void post(String message, Throwable t) {
if (message == null) {
message = "null";
}
debug(message, t);
postException(new IllegalStateException(message, t));
}
private static void postException(Throwable t) {
if (t == null) {
return;
}
// 开发过程不要上报,
if (BuildConfig.DEBUG) {
return;
}
Throwable cause = t;
while (cause != null) {
if (isNoInternetException(cause)) {
// 没有网络连接导致的异常不上报,
return;
}
// 以防万一,虽然应该不会出现cause就是本身导致死循环,
if (cause.getCause() == cause) {
break;
}
cause = cause.getCause();
}
CrashReport.postCatchedException(t);
}
/**
* 判断这个异常是不是没有网络导致的,
* 不准确,只是过滤部分明显的情况,
*
* @return 是断网导致的异常则返回true,
*/
private static boolean isNoInternetException(Throwable t) {
if (t == null) {
return false;
}
if (t instanceof UnknownHostException) {
return true;
}
//noinspection RedundantIfStatement
if (t.getMessage() != null && t.getMessage().contains("No address associated with hostname")) {
// 有的设备报的不是UnknownHostException,原因不明,
// android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
return true;
}
return false;
}
/**
* 对不可空的参数调用该方法,上报参数异常并抛出,
*/
public <E> E notNullOrReport(E e) {
return notNullOrReport(e, "value");
}
}
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
package com.xxfc.rv;
import android.content.Context;
import android.util.Log;
import com.sk.weichat.MyApplication;
import com.sk.weichat.helper.LoginHelper;
import com.sk.weichat.ui.UserCheckedActivity;
import org.jivesoftware.smack.AbstractConnectionListener;
import org.jivesoftware.smack.ReconnectionListener;
import org.jivesoftware.smack.ReconnectionManager;
import org.jivesoftware.smack.XMPPException.StreamErrorException;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
/**
* 当网络发生改变<由无网络变成有网络>的时候,会调用该类的重连线程 {@link #setNetWorkState(boolean)}-->重连{@link #reconnect()} 或 停止重连{@link #mReconnectionThread}{@link Thread#interrupt()};
*/
public class XReconnectionManager extends AbstractConnectionListener {
boolean mIsNetWorkActive;
// Holds the state of the reconnection
boolean doReconnecting = false;
private Context mContext;
private XMPPTCPConnection mConnection;
private boolean isReconnectionAllowed = false;
private Thread mReconnectionThread;
private ReconnectionManager mReconnectionManager;
public XReconnectionManager(Context context, XMPPTCPConnection connection, boolean reconnectionAllowed, boolean isNetWorkActive) {
mContext = context;
mConnection = connection;
mConnection.addConnectionListener(this);
isReconnectionAllowed = reconnectionAllowed;
mIsNetWorkActive = isNetWorkActive;
// 不自己重连,改为smack内部的自动重连
mReconnectionManager = ReconnectionManager.getInstanceFor(mConnection);
mReconnectionManager.enableAutomaticReconnection();
mReconnectionManager.setReconnectionPolicy(ReconnectionManager.ReconnectionPolicy.RANDOM_INCREASING_DELAY);
mReconnectionManager.addReconnectionListener(new ReconnectionListener() {
@Override
public void reconnectingIn(int seconds) {
Log.e("zq", "重连中..." + seconds);
}
@Override
public void reconnectionFailed(Exception e) {
Log.e("zq", "重连失败" + e.getMessage());
}
});
}
/**
* Returns true if the reconnection mechanism is enabled.
*
* @return true if automatic reconnections are allowed.
*/
private boolean isReconnectionAllowed() {
return doReconnecting && mIsNetWorkActive && !mConnection.isConnected() && isReconnectionAllowed;
}
public void setNetWorkState(boolean isNetWorkActive) {
mIsNetWorkActive = isNetWorkActive;
if (mIsNetWorkActive) {// 网络状态变为可用
if (isReconnectionAllowed()) {
reconnect();
}
} else {// 网络不可用,断开重连线程
if (mReconnectionThread != null && mReconnectionThread.isAlive()) {
mReconnectionThread.interrupt();
}
}
}
public void restartConnection() {
doReconnecting = true;
if (this.isReconnectionAllowed()) {
if (CoreService.DEBUG)
this.reconnect();
}
}
void release() {
doReconnecting = false;
if (mReconnectionThread != null && mReconnectionThread.isAlive()) {
mReconnectionThread.interrupt();
}
if (mReconnectionManager != null) {// 停止重连
mReconnectionManager.disableAutomaticReconnection();
}
}
/**
* Starts a reconnection mechanism if it was configured to do that. The algorithm is been executed when the first connection error is detected.
* <p/>
* The reconnection mechanism will try to reconnect periodically in this way:
* <ol>
* <li>First it will try 6 times every 10 seconds.
* <li>Then it will try 10 times every 1 minute.
* <li>Finally it will try indefinitely every 5 minutes.
* </ol>
*/
private synchronized void reconnect() {
// if (this.isReconnectionAllowed()) {
// // Since there is no thread running, creates a new one to attempt
// // the reconnection.
// // avoid to run duplicated reconnectionThread -- fd: 16/09/2010
// if (mReconnectionThread != null && mReconnectionThread.isAlive()) {
// return;
// }
// mReconnectionThread = new Thread() {
//
// private int mRandomBase = new Random().nextInt(11) + 5; // between 5 and 15 seconds
// /**
// * Holds the current number of reconnection attempts
// */
// private int attempts = 0;
//
// /**
// * Returns the number of seconds until the next reconnection attempt.
// *
// * @return the number of seconds until the next reconnection attempt.
// */
// private int timeDelay() {
// attempts++;
// if (attempts > 13) {
// return mRandomBase * 6 * 5; // between 2.5 and 7.5
// // minutes (~5 minutes)
// }
// if (attempts > 7) {
// return mRandomBase * 6; // between 30 and 90 seconds (~1
// // minutes)
// }
// return mRandomBase; // 10 seconds
// }
//
// /**
// * The process will try the reconnection until the connection succeed or the user cancel it
// */
// public void run() {
// Log.e("zq", "网络发生改变,开始重连");
// while (isReconnectionAllowed()) {
// // Makes a reconnection attempt
// try {
// if (isReconnectionAllowed()) {
// Log.e("zq", "网络发生改变,正在重连...");
// mConnection.connect();
// }
// } catch (Exception e) {
// notifyReconnectionFailed(e);// Fires the failed reconnection notification
// }
//
// int remainingSeconds = timeDelay();
// while (isReconnectionAllowed() && remainingSeconds > 0) {
// try {
// Thread.sleep(1000);
// remainingSeconds--;
// notifyAttemptToReconnectIn(remainingSeconds);
// } catch (InterruptedException e1) {
// // Notify the reconnection has failed
// notifyReconnectionFailed(e1);
// }
// }
// }
// }
// };
// mReconnectionThread.setName("Smack XReconnectionManager");
// mReconnectionThread.setDaemon(true);
// mReconnectionThread.start();
// }
}
private void notifyReconnectionFailed(Exception exception) {
/*
Log.e("zq", "网络发生改变,重连发生异常");
if (isReconnectionAllowed()) {
for (ConnectionListener listener : mConnection.getConnectionListeners()) {
listener.reconnectionFailed(exception);
}
}
*/
}
private void notifyAttemptToReconnectIn(int seconds) {
/*
if (isReconnectionAllowed()) {
for (ConnectionListener listener : mConnection.getConnectionListeners()) {
listener.reconnectingIn(seconds);
}
}
*/
}
private void conflict() {
((CoreService) mContext).logout();
MyApplication.getInstance().mUserStatus = LoginHelper.STATUS_USER_TOKEN_CHANGE;
// 弹出对话框
UserCheckedActivity.start(mContext);
// LoginHelper.broadcastConflict(mContext);
}
@Override
public void connectionClosed() {// 连接关闭,不允许自动重连
doReconnecting = false;
}
/**
* @param e
*/
@Override
public void connectionClosedOnError(Exception e) {
doReconnecting = true;
if (e instanceof StreamErrorException) {// 重复登录
StreamErrorException streamErrorException = (StreamErrorException) e;
StreamError streamError = streamErrorException.getStreamError();
if (streamError.getCondition().equals(StreamError.Condition.conflict)) {// 下线通知
if (CoreService.DEBUG)
Log.d(CoreService.TAG, "异常断开,有另外设备登陆啦");
conflict();
doReconnecting = false;
return;
}
}
// 因为其他原因导致下线,那么就开始重连
if (this.isReconnectionAllowed()) {
if (CoreService.DEBUG)
Log.d(CoreService.TAG, "异常断开,开始重连");
this.reconnect();
}
}
}
package com.xxfc.rv;
import android.text.TextUtils;
import com.sk.weichat.MyApplication;
import com.sk.weichat.bean.message.NewFriendMessage;
import com.sk.weichat.db.dao.ChatMessageDao;
import com.sk.weichat.ui.base.CoreManager;
import com.sk.weichat.util.log.LogUtils;
import com.sk.weichat.xmpp.listener.ChatMessageListener;
import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import de.greenrobot.event.EventBus;
import fm.jiecao.jcvideoplayer_lib.MessageEvent;
/**
* 消息发送出去后,判断服务端是否收到,服务端收到后将消息置为送达
*/
public class XServerReceivedListener implements StanzaListener {
private String mLoginUserId = CoreManager.requireSelf(MyApplication.getInstance()).getUserId();
@Override
public void processStanza(Stanza packet) {
// Message
if (packet instanceof Message) {
Message message = (Message) packet;
if (message.getType() == Message.Type.chat) {
LogUtils.e("msg", "单聊:" + message.getPacketID());
LogUtils.e("msg", "单聊:" + message.getBody());
} else if (message.getType() == Message.Type.groupchat) {
LogUtils.e("msg", "群聊:" + message.getPacketID());
LogUtils.e("msg", "群聊:" + message.getBody());
} else if (message.getType() == Message.Type.error) {
LogUtils.e("msg", "error:" + message.getPacketID());
LogUtils.e("msg", "error:" + message.getBody());
} else {
LogUtils.e("msg", "else:" + message.getPacketID());
LogUtils.e("msg", "else:" + message.getBody());
}
}
/*
// Presence
if (packet instanceof Presence) {
Presence presence = (Presence) packet;
LogUtils.e("msg", "表示接收到的是Presence包:" + presence.toString());
}
// IQ
if (packet instanceof IQ) {
IQ iq = (IQ) packet;
LogUtils.e("msg", "表示接收到的是IQ包:" + iq.toString());
}
*/
LogUtils.e("msg", "packet.getStanzaId():" + packet.getStanzaId());
if (TextUtils.isEmpty(packet.getStanzaId())) {
LogUtils.e("msg", "packet.getStanzaId() == Null Return");
return;
}
ReceiptManager.ReceiptObj mReceiptObj = ReceiptManager.mReceiptMap.get(packet.getStanzaId());
if (mReceiptObj != null) {
LogUtils.e("msg", "消息已送至服务器");
if (mReceiptObj.Read == 1) {// 已读消息 Type==26
if (mLoginUserId.equals(mReceiptObj.toUserId)) {
for (String s : MyApplication.machine) {
ChatMessageDao.getInstance().updateMessageRead(mLoginUserId, s, mReceiptObj.Read_msg_pid, true);
}
} else {
ChatMessageDao.getInstance().updateMessageRead(mLoginUserId, mReceiptObj.toUserId, mReceiptObj.Read_msg_pid, true);
}
} else {// 普通消息 && 新朋友消息
if (mReceiptObj.sendType == ReceiptManager.SendType.NORMAL) {
ListenerManager.getInstance().notifyMessageSendStateChange(mLoginUserId, mReceiptObj.toUserId, packet.getStanzaId(),
ChatMessageListener.MESSAGE_SEND_SUCCESS);
EventBus.getDefault().post(new MessageEvent(mReceiptObj.toUserId));
} else {
ListenerManager.getInstance().notifyNewFriendSendStateChange(mReceiptObj.toUserId, ((NewFriendMessage) mReceiptObj.msg),
ChatMessageListener.MESSAGE_SEND_SUCCESS);
}
}
ReceiptManager.mReceiptMap.remove(packet.getStanzaId());
}
}
}
This diff is collapsed.
package com.xxfc.rv.bean;
import com.alibaba.fastjson.annotation.JSONField;
public class AttentionUser {
private int blacklist; // 0 表示不是黑名单,1表示是在黑名单
private int isBeenBlack;// 1表示对方将我拉入黑名单
private int status;
private String userId;// 发起关注的人
private String toUserId;// 被关注的人
private int toUserType;// 2 公众号
@JSONField(name = "toNickname")
private String toNickName;
private String remarkName;
private String describe;
private int offlineNoPushMsg;// 消息免打扰
private double chatRecordTimeOut;//0 || -1 消息永久保存 单位:day
private int createTime;
private int modifyTime;// 修改时间
private int groupId;// 分组Id
private String groupName;// 分组名称
private int companyId;
public int getBlacklist() {
return blacklist;
}
public void setBlacklist(int blacklist) {
this.blacklist = blacklist;
}
public int getIsBeenBlack() {
return isBeenBlack;
}
public void setIsBeenBlack(int isBeenBlack) {
this.isBeenBlack = isBeenBlack;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getToUserId() {
return toUserId;
}
public void setToUserId(String toUserId) {
this.toUserId = toUserId;
}
public int getToUserType() {
return toUserType;
}
public void setToUserType(int toUserType) {
this.toUserType = toUserType;
}
public String getToNickName() {
return toNickName;
}
public void setToNickName(String toNickName) {
this.toNickName = toNickName;
}
public String getRemarkName() {
return remarkName;
}
public void setRemarkName(String remarkName) {
this.remarkName = remarkName;
}
public int getOfflineNoPushMsg() {
return offlineNoPushMsg;
}
public void setOfflineNoPushMsg(int offlineNoPushMsg) {
this.offlineNoPushMsg = offlineNoPushMsg;
}
public double getChatRecordTimeOut() {
return chatRecordTimeOut;
}
public void setChatRecordTimeOut(double chatRecordTimeOut) {
this.chatRecordTimeOut = chatRecordTimeOut;
}
public int getCreateTime() {
return createTime;
}
public void setCreateTime(int createTime) {
this.createTime = createTime;
}
public int getModifyTime() {
return modifyTime;
}
public void setModifyTime(int modifyTime) {
this.modifyTime = modifyTime;
}
public int getGroupId() {
return groupId;
}
public void setGroupId(int groupId) {
this.groupId = groupId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public int getCompanyId() {
return companyId;
}
public void setCompanyId(int companyId) {
this.companyId = companyId;
}
public String getDescribe() {
return describe;
}
public void setDescribe(String describe) {
this.describe = describe;
}
}
package com.xxfc.rv.bean;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import com.xxfc.rv.utils.StringUtils;
import java.io.Serializable;
@DatabaseTable
public class Company implements Serializable, Cloneable {
private static final long serialVersionUID = -320509115872200611L;
@DatabaseField(id = true)
private int id;// 公司Id
@DatabaseField
private String name;// 公司名称
@DatabaseField
private int industryId;// 公司行业
@DatabaseField
private int natureId;// 公司性质
@DatabaseField
private int scale;// 公司规模
@DatabaseField
private String description;// 公司说明
@DatabaseField
private String website;// 公司主页
@DatabaseField
private int countryId;// 国家
@DatabaseField
private int provinceId;// 省份
@DatabaseField
private int cityId;// 城市
@DatabaseField
private int areaId;// 地区
@DatabaseField
private int createTime;// 创建时间
@DatabaseField
private int isAuth;
// 用户信息集合
// @ForeignCollectionField(eager = false)
// private ForeignCollection<User> users;
@DatabaseField
private double longitude;// 经度
@DatabaseField
private double latitude;// 纬度
@DatabaseField
private String address;// 详细地址
@DatabaseField
private float total;// 累计充值金钱的总数
@DatabaseField
private float balance;// 可用的金钱总数
@DatabaseField
private int payMode;// 支付的方式,
@DatabaseField
private long payEndTime;// 包年包月结束时间
@DatabaseField
private int status;// 1、正常
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getIndustryId() {
return industryId;
}
public void setIndustryId(int industryId) {
this.industryId = industryId;
}
public int getNatureId() {
return natureId;
}
public void setNatureId(int natureId) {
this.natureId = natureId;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
public int getCountryId() {
return countryId;
}
public void setCountryId(int countryId) {
this.countryId = countryId;
}
public int getProvinceId() {
return provinceId;
}
public void setProvinceId(int provinceId) {
this.provinceId = provinceId;
}
public int getCityId() {
return cityId;
}
public void setCityId(int cityId) {
this.cityId = cityId;
}
public int getAreaId() {
return areaId;
}
public void setAreaId(int areaId) {
this.areaId = areaId;
}
public int getScale() {
return scale;
}
public void setScale(int scale) {
this.scale = scale;
}
public int getCreateTime() {
return createTime;
}
public void setCreateTime(int createTime) {
this.createTime = createTime;
}
public int getIsAuth() {
return isAuth;
}
public void setIsAuth(int isAuth) {
this.isAuth = isAuth;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public float getTotal() {
return total;
}
public void setTotal(float total) {
this.total = total;
}
public float getBalance() {
return balance;
}
public void setBalance(float balance) {
this.balance = balance;
}
public int getPayMode() {
return payMode;
}
public void setPayMode(int payMode) {
this.payMode = payMode;
}
public long getPayEndTime() {
return payEndTime;
}
public void setPayEndTime(long payEndTime) {
this.payEndTime = payEndTime;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
@Override
public boolean equals(Object o) {
if (o == null || !(o instanceof Company)) {
return false;
}
if (o == this) {
return true;
}
Company other = (Company) o;
boolean equals = true;
equals &= id == other.id;
equals &= StringUtils.strEquals(name, other.name);
equals &= industryId == other.industryId;
equals &= natureId == other.natureId;
equals &= scale == other.scale;
equals &= StringUtils.strEquals(description, other.description);
equals &= StringUtils.strEquals(website, other.website);
equals &= countryId == other.countryId;
equals &= provinceId == other.provinceId;
equals &= cityId == other.cityId;
equals &= areaId == other.areaId;
equals &= createTime == other.createTime;
equals &= isAuth == other.isAuth;
equals &= longitude == other.longitude;
equals &= latitude == other.latitude;
equals &= StringUtils.strEquals(address, other.address);
equals &= total == other.total;
equals &= balance == other.balance;
equals &= payMode == other.payMode;
equals &= payEndTime == other.payEndTime;
equals &= status == other.status;
return equals;
}
}
This diff is collapsed.
This diff is collapsed.
package com.xxfc.rv.broadcast;
import android.content.Context;
import android.content.Intent;
import com.xxfc.rv.AppConfig;
/**
* 用于聊天消息的广播,更新MainActivity Tab栏显示的未读数量 和 消息界面数据的更新
*/
public class MsgBroadcast {
public static final String ACTION_MSG_UI_UPDATE = AppConfig.sPackageName + ".action.msg_ui_update";// 消息界面的更新
public static final String ACTION_MSG_NUM_UPDATE = AppConfig.sPackageName + ".intent.action.msg_num_update";// 未读数量的更新
public static final String ACTION_MSG_NUM_UPDATE_NEW_FRIEND = AppConfig.sPackageName + ".intent.action.msg_num_update_new_friend";// 新的朋友 未读数量的更新
public static final String ACTION_MSG_NUM_RESET = AppConfig.sPackageName + ".action.msg_num_reset";// 未读数量需要重置,即从数据库重新查
public static final String EXTRA_NUM_COUNT = "count";
public static final String EXTRA_NUM_OPERATION = "operation";
public static final int NUM_ADD = 0; // 消息加
public static final int NUM_REDUCE = 1; // 消息减
public static final String ACTION_MSG_STATE_UPDATE = AppConfig.sPackageName + ".action.CHANGE_MESSAGE_STATE"; // 通知某条消息改变
public static final String ACTION_DISABLE_GROUP_BY_SERVICE = AppConfig.sPackageName + ".action.disable_group_by_service"; // 群组被锁定/解锁
public static final String ACTION_FACE_GROUP_NOTIFY = AppConfig.sPackageName + ".action.face_group_notify"; // 面对面建群界面广播
public static final String EXTRA_OPERATING = "EXTRA_OPERATING";
public static final String ACTION_MSG_UPDATE_ROOM = AppConfig.sPackageName + ".action.msg_room_update"; // 聊天群组界面的更新
public static final String ACTION_MSG_ROLE_CHANGED = AppConfig.sPackageName + ".action.ROLE_CHANGED";
public static final String ACTION_MSG_UPDATE_ROOM_GET_ROOM_STATUS = AppConfig.sPackageName + ".action.msg_room_update_get_room_status"; // 聊天群组界面的更新并调用群属性接口
public static final String ACTION_MSG_CLOSE_TRILL = AppConfig.sPackageName + ".action.colse_trill"; // 关闭抖音模块
public static final String ACTION_MSG_UPDATE_ROOM_INVITE = AppConfig.sPackageName + ".action.msg_room_update_invite"; // 群组信息界面更新允许群成员邀请好友,
public static final String EXTRA_ENABLED = "EXTRA_ENABLED";
/**
* 更新消息Fragment的广播
*/
public static void broadcastMsgUiUpdate(Context context) {
context.sendBroadcast(new Intent(ACTION_MSG_UI_UPDATE));
}
public static void broadcastMsgNumUpdate(Context context, boolean add, int count) {
Intent intent = new Intent(ACTION_MSG_NUM_UPDATE);
intent.putExtra(EXTRA_NUM_COUNT, count);
if (add) {
intent.putExtra(EXTRA_NUM_OPERATION, NUM_ADD);
} else {
intent.putExtra(EXTRA_NUM_OPERATION, NUM_REDUCE);
}
context.sendBroadcast(intent);
}
public static void broadcastMsgNumUpdateNewFriend(Context context) {
Intent intent = new Intent(ACTION_MSG_NUM_UPDATE_NEW_FRIEND);
context.sendBroadcast(intent);
}
public static void broadcastMsgNumReset(Context context) {
context.sendBroadcast(new Intent(ACTION_MSG_NUM_RESET));
}
public static void broadcastMsgReadUpdate(Context context, String packetId) {
Intent intent = new Intent(ACTION_MSG_STATE_UPDATE);
intent.putExtra("packetId", packetId);
context.sendBroadcast(intent);
}
/**
* 群组有关广播
*
* @param context
*/
public static void broadcastMsgRoomUpdate(Context context) {
context.sendBroadcast(new Intent(ACTION_MSG_UPDATE_ROOM));
}
public static void broadcastMsgRoleChanged(Context context) {
context.sendBroadcast(new Intent(ACTION_MSG_ROLE_CHANGED));
}
public static void broadcastMsgRoomUpdateGetRoomStatus(Context context) {
context.sendBroadcast(new Intent(ACTION_MSG_UPDATE_ROOM_GET_ROOM_STATUS));
}
public static void broadcastMsgRoomUpdateInvite(Context context, int enabled) {
Intent intent = new Intent(ACTION_MSG_UPDATE_ROOM_INVITE);
intent.putExtra(EXTRA_ENABLED, enabled);
context.sendBroadcast(intent);
}
public static void broadcastFaceGroupNotify(Context context, String operating) {
Intent intent = new Intent(ACTION_FACE_GROUP_NOTIFY);
intent.putExtra(EXTRA_OPERATING, operating);
context.sendBroadcast(intent);
}
public static void broadcastMsgColseTrill(Context context) {
context.sendBroadcast(new Intent(ACTION_MSG_CLOSE_TRILL));
}
}
package com.xxfc.rv.broadcast;
import com.sk.weichat.AppConfig;
/**
* 项目老代码中大量广播都是写死action,统一移到这里,改成包名开头,
*/
public class OtherBroadcast {
public static final String Read = AppConfig.sPackageName + "Read";
public static final String NAME_CHANGE = AppConfig.sPackageName + "NAME_CHANGE";
public static final String TYPE_DELALL = AppConfig.sPackageName + "TYPE_DELALL";
public static final String SEND_MULTI_NOTIFY = AppConfig.sPackageName + "SEND_MULTI_NOTIFY";
public static final String CollectionRefresh = AppConfig.sPackageName + "CollectionRefresh";
public static final String NO_EXECUTABLE_INTENT = AppConfig.sPackageName + "NO_EXECUTABLE_INTENT";
public static final String QC_FINISH = AppConfig.sPackageName + "QC_FINISH";
public static final String longpress = AppConfig.sPackageName + "longpress";
public static final String FINISH_MAIN = AppConfig.sPackageName + "FINISH_MAIN";
public static final String IsRead = AppConfig.sPackageName + "IsRead";
public static final String MULTI_LOGIN_READ_DELETE = AppConfig.sPackageName + "MULTI_LOGIN_READ_DELETE";
public static final String TYPE_INPUT = AppConfig.sPackageName + "TYPE_INPUT";
public static final String MSG_BACK = AppConfig.sPackageName + "MSG_BACK";
public static final String REFRESH_MANAGER = AppConfig.sPackageName + "REFRESH_MANAGER";
public static final String singledown = AppConfig.sPackageName + "singledown";
}
package com.xxfc.rv.db.dao;
import android.text.TextUtils;
import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.dao.GenericRawResults;
import com.j256.ormlite.stmt.QueryBuilder;
import com.sk.weichat.MyApplication;
import com.sk.weichat.R;
import com.sk.weichat.bean.Area;
import com.sk.weichat.db.SQLiteHelper;
import java.sql.SQLException;
import java.util.List;
public class AreasDao {
private static AreasDao instance = null;
public static AreasDao getInstance() {
if (instance == null) {
synchronized (AreasDao.class) {
if (instance == null) {
instance = new AreasDao();
}
}
}
return instance;
}
public Dao<Area, Integer> dao;
private AreasDao() {
try {
dao = DaoManager
.createDao(OpenHelperManager.getHelper(MyApplication.getInstance(), SQLiteHelper.class).getConnectionSource(), Area.class);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
protected void finalize() throws Throwable {
super.finalize();
OpenHelperManager.releaseHelper();
}
public Area getArea(int id) {
try {
return dao.queryForId(id);
} catch (SQLException e) {
e.printStackTrace();
}
return mDefaultAreas;
}
public Area mDefaultAreas;
{
mDefaultAreas = new Area();
mDefaultAreas.setId(0);
mDefaultAreas.setName(MyApplication.getInstance().getString(R.string.unknown));
}
/**
* 根据Type查询
*
* @param type
* @return
*/
public List<Area> getAreasByTypeAndParentId(int type, int id) {
QueryBuilder<Area, Integer> builder = dao.queryBuilder();
try {
if (id <= 0) {
builder.where().eq("type", type);
} else {
builder.where().eq("type", type).and().eq("parent_id", id);
}
return dao.query(builder.prepare());
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
/**
* 根据Type查询
*
* @param id
* @return
*/
public boolean hasSubAreas(int id) {
try {
QueryBuilder<Area, Integer> builder = dao.queryBuilder();
builder.setCountOf(true);
builder.where().eq("parent_id", id);
GenericRawResults<String[]> results = dao.queryRaw(builder.prepareStatementString());
if (results != null) {
String[] first = results.getFirstResult();
if (first != null && first.length > 0) {
return Integer.parseInt(first[0]) > 0 ? true : false;
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
public Area searchByName(String likeName) {
try {
QueryBuilder<Area, Integer> builder = dao.queryBuilder();
builder.where().like("name", likeName);
return dao.queryForFirst(builder.prepare());
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public Area searchByNameAndParentId(int parentId, String likeName) {
try {
QueryBuilder<Area, Integer> builder = dao.queryBuilder();
if (TextUtils.isEmpty(likeName)) {
builder.where().eq("parent_id", parentId);
} else {
builder.where().like("name", likeName).and().eq("parent_id", parentId);
}
Area area = dao.queryForFirst(builder.prepare());
if (area == null && !TextUtils.isEmpty(likeName)) {
QueryBuilder<Area, Integer> builder2 = dao.queryBuilder();
builder2.where().eq("parent_id", parentId);
area = dao.queryForFirst(builder.prepare());
}
return area;
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
}
This diff is collapsed.
package com.xxfc.rv.db.dao;
import com.j256.ormlite.dao.BaseDaoImpl;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.DatabaseTableConfig;
import com.sk.weichat.bean.message.ChatMessage;
import java.sql.SQLException;
public class ChatMessageDaoImpl extends BaseDaoImpl<ChatMessage, Integer> {
public ChatMessageDaoImpl(ConnectionSource connectionSource, DatabaseTableConfig<ChatMessage> tableConfig) throws SQLException {
super(connectionSource, tableConfig);
}
}
package com.xxfc.rv.db.dao;
import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.stmt.DeleteBuilder;
import com.j256.ormlite.stmt.PreparedQuery;
import com.sk.weichat.MyApplication;
import com.sk.weichat.bean.Contact;
import com.sk.weichat.db.SQLiteHelper;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* 访问手机联系人的Dao
*/
public class ContactDao {
private static ContactDao instance = null;
public static ContactDao getInstance() {
if (instance == null) {
synchronized (ContactDao.class) {
if (instance == null) {
instance = new ContactDao();
}
}
}
return instance;
}
public Dao<Contact, Integer> contactDao;
private ContactDao() {
try {
contactDao = DaoManager.createDao(OpenHelperManager.getHelper(MyApplication.getInstance(), SQLiteHelper.class).getConnectionSource(),
Contact.class);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
protected void finalize() throws Throwable {
super.finalize();
OpenHelperManager.releaseHelper();
}
// 创建联系人
public boolean createContact(Contact contact) {
try {
List<Contact> mContactsByToUserId = getContactsByToUserId(contact.getUserId(), contact.getToUserId());
if (mContactsByToUserId != null && mContactsByToUserId.size() > 0) {
return false;
}
contactDao.create(contact);
return true;
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
// 删除联系人
public void deleteContact(String ownerId, String toUserId) {
try {
DeleteBuilder<Contact, Integer> builder = contactDao.deleteBuilder();
builder.where().eq("userId", ownerId).and().eq("toUserId", toUserId);
contactDao.delete(builder.prepare());
} catch (SQLException e) {
e.printStackTrace();
}
}
// 获取ownerId用户的所有联系人
public List<Contact> getAllContacts(String ownerId) {
List<Contact> contacts = new ArrayList<>();
try {
PreparedQuery<Contact> preparedQuery = contactDao.queryBuilder().where()
.eq("userId", ownerId)
.prepare();
contacts = contactDao.query(preparedQuery);
} catch (SQLException e) {
e.printStackTrace();
}
return contacts;
}
// 获取ownerId下指定id的联系人
public List<Contact> getContactsByToUserId(String ownerId, String toUserId) {
try {
PreparedQuery<Contact> preparedQuery = contactDao.queryBuilder().where()
.eq("userId", ownerId).and()
.eq("toUserId", toUserId)
.prepare();
return contactDao.query(preparedQuery);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public void refreshContact(String ownerId, List<Contact> contacts) {
// 1.清空本地
List<Contact> contactListFromLocal = getAllContacts(ownerId);
for (Contact contact : contactListFromLocal) {
deleteContact(ownerId, contact.getToUserId());
}
// 2.将服务端数据存入本地
for (Contact contact : contacts) {
createContact(contact);
}
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
package com.xxfc.rv.db.dao;
public interface OnCompleteListener {
void onCompleted();
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<resources>
<string name="app_name">plugin_im</string>
<string name="tip_crash">很抱歉,程序出现异常,即将重启.</string>
</resources>
This diff is collapsed.
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