Merge pull request #194 from misaochan/google-photos-fix

Google Photos fix attempt
This commit is contained in:
Nicolas Raoul 2016-07-19 15:18:13 +09:00 committed by GitHub
commit fa5b6c0869
6 changed files with 15 additions and 6 deletions

View file

@ -16,6 +16,7 @@ public abstract class HandlerService<T> extends Service {
@Override
public void handleMessage(Message msg) {
//FIXME: Google Photos bug
handle(msg.what, (T)msg.obj);
stopSelf(msg.arg1);
}

View file

@ -61,18 +61,20 @@ public class ContributionController {
}
public void startGalleryPick() {
//FIXME: Starts gallery (opens Google Photos)
Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
pickImageIntent.setType("image/*");
fragment.startActivityForResult(pickImageIntent, SELECT_FROM_GALLERY);
}
public void handleImagePicked(int requestCode, Intent data) {
public void handleImagePicked(int requestCode, Uri imageData) {
Intent shareIntent = new Intent(activity, ShareActivity.class);
shareIntent.setAction(Intent.ACTION_SEND);
switch(requestCode) {
case SELECT_FROM_GALLERY:
shareIntent.setType(activity.getContentResolver().getType(data.getData()));
shareIntent.putExtra(Intent.EXTRA_STREAM, data.getData());
//FIXME: Handles image picked from gallery (from Google Photos)
shareIntent.setType(activity.getContentResolver().getType(imageData));
shareIntent.putExtra(Intent.EXTRA_STREAM, imageData);
shareIntent.putExtra(UploadService.EXTRA_SOURCE, fr.free.nrw.commons.contributions.Contribution.SOURCE_GALLERY);
break;
case SELECT_FROM_CAMERA:

View file

@ -227,6 +227,7 @@ public class ContributionsActivity
}
//FIXME: Potential cause of wrong image display bug
public Media getMediaAtPosition(int i) {
if (contributionsList.getAdapter() == null) {
// not yet ready to return data

View file

@ -36,6 +36,7 @@ class ContributionsListAdapter extends CursorAdapter {
return parent;
}
//FIXME: Potential cause of wrong image display bug
@Override
public void bindView(View view, Context context, Cursor cursor) {
final ContributionViewHolder views = (ContributionViewHolder)view.getTag();

View file

@ -7,6 +7,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
@ -29,6 +30,7 @@ import fr.free.nrw.commons.AboutActivity;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.SettingsActivity;
import fr.free.nrw.commons.upload.UploadService;
public class ContributionsListFragment extends Fragment {
@ -88,10 +90,10 @@ public class ContributionsListFragment extends Fragment {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
//FIXME: must get the file data for Google Photos when receive the intent answer, in the onActivityResult method
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == Activity.RESULT_OK) {
controller.handleImagePicked(requestCode, data);
}
Uri imageData = data.getData();
controller.handleImagePicked(requestCode, imageData);
}

View file

@ -111,6 +111,7 @@ public class UploadService extends HandlerService<Contribution> {
protected void handle(int what, Contribution contribution) {
switch(what) {
case ACTION_UPLOAD_FILE:
//FIXME: Google Photos bug
uploadContribution(contribution);
break;
default:
@ -173,6 +174,7 @@ public class UploadService extends HandlerService<Contribution> {
String notificationTag = contribution.getLocalUri().toString();
try {
//FIXME: Google Photos bug
file = this.getContentResolver().openInputStream(contribution.getLocalUri());
} catch(FileNotFoundException e) {
Log.d("Exception", "File not found");