accept froidrepo and fdroidrepos URIs, which can be scanned via QRCode, etc
This patch makes F-Droid register with Android that it accepts the URI schemes of fdroidrepo (HTTP) and fdroidrepos(HTTPS). When F-Droid receives one of these URIs, it launches the ManageRepo Activity and then launches the New Repository dialog. refs #2454
This commit is contained in:
parent
1b8ea8f3d5
commit
6928bd1244
@ -71,6 +71,18 @@
|
|||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value=".FDroid" />
|
android:value=".FDroid" />
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
|
||||||
|
<!-- Android's scheme matcher is case-sensitive, so include most likely variations -->
|
||||||
|
<data android:scheme="fdroidrepo" />
|
||||||
|
<data android:scheme="FDROIDREPO" />
|
||||||
|
<data android:scheme="fdroidrepos" />
|
||||||
|
<data android:scheme="FDROIDREPOS" />
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
|
@ -25,6 +25,7 @@ import java.util.Date;
|
|||||||
import java.util.Formatter;
|
import java.util.Formatter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@ -33,6 +34,7 @@ import android.app.ListActivity;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
@ -106,6 +108,23 @@ public class ManageRepo extends ListActivity {
|
|||||||
|
|
||||||
reposToRemove = new ArrayList<String>();
|
reposToRemove = new ArrayList<String>();
|
||||||
reposToDisable = new ArrayList<String>();
|
reposToDisable = new ArrayList<String>();
|
||||||
|
|
||||||
|
/* let's see if someone is trying to send us a new repo */
|
||||||
|
Intent intent = getIntent();
|
||||||
|
/* an URL from a click or a QRCode scan */
|
||||||
|
Uri uri = intent.getData();
|
||||||
|
if (uri != null) {
|
||||||
|
// scheme should only ever be pure ASCII:
|
||||||
|
String scheme = intent.getScheme().toLowerCase(Locale.ENGLISH);
|
||||||
|
String fingerprint = uri.getUserInfo();
|
||||||
|
if (scheme.equals("fdroidrepos") || scheme.equals("fdroidrepo")
|
||||||
|
|| scheme.equals("https") || scheme.equals("http")) {
|
||||||
|
String uriString = uri.toString().replace("fdroidrepo", "http").
|
||||||
|
replace(fingerprint + "@", "");
|
||||||
|
showAddRepo(uriString);
|
||||||
|
Log.i("ManageRepo", uriString + " fingerprint: " + fingerprint);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -211,23 +230,23 @@ public class ManageRepo extends ListActivity {
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void showAddRepo(String uriString) {
|
||||||
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
|
||||||
|
|
||||||
super.onMenuItemSelected(featureId, item);
|
|
||||||
LayoutInflater li = LayoutInflater.from(this);
|
LayoutInflater li = LayoutInflater.from(this);
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case ADD_REPO:
|
|
||||||
View view = li.inflate(R.layout.addrepo, null);
|
View view = li.inflate(R.layout.addrepo, null);
|
||||||
Builder p = new AlertDialog.Builder(this).setView(view);
|
Builder p = new AlertDialog.Builder(this).setView(view);
|
||||||
final AlertDialog alrt = p.create();
|
final AlertDialog alrt = p.create();
|
||||||
|
|
||||||
|
if (uriString != null) {
|
||||||
|
EditText uriEditText = (EditText) view.findViewById(R.id.edit_uri);
|
||||||
|
uriEditText.setText(uriString);
|
||||||
|
}
|
||||||
|
|
||||||
alrt.setIcon(android.R.drawable.ic_menu_add);
|
alrt.setIcon(android.R.drawable.ic_menu_add);
|
||||||
alrt.setTitle(getString(R.string.repo_add_title));
|
alrt.setTitle(getString(R.string.repo_add_title));
|
||||||
alrt.setButton(DialogInterface.BUTTON_POSITIVE,
|
alrt.setButton(DialogInterface.BUTTON_POSITIVE,
|
||||||
getString(R.string.repo_add_add),
|
getString(R.string.repo_add_add),
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
EditText uri = (EditText) alrt
|
EditText uri = (EditText) alrt
|
||||||
.findViewById(R.id.edit_uri);
|
.findViewById(R.id.edit_uri);
|
||||||
@ -240,11 +259,22 @@ public class ManageRepo extends ListActivity {
|
|||||||
alrt.setButton(DialogInterface.BUTTON_NEGATIVE,
|
alrt.setButton(DialogInterface.BUTTON_NEGATIVE,
|
||||||
getString(R.string.cancel),
|
getString(R.string.cancel),
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
alrt.show();
|
alrt.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
||||||
|
|
||||||
|
super.onMenuItemSelected(featureId, item);
|
||||||
|
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case ADD_REPO:
|
||||||
|
showAddRepo(null);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case REM_REPO:
|
case REM_REPO:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user