Browse Source

Uploads UI fixes

pull/50/head
Apostolos Fanakis 6 years ago
parent
commit
9a9633e3e3
  1. 77
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  2. 5
      app/src/main/res/drawable/ic_photo_camera_white_24dp.xml
  3. 35
      app/src/main/res/layout/activity_upload.xml
  4. 2
      app/src/main/res/values/strings.xml

77
app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java

@ -11,7 +11,6 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.AlertDialog;
import android.support.v7.content.res.AppCompatResources;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.AppCompatButton;
@ -21,6 +20,7 @@ import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import net.gotev.uploadservice.MultipartUploadRequest;
@ -86,8 +86,7 @@ public class UploadActivity extends BaseActivity {
private EditText uploadTitle;
private EditText uploadDescription;
private AppCompatButton titleDescriptionBuilderButton;
private AppCompatButton selectFileButton;
//private static AppCompatButton titleDescriptionBuilderButton;
private TextView filenameHolder;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -193,47 +192,39 @@ public class UploadActivity extends BaseActivity {
uploadTitle = findViewById(R.id.upload_title);
uploadDescription = findViewById(R.id.upload_description);
selectFileButton = findViewById(R.id.upload_select_file_button);
filenameHolder = findViewById(R.id.upload_filename);
AppCompatButton selectFileButton = findViewById(R.id.upload_select_file_button);
Drawable selectStartDrawable = AppCompatResources.getDrawable(this, R.drawable.ic_insert_drive_file_white_24dp);
selectFileButton.setCompoundDrawablesRelativeWithIntrinsicBounds(selectStartDrawable, null, null, null);
selectFileButton.setOnClickListener(v -> {
final CharSequence[] options = {"Take photo", "Choose file",
"Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(UploadActivity.this);
builder.setTitle("Upload file");
builder.setItems(options, (dialog, item) -> {
if (options[item].equals("Take photo")) {
/*Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CODE_CAMERA);*/
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePhotoIntent.putExtra("return-data", true);
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(UploadsHelper.getTempFile(this)));
Intent targetedIntent = new Intent(takePhotoIntent);
List<ResolveInfo> resInfo = this.getPackageManager().queryIntentActivities(takePhotoIntent, 0);
for (ResolveInfo resolveInfo : resInfo) {
String packageName = resolveInfo.activityInfo.packageName;
targetedIntent.setPackage(packageName);
}
startActivityForResult(takePhotoIntent, REQUEST_CODE_CAMERA);
String[] mimeTypes = {"image/jpeg", "text/html", "image/png", "image/jpg", "image/gif",
"application/pdf", "application/rar", "application/x-tar", "application/zip",
"application/msword", "image/vnd.djvu", "application/gz", "application/tar.gz"};
} else if (options[item].equals("Choose file")) {
String[] mimeTypes = {"image/jpeg", "text/html", "image/png", "image/jpg", "image/gif",
"application/pdf", "application/rar", "application/x-tar", "application/zip",
"application/msword", "image/vnd.djvu", "application/gz", "application/tar.gz"};
Intent intent = new Intent(Intent.ACTION_GET_CONTENT)
//.setType("*/*")
.setType("image/jpeg")
.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
Intent intent = new Intent(Intent.ACTION_GET_CONTENT)
//.setType("*/*")
.setType("image/jpeg")
.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
startActivityForResult(intent, REQUEST_CODE_CHOOSE_FILE);
});
startActivityForResult(intent, REQUEST_CODE_CHOOSE_FILE);
} else if (options[item].equals("Cancel")) {
dialog.dismiss();
}
});
builder.show();
AppCompatButton takePhotoButton = findViewById(R.id.upload_take_photo_button);
Drawable takePhotoDrawable = AppCompatResources.getDrawable(this, R.drawable.ic_photo_camera_white_24dp);
takePhotoButton.setCompoundDrawablesRelativeWithIntrinsicBounds(takePhotoDrawable, null, null, null);
takePhotoButton.setOnClickListener(v -> {
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePhotoIntent.putExtra("return-data", true);
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(UploadsHelper.getTempFile(this)));
Intent targetedIntent = new Intent(takePhotoIntent);
List<ResolveInfo> resInfo = this.getPackageManager().queryIntentActivities(takePhotoIntent, 0);
for (ResolveInfo resolveInfo : resInfo) {
String packageName = resolveInfo.activityInfo.packageName;
targetedIntent.setPackage(packageName);
}
startActivityForResult(takePhotoIntent, REQUEST_CODE_CAMERA);
});
findViewById(R.id.upload_upload_button).setOnClickListener(view -> {
@ -244,7 +235,7 @@ public class UploadActivity extends BaseActivity {
uploadTitle.setError("Required");
}
if (fileUri == null) {
selectFileButton.setError("Required");
filenameHolder.setError("Required");
}
if (categorySelected.equals("-1")) {
Toast.makeText(view.getContext(), "Please choose category first", Toast.LENGTH_SHORT).show();
@ -308,6 +299,10 @@ public class UploadActivity extends BaseActivity {
Toast.makeText(context, "Failed to delete temporary file", Toast.LENGTH_SHORT).show();
}
}
uploadTitle.setText(null);
uploadDescription.setText(null);
filenameHolder.setText(R.string.upload_filename);
}
@Override
@ -392,7 +387,7 @@ public class UploadActivity extends BaseActivity {
fileUri = data.getData();
if (fileUri != null) {
String filename = UploadsHelper.filenameFromUri(this, fileUri);
selectFileButton.setText(filename);
filenameHolder.setText(filename);
filename = filename.toLowerCase();
if (filename.endsWith(".jpg")) {
@ -443,7 +438,7 @@ public class UploadActivity extends BaseActivity {
fileUri = Uri.parse(UploadsHelper.createTempFile(this, fileUri, newFilename));
newFilename += ".jpg";
selectFileButton.setText(newFilename);
filenameHolder.setText(newFilename);
}
} else if (requestCode == REQUEST_CODE_FIELDS_BUILDER) {
if (resultCode == Activity.RESULT_CANCELED) {

5
app/src/main/res/drawable/ic_photo_camera_white_24dp.xml

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp">
<path android:fillColor="#FFFFFF" 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="#FFFFFF" 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>

35
app/src/main/res/layout/activity_upload.xml

@ -98,13 +98,26 @@
android:textAlignment="center"
android:textColor="@color/accent" />
<TextView
android:id="@+id/upload_filename"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"
android:ellipsize="marquee"
android:singleLine="true"
android:textColor="@color/primary_text"
android:text="@string/upload_filename"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<android.support.v7.widget.AppCompatButton
android:id="@+id/upload_select_file_button"
android:layout_width="wrap_content"
@ -116,17 +129,31 @@
android:text="@string/upload_select_file"
android:textColor="@color/primary_text" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<android.support.v7.widget.AppCompatButton
android:id="@+id/upload_upload_button"
android:id="@+id/upload_take_photo_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="16dp"
android:drawablePadding="5dp"
android:gravity="center_vertical"
android:text="@string/upload_upload_button"
android:textAlignment="center"
android:textColor="@color/accent" />
android:text="@string/upload_select_file"
android:textColor="@color/primary_text" />
</LinearLayout>
<android.support.v7.widget.AppCompatButton
android:id="@+id/upload_upload_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/upload_upload_button"
android:textAlignment="center"
android:textColor="@color/accent" />
</LinearLayout>
</ScrollView>

2
app/src/main/res/values/strings.xml

@ -112,7 +112,9 @@
<string name="upload_title_description_builder">Generate title and description</string>
<string name="upload_title_hint">Title</string>
<string name="upload_description_hint">Description</string>
<string name="upload_filename">Filename</string>
<string name="upload_select_file">Select file</string>
<string name="upload_take_photo">Take photo</string>
<string name="upload_upload_button">Upload</string>
<string name="upload_spinners_hint">Select a category</string>

Loading…
Cancel
Save