widget: some more debugging, try delaying network request on update

This commit is contained in:
Andrew Dolgov 2017-05-30 10:27:56 +03:00
parent 99d6ce12f7
commit efb22befbd
3 changed files with 20 additions and 6 deletions

View File

@ -18,6 +18,7 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.support.customtabs.CustomTabsCallback;
import android.support.customtabs.CustomTabsClient;
@ -435,8 +436,8 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
alarmManager.cancel(pendingIntentAlarm);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + updateInterval,
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + updateInterval,
updateInterval,
pendingIntentAlarm);

View File

@ -8,6 +8,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
@ -52,6 +53,7 @@ public class SmallWidgetProvider extends AppWidgetProvider {
Intent serviceIntent = new Intent(context.getApplicationContext(), WidgetUpdateService.class);
context.startService(serviceIntent);
}

View File

@ -3,6 +3,7 @@ package org.fox.ttrss.widget;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;
@ -52,7 +53,7 @@ public class WidgetUpdateService extends Service {
final int feedId = m_prefs.getBoolean("widget_show_fresh", true) ? -3 : 0;
SimpleLoginManager loginManager = new SimpleLoginManager() {
final SimpleLoginManager loginManager = new SimpleLoginManager() {
@Override
protected void onLoginSuccess(int requestId, String sessionId, int apiLevel) {
@ -75,6 +76,8 @@ public class WidgetUpdateService extends Service {
} catch (Exception e) {
e.printStackTrace();
}
} else {
Log.d(TAG, "request failed: " + getErrorMessage());
}
++m_updateFailures;
@ -97,6 +100,8 @@ public class WidgetUpdateService extends Service {
@Override
protected void onLoginFailed(int requestId, ApiRequest ar) {
Log.d(TAG, "login failed: " + ar.getErrorMessage());
++m_updateFailures;
sendResultIntent(-1, UPDATE_RESULT_ERROR_LOGIN);
}
@ -108,10 +113,16 @@ public class WidgetUpdateService extends Service {
}
};
String login = m_prefs.getString("login", "").trim();
String password = m_prefs.getString("password", "").trim();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
String login = m_prefs.getString("login", "").trim();
String password = m_prefs.getString("password", "").trim();
loginManager.logIn(getApplicationContext(), 1, login, password);
}
}, 2 * 1000);
loginManager.logIn(getApplicationContext(), 1, login, password);
}
} catch (Exception e) {
e.printStackTrace();