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);
}
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:

View File

@ -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:

View File

@ -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:

View File

@ -142,12 +142,20 @@ 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);
// 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
public void onPreferenceChange() {

View File

@ -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);
}
}

View File

@ -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);
}
}
}