run index update in the background after adding a new repo

That makes that repo automatically ready for use based on user actions like
adding a new repo, switching an existing repo on, etc.

This also lowers the priority of the "update" menu item since it shouldn't
be needed any more.  But leave it for now, just in case.
This commit is contained in:
Hans-Christoph Steiner 2015-06-19 17:12:35 -04:00
parent cd0b5b80f9
commit e984ed82ef
3 changed files with 9 additions and 88 deletions

View File

@ -7,11 +7,6 @@
android:icon="@drawable/ic_search_white"
android:title="@string/menu_search"
app:showAsAction="always"/>
<item
android:id="@+id/action_update_repo"
android:icon="@drawable/ic_refresh_white"
android:title="@string/menu_update_repo"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_swap"
android:title="@string/swap"
@ -26,6 +21,11 @@
android:icon="@drawable/ic_bluetooth_white"
android:title="@string/menu_send_apk_bt"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_update_repo"
android:icon="@drawable/ic_refresh_white"
android:title="@string/menu_update_repo"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_settings"
android:icon="@drawable/ic_settings_white"

View File

@ -55,7 +55,6 @@ public class FDroid extends ActionBarActivity {
private static final String TAG = "FDroid";
public static final int REQUEST_MANAGEREPOS = 0;
public static final int REQUEST_PREFS = 1;
public static final int REQUEST_ENABLE_BLUETOOTH = 2;
public static final int REQUEST_SWAP = 3;
@ -244,12 +243,11 @@ public class FDroid extends ActionBarActivity {
switch (item.getItemId()) {
case R.id.action_update_repo:
updateRepos();
UpdateService.updateNow(this);
return true;
case R.id.action_manage_repos:
Intent i = new Intent(this, ManageReposActivity.class);
startActivityForResult(i, REQUEST_MANAGEREPOS);
startActivity(new Intent(this, ManageReposActivity.class));
return true;
case R.id.action_settings:
@ -318,31 +316,6 @@ public class FDroid extends ActionBarActivity {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_MANAGEREPOS:
if (data != null && data.hasExtra(ManageReposActivity.REQUEST_UPDATE)) {
AlertDialog.Builder ask_alrt = new AlertDialog.Builder(this);
ask_alrt.setTitle(getString(R.string.repo_update_title));
ask_alrt.setMessage(getString(R.string.repo_alrt));
ask_alrt.setPositiveButton(getString(R.string.yes),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int whichButton) {
updateRepos();
}
});
ask_alrt.setNegativeButton(getString(R.string.no),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int whichButton) {
// do nothing
}
});
AlertDialog alert = ask_alrt.create();
alert.show();
}
break;
case REQUEST_PREFS:
// The automatic update settings may have changed, so reschedule (or
// unschedule) the service accordingly. It's cheap, so no need to
@ -377,13 +350,6 @@ public class FDroid extends ActionBarActivity {
});
}
// Force a repo update now. A progress dialog is shown and the UpdateService
// is told to do the update, which will result in the database changing. The
// UpdateReceiver class should get told when this is finished.
public void updateRepos() {
UpdateService.updateNow(this);
}
private TabManager getTabManager() {
if (tabManager == null) {
tabManager = new TabManager(this, viewPager);

View File

@ -19,12 +19,10 @@
package org.fdroid.fdroid.views;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.database.Cursor;
@ -42,7 +40,6 @@ import android.support.v4.app.LoaderManager;
import android.support.v4.app.NavUtils;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
@ -88,13 +85,6 @@ import java.util.Locale;
import javax.jmdns.ServiceInfo;
public class ManageReposActivity extends ActionBarActivity {
/**
* If we have a new repo added, or the address of a repo has changed, then
* we when we're finished, we'll set this boolean to true in the intent that
* we finish with, to signify that we want the main list of apps updated.
*/
public static final String REQUEST_UPDATE = "update";
private static final String TAG = "ManageReposActivity";
private static final String DEFAULT_NEW_REPO_TEXT = "https://";
@ -105,8 +95,6 @@ public class ManageReposActivity extends ActionBarActivity {
IS_SWAP
}
private static boolean changed = false;
private RepoListFragment listFragment;
/**
@ -152,19 +140,10 @@ public class ManageReposActivity extends ActionBarActivity {
protected void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver,
new IntentFilter(UpdateService.LOCAL_ACTION_STATUS));
/* let's see if someone is trying to send us a new repo */
addRepoFromIntent(getIntent());
}
@Override
protected void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
}
@Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
@ -173,22 +152,10 @@ public class ManageReposActivity extends ActionBarActivity {
@Override
public void finish() {
Intent ret = new Intent();
markChangedIfRequired(ret);
setResult(RESULT_OK, ret);
super.finish();
}
private boolean hasChanged() {
return changed;
}
private void markChangedIfRequired(Intent intent) {
if (hasChanged()) {
Log.i(TAG, "Repo details have changed, prompting for update.");
intent.putExtra(REQUEST_UPDATE, true);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.manage_repos, menu);
@ -200,7 +167,6 @@ public class ManageReposActivity extends ActionBarActivity {
switch (item.getItemId()) {
case android.R.id.home:
Intent destIntent = new Intent(this, FDroid.class);
markChangedIfRequired(destIntent);
setResult(RESULT_OK, destIntent);
NavUtils.navigateUpTo(this, destIntent);
return true;
@ -217,17 +183,6 @@ public class ManageReposActivity extends ActionBarActivity {
return super.onOptionsItemSelected(item);
}
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int statusCode = intent.getIntExtra(UpdateService.EXTRA_STATUS_CODE, -1);
if (statusCode == UpdateService.STATUS_COMPLETE_AND_SAME
|| statusCode == UpdateService.STATUS_COMPLETE_WITH_CHANGES)
// No need to prompt to update any more, we just did it!
changed = false;
}
};
private void scanForRepos() {
final RepoScanListAdapter adapter = new RepoScanListAdapter(this);
final MDnsHelper mDnsHelper = new MDnsHelper(this, adapter);
@ -699,7 +654,7 @@ public class ManageReposActivity extends ActionBarActivity {
* to reflect the newly created repo.
*/
private void finishedAddingRepo() {
changed = true;
UpdateService.updateNow(ManageReposActivity.this);
if (addRepoDialog.isShowing()) {
addRepoDialog.dismiss();
}
@ -792,7 +747,7 @@ public class ManageReposActivity extends ActionBarActivity {
RepoProvider.Helper.update(getActivity(), repo, values);
if (isEnabled) {
changed = true;
UpdateService.updateNow(getActivity());
} else {
FDroidApp app = (FDroidApp) getActivity().getApplication();
RepoProvider.Helper.purgeApps(getActivity(), repo, app);