Skip to content

Commit d8f35ac

Browse files
committed
Perform a Quick Sync during setup
Pull down only 1 hour of EPG, then restart the service to allow the HTSP connection to be re-established with a longer EPG max time. This delays the logo download until the end of the second sync, but that's OK in my opinion.
1 parent 53e713c commit d8f35ac

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed

app/src/debug/java/ie/macinnes/tvheadend/DevTestActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ public void accountInfo(View view) {
113113

114114
public void deleteChannels(View view) {
115115
setRunning();
116+
117+
Context context = getBaseContext();
118+
Intent i = new Intent(context, EpgSyncService.class);
119+
context.stopService(i);
120+
121+
i = new Intent(context, TvInputService.class);
122+
context.stopService(i);
123+
116124
TvContractUtils.removeChannels(getBaseContext());
117125
setOk();
118126
}

app/src/main/java/ie/macinnes/tvheadend/setup/TvInputSetupActivity.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@ public void run() {
339339
GuidedStepFragment fragment = new CompletedFragment();
340340
fragment.setArguments(getArguments());
341341
add(getFragmentManager(), fragment);
342+
343+
// Re-Start EPG sync service (removing quick-sync)
344+
Context context = getActivity().getBaseContext();
345+
346+
Intent intent = new Intent(context, EpgSyncService.class);
347+
context.stopService(intent);
348+
context.startService(intent);
342349
}
343350
};
344351

@@ -360,10 +367,14 @@ public void onDestroy() {
360367
public void onStart() {
361368
super.onStart();
362369

363-
// Start EPG sync service
370+
// Re-Start EPG sync service
364371
Context context = getActivity().getBaseContext();
365-
context.stopService(new Intent(context, EpgSyncService.class));
366-
context.startService(new Intent(context, EpgSyncService.class));
372+
373+
Intent intent = new Intent(context, EpgSyncService.class);
374+
intent.putExtra(EpgSyncService.SYNC_QUICK, true);
375+
376+
context.stopService(intent);
377+
context.startService(intent);
367378
}
368379

369380
@Override
@@ -414,7 +425,7 @@ public static class CompletedFragment extends BaseGuidedStepFragment {
414425
public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
415426
GuidanceStylist.Guidance guidance = new GuidanceStylist.Guidance(
416427
"Setup Complete",
417-
"Enjoy!",
428+
"More EPG data, channel logs, etc are downloading in the background",
418429
"TVHeadend",
419430
null);
420431

app/src/main/java/ie/macinnes/tvheadend/sync/EpgSyncService.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
public class EpgSyncService extends Service {
4242
private static final String TAG = EpgSyncService.class.getName();
4343

44+
public static final String SYNC_QUICK = "sync-quick";
45+
4446
protected HandlerThread mHandlerThread;
4547
protected Handler mHandler;
4648

@@ -55,6 +57,7 @@ public class EpgSyncService extends Service {
5557
protected GetFileTask mGetFileTask;
5658

5759
protected static List<Runnable> sInitialSyncCompleteCallbacks = new ArrayList<>();
60+
protected boolean mQuickSyncRequested = false;
5861

5962
protected final Runnable mInitialSyncCompleteCallback = new Runnable() {
6063
@Override
@@ -115,6 +118,9 @@ public void onCreate() {
115118

116119
@Override
117120
public int onStartCommand(Intent intent, int flags, int startId) {
121+
if (intent != null) {
122+
mQuickSyncRequested = intent.getBooleanExtra(SYNC_QUICK, false);
123+
}
118124
if (mAccount == null) {
119125
return START_NOT_STICKY;
120126
}
@@ -173,7 +179,13 @@ public void onStateChange(int state, int previous) {
173179
} else if (state == Connection.STATE_READY) {
174180
Log.d(TAG, "HTSP Connection Ready");
175181
installTasks();
176-
enableAsyncMetadata();
182+
if (mQuickSyncRequested) {
183+
// Sync 1 hour of EPG
184+
enableAsyncMetadata(3600);
185+
mQuickSyncRequested = false;
186+
} else {
187+
enableAsyncMetadata();
188+
}
177189
} else if (state == Connection.STATE_FAILED) {
178190
Log.e(TAG, "HTSP Connection Failed, Reconnecting");
179191
closeConnection();
@@ -207,6 +219,11 @@ protected void enableAsyncMetadata() {
207219
mEpgSyncTask.enableAsyncMetadata(mInitialSyncCompleteCallback);
208220
}
209221

222+
protected void enableAsyncMetadata(long epgMaxTime) {
223+
Log.d(TAG, "Enabling Async Metadata");
224+
mEpgSyncTask.enableAsyncMetadata(mInitialSyncCompleteCallback, epgMaxTime);
225+
}
226+
210227
protected void closeConnection() {
211228
if (mConnection != null) {
212229
Log.d(TAG, "Closing HTSP connection");

app/src/main/java/ie/macinnes/tvheadend/sync/EpgSyncTask.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,20 @@ public EpgSyncTask(Context context, Handler handler, Account account, GetFileTas
9292
Constants.PREFERENCE_TVHEADEND, Context.MODE_PRIVATE);
9393
}
9494

95+
9596
public void enableAsyncMetadata(Runnable initialSyncCompleteCallback) {
97+
long epgMaxTime = Long.parseLong(mSharedPreferences.getString(Constants.KEY_EPG_MAX_TIME, "3600"));
98+
99+
enableAsyncMetadata(initialSyncCompleteCallback, epgMaxTime);
100+
}
101+
102+
public void enableAsyncMetadata(Runnable initialSyncCompleteCallback, long epgMaxTime) {
96103
long lastUpdate = mSharedPreferences.getLong(Constants.KEY_EPG_LAST_UPDATE, 0);
97-
long epgMaxTime = mSharedPreferences.getLong(Constants.KEY_EPG_MAX_TIME, 3600);
98-
epgMaxTime = epgMaxTime + (System.currentTimeMillis() / 1000L);
99104

100105
Log.i(TAG, "Enabling Async Metadata. Last Update: " + lastUpdate + ", EPG max time: " + epgMaxTime);
101106

107+
epgMaxTime = epgMaxTime + (System.currentTimeMillis() / 1000L);
108+
102109
mInitialSyncCompleteCallback = initialSyncCompleteCallback;
103110

104111
EnableAsyncMetadataRequest enableAsyncMetadataRequest = new EnableAsyncMetadataRequest();

0 commit comments

Comments
 (0)