Browse Source

Uploads improvements

pull/30/merge
Apostolos Fanakis 7 years ago
parent
commit
1192151821
  1. 10
      app/src/main/AndroidManifest.xml
  2. 5
      app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java
  3. 49
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  4. 181
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java
  5. 2
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  6. 4
      app/src/main/res/layout/activity_upload.xml
  7. 176
      app/src/main/res/layout/activity_upload_fields_builder.xml
  8. 19
      app/src/main/res/values/strings.xml

10
app/src/main/AndroidManifest.xml

@ -98,7 +98,15 @@
android:value=".activities.main.MainActivity" />
</activity>
<activity
android:name=".activities.UploadActivity"
android:name=".activities.upload.UploadActivity"
android:parentActivityName=".activities.main.MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.main.MainActivity" />
</activity>
<activity
android:name=".activities.upload.UploadFieldsBuilderActivity"
android:parentActivityName=".activities.main.MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data

5
app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java

@ -8,7 +8,6 @@ import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -23,7 +22,7 @@ import java.util.ArrayList;
import java.util.Objects;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.UploadActivity;
import gr.thmmy.mthmmy.activities.upload.UploadActivity;
import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.model.Download;
@ -36,7 +35,7 @@ import okhttp3.Request;
import okhttp3.Response;
import timber.log.Timber;
import static gr.thmmy.mthmmy.activities.UploadActivity.BUNDLE_UPLOAD_CATEGORY;
import static gr.thmmy.mthmmy.activities.upload.UploadActivity.BUNDLE_UPLOAD_CATEGORY;
public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.OnLoadMoreListener {
/**

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

@ -1,5 +1,6 @@
package gr.thmmy.mthmmy.activities;
package gr.thmmy.mthmmy.activities.upload;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
@ -13,6 +14,7 @@ import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.AppCompatButton;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
@ -42,6 +44,10 @@ import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import timber.log.Timber;
import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.UPLOADING_APP_SIGNATURE_ENABLE_KEY;
import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.BUNDLE_UPLOAD_FIELD_BUILDER_COURSE;
import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.BUNDLE_UPLOAD_FIELD_BUILDER_SEMESTER;
import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.RESULT_DESCRIPTION;
import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.RESULT_TITLE;
public class UploadActivity extends BaseActivity {
/**
@ -52,6 +58,7 @@ public class UploadActivity extends BaseActivity {
private static final String uploadedFrommThmmyPromptHtml = "<br /><div style=\"text-align: right;\"><span style=\"font-style: italic;\">uploaded from <a href=\"https://play.google.com/store/apps/details?id=gr.thmmy.mthmmy\">mTHMMY</a></span>";
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<UploadCategory> 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);
}

181
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;
}
}
}

2
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;

4
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">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
@ -32,7 +32,7 @@
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="gr.thmmy.mthmmy.activities.UploadActivity">
tools:context="gr.thmmy.mthmmy.activities.upload.UploadActivity">
<LinearLayout
android:layout_width="match_parent"

176
app/src/main/res/layout/activity_upload_fields_builder.xml

@ -0,0 +1,176 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activities.upload.UploadFieldsBuilderActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/ToolbarTheme">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:gravity="center"
app:popupTheme="@style/ToolbarTheme" />
</android.support.design.widget.AppBarLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top|start"
android:background="@color/background"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity">
<LinearLayout
android:id="@+id/upload_fields_builder_content_linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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_fields_builder_type_radio_buttons_title"
android:textAlignment="center"
android:textColor="@color/accent" />
<RadioGroup
android:id="@+id/upload_fields_builder_type_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"
android:orientation="vertical">
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/upload_fields_builder_radio_button_exams"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="@string/upload_fields_builder_radio_button_exams"
android:textColor="@color/primary_text" />
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/upload_fields_builder_radio_button_exam_solutions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="@string/upload_fields_builder_radio_button_exam_solutions"
android:textColor="@color/primary_text" />
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/upload_fields_builder_radio_button_notes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="@string/upload_fields_builder_radio_button_notes"
android:textColor="@color/primary_text" />
</RadioGroup>
<LinearLayout
android:id="@+id/upload_fields_builder_choose_semester"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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_fields_builder_select_semester_title"
android:textAlignment="center"
android:textColor="@color/accent" />
<RadioGroup
android:id="@+id/upload_fields_builder_semester_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"
android:orientation="vertical">
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/upload_fields_builder_radio_button_feb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="@string/upload_fields_builder_radio_button_feb"
android:textColor="@color/primary_text" />
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/upload_fields_builder_radio_button_jun"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="@string/upload_fields_builder_radio_button_exam_jun"
android:textColor="@color/primary_text" />
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/upload_fields_builder_radio_button_sept"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="@string/upload_fields_builder_radio_button_sept"
android:textColor="@color/primary_text" />
</RadioGroup>
</LinearLayout>
<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_fields_builder_select_year_title"
android:textAlignment="center"
android:textColor="@color/accent" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp">
<EditText
android:id="@+id/upload_fields_builder_year"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="4"
android:hint="@string/upload_fields_builder_year_hint"
android:inputType="number" />
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatButton
android:id="@+id/upload_fields_builder_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="@string/upload_fields_builder_submit"
android:textColor="@color/accent" />
</LinearLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>

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

@ -116,13 +116,18 @@
<string name="upload_upload_button">Upload</string>
<string name="upload_spinners_hint">Select a category</string>
<!--Upload Dialog-->
<string name="dialog_upload_radio_buttons_title">Select type of upload</string>
<string name="dialog_upload_radio_button_exams">Exam subjects</string>
<string name="dialog_upload_radio_button_exam_solutions">Exam solutions</string>
<string name="dialog_upload_radio_button_notes">Course notes</string>
<string name="dialog_upload_select_lesson_title">Select the course</string>
<string name="dialog_upload_select_semester">Select the semester</string>
<!--Upload Fields Builder Activity-->
<string name="upload_fields_builder_type_radio_buttons_title">Select type of upload</string>
<string name="upload_fields_builder_radio_button_exams">Exam subjects</string>
<string name="upload_fields_builder_radio_button_exam_solutions">Exam solutions</string>
<string name="upload_fields_builder_radio_button_notes">Course notes</string>
<string name="upload_fields_builder_select_semester_title">Select period</string>
<string name="upload_fields_builder_radio_button_feb">February</string>
<string name="upload_fields_builder_radio_button_exam_jun">June</string>
<string name="upload_fields_builder_radio_button_sept">September</string>
<string name="upload_fields_builder_select_year_title">Select year</string>
<string name="upload_fields_builder_year_hint">Year</string>
<string name="upload_fields_builder_submit">Build</string>
<!--Settings Activity-->
<string name="action_settings">Settings</string>

Loading…
Cancel
Save