Merge branch 'merge-requests/39'

This commit is contained in:
Ciaran Gultnieks 2013-11-22 09:44:54 +00:00
commit 6a6c2287d4
5 changed files with 195 additions and 63 deletions

View File

@ -49,14 +49,11 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="f-droid.org"
android:pathPrefix="/repository/browse" />
<data android:scheme="https" android:host="f-droid.org"
android:pathPrefix="/repository/browse" />
<data android:scheme="http" android:host="www.f-droid.org"
android:pathPrefix="/repository/browse" />
<data android:scheme="https" android:host="www.f-droid.org"
android:pathPrefix="/repository/browse" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="f-droid.org" />
<data android:host="www.f-droid.org" />
<data android:pathPrefix="/repository/browse" />
</intent-filter>
<meta-data
@ -71,6 +68,34 @@
<meta-data
android:name="android.support.PARENT_ACTIVITY"
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" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="*" />
<!-- the patterns are unpredictable, this is the best I could get working -->
<data android:path="/repo" />
<data android:path="/archive" />
<data android:pathPattern="/repo/*" />
<data android:pathPattern="/archive/*" />
</intent-filter>
<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
@ -106,14 +131,11 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="f-droid.org"
android:pathPrefix="/app/" />
<data android:scheme="https" android:host="f-droid.org"
android:pathPrefix="/app/" />
<data android:scheme="http" android:host="www.f-droid.org"
android:pathPrefix="/app/" />
<data android:scheme="https" android:host="www.f-droid.org"
android:pathPrefix="/app/" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="f-droid.org" />
<data android:host="www.f-droid.org" />
<data android:pathPrefix="/app/" />
</intent-filter>
</activity>
<activity

View File

@ -1,24 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:ems="20"
android:layout_height="wrap_content" android:text="@string/repo_add_url"/>
<EditText
android:id="@+id/edit_uri"
android:inputType="textUri"
android:maxLines="1"
android:layout_width="wrap_content"
android:ems="20"
android:layout_height="wrap_content"
android:text="https://"/>
</LinearLayout>
<!--
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/repo_alert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/ic_dialog_alert"
android:gravity="center"
android:text="@string/repo_exists"
android:textAppearance="@android:style/TextAppearance.Large"
android:textColor="@color/red"
android:visibility="gone" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/repo_add_url" />
<EditText
android:id="@+id/edit_uri"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textUri"
android:maxLines="1"
android:text="https://" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/repo_add_fingerprint" />
<EditText
android:id="@+id/edit_fingerprint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="0123456789ABCDEFabcedf: "
android:inputType="textNoSuggestions"
android:maxLines="1"
android:typeface="monospace" />
<CheckBox
android:id="@+id/overwrite_repo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="@string/repo_overwrite"
android:textAppearance="@android:style/TextAppearance.Medium"
android:visibility="gone" />
</LinearLayout><!--
* Copyright (C) 2009 Roberto Jacinto
* roberto.jacinto@caixamagica.pt
*

View File

@ -70,6 +70,9 @@
<string name="download_server">Getting application from</string>
<string name="repo_add_url">Repository address</string>
<string name="repo_add_fingerprint">fingerprint (optional)</string>
<string name="repo_exists">This repo already exists!</string>
<string name="repo_overwrite">Overwrite the existing repo?</string>
<string name="repo_alrt">The list of used repositories has
changed.\nDo you

View File

@ -10,6 +10,7 @@
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="red">#FFFF0000</color>
<style name="AboutDialogLight" parent="@android:style/Theme.Dialog">
<item name="@android:windowBackground">@color/black</item>

View File

@ -25,6 +25,7 @@ import java.util.Date;
import java.util.Formatter;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import android.app.AlertDialog;
@ -33,6 +34,7 @@ import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.format.DateFormat;
@ -41,11 +43,15 @@ import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import org.fdroid.fdroid.DB.Repo;
import android.support.v4.app.NavUtils;
import android.support.v4.view.MenuItemCompat;
@ -106,6 +112,23 @@ public class ManageRepo extends ListActivity {
reposToRemove = 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, fingerprint);
Log.i("ManageRepo", uriString + " fingerprint: " + fingerprint);
}
}
}
@Override
@ -201,6 +224,25 @@ public class ManageRepo extends ListActivity {
}
}
protected List<Repo> getRepos() {
List<Repo> repos = null;
try {
DB db = DB.getDB();
repos = db.getRepos();
} finally {
DB.releaseDB();
}
return repos;
}
protected Repo getRepo(String repoUri, List<Repo> repos) {
if (repoUri != null)
for (Repo repo : repos)
if (repoUri.equals(repo.address))
return repo;
return null;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -211,40 +253,71 @@ public class ManageRepo extends ListActivity {
return super.onOptionsItemSelected(item);
}
private void showAddRepo(String uriString, String fingerprint) {
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.addrepo, null);
Builder p = new AlertDialog.Builder(this).setView(view);
final AlertDialog alrt = p.create();
final EditText uriEditText = (EditText) view.findViewById(R.id.edit_uri);
final EditText fingerprintEditText = (EditText) view.findViewById(R.id.edit_fingerprint);
alrt.setIcon(android.R.drawable.ic_menu_add);
alrt.setTitle(getString(R.string.repo_add_title));
alrt.setButton(DialogInterface.BUTTON_POSITIVE,
getString(R.string.repo_add_add),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
addRepo(uriEditText.getText().toString());
changed = true;
redraw();
}
});
alrt.setButton(DialogInterface.BUTTON_NEGATIVE,
getString(R.string.cancel),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alrt.show();
List<Repo> repos = getRepos();
Repo repo = getRepo(uriString, repos);
if (repo != null) {
TextView tv = (TextView) view.findViewById(R.id.repo_alert);
tv.setVisibility(0);
tv.setText(R.string.repo_exists);
final Button addButton = alrt.getButton(DialogInterface.BUTTON_POSITIVE);
addButton.setEnabled(false);
final CheckBox overwriteCheckBox = (CheckBox) view.findViewById(R.id.overwrite_repo);
overwriteCheckBox.setVisibility(0);
overwriteCheckBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
addButton.setEnabled(overwriteCheckBox.isChecked());
}
});
// TODO if address and fingerprint match, then enable existing repo
// TODO if address matches but fingerprint doesn't, handle this with extra widgets
}
if (uriString != null)
uriEditText.setText(uriString);
if (fingerprint != null)
fingerprintEditText.setText(fingerprint);
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
super.onMenuItemSelected(featureId, item);
LayoutInflater li = LayoutInflater.from(this);
switch (item.getItemId()) {
case ADD_REPO:
View view = li.inflate(R.layout.addrepo, null);
Builder p = new AlertDialog.Builder(this).setView(view);
final AlertDialog alrt = p.create();
alrt.setIcon(android.R.drawable.ic_menu_add);
alrt.setTitle(getString(R.string.repo_add_title));
alrt.setButton(DialogInterface.BUTTON_POSITIVE,
getString(R.string.repo_add_add),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
EditText uri = (EditText) alrt
.findViewById(R.id.edit_uri);
addRepo(uri.getText().toString());
changed = true;
redraw();
}
});
alrt.setButton(DialogInterface.BUTTON_NEGATIVE,
getString(R.string.cancel),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alrt.show();
showAddRepo(null, null);
return true;
case REM_REPO: