mirror of
https://github.com/ChronosX88/Influence.git
synced 2024-11-09 12:01:01 +00:00
Fixed minor bug with user presence system
This commit is contained in:
parent
0c99ac4db1
commit
33a8289177
@ -128,6 +128,9 @@ public class XMPPConnection implements ConnectionListener {
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(AppHelper.isIsMainActivityDestroyed()) {
|
||||
sendUserPresence(new Presence(Presence.Type.unavailable));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,7 @@ public class AppHelper extends MultiDexApplication {
|
||||
private static LoginCredentials currentLoginCredentials;
|
||||
private static Handler mainUIThreadHandler;
|
||||
private static ServiceConnection serviceConnection;
|
||||
private static boolean isMainActivityDestroyed = true;
|
||||
public final static Map<String, byte[]> avatarsCache = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
@ -140,4 +141,12 @@ public class AppHelper extends MultiDexApplication {
|
||||
public static ServiceConnection getServiceConnection() {
|
||||
return serviceConnection;
|
||||
}
|
||||
|
||||
public static boolean isIsMainActivityDestroyed() {
|
||||
return isMainActivityDestroyed;
|
||||
}
|
||||
|
||||
public static void setIsMainActivityDestroyed(boolean isMainActivityDestroyed) {
|
||||
AppHelper.isMainActivityDestroyed = isMainActivityDestroyed;
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
package io.github.chronosx88.influence.presenters
|
||||
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import io.github.chronosx88.influence.R
|
||||
import io.github.chronosx88.influence.contracts.CoreContracts
|
||||
import io.github.chronosx88.influence.helpers.AppHelper
|
||||
@ -27,6 +28,7 @@ import io.github.chronosx88.influence.models.appEvents.NewChatEvent
|
||||
import io.github.chronosx88.influence.views.LoginActivity
|
||||
import java9.util.concurrent.CompletableFuture
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
@ -74,6 +76,17 @@ class MainPresenter(private val view: CoreContracts.IMainViewContract) : CoreCon
|
||||
|
||||
override fun onStart() {
|
||||
EventBus.getDefault().register(this)
|
||||
GlobalScope.launch {
|
||||
var count = 0
|
||||
while(AppHelper.getXmppConnection() == null && count <= 10) {
|
||||
delay(1000)
|
||||
count++
|
||||
}
|
||||
if(AppHelper.getXmppConnection() != null) {
|
||||
AppHelper.getXmppConnection().sendUserPresence(Presence(Presence.Type.available))
|
||||
}
|
||||
}
|
||||
AppHelper.setIsMainActivityDestroyed(false)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
@ -82,10 +95,16 @@ class MainPresenter(private val view: CoreContracts.IMainViewContract) : CoreCon
|
||||
|
||||
override fun onDestroy() {
|
||||
GlobalScope.launch {
|
||||
var count = 0
|
||||
// Wait for connection will not be null
|
||||
while(AppHelper.getXmppConnection() == null && count <= 10) {
|
||||
delay(1000)
|
||||
count++
|
||||
}
|
||||
if(AppHelper.getXmppConnection() != null) {
|
||||
if(AppHelper.getXmppConnection().isConnectionAlive)
|
||||
AppHelper.getXmppConnection().sendUserPresence(Presence(Presence.Type.unavailable))
|
||||
}
|
||||
}
|
||||
AppHelper.setIsMainActivityDestroyed(true)
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import io.github.chronosx88.influence.R;
|
||||
import io.github.chronosx88.influence.contracts.CoreContracts;
|
||||
import io.github.chronosx88.influence.helpers.AppHelper;
|
||||
import io.github.chronosx88.influence.presenters.MainPresenter;
|
||||
import io.github.chronosx88.influence.views.fragments.DialogListFragment;
|
||||
import io.github.chronosx88.influence.views.fragments.SettingsFragment;
|
||||
@ -96,6 +97,7 @@ public class MainActivity extends AppCompatActivity implements CoreContracts.IMa
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
|
||||
presenter.initConnection();
|
||||
AppHelper.setIsMainActivityDestroyed(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user