Fixing merge saddness after rebasing my changes over master.

I had a couple of months of changes which I rebased over master.
It made me sad. After doign what I thought was required to resolve
conflicts, I've now gone and fixed a few bits here and there.

This arose because I didn't try and compile after each merge conflict.
I'll take the lesson onboard and try to remember to do this in the
future :)
This commit is contained in:
Peter Serwylo 2014-08-19 15:43:16 +09:30
parent a299340db7
commit 4857ed2d45
5 changed files with 39 additions and 210 deletions

View File

@ -105,39 +105,6 @@
<data android:pathPrefix="/repository/browse" /> <data android:pathPrefix="/repository/browse" />
</intent-filter> </intent-filter>
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchResults" />
</activity>
<activity
android:name=".views.swap.ConnectSwapActivity"
android:theme="@style/SwapTheme.Wizard"
android:label=""
android:parentActivityName=".FDroid">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".FDroid" />
<intent-filter>
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="*" />
<data android:path="/FDROID/REPO/SWAP" />
<data android:path="/fdroid/repo/swap" />
</intent-filter>
</activity>
<!--
The title for ManageReposActivity is "F-Droid" here, but "Repositories"
when viewing the Activity itself in the app.
-->
<activity
android:name=".views.ManageReposActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:parentActivityName=".FDroid" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".FDroid" />
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
@ -192,9 +159,13 @@
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".FDroid" /> android:value=".FDroid" />
</activity> </activity>
<!--
The title for ManageReposActivity is "F-Droid" here, but "Repositories"
when viewing the Activity itself in the app.
-->
<activity <activity
android:name=".ManageRepo" android:name=".views.ManageReposActivity"
android:label="@string/menu_manage" android:label="@string/app_name"
android:launchMode="singleTask" android:launchMode="singleTask"
android:parentActivityName=".FDroid" > android:parentActivityName=".FDroid" >
<meta-data <meta-data
@ -242,7 +213,7 @@
<activity <activity
android:name=".NfcNotEnabledActivity" android:name=".NfcNotEnabledActivity"
android:noHistory="true" /> android:noHistory="true" />
<activity android:name=".views.QrWizardDownloadActivity" /> <!--<activity android:name=".views.QrWizardDownloadActivity" />
<activity android:name=".views.QrWizardWifiNetworkActivity" /> <activity android:name=".views.QrWizardWifiNetworkActivity" />
<activity <activity
android:name=".views.LocalRepoActivity" android:name=".views.LocalRepoActivity"
@ -262,7 +233,7 @@
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".views.LocalRepoActivity" /> android:value=".views.LocalRepoActivity" />
</activity> </activity>-->
<activity <activity
android:name=".views.RepoDetailsActivity" android:name=".views.RepoDetailsActivity"
android:label="@string/menu_manage" android:label="@string/menu_manage"
@ -270,7 +241,7 @@
android:windowSoftInputMode="stateHidden"> android:windowSoftInputMode="stateHidden">
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".ManageRepo" /> android:value=".views.ManageReposActivity" />
</activity> </activity>
<activity <activity

View File

@ -44,6 +44,7 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import org.fdroid.fdroid.compat.TabManager; import org.fdroid.fdroid.compat.TabManager;
import org.fdroid.fdroid.data.AppProvider; import org.fdroid.fdroid.data.AppProvider;
import org.fdroid.fdroid.data.NewRepoConfig;
import org.fdroid.fdroid.views.AppListFragmentPagerAdapter; import org.fdroid.fdroid.views.AppListFragmentPagerAdapter;
import org.fdroid.fdroid.views.LocalRepoActivity; import org.fdroid.fdroid.views.LocalRepoActivity;
import org.fdroid.fdroid.views.ManageReposActivity; import org.fdroid.fdroid.views.ManageReposActivity;
@ -119,13 +120,13 @@ public class FDroid extends ActionBarActivity {
// Don't handle the intent after coming back to this view (e.g. after hitting the back button) // Don't handle the intent after coming back to this view (e.g. after hitting the back button)
// http://stackoverflow.com/a/14820849 // http://stackoverflow.com/a/14820849
if (!getIntent().hasExtra("handled")) { if (!getIntent().hasExtra("handled")) {
RepoIntentParser parser = new RepoIntentParser(this, getIntent()); NewRepoConfig parser = new NewRepoConfig(this, getIntent());
if (parser.parse()) { if (parser.isValidRepo()) {
getIntent().putExtra("handled", true); getIntent().putExtra("handled", true);
if (parser.isFromSwap()) { if (parser.isFromSwap()) {
startActivityForResult(new Intent(ACTION_ADD_REPO, getIntent().getData(), this, ConnectSwapActivity.class), REQUEST_SWAP); startActivityForResult(new Intent(ACTION_ADD_REPO, getIntent().getData(), this, ConnectSwapActivity.class), REQUEST_SWAP);
} else { } else {
startActivity(new Intent(ACTION_ADD_REPO, getIntent().getData(), this, ManageRepo.class)); startActivity(new Intent(ACTION_ADD_REPO, getIntent().getData(), this, ManageReposActivity.class));
} }
} else if (parser.getErrorMessage() != null) { } else if (parser.getErrorMessage() != null) {
Toast.makeText(this, parser.getErrorMessage(), Toast.LENGTH_LONG).show(); Toast.makeText(this, parser.getErrorMessage(), Toast.LENGTH_LONG).show();
@ -173,10 +174,6 @@ public class FDroid extends ActionBarActivity {
startActivity(new Intent(this, SwapActivity.class)); startActivity(new Intent(this, SwapActivity.class));
return true; return true;
case R.id.action_swap:
startActivity(new Intent(this, SwapActivity.class));
return true;
case R.id.action_search: case R.id.action_search:
onSearchRequested(); onSearchRequested();
return true; return true;

View File

@ -1,148 +0,0 @@
package org.fdroid.fdroid;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import java.util.Locale;
public class RepoIntentParser {
private final Intent intent;
private final Context context;
private String errorMessage;
private String repoUriString;
private Uri repoUri;
private String host;
private int port;
private String scheme;
private String fingerprint;
private String bssid = null;
private String ssid = null;
private boolean fromSwap;
public RepoIntentParser(Context context, Intent intent) {
this.intent = intent;
this.context = context;
}
public String getBssid() {
return bssid;
}
public String getSsid() {
return ssid;
}
public int getPort() {
return port;
}
public String getUri() {
return repoUriString;
}
public String getHost() {
return host;
}
public String getScheme() {
return scheme;
}
public String getFingerprint() {
return fingerprint;
}
public String getErrorMessage() {
return errorMessage;
}
/**
* TODO: This has changed a little from before, it used to be: port != 8888 and !ip then not local repo.
* TODO: Port no longer fixed to 8888, as we can use whatever port we want from the settings of the local
* repo device. However, perhaps we should choose a higher port, as a lot of regular web servers may opt for 8888
* in liu of root permissions on the server for using port 80, and if port 8080 is already taken.
*/
public boolean looksLikeLocalAddress() {
return port == 8888 && host.matches("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+");
}
public boolean parse() {
/* an URL from a click, NFC, QRCode scan, etc */
repoUri = intent.getData();
if (repoUri == null) {
return false;
}
Log.d("org.fdroid.fdroid.RepoIntentParser", "Parsing intent URI " + repoUri);
// scheme and host should only ever be pure ASCII aka Locale.ENGLISH
scheme = intent.getScheme();
host = repoUri.getHost();
port = repoUri.getPort();
if (scheme == null || host == null) {
this.errorMessage = String.format(context.getString(R.string.malformed_repo_uri), repoUri);
return false;
}
if (equalsInList(scheme, new String[]{"FDROIDREPO", "FDROIDREPOS"})) {
/*
* QRCodes are more efficient in all upper case, so QR URIs are
* encoded in all upper case, then forced to lower case.
* Checking if the special F-Droid scheme being all is upper
* case means it should be downcased.
*/
repoUri = Uri.parse(repoUri.toString().toLowerCase(Locale.ENGLISH));
} else if (repoUri.getPath().startsWith("/FDROID/REPO")) {
/*
* some QR scanners chop off the fdroidrepo:// and just try
* http://, then the incoming URI does not get downcased
* properly, and the query string is stripped off. So just
* downcase the path, and carry on to get something working.
*/
repoUri = Uri.parse(repoUri.toString().toLowerCase(Locale.ENGLISH));
}
// make scheme and host lowercase so they're readable in dialogs
scheme = scheme.toLowerCase(Locale.ENGLISH);
host = host.toLowerCase(Locale.ENGLISH);
fingerprint = repoUri.getQueryParameter("fingerprint");
bssid = repoUri.getQueryParameter("bssid");
ssid = repoUri.getQueryParameter("ssid");
fromSwap = repoUri.getQueryParameter("swap") != null;
Log.i("RepoListFragment", "onCreate " + fingerprint);
if (equalsInList(scheme, new String[] { "fdroidrepos", "fdroidrepo", "https", "http" })) {
/* sanitize and format for function and readability */
repoUriString = repoUri.toString()
.replaceAll("\\?.*$", "") // remove the whole query
.replaceAll("/*$", "") // remove all trailing slashes
.replace(repoUri.getHost(), host) // downcase host name
.replace(intent.getScheme(), scheme) // downcase scheme
.replace("fdroidrepo", "http"); // proper repo address
return true;
}
return false;
}
private static boolean equalsInList(String value, String[] list) {
for (String item : list) {
if (item.equals(value)) {
return true;
}
}
return false;
}
public boolean isFromSwap() {
return fromSwap;
}
}

View File

@ -5,8 +5,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
import java.util.Arrays; import java.util.Arrays;
@ -25,6 +23,7 @@ public class NewRepoConfig {
private String fingerprint; private String fingerprint;
private String bssid; private String bssid;
private String ssid; private String ssid;
private boolean fromSwap;
public NewRepoConfig(Context context, String uri) { public NewRepoConfig(Context context, String uri) {
init(context, Uri.parse(uri)); init(context, Uri.parse(uri));
@ -47,8 +46,7 @@ public class NewRepoConfig {
host = uri.getHost(); host = uri.getHost();
port = uri.getPort(); port = uri.getPort();
if (TextUtils.isEmpty(scheme) || TextUtils.isEmpty(host)) { if (TextUtils.isEmpty(scheme) || TextUtils.isEmpty(host)) {
errorMessage = String.format(context.getString(R.string.malformed_repo_uri), errorMessage = String.format(context.getString(R.string.malformed_repo_uri), uri);
uri);
isValidRepo = false; isValidRepo = false;
return; return;
} }
@ -77,13 +75,16 @@ public class NewRepoConfig {
fingerprint = uri.getQueryParameter("fingerprint"); fingerprint = uri.getQueryParameter("fingerprint");
bssid = uri.getQueryParameter("bssid"); bssid = uri.getQueryParameter("bssid");
ssid = uri.getQueryParameter("ssid"); ssid = uri.getQueryParameter("ssid");
fromSwap = uri.getQueryParameter("swap") != null;
Log.i("RepoListFragment", "onCreate " + fingerprint); if (!Arrays.asList("fdroidrepos", "fdroidrepo", "https", "http").contains(scheme)) {
if (Arrays.asList("fdroidrepos", "fdroidrepo", "https", "http").contains(scheme)) { isValidRepo = false;
uriString = sanitizeRepoUri(uri); return;
} }
this.isValidRepo = true; uriString = sanitizeRepoUri(uri);
isValidRepo = true;
} }
public String getBssid() { public String getBssid() {
@ -102,6 +103,10 @@ public class NewRepoConfig {
return uriString; return uriString;
} }
public Uri getUri() {
return uri;
}
public String getHost() { public String getHost() {
return host; return host;
} }
@ -118,6 +123,10 @@ public class NewRepoConfig {
return isValidRepo; return isValidRepo;
} }
public boolean isFromSwap() {
return fromSwap;
}
/* /*
* The port starts out as 8888, but if there is a conflict, it will be * The port starts out as 8888, but if there is a conflict, it will be
* incremented until there is a free port found. * incremented until there is a free port found.

View File

@ -11,14 +11,14 @@ import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.fdroid.fdroid.ProgressListener; import org.fdroid.fdroid.ProgressListener;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
import org.fdroid.fdroid.RepoIntentParser;
import org.fdroid.fdroid.UpdateService; import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.data.NewRepoConfig;
import org.fdroid.fdroid.data.Repo; import org.fdroid.fdroid.data.Repo;
import org.fdroid.fdroid.data.RepoProvider; import org.fdroid.fdroid.data.RepoProvider;
public class ConfirmReceiveSwapFragment extends Fragment implements ProgressListener { public class ConfirmReceiveSwapFragment extends Fragment implements ProgressListener {
private RepoIntentParser parser; private NewRepoConfig newRepoConfig;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -49,10 +49,10 @@ public class ConfirmReceiveSwapFragment extends Fragment implements ProgressList
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
parser = new RepoIntentParser(getActivity(), getActivity().getIntent()); newRepoConfig = new NewRepoConfig(getActivity(), getActivity().getIntent());
if (parser.parse()) { if (newRepoConfig.isValidRepo()) {
((TextView) getView().findViewById(R.id.text_description)).setText( ((TextView) getView().findViewById(R.id.text_description)).setText(
getString(R.string.swap_confirm_connect, parser.getHost()) getString(R.string.swap_confirm_connect, newRepoConfig.getHost())
); );
} else { } else {
// TODO: Show error message on screen (not in popup). // TODO: Show error message on screen (not in popup).
@ -65,18 +65,18 @@ public class ConfirmReceiveSwapFragment extends Fragment implements ProgressList
} }
private Repo ensureRepoExists() { private Repo ensureRepoExists() {
// TODO: parser.getUri() will include a fingerprint, which may not match with // TODO: newRepoConfig.getUri() will include a fingerprint, which may not match with
// the repos address in the database. // the repos address in the database.
Repo repo = RepoProvider.Helper.findByAddress(getActivity(), parser.getUri()); Repo repo = RepoProvider.Helper.findByAddress(getActivity(), newRepoConfig.getUriString());
if (repo == null) { if (repo == null) {
ContentValues values = new ContentValues(5); ContentValues values = new ContentValues(5);
// TODO: i18n and think about most appropriate name. Although ideally, it will not be seen often, // TODO: i18n and think about most appropriate name. Although ideally, it will not be seen often,
// because we're whacking a pretty UI over the swap process so they don't need to "Manage repos"... // because we're whacking a pretty UI over the swap process so they don't need to "Manage repos"...
values.put(RepoProvider.DataColumns.NAME, "Swap"); values.put(RepoProvider.DataColumns.NAME, "Swap");
values.put(RepoProvider.DataColumns.ADDRESS, parser.getUri()); values.put(RepoProvider.DataColumns.ADDRESS, newRepoConfig.getUriString());
values.put(RepoProvider.DataColumns.DESCRIPTION, ""); // TODO; values.put(RepoProvider.DataColumns.DESCRIPTION, ""); // TODO;
values.put(RepoProvider.DataColumns.FINGERPRINT, parser.getFingerprint()); values.put(RepoProvider.DataColumns.FINGERPRINT, newRepoConfig.getFingerprint());
values.put(RepoProvider.DataColumns.IN_USE, true); values.put(RepoProvider.DataColumns.IN_USE, true);
Uri uri = RepoProvider.Helper.insert(getActivity(), values); Uri uri = RepoProvider.Helper.insert(getActivity(), values);
repo = RepoProvider.Helper.findByUri(getActivity(), uri); repo = RepoProvider.Helper.findByUri(getActivity(), uri);