add share button to repo details activity, for sharing repo urls
This commit is contained in:
parent
1bd4f9f4e7
commit
c2fce47975
@ -22,6 +22,7 @@ import android.text.TextUtils;
|
|||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.TextureView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
@ -38,6 +39,7 @@ import org.fdroid.fdroid.data.Repo;
|
|||||||
import org.fdroid.fdroid.data.RepoProvider;
|
import org.fdroid.fdroid.data.RepoProvider;
|
||||||
import org.fdroid.fdroid.data.Schema.RepoTable;
|
import org.fdroid.fdroid.data.Schema.RepoTable;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class RepoDetailsActivity extends AppCompatActivity {
|
public class RepoDetailsActivity extends AppCompatActivity {
|
||||||
@ -75,6 +77,8 @@ public class RepoDetailsActivity extends AppCompatActivity {
|
|||||||
private long repoId;
|
private long repoId;
|
||||||
private View repoView;
|
private View repoView;
|
||||||
|
|
||||||
|
private String shareUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Help function to make switching between two view states easier.
|
* Help function to make switching between two view states easier.
|
||||||
* Perhaps there is a better way to do this. I recall that using Adobe
|
* Perhaps there is a better way to do this. I recall that using Adobe
|
||||||
@ -205,6 +209,7 @@ public class RepoDetailsActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
Intent intent;
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
NavUtils.navigateUpFromSameTask(this);
|
NavUtils.navigateUpFromSameTask(this);
|
||||||
@ -213,9 +218,14 @@ public class RepoDetailsActivity extends AppCompatActivity {
|
|||||||
promptForDelete();
|
promptForDelete();
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_enable_nfc:
|
case R.id.menu_enable_nfc:
|
||||||
Intent intent = new Intent(this, NfcNotEnabledActivity.class);
|
intent = new Intent(this, NfcNotEnabledActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
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, "gogogo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
@ -224,6 +234,7 @@ public class RepoDetailsActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
prepareNfcMenuItems(menu);
|
prepareNfcMenuItems(menu);
|
||||||
|
prepareShareMenuItems(menu);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,6 +258,19 @@ public class RepoDetailsActivity extends AppCompatActivity {
|
|||||||
menuItem.setVisible(needsEnableNfcMenuItem);
|
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) {
|
private void setupDescription(View parent, Repo repo) {
|
||||||
|
|
||||||
TextView descriptionLabel = (TextView) parent.findViewById(R.id.label_description);
|
TextView descriptionLabel = (TextView) parent.findViewById(R.id.label_description);
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_share"
|
||||||
|
android:icon="@drawable/ic_share_white"
|
||||||
|
android:title="@string/menu_share"
|
||||||
|
app:showAsAction="ifRoom|withText"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_delete"
|
android:id="@+id/menu_delete"
|
||||||
android:icon="@drawable/ic_delete_white"
|
android:icon="@drawable/ic_delete_white"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user