mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Show only contextually appropriate actions in Contributions
Camera / From Gallery only on Contributions List view Share only on Detail View
This commit is contained in:
parent
95320396a5
commit
48b6e5cc53
5 changed files with 113 additions and 90 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/menu_share_current_image"
|
||||
android:showAsAction="always"
|
||||
android:showAsAction="always|withText"
|
||||
android:icon="@android:drawable/ic_menu_share"
|
||||
android:title="@string/menu_share"
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -34,8 +34,6 @@ public class ContributionsActivity
|
|||
MediaDetailPagerFragment.MediaDetailProvider,
|
||||
FragmentManager.OnBackStackChangedListener {
|
||||
|
||||
private final static int SELECT_FROM_GALLERY = 1;
|
||||
private final static int SELECT_FROM_CAMERA = 2;
|
||||
|
||||
private Cursor allContributions;
|
||||
private ContributionsListFragment contributionsList;
|
||||
|
|
@ -94,7 +92,7 @@ public class ContributionsActivity
|
|||
@Override
|
||||
protected void onAuthCookieAcquired(String authCookie) {
|
||||
// Do a sync everytime we get here!
|
||||
ContentResolver.requestSync(((CommonsApplication)getApplicationContext()).getCurrentAccount(), ContributionsContentProvider.AUTHORITY, new Bundle());
|
||||
ContentResolver.requestSync(((CommonsApplication) getApplicationContext()).getCurrentAccount(), ContributionsContentProvider.AUTHORITY, new Bundle());
|
||||
Intent uploadServiceIntent = new Intent(this, UploadService.class);
|
||||
uploadServiceIntent.setAction(UploadService.ACTION_START_SERVICE);
|
||||
startService(uploadServiceIntent);
|
||||
|
|
@ -131,91 +129,9 @@ public class ContributionsActivity
|
|||
mediaDetails.showImage(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
outState.putParcelable("lastGeneratedCaptureURI", lastGeneratedCaptureURI);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
lastGeneratedCaptureURI = (Uri) savedInstanceState.getParcelable("lastGeneratedCaptureURI");
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
switch(requestCode) {
|
||||
case SELECT_FROM_GALLERY:
|
||||
if(resultCode == RESULT_OK) {
|
||||
Intent shareIntent = new Intent(this, ShareActivity.class);
|
||||
shareIntent.setAction(Intent.ACTION_SEND);
|
||||
Log.d("Commons", "Type is " + data.getType() + " Uri is " + data.getData());
|
||||
shareIntent.setType("image/*"); //FIXME: Find out appropriate mime type
|
||||
shareIntent.putExtra(Intent.EXTRA_STREAM, data.getData());
|
||||
shareIntent.putExtra(UploadService.EXTRA_SOURCE, Contribution.SOURCE_GALLERY);
|
||||
startActivity(shareIntent);
|
||||
}
|
||||
break;
|
||||
case SELECT_FROM_CAMERA:
|
||||
if(resultCode == RESULT_OK) {
|
||||
Intent shareIntent = new Intent(this, ShareActivity.class);
|
||||
shareIntent.setAction(Intent.ACTION_SEND);
|
||||
Log.d("Commons", "Uri is " + lastGeneratedCaptureURI);
|
||||
shareIntent.setType("image/jpeg"); //FIXME: Find out appropriate mime type
|
||||
shareIntent.putExtra(Intent.EXTRA_STREAM, lastGeneratedCaptureURI);
|
||||
shareIntent.putExtra(UploadService.EXTRA_SOURCE, Contribution.SOURCE_CAMERA);
|
||||
startActivity(shareIntent);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// See http://stackoverflow.com/a/5054673/17865 for why this is done
|
||||
private Uri lastGeneratedCaptureURI;
|
||||
|
||||
@Override
|
||||
protected void onAuthFailure() {
|
||||
super.onAuthFailure();
|
||||
finish(); // If authentication failed, we just exit
|
||||
}
|
||||
|
||||
private void reGenerateImageCaptureURI() {
|
||||
String storageState = Environment.getExternalStorageState();
|
||||
if(storageState.equals(Environment.MEDIA_MOUNTED)) {
|
||||
|
||||
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Commons/images/" + new Date().getTime() + ".jpg";
|
||||
File _photoFile = new File(path);
|
||||
try {
|
||||
if(_photoFile.exists() == false) {
|
||||
_photoFile.getParentFile().mkdirs();
|
||||
_photoFile.createNewFile();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.e("Commons", "Could not create file: " + path, e);
|
||||
}
|
||||
|
||||
lastGeneratedCaptureURI = Uri.fromFile(_photoFile);
|
||||
} else {
|
||||
throw new RuntimeException("No external storage found!");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch(item.getItemId()) {
|
||||
case R.id.menu_from_gallery:
|
||||
Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
pickImageIntent.setType("image/*");
|
||||
startActivityForResult(pickImageIntent, SELECT_FROM_GALLERY);
|
||||
return true;
|
||||
case R.id.menu_from_camera:
|
||||
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
reGenerateImageCaptureURI();
|
||||
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, lastGeneratedCaptureURI);
|
||||
startActivityForResult(takePictureIntent, SELECT_FROM_CAMERA);
|
||||
return true;
|
||||
case android.R.id.home:
|
||||
if(mediaDetails.isVisible()) {
|
||||
getSupportFragmentManager().popBackStack();
|
||||
|
|
@ -226,6 +142,13 @@ public class ContributionsActivity
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAuthFailure() {
|
||||
super.onAuthFailure();
|
||||
finish(); // If authentication failed, we just exit
|
||||
}
|
||||
|
||||
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int position, long item) {
|
||||
Cursor cursor = (Cursor)adapterView.getItemAtPosition(position);
|
||||
Contribution c = Contribution.fromCursor(cursor);
|
||||
|
|
@ -241,8 +164,7 @@ public class ContributionsActivity
|
|||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getSupportMenuInflater().inflate(R.menu.activity_contributions, menu);
|
||||
return true;
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
package org.wikimedia.commons.contributions;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v4.widget.CursorAdapter;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
|
@ -14,19 +19,27 @@ import android.widget.GridView;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
|
||||
import org.wikimedia.commons.R;
|
||||
import org.wikimedia.commons.ShareActivity;
|
||||
import org.wikimedia.commons.UploadService;
|
||||
import org.wikimedia.commons.Utils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
public class ContributionsListFragment extends SherlockFragment {
|
||||
|
||||
private final static int SELECT_FROM_GALLERY = 1;
|
||||
private final static int SELECT_FROM_CAMERA = 2;
|
||||
|
||||
private GridView contributionsList;
|
||||
|
||||
private ContributionsListAdapter contributionsAdapter;
|
||||
|
|
@ -108,11 +121,97 @@ public class ContributionsListFragment extends SherlockFragment {
|
|||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("grid-position", contributionsList.getFirstVisiblePosition());
|
||||
outState.putParcelable("lastGeneratedCaptureURI", lastGeneratedCaptureURI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
switch(requestCode) {
|
||||
case SELECT_FROM_GALLERY:
|
||||
if(resultCode == Activity.RESULT_OK) {
|
||||
Intent shareIntent = new Intent(getActivity(), ShareActivity.class);
|
||||
shareIntent.setAction(Intent.ACTION_SEND);
|
||||
Log.d("Commons", "Type is " + data.getType() + " Uri is " + data.getData());
|
||||
shareIntent.setType("image/*"); //FIXME: Find out appropriate mime type
|
||||
shareIntent.putExtra(Intent.EXTRA_STREAM, data.getData());
|
||||
shareIntent.putExtra(UploadService.EXTRA_SOURCE, Contribution.SOURCE_GALLERY);
|
||||
startActivity(shareIntent);
|
||||
}
|
||||
break;
|
||||
case SELECT_FROM_CAMERA:
|
||||
if(resultCode == Activity.RESULT_OK) {
|
||||
Intent shareIntent = new Intent(getActivity(), ShareActivity.class);
|
||||
shareIntent.setAction(Intent.ACTION_SEND);
|
||||
Log.d("Commons", "Uri is " + lastGeneratedCaptureURI);
|
||||
shareIntent.setType("image/jpeg"); //FIXME: Find out appropriate mime type
|
||||
shareIntent.putExtra(Intent.EXTRA_STREAM, lastGeneratedCaptureURI);
|
||||
shareIntent.putExtra(UploadService.EXTRA_SOURCE, Contribution.SOURCE_CAMERA);
|
||||
startActivity(shareIntent);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// See http://stackoverflow.com/a/5054673/17865 for why this is done
|
||||
private Uri lastGeneratedCaptureURI;
|
||||
|
||||
private void reGenerateImageCaptureURI() {
|
||||
String storageState = Environment.getExternalStorageState();
|
||||
if(storageState.equals(Environment.MEDIA_MOUNTED)) {
|
||||
|
||||
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Commons/images/" + new Date().getTime() + ".jpg";
|
||||
File _photoFile = new File(path);
|
||||
try {
|
||||
if(_photoFile.exists() == false) {
|
||||
_photoFile.getParentFile().mkdirs();
|
||||
_photoFile.createNewFile();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.e("Commons", "Could not create file: " + path, e);
|
||||
}
|
||||
|
||||
lastGeneratedCaptureURI = Uri.fromFile(_photoFile);
|
||||
} else {
|
||||
throw new RuntimeException("No external storage found!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch(item.getItemId()) {
|
||||
case R.id.menu_from_gallery:
|
||||
Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
pickImageIntent.setType("image/*");
|
||||
startActivityForResult(pickImageIntent, SELECT_FROM_GALLERY);
|
||||
return true;
|
||||
case R.id.menu_from_camera:
|
||||
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
reGenerateImageCaptureURI();
|
||||
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, lastGeneratedCaptureURI);
|
||||
startActivityForResult(takePictureIntent, SELECT_FROM_CAMERA);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.clear(); // See http://stackoverflow.com/a/8495697/17865
|
||||
inflater.inflate(R.menu.fragment_contributions_list, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
contributionsList = (GridView)getView().findViewById(R.id.contributionsList);
|
||||
contributionDisplayOptions = new DisplayImageOptions.Builder().cacheInMemory()
|
||||
|
|
@ -125,6 +224,7 @@ public class ContributionsListFragment extends SherlockFragment {
|
|||
contributionsList.setOnItemClickListener((AdapterView.OnItemClickListener)getActivity());
|
||||
if(savedInstanceState != null) {
|
||||
Log.d("Commons", "Scrolling to " + savedInstanceState.getInt("grid-position"));
|
||||
lastGeneratedCaptureURI = (Uri) savedInstanceState.getParcelable("lastGeneratedCaptureURI");
|
||||
contributionsList.setSelection(savedInstanceState.getInt("grid-position"));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ public class MediaDetailPagerFragment extends SherlockFragment {
|
|||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.clear(); // see http://stackoverflow.com/a/8495697/17865
|
||||
inflater.inflate(R.menu.fragment_image_detail, menu);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue