Fixed visualization of the overlay header when there is no connection

This commit is contained in:
mscg82 2014-06-08 13:42:32 +02:00
parent 9094871824
commit 576ca6c23e
4 changed files with 61 additions and 13 deletions

View file

@ -0,0 +1,39 @@
/*
* This is the source code of Telegram for Android v. 1.4.x.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.messenger;
import java.util.ArrayList;
import java.util.Collection;
public class ChangeAwareArrayList<T> extends ArrayList<T> {
protected int oldModCount;
public ChangeAwareArrayList() {
oldModCount = modCount;
}
public ChangeAwareArrayList(int capacity) {
super(capacity);
oldModCount = modCount;
}
public ChangeAwareArrayList(Collection<? extends T> collection) {
super(collection);
oldModCount = modCount;
}
public boolean peekIsChanged() {
return oldModCount != modCount;
}
public boolean isChanged() {
boolean ret = peekIsChanged();
oldModCount = modCount;
return ret;
}
}

View file

@ -83,6 +83,9 @@ public class TcpConnection extends ConnectionContext {
public void connect() {
if(!ConnectionsManager.isNetworkOnline() && !tryWithNoNetworkAnyway) {
FileLog.d("tmessages", "Connection is not available, skipping task scheduling");
notifyConnectionError();
return;
}
@ -155,6 +158,19 @@ public class TcpConnection extends ConnectionContext {
});
}
protected void notifyConnectionError() {
connectionState = TcpConnectionState.TcpConnectionStageReconnecting;
if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
finalDelegate.tcpConnectionClosed(TcpConnection.this);
}
});
}
}
private void handleConnectionError(Exception e) {
try {
synchronized (timerSync) {
@ -166,16 +182,8 @@ public class TcpConnection extends ConnectionContext {
} catch (Exception e2) {
FileLog.e("tmessages", e2);
}
connectionState = TcpConnectionState.TcpConnectionStageReconnecting;
if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
finalDelegate.tcpConnectionClosed(TcpConnection.this);
}
});
}
notifyConnectionError();
failedConnectionCount++;
if (failedConnectionCount == 1) {

View file

@ -680,8 +680,8 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
onFinish();
}
} else if (id == 703) {
int state = (Integer)args[0];
if (currentConnectionState != state) {
if (fragmentsStack.isChanged()) {
int state = (Integer)args[0];
FileLog.e("tmessages", "switch to state " + state);
currentConnectionState = state;
updateActionBar();

View file

@ -31,6 +31,7 @@ import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import org.telegram.messenger.ChangeAwareArrayList;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
@ -90,7 +91,7 @@ public class ActionBarActivity extends Activity {
}
}
public static ArrayList<BaseFragment> fragmentsStack = new ArrayList<BaseFragment>();
public static ChangeAwareArrayList<BaseFragment> fragmentsStack = new ChangeAwareArrayList<BaseFragment>();
protected void onCreateFinish(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);