mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Convert share button to ShareActionProvider
This commit is contained in:
parent
74f9775771
commit
d48c4c13ee
3 changed files with 44 additions and 36 deletions
|
|
@ -15,7 +15,9 @@ import android.os.Environment;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||||
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
|
import android.support.v7.widget.ShareActionProvider;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
|
@ -130,27 +132,25 @@ public class MediaDetailPagerFragment extends Fragment implements ViewPager.OnPa
|
||||||
Media m = provider.getMediaAtPosition(pager.getCurrentItem());
|
Media m = provider.getMediaAtPosition(pager.getCurrentItem());
|
||||||
switch(item.getItemId()) {
|
switch(item.getItemId()) {
|
||||||
case R.id.menu_share_current_image:
|
case R.id.menu_share_current_image:
|
||||||
|
// Share - this is just logs it, intent set in onCreateOptionsMenu, around line 252
|
||||||
EventLog.schema(CommonsApplication.EVENT_SHARE_ATTEMPT)
|
EventLog.schema(CommonsApplication.EVENT_SHARE_ATTEMPT)
|
||||||
.param("username", app.getCurrentAccount().name)
|
.param("username", app.getCurrentAccount().name)
|
||||||
.param("filename", m.getFilename())
|
.param("filename", m.getFilename())
|
||||||
.log();
|
.log();
|
||||||
Intent shareIntent = new Intent();
|
|
||||||
shareIntent.setAction(Intent.ACTION_SEND);
|
|
||||||
shareIntent.setType("text/plain");
|
|
||||||
shareIntent.putExtra(Intent.EXTRA_TEXT, m.getDisplayTitle() + " " + m.getDescriptionUrl());
|
|
||||||
startActivity(shareIntent);
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_browser_current_image:
|
case R.id.menu_browser_current_image:
|
||||||
|
// View in browser
|
||||||
Intent viewIntent = new Intent();
|
Intent viewIntent = new Intent();
|
||||||
viewIntent.setAction(Intent.ACTION_VIEW);
|
viewIntent.setAction(Intent.ACTION_VIEW);
|
||||||
viewIntent.setData(Uri.parse(m.getDescriptionUrl()));
|
viewIntent.setData(Uri.parse(m.getDescriptionUrl()));
|
||||||
startActivity(viewIntent);
|
startActivity(viewIntent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_download_current_image:
|
case R.id.menu_download_current_image:
|
||||||
|
// Download
|
||||||
downloadMedia(m);
|
downloadMedia(m);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_retry_current_image:
|
case R.id.menu_retry_current_image:
|
||||||
// Is this... sane? :)
|
// Retry
|
||||||
((ContributionsActivity)getActivity()).retryUpload(pager.getCurrentItem());
|
((ContributionsActivity)getActivity()).retryUpload(pager.getCurrentItem());
|
||||||
getActivity().getSupportFragmentManager().popBackStack();
|
getActivity().getSupportFragmentManager().popBackStack();
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -249,6 +249,13 @@ public class MediaDetailPagerFragment extends Fragment implements ViewPager.OnPa
|
||||||
menu.findItem(R.id.menu_share_current_image).setEnabled(true).setVisible(true);
|
menu.findItem(R.id.menu_share_current_image).setEnabled(true).setVisible(true);
|
||||||
menu.findItem(R.id.menu_download_current_image).setEnabled(true).setVisible(true);
|
menu.findItem(R.id.menu_download_current_image).setEnabled(true).setVisible(true);
|
||||||
|
|
||||||
|
// Set ShareActionProvider Intent
|
||||||
|
ShareActionProvider mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(menu.findItem(R.id.menu_share_current_image));
|
||||||
|
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||||
|
shareIntent.setType("text/plain");
|
||||||
|
shareIntent.putExtra(Intent.EXTRA_TEXT, m.getDisplayTitle() + " " + m.getDescriptionUrl());
|
||||||
|
mShareActionProvider.setShareIntent(shareIntent);
|
||||||
|
|
||||||
if(m instanceof Contribution) {
|
if(m instanceof Contribution) {
|
||||||
Contribution c = (Contribution)m;
|
Contribution c = (Contribution)m;
|
||||||
switch(c.getState()) {
|
switch(c.getState()) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
|
@ -12,6 +13,6 @@
|
||||||
android:id="@+id/contributionsListFragment"
|
android:id="@+id/contributionsListFragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
/>
|
tools:layout="@layout/fragment_contributions" />
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
@ -2,34 +2,34 @@
|
||||||
|
|
||||||
<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/menu_share_current_image"
|
<item
|
||||||
app:showAsAction="ifRoom|withText"
|
android:id="@+id/menu_share_current_image"
|
||||||
android:icon="@android:drawable/ic_menu_share"
|
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
|
||||||
android:title="@string/menu_share"
|
android:title="@string/menu_share"
|
||||||
/>
|
app:showAsAction="ifRoom|withText" />
|
||||||
<item android:id="@+id/menu_browser_current_image"
|
<item
|
||||||
app:showAsAction="never"
|
android:id="@+id/menu_browser_current_image"
|
||||||
android:icon="@android:drawable/ic_menu_view"
|
android:icon="@android:drawable/ic_menu_view"
|
||||||
android:title="@string/menu_open_in_browser"
|
android:title="@string/menu_open_in_browser"
|
||||||
/>
|
app:showAsAction="never" />
|
||||||
<item android:id="@+id/menu_download_current_image"
|
<item
|
||||||
app:showAsAction="never"
|
android:id="@+id/menu_download_current_image"
|
||||||
android:icon="@drawable/ic_menu_download"
|
android:icon="@drawable/ic_menu_download"
|
||||||
android:title="@string/menu_download"
|
android:title="@string/menu_download"
|
||||||
/>
|
app:showAsAction="never" />
|
||||||
<item android:id="@+id/menu_retry_current_image"
|
<item
|
||||||
app:showAsAction="ifRoom|withText"
|
android:id="@+id/menu_retry_current_image"
|
||||||
android:icon="@android:drawable/ic_menu_revert"
|
android:enabled="false"
|
||||||
android:title="@string/menu_retry_upload"
|
android:icon="@android:drawable/ic_menu_revert"
|
||||||
android:visible="false"
|
android:title="@string/menu_retry_upload"
|
||||||
android:enabled="false"
|
android:visible="false"
|
||||||
/>
|
app:showAsAction="ifRoom|withText" />
|
||||||
<item android:id="@+id/menu_cancel_current_image"
|
<item
|
||||||
app:showAsAction="never"
|
android:id="@+id/menu_cancel_current_image"
|
||||||
android:icon="@android:drawable/ic_menu_delete"
|
android:enabled="false"
|
||||||
android:title="@string/menu_cancel_upload"
|
android:icon="@android:drawable/ic_menu_delete"
|
||||||
android:visible="false"
|
android:title="@string/menu_cancel_upload"
|
||||||
android:enabled="false"
|
android:visible="false"
|
||||||
/>
|
app:showAsAction="never" />
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue