From d216964acb666fd7c5d2f564c519f7a5fffbfba0 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Mon, 9 Jul 2018 17:12:12 +0300 Subject: [PATCH] Init uploads, minor fixes --- app/build.gradle | 2 + app/src/main/AndroidManifest.xml | 8 + .../mthmmy/activities/UploadActivity.java | 319 ++++++++++++++++++ .../activities/board/BoardActivity.java | 2 +- .../downloads/DownloadsActivity.java | 53 ++- .../gr/thmmy/mthmmy/base/BaseActivity.java | 63 +++- .../gr/thmmy/mthmmy/base/BaseApplication.java | 7 + .../gr/thmmy/mthmmy/model/UploadCategory.java | 37 ++ .../main/res/drawable-hdpi/ic_file_upload.png | Bin 0 -> 175 bytes .../drawable-hdpi/ic_insert_drive_file.png | Bin 0 -> 183 bytes .../main/res/drawable-mdpi/ic_file_upload.png | Bin 0 -> 139 bytes .../drawable-mdpi/ic_insert_drive_file.png | Bin 0 -> 153 bytes .../res/drawable-xhdpi/ic_file_upload.png | Bin 0 -> 196 bytes .../drawable-xhdpi/ic_insert_drive_file.png | Bin 0 -> 249 bytes .../res/drawable-xxhdpi/ic_file_upload.png | Bin 0 -> 254 bytes .../drawable-xxhdpi/ic_insert_drive_file.png | Bin 0 -> 364 bytes .../res/drawable-xxxhdpi/ic_file_upload.png | Bin 0 -> 317 bytes .../drawable-xxxhdpi/ic_insert_drive_file.png | Bin 0 -> 475 bytes app/src/main/res/layout/activity_upload.xml | 163 +++++++++ app/src/main/res/menu/downloads_menu.xml | 10 + app/src/main/res/values/strings.xml | 13 + 21 files changed, 647 insertions(+), 30 deletions(-) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/activities/UploadActivity.java create mode 100644 app/src/main/java/gr/thmmy/mthmmy/model/UploadCategory.java create mode 100644 app/src/main/res/drawable-hdpi/ic_file_upload.png create mode 100644 app/src/main/res/drawable-hdpi/ic_insert_drive_file.png create mode 100644 app/src/main/res/drawable-mdpi/ic_file_upload.png create mode 100644 app/src/main/res/drawable-mdpi/ic_insert_drive_file.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_file_upload.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_insert_drive_file.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_file_upload.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_insert_drive_file.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_file_upload.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_insert_drive_file.png create mode 100644 app/src/main/res/layout/activity_upload.xml create mode 100644 app/src/main/res/menu/downloads_menu.xml diff --git a/app/build.gradle b/app/build.gradle index a4de63b5..cb816145 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,6 +54,8 @@ dependencies { implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'//TODO: deprecated! implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2' implementation 'com.jakewharton.timber:timber:4.7.0' + implementation 'net.gotev:uploadservice:3.4.2' + implementation 'net.gotev:uploadservice-okhttp:3.4.2' } apply plugin: 'com.google.gms.google-services' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 84fe83a8..3e7a42a9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -97,6 +97,14 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".activities.main.MainActivity" /> + + + uploadRootCategories = new ArrayList<>(); + //private String currentUploadCategory = ""; + private ParseUploadPageTask parseUploadPageTask; + private String categorySelected = "0"; + private String uploaderProfileIndex = "1"; + private Uri fileUri; + + //UI elements + private MaterialProgressBar progressBar; + private LinearLayout categoriesSpinners; + private AppCompatSpinner 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) { + if (fileUri != null) { + try { + String uploadId = new MultipartUploadRequest(v.getContext(), uploadIndexUrl) + .addParameter("tp-dluploadtitle", uploadTitle.getText().toString()) + .addParameter("tp-dluploadcat", categorySelected) + .addParameter("tp-dluploadtext", uploadDescription.getText().toString()) + .addFileToUpload(fileUri.toString(), "tp-dluploadfile") + .addParameter("tp_dluploadicon", "blank.gif") + .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 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 parentCategories, childCategories; + private boolean initialized = false; + + private CustomOnItemSelectedListener() { + //Disable default constructor + } + + CustomOnItemSelectedListener(ArrayList parentCategories) { + this.parentCategories = parentCategories; + } + + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + //Avoids call on initialization + if (!initialized) { + initialized = true; + return; + } + + //Removes old, unneeded sub categories spinner(s) + int viewIndex = categoriesSpinners.indexOfChild((AppCompatSpinner) 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 spinnerArrayAdapter = new ArrayAdapter<>(getApplicationContext(), + android.R.layout.simple_spinner_dropdown_item, tmpSpinnerArray); + spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + + AppCompatSpinner subSpinner = new AppCompatSpinner(categoriesSpinners.getContext(), Spinner.MODE_DROPDOWN); + 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 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); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java index 728a642b..d5d8f593 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java @@ -103,7 +103,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo @Override public void onClick(View view) { if (sessionManager.isLoggedIn()) { - //TODO PM + //TODO create topic } else { new AlertDialog.Builder(BoardActivity.this) .setMessage("You need to be logged in to create a new topic!") diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java index 93d92f1a..836efc31 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java @@ -1,5 +1,6 @@ package gr.thmmy.mthmmy.activities.downloads; +import android.content.Intent; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; @@ -7,6 +8,8 @@ import android.support.design.widget.FloatingActionButton; import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.widget.ProgressBar; import android.widget.Toast; @@ -19,6 +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.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.model.Download; @@ -31,6 +35,8 @@ import okhttp3.Request; import okhttp3.Response; import timber.log.Timber; +import static gr.thmmy.mthmmy.activities.UploadActivity.BUNDLE_UPLOAD_CATEGORY; + public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.OnLoadMoreListener { /** * The key to use when putting download's url String to {@link DownloadsActivity}'s Bundle. @@ -68,7 +74,7 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter. if (downloadsUrl != null && !Objects.equals(downloadsUrl, "")) { ThmmyPage.PageCategory target = ThmmyPage.resolvePageCategory(Uri.parse(downloadsUrl)); if (!target.is(ThmmyPage.PageCategory.DOWNLOADS)) { - Timber.e("Bundle came with a non downloads url!\nUrl:\n%s" , downloadsUrl); + Timber.e("Bundle came with a non downloads url!\nUrl:\n%s", downloadsUrl); Toast.makeText(this, "An error has occurred\nAborting.", Toast.LENGTH_SHORT).show(); finish(); } @@ -122,6 +128,30 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter. parseDownloadPageTask.execute(downloadsUrl); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflates the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.downloads_menu, menu); + super.onCreateOptionsMenu(menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle presses on the action bar items + switch (item.getItemId()) { + 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);*/ + startActivity(intent); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + @Override public void onLoadMore() { if (pagesLoaded < numberOfPages) { @@ -165,7 +195,7 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter. * data. {@link ParseTask#postExecution(ResultCode) postExecution} method calls {@link RecyclerView#swapAdapter} * to build graphics. *

- *

Calling TopicTask's {@link ParseTask#execute execute} method needs to have profile's url + *

Calling TopicTask's {@link ParseTask#execute execute} method needs to have download's page url * as String parameter!

*/ private class ParseDownloadPageTask extends ParseTask { @@ -180,13 +210,14 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter. @Override protected void parse(Document downloadPage) throws ParseException { - try{ + try { if (downloadsTitle == null || Objects.equals(downloadsTitle, "")) downloadsTitle = downloadPage.select("div.nav>b>a.nav").last().text(); //Removes loading item if (isLoadingMore) { - if (parsedDownloads.size() > 0) parsedDownloads.remove(parsedDownloads.size() - 1); + if (parsedDownloads.size() > 0) + parsedDownloads.remove(parsedDownloads.size() - 1); } if (ThmmyPage.resolvePageCategory(Uri.parse(url)).is(ThmmyPage.PageCategory.DOWNLOADS_CATEGORY)) @@ -231,15 +262,15 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter. } } else { download = new Download(type, - rows.select("b>a").first().attr("href"), - rows.select("b>a").first().text(), - rows.select("div.smalltext:not(:has(a))").text(), - rows.select("span:not(:has(a))").first().text(), - false, - rows.select("span:has(a)").first().text()); + rows.select("b>a").first().attr("href"), + rows.select("b>a").first().text(), + rows.select("div.smalltext:not(:has(a))").text(), + rows.select("span:not(:has(a))").first().text(), + false, + rows.select("span:has(a)").first().text()); parsedDownloads.add(download); } - }catch(Exception e){ + } catch (Exception e) { throw new ParseException("Parsing failed (DownloadsActivity)"); } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index 94694bd0..27002423 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -43,6 +43,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.bookmarks.BookmarkActivity; import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity; import gr.thmmy.mthmmy.activities.main.MainActivity; @@ -145,14 +146,15 @@ public abstract class BaseActivity extends AppCompatActivity { //------------------------------------------DRAWER STUFF---------------------------------------- protected static final int HOME_ID = 0; protected static final int DOWNLOADS_ID = 1; - protected static final int BOOKMARKS_ID = 2; - protected static final int LOG_ID = 3; - protected static final int ABOUT_ID = 4; - protected static final int SETTINGS_ID = 5; + protected static final int UPLOAD_ID = 2; + protected static final int BOOKMARKS_ID = 3; + protected static final int LOG_ID = 4; + protected static final int ABOUT_ID = 5; + protected static final int SETTINGS_ID = 6; private AccountHeader accountHeader; private ProfileDrawerItem profileDrawerItem; - private PrimaryDrawerItem downloadsItem, loginLogoutItem; + private PrimaryDrawerItem downloadsItem, uploadItem, loginLogoutItem; private IconicsDrawable loginIcon, logoutIcon; /** @@ -164,7 +166,7 @@ public abstract class BaseActivity extends AppCompatActivity { final int selectedSecondaryColor = ContextCompat.getColor(this, R.color.accent); PrimaryDrawerItem homeItem, bookmarksItem, settingsItem, aboutItem; - IconicsDrawable homeIcon, homeIconSelected, downloadsIcon, downloadsIconSelected, settingsIcon, + IconicsDrawable homeIcon, homeIconSelected, downloadsIcon, downloadsIconSelected, uploadIcon, uploadIconSelected, settingsIcon, settingsIconSelected, bookmarksIcon, bookmarksIconSelected, aboutIcon, aboutIconSelected; //Drawer Icons @@ -189,7 +191,15 @@ public abstract class BaseActivity extends AppCompatActivity { .color(primaryColor); downloadsIconSelected = new IconicsDrawable(this) - .icon(GoogleMaterial.Icon.gmd_settings) + .icon(GoogleMaterial.Icon.gmd_file_download) + .color(selectedSecondaryColor); + + uploadIcon = new IconicsDrawable(this) + .icon(GoogleMaterial.Icon.gmd_file_upload) + .color(primaryColor); + + uploadIconSelected = new IconicsDrawable(this) + .icon(GoogleMaterial.Icon.gmd_file_upload) .color(selectedSecondaryColor); settingsIcon = new IconicsDrawable(this) @@ -244,6 +254,14 @@ public abstract class BaseActivity extends AppCompatActivity { .withName(R.string.downloads) .withIcon(downloadsIcon) .withSelectedIcon(downloadsIconSelected); + uploadItem = new PrimaryDrawerItem() + .withTextColor(primaryColor) + .withSelectedColor(selectedPrimaryColor) + .withSelectedTextColor(selectedSecondaryColor) + .withIdentifier(UPLOAD_ID) + .withName(R.string.upload) + .withIcon(uploadIcon) + .withSelectedIcon(uploadIconSelected); } else loginLogoutItem = new PrimaryDrawerItem() .withTextColor(primaryColor) @@ -324,22 +342,27 @@ public abstract class BaseActivity extends AppCompatActivity { public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { if (drawerItem.equals(HOME_ID)) { if (!(BaseActivity.this instanceof MainActivity)) { - Intent i = new Intent(BaseActivity.this, MainActivity.class); - startActivity(i); + Intent intent = new Intent(BaseActivity.this, MainActivity.class); + startActivity(intent); } } else if (drawerItem.equals(DOWNLOADS_ID)) { if (!(BaseActivity.this instanceof DownloadsActivity)) { - Intent i = new Intent(BaseActivity.this, DownloadsActivity.class); + Intent intent = new Intent(BaseActivity.this, DownloadsActivity.class); Bundle extras = new Bundle(); extras.putString(BUNDLE_DOWNLOADS_URL, ""); extras.putString(BUNDLE_DOWNLOADS_TITLE, null); - i.putExtras(extras); - startActivity(i); + intent.putExtras(extras); + startActivity(intent); + } + } else if (drawerItem.equals(UPLOAD_ID)) { + if (!(BaseActivity.this instanceof UploadActivity)) { + Intent intent = new Intent(BaseActivity.this, UploadActivity.class); + startActivity(intent); } } else if (drawerItem.equals(BOOKMARKS_ID)) { if (!(BaseActivity.this instanceof BookmarkActivity)) { - Intent i = new Intent(BaseActivity.this, BookmarkActivity.class); - startActivity(i); + Intent intent = new Intent(BaseActivity.this, BookmarkActivity.class); + startActivity(intent); } } else if (drawerItem.equals(LOG_ID)) { if (!sessionManager.isLoggedIn()) //When logged out or if user is guest @@ -352,8 +375,8 @@ public abstract class BaseActivity extends AppCompatActivity { new LogoutTask().execute(); } else if (drawerItem.equals(ABOUT_ID)) { if (!(BaseActivity.this instanceof AboutActivity)) { - Intent i = new Intent(BaseActivity.this, AboutActivity.class); - startActivity(i); + Intent intent = new Intent(BaseActivity.this, AboutActivity.class); + startActivity(intent); } } else if (drawerItem.equals(SETTINGS_ID)) { if (!(BaseActivity.this instanceof SettingsActivity)) { @@ -368,7 +391,7 @@ public abstract class BaseActivity extends AppCompatActivity { }); if (sessionManager.isLoggedIn()) - drawerBuilder.addDrawerItems(homeItem, bookmarksItem, downloadsItem, settingsItem, loginLogoutItem, aboutItem); + drawerBuilder.addDrawerItems(homeItem, bookmarksItem, downloadsItem, uploadItem, settingsItem, loginLogoutItem, aboutItem); else drawerBuilder.addDrawerItems(homeItem, bookmarksItem, settingsItem, loginLogoutItem, aboutItem); @@ -391,13 +414,17 @@ public abstract class BaseActivity extends AppCompatActivity { if (!sessionManager.isLoggedIn()) //When logged out or if user is guest { drawer.removeItem(DOWNLOADS_ID); + drawer.removeItem(UPLOAD_ID); loginLogoutItem.withName(R.string.login).withIcon(loginIcon); //Swap logout with login profileDrawerItem.withName(sessionManager.getUsername()); setDefaultAvatar(); } else { - if (!drawer.getDrawerItems().contains(downloadsItem)){ + if (!drawer.getDrawerItems().contains(downloadsItem)) { drawer.addItemAtPosition(downloadsItem, 2); } + if (!drawer.getDrawerItems().contains(uploadItem)) { + drawer.addItemAtPosition(uploadItem, 3); + } loginLogoutItem.withName(R.string.logout).withIcon(logoutIcon); //Swap login with logout profileDrawerItem.withName(sessionManager.getUsername()); if (sessionManager.hasAvatar()) diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java index 35318579..95a1ab1d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -19,6 +19,9 @@ import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader; import com.mikepenz.materialdrawer.util.DrawerImageLoader; import com.squareup.picasso.Picasso; +import net.gotev.uploadservice.UploadService; +import net.gotev.uploadservice.okhttp.OkHttpStack; + import java.io.IOException; import java.util.Objects; import java.util.concurrent.TimeUnit; @@ -94,6 +97,10 @@ public class BaseApplication extends Application { Picasso.setSingletonInstance(picasso); //All following Picasso (with Picasso.with(Context context) requests will use this Picasso object + //Sets up upload service + UploadService.NAMESPACE = BuildConfig.APPLICATION_ID; + UploadService.HTTP_STACK = new OkHttpStack(client); + //Initialize and create the image loader logic DrawerImageLoader.init(new AbstractDrawerImageLoader() { @Override diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/UploadCategory.java b/app/src/main/java/gr/thmmy/mthmmy/model/UploadCategory.java new file mode 100644 index 00000000..311446d3 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/model/UploadCategory.java @@ -0,0 +1,37 @@ +package gr.thmmy.mthmmy.model; + +import java.util.ArrayList; + +public class UploadCategory { + private String value, categoryTitle; + private ArrayList subCategories = new ArrayList<>(); + + private UploadCategory() { + //Disables default constructor + } + + public UploadCategory(String value, String categoryTitle) { + this.value = value; + this.categoryTitle = categoryTitle; + } + + public String getValue() { + return value; + } + + public String getCategoryTitle() { + return categoryTitle; + } + + public void addSubCategory(String value, String categoryTitle) { + subCategories.add(new UploadCategory(value, categoryTitle)); + } + + public ArrayList getSubCategories() { + return subCategories; + } + + public boolean hasSubCategories() { + return !subCategories.isEmpty(); + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/ic_file_upload.png b/app/src/main/res/drawable-hdpi/ic_file_upload.png new file mode 100644 index 0000000000000000000000000000000000000000..4cdd48825c39e3f7543c75304d0bf6ae33cc7055 GIT binary patch literal 175 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k1|%Oc%$NbB$~;{hLn>~)y?&6B!H|Q+!P|4? zw5qukGAjRFVwLZ3{VtQ!(nwRAtHknG)Fdsc!R~~yabB}nTByX-PEW_w{hbBq0tQc4KbLh*2~7a9LpY=W literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-hdpi/ic_insert_drive_file.png b/app/src/main/res/drawable-hdpi/ic_insert_drive_file.png new file mode 100644 index 0000000000000000000000000000000000000000..6459c3571cc0d94a242b7c396205035b84436e83 GIT binary patch literal 183 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k1|%Oc%$NbB>O5T>Ln>~)y%EUOpdirlaBsqu ziFh=Gau_cWjoJr!qx>5 z3g%s$MGJ2%$O_>P5M3p{LgK1$NXseN_y>LpjVw}pER8He9zd4Ri^vOpM_l+bJabjf geCg(29lnckddaDZsG`5oK$kFhy85}Sb4q9e0NFM}&;S4c literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_file_upload.png b/app/src/main/res/drawable-mdpi/ic_file_upload.png new file mode 100644 index 0000000000000000000000000000000000000000..3e9f35e93f686acc950d3b7c09625c37ecb55c11 GIT binary patch literal 139 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjL7py-Ar-fhfBgS%&#Y^BxMTAI z#;(jH#uEt=84I?to@kq#!nw0eIG0nkO*oZvX`Aqt7OA$!TU%~;9AjNEt;DfT m@1t2U1{FFIYbU=JY6i- z6J?Nfuwd&0QP#Ho3foTAxGsCRuX)j>FVdQ&MBb@0Hr}U A^8f$< literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_file_upload.png b/app/src/main/res/drawable-xhdpi/ic_file_upload.png new file mode 100644 index 0000000000000000000000000000000000000000..a592393e0e54a463ac07d826212514e159c4acb4 GIT binary patch literal 196 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpUtZci7-kcwMxZ+LSZP~c&>D06rA za*?Ql&FVdQ&MBb@02Zo6pa1{> literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_insert_drive_file.png b/app/src/main/res/drawable-xhdpi/ic_insert_drive_file.png new file mode 100644 index 0000000000000000000000000000000000000000..1f2e592d2579cf2c8f32d0b6f4c71772651f06e9 GIT binary patch literal 249 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpUt1D-C9Ar-gY-gM+*GURD}IB(e_ z-RBNXi@pbyq^&&0we=-BZ2gV#PK2`J8^AAc-@YY*4 z_n`2G&1S|GjOPwDKkZQUE*DhT>Yx)@#lcwQ!s5`?!E{1kA_J$AR6y?w#(>rrtQ({* z3O|ruB=w<$rN*g*IfIEE=#Ykgj38&hK*QDs%@02U87~)y}pr`#gN1Gpl+@8 zceV0`#yyN@r^hi*R+zW-+TvOP21X_p4gm#+hO96Dn6@1J`JQ#lan05c(d9frsdI!p zt`@FSEk8|0sUY<^+8%ccE={z0v_z@&sHgL*p2%+Cv zY!5d*_?sf_KjAW`-iluK4;)Pk#Ik%6q9Z%g)P(;vhWkzIPg$kX`+c9{d}byG21b^E zr4G3#1UB*R{PE|h4&zrvcK!HsOaXT+tJjCGD_Jo0x_-FP1vi05OM0hVDiLFe%2Hlx zV$0GfmAhohvgHO7v?hrvn5uX?Xn9;~I5JU(sZ%MERmgc0k4jUDtcGTt&s^MK*;W{A) z>%$IU}W)haSW-r_4ejY-XjJAERL<~ z&QzW|IbHdT-PQvt7g7cHoU@$%RE>#&fsLVo5u{xL$b9hi-G7FbNA~5+CywU#8mQJq zw|IVxR`Th-&zG3=CyXQb@pi`M3=Ajimt0~;)&dqqQUGE)eErLyAGUb+>KXp$L25l+{an^LB{Ts5M=@Vu literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_insert_drive_file.png b/app/src/main/res/drawable-xxxhdpi/ic_insert_drive_file.png new file mode 100644 index 0000000000000000000000000000000000000000..1156337394957ee2a73e958fe518487bc5ba7628 GIT binary patch literal 475 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7Ro>U|i(s;uunK>+M}%FJ?!9hKp}R z)+;eyx~O7Ghu! zU|?Wka1ds+klZa*Emy7mHvI%sfkm0|x7bH#4N4onevz#~xN(^(#VZqnK$~IQN5$H-;BKy+6*U z#F!)SPROQAZ0odm>4eKS-*;P{D&1ykXF7eq{+-IVwL3#@_TFM(VQ2sbZ9~mphWK^9 U)!DyQcY!SSboFyt=akR{0PmHVSO5S3 literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/activity_upload.xml b/app/src/main/res/layout/activity_upload.xml new file mode 100644 index 00000000..d334e423 --- /dev/null +++ b/app/src/main/res/layout/activity_upload.xml @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/downloads_menu.xml b/app/src/main/res/menu/downloads_menu.xml new file mode 100644 index 00000000..a644bb54 --- /dev/null +++ b/app/src/main/res/menu/downloads_menu.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d5028149..996f7d90 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -6,6 +6,7 @@ Authenticating… Logout Downloads + Upload Settings About Home @@ -102,6 +103,18 @@ Open Download + + Upload + + + Select the correct category for the file + Fill in the title and description\nor + build them automatically + Title + Description + Select file to upload + Upload + Settings Settings