Browse Source

Merge remote-tracking branch 'origin/ui_adjustment' into develop

# Conflicts:
#	app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
pull/50/head
Apostolos Fanakis 6 years ago
parent
commit
2fc2fab706
  1. 72
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  2. 4
      app/src/main/res/drawable/ic_attach_file_white_24dp.xml
  3. 5
      app/src/main/res/drawable/ic_photo_camera_white_24dp.xml
  4. 87
      app/src/main/res/layout/activity_upload.xml
  5. 14
      app/src/main/res/layout/spinner_dropdown_item.xml
  6. 14
      app/src/main/res/layout/spinner_item.xml
  7. 1
      app/src/main/res/values-w820dp/dimens.xml
  8. 1
      app/src/main/res/values/dimens.xml
  9. 8
      app/src/main/res/values/strings.xml

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

@ -4,16 +4,18 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
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.design.widget.FloatingActionButton;
import android.support.v7.content.res.AppCompatResources;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.AppCompatTextView;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
@ -38,6 +40,7 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import gr.thmmy.mthmmy.R;
@ -87,7 +90,7 @@ public class UploadActivity extends BaseActivity {
private EditText uploadTitle;
private EditText uploadDescription;
private AppCompatButton titleDescriptionBuilderButton;
private AppCompatButton selectFileButton;
private AppCompatTextView filenameHolder;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -193,22 +196,14 @@ 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);
Drawable filenameDrawable = AppCompatResources.getDrawable(this, R.drawable.ic_attach_file_white_24dp);
filenameHolder.setCompoundDrawablesRelativeWithIntrinsicBounds(filenameDrawable, null, null, null);
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 takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePhotoIntent.putExtra("return-data", true);
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(UploadsHelper.getCacheFile(this)));
startActivityForResult(takePhotoIntent, AFR_REQUEST_CODE_CAMERA);
} 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"};
@ -219,14 +214,27 @@ public class UploadActivity extends BaseActivity {
.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
startActivityForResult(intent, AFR_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, AFR_REQUEST_CODE_CAMERA);
});
findViewById(R.id.upload_upload_button).setOnClickListener(view -> {
FloatingActionButton uploadFAB = findViewById(R.id.upload_fab);
uploadFAB.setOnClickListener(view -> {
progressBar.setVisibility(View.VISIBLE);
String uploadTitleText = uploadTitle.getText().toString();
@ -236,7 +244,7 @@ public class UploadActivity extends BaseActivity {
uploadTitle.setError("Required");
}
if (fileUri == null) {
selectFileButton.setError("Required");
Toast.makeText(view.getContext(), "Please choose a file to upload or take a photo", Toast.LENGTH_LONG).show();
}
if (categorySelected.equals("-1")) {
Toast.makeText(view.getContext(), "Please choose category first", Toast.LENGTH_SHORT).show();
@ -296,11 +304,19 @@ public class UploadActivity extends BaseActivity {
Toast.makeText(context, "Upload completed successfully", Toast.LENGTH_SHORT).show();
UploadsHelper.deleteTempFiles();
BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_upload", null);
uploadTitle.setText(null);
uploadDescription.setText(null);
fileUri = null;
filenameHolder.setText(null);
filenameHolder.setVisibility(View.GONE);
progressBar.setVisibility(View.GONE);
}
@Override
public void onCancelled(Context context, UploadInfo uploadInfo) {
Toast.makeText(context, "Upload canceled", Toast.LENGTH_SHORT).show();
UploadsHelper.deleteTempFiles();
progressBar.setVisibility(View.GONE);
}
@ -355,7 +371,8 @@ public class UploadActivity extends BaseActivity {
fileUri = data.getData();
if (fileUri != null) {
String filename = UploadsHelper.filenameFromUri(this, fileUri);
selectFileButton.setText(filename);
filenameHolder.setText(filename);
filenameHolder.setVisibility(View.VISIBLE);
filename = filename.toLowerCase();
if (filename.endsWith(".jpg")) {
@ -406,7 +423,8 @@ public class UploadActivity extends BaseActivity {
fileUri = Uri.parse(UploadsHelper.createTempFile(this, cacheFileUri, newFilename));
newFilename += ".jpg";
selectFileButton.setText(newFilename);
filenameHolder.setText(newFilename);
filenameHolder.setVisibility(View.VISIBLE);
UploadsHelper.deleteCacheFiles(this);
} else if (requestCode == AFR_REQUEST_CODE_FIELDS_BUILDER) {
@ -455,8 +473,8 @@ public class UploadActivity extends BaseActivity {
}
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(getApplicationContext(),
android.R.layout.simple_spinner_dropdown_item, tmpSpinnerArray);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
R.layout.spinner_item, tmpSpinnerArray);
spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
AppCompatSpinnerWithoutDefault subSpinner = new AppCompatSpinnerWithoutDefault(categoriesSpinners.getContext());
subSpinner.setPromptId(R.string.upload_spinners_hint);
@ -562,8 +580,8 @@ public class UploadActivity extends BaseActivity {
}
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(BaseApplication.getInstance().getApplicationContext(),
android.R.layout.simple_spinner_dropdown_item, tmpSpinnerArray);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
R.layout.spinner_item, tmpSpinnerArray);
spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
rootCategorySpinner.setAdapter(spinnerArrayAdapter);
//Sets bundle selection

4
app/src/main/res/drawable/ic_attach_file_white_24dp.xml

@ -0,0 +1,4 @@
<?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="M16.5,6v11.5c0,2.21 -1.79,4 -4,4s-4,-1.79 -4,-4V5c0,-1.38 1.12,-2.5 2.5,-2.5s2.5,1.12 2.5,2.5v10.5c0,0.55 -0.45,1 -1,1s-1,-0.45 -1,-1V6H10v9.5c0,1.38 1.12,2.5 2.5,2.5s2.5,-1.12 2.5,-2.5V5c0,-2.21 -1.79,-4 -4,-4S7,2.79 7,5v12.5c0,3.04 2.46,5.5 5.5,5.5s5.5,-2.46 5.5,-5.5V6h-1.5z"/>
</vector>

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>

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

@ -23,7 +23,7 @@
app:popupTheme="@style/ToolbarTheme" />
</android.support.design.widget.AppBarLayout>
<ScrollView
<android.support.v4.widget.NestedScrollView
android:id="@+id/upload_outer_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -41,16 +41,6 @@
android:focusableInTouchMode="true"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"
android:gravity="center"
android:text="@string/upload_category_pre_text"
android:textAlignment="center"
android:textColor="@color/accent" />
<LinearLayout
android:id="@+id/upload_spinners"
android:layout_width="match_parent"
@ -68,25 +58,6 @@
android:prompt="@string/upload_spinners_hint" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:gravity="center"
android:text="@string/upload_title_description_pre_text"
android:textAlignment="center"
android:textColor="@color/accent" />
<android.support.v7.widget.AppCompatButton
android:id="@+id/upload_title_description_builder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:gravity="center"
android:text="@string/upload_title_description_builder"
android:textAlignment="center"
android:textColor="@color/accent" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -113,40 +84,69 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/upload_description_hint"
android:inputType="textMultiLine"
android:maxLines="3" />
android:inputType="textMultiLine" />
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatButton
android:id="@+id/upload_title_description_builder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:gravity="center"
android:text="@string/upload_title_description_builder"
android:textAlignment="center"
android:textColor="@color/accent" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/upload_filename"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"
android:drawablePadding="5dp"
android:ellipsize="marquee"
android:singleLine="true"
android:textColor="@color/primary_text"
android:visibility="gone" />
<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"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="16dp"
android:drawablePadding="5dp"
android:gravity="center_vertical"
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_take_photo"
android:textColor="@color/primary_text" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</android.support.v4.widget.NestedScrollView>
<me.zhanghai.android.materialprogressbar.MaterialProgressBar
android:id="@+id/progressBar"
@ -159,6 +159,15 @@
app:layout_anchorGravity="bottom|center"
app:mpb_indeterminateTint="@color/accent"
app:mpb_progressStyle="horizontal" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/upload_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="@dimen/fab_margins"
android:layout_marginEnd="@dimen/fab_margins"
app:layout_behavior="gr.thmmy.mthmmy.utils.ScrollAwareFABBehavior"
app:srcCompat="@drawable/ic_file_upload_white_24dp" />
</android.support.design.widget.CoordinatorLayout>

14
app/src/main/res/layout/spinner_dropdown_item.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:paddingBottom="6dp"
android:paddingEnd="7dp"
android:paddingStart="7dp"
android:paddingTop="6dp"
android:singleLine="true"
android:textColor="@color/primary_text"
android:textSize="@dimen/medium_text" />

14
app/src/main/res/layout/spinner_item.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:paddingBottom="6dp"
android:paddingEnd="7dp"
android:paddingStart="7dp"
android:paddingTop="6dp"
android:singleLine="true"
android:textColor="@color/primary_text"
android:textSize="@dimen/medium_text" />

1
app/src/main/res/values-w820dp/dimens.xml

@ -9,5 +9,6 @@
<dimen name="post_image_button">144dp</dimen>
<dimen name="fab_margins">64dp</dimen>
<dimen name="progress_bar_height">40dp</dimen>
<dimen name="medium_text">16sp</dimen>
<dimen name="big_text">24sp</dimen>
</resources>

1
app/src/main/res/values/dimens.xml

@ -7,5 +7,6 @@
<dimen name="post_image_button">36dp</dimen>
<dimen name="fab_margins">16dp</dimen>
<dimen name="progress_bar_height">10dp</dimen>
<dimen name="medium_text">16sp</dimen>
<dimen name="big_text">24sp</dimen>
</resources>

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

@ -113,13 +113,11 @@
<string name="upload_button">Upload</string>
<!--Upload Activity-->
<string name="upload_category_pre_text">Select the correct category for the file</string>
<string name="upload_title_description_pre_text">Fill in the title and description\nor</string>
<string name="upload_title_description_builder">build them automatically</string>
<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_select_file">Select file to upload</string>
<string name="upload_upload_button">Upload</string>
<string name="upload_select_file">Select file</string>
<string name="upload_take_photo">Take photo</string>
<string name="upload_spinners_hint">Select a category</string>
<!--Upload Fields Builder Activity-->

Loading…
Cancel
Save