diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 86a9cdce..199386e1 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -98,7 +98,15 @@
android:value=".activities.main.MainActivity" />
+
+
+
uploaded from mTHMMY";
private static final int REQUEST_CODE_CHOOSE_FILE = 8;
private static final int REQUEST_CODE_CAMERA = 4;
+ private static final int REQUEST_CODE_FIELDS_BUILDER = 74;
private static ArrayList uploadRootCategories = new ArrayList<>();
private ParseUploadPageTask parseUploadPageTask;
@@ -120,7 +127,35 @@ public class UploadActivity extends BaseActivity {
Toast.makeText(view.getContext(), "Please choose category first", Toast.LENGTH_SHORT).show();
return;
}
- //TODO else
+
+ int numberOfSpinners = categoriesSpinners.getChildCount();
+
+ if (numberOfSpinners < 3) {
+ Toast.makeText(view.getContext(), "Please choose a course category", Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ String maybeSemester = (String) ((AppCompatSpinnerWithoutDefault)
+ categoriesSpinners.getChildAt(numberOfSpinners - 2)).getSelectedItem(),
+ maybeCourse = (String) ((AppCompatSpinnerWithoutDefault)
+ categoriesSpinners.getChildAt(numberOfSpinners - 1)).getSelectedItem();
+
+ if (!maybeSemester.contains("εξάμηνο") && !maybeSemester.contains("Εξάμηνο")) {
+ Toast.makeText(view.getContext(), "Please choose a course category", Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ //Fixes course and semester
+ maybeCourse = maybeCourse.replaceAll("-", "").replace("(ΝΠΣ)", "").trim();
+ maybeSemester = maybeSemester.replaceAll("-", "").trim().
+ substring(0, 1);
+
+ Intent intent = new Intent(UploadActivity.this, UploadFieldsBuilderActivity.class);
+ Bundle extras = new Bundle();
+ extras.putString(BUNDLE_UPLOAD_FIELD_BUILDER_COURSE, maybeCourse);
+ extras.putString(BUNDLE_UPLOAD_FIELD_BUILDER_SEMESTER, maybeSemester);
+ intent.putExtras(extras);
+ startActivityForResult(intent, REQUEST_CODE_FIELDS_BUILDER);
}
});
titleDescriptionBuilderButton.setEnabled(false);
@@ -291,7 +326,17 @@ public class UploadActivity extends BaseActivity {
}
}
} else if (requestCode == REQUEST_CODE_CAMERA && data != null) {
+ if (resultCode == Activity.RESULT_CANCELED) {
+ return;
+ }
//TODO
+ } else if (requestCode == REQUEST_CODE_FIELDS_BUILDER) {
+ if (resultCode == Activity.RESULT_CANCELED) {
+ return;
+ }
+ //TODO rename file
+ uploadTitle.setText(data.getStringExtra(RESULT_TITLE));
+ uploadDescription.setText(data.getStringExtra(RESULT_DESCRIPTION));
} else {
super.onActivityResult(requestCode, resultCode, data);
}
diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java
new file mode 100644
index 00000000..af9b2ec6
--- /dev/null
+++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java
@@ -0,0 +1,181 @@
+package gr.thmmy.mthmmy.activities.upload;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.RadioGroup;
+import android.widget.Toast;
+
+import gr.thmmy.mthmmy.R;
+import gr.thmmy.mthmmy.base.BaseActivity;
+import timber.log.Timber;
+
+public class UploadFieldsBuilderActivity extends BaseActivity {
+ static final String BUNDLE_UPLOAD_FIELD_BUILDER_COURSE = "UPLOAD_FIELD_BUILDER_COURSE";
+ static final String BUNDLE_UPLOAD_FIELD_BUILDER_SEMESTER = "UPLOAD_FIELD_BUILDER_SEMESTER";
+
+ static final String RESULT_FILENAME = "RESULT_FILENAME";
+ static final String RESULT_TITLE = "RESULT_TITLE";
+ static final String RESULT_DESCRIPTION = "RESULT_DESCRIPTION";
+
+ private String course, semester;
+
+ //UI elements
+ private LinearLayout semesterChooserLinear;
+ private RadioGroup typeRadio, semesterRadio;
+ private EditText year;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_upload_fields_builder);
+
+ Bundle extras = getIntent().getExtras();
+ if (extras != null) {
+ course = extras.getString(BUNDLE_UPLOAD_FIELD_BUILDER_COURSE);
+ semester = extras.getString(BUNDLE_UPLOAD_FIELD_BUILDER_SEMESTER);
+ if (course == null || course.equals("") || semester == null || semester.equals("")) {
+ Toast.makeText(this, "Something went wrong!", Toast.LENGTH_SHORT).show();
+ Timber.e("Bundle came empty in %s", UploadFieldsBuilderActivity.class.getSimpleName());
+
+ Intent returnIntent = new Intent();
+ setResult(Activity.RESULT_CANCELED, returnIntent);
+ finish();
+ }
+ }
+
+ //Initialize toolbar
+ toolbar = findViewById(R.id.toolbar);
+ toolbar.setTitle("Upload fields builder");
+ setSupportActionBar(toolbar);
+ if (getSupportActionBar() != null) {
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ getSupportActionBar().setDisplayShowHomeEnabled(true);
+ }
+
+ createDrawer();
+ drawer.setSelection(UPLOAD_ID);
+
+ semesterChooserLinear = findViewById(R.id.upload_fields_builder_choose_semester);
+ semesterRadio = findViewById(R.id.upload_fields_builder_semester_radio_group);
+ year = findViewById(R.id.upload_fields_builder_year);
+
+ typeRadio = findViewById(R.id.upload_fields_builder_type_radio_group);
+ typeRadio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(RadioGroup group, int checkedId) {
+ if (checkedId == R.id.upload_fields_builder_radio_button_notes) {
+ semesterChooserLinear.setVisibility(View.GONE);
+ } else {
+ semesterChooserLinear.setVisibility(View.VISIBLE);
+ }
+ }
+ });
+
+ findViewById(R.id.upload_fields_builder_submit).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ int typeId = typeRadio.getCheckedRadioButtonId(),
+ semesterId = semesterRadio.getCheckedRadioButtonId();
+ if (typeId == -1) {
+ Toast.makeText(view.getContext(), "Please choose a type for the upload", Toast.LENGTH_SHORT).show();
+ return;
+ } else if (semesterChooserLinear.getVisibility() == View.VISIBLE && semesterId == -1) {
+ Toast.makeText(view.getContext(), "Please choose a semester for the upload", Toast.LENGTH_SHORT).show();
+ return;
+ } else if (year.getText().toString().isEmpty()) {
+ Toast.makeText(view.getContext(), "Please choose a year for the upload", Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra(RESULT_FILENAME, buildFilename());
+ returnIntent.putExtra(RESULT_TITLE, buildTitle());
+ returnIntent.putExtra(RESULT_DESCRIPTION, buildDescription());
+ setResult(Activity.RESULT_OK, returnIntent);
+ finish();
+ }
+ });
+ }
+
+ @Nullable
+ private String buildFilename() {
+ switch (typeRadio.getCheckedRadioButtonId()) {
+ case R.id.upload_fields_builder_radio_button_exams:
+ return getGreeklishCourseName() + "_" + getGreeklishPeriod() + "_" + year.getText().toString();
+ case R.id.upload_fields_builder_radio_button_exam_solutions:
+ return getGreeklishCourseName() + "_" + getGreeklishPeriod() + "_" + year.getText().toString() + "_Lyseis";
+ case R.id.upload_fields_builder_radio_button_notes:
+ return getGreeklishCourseName() + "_" + year.getText().toString() + "_Shmeiwseis";
+ default:
+ return null;
+ }
+ }
+
+ @Nullable
+ private String buildTitle() {
+ switch (typeRadio.getCheckedRadioButtonId()) {
+ case R.id.upload_fields_builder_radio_button_exams:
+ return getMinifiedCourseName() + " - " + "Θέματα εξετάσεων " + getPeriod() + " " + year.getText().toString();
+ case R.id.upload_fields_builder_radio_button_exam_solutions:
+ return getMinifiedCourseName() + " - " + "Λύσεις θεμάτων " + getPeriod() + " " + year.getText().toString();
+ case R.id.upload_fields_builder_radio_button_notes:
+ return getMinifiedCourseName() + " - " + "Σημειώσεις παραδόσεων " + year.getText().toString();
+ default:
+ return null;
+ }
+ }
+
+ private String buildDescription() {
+ switch (typeRadio.getCheckedRadioButtonId()) {
+ case R.id.upload_fields_builder_radio_button_exams:
+ return "Θέματα εξετάσεων " + getPeriod() + " " + year.getText().toString() + " του μαθήματος \"" + course + "\"";
+ case R.id.upload_fields_builder_radio_button_exam_solutions:
+ return "Λύσεις των θεμάτων των εξετάσεων " + getPeriod() + " " + year.getText().toString() + " του μαθήματος \"" + course + "\"";
+ case R.id.upload_fields_builder_radio_button_notes:
+ return "Σημειώσεις των παραδόσεων του μαθήματος \"" + course + "\" από το " + year.getText().toString();
+ default:
+ return null;
+ }
+ }
+
+ private String getGreeklishCourseName() {
+ //TODO
+ return "";
+ }
+
+ private String getGreeklishPeriod() {
+ switch (semesterRadio.getCheckedRadioButtonId()) {
+ case R.id.upload_fields_builder_radio_button_feb:
+ return "FEB";
+ case R.id.upload_fields_builder_radio_button_jun:
+ return "IOY";
+ case R.id.upload_fields_builder_radio_button_sept:
+ return "SEP";
+ default:
+ return null;
+ }
+ }
+
+ private String getMinifiedCourseName() {
+ //TODO
+ return "";
+ }
+
+ private String getPeriod() {
+ switch (semesterRadio.getCheckedRadioButtonId()) {
+ case R.id.upload_fields_builder_radio_button_feb:
+ return "Φεβρουαρίου";
+ case R.id.upload_fields_builder_radio_button_jun:
+ return "Ιουνίου";
+ case R.id.upload_fields_builder_radio_button_sept:
+ return "Σεπτεμβρίου";
+ default:
+ return null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
index faad57b6..e0c70e1f 100644
--- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
+++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
@@ -44,7 +44,7 @@ import java.util.ArrayList;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.AboutActivity;
import gr.thmmy.mthmmy.activities.LoginActivity;
-import gr.thmmy.mthmmy.activities.UploadActivity;
+import gr.thmmy.mthmmy.activities.upload.UploadActivity;
import gr.thmmy.mthmmy.activities.bookmarks.BookmarkActivity;
import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity;
import gr.thmmy.mthmmy.activities.main.MainActivity;
diff --git a/app/src/main/res/layout/activity_upload.xml b/app/src/main/res/layout/activity_upload.xml
index 43e17fad..f32db5c5 100644
--- a/app/src/main/res/layout/activity_upload.xml
+++ b/app/src/main/res/layout/activity_upload.xml
@@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
- tools:context=".activities.UploadActivity">
+ tools:context=".activities.upload.UploadActivity">
+ tools:context="gr.thmmy.mthmmy.activities.upload.UploadActivity">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 149526ec..309f24ce 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -116,13 +116,18 @@
Upload
Select a category
-
- Select type of upload
- Exam subjects
- Exam solutions
- Course notes
- Select the course
- Select the semester
+
+ Select type of upload
+ Exam subjects
+ Exam solutions
+ Course notes
+ Select period
+ February
+ June
+ September
+ Select year
+ Year
+ Build
Settings