Browse Source

Merge remote-tracking branch 'origin/viewmodel' into viewmodel

# Conflicts:
#	app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
pull/34/head
Thodoris1999 7 years ago
parent
commit
3e2f90a25f
  1. 10
      app/src/main/AndroidManifest.xml
  2. 3
      app/src/main/assets/apache_libraries.html
  3. 333
      app/src/main/java/gr/thmmy/mthmmy/activities/UploadActivity.java
  4. 16
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java
  5. 14
      app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java
  6. 8
      app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsAdapter.java
  7. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  8. 8
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java
  9. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java
  10. 15
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java
  11. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  12. 16
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  13. 643
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  14. 481
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java
  15. 53
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  16. BIN
      app/src/main/res/drawable-hdpi/ic_arrow_drop_down.png
  17. BIN
      app/src/main/res/drawable-hdpi/ic_arrow_drop_up.png
  18. BIN
      app/src/main/res/drawable-hdpi/ic_bookmark_false.png
  19. BIN
      app/src/main/res/drawable-hdpi/ic_bookmark_true.png
  20. BIN
      app/src/main/res/drawable-hdpi/ic_delete_accent.png
  21. BIN
      app/src/main/res/drawable-hdpi/ic_delete_white.png
  22. BIN
      app/src/main/res/drawable-hdpi/ic_file_upload.png
  23. BIN
      app/src/main/res/drawable-hdpi/ic_format_quote_checked.png
  24. BIN
      app/src/main/res/drawable-hdpi/ic_format_quote_unchecked.png
  25. BIN
      app/src/main/res/drawable-hdpi/ic_info.png
  26. BIN
      app/src/main/res/drawable-hdpi/ic_insert_drive_file.png
  27. BIN
      app/src/main/res/drawable-hdpi/ic_more_vert.png
  28. BIN
      app/src/main/res/drawable-hdpi/ic_send.png
  29. BIN
      app/src/main/res/drawable-hdpi/ic_share.png
  30. BIN
      app/src/main/res/drawable-mdpi/ic_arrow_drop_down.png
  31. BIN
      app/src/main/res/drawable-mdpi/ic_arrow_drop_up.png
  32. BIN
      app/src/main/res/drawable-mdpi/ic_bookmark_false.png
  33. BIN
      app/src/main/res/drawable-mdpi/ic_bookmark_true.png
  34. BIN
      app/src/main/res/drawable-mdpi/ic_delete_accent.png
  35. BIN
      app/src/main/res/drawable-mdpi/ic_delete_white.png
  36. BIN
      app/src/main/res/drawable-mdpi/ic_file_upload.png
  37. BIN
      app/src/main/res/drawable-mdpi/ic_format_quote_checked.png
  38. BIN
      app/src/main/res/drawable-mdpi/ic_format_quote_unchecked.png
  39. BIN
      app/src/main/res/drawable-mdpi/ic_info.png
  40. BIN
      app/src/main/res/drawable-mdpi/ic_insert_drive_file.png
  41. BIN
      app/src/main/res/drawable-mdpi/ic_more_vert.png
  42. BIN
      app/src/main/res/drawable-mdpi/ic_send.png
  43. BIN
      app/src/main/res/drawable-mdpi/ic_share.png
  44. BIN
      app/src/main/res/drawable-xhdpi/ic_arrow_drop_down.png
  45. BIN
      app/src/main/res/drawable-xhdpi/ic_arrow_drop_up.png
  46. BIN
      app/src/main/res/drawable-xhdpi/ic_bookmark_false.png
  47. BIN
      app/src/main/res/drawable-xhdpi/ic_bookmark_true.png
  48. BIN
      app/src/main/res/drawable-xhdpi/ic_delete_accent.png
  49. BIN
      app/src/main/res/drawable-xhdpi/ic_delete_white.png
  50. BIN
      app/src/main/res/drawable-xhdpi/ic_file_upload.png
  51. BIN
      app/src/main/res/drawable-xhdpi/ic_format_quote_checked.png
  52. BIN
      app/src/main/res/drawable-xhdpi/ic_format_quote_unchecked.png
  53. BIN
      app/src/main/res/drawable-xhdpi/ic_info.png
  54. BIN
      app/src/main/res/drawable-xhdpi/ic_insert_drive_file.png
  55. BIN
      app/src/main/res/drawable-xhdpi/ic_more_vert.png
  56. BIN
      app/src/main/res/drawable-xhdpi/ic_send.png
  57. BIN
      app/src/main/res/drawable-xhdpi/ic_share.png
  58. BIN
      app/src/main/res/drawable-xxhdpi/ic_arrow_drop_down.png
  59. BIN
      app/src/main/res/drawable-xxhdpi/ic_arrow_drop_up.png
  60. BIN
      app/src/main/res/drawable-xxhdpi/ic_bookmark_false.png
  61. BIN
      app/src/main/res/drawable-xxhdpi/ic_bookmark_true.png
  62. BIN
      app/src/main/res/drawable-xxhdpi/ic_delete_accent.png
  63. BIN
      app/src/main/res/drawable-xxhdpi/ic_delete_white.png
  64. BIN
      app/src/main/res/drawable-xxhdpi/ic_file_upload.png
  65. BIN
      app/src/main/res/drawable-xxhdpi/ic_format_quote_checked.png
  66. BIN
      app/src/main/res/drawable-xxhdpi/ic_format_quote_unchecked.png
  67. BIN
      app/src/main/res/drawable-xxhdpi/ic_info.png
  68. BIN
      app/src/main/res/drawable-xxhdpi/ic_insert_drive_file.png
  69. BIN
      app/src/main/res/drawable-xxhdpi/ic_more_vert.png
  70. BIN
      app/src/main/res/drawable-xxhdpi/ic_send.png
  71. BIN
      app/src/main/res/drawable-xxhdpi/ic_share.png
  72. BIN
      app/src/main/res/drawable-xxxhdpi/ic_arrow_drop_down.png
  73. BIN
      app/src/main/res/drawable-xxxhdpi/ic_arrow_drop_up.png
  74. BIN
      app/src/main/res/drawable-xxxhdpi/ic_bookmark_false.png
  75. BIN
      app/src/main/res/drawable-xxxhdpi/ic_bookmark_true.png
  76. BIN
      app/src/main/res/drawable-xxxhdpi/ic_delete_accent.png
  77. BIN
      app/src/main/res/drawable-xxxhdpi/ic_delete_white.png
  78. BIN
      app/src/main/res/drawable-xxxhdpi/ic_file_upload.png
  79. BIN
      app/src/main/res/drawable-xxxhdpi/ic_format_quote_checked.png
  80. BIN
      app/src/main/res/drawable-xxxhdpi/ic_format_quote_unchecked.png
  81. BIN
      app/src/main/res/drawable-xxxhdpi/ic_info.png
  82. BIN
      app/src/main/res/drawable-xxxhdpi/ic_insert_drive_file.png
  83. BIN
      app/src/main/res/drawable-xxxhdpi/ic_more_vert.png
  84. BIN
      app/src/main/res/drawable-xxxhdpi/ic_send.png
  85. BIN
      app/src/main/res/drawable-xxxhdpi/ic_share.png
  86. 5
      app/src/main/res/drawable/ic_arrow_drop_down_accent_24dp.xml
  87. 5
      app/src/main/res/drawable/ic_arrow_drop_up_accent_24dp.xml
  88. 5
      app/src/main/res/drawable/ic_bookmark_false_accent_24dp.xml
  89. 5
      app/src/main/res/drawable/ic_bookmark_true_accent_24dp.xml
  90. BIN
      app/src/main/res/drawable/ic_default_user_thumbnail.png
  91. 5
      app/src/main/res/drawable/ic_default_user_thumbnail_white_24dp.xml
  92. 5
      app/src/main/res/drawable/ic_delete_accent_24dp.xml
  93. 5
      app/src/main/res/drawable/ic_delete_white_24dp.xml
  94. 11
      app/src/main/res/drawable/ic_file_upload.xml
  95. 5
      app/src/main/res/drawable/ic_file_upload_white_24dp.xml
  96. 5
      app/src/main/res/drawable/ic_format_quote_checked_accent_24dp.xml
  97. 5
      app/src/main/res/drawable/ic_format_quote_unchecked_grey_24dp.xml
  98. 5
      app/src/main/res/drawable/ic_info_outline_white_24dp.xml
  99. 5
      app/src/main/res/drawable/ic_insert_drive_file_white_24dp.xml
  100. 5
      app/src/main/res/drawable/ic_more_vert_white_24dp.xml

10
app/src/main/AndroidManifest.xml

@ -98,13 +98,21 @@
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.upload.UploadActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.main.MainActivity" />
</activity>
<activity
android:name=".activities.bookmarks.BookmarkActivity"
android:parentActivityName=".activities.main.MainActivity"

3
app/src/main/assets/apache_libraries.html

@ -62,6 +62,9 @@
<li>
<h5><a href="https://github.com/JakeWharton/timber">Timber</a>&nbsp;v4.7.0 (Copyright ©2013 Jake Wharton)</h5>
</li>
<li>
<h5><a href="https://github.com/gotev/android-upload-service">Android Upload Service</a>&nbsp;v3.4.2 (Copyright ©2013-2018 Aleksandar Gotev)</h5>
</li>
</ul>

333
app/src/main/java/gr/thmmy/mthmmy/activities/UploadActivity.java

@ -1,333 +0,0 @@
package gr.thmmy.mthmmy.activities;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.widget.AppCompatSpinner;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Spinner;
import net.gotev.uploadservice.MultipartUploadRequest;
import net.gotev.uploadservice.UploadNotificationConfig;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.net.URLEncoder;
import java.util.ArrayList;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.model.UploadCategory;
import gr.thmmy.mthmmy.utils.AppCompatSpinnerWithoutDefault;
import gr.thmmy.mthmmy.utils.parsing.ParseException;
import gr.thmmy.mthmmy.utils.parsing.ParseTask;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import timber.log.Timber;
public class UploadActivity extends BaseActivity {
/**
* The key to use when putting upload's category String to {@link UploadActivity}'s Bundle.
*/
public static final String BUNDLE_UPLOAD_CATEGORY = "UPLOAD_CATEGORY";
private static final String uploadIndexUrl = "https://www.thmmy.gr/smf/index.php?action=tpmod;dl=upload";
private static final int REQUEST_CODE_CHOOSE_FILE = 8;
private static ArrayList<UploadCategory> uploadRootCategories = new ArrayList<>();
//private String currentUploadCategory = "";
private ParseUploadPageTask parseUploadPageTask;
private String categorySelected = "-1";
private String uploaderProfileIndex = "1";
private Uri fileUri;
//UI elements
private MaterialProgressBar progressBar;
private LinearLayout categoriesSpinners;
private AppCompatSpinnerWithoutDefault rootCategorySpinner;
private EditText uploadTitle;
private EditText uploadDescription;
//private static AppCompatButton titleDescriptionBuilderButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload);
/*Bundle extras = getIntent().getExtras();
if (extras != null) {
//TODO auto fill category from bundle
currentUploadCategory = extras.getString(BUNDLE_UPLOAD_CATEGORY);
if (currentUploadCategory != null && !Objects.equals(currentUploadCategory, "")) {
}
}*/
//Initialize toolbar
toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("Upload");
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
createDrawer();
drawer.setSelection(UPLOAD_ID);
progressBar = findViewById(R.id.progressBar);
findViewById(R.id.upload_outer_scrollview).setVerticalScrollBarEnabled(false);
categoriesSpinners = findViewById(R.id.upload_spinners);
rootCategorySpinner = findViewById(R.id.upload_spinner_category_root);
rootCategorySpinner.setOnItemSelectedListener(new CustomOnItemSelectedListener(uploadRootCategories));
/*titleDescriptionBuilderButton = findViewById(R.id.upload_title_description_builder);
titleDescriptionBuilderButton.setEnabled(false);
titleDescriptionBuilderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO some dialog?
}
});*/
uploadTitle = findViewById(R.id.upload_title);
uploadDescription = findViewById(R.id.upload_description);
findViewById(R.id.upload_select_file_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
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);
startActivityForResult(intent, REQUEST_CODE_CHOOSE_FILE);
}
});
findViewById(R.id.upload_upload_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String uploadTitleText = uploadTitle.getText().toString();
String uploadDescriptionText = uploadDescription.getText().toString();
if (uploadTitleText.equals("")) {
uploadTitle.setError("Required");
}
if (uploadDescriptionText.equals("")) {
uploadDescription.setError("Required");
}
/*if (categorySelected.equals("-1")){
//TODO set error
//rootCategorySpinner
}*/
if (categorySelected.equals("-1") || uploadTitleText.equals("") ||
fileUri == null || uploadDescriptionText.equals("")) {
return;
}
try {
String uploadId = new MultipartUploadRequest(v.getContext(), uploadIndexUrl)
.setUtf8Charset()
.addParameter("tp-dluploadtitle", uploadTitleText)
.addParameter("tp-dluploadcat", categorySelected)
.addParameter("tp-dluploadtext", uploadDescriptionText)
.addFileToUpload(fileUri.toString(), "tp-dluploadfile")
.addParameter("tp_dluploadicon", "blank.gif") //TODO auto-select this
.addParameter("tp-uploaduser", uploaderProfileIndex)
.setNotificationConfig(new UploadNotificationConfig())
.setMaxRetries(2).startUpload();
} catch (Exception exception) {
Timber.e(exception, "AndroidUploadService: %s", exception.getMessage());
}
}
});
if (uploadRootCategories.isEmpty()) {
parseUploadPageTask = new ParseUploadPageTask();
parseUploadPageTask.execute(uploadIndexUrl);
} else {
String[] tmpSpinnerArray = new String[uploadRootCategories.size()];
for (int i = 0; i < uploadRootCategories.size(); ++i) {
tmpSpinnerArray[i] = uploadRootCategories.get(i).getCategoryTitle();
}
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);
rootCategorySpinner.setAdapter(spinnerArrayAdapter);
}
}
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen()) {
drawer.closeDrawer();
return;
}
super.onBackPressed();
}
@Override
protected void onResume() {
drawer.setSelection(UPLOAD_ID);
super.onResume();
}
@Override
protected void onDestroy() {
super.onDestroy();
if (parseUploadPageTask != null && parseUploadPageTask.getStatus() != AsyncTask.Status.RUNNING)
parseUploadPageTask.cancel(true);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_CHOOSE_FILE && data != null) {
//TODO upload the correct file
//Check this https://stackoverflow.com/questions/5568874/how-to-extract-the-file-name-from-uri-returned-from-intent-action-get-content/25005243
fileUri = data.getData();
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
private class CustomOnItemSelectedListener implements AdapterView.OnItemSelectedListener {
private ArrayList<UploadCategory> parentCategories, childCategories;
private CustomOnItemSelectedListener() {
//Disable default constructor
}
CustomOnItemSelectedListener(ArrayList<UploadCategory> parentCategories) {
this.parentCategories = parentCategories;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//Removes old, unneeded sub categories spinner(s)
int viewIndex = categoriesSpinners.indexOfChild((AppCompatSpinnerWithoutDefault) view.getParent());
if (viewIndex + 1 != categoriesSpinners.getChildCount()) { //Makes sure this is not the last child
categoriesSpinners.removeViews(viewIndex + 1, categoriesSpinners.getChildCount() - viewIndex - 1);
}
categorySelected = parentCategories.get(position).getValue();
//Adds new sub categories spinner
if (parentCategories.get(position).hasSubCategories()) {
childCategories = parentCategories.get(position).getSubCategories();
String[] tmpSpinnerArray = new String[childCategories.size()];
for (int i = 0; i < tmpSpinnerArray.length; ++i) {
tmpSpinnerArray[i] = childCategories.get(i).getCategoryTitle();
}
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(getApplicationContext(),
android.R.layout.simple_spinner_dropdown_item, tmpSpinnerArray);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
AppCompatSpinnerWithoutDefault subSpinner = new AppCompatSpinnerWithoutDefault(categoriesSpinners.getContext());
subSpinner.setPromptId(R.string.upload_spinners_prompt);
subSpinner.setPopupBackgroundResource(R.color.primary);
subSpinner.setAdapter(spinnerArrayAdapter);
subSpinner.setOnItemSelectedListener(new CustomOnItemSelectedListener(childCategories));
categoriesSpinners.addView(subSpinner);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
/**
* An {@link ParseTask} that handles asynchronous fetching of the upload page and parsing the
* upload categories.
*/
private class ParseUploadPageTask extends ParseTask {
@Override
protected void onPreExecute() {
progressBar.setVisibility(ProgressBar.VISIBLE);
}
@Override
protected void parse(Document uploadPage) throws ParseException {
Elements categoriesElements;
Element uploaderProfileIndexElement;
try {
categoriesElements = uploadPage.select("select[name='tp-dluploadcat']>option");
uploaderProfileIndexElement = uploadPage.select("input[name=\"tp-uploaduser\"]").first();
} catch (Exception e) {
throw new ParseException("Parsing failed (UploadActivity)");
}
uploaderProfileIndex = uploaderProfileIndexElement.attr("value");
for (Element category : categoriesElements) {
String categoryValue = category.attr("value");
String categoryText = category.text();
if (categoryText.startsWith("- ")) {
//This is a level one subcategory
uploadRootCategories.get(uploadRootCategories.size() - 1).addSubCategory(categoryValue, categoryText);
} else if (categoryText.startsWith("-- ")) {
//This is a level two subcategory
UploadCategory rootLevelCategory = uploadRootCategories.get(uploadRootCategories.size() - 1);
UploadCategory firstLevelCategory = rootLevelCategory.getSubCategories().get(rootLevelCategory.getSubCategories().size() - 1);
firstLevelCategory.addSubCategory(categoryValue, categoryText);
} else if (categoryText.startsWith("--- ")) {
//This is a level three subcategory
UploadCategory rootLevelCategory = uploadRootCategories.get(uploadRootCategories.size() - 1);
UploadCategory firstLevelCategory = rootLevelCategory.getSubCategories().get(rootLevelCategory.getSubCategories().size() - 1);
UploadCategory secondLevelCategory = firstLevelCategory.getSubCategories().get(firstLevelCategory.getSubCategories().size() - 1);
secondLevelCategory.addSubCategory(categoryValue, categoryText);
} else if (categoryText.startsWith("---- ")) {
//This is a level three subcategory
UploadCategory rootLevelCategory = uploadRootCategories.get(uploadRootCategories.size() - 1);
UploadCategory firstLevelCategory = rootLevelCategory.getSubCategories().get(rootLevelCategory.getSubCategories().size() - 1);
UploadCategory secondLevelCategory = firstLevelCategory.getSubCategories().get(firstLevelCategory.getSubCategories().size() - 1);
UploadCategory thirdLevelCategory = secondLevelCategory.getSubCategories().get(secondLevelCategory.getSubCategories().size() - 1);
thirdLevelCategory.addSubCategory(categoryValue, categoryText);
} else {
//This is a root category
uploadRootCategories.add(new UploadCategory(categoryValue, categoryText));
}
}
}
@Override
protected void postExecution(ResultCode result) {
String[] tmpSpinnerArray = new String[uploadRootCategories.size()];
for (int i = 0; i < uploadRootCategories.size(); ++i) {
tmpSpinnerArray[i] = uploadRootCategories.get(i).getCategoryTitle();
}
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);
rootCategorySpinner.setAdapter(spinnerArrayAdapter);
//titleDescriptionBuilderButton.setEnabled(true);
progressBar.setVisibility(ProgressBar.GONE);
}
}
}

16
app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java

@ -147,10 +147,10 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
});
if (boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition() - 1)) {
subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE);
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up);
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
} else {
subBoardViewHolder.boardExpandable.setVisibility(View.GONE);
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down);
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
}
subBoardViewHolder.showHideExpandable.setOnClickListener(new View.OnClickListener() {
@Override
@ -158,10 +158,10 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
final boolean visible = boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition() - 1);
if (visible) {
subBoardViewHolder.boardExpandable.setVisibility(View.GONE);
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down);
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
} else {
subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE);
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up);
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
}
boardExpandableVisibility.set(subBoardViewHolder.getAdapterPosition() - 1, !visible);
}
@ -208,10 +208,10 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
if (topicExpandableVisibility.get(topicViewHolder.getAdapterPosition() - parsedSubBoards
.size() - 2)) {
topicViewHolder.topicExpandable.setVisibility(View.VISIBLE);
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up);
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
} else {
topicViewHolder.topicExpandable.setVisibility(View.GONE);
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down);
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
}
topicViewHolder.showHideExpandable.setOnClickListener(new View.OnClickListener() {
@Override
@ -220,10 +220,10 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
getAdapterPosition() - parsedSubBoards.size() - 2);
if (visible) {
topicViewHolder.topicExpandable.setVisibility(View.GONE);
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down);
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
} else {
topicViewHolder.topicExpandable.setVisibility(View.VISIBLE);
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up);
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
}
topicExpandableVisibility.set(topicViewHolder.getAdapterPosition() -
parsedSubBoards.size() - 2, !visible);

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

@ -22,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;
@ -35,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 {
/**
@ -48,6 +48,7 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.
public static final String BUNDLE_DOWNLOADS_TITLE = "DOWNLOADS_TITLE";
private static final String downloadsIndexUrl = "https://www.thmmy.gr/smf/index.php?action=tpmod;dl;";
private String downloadsUrl;
private String downloadsNav;
private String downloadsTitle;
private final ArrayList<Download> parsedDownloads = new ArrayList<>();
@ -143,8 +144,8 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.
case R.id.menu_upload:
Intent intent = new Intent(DownloadsActivity.this, UploadActivity.class);
Bundle extras = new Bundle();
/*extras.putString(BUNDLE_UPLOAD_CATEGORY, "");
intent.putExtras(extras);*/
extras.putString(BUNDLE_UPLOAD_CATEGORY, downloadsNav);
intent.putExtras(extras);
startActivity(intent);
return true;
default:
@ -211,8 +212,11 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.
@Override
protected void parse(Document downloadPage) throws ParseException {
try {
Element downloadsNavElement = downloadPage.select("div.nav").first();
downloadsNav = downloadsNavElement.text();
if (downloadsTitle == null || Objects.equals(downloadsTitle, ""))
downloadsTitle = downloadPage.select("div.nav>b>a.nav").last().text();
downloadsTitle = downloadsNavElement.select("b>a.nav").last().text();
//Removes loading item
if (isLoadingMore) {

8
app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsAdapter.java

@ -91,10 +91,10 @@ class DownloadsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
if (downloadExpandableVisibility.get(downloadViewHolder.getAdapterPosition())) {
downloadViewHolder.informationExpandable.setVisibility(View.VISIBLE);
downloadViewHolder.informationExpandableBtn.setImageResource(R.drawable.ic_arrow_drop_up);
downloadViewHolder.informationExpandableBtn.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
} else {
downloadViewHolder.informationExpandable.setVisibility(View.GONE);
downloadViewHolder.informationExpandableBtn.setImageResource(R.drawable.ic_arrow_drop_down);
downloadViewHolder.informationExpandableBtn.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
}
downloadViewHolder.informationExpandableBtn.setOnClickListener(new View.OnClickListener() {
@Override
@ -103,10 +103,10 @@ class DownloadsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
getAdapterPosition());
if (visible) {
downloadViewHolder.informationExpandable.setVisibility(View.GONE);
downloadViewHolder.informationExpandableBtn.setImageResource(R.drawable.ic_arrow_drop_down);
downloadViewHolder.informationExpandableBtn.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
} else {
downloadViewHolder.informationExpandable.setVisibility(View.VISIBLE);
downloadViewHolder.informationExpandableBtn.setImageResource(R.drawable.ic_arrow_drop_up);
downloadViewHolder.informationExpandableBtn.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
}
downloadExpandableVisibility.set(downloadViewHolder.getAdapterPosition(), !visible);
}

6
app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java

@ -84,7 +84,11 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
tabLayout.setupWithViewPager(viewPager);
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
tabLayout.getTabAt(Integer.parseInt(sharedPrefs.getString(DEFAULT_HOME_TAB, "0"))).select();
int preferredTab = Integer.parseInt(sharedPrefs.getString(DEFAULT_HOME_TAB, "0"));
if (preferredTab != 3 || sessionManager.isLoggedIn()) {
tabLayout.getTabAt(preferredTab).select();
}
setMainActivity(this);
}

8
app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java

@ -124,9 +124,9 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
.resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE)
.centerCrop()
.error(ResourcesCompat.getDrawable(this.getResources()
, R.drawable.ic_default_user_thumbnail, null))
, R.drawable.ic_default_user_thumbnail_white_24dp, null))
.placeholder(ResourcesCompat.getDrawable(this.getResources()
, R.drawable.ic_default_user_thumbnail, null))
, R.drawable.ic_default_user_thumbnail_white_24dp, null))
.transform(new CircleTransform())
.into(thumbnailView);
usernameView = findViewById(R.id.profile_activity_username);
@ -310,9 +310,9 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
.resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE)
.centerCrop()
.error(ResourcesCompat.getDrawable(getResources()
, R.drawable.ic_default_user_thumbnail, null))
, R.drawable.ic_default_user_thumbnail_white_24dp, null))
.placeholder(ResourcesCompat.getDrawable(getResources()
, R.drawable.ic_default_user_thumbnail, null))
, R.drawable.ic_default_user_thumbnail_white_24dp, null))
.transform(new CircleTransform())
.into(thumbnailView);
if (personalText != null) {

9
app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java

@ -11,9 +11,10 @@ public class SettingsActivity extends BaseActivity {
public static final String DEFAULT_HOME_TAB = "pref_app_main_default_tab_key";
public static final String NOTIFICATION_LED_KEY = "pref_notification_led_enable_key";
public static final String NOTIFICATION_VIBRATION_KEY = "pref_notification_vibration_enable_key";
public static final String APP_SIGNATURE_ENABLE_KEY = "pref_posting_app_signature_enable_key";
public static final String POSTING_APP_SIGNATURE_ENABLE_KEY = "pref_posting_app_signature_enable_key";
public static final String UPLOADING_APP_SIGNATURE_ENABLE_KEY = "pref_uploading_app_signature_enable_key";
private Fragment preferenceFragment;
private SettingsFragment preferenceFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -42,6 +43,8 @@ public class SettingsActivity extends BaseActivity {
protected void onResume() {
drawer.setSelection(SETTINGS_ID);
super.onResume();
((SettingsFragment) preferenceFragment).updateUserLoginState(sessionManager.isLoggedIn());
if (preferenceFragment != null) {
preferenceFragment.updateUserLoginState(sessionManager.isLoggedIn());
}
}
}

15
app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java

@ -22,10 +22,12 @@ public class SettingsFragment extends PreferenceFragmentCompat {
public static final String ARG_IS_LOGGED_IN = "selectedRingtoneKey";
//Preferences xml keys
private static final String POSTING_CATEGORY = "pref_category_posting_key";
private static final String DEFAULT_HOME_TAB = "pref_app_main_default_tab_key";
private static final String POSTING_APP_SIGNATURE_ENABLE = "pref_posting_app_signature_enable_key";
private static final String SELECTED_NOTIFICATIONS_SOUND = "pref_notifications_select_sound_key";
private static final String POSTING_CATEGORY = "pref_category_posting_key";
private static final String POSTING_APP_SIGNATURE_ENABLE = "pref_posting_app_signature_enable_key";
private static final String UPLOADING_CATEGORY = "pref_category_uploading_key";
private static final String UPLOADING_APP_SIGNATURE_ENABLE = "pref_uploading_app_signature_enable_key";
//SharedPreferences keys
private static final int REQUEST_CODE_ALERT_RINGTONE = 2;
@ -79,6 +81,9 @@ public class SettingsFragment extends PreferenceFragmentCompat {
findPreference(POSTING_CATEGORY).setVisible(isLoggedIn);
findPreference(POSTING_APP_SIGNATURE_ENABLE).setVisible(isLoggedIn);
findPreference(UPLOADING_CATEGORY).setVisible(isLoggedIn);
findPreference(UPLOADING_APP_SIGNATURE_ENABLE).setVisible(isLoggedIn);
if (!isLoggedIn && defaultHomeTabEntries.contains("Unread")) {
defaultHomeTabEntries.remove("Unread");
defaultHomeTabValues.remove("2");
@ -148,6 +153,12 @@ public class SettingsFragment extends PreferenceFragmentCompat {
public void updateUserLoginState(boolean isLoggedIn) {
this.isLoggedIn = isLoggedIn;
findPreference(POSTING_CATEGORY).setVisible(isLoggedIn);
findPreference(POSTING_APP_SIGNATURE_ENABLE).setVisible(isLoggedIn);
findPreference(UPLOADING_CATEGORY).setVisible(isLoggedIn);
findPreference(UPLOADING_APP_SIGNATURE_ENABLE).setVisible(isLoggedIn);
if (!isLoggedIn && defaultHomeTabEntries.contains("Unread")) {
defaultHomeTabEntries.remove("Unread");
defaultHomeTabValues.remove("2");

6
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

@ -119,6 +119,8 @@ public class TopicActivity extends BaseActivity implements TopicTask.TopicTaskOb
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Fix for vector drawables on android <21
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
setContentView(R.layout.activity_topic);
viewModel = ViewModelProviders.of(this).get(TopicViewModel.class);
@ -141,8 +143,6 @@ public class TopicActivity extends BaseActivity implements TopicTask.TopicTaskOb
}
topicPageUrl = ThmmyPage.sanitizeTopicUrl(topicPageUrl);
thisPageBookmark = new Bookmark(topicTitle, ThmmyPage.getTopicId(topicPageUrl), true);
//Initializes graphics
@ -293,7 +293,7 @@ public class TopicActivity extends BaseActivity implements TopicTask.TopicTaskOb
topicMenuBookmarkClick();
return true;
case R.id.menu_info:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyleAccent);
LayoutInflater inflater = this.getLayoutInflater();
LinearLayout infoDialog = (LinearLayout) inflater.inflate(R.layout.dialog_topic_info
, null);

16
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -155,9 +155,9 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
.resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE)
.centerCrop()
.error(ResourcesCompat.getDrawable(context.getResources()
, R.drawable.ic_default_user_thumbnail, null))
, R.drawable.ic_default_user_thumbnail_white_24dp, null))
.placeholder(ResourcesCompat.getDrawable(context.getResources()
, R.drawable.ic_default_user_thumbnail, null))
, R.drawable.ic_default_user_thumbnail_white_24dp, null))
.transform(new CircleTransform())
.into(holder.thumbnail);
@ -409,16 +409,16 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
holder.quoteToggle.setVisibility(View.GONE);
} else {
if (viewModel.getToQuoteList().contains(currentPost.getPostIndex()))
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked);
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked_accent_24dp);
else
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked);
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked_grey_24dp);
//Sets graphics behavior
holder.quoteToggle.setOnClickListener(view -> {
viewModel.postIndexToggle(currentPost.getPostIndex());
if (viewModel.getToQuoteList().contains(currentPost.getPostIndex()))
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked);
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked_accent_24dp);
else
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked);
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked_grey_24dp);
});
}
} else if (currentHolder instanceof QuickReplyViewHolder) {
@ -430,9 +430,9 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
.resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE)
.centerCrop()
.error(ResourcesCompat.getDrawable(context.getResources()
, R.drawable.ic_default_user_thumbnail, null))
, R.drawable.ic_default_user_thumbnail_white_24dp, null))
.placeholder(ResourcesCompat.getDrawable(context.getResources()
, R.drawable.ic_default_user_thumbnail, null))
, R.drawable.ic_default_user_thumbnail_white_24dp, null))
.transform(new CircleTransform())
.into(holder.thumbnail);
holder.username.setText(getSessionManager().getUsername());

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

@ -0,0 +1,643 @@
package gr.thmmy.mthmmy.activities.upload;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.OpenableColumns;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.AppCompatButton;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Toast;
import net.gotev.uploadservice.MultipartUploadRequest;
import net.gotev.uploadservice.ServerResponse;
import net.gotev.uploadservice.UploadInfo;
import net.gotev.uploadservice.UploadNotificationConfig;
import net.gotev.uploadservice.UploadStatusDelegate;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.model.UploadCategory;
import gr.thmmy.mthmmy.utils.AppCompatSpinnerWithoutDefault;
import gr.thmmy.mthmmy.utils.parsing.ParseException;
import gr.thmmy.mthmmy.utils.parsing.ParseTask;
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_FILENAME;
import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.RESULT_TITLE;
public class UploadActivity extends BaseActivity {
/**
* The key to use when putting upload's category String to {@link UploadActivity}'s Bundle.
*/
public static final String BUNDLE_UPLOAD_CATEGORY = "UPLOAD_CATEGORY";
private static final String uploadIndexUrl = "https://www.thmmy.gr/smf/index.php?action=tpmod;dl=upload";
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;
private ArrayList<String> bundleCategory;
private String categorySelected = "-1";
private String uploaderProfileIndex = "1";
private String uploadFilename;
private Uri fileUri;
private String fileIcon;
//UI elements
private MaterialProgressBar progressBar;
private LinearLayout categoriesSpinners;
private AppCompatSpinnerWithoutDefault rootCategorySpinner;
private EditText uploadTitle;
private EditText uploadDescription;
private AppCompatButton titleDescriptionBuilderButton;
private AppCompatButton selectFileButton;
//private static AppCompatButton titleDescriptionBuilderButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload);
Bundle extras = getIntent().getExtras();
if (extras != null) {
String tmpUploadCategoryNav = extras.getString(BUNDLE_UPLOAD_CATEGORY);
//something like "THMMY.gr > Downloads > Βασικός Κύκλος > 3ο εξάμηνο > Ηλεκτρικά Κυκλώματα ΙΙ"
if (tmpUploadCategoryNav != null && !tmpUploadCategoryNav.equals("")) {
String[] tmpSplitUploadCategoryNav = tmpUploadCategoryNav.split(">");
for (int i = 0; i < tmpSplitUploadCategoryNav.length; ++i) {
tmpSplitUploadCategoryNav[i] = tmpSplitUploadCategoryNav[i].trim();
}
if (tmpSplitUploadCategoryNav.length > 2) {
bundleCategory = new ArrayList<>(Arrays.asList(tmpSplitUploadCategoryNav).subList(2, tmpSplitUploadCategoryNav.length));
}
}
}
//Initialize toolbar
toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("Upload");
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
createDrawer();
drawer.setSelection(UPLOAD_ID);
progressBar = findViewById(R.id.progressBar);
findViewById(R.id.upload_outer_scrollview).setVerticalScrollBarEnabled(false);
categoriesSpinners = findViewById(R.id.upload_spinners);
rootCategorySpinner = findViewById(R.id.upload_spinner_category_root);
rootCategorySpinner.setOnItemSelectedListener(new CustomOnItemSelectedListener(uploadRootCategories));
titleDescriptionBuilderButton = findViewById(R.id.upload_title_description_builder);
titleDescriptionBuilderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (categorySelected.equals("-1")) {
Toast.makeText(view.getContext(), "Please choose category first", Toast.LENGTH_SHORT).show();
return;
}
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();
String 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;
}
if (maybeCourse == null) {
Toast.makeText(view.getContext(), "Please choose a course", 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);
uploadTitle = findViewById(R.id.upload_title);
uploadDescription = findViewById(R.id.upload_description);
selectFileButton = findViewById(R.id.upload_select_file_button);
selectFileButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final CharSequence[] options = {"Take photo", "Choose file",
"Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(UploadActivity.this);
builder.setTitle("Upload file");
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
if (options[item].equals("Take photo")) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 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"};
Intent intent = new Intent(Intent.ACTION_GET_CONTENT)
//.setType("*/*")
.setType("image/jpeg")
.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
startActivityForResult(intent, REQUEST_CODE_CHOOSE_FILE);
} else if (options[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
}
});
findViewById(R.id.upload_upload_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String uploadTitleText = uploadTitle.getText().toString();
String uploadDescriptionText = uploadDescription.getText().toString();
if (uploadTitleText.equals("")) {
uploadTitle.setError("Required");
}
if (fileUri == null) {
selectFileButton.setError("Required");
}
if (categorySelected.equals("-1")) {
Toast.makeText(view.getContext(), "Please choose category first", Toast.LENGTH_SHORT).show();
}
if (categorySelected.equals("-1") || uploadTitleText.equals("") || fileUri == null) {
return;
}
String tmpDescriptionText = uploadDescriptionText;
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(view.getContext());
if (sharedPrefs.getBoolean(UPLOADING_APP_SIGNATURE_ENABLE_KEY, true)) {
tmpDescriptionText += uploadedFrommThmmyPromptHtml;
}
String tempFilePath = null;
if (uploadFilename != null) {
tempFilePath = createTempFile(uploadFilename);
if (tempFilePath == null) {
//Something went wrong, abort
return;
}
}
try {
final String finalTempFilePath = tempFilePath;
new MultipartUploadRequest(view.getContext(), uploadIndexUrl)
.setUtf8Charset()
.addParameter("tp-dluploadtitle", uploadTitleText)
.addParameter("tp-dluploadcat", categorySelected)
.addParameter("tp-dluploadtext", tmpDescriptionText)
.addFileToUpload(tempFilePath == null
? fileUri.toString()
: tempFilePath
, "tp-dluploadfile")
.addParameter("tp_dluploadicon", fileIcon)
.addParameter("tp-uploaduser", uploaderProfileIndex)
.setNotificationConfig(new UploadNotificationConfig())
.setMaxRetries(2)
.setDelegate(new UploadStatusDelegate() {
@Override
public void onProgress(Context context, UploadInfo uploadInfo) {
}
@Override
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse,
Exception exception) {
Toast.makeText(context, "Upload failed", Toast.LENGTH_SHORT).show();
if (finalTempFilePath != null) {
if (!deleteTempFile(finalTempFilePath)) {
Toast.makeText(context, "Failed to delete temp file", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
if (finalTempFilePath != null) {
if (!deleteTempFile(finalTempFilePath)) {
Toast.makeText(context, "Failed to delete temp file", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onCancelled(Context context, UploadInfo uploadInfo) {
if (finalTempFilePath != null) {
if (!deleteTempFile(finalTempFilePath)) {
Toast.makeText(context, "Failed to delete temp file", Toast.LENGTH_SHORT).show();
}
}
}
})
.startUpload();
} catch (Exception exception) {
Timber.e(exception, "AndroidUploadService: %s", exception.getMessage());
}
}
});
if (uploadRootCategories.isEmpty()) {
parseUploadPageTask = new ParseUploadPageTask();
parseUploadPageTask.execute(uploadIndexUrl);
} else {
String[] tmpSpinnerArray = new String[uploadRootCategories.size()];
for (int i = 0; i < uploadRootCategories.size(); ++i) {
tmpSpinnerArray[i] = uploadRootCategories.get(i).getCategoryTitle();
}
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);
rootCategorySpinner.setAdapter(spinnerArrayAdapter);
//Sets bundle selection
if (bundleCategory != null) {
int bundleSelectionIndex = -1, currentIndex = 0;
for (UploadCategory category : uploadRootCategories) {
if (category.getCategoryTitle().contains(bundleCategory.get(0))) { //TODO fix .contains, always false
bundleSelectionIndex = currentIndex;
break;
}
++currentIndex;
}
if (bundleSelectionIndex != -1) {
rootCategorySpinner.setSelection(bundleSelectionIndex, true);
}
}
titleDescriptionBuilderButton.setEnabled(true);
}
}
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen()) {
drawer.closeDrawer();
return;
}
super.onBackPressed();
}
@Override
protected void onResume() {
drawer.setSelection(UPLOAD_ID);
super.onResume();
}
@Override
protected void onDestroy() {
super.onDestroy();
if (parseUploadPageTask != null && parseUploadPageTask.getStatus() != AsyncTask.Status.RUNNING)
parseUploadPageTask.cancel(true);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_CHOOSE_FILE && data != null) {
if (resultCode == Activity.RESULT_CANCELED) {
return;
}
fileUri = data.getData();
if (fileUri != null) {
String filename = filenameFromUri(fileUri);
selectFileButton.setText(filename);
filename = filename.toLowerCase();
if (filename.endsWith(".jpg")) {
fileIcon = "jpg_image.gif";
} else if (filename.endsWith(".gif")) {
fileIcon = "gif_image.gif";
} else if (filename.endsWith(".png")) {
fileIcon = "png_image.gif";
} else if (filename.endsWith(".html") || filename.endsWith(".htm")) {
fileIcon = "html_file.gif";
} else if (filename.endsWith(".pdf") || filename.endsWith(".doc") ||
filename.endsWith("djvu")) {
fileIcon = "text_file.gif";
} else if (filename.endsWith(".zip") || filename.endsWith(".rar") ||
filename.endsWith(".tar") || filename.endsWith(".tar.gz") ||
filename.endsWith(".gz")) {
fileIcon = "archive.gif";
} else {
fileIcon = "blank.gif";
}
}
} 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;
}
uploadFilename = data.getStringExtra(RESULT_FILENAME);
uploadTitle.setText(data.getStringExtra(RESULT_TITLE));
uploadDescription.setText(data.getStringExtra(RESULT_DESCRIPTION));
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
@NonNull
private String filenameFromUri(Uri uri) {
String filename = null;
if (uri.getScheme().equals("content")) {
try (Cursor cursor = getContentResolver().query(uri, null, null, null, null)) {
if (cursor != null && cursor.moveToFirst()) {
filename = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
}
}
if (filename == null) {
filename = uri.getPath();
int cut = filename.lastIndexOf('/');
if (cut != -1) {
filename = filename.substring(cut + 1);
}
}
return filename;
}
@Nullable
private String createTempFile(String newFilename) {
String oldFilename = filenameFromUri(fileUri);
String fileExtension = oldFilename.substring(oldFilename.indexOf("."));
String destinationFilename = android.os.Environment.getExternalStorageDirectory().getPath() +
File.separatorChar + "~tmp_mThmmy_uploads" + File.separatorChar + newFilename + fileExtension;
File tempDirectory = new File(android.os.Environment.getExternalStorageDirectory().getPath() +
File.separatorChar + "~tmp_mThmmy_uploads");
if (!tempDirectory.exists()) {
if (!tempDirectory.mkdirs()) {
Timber.w("Temporary directory build returned false in %s", UploadActivity.class.getSimpleName());
Toast.makeText(this, "Couldn't create temporary directory", Toast.LENGTH_SHORT).show();
return null;
}
}
InputStream inputStream;
BufferedInputStream bufferedInputStream = null;
BufferedOutputStream bufferedOutputStream = null;
try {
inputStream = getContentResolver().openInputStream(fileUri);
if (inputStream == null) {
Timber.w("Input stream was null, %s", UploadActivity.class.getSimpleName());
return null;
}
bufferedInputStream = new BufferedInputStream(inputStream);
bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(destinationFilename, false));
byte[] buf = new byte[1024];
bufferedInputStream.read(buf);
do {
bufferedOutputStream.write(buf);
} while (bufferedInputStream.read(buf) != -1);
} catch (IOException exception) {
exception.printStackTrace();
} finally {
try {
if (bufferedInputStream != null) bufferedInputStream.close();
if (bufferedOutputStream != null) bufferedOutputStream.close();
} catch (IOException exception) {
exception.printStackTrace();
}
}
return destinationFilename;
}
private boolean deleteTempFile(String destinationFilename) {
File file = new File(destinationFilename);
return file.delete();
}
private class CustomOnItemSelectedListener implements AdapterView.OnItemSelectedListener {
private ArrayList<UploadCategory> parentCategories, childCategories;
// Suppresses default constructor
@SuppressWarnings("unused")
private CustomOnItemSelectedListener() {
}
CustomOnItemSelectedListener(ArrayList<UploadCategory> parentCategories) {
this.parentCategories = parentCategories;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//Removes old, unneeded sub-category spinner(s)
int viewIndex = categoriesSpinners.indexOfChild((AppCompatSpinnerWithoutDefault) view.getParent());
if (viewIndex + 1 != categoriesSpinners.getChildCount()) { //Makes sure this is not the last child
categoriesSpinners.removeViews(viewIndex + 1, categoriesSpinners.getChildCount() - viewIndex - 1);
}
categorySelected = parentCategories.get(position).getValue();
//Adds new sub-category spinner
if (parentCategories.get(position).hasSubCategories()) {
childCategories = parentCategories.get(position).getSubCategories();
String[] tmpSpinnerArray = new String[childCategories.size()];
for (int i = 0; i < tmpSpinnerArray.length; ++i) {
tmpSpinnerArray[i] = childCategories.get(i).getCategoryTitle();
}
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(getApplicationContext(),
android.R.layout.simple_spinner_dropdown_item, tmpSpinnerArray);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
AppCompatSpinnerWithoutDefault subSpinner = new AppCompatSpinnerWithoutDefault(categoriesSpinners.getContext());
subSpinner.setPromptId(R.string.upload_spinners_hint);
subSpinner.setPopupBackgroundResource(R.color.primary);
subSpinner.setAdapter(spinnerArrayAdapter);
subSpinner.setOnItemSelectedListener(new CustomOnItemSelectedListener(childCategories));
categoriesSpinners.addView(subSpinner);
//Sets bundle selection
if (bundleCategory != null && viewIndex < bundleCategory.size()) {
int bundleSelectionIndex = -1, currentIndex = 0;
for (UploadCategory category : parentCategories) {
if (category.getCategoryTitle().contains(bundleCategory.get(viewIndex))) {
bundleSelectionIndex = currentIndex;
break;
}
++currentIndex;
}
if (bundleSelectionIndex != -1) {
subSpinner.setSelection(bundleSelectionIndex, true);
}
}
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
/**
* An {@link ParseTask} that handles asynchronous fetching of the upload page and parsing the
* upload categories.
*/
private class ParseUploadPageTask extends ParseTask {
@Override
protected void onPreExecute() {
progressBar.setVisibility(ProgressBar.VISIBLE);
}
@Override
protected void parse(Document uploadPage) throws ParseException {
Elements categoriesElements;
Element uploaderProfileIndexElement;
try {
categoriesElements = uploadPage.select("select[name='tp-dluploadcat']>option");
uploaderProfileIndexElement = uploadPage.select("input[name=\"tp-uploaduser\"]").first();
} catch (Exception e) {
throw new ParseException("Parsing failed (UploadActivity)");
}
uploaderProfileIndex = uploaderProfileIndexElement.attr("value");
for (Element category : categoriesElements) {
String categoryValue = category.attr("value");
String categoryText = category.text();
if (categoryText.startsWith("- ")) {
//This is a level one subcategory
uploadRootCategories.get(uploadRootCategories.size() - 1).addSubCategory(categoryValue, categoryText);
} else if (categoryText.startsWith("-- ")) {
//This is a level two subcategory
UploadCategory rootLevelCategory = uploadRootCategories.get(uploadRootCategories.size() - 1);
UploadCategory firstLevelCategory = rootLevelCategory.getSubCategories().get(rootLevelCategory.getSubCategories().size() - 1);
firstLevelCategory.addSubCategory(categoryValue, categoryText);
} else if (categoryText.startsWith("--- ")) {
//This is a level three subcategory
UploadCategory rootLevelCategory = uploadRootCategories.get(uploadRootCategories.size() - 1);
UploadCategory firstLevelCategory = rootLevelCategory.getSubCategories().get(rootLevelCategory.getSubCategories().size() - 1);
UploadCategory secondLevelCategory = firstLevelCategory.getSubCategories().get(firstLevelCategory.getSubCategories().size() - 1);
secondLevelCategory.addSubCategory(categoryValue, categoryText);
} else if (categoryText.startsWith("---- ")) {
//This is a level three subcategory
UploadCategory rootLevelCategory = uploadRootCategories.get(uploadRootCategories.size() - 1);
UploadCategory firstLevelCategory = rootLevelCategory.getSubCategories().get(rootLevelCategory.getSubCategories().size() - 1);
UploadCategory secondLevelCategory = firstLevelCategory.getSubCategories().get(firstLevelCategory.getSubCategories().size() - 1);
UploadCategory thirdLevelCategory = secondLevelCategory.getSubCategories().get(secondLevelCategory.getSubCategories().size() - 1);
thirdLevelCategory.addSubCategory(categoryValue, categoryText);
} else {
//This is a root category
uploadRootCategories.add(new UploadCategory(categoryValue, categoryText));
}
}
}
@Override
protected void postExecution(ResultCode result) {
String[] tmpSpinnerArray = new String[uploadRootCategories.size()];
for (int i = 0; i < uploadRootCategories.size(); ++i) {
tmpSpinnerArray[i] = uploadRootCategories.get(i).getCategoryTitle();
}
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);
rootCategorySpinner.setAdapter(spinnerArrayAdapter);
//Sets bundle selection
if (bundleCategory != null) {
int bundleSelectionIndex = -1, currentIndex = 0;
for (UploadCategory category : uploadRootCategories) {
if (category.getCategoryTitle().contains(bundleCategory.get(0))) { //TODO fix .contains, always false
bundleSelectionIndex = currentIndex;
break;
}
++currentIndex;
}
if (bundleSelectionIndex != -1) {
rootCategorySpinner.setSelection(bundleSelectionIndex, true);
}
}
titleDescriptionBuilderButton.setEnabled(true);
progressBar.setVisibility(ProgressBar.GONE);
}
}
}

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

@ -0,0 +1,481 @@
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.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.Toast;
import java.util.Calendar;
import gr.thmmy.mthmmy.R;
import timber.log.Timber;
public class UploadFieldsBuilderActivity extends AppCompatActivity {
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;
private LinearLayout semesterChooserLinear;
private RadioGroup typeRadio, semesterRadio;
private EditText year;
private TextWatcher customYearWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String working = s.toString();
boolean isValid;
if (working.length() == 4) {
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
int inputYear = Integer.parseInt(working);
isValid = inputYear <= currentYear && inputYear > 2000;
} else {
isValid = false;
}
if (!isValid) {
year.setError("Please enter a valid year");
} else {
year.setError(null);
}
}
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
};
@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 toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("Upload fields builder");
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
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);
year.addTextChangedListener(customYearWatcher);
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 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 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;
}
}
@Nullable
private String getGreeklishCourseName() {
return getGreeklishOrMinifiedCourseName(true);
}
@Nullable
private String getMinifiedCourseName() {
return getGreeklishOrMinifiedCourseName(false);
}
@Nullable
private String getGreeklishOrMinifiedCourseName(boolean greeklish) {
//TODO fill missing values
if (course.contains("Συστήματα Υπολογιστών (Υπολογιστικά Συστήματα)")) {
return greeklish ? "sys_ypologistwn" : "Συσ. Υπολογιστών";
} else if (course.contains("Τεχνική Μηχανική")) {
return greeklish ? "texn_mhxan" : "Τεχν. Μηχαν.";
} else if (course.contains("Διαφορικές Εξισώσεις")) {
return greeklish ? "diaforikes" : "Διαφορικές";
} else if (course.contains("Θεωρία Πιθανοτήτων και Στατιστική")) {
return greeklish ? "pithanothtes" : "Πιθανότητες";
} else if (course.contains("Εφαρμοσμένα Μαθηματικά Ι")) {
return greeklish ? "efarmosmena_math_I" : "Εφαρμοσμένα 1";
} else if (course.contains("Ηλεκτρικά Κυκλώματα ΙΙ")) {
return greeklish ? "kyklwmata_II" : "Κυκλώματα 2";
} else if (course.contains("Ηλεκτρολογικά Υλικά")) {
return greeklish ? "ylika" : "Ηλεκτρ. Υλικά";
} else if (course.contains("Ηλεκτρομαγνητικό Πεδίο Ι")) {
return greeklish ? "pedio_I" : "Πεδίο 1";
} else if (course.contains("Θεωρία Σημάτων και Γραμμικών Συστημάτων")) {
return greeklish ? "analog_shma" : "Σύματα & Συστήματα";
} else if (course.contains("Προγραμματιστικές Τεχνικές")) {
return greeklish ? "cpp" : "Προγραμματ. Τεχν.";
} else if (course.contains("Αριθμητική Ανάλυση")) {
return greeklish ? "arith_anal" : "Αριθμ. Ανάλυση";
} else if (course.contains("Αρχιτεκτονική Υπολογιστών")) {
return greeklish ? "arx_ypologistwn" : "Αρχ. Υπολογιστών";
} else if (course.contains("Εισαγωγή στην Ενεργειακή Τεχνολογία Ι")) {
return greeklish ? "EET_I" : "ΕΕΤ 1";
} else if (course.contains("Ηλεκτρικά Κυκλώματα ΙΙΙ")) {
return greeklish ? "kyklwmata_I" : "Κυκλώματα 3";
} else if (course.contains("Ηλεκτρομαγνητικό Πεδίο ΙΙ")) {
return greeklish ? "pedio_II" : "Πεδίο 2";
} else if (course.contains("Στοχαστικό Σήμα")) {
return greeklish ? "stox_shma" : "Στοχ. Σήμα";
} else if (course.contains("Ψηφιακά Συστήματα Ι")) {
return greeklish ? "pshfiaka_I" : "Ψηφιακά 1";
} else if (course.contains("Αναλογικές Τηλεπικοινωνίες (πρώην Τηλεπικοινωνιακά Συστήματα Ι)")) {
return greeklish ? "anal_thlep" : "Αναλογικές Τηλεπ.";
} else if (course.contains("Διάδοση Ηλεκτρομαγνητικού Κύματος Ι (πρώην Πεδίο ΙΙΙ)")) {
return greeklish ? "diadosi_1" : "Διάδοση 1";
} else if (course.contains("Δομές Δεδομένων")) {
return greeklish ? "dom_dedomenwn" : "Δομ. Δεδομ.";
} else if (course.contains("Εισαγωγή στην Ενεργειακή Τεχνολογία ΙΙ")) {
return greeklish ? "EET_2" : "ΕΕΤ2";
} else if (course.contains("Ηλεκτρικές Μετρήσεις Ι")) {
return greeklish ? "metrhseis_1" : "Μετρήσεις 1";
} else if (course.contains("Ηλεκτρονική ΙΙ")) {
return greeklish ? "hlektronikh_2" : "Ηλεκτρονική 2";
} else if (course.contains("Συστήματα Αυτομάτου Ελέγχου Ι")) {
return greeklish ? "SAE_1" : "ΣΑΕ 1";
} else if (course.contains("Γραμμική Άλγεβρα")) {
return greeklish ? "grammikh_algebra" : "Γραμμ. Άλγεβρ.";
} else if (course.contains("Δομημένος Προγραμματισμός")) {
return greeklish ? "C" : "Δομ. Προγραμμ.";
} else if (course.contains("Λογική Σχεδίαση")) {
return greeklish ? "logiki_sxediash" : "Λογική Σχεδίαση";
} else if (course.contains("Λογισμός Ι")) {
return greeklish ? "logismos_I" : "Λογισμός 1";
} else if (course.contains("Τεχνικές Σχεδίασης με Η/Υ")) {
return greeklish ? "sxedio" : "Σχέδιο";
} else if (course.contains("Φυσική Ι")) {
return greeklish ? "fysikh_I" : "Φυσική 1";
} else if (course.contains("Αντικειμενοστραφής Προγραμματισμός")) {
return greeklish ? "OOP" : "Αντικειμενοστραφής";
} else if (course.contains("Εφαρμοσμένη Θερμοδυναμική")) {
return greeklish ? "thermodynamikh" : "Θερμοδυναμική";
} else if (course.contains("Ηλεκτρικά Κυκλώματα Ι")) {
return greeklish ? "kyklwmata_I" : "Κυκλώματα 1";
} else if (course.contains("Λογισμός ΙΙ")) {
return greeklish ? "logismos_II" : "Λογισμός 2";
} else if (course.contains("Οργάνωση Υπολογιστών")) {
return greeklish ? "org_ypol" : "Οργάνωση Υπολ.";
} else if (course.contains("Ηλεκτρονική Ι")) {
return greeklish ? "hlektronikh_1" : "Ηλεκτρονική 1";
} else if (course.contains("Διακριτά μαθηματικά")) {
return greeklish ? "diakrita" : "Διακριτά Μαθηματικά";
} else if (course.contains("Σήματα και Συστήματα")) {
return greeklish ? "analog_shma" : "Σύματα & Συστήματα";
} else if (course.contains("Εισαγωγή στις εφαρμογές Πυρηνικής Τεχνολογίας")) {
return greeklish ? "Intro_Purhnikh_Texn" : "Εισ. Πυρηνικη Τεχν.";
} else if (course.contains("Επιχειρησιακή Έρευνα")) {
return greeklish ? "epixeirisiaki" : "Επιχειρησιακή Έρευνα";
} else if (course.contains("Ημιαγωγά Υλικά: Θεωρία-Διατάξεις")) {
return greeklish ? "Hmiagwga_Ylika" : "Ημιαγωγά Υλικά";
} else if (course.contains("Μετάδοση Θερμότητας")) {
return greeklish ? "metadosi_therm" : "Μετάδοση Θερμ.";
} else if (course.contains("Συστήματα Ηλεκτρικής Ενέργειας Ι")) {
return greeklish ? "SHE_I" : "ΣΗΕ 1";
} else if (course.contains("Υψηλές Τάσεις Ι")) {
return greeklish ? "ypshles_I" : "Υψηλές 1";
} else if (course.contains("Θεωρία και Τεχνολογία Πυρηνικών Αντιδραστήρων")) {
return greeklish ? "texn_antidrasthrwn" : "Τεχνολογία Αντιδραστήρων";
} else if (course.contains("Τεχνολογία Ηλεκτροτεχνικών Υλικών")) {
return greeklish ? "Hlektrotexnika_Ylika" : "Ηλεκτροτεχνικά Υλικά";
} else if (course.contains("Ηλεκτρικές Μηχανές Α'")) {
return greeklish ? "mhxanes_A" : "Μηχανές Α";
} else if (course.contains("Σταθμοί Παραγωγής Ηλεκτρικής Ενέργειας")) {
return greeklish ? "SPHE" : "ΣΠΗΕ";
} else if (course.contains("Συστήματα Ηλεκτρικής Ενέργειας ΙΙ")) {
return greeklish ? "SHE_II" : "ΣΗΕ 2";
} else if (course.contains("Υψηλές Τάσεις ΙΙ")) {
return greeklish ? "ypshles_II" : "Υψηλές 2";
} else if (course.contains("Αρχές Οικονομίας")) {
return greeklish ? "arx_oikonomias" : "Αρχές Οικονομίας";
} else if (course.contains("Διανεμημένη Παραγωγή")) {
return greeklish ? "dian_paragwgh" : "Διανεμημένη Παραγωγή";
} else if (course.contains("Διαχείριση Συστημάτων Ηλεκτρικής Ενέργειας")) {
return greeklish ? "dshe" : "ΔΣΗΕ";
} else if (course.contains("Υψηλές Τάσεις ΙΙΙ")) {
return greeklish ? "ypshles_III" : "Υψηλές 3";
} else if (course.contains("Ανάλυση Συστημάτων Ηλεκτρικής Ενέργειας")) {
return greeklish ? "ASHE" : "ΑΣΗΕ";
} else if (course.contains("Ηλεκτρικές Μηχανές Β'")) {
return greeklish ? "mhxanes_B" : "Μηχανές Β";
} else if (course.contains("Ηλεκτρονικά Ισχύος Ι")) {
return greeklish ? "isxyos_I" : "Ισχύος 1";
} else if (course.contains("Συστήματα Ηλεκτρικής Ενέργειας ΙΙΙ")) {
return greeklish ? "SHE_III" : "ΣΗΕ 3";
} else if (course.contains("Σερβοκινητήρια Συστήματα")) {
return greeklish ? "servo" : "Σέρβο";
} else if (course.contains("Συστήματα Ηλεκτροκίνησης")) {
return greeklish ? "hlektrokinhsh" : "Ηλεκτροκίνηση";
} else if (course.contains("Υπολογιστικές Μέθοδοι στα Ενεργειακά Συστήματα")) {
return greeklish ? "ymes" : "ΥΜΕΣ";
} else if (course.contains("Υψηλές Τάσεις 4")) {
return greeklish ? "ypshles_IV" : "Υψηλές 4";
} else if (course.contains("Ηλεκτρικές Μηχανές Γ'")) {
return greeklish ? "mhxanes_C" : "Μηχανές Γ";
} else if (course.contains("Ηλεκτρική Οικονομία")) {
return greeklish ? "hlektr_oikonomia" : "Ηλεκτρική Οικονομία";
} else if (course.contains("Ηλεκτρονικά Ισχύος ΙΙ")) {
return greeklish ? "isxyos_II" : "Ισχύος 2";
} else if (course.contains("Ανάλυση και Σχεδίαση Αλγορίθμων")) {
return greeklish ? "algorithms" : "Αλγόριθμοι";
} else if (course.contains("Διακριτά Μαθηματικά")) {
return greeklish ? "diakrita" : "Διακριτά Μαθηματικά";
} else if (course.contains("Κβαντική Φυσική")) {
return greeklish ? "kvantikh" : "Κβαντική";
} else if (course.contains("Ρομποτική")) {
return greeklish ? "rompotikh" : "Ρομποτική";
} else if (course.contains("Τεχνικές Βελτιστοποίησης")) {
return greeklish ? "veltistopoihsh" : "Βελτιστοποίηση";
} else if (course.contains("Ηλεκτρικές Μετρήσεις ΙΙ")) {
return greeklish ? "metrhseis_II" : "Μετρήσεις 2";
} else if (course.contains("Ηλεκτρονική ΙΙΙ")) {
return greeklish ? "hlektronikh_III" : "Ηλεκτρονική 3";
} else if (course.contains("Συστήματα Αυτομάτου Ελέγχου ΙΙ")) {
return greeklish ? "SAE_II" : "ΣΑΕ 2";
} else if (course.contains("Ψηφιακά Συστήματα ΙΙ")) {
return greeklish ? "pshfiaka_II" : "Ψηφιακά 2";
} else if (course.contains("Ανάλυση Χρονοσειρών")) {
return greeklish ? "xronoseires" : "Χρονοσειρές";
} else if (course.contains("Θεωρία Υπολογισμών και Αλγορίθμων")) {
return greeklish ? "thya" : "ΘΥΑ";
} else if (course.contains("Παράλληλα και Κατανεμημένα Συστήματα")) {
return greeklish ? "parallhla" : "Παράλληλα";
} else if (course.contains("Προγραμματιζόμενα Κυκλώματα ASIC")) {
return greeklish ? "asic" : "ASIC";
} else if (course.contains("Προσομοίωση και Μοντελοποίηση Συστημάτων")) {
return greeklish ? "montelopoihsh" : "Μοντελοποίηση";
} else if (course.contains("Συστήματα Αυτομάτου Ελέγχου ΙΙI")) {
return greeklish ? "SAE_III" : "ΣΑΕ 3";
} else if (course.contains("Σύνθεση Ενεργών και Παθητικών Κυκλωμάτων")) {
return greeklish ? "synthesh" : "Σύνθεση";
} else if (course.contains("Δίκτυα Υπολογιστών Ι")) {
return greeklish ? "diktya_I" : "Δίκτυα 1";
} else if (course.contains("Λειτουργικά Συστήματα")) {
return greeklish ? "OS" : "Λειτουργικά";
} else if (course.contains("Συστήματα Μικροϋπολογιστών")) {
return greeklish ? "mikro_I" : "Μίκρο 1";
} else if (course.contains("Ασαφή Συστήματα")) {
return greeklish ? "asafh" : "Ασαφή";
} else if (course.contains("Γραφική με Υπολογιστές")) {
return greeklish ? "grafikh" : "Γραφική";
} else if (course.contains("Ενσωματωμένα Συστήματα Πραγματικού Χρόνου")) {
return greeklish ? "enswmatwmena" : "Ενσωματωμένα";
} else if (course.contains("Τηλεπικοινωνιακή Ηλεκτρονική")) {
return greeklish ? "tilep_ilektr" : "Τηλεπ. Ηλεκτρ.";
} else if (course.contains("Ψηφιακά Συστήματα ΙΙΙ")) {
return greeklish ? "pshfiaka_III" : "Ψηφιακά 3";
} else if (course.contains("Ψηφιακή Επεξεργασία Εικόνας")) {
return greeklish ? "psee" : "ΨΕΕ";
} else if (course.contains("Δίκτυα Υπολογιστών ΙΙ")) {
return greeklish ? "diktya_II" : "Δίκτυα 2";
} else if (course.contains("Μικροεπεξεργαστές και Περιφερειακά")) {
return greeklish ? "mikro_II" : "Μίκρο 2";
} else if (course.contains("Τεχνολογία Λογισμικού")) {
return greeklish ? "SE" : "Τεχνολογία Λογισμικού";
} else if (course.contains("Ψηφιακά Φίλτρα")) {
return greeklish ? "filtra" : "Φίλτρα";
} else if (course.contains("Αναγνώριση Προτύπων")) {
return greeklish ? "protipa" : "Αναγνώριση Προτύπων";
} else if (course.contains("Ασφάλεια Πληροφοριακών Συστημάτων")) {
return greeklish ? "asfaleia" : "Ασφάλεια";
} else if (course.contains("Βάσεις Δεδομένων")) {
return greeklish ? "vaseis" : "Βάσεις";
} else if (course.contains("Βιομηχανική Πληροφορική")) {
return greeklish ? "viomix_plir" : "Βιομηχανική Πληρ";
} else if (course.contains("Ευφυή Συστήματα Ρομπότ")) {
return greeklish ? "eufuh" : "Ευφυή";
} else if (course.contains("Συστήματα Πολυμέσων και Εικονική Πραγματικότητα")) {
return greeklish ? "polymesa" : "Πολυμέσα";
} else if (course.contains("Σχεδίαση Συστημάτων VLSI")) {
return greeklish ? "VLSI" : "VLSI";
} else if (course.contains("Ακουστική Ι")) {
return greeklish ? "akoystikh_I" : "Ακουστική 1";
} else if (course.contains("Εφαρμοσμένα Μαθηματικά ΙΙ")) {
return greeklish ? "efarmosmena_math_II" : "Εφαρμοσμένα 2";
} else if (course.contains("Ηλεκτρακουστική Ι")) {
return greeklish ? "hlektroakoystikh_I" : "Ηλεκτροακουστική 1";
} else if (course.contains("Οπτική Ι")) {
return greeklish ? "optikh_I" : "Οπτική 1";
} else if (course.contains("Διάδοση Η/Μ Κύματος ΙΙ")) {
return greeklish ? "diadosi_II" : "Διάδοση 2";
} else if (course.contains("Ψηφιακές Τηλεπικοινωνίες Ι")) {
return greeklish ? "pshf_thlep_I" : "Ψηφιακές Τηλεπ. 1";
} else if (course.contains("Ακουστική ΙΙ")) {
return greeklish ? "akoystikh_II" : "Ακουστική 2";
} else if (course.contains("Βιοϊατρική Τεχνολογία")) {
return greeklish ? "vioiatriki" : "Βιοιατρική";
} else if (course.contains("Ηλεκτρακουστική ΙΙ")) {
return greeklish ? "hlektroakoystikh_II" : "Ηλεκτροακουστική 2";
} else if (course.contains("Οπτική ΙΙ")) {
return greeklish ? "optikh_II" : "Οπτική 2";
} else if (course.contains("Ασύρματος Τηλεπικοινωνία Ι")) {
return greeklish ? "asyrmatos_I" : "Ασύρματος 1";
} else if (course.contains("Μικροκύματα I")) {
return greeklish ? "mikrokymata_I" : "Μικροκύματα 1";
} else if (course.contains("Ψηφιακές Τηλεπικοινωνίες ΙΙ")) {
return greeklish ? "pshf_thlep_II" : "Ψηφιακές Τηλεπ. 2";
} else if (course.contains("Ψηφιακή Επεξεργασία Σήματος")) {
return greeklish ? "PSES" : "ΨΕΣ";
} else if (course.contains("Εισαγωγή στην Πολιτική Οικονομία")) {
return greeklish ? "polit_oik" : "Πολιτική Οικονομία";
} else if (course.contains("Θεωρία Σκέδασης")) {
return greeklish ? "skedash" : "Σκέδαση";
} else if (course.contains("Προηγμένες Τεχνικές Επεξεργασίας Σήματος")) {
return greeklish ? "ptes" : "ΠΤΕΣ";
} else if (course.contains("Τηλεοπτικά Συστήματα")) {
return greeklish ? "tileoptika" : "Τηλεοπτικά";
} else if (course.contains("Ασύρματος Τηλεπικοινωνία ΙΙ")) {
return greeklish ? "asyrmatos_II" : "Ασύρματος 2";
} else if (course.contains("Δίκτυα Τηλεπικοινωνιών")) {
return greeklish ? "diktya_thlep" : "Δίκτυα Τηλέπ.";
} else if (course.contains("Θεωρία Πληροφοριών")) {
return greeklish ? "theoria_plir" : "Θεωρία Πληρ.";
} else if (course.contains("Οπτικές Επικοινωνίες")) {
return greeklish ? "optikes_thlep" : "Οπτικές Τηλεπ.";
} else if (course.contains("Ευρυζωνικά Δίκτυα")) {
return greeklish ? "eyryzwnika" : "Ευρυζωνικά";
} else if (course.contains("Τεχνικές μη Καταστρεπτικών Δοκιμών")) {
return greeklish ? "non_destructive_tests" : "Μη Καταστρεπτικές Δοκιμές";
} else if (course.contains("Φωτονική Τεχνολογία")) {
return greeklish ? "fwtonikh" : "Φωτονική";
} else if (course.contains("Μικροκυματική Τηλεπισκόπηση")) {
return greeklish ? "thlepiskophsh" : "Τηλεπισκόπηση";
} else if (course.contains("Μικροκύματα II")) {
return greeklish ? "mikrokymata_II" : "Μικροκύματα 2";
} else {
return null;
}
}
}

53
app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java

@ -17,6 +17,7 @@ import android.support.design.widget.BottomSheetDialog;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
@ -44,7 +45,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;
@ -65,7 +66,9 @@ import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWN
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME;
import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DEFAULT_HOME_TAB;
import static gr.thmmy.mthmmy.services.DownloadHelper.SAVE_DIR;
import static gr.thmmy.mthmmy.session.SessionManager.SUCCESS;
import static gr.thmmy.mthmmy.utils.FileUtils.getMimeType;
public abstract class BaseActivity extends AppCompatActivity {
@ -84,8 +87,6 @@ public abstract class BaseActivity extends AppCompatActivity {
private SharedPreferences bookmarksFile;
private ArrayList<Bookmark> topicsBookmarked;
private ArrayList<Bookmark> boardsBookmarked;
private static Drawable bookmarked;
private static Drawable notBookmarked;
//Common UI elements
protected Toolbar toolbar;
@ -103,18 +104,6 @@ public abstract class BaseActivity extends AppCompatActivity {
if (sessionManager == null)
sessionManager = BaseApplication.getInstance().getSessionManager();
if (bookmarked == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
bookmarked = getResources().getDrawable(R.drawable.ic_bookmark_true, null);
} else //noinspection deprecation
bookmarked = getResources().getDrawable(R.drawable.ic_bookmark_true);
}
if (notBookmarked == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
notBookmarked = getResources().getDrawable(R.drawable.ic_bookmark_false, null);
} else //noinspection deprecation
notBookmarked = getResources().getDrawable(R.drawable.ic_bookmark_false);
}
if (topicsBookmarked == null || boardsBookmarked == null) {
bookmarksFile = getSharedPreferences(BOOKMARKS_SHARED_PREFS, Context.MODE_PRIVATE);
loadSavedBookmarks();
@ -475,6 +464,14 @@ public abstract class BaseActivity extends AppCompatActivity {
}
protected void onPostExecute(Integer result) {
if (result == SUCCESS) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
if (sharedPrefs.getString(DEFAULT_HOME_TAB, "0").equals("2")) {
SharedPreferences.Editor editor = sharedPrefs.edit();
editor.putString(DEFAULT_HOME_TAB, "0").apply();
}
}
updateDrawer();
if (mainActivity != null)
mainActivity.updateTabs();
@ -501,9 +498,9 @@ public abstract class BaseActivity extends AppCompatActivity {
protected void setTopicBookmark(MenuItem thisPageBookmarkMenuButton) {
this.thisPageBookmarkMenuButton = thisPageBookmarkMenuButton;
if (thisPageBookmark.matchExists(topicsBookmarked)) {
thisPageBookmarkMenuButton.setIcon(bookmarked);
thisPageBookmarkMenuButton.setIcon(R.drawable.ic_bookmark_true_accent_24dp);
} else {
thisPageBookmarkMenuButton.setIcon(notBookmarked);
thisPageBookmarkMenuButton.setIcon(R.drawable.ic_bookmark_false_accent_24dp);
}
}
@ -513,19 +510,19 @@ public abstract class BaseActivity extends AppCompatActivity {
}
loadSavedBookmarks();
if (thisPageBookmark.matchExists(topicsBookmarked)) {
thisPageBookmarkMenuButton.setIcon(bookmarked);
thisPageBookmarkMenuButton.setIcon(R.drawable.ic_bookmark_true_accent_24dp);
} else {
thisPageBookmarkMenuButton.setIcon(notBookmarked);
thisPageBookmarkMenuButton.setIcon(R.drawable.ic_bookmark_false_accent_24dp);
}
}
protected void topicMenuBookmarkClick() {
if (thisPageBookmark.matchExists(topicsBookmarked)) {
thisPageBookmarkMenuButton.setIcon(notBookmarked);
thisPageBookmarkMenuButton.setIcon(R.drawable.ic_bookmark_false_accent_24dp);
toggleTopicToBookmarks(thisPageBookmark);
Toast.makeText(getBaseContext(), "Bookmark removed", Toast.LENGTH_SHORT).show();
} else {
thisPageBookmarkMenuButton.setIcon(bookmarked);
thisPageBookmarkMenuButton.setIcon(R.drawable.ic_bookmark_true_accent_24dp);
toggleTopicToBookmarks(thisPageBookmark);
Toast.makeText(getBaseContext(), "Bookmark added", Toast.LENGTH_SHORT).show();
}
@ -533,18 +530,18 @@ public abstract class BaseActivity extends AppCompatActivity {
protected void setBoardBookmark(final ImageButton thisPageBookmarkImageButton) {
if (thisPageBookmark.matchExists(boardsBookmarked)) {
thisPageBookmarkImageButton.setImageDrawable(bookmarked);
thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_true_accent_24dp);
} else {
thisPageBookmarkImageButton.setImageDrawable(notBookmarked);
thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_false_accent_24dp);
}
thisPageBookmarkImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (thisPageBookmark.matchExists(boardsBookmarked)) {
thisPageBookmarkImageButton.setImageDrawable(notBookmarked);
thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_false_accent_24dp);
Toast.makeText(getBaseContext(), "Bookmark removed", Toast.LENGTH_SHORT).show();
} else {
thisPageBookmarkImageButton.setImageDrawable(bookmarked);
thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_true_accent_24dp);
Toast.makeText(getBaseContext(), "Bookmark added", Toast.LENGTH_SHORT).show();
}
toggleBoardToBookmarks(thisPageBookmark);
@ -557,9 +554,9 @@ public abstract class BaseActivity extends AppCompatActivity {
return;
loadSavedBookmarks();
if (thisPageBookmark.matchExists(boardsBookmarked)) {
thisPageBookmarkImageButton.setImageDrawable(bookmarked);
thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_true_accent_24dp);
} else {
thisPageBookmarkImageButton.setImageDrawable(notBookmarked);
thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_false_accent_24dp);
}
}
@ -651,7 +648,7 @@ public abstract class BaseActivity extends AppCompatActivity {
return true;
}
//Display popup gor user to grant permission
//Display popup for user to grant permission
private void requestPerms() { //Runtime permissions request for devices with API >= 23
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
String[] PERMISSIONS_STORAGE = {

BIN
app/src/main/res/drawable-hdpi/ic_arrow_drop_down.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 197 B

BIN
app/src/main/res/drawable-hdpi/ic_arrow_drop_up.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 186 B

BIN
app/src/main/res/drawable-hdpi/ic_bookmark_false.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 293 B

BIN
app/src/main/res/drawable-hdpi/ic_bookmark_true.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 230 B

BIN
app/src/main/res/drawable-hdpi/ic_delete_accent.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 B

BIN
app/src/main/res/drawable-hdpi/ic_delete_white.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 189 B

BIN
app/src/main/res/drawable-hdpi/ic_file_upload.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 175 B

BIN
app/src/main/res/drawable-hdpi/ic_format_quote_checked.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 258 B

BIN
app/src/main/res/drawable-hdpi/ic_format_quote_unchecked.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 257 B

BIN
app/src/main/res/drawable-hdpi/ic_info.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 595 B

BIN
app/src/main/res/drawable-hdpi/ic_insert_drive_file.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 183 B

BIN
app/src/main/res/drawable-hdpi/ic_more_vert.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 B

BIN
app/src/main/res/drawable-hdpi/ic_send.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 324 B

BIN
app/src/main/res/drawable-hdpi/ic_share.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 541 B

BIN
app/src/main/res/drawable-mdpi/ic_arrow_drop_down.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 170 B

BIN
app/src/main/res/drawable-mdpi/ic_arrow_drop_up.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 B

BIN
app/src/main/res/drawable-mdpi/ic_bookmark_false.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 203 B

BIN
app/src/main/res/drawable-mdpi/ic_bookmark_true.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 161 B

BIN
app/src/main/res/drawable-mdpi/ic_delete_accent.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 B

BIN
app/src/main/res/drawable-mdpi/ic_delete_white.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 129 B

BIN
app/src/main/res/drawable-mdpi/ic_file_upload.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 139 B

BIN
app/src/main/res/drawable-mdpi/ic_format_quote_checked.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 189 B

BIN
app/src/main/res/drawable-mdpi/ic_format_quote_unchecked.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 187 B

BIN
app/src/main/res/drawable-mdpi/ic_info.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 376 B

BIN
app/src/main/res/drawable-mdpi/ic_insert_drive_file.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 153 B

BIN
app/src/main/res/drawable-mdpi/ic_more_vert.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 B

BIN
app/src/main/res/drawable-mdpi/ic_send.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 257 B

BIN
app/src/main/res/drawable-mdpi/ic_share.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 365 B

BIN
app/src/main/res/drawable-xhdpi/ic_arrow_drop_down.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 B

BIN
app/src/main/res/drawable-xhdpi/ic_arrow_drop_up.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 228 B

BIN
app/src/main/res/drawable-xhdpi/ic_bookmark_false.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 336 B

BIN
app/src/main/res/drawable-xhdpi/ic_bookmark_true.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 261 B

BIN
app/src/main/res/drawable-xhdpi/ic_delete_accent.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 B

BIN
app/src/main/res/drawable-xhdpi/ic_delete_white.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 192 B

BIN
app/src/main/res/drawable-xhdpi/ic_file_upload.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 B

BIN
app/src/main/res/drawable-xhdpi/ic_format_quote_checked.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 B

BIN
app/src/main/res/drawable-xhdpi/ic_format_quote_unchecked.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 236 B

BIN
app/src/main/res/drawable-xhdpi/ic_info.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 796 B

BIN
app/src/main/res/drawable-xhdpi/ic_insert_drive_file.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 249 B

BIN
app/src/main/res/drawable-xhdpi/ic_more_vert.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 203 B

BIN
app/src/main/res/drawable-xhdpi/ic_send.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 419 B

BIN
app/src/main/res/drawable-xhdpi/ic_share.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 675 B

BIN
app/src/main/res/drawable-xxhdpi/ic_arrow_drop_down.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 396 B

BIN
app/src/main/res/drawable-xxhdpi/ic_arrow_drop_up.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 308 B

BIN
app/src/main/res/drawable-xxhdpi/ic_bookmark_false.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 478 B

BIN
app/src/main/res/drawable-xxhdpi/ic_bookmark_true.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 362 B

BIN
app/src/main/res/drawable-xxhdpi/ic_delete_accent.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 279 B

BIN
app/src/main/res/drawable-xxhdpi/ic_delete_white.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 277 B

BIN
app/src/main/res/drawable-xxhdpi/ic_file_upload.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 B

BIN
app/src/main/res/drawable-xxhdpi/ic_format_quote_checked.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 424 B

BIN
app/src/main/res/drawable-xxhdpi/ic_format_quote_unchecked.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 421 B

BIN
app/src/main/res/drawable-xxhdpi/ic_info.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

BIN
app/src/main/res/drawable-xxhdpi/ic_insert_drive_file.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 364 B

BIN
app/src/main/res/drawable-xxhdpi/ic_more_vert.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 297 B

BIN
app/src/main/res/drawable-xxhdpi/ic_send.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 553 B

BIN
app/src/main/res/drawable-xxhdpi/ic_share.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

BIN
app/src/main/res/drawable-xxxhdpi/ic_arrow_drop_down.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 451 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_arrow_drop_up.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 432 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_bookmark_false.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 620 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_bookmark_true.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 473 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_delete_accent.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 357 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_delete_white.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 353 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_file_upload.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 317 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_format_quote_checked.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 505 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_format_quote_unchecked.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 502 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_info.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

BIN
app/src/main/res/drawable-xxxhdpi/ic_insert_drive_file.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 475 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_more_vert.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_send.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 729 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_share.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

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

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="@color/accent"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M7,10l5,5 5,-5z"/>
</vector>

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

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="@color/accent"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M7,14l5,-5 5,5z"/>
</vector>

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

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="@color/accent"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M17,3L7,3c-1.1,0 -1.99,0.9 -1.99,2L5,21l7,-3 7,3L19,5c0,-1.1 -0.9,-2 -2,-2zM17,18l-5,-2.18L7,18L7,5h10v13z"/>
</vector>

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

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="@color/accent"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M17,3H7c-1.1,0 -1.99,0.9 -1.99,2L5,21l7,-3 7,3V5c0,-1.1 -0.9,-2 -2,-2z"/>
</vector>

BIN
app/src/main/res/drawable/ic_default_user_thumbnail.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

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

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
</vector>

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

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="@color/accent"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
</vector>

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

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
</vector>

11
app/src/main/res/drawable/ic_file_upload.xml

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M9,16h6v-6h4l-7,-7 -7,7h4zM5,18h14v2L5,20z"/>
</vector>

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

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M9,16h6v-6h4l-7,-7 -7,7h4zM5,18h14v2L5,20z"/>
</vector>

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

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="@color/accent"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M6,17h3l2,-4L11,7L5,7v6h3zM14,17h3l2,-4L19,7h-6v6h3z"/>
</vector>

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

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#4B4B4B"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M6,17h3l2,-4L11,7L5,7v6h3zM14,17h3l2,-4L19,7h-6v6h3z"/>
</vector>

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

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M11,17h2v-6h-2v6zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM11,9h2L13,7h-2v2z"/>
</vector>

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

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M6,2c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2L18,22c1.1,0 2,-0.9 2,-2L20,8l-6,-6L6,2zM13,9L13,3.5L18.5,9L13,9z"/>
</vector>

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

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
</vector>

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save