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

View File

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

View File

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