Correctly navigate "up" to the swap list.

When viewing app details from a swap list, we need to return to the
swap list when pressing "up". Previously it would go to the main list
of apps, and only return to the swap list when pressing "back".

Now, a subclass of AppDetails is used when in swap mode, which knows
how to navigate up to the correct task.
This commit is contained in:
Peter Serwylo 2015-03-27 07:36:24 +11:00
parent a16bc22c4a
commit 2a481f6889
6 changed files with 72 additions and 21 deletions

View File

@ -768,13 +768,17 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A
startActivity(intent); startActivity(intent);
} }
protected void navigateUp() {
NavUtils.navigateUpFromSameTask(this);
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
NavUtils.navigateUpFromSameTask(this); navigateUp();
return true; return true;
case LAUNCH: case LAUNCH:

View File

@ -634,31 +634,36 @@ public class AppProvider extends FDroidProvider {
public Cursor query(Uri uri, String[] projection, String customSelection, String[] selectionArgs, String sortOrder) { public Cursor query(Uri uri, String[] projection, String customSelection, String[] selectionArgs, String sortOrder) {
Query query = new Query(); Query query = new Query();
AppQuerySelection selection = new AppQuerySelection(customSelection, selectionArgs); 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)) { switch (matcher.match(uri)) {
case CODE_LIST: case CODE_LIST:
includeSwap = false;
break; break;
case CODE_SINGLE: case CODE_SINGLE:
includeSwap = true;
selection = selection.add(querySingle(uri.getLastPathSegment())); selection = selection.add(querySingle(uri.getLastPathSegment()));
break; break;
case CAN_UPDATE: case CAN_UPDATE:
selection = selection.add(queryCanUpdate()); selection = selection.add(queryCanUpdate());
includeSwap = false;
break; break;
case REPO: case REPO:
includeSwap = true;
selection = selection.add(queryRepo(Long.parseLong(uri.getLastPathSegment()))); selection = selection.add(queryRepo(Long.parseLong(uri.getLastPathSegment())));
break; break;
case INSTALLED: case INSTALLED:
selection = selection.add(queryInstalled()); selection = selection.add(queryInstalled());
includeSwap = false;
break; break;
case SEARCH: case SEARCH:
selection = selection.add(querySearch(uri.getLastPathSegment())); selection = selection.add(querySearch(uri.getLastPathSegment()));
includeSwap = false;
break; break;
case NO_APKS: case NO_APKS:
@ -675,16 +680,19 @@ public class AppProvider extends FDroidProvider {
case CATEGORY: case CATEGORY:
selection = selection.add(queryCategory(uri.getLastPathSegment())); selection = selection.add(queryCategory(uri.getLastPathSegment()));
includeSwap = false;
break; break;
case RECENTLY_UPDATED: case RECENTLY_UPDATED:
sortOrder = " fdroid_app.lastUpdated DESC"; sortOrder = " fdroid_app.lastUpdated DESC";
selection = selection.add(queryRecentlyUpdated()); selection = selection.add(queryRecentlyUpdated());
includeSwap = false;
break; break;
case NEWLY_ADDED: case NEWLY_ADDED:
sortOrder = " fdroid_app.added DESC"; sortOrder = " fdroid_app.added DESC";
selection = selection.add(queryNewlyAdded()); selection = selection.add(queryNewlyAdded());
includeSwap = false;
break; break;
default: default:

View File

@ -286,7 +286,7 @@ public class RepoProvider extends FDroidProvider {
break; break;
case CODE_ALL_EXCEPT_SWAP: case CODE_ALL_EXCEPT_SWAP:
selection = DataColumns.IS_SWAP + " = 0"; selection = DataColumns.IS_SWAP + " = 0 OR " + DataColumns.IS_SWAP + " IS NULL ";
break; break;
default: default:

View File

@ -142,11 +142,19 @@ abstract public class AppListFragment extends ThemeableListFragment implements
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final App app = new App((Cursor)getListView().getItemAtPosition(position)); // Cursor is null in the swap list when touching the first item.
Intent intent = new Intent(getActivity(), AppDetails.class); Cursor cursor = (Cursor)getListView().getItemAtPosition(position);
intent.putExtra(AppDetails.EXTRA_APPID, app.id); if (cursor != null) {
intent.putExtra(AppDetails.EXTRA_FROM, getFromTitle()); final App app = new App(cursor);
startActivityForResult(intent, FDroid.REQUEST_APPDETAILS); 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 @Override

View File

@ -44,10 +44,8 @@ public class ConnectSwapActivity extends FragmentActivity {
} }
public void onRepoUpdated(Repo repo) { public void onRepoUpdated(Repo repo) {
Intent intent = new Intent(this, SwapAppListActivity.class); 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); startActivity(intent);
} }
} }

View File

@ -1,11 +1,14 @@
package org.fdroid.fdroid.views.swap; package org.fdroid.fdroid.views.swap;
import android.app.Activity; import android.app.Activity;
import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.v4.app.NavUtils;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import org.fdroid.fdroid.AppDetails; import org.fdroid.fdroid.AppDetails;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
@ -18,7 +21,9 @@ import org.fdroid.fdroid.views.fragments.AppListFragment;
public class SwapAppListActivity extends ActionBarActivity { 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; private Repo repo;
@ -47,8 +52,12 @@ public class SwapAppListActivity extends ActionBarActivity {
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
String repoAddress = getIntent().getStringExtra(EXTRA_REPO_ADDRESS); long repoAddress = getIntent().getLongExtra(EXTRA_REPO_ID, -1);
repo = RepoProvider.Helper.findByAddress(this, repoAddress); 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() { public Repo getRepo() {
@ -91,14 +100,38 @@ public class SwapAppListActivity extends ActionBarActivity {
return AppProvider.getRepoUri(repo); 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 * Only difference from base class is that it navigates up to a different task.
* can be different form the regular AppDetails. That is - the AppDetails goes back * It will go to the {@link org.fdroid.fdroid.views.swap.SwapAppListActivity}
* to the main app list, but the SwapAppDetails will go back to the "Swap app list" * whereas the baseclass will go back to the main list of apps. Need to juggle
* activity. * 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);
}
}
} }