Commit 33c1802f authored by Leonardo Aramaki's avatar Leonardo Aramaki

Pack of fixes for crashes on last versions released on Beta

parent 07e15c9e
...@@ -4,48 +4,67 @@ import android.os.Build; ...@@ -4,48 +4,67 @@ import android.os.Build;
import android.support.multidex.MultiDexApplication; import android.support.multidex.MultiDexApplication;
import android.support.v7.app.AppCompatDelegate; import android.support.v7.app.AppCompatDelegate;
import chat.rocket.android.helper.OkHttpHelper;
import com.crashlytics.android.Crashlytics; import com.crashlytics.android.Crashlytics;
import chat.rocket.android_ddp.DDPClient;
import io.fabric.sdk.android.Fabric;
import java.util.List; import java.util.List;
import chat.rocket.persistence.realm.RealmStore; import java.util.concurrent.TimeoutException;
import chat.rocket.android.helper.Logger;
import chat.rocket.android.helper.OkHttpHelper;
import chat.rocket.android.log.RCLog;
import chat.rocket.android.service.ConnectivityManager; import chat.rocket.android.service.ConnectivityManager;
import chat.rocket.core.models.ServerInfo;
import chat.rocket.android.widget.RocketChatWidgets; import chat.rocket.android.widget.RocketChatWidgets;
import chat.rocket.android_ddp.DDPClient;
import chat.rocket.core.models.ServerInfo;
import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.persistence.realm.RocketChatPersistenceRealm; import chat.rocket.persistence.realm.RocketChatPersistenceRealm;
import io.fabric.sdk.android.Fabric;
import io.reactivex.exceptions.UndeliverableException;
import io.reactivex.plugins.RxJavaPlugins;
/** /**
* Customized Application-class for Rocket.Chat * Customized Application-class for Rocket.Chat
*/ */
public class RocketChatApplication extends MultiDexApplication { public class RocketChatApplication extends MultiDexApplication {
private static RocketChatApplication instance; private static RocketChatApplication instance;
public static RocketChatApplication getInstance() { public static RocketChatApplication getInstance() {
return instance; return instance;
} }
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
DDPClient.initialize(OkHttpHelper.INSTANCE.getClientForWebSocket()); DDPClient.initialize(OkHttpHelper.INSTANCE.getClientForWebSocket());
Fabric.with(this, new Crashlytics()); Fabric.with(this, new Crashlytics());
RocketChatPersistenceRealm.init(this); RocketChatPersistenceRealm.init(this);
List<ServerInfo> serverInfoList = ConnectivityManager.getInstance(this).getServerList(); List<ServerInfo> serverInfoList = ConnectivityManager.getInstance(this).getServerList();
for (ServerInfo serverInfo : serverInfoList) { for (ServerInfo serverInfo : serverInfoList) {
RealmStore.put(serverInfo.getHostname()); RealmStore.put(serverInfo.getHostname());
} }
RocketChatWidgets.initialize(this, OkHttpHelper.INSTANCE.getClientForDownloadFile(this)); RocketChatWidgets.initialize(this, OkHttpHelper.INSTANCE.getClientForDownloadFile(this));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
} }
RxJavaPlugins.setErrorHandler(e -> {
if (e instanceof UndeliverableException) {
e = e.getCause();
}
if (e instanceof TimeoutException) {
// Some work timed-out after a server change is most probable.
return;
}
instance = this; Thread.currentThread().getUncaughtExceptionHandler()
} .uncaughtException(Thread.currentThread(), e);
});
instance = this;
}
} }
\ No newline at end of file
...@@ -7,10 +7,13 @@ import android.view.ViewGroup ...@@ -7,10 +7,13 @@ import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.helper.DateTime import chat.rocket.android.helper.DateTime
import chat.rocket.android.helper.Logger
import chat.rocket.android.log.RCLog
import chat.rocket.android.widget.message.RocketChatMessageAttachmentsLayout import chat.rocket.android.widget.message.RocketChatMessageAttachmentsLayout
import chat.rocket.core.models.Attachment import chat.rocket.core.models.Attachment
import kotlinx.android.synthetic.main.day.view.* import kotlinx.android.synthetic.main.day.view.*
import kotlinx.android.synthetic.main.item_room_file.view.* import kotlinx.android.synthetic.main.item_room_file.view.*
import java.lang.IllegalArgumentException
import java.sql.Timestamp import java.sql.Timestamp
/** /**
...@@ -26,8 +29,16 @@ class RoomFileListAdapter(private var dataSet: List<Attachment>) : RecyclerView. ...@@ -26,8 +29,16 @@ class RoomFileListAdapter(private var dataSet: List<Attachment>) : RecyclerView.
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val attachment = dataSet[position] val attachment = dataSet[position]
holder.newDay.text = DateTime.fromEpocMs(Timestamp.valueOf(attachment.timestamp).time, DateTime.Format.DATE) val timestamp: Timestamp?
holder.attachment.appendAttachmentView(attachment, true, false) try {
timestamp = Timestamp.valueOf(attachment.timestamp)
// If we don't have a timestamp we can parse let's be safe and stop here.
holder.newDay.text = DateTime.fromEpocMs(timestamp.time, DateTime.Format.DATE)
holder.attachment.appendAttachmentView(attachment, true, false)
} catch (e: IllegalArgumentException) {
RCLog.e(e)
Logger.report(e)
}
} }
override fun getItemCount(): Int = dataSet.size override fun getItemCount(): Int = dataSet.size
......
...@@ -105,7 +105,10 @@ object PushManager { ...@@ -105,7 +105,10 @@ object PushManager {
} }
} }
fun clearNotificationsByHostAndNotificationId(host: String, notificationId: Int) { fun clearNotificationsByHostAndNotificationId(host: String?, notificationId: Int?) {
if (host == null || notificationId == null) {
return
}
if (hostToPushMessageList.isNotEmpty()) { if (hostToPushMessageList.isNotEmpty()) {
val notifications = hostToPushMessageList[host] val notifications = hostToPushMessageList[host]
notifications?.let { notifications?.let {
......
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