Browse Source

Uploads bug fixes

pull/44/head
Apostolos Fanakis 6 years ago
parent
commit
56a255e4e3
  1. 70
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  2. 14
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java

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

@ -2,7 +2,6 @@ package gr.thmmy.mthmmy.activities.upload;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
@ -18,6 +17,7 @@ import android.support.v7.app.AlertDialog;
import android.support.v7.content.res.AppCompatResources; import android.support.v7.content.res.AppCompatResources;
import android.support.v7.preference.PreferenceManager; import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.AppCompatButton; import android.support.v7.widget.AppCompatButton;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
@ -134,9 +134,7 @@ public class UploadActivity extends BaseActivity {
rootCategorySpinner.setOnItemSelectedListener(new CustomOnItemSelectedListener(uploadRootCategories)); rootCategorySpinner.setOnItemSelectedListener(new CustomOnItemSelectedListener(uploadRootCategories));
titleDescriptionBuilderButton = findViewById(R.id.upload_title_description_builder); titleDescriptionBuilderButton = findViewById(R.id.upload_title_description_builder);
titleDescriptionBuilderButton.setOnClickListener(new View.OnClickListener() { titleDescriptionBuilderButton.setOnClickListener(view -> {
@Override
public void onClick(View view) {
if (categorySelected.equals("-1")) { if (categorySelected.equals("-1")) {
Toast.makeText(view.getContext(), "Please choose category first", Toast.LENGTH_SHORT).show(); Toast.makeText(view.getContext(), "Please choose category first", Toast.LENGTH_SHORT).show();
return; return;
@ -149,10 +147,29 @@ public class UploadActivity extends BaseActivity {
return; return;
} }
String maybeSemester = (String) ((AppCompatSpinnerWithoutDefault) String maybeSemester = "", maybeCourse = "";
if (numberOfSpinners == 5) {
if (((AppCompatSpinnerWithoutDefault) categoriesSpinners.getChildAt(numberOfSpinners - 1)).
getSelectedItemPosition() == -1) {
maybeSemester = (String) ((AppCompatSpinnerWithoutDefault)
categoriesSpinners.getChildAt(numberOfSpinners - 4)).getSelectedItem();
maybeCourse = (String) ((AppCompatSpinnerWithoutDefault)
categoriesSpinners.getChildAt(numberOfSpinners - 2)).getSelectedItem(); categoriesSpinners.getChildAt(numberOfSpinners - 2)).getSelectedItem();
String maybeCourse = (String) ((AppCompatSpinnerWithoutDefault) } else {
Toast.makeText(view.getContext(), "Please choose a course category", Toast.LENGTH_SHORT).show();
}
} else if (numberOfSpinners == 4) {
maybeSemester = (String) ((AppCompatSpinnerWithoutDefault)
categoriesSpinners.getChildAt(numberOfSpinners - 3)).getSelectedItem();
maybeCourse = (String) ((AppCompatSpinnerWithoutDefault)
categoriesSpinners.getChildAt(numberOfSpinners - 1)).getSelectedItem(); categoriesSpinners.getChildAt(numberOfSpinners - 1)).getSelectedItem();
} else {
maybeSemester = (String) ((AppCompatSpinnerWithoutDefault)
categoriesSpinners.getChildAt(numberOfSpinners - 2)).getSelectedItem();
maybeCourse = (String) ((AppCompatSpinnerWithoutDefault)
categoriesSpinners.getChildAt(numberOfSpinners - 1)).getSelectedItem();
}
if (!maybeSemester.contains("εξάμηνο") && !maybeSemester.contains("Εξάμηνο")) { if (!maybeSemester.contains("εξάμηνο") && !maybeSemester.contains("Εξάμηνο")) {
Toast.makeText(view.getContext(), "Please choose a course category", Toast.LENGTH_SHORT).show(); Toast.makeText(view.getContext(), "Please choose a course category", Toast.LENGTH_SHORT).show();
@ -168,12 +185,11 @@ public class UploadActivity extends BaseActivity {
maybeSemester = maybeSemester.replaceAll("-", "").trim().substring(0, 1); maybeSemester = maybeSemester.replaceAll("-", "").trim().substring(0, 1);
Intent intent = new Intent(UploadActivity.this, UploadFieldsBuilderActivity.class); Intent intent = new Intent(UploadActivity.this, UploadFieldsBuilderActivity.class);
Bundle extras = new Bundle(); Bundle builderExtras = new Bundle();
extras.putString(BUNDLE_UPLOAD_FIELD_BUILDER_COURSE, maybeCourse); builderExtras.putString(BUNDLE_UPLOAD_FIELD_BUILDER_COURSE, maybeCourse);
extras.putString(BUNDLE_UPLOAD_FIELD_BUILDER_SEMESTER, maybeSemester); builderExtras.putString(BUNDLE_UPLOAD_FIELD_BUILDER_SEMESTER, maybeSemester);
intent.putExtras(extras); intent.putExtras(builderExtras);
startActivityForResult(intent, REQUEST_CODE_FIELDS_BUILDER); startActivityForResult(intent, REQUEST_CODE_FIELDS_BUILDER);
}
}); });
titleDescriptionBuilderButton.setEnabled(false); titleDescriptionBuilderButton.setEnabled(false);
@ -183,16 +199,12 @@ public class UploadActivity extends BaseActivity {
selectFileButton = findViewById(R.id.upload_select_file_button); selectFileButton = findViewById(R.id.upload_select_file_button);
Drawable selectStartDrawable = AppCompatResources.getDrawable(this, R.drawable.ic_insert_drive_file_white_24dp); Drawable selectStartDrawable = AppCompatResources.getDrawable(this, R.drawable.ic_insert_drive_file_white_24dp);
selectFileButton.setCompoundDrawablesRelativeWithIntrinsicBounds(selectStartDrawable, null, null, null); selectFileButton.setCompoundDrawablesRelativeWithIntrinsicBounds(selectStartDrawable, null, null, null);
selectFileButton.setOnClickListener(new View.OnClickListener() { selectFileButton.setOnClickListener(v -> {
@Override
public void onClick(View v) {
final CharSequence[] options = {"Take photo", "Choose file", final CharSequence[] options = {"Take photo", "Choose file",
"Cancel"}; "Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(UploadActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(UploadActivity.this);
builder.setTitle("Upload file"); builder.setTitle("Upload file");
builder.setItems(options, new DialogInterface.OnClickListener() { builder.setItems(options, (dialog, item) -> {
@Override
public void onClick(DialogInterface dialog, int item) {
if (options[item].equals("Take photo")) { if (options[item].equals("Take photo")) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CODE_CAMERA); startActivityForResult(intent, REQUEST_CODE_CAMERA);
@ -210,15 +222,11 @@ public class UploadActivity extends BaseActivity {
} else if (options[item].equals("Cancel")) { } else if (options[item].equals("Cancel")) {
dialog.dismiss(); dialog.dismiss();
} }
}
}); });
builder.show(); builder.show();
}
}); });
findViewById(R.id.upload_upload_button).setOnClickListener(new View.OnClickListener() { findViewById(R.id.upload_upload_button).setOnClickListener(view -> {
@Override
public void onClick(View view) {
String uploadTitleText = uploadTitle.getText().toString(); String uploadTitleText = uploadTitle.getText().toString();
String uploadDescriptionText = uploadDescription.getText().toString(); String uploadDescriptionText = uploadDescription.getText().toString();
@ -305,7 +313,6 @@ public class UploadActivity extends BaseActivity {
} catch (Exception exception) { } catch (Exception exception) {
Timber.e(exception, "AndroidUploadService: %s", exception.getMessage()); Timber.e(exception, "AndroidUploadService: %s", exception.getMessage());
} }
}
}); });
if (uploadRootCategories.isEmpty()) { if (uploadRootCategories.isEmpty()) {
@ -326,7 +333,7 @@ public class UploadActivity extends BaseActivity {
if (bundleCategory != null) { if (bundleCategory != null) {
int bundleSelectionIndex = -1, currentIndex = 0; int bundleSelectionIndex = -1, currentIndex = 0;
for (UploadCategory category : uploadRootCategories) { for (UploadCategory category : uploadRootCategories) {
if (category.getCategoryTitle().contains(bundleCategory.get(0))) { //TODO fix .contains, always false if (bundleCategory.get(0).contains(category.getCategoryTitle())) {
bundleSelectionIndex = currentIndex; bundleSelectionIndex = currentIndex;
break; break;
} }
@ -335,6 +342,7 @@ public class UploadActivity extends BaseActivity {
if (bundleSelectionIndex != -1) { if (bundleSelectionIndex != -1) {
rootCategorySpinner.setSelection(bundleSelectionIndex, true); rootCategorySpinner.setSelection(bundleSelectionIndex, true);
bundleCategory.remove(0);
} }
} }
@ -435,6 +443,7 @@ public class UploadActivity extends BaseActivity {
return filename; return filename;
} }
@SuppressWarnings("ResultOfMethodCallIgnored")
@Nullable @Nullable
private String createTempFile(String newFilename) { private String createTempFile(String newFilename) {
String oldFilename = filenameFromUri(fileUri); String oldFilename = filenameFromUri(fileUri);
@ -534,10 +543,12 @@ public class UploadActivity extends BaseActivity {
categoriesSpinners.addView(subSpinner); categoriesSpinners.addView(subSpinner);
//Sets bundle selection //Sets bundle selection
if (bundleCategory != null && viewIndex < bundleCategory.size()) { if (bundleCategory != null && !bundleCategory.isEmpty()) {
int bundleSelectionIndex = -1, currentIndex = 0; int bundleSelectionIndex = -1, currentIndex = 0;
for (UploadCategory category : parentCategories) {
if (category.getCategoryTitle().contains(bundleCategory.get(viewIndex))) { for (UploadCategory category : childCategories) {
if (bundleCategory.get(0).contains(category.getCategoryTitle()
.replace("-", "").trim())) {
bundleSelectionIndex = currentIndex; bundleSelectionIndex = currentIndex;
break; break;
} }
@ -546,6 +557,7 @@ public class UploadActivity extends BaseActivity {
if (bundleSelectionIndex != -1) { if (bundleSelectionIndex != -1) {
subSpinner.setSelection(bundleSelectionIndex, true); subSpinner.setSelection(bundleSelectionIndex, true);
bundleCategory.remove(0);
} }
} }
} }
@ -627,8 +639,9 @@ public class UploadActivity extends BaseActivity {
//Sets bundle selection //Sets bundle selection
if (bundleCategory != null) { if (bundleCategory != null) {
int bundleSelectionIndex = -1, currentIndex = 0; int bundleSelectionIndex = -1, currentIndex = 0;
for (UploadCategory category : uploadRootCategories) { for (UploadCategory category : uploadRootCategories) {
if (category.getCategoryTitle().contains(bundleCategory.get(0))) { //TODO fix .contains, always false if (bundleCategory.get(0).contains(category.getCategoryTitle())) {
bundleSelectionIndex = currentIndex; bundleSelectionIndex = currentIndex;
break; break;
} }
@ -637,6 +650,7 @@ public class UploadActivity extends BaseActivity {
if (bundleSelectionIndex != -1) { if (bundleSelectionIndex != -1) {
rootCategorySpinner.setSelection(bundleSelectionIndex, true); rootCategorySpinner.setSelection(bundleSelectionIndex, true);
bundleCategory.remove(0);
} }
} }

14
app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java

@ -96,24 +96,23 @@ public class UploadFieldsBuilderActivity extends AppCompatActivity {
semesterChooserLinear = findViewById(R.id.upload_fields_builder_choose_semester); semesterChooserLinear = findViewById(R.id.upload_fields_builder_choose_semester);
semesterRadio = findViewById(R.id.upload_fields_builder_semester_radio_group); semesterRadio = findViewById(R.id.upload_fields_builder_semester_radio_group);
semesterRadio.check(Integer.parseInt(semester) % 2 == 0
? R.id.upload_fields_builder_radio_button_jun
: R.id.upload_fields_builder_radio_button_feb);
year = findViewById(R.id.upload_fields_builder_year); year = findViewById(R.id.upload_fields_builder_year);
year.addTextChangedListener(customYearWatcher); year.addTextChangedListener(customYearWatcher);
typeRadio = findViewById(R.id.upload_fields_builder_type_radio_group); typeRadio = findViewById(R.id.upload_fields_builder_type_radio_group);
typeRadio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { typeRadio.setOnCheckedChangeListener((group, checkedId) -> {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.upload_fields_builder_radio_button_notes) { if (checkedId == R.id.upload_fields_builder_radio_button_notes) {
semesterChooserLinear.setVisibility(View.GONE); semesterChooserLinear.setVisibility(View.GONE);
} else { } else {
semesterChooserLinear.setVisibility(View.VISIBLE); semesterChooserLinear.setVisibility(View.VISIBLE);
} }
}
}); });
findViewById(R.id.upload_fields_builder_submit).setOnClickListener(new View.OnClickListener() { findViewById(R.id.upload_fields_builder_submit).setOnClickListener(view -> {
@Override
public void onClick(View view) {
int typeId = typeRadio.getCheckedRadioButtonId(), int typeId = typeRadio.getCheckedRadioButtonId(),
semesterId = semesterRadio.getCheckedRadioButtonId(); semesterId = semesterRadio.getCheckedRadioButtonId();
if (typeId == -1) { if (typeId == -1) {
@ -133,7 +132,6 @@ public class UploadFieldsBuilderActivity extends AppCompatActivity {
returnIntent.putExtra(RESULT_DESCRIPTION, buildDescription()); returnIntent.putExtra(RESULT_DESCRIPTION, buildDescription());
setResult(Activity.RESULT_OK, returnIntent); setResult(Activity.RESULT_OK, returnIntent);
finish(); finish();
}
}); });
} }

Loading…
Cancel
Save