Merge branch 'raphaelm-issue_139'

This commit is contained in:
Vavassor 2017-04-21 01:08:55 -04:00
commit 70f8b6dc40
7 changed files with 144 additions and 35 deletions

View file

@ -95,6 +95,16 @@
<action android:name="android.service.quicksettings.action.QS_TILE" /> <action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter> </intent-filter>
</service> </service>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.keylesspalace.tusky.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application> </application>
</manifest> </manifest>

View file

@ -36,8 +36,10 @@ import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.provider.MediaStore;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -48,6 +50,7 @@ import android.support.v13.view.inputmethod.InputConnectionCompat;
import android.support.v13.view.inputmethod.InputContentInfoCompat; import android.support.v13.view.inputmethod.InputContentInfoCompat;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.content.res.AppCompatResources; import android.support.v7.content.res.AppCompatResources;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
@ -77,9 +80,11 @@ import com.keylesspalace.tusky.entity.Media;
import com.keylesspalace.tusky.entity.Status; import com.keylesspalace.tusky.entity.Status;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
@ -99,9 +104,11 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
private static final int STATUS_CHARACTER_LIMIT = 500; private static final int STATUS_CHARACTER_LIMIT = 500;
private static final int STATUS_MEDIA_SIZE_LIMIT = 4000000; // 4MB private static final int STATUS_MEDIA_SIZE_LIMIT = 4000000; // 4MB
private static final int MEDIA_PICK_RESULT = 1; private static final int MEDIA_PICK_RESULT = 1;
private static final int MEDIA_TAKE_PHOTO_RESULT = 2;
private static final int PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1; private static final int PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;
private static final int MEDIA_SIZE_UNKNOWN = -1; private static final int MEDIA_SIZE_UNKNOWN = -1;
private static final int COMPOSE_SUCCESS = -1; private static final int COMPOSE_SUCCESS = -1;
private static final int THUMBNAIL_SIZE = 128;
private String inReplyToId; private String inReplyToId;
private EditText textEditor; private EditText textEditor;
@ -121,9 +128,11 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
private TextView charactersLeft; private TextView charactersLeft;
private Button floatingBtn; private Button floatingBtn;
private ImageButton pickBtn; private ImageButton pickBtn;
private ImageButton takeBtn;
private Button nsfwBtn; private Button nsfwBtn;
private ProgressBar postProgress; private ProgressBar postProgress;
private ImageButton visibilityBtn; private ImageButton visibilityBtn;
private Uri photoUploadUri;
private static class QueuedMedia { private static class QueuedMedia {
enum Type { enum Type {
@ -342,6 +351,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
floatingBtn = (Button) findViewById(R.id.floating_btn); floatingBtn = (Button) findViewById(R.id.floating_btn);
pickBtn = (ImageButton) findViewById(R.id.compose_photo_pick); pickBtn = (ImageButton) findViewById(R.id.compose_photo_pick);
takeBtn = (ImageButton) findViewById(R.id.compose_photo_take);
nsfwBtn = (Button) findViewById(R.id.action_toggle_nsfw); nsfwBtn = (Button) findViewById(R.id.action_toggle_nsfw);
visibilityBtn = (ImageButton) findViewById(R.id.action_toggle_visibility); visibilityBtn = (ImageButton) findViewById(R.id.action_toggle_visibility);
@ -357,6 +367,12 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
onMediaPick(); onMediaPick();
} }
}); });
takeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
initiateCameraApp();
}
});
nsfwBtn.setOnClickListener(new View.OnClickListener() { nsfwBtn.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -565,6 +581,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
private void disableButtons() { private void disableButtons() {
pickBtn.setClickable(false); pickBtn.setClickable(false);
takeBtn.setClickable(false);
nsfwBtn.setClickable(false); nsfwBtn.setClickable(false);
visibilityBtn.setClickable(false); visibilityBtn.setClickable(false);
floatingBtn.setEnabled(false); floatingBtn.setEnabled(false);
@ -572,6 +589,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
private void enableButtons() { private void enableButtons() {
pickBtn.setClickable(true); pickBtn.setClickable(true);
takeBtn.setClickable(true);
nsfwBtn.setClickable(true); nsfwBtn.setClickable(true);
visibilityBtn.setClickable(true); visibilityBtn.setClickable(true);
floatingBtn.setEnabled(true); floatingBtn.setEnabled(true);
@ -944,6 +962,42 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
} }
} }
private File createNewImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
String imageFileName = "Tusky_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
return image;
}
private void initiateCameraApp() {
// We don't need to ask for permission in this case, because the used calls require
// android.permission.WRITE_EXTERNAL_STORAGE only on SDKs *older* than Kitkat, which was
// way before permission dialogues have been introduced.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = createNewImageFile();
} catch (IOException ex) {
displayTransientError(R.string.error_media_upload_opening);
}
// Continue only if the File was successfully created
if (photoFile != null) {
photoUploadUri = FileProvider.getUriForFile(this,
"com.keylesspalace.tusky.fileprovider",
photoFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUploadUri);
startActivityForResult(intent, MEDIA_TAKE_PHOTO_RESULT);
}
}
}
private void initiateMediaPicking() { private void initiateMediaPicking() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE); intent.addCategory(Intent.CATEGORY_OPENABLE);
@ -957,16 +1011,22 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
startActivityForResult(intent, MEDIA_PICK_RESULT); startActivityForResult(intent, MEDIA_PICK_RESULT);
} }
private void enableMediaPicking() { private void enableMediaButtons() {
pickBtn.setEnabled(true); pickBtn.setEnabled(true);
ThemeUtils.setDrawableTint(this, pickBtn.getDrawable(), ThemeUtils.setDrawableTint(this, pickBtn.getDrawable(),
R.attr.compose_media_button_tint); R.attr.compose_media_button_tint);
takeBtn.setEnabled(true);
ThemeUtils.setDrawableTint(this, takeBtn.getDrawable(),
R.attr.compose_media_button_tint);
} }
private void disableMediaPicking() { private void disableMediaButtons() {
pickBtn.setEnabled(false); pickBtn.setEnabled(false);
ThemeUtils.setDrawableTint(this, pickBtn.getDrawable(), ThemeUtils.setDrawableTint(this, pickBtn.getDrawable(),
R.attr.compose_media_button_disabled_tint); R.attr.compose_media_button_disabled_tint);
takeBtn.setEnabled(false);
ThemeUtils.setDrawableTint(this, takeBtn.getDrawable(),
R.attr.compose_media_button_disabled_tint);
} }
private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) { private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) {
@ -1001,11 +1061,11 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
textEditor.getPaddingRight(), totalHeight); textEditor.getPaddingRight(), totalHeight);
// If there's one video in the queue it is full, so disable the button to queue more. // If there's one video in the queue it is full, so disable the button to queue more.
if (item.type == QueuedMedia.Type.VIDEO) { if (item.type == QueuedMedia.Type.VIDEO) {
disableMediaPicking(); disableMediaButtons();
} }
} else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) { } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
// Limit the total media attachments, also. // Limit the total media attachments, also.
disableMediaPicking(); disableMediaButtons();
} }
if (queuedCount >= 1) { if (queuedCount >= 1) {
showMarkSensitive(true); showMarkSensitive(true);
@ -1028,7 +1088,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
textEditor.setPadding(textEditor.getPaddingLeft(), textEditor.getPaddingTop(), textEditor.setPadding(textEditor.getPaddingLeft(), textEditor.getPaddingTop(),
textEditor.getPaddingRight(), 0); textEditor.getPaddingRight(), 0);
} }
enableMediaPicking(); enableMediaButtons();
cancelReadyingMedia(item); cancelReadyingMedia(item);
} }
@ -1189,9 +1249,20 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
Uri uri = data.getData(); Uri uri = data.getData();
long mediaSize = getMediaSize(getContentResolver(), uri); long mediaSize = getMediaSize(getContentResolver(), uri);
pickMedia(uri, mediaSize); pickMedia(uri, mediaSize);
} else if (requestCode == MEDIA_TAKE_PHOTO_RESULT && resultCode == RESULT_OK) {
queueCameraResult();
} }
} }
private void queueCameraResult() {
ContentResolver contentResolver = getContentResolver();
Cursor returnCursor = contentResolver.query(photoUploadUri, null, null, null, null);
int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
returnCursor.moveToFirst();
pickMedia(photoUploadUri, returnCursor.getLong(sizeIndex));
}
private void pickMedia(Uri uri, long mediaSize) { private void pickMedia(Uri uri, long mediaSize) {
ContentResolver contentResolver = getContentResolver(); ContentResolver contentResolver = getContentResolver();
if (mediaSize == MEDIA_SIZE_UNKNOWN) { if (mediaSize == MEDIA_SIZE_UNKNOWN) {
@ -1215,7 +1286,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
MediaMetadataRetriever retriever = new MediaMetadataRetriever(); MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(this, uri); retriever.setDataSource(this, uri);
Bitmap source = retriever.getFrameAtTime(); Bitmap source = retriever.getFrameAtTime();
Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, 128, 128); Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, THUMBNAIL_SIZE, THUMBNAIL_SIZE);
source.recycle(); source.recycle();
addMediaToQueue(QueuedMedia.Type.VIDEO, bitmap, uri, mediaSize); addMediaToQueue(QueuedMedia.Type.VIDEO, bitmap, uri, mediaSize);
break; break;
@ -1228,8 +1299,9 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
displayTransientError(R.string.error_media_upload_opening); displayTransientError(R.string.error_media_upload_opening);
return; return;
} }
Bitmap source = BitmapFactory.decodeStream(stream); Bitmap source = BitmapFactory.decodeStream(stream);
Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, 128, 128); Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, THUMBNAIL_SIZE, THUMBNAIL_SIZE);
source.recycle(); source.recycle();
try { try {
if (stream != null) { if (stream != null) {

View file

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/toolbar_icon_dark"
android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0"/>
<path
android:fillColor="@color/toolbar_icon_dark"
android:pathData="M9,2L7.17,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2L9,2zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z"/>
</vector>

View file

@ -19,6 +19,33 @@
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:elevation="4dp" /> android:elevation="4dp" />
<LinearLayout
android:id="@+id/compose_content_warning_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="8dp">
<EditText
android:id="@+id/field_content_warning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:ems="10"
android:maxLines="1"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:hint="@string/hint_content_warning"
android:inputType="text|textCapSentences" />
<View
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"/>
</LinearLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/compose_edit_area" android:id="@+id/compose_edit_area"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -56,32 +83,6 @@
</RelativeLayout> </RelativeLayout>
<LinearLayout
android:id="@+id/compose_content_warning_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="8dp">
<EditText
android:id="@+id/field_content_warning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:ems="10"
android:maxLines="1"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:hint="@string/hint_content_warning"
android:inputType="text|textCapSentences" />
<View
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -91,6 +92,15 @@
android:paddingRight="16dp" android:paddingRight="16dp"
android:paddingTop="4dp"> android:paddingTop="4dp">
<ImageButton
android:id="@+id/compose_photo_take"
style="?attr/image_button_style"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginRight="8dp"
app:srcCompat="@drawable/ic_camera_24dp"
android:contentDescription="@string/action_photo_take" />
<ImageButton <ImageButton
android:id="@+id/compose_photo_pick" android:id="@+id/compose_photo_pick"
style="?attr/image_button_style" style="?attr/image_button_style"

View file

@ -45,7 +45,7 @@
<string name="notification_favourite_format">%s iletini favori etti</string> <string name="notification_favourite_format">%s iletini favori etti</string>
<string name="notification_follow_format">%s seni takip etti</string> <string name="notification_follow_format">%s seni takip etti</string>
<string name="report_username_format">@%s bildir</string> <string name="report_username_format">\@%s bildir</string>
<string name="report_comment_hint">Daha fazla yorum?</string> <string name="report_comment_hint">Daha fazla yorum?</string>
<string name="action_reply">Yanıtla</string> <string name="action_reply">Yanıtla</string>

View file

@ -81,6 +81,7 @@
<string name="action_open_in_web">Open in browser</string> <string name="action_open_in_web">Open in browser</string>
<string name="action_submit">Submit</string> <string name="action_submit">Submit</string>
<string name="action_photo_pick">Add media</string> <string name="action_photo_pick">Add media</string>
<string name="action_photo_take">Take photo</string>
<string name="action_share">Share</string> <string name="action_share">Share</string>
<string name="action_mute">Mute</string> <string name="action_mute">Mute</string>
<string name="action_unmute">Unmute</string> <string name="action_unmute">Unmute</string>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" />
</paths>