diff --git a/F-Droid/src/org/fdroid/fdroid/AppDetails.java b/F-Droid/src/org/fdroid/fdroid/AppDetails.java index f97e7908b..abf543b57 100644 --- a/F-Droid/src/org/fdroid/fdroid/AppDetails.java +++ b/F-Droid/src/org/fdroid/fdroid/AppDetails.java @@ -768,13 +768,17 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A startActivity(intent); } + protected void navigateUp() { + NavUtils.navigateUpFromSameTask(this); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: - NavUtils.navigateUpFromSameTask(this); + navigateUp(); return true; case LAUNCH: diff --git a/F-Droid/src/org/fdroid/fdroid/data/AppProvider.java b/F-Droid/src/org/fdroid/fdroid/data/AppProvider.java index e3ec1b4ba..189220433 100644 --- a/F-Droid/src/org/fdroid/fdroid/data/AppProvider.java +++ b/F-Droid/src/org/fdroid/fdroid/data/AppProvider.java @@ -634,31 +634,36 @@ public class AppProvider extends FDroidProvider { public Cursor query(Uri uri, String[] projection, String customSelection, String[] selectionArgs, String sortOrder) { Query query = new Query(); AppQuerySelection selection = new AppQuerySelection(customSelection, selectionArgs); - boolean includeSwap = false; + + // Queries which are for the main list of apps should not include swap apps. + boolean includeSwap = true; + switch (matcher.match(uri)) { case CODE_LIST: + includeSwap = false; break; case CODE_SINGLE: - includeSwap = true; selection = selection.add(querySingle(uri.getLastPathSegment())); break; case CAN_UPDATE: selection = selection.add(queryCanUpdate()); + includeSwap = false; break; case REPO: - includeSwap = true; selection = selection.add(queryRepo(Long.parseLong(uri.getLastPathSegment()))); break; case INSTALLED: selection = selection.add(queryInstalled()); + includeSwap = false; break; case SEARCH: selection = selection.add(querySearch(uri.getLastPathSegment())); + includeSwap = false; break; case NO_APKS: @@ -675,16 +680,19 @@ public class AppProvider extends FDroidProvider { case CATEGORY: selection = selection.add(queryCategory(uri.getLastPathSegment())); + includeSwap = false; break; case RECENTLY_UPDATED: sortOrder = " fdroid_app.lastUpdated DESC"; selection = selection.add(queryRecentlyUpdated()); + includeSwap = false; break; case NEWLY_ADDED: sortOrder = " fdroid_app.added DESC"; selection = selection.add(queryNewlyAdded()); + includeSwap = false; break; default: diff --git a/F-Droid/src/org/fdroid/fdroid/data/RepoProvider.java b/F-Droid/src/org/fdroid/fdroid/data/RepoProvider.java index 0497460d0..a4f250c03 100644 --- a/F-Droid/src/org/fdroid/fdroid/data/RepoProvider.java +++ b/F-Droid/src/org/fdroid/fdroid/data/RepoProvider.java @@ -286,7 +286,7 @@ public class RepoProvider extends FDroidProvider { break; case CODE_ALL_EXCEPT_SWAP: - selection = DataColumns.IS_SWAP + " = 0"; + selection = DataColumns.IS_SWAP + " = 0 OR " + DataColumns.IS_SWAP + " IS NULL "; break; default: diff --git a/F-Droid/src/org/fdroid/fdroid/views/fragments/AppListFragment.java b/F-Droid/src/org/fdroid/fdroid/views/fragments/AppListFragment.java index e7d33c607..a34d5994c 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/fragments/AppListFragment.java +++ b/F-Droid/src/org/fdroid/fdroid/views/fragments/AppListFragment.java @@ -142,11 +142,19 @@ abstract public class AppListFragment extends ThemeableListFragment implements @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - final App app = new App((Cursor)getListView().getItemAtPosition(position)); - Intent intent = new Intent(getActivity(), AppDetails.class); - intent.putExtra(AppDetails.EXTRA_APPID, app.id); - intent.putExtra(AppDetails.EXTRA_FROM, getFromTitle()); - startActivityForResult(intent, FDroid.REQUEST_APPDETAILS); + // Cursor is null in the swap list when touching the first item. + Cursor cursor = (Cursor)getListView().getItemAtPosition(position); + if (cursor != null) { + final App app = new App(cursor); + Intent intent = getAppDetailsIntent(); + intent.putExtra(AppDetails.EXTRA_APPID, app.id); + intent.putExtra(AppDetails.EXTRA_FROM, getFromTitle()); + startActivityForResult(intent, FDroid.REQUEST_APPDETAILS); + } + } + + protected Intent getAppDetailsIntent() { + return new Intent(getActivity(), AppDetails.class); } @Override diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/ConnectSwapActivity.java b/F-Droid/src/org/fdroid/fdroid/views/swap/ConnectSwapActivity.java index 60f065ec7..946cd3e77 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/ConnectSwapActivity.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/ConnectSwapActivity.java @@ -44,10 +44,8 @@ public class ConnectSwapActivity extends FragmentActivity { } public void onRepoUpdated(Repo repo) { - Intent intent = new Intent(this, SwapAppListActivity.class); - intent.putExtra(SwapAppListActivity.EXTRA_REPO_ADDRESS, repo.address); + intent.putExtra(SwapAppListActivity.EXTRA_REPO_ID, repo.getId()); startActivity(intent); - } } diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppListActivity.java b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppListActivity.java index fd1ed73a3..bc935d73f 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppListActivity.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppListActivity.java @@ -1,11 +1,14 @@ package org.fdroid.fdroid.views.swap; import android.app.Activity; +import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.Handler; +import android.support.v4.app.NavUtils; import android.support.annotation.Nullable; import android.support.v7.app.ActionBarActivity; +import android.util.Log; import org.fdroid.fdroid.AppDetails; import org.fdroid.fdroid.R; @@ -18,7 +21,9 @@ import org.fdroid.fdroid.views.fragments.AppListFragment; public class SwapAppListActivity extends ActionBarActivity { - public static String EXTRA_REPO_ADDRESS = "repoAddress"; + private static final String TAG = "fdroid.SwapAppListActivity"; + + public static String EXTRA_REPO_ID = "repoId"; private Repo repo; @@ -47,8 +52,12 @@ public class SwapAppListActivity extends ActionBarActivity { protected void onResume() { super.onResume(); - String repoAddress = getIntent().getStringExtra(EXTRA_REPO_ADDRESS); - repo = RepoProvider.Helper.findByAddress(this, repoAddress); + long repoAddress = getIntent().getLongExtra(EXTRA_REPO_ID, -1); + repo = RepoProvider.Helper.findById(this, repoAddress); + if (repo == null) { + Log.e(TAG, "Couldn't show swap app list for repo " + repoAddress); + finish(); + } } public Repo getRepo() { @@ -91,14 +100,38 @@ public class SwapAppListActivity extends ActionBarActivity { return AppProvider.getRepoUri(repo); } + protected Intent getAppDetailsIntent() { + Intent intent = new Intent(getActivity(), SwapAppDetails.class); + intent.putExtra(EXTRA_REPO_ID, repo.getId()); + return intent; + } + } /** - * Here so that the AndroidManifest.xml can specify the "parent" activity from this - * can be different form the regular AppDetails. That is - the AppDetails goes back - * to the main app list, but the SwapAppDetails will go back to the "Swap app list" - * activity. + * Only difference from base class is that it navigates up to a different task. + * It will go to the {@link org.fdroid.fdroid.views.swap.SwapAppListActivity} + * whereas the baseclass will go back to the main list of apps. Need to juggle + * the repoId in order to be able to return to an appropriately configured swap + * list (see {@link org.fdroid.fdroid.views.swap.SwapAppListActivity.SwapAppListFragment#getAppDetailsIntent()}). */ - public static class SwapAppDetails extends AppDetails {} + public static class SwapAppDetails extends AppDetails { + + private long repoId; + + @Override + protected void onResume() { + super.onResume(); + repoId = getIntent().getLongExtra(EXTRA_REPO_ID, -1); + } + + @Override + protected void navigateUp() { + Intent parentIntent = NavUtils.getParentActivityIntent(this); + parentIntent.putExtra(EXTRA_REPO_ID, repoId); + NavUtils.navigateUpTo(this, parentIntent); + } + + } }