[app] separate link and file sharing in app details

previously only file sharing worked and link sharing was broken.

Users were often confused why the file was shared which isn't something we want to encourage, so now file sharing is a dedicated less prominent option.
This commit is contained in:
Torsten Grote 2024-04-15 09:59:42 -03:00
parent 429eae6f9e
commit 3d63f0f814
No known key found for this signature in database
GPG Key ID: 3E5F77D92CF891FF
3 changed files with 27 additions and 31 deletions

View File

@ -244,6 +244,12 @@ public class AppDetailsActivity extends AppCompatActivity
// don't show menu before appPrefs haven't been loaded
if (prefs == null || app == null) return false;
MenuItem share = menu.findItem(R.id.action_share);
share.setVisible(app.getShareUri(this) != null);
MenuItem shareApk = menu.findItem(R.id.action_share_apk);
shareApk.setVisible(app.isInstalled(getApplicationContext()));
MenuItem itemIgnoreAll = menu.findItem(R.id.action_ignore_all);
itemIgnoreAll.setChecked(prefs.getIgnoreAllUpdates());
MenuItem itemIgnoreThis = menu.findItem(R.id.action_ignore_this);
@ -282,41 +288,24 @@ public class AppDetailsActivity extends AppCompatActivity
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_share) {
String extraText = String.format("%s (%s)\nhttps://f-droid.org/packages/%s/",
app.name, app.summary, app.packageName);
Intent uriIntent = new Intent(Intent.ACTION_SEND);
Uri shareUri = app.getShareUri(this);
if (shareUri != null) uriIntent.setData(shareUri);
Uri shareUri = ObjectsCompat.requireNonNull(app.getShareUri(this));
uriIntent.setType("text/plain");
uriIntent.putExtra(Intent.EXTRA_SUBJECT, app.name);
uriIntent.putExtra(Intent.EXTRA_TITLE, app.name);
uriIntent.putExtra(Intent.EXTRA_TEXT, shareUri.toString());
Intent textIntent = new Intent(Intent.ACTION_SEND);
textIntent.setType("text/plain");
textIntent.putExtra(Intent.EXTRA_SUBJECT, app.name);
textIntent.putExtra(Intent.EXTRA_TITLE, app.name);
textIntent.putExtra(Intent.EXTRA_TEXT, extraText);
if (app.isInstalled(getApplicationContext())) {
// allow user to share APK if app is installed
Intent streamIntent = PublicSourceDirProvider.getApkShareIntent(this, app.packageName);
streamIntent.putExtra(Intent.EXTRA_SUBJECT, "Shared from F-Droid: " + app.name + ".apk");
streamIntent.putExtra(Intent.EXTRA_TITLE, app.name + ".apk");
streamIntent.putExtra(Intent.EXTRA_TEXT, extraText);
Intent chooserIntent = Intent.createChooser(streamIntent, getString(R.string.menu_share));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{
textIntent,
uriIntent,
});
startActivity(chooserIntent);
} else {
Intent chooserIntent = Intent.createChooser(textIntent, getString(R.string.menu_share));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{
uriIntent,
});
startActivity(chooserIntent);
}
Intent chooserIntent = Intent.createChooser(uriIntent, getString(R.string.menu_share));
startActivity(chooserIntent);
return true;
} else if (item.getItemId() == R.id.action_share_apk) {
// allow user to share APK if app is installed
Intent streamIntent = PublicSourceDirProvider.getApkShareIntent(this, app.packageName);
streamIntent.putExtra(Intent.EXTRA_SUBJECT, "Shared from F-Droid: " + app.name + ".apk");
streamIntent.putExtra(Intent.EXTRA_TITLE, app.name + ".apk");
Intent chooserIntent = Intent.createChooser(streamIntent, getString(R.string.menu_share));
startActivity(chooserIntent);
} else if (item.getItemId() == R.id.action_ignore_all) {
model.ignoreAllUpdates();
return true;

View File

@ -7,6 +7,12 @@
android:icon="@drawable/ic_share_with_background"
android:title="@string/menu_share"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_share_apk"
android:icon="@drawable/ic_share_with_background"
android:title="@string/menu_share_apk"
android:visible="false"
app:showAsAction="never" />
<item
android:id="@+id/action_ignore_all"
android:title="@string/menu_ignore_all"

View File

@ -246,6 +246,7 @@ This often occurs with apps installed via Google Play or other sources, if they
<string name="menu_open">Open</string>
<!-- This should be exactly the same as the standard word for Share throughout Android and apps -->
<string name="menu_share">Share</string>
<string name="menu_share_apk">Share APK file</string>
<!-- This is a button label, it must be the right size, or the layout gets messed up. It should ideally be 10-20 characters. -->
<string name="menu_install">Install</string>
<!-- This is a button label, it must be the right size, or the layout gets messed up. It should ideally be 10-20 characters. -->