Sharing images from other apps now supported.

This commit is contained in:
Vavassor 2017-04-05 16:35:22 -04:00
parent 209f1ec4a5
commit 0719512134
3 changed files with 65 additions and 14 deletions

View File

@ -38,7 +38,18 @@
<activity android:name=".MainActivity" /> <activity android:name=".MainActivity" />
<activity <activity
android:name=".ComposeActivity" android:name=".ComposeActivity"
android:windowSoftInputMode="stateVisible|adjustResize" /> android:windowSoftInputMode="stateVisible|adjustResize">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<activity android:name=".ViewVideoActivity" android:configChanges="orientation|keyboardHidden|screenSize" /> <activity android:name=".ViewVideoActivity" android:configChanges="orientation|keyboardHidden|screenSize" />
<activity android:name=".ViewThreadActivity" /> <activity android:name=".ViewThreadActivity" />
<activity android:name=".ViewTagActivity" /> <activity android:name=".ViewTagActivity" />

View File

@ -159,8 +159,8 @@ public class BaseActivity extends AppCompatActivity {
getString(R.string.preferences_file_key), Context.MODE_PRIVATE); getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
String domain = preferences.getString("domain", null); String domain = preferences.getString("domain", null);
String accessToken = preferences.getString("accessToken", null); String accessToken = preferences.getString("accessToken", null);
if (domain != null && accessToken != null) { if (domain == null || accessToken == null) {
Intent intent = new Intent(this, MainActivity.class); Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent); startActivity(intent);
finish(); finish();

View File

@ -81,6 +81,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -365,6 +366,8 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
} }
}); });
Intent intent = getIntent();
String startingVisibility; String startingVisibility;
boolean startingHideText; boolean startingHideText;
ArrayList<SavedQueuedMedia> savedMediaQueued = null; ArrayList<SavedQueuedMedia> savedMediaQueued = null;
@ -391,7 +394,6 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
updateNsfwButtonColor(); updateNsfwButtonColor();
Intent intent = getIntent();
String[] mentionedUsernames = null; String[] mentionedUsernames = null;
inReplyToId = null; inReplyToId = null;
if (intent != null) { if (intent != null) {
@ -482,6 +484,39 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
for (SavedQueuedMedia item : savedMediaQueued) { for (SavedQueuedMedia item : savedMediaQueued) {
addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize); addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize);
} }
} else if (savedInstanceState == null) {
/* Get incoming images being sent through a share action from another app. Only do this
* when savedInstanceState is null, otherwise both the images from the intent and the
* instance state will be re-queued. */
String type = intent.getType();
if (type != null && type.startsWith("image/")) {
List<Uri> uriList = new ArrayList<>();
switch (intent.getAction()) {
case Intent.ACTION_SEND: {
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri != null) {
uriList.add(uri);
}
break;
}
case Intent.ACTION_SEND_MULTIPLE: {
ArrayList<Uri> list = intent.getParcelableArrayListExtra(
Intent.EXTRA_STREAM);
if (list != null) {
for (Uri uri : list) {
if (uri != null) {
uriList.add(uri);
}
}
}
break;
}
}
for (Uri uri : uriList) {
long mediaSize = getMediaSize(getContentResolver(), uri);
pickMedia(uri, mediaSize);
}
}
} }
} }
@ -1064,21 +1099,26 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
} }
} }
private static long getMediaSize(ContentResolver contentResolver, Uri uri) {
long mediaSize;
Cursor cursor = contentResolver.query(uri, null, null, null, null);
if (cursor != null) {
int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
cursor.moveToFirst();
mediaSize = cursor.getLong(sizeIndex);
cursor.close();
} else {
mediaSize = MEDIA_SIZE_UNKNOWN;
}
return mediaSize;
}
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (requestCode == MEDIA_PICK_RESULT && resultCode == RESULT_OK && data != null) { if (requestCode == MEDIA_PICK_RESULT && resultCode == RESULT_OK && data != null) {
Uri uri = data.getData(); Uri uri = data.getData();
long mediaSize; long mediaSize = getMediaSize(getContentResolver(), uri);
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
if (cursor != null) {
int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
cursor.moveToFirst();
mediaSize = cursor.getLong(sizeIndex);
cursor.close();
} else {
mediaSize = MEDIA_SIZE_UNKNOWN;
}
pickMedia(uri, mediaSize); pickMedia(uri, mediaSize);
} }
} }