Merge branch 'share-repo-url' into 'master'

add share button to repo details activity, for sharing repo urls

See merge request fdroid/fdroidclient!696
This commit is contained in:
Hans-Christoph Steiner 2018-06-28 18:40:08 +00:00
commit bfb67061b2
3 changed files with 35 additions and 5 deletions

View File

@ -75,6 +75,8 @@ public class RepoDetailsActivity extends AppCompatActivity {
private long repoId;
private View repoView;
private String shareUrl;
/**
* Help function to make switching between two view states easier.
* Perhaps there is a better way to do this. I recall that using Adobe
@ -205,6 +207,7 @@ public class RepoDetailsActivity extends AppCompatActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent;
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
@ -213,9 +216,15 @@ public class RepoDetailsActivity extends AppCompatActivity {
promptForDelete();
return true;
case R.id.menu_enable_nfc:
Intent intent = new Intent(this, NfcNotEnabledActivity.class);
intent = new Intent(this, NfcNotEnabledActivity.class);
startActivity(intent);
return true;
case R.id.action_share:
intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, shareUrl);
startActivity(Intent.createChooser(intent,
getResources().getString(R.string.share_repository)));
}
return super.onOptionsItemSelected(item);
@ -224,6 +233,7 @@ public class RepoDetailsActivity extends AppCompatActivity {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
prepareNfcMenuItems(menu);
prepareShareMenuItems(menu);
return true;
}
@ -247,6 +257,20 @@ public class RepoDetailsActivity extends AppCompatActivity {
menuItem.setVisible(needsEnableNfcMenuItem);
}
private void prepareShareMenuItems(Menu menu) {
if (!TextUtils.isEmpty(repo.address)) {
if (!TextUtils.isEmpty(repo.fingerprint)) {
shareUrl = Uri.parse(repo.address).buildUpon()
.appendQueryParameter("fingerprint", repo.fingerprint).toString();
} else {
shareUrl = repo.address;
}
menu.findItem(R.id.action_share).setVisible(true);
} else {
menu.findItem(R.id.action_share).setVisible(false);
}
}
private void setupDescription(View parent, Repo repo) {
TextView descriptionLabel = (TextView) parent.findViewById(R.id.label_description);

View File

@ -3,14 +3,19 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_delete"
android:icon="@drawable/ic_delete_white"
android:title="@string/delete"
app:showAsAction="ifRoom|withText" />
android:id="@+id/action_share"
android:icon="@drawable/ic_share_white"
android:title="@string/menu_share"
app:showAsAction="ifRoom|withText"/>
<item
android:id="@+id/menu_enable_nfc"
android:icon="@drawable/ic_nfc_white"
android:title="@string/enable_nfc_send"
app:showAsAction="ifRoom|withText" />
<item
android:id="@+id/menu_delete"
android:icon="@drawable/ic_delete_white"
android:title="@string/delete"
app:showAsAction="ifRoom|withText" />
</menu>

View File

@ -345,6 +345,7 @@ This often occurs with apps installed via Google Play or other sources, if they
</string>
<string name="repo_added">Saved package repository %1$s.</string>
<string name="repo_searching_address">Looking for package repository at\n%1$s</string>
<string name="share_repository">Share Repository</string>
<string name="minsdk_or_later">%s or later</string>
<string name="up_to_maxsdk">Up to %s</string>
<string name="minsdk_up_to_maxsdk">%1$s up to %2$s</string>