aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2015-02-17 14:18:35 +0100
committeriNPUTmice <daniel@gultsch.de>2015-02-17 14:18:35 +0100
commita8ec36cda816e37fae5abf4a5947872cbe834fdc (patch)
tree5f6926dd60294e3304f39739b28f4c8382ee8947
parent67d5ee6b71d036206df03ec09f6188f2fe2f5918 (diff)
limit ui refresh rate
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/Config.java3
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java19
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java22
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationActivity.java49
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java15
-rw-r--r--src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java25
-rw-r--r--src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java12
-rw-r--r--src/main/java/eu/siacs/conversations/ui/XmppActivity.java29
8 files changed, 81 insertions, 93 deletions
diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java
index d8b3139e..5dc7c207 100644
--- a/src/main/java/eu/siacs/conversations/Config.java
+++ b/src/main/java/eu/siacs/conversations/Config.java
@@ -21,7 +21,8 @@ public final class Config {
public static final int PAGE_SIZE = 50;
public static final int MAX_NUM_PAGES = 3;
- public static final int PROGRESS_UI_UPDATE_INTERVAL = 750;
+ public static final int PROGRESS_UI_UPDATE_INTERVAL = 750;
+ public static final int REFRESH_UI_INTERVAL = 500;
public static final boolean NO_PROXY_LOOKUP = false; //useful to debug ibb
diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
index 6a8ee024..e4bfd6ff 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
@@ -144,24 +144,17 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
@Override
public void onConversationUpdate() {
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- updateView();
- }
- });
+ refreshUi();
}
@Override
public void onMucRosterUpdate() {
- runOnUiThread(new Runnable() {
+ refreshUi();
+ }
- @Override
- public void run() {
- updateView();
- }
- });
+ @Override
+ protected void refreshUiReal() {
+ updateView();
}
@Override
diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
index fda0c617..40a4587c 100644
--- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
@@ -139,26 +139,18 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
@Override
public void onRosterUpdate() {
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- invalidateOptionsMenu();
- populateView();
- }
- });
+ refreshUi();
}
@Override
public void onAccountUpdate() {
- runOnUiThread(new Runnable() {
+ refreshUi();
+ }
- @Override
- public void run() {
- invalidateOptionsMenu();
- populateView();
- }
- });
+ @Override
+ protected void refreshUiReal() {
+ invalidateOptionsMenu();
+ populateView();
}
@Override
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
index 1b5f76f0..118f6dd2 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
@@ -1006,56 +1006,39 @@ public class ConversationActivity extends XmppActivity
}
@Override
- public void onAccountUpdate() {
- runOnUiThread(new Runnable() {
+ protected void refreshUiReal() {
+ updateConversationList();
+ if (conversationList.size() == 0) {
+ startActivity(new Intent(getApplicationContext(),
+ StartConversationActivity.class));
+ finish();
+ }
+ ConversationActivity.this.mConversationFragment.updateMessages();
+ updateActionBarTitle();
+ }
- @Override
- public void run() {
- updateConversationList();
- ConversationActivity.this.mConversationFragment.updateMessages();
- updateActionBarTitle();
- }
- });
+ @Override
+ public void onAccountUpdate() {
+ this.refreshUi();
}
@Override
public void onConversationUpdate() {
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- updateConversationList();
- if (conversationList.size() == 0) {
- startActivity(new Intent(getApplicationContext(),
- StartConversationActivity.class));
- finish();
- }
- ConversationActivity.this.mConversationFragment.updateMessages();
- updateActionBarTitle();
- }
- });
+ this.refreshUi();
}
@Override
public void onRosterUpdate() {
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- updateConversationList();
- ConversationActivity.this.mConversationFragment.updateMessages();
- updateActionBarTitle();
- }
- });
+ this.refreshUi();
}
@Override
public void OnUpdateBlocklist(Status status) {
+ this.refreshUi();
runOnUiThread(new Runnable() {
@Override
public void run() {
invalidateOptionsMenu();
- ConversationActivity.this.mConversationFragment.updateMessages();
}
});
}
diff --git a/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java
index b3ab5ee6..b2d5ddfd 100644
--- a/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java
@@ -32,18 +32,17 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
@Override
public void onAccountUpdate() {
+ refreshUi();
+ }
+
+ @Override
+ protected void refreshUiReal() {
synchronized (this.accountList) {
accountList.clear();
accountList.addAll(xmppConnectionService.getAccounts());
}
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- invalidateOptionsMenu();
- mAccountAdapter.notifyDataSetChanged();
- }
- });
+ invalidateOptionsMenu();
+ mAccountAdapter.notifyDataSetChanged();
}
@Override
diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
index ff46ffd8..2e16d8e7 100644
--- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
@@ -176,15 +176,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
@Override
public void onRosterUpdate() {
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- if (mSearchEditText != null) {
- filter(mSearchEditText.getText().toString());
- }
- }
- });
+ this.refreshUi();
}
@Override
@@ -711,15 +703,14 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
@Override
public void OnUpdateBlocklist(final Status status) {
- runOnUiThread(new Runnable() {
+ refreshUi();
+ }
- @Override
- public void run() {
- if (mSearchEditText != null) {
- filter(mSearchEditText.getText().toString());
- }
- }
- });
+ @Override
+ protected void refreshUiReal() {
+ if (mSearchEditText != null) {
+ filter(mSearchEditText.getText().toString());
+ }
}
public static class MyListFragment extends ListFragment {
diff --git a/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java b/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java
index c33decd8..ec9d59e1 100644
--- a/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java
@@ -436,11 +436,11 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer
}
public void onConversationUpdate() {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- updateView();
- }
- });
+ refreshUi();
+ }
+
+ @Override
+ protected void refreshUiReal() {
+ updateView();
}
}
diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
index bf247787..ac7fcf9d 100644
--- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
@@ -33,7 +33,9 @@ import android.nfc.NfcEvent;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
+import android.os.Handler;
import android.os.IBinder;
+import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.text.InputType;
import android.util.DisplayMetrics;
@@ -99,6 +101,33 @@ public abstract class XmppActivity extends Activity {
protected int mTheme;
protected boolean mUsingEnterKey = false;
+ private long mLastUiRefresh = 0;
+ private Handler mRefreshUiHandler = new Handler();
+ private Runnable mRefreshUiRunnable = new Runnable() {
+ @Override
+ public void run() {
+ mLastUiRefresh = SystemClock.elapsedRealtime();
+ refreshUiReal();
+ }
+ };
+
+
+ protected void refreshUi() {
+ final long diff = SystemClock.elapsedRealtime() - mLastUiRefresh;
+ if (diff > Config.REFRESH_UI_INTERVAL) {
+ mRefreshUiHandler.removeCallbacks(mRefreshUiRunnable);
+ runOnUiThread(mRefreshUiRunnable);
+ } else {
+ final long next = Config.REFRESH_UI_INTERVAL - diff;
+ mRefreshUiHandler.removeCallbacks(mRefreshUiRunnable);
+ mRefreshUiHandler.postDelayed(mRefreshUiRunnable,next);
+ }
+ }
+
+ protected void refreshUiReal() {
+
+ };
+
protected interface OnValueEdited {
public void onValueEdited(String value);
}