Browse Source

Init uploads, minor fixes

pull/27/head
Apostolos Fanakis 7 years ago
parent
commit
d216964acb
  1. 2
      app/build.gradle
  2. 8
      app/src/main/AndroidManifest.xml
  3. 319
      app/src/main/java/gr/thmmy/mthmmy/activities/UploadActivity.java
  4. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  5. 53
      app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java
  6. 63
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  7. 7
      app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java
  8. 37
      app/src/main/java/gr/thmmy/mthmmy/model/UploadCategory.java
  9. BIN
      app/src/main/res/drawable-hdpi/ic_file_upload.png
  10. BIN
      app/src/main/res/drawable-hdpi/ic_insert_drive_file.png
  11. BIN
      app/src/main/res/drawable-mdpi/ic_file_upload.png
  12. BIN
      app/src/main/res/drawable-mdpi/ic_insert_drive_file.png
  13. BIN
      app/src/main/res/drawable-xhdpi/ic_file_upload.png
  14. BIN
      app/src/main/res/drawable-xhdpi/ic_insert_drive_file.png
  15. BIN
      app/src/main/res/drawable-xxhdpi/ic_file_upload.png
  16. BIN
      app/src/main/res/drawable-xxhdpi/ic_insert_drive_file.png
  17. BIN
      app/src/main/res/drawable-xxxhdpi/ic_file_upload.png
  18. BIN
      app/src/main/res/drawable-xxxhdpi/ic_insert_drive_file.png
  19. 163
      app/src/main/res/layout/activity_upload.xml
  20. 10
      app/src/main/res/menu/downloads_menu.xml
  21. 13
      app/src/main/res/values/strings.xml

2
app/build.gradle

@ -54,6 +54,8 @@ dependencies {
implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'//TODO: deprecated! implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'//TODO: deprecated!
implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2' implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2'
implementation 'com.jakewharton.timber:timber:4.7.0' 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' apply plugin: 'com.google.gms.google-services'

8
app/src/main/AndroidManifest.xml

@ -97,6 +97,14 @@
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.main.MainActivity" /> android:value=".activities.main.MainActivity" />
</activity> </activity>
<activity
android:name=".activities.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 <activity
android:name=".activities.bookmarks.BookmarkActivity" android:name=".activities.bookmarks.BookmarkActivity"
android:parentActivityName=".activities.main.MainActivity" android:parentActivityName=".activities.main.MainActivity"

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

@ -0,0 +1,319 @@
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.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.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 = "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<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 boolean initialized = false;
private CustomOnItemSelectedListener() {
//Disable default constructor
}
CustomOnItemSelectedListener(ArrayList<UploadCategory> 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<String> 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<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);
}
}
}

2
app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java

@ -103,7 +103,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (sessionManager.isLoggedIn()) { if (sessionManager.isLoggedIn()) {
//TODO PM //TODO create topic
} else { } else {
new AlertDialog.Builder(BoardActivity.this) new AlertDialog.Builder(BoardActivity.this)
.setMessage("You need to be logged in to create a new topic!") .setMessage("You need to be logged in to create a new topic!")

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

@ -1,5 +1,6 @@
package gr.thmmy.mthmmy.activities.downloads; package gr.thmmy.mthmmy.activities.downloads;
import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; 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.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Toast; import android.widget.Toast;
@ -19,6 +22,7 @@ import java.util.ArrayList;
import java.util.Objects; import java.util.Objects;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.UploadActivity;
import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.model.Download; import gr.thmmy.mthmmy.model.Download;
@ -31,6 +35,8 @@ import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import timber.log.Timber; import timber.log.Timber;
import static gr.thmmy.mthmmy.activities.UploadActivity.BUNDLE_UPLOAD_CATEGORY;
public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.OnLoadMoreListener { public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.OnLoadMoreListener {
/** /**
* The key to use when putting download's url String to {@link DownloadsActivity}'s Bundle. * 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, "")) { if (downloadsUrl != null && !Objects.equals(downloadsUrl, "")) {
ThmmyPage.PageCategory target = ThmmyPage.resolvePageCategory(Uri.parse(downloadsUrl)); ThmmyPage.PageCategory target = ThmmyPage.resolvePageCategory(Uri.parse(downloadsUrl));
if (!target.is(ThmmyPage.PageCategory.DOWNLOADS)) { 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(); Toast.makeText(this, "An error has occurred\nAborting.", Toast.LENGTH_SHORT).show();
finish(); finish();
} }
@ -122,6 +128,30 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.
parseDownloadPageTask.execute(downloadsUrl); 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 @Override
public void onLoadMore() { public void onLoadMore() {
if (pagesLoaded < numberOfPages) { 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} * data. {@link ParseTask#postExecution(ResultCode) postExecution} method calls {@link RecyclerView#swapAdapter}
* to build graphics. * to build graphics.
* <p> * <p>
* <p>Calling TopicTask's {@link ParseTask#execute execute} method needs to have profile's url * <p>Calling TopicTask's {@link ParseTask#execute execute} method needs to have download's page url
* as String parameter!</p> * as String parameter!</p>
*/ */
private class ParseDownloadPageTask extends ParseTask { private class ParseDownloadPageTask extends ParseTask {
@ -180,13 +210,14 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.
@Override @Override
protected void parse(Document downloadPage) throws ParseException { protected void parse(Document downloadPage) throws ParseException {
try{ try {
if (downloadsTitle == null || Objects.equals(downloadsTitle, "")) if (downloadsTitle == null || Objects.equals(downloadsTitle, ""))
downloadsTitle = downloadPage.select("div.nav>b>a.nav").last().text(); downloadsTitle = downloadPage.select("div.nav>b>a.nav").last().text();
//Removes loading item //Removes loading item
if (isLoadingMore) { 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)) if (ThmmyPage.resolvePageCategory(Uri.parse(url)).is(ThmmyPage.PageCategory.DOWNLOADS_CATEGORY))
@ -231,15 +262,15 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.
} }
} else { } else {
download = new Download(type, download = new Download(type,
rows.select("b>a").first().attr("href"), rows.select("b>a").first().attr("href"),
rows.select("b>a").first().text(), rows.select("b>a").first().text(),
rows.select("div.smalltext:not(:has(a))").text(), rows.select("div.smalltext:not(:has(a))").text(),
rows.select("span:not(:has(a))").first().text(), rows.select("span:not(:has(a))").first().text(),
false, false,
rows.select("span:has(a)").first().text()); rows.select("span:has(a)").first().text());
parsedDownloads.add(download); parsedDownloads.add(download);
} }
}catch(Exception e){ } catch (Exception e) {
throw new ParseException("Parsing failed (DownloadsActivity)"); throw new ParseException("Parsing failed (DownloadsActivity)");
} }
} }

63
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.R;
import gr.thmmy.mthmmy.activities.AboutActivity; import gr.thmmy.mthmmy.activities.AboutActivity;
import gr.thmmy.mthmmy.activities.LoginActivity; import gr.thmmy.mthmmy.activities.LoginActivity;
import gr.thmmy.mthmmy.activities.UploadActivity;
import gr.thmmy.mthmmy.activities.bookmarks.BookmarkActivity; import gr.thmmy.mthmmy.activities.bookmarks.BookmarkActivity;
import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity; import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity;
import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.activities.main.MainActivity;
@ -145,14 +146,15 @@ public abstract class BaseActivity extends AppCompatActivity {
//------------------------------------------DRAWER STUFF---------------------------------------- //------------------------------------------DRAWER STUFF----------------------------------------
protected static final int HOME_ID = 0; protected static final int HOME_ID = 0;
protected static final int DOWNLOADS_ID = 1; protected static final int DOWNLOADS_ID = 1;
protected static final int BOOKMARKS_ID = 2; protected static final int UPLOAD_ID = 2;
protected static final int LOG_ID = 3; protected static final int BOOKMARKS_ID = 3;
protected static final int ABOUT_ID = 4; protected static final int LOG_ID = 4;
protected static final int SETTINGS_ID = 5; protected static final int ABOUT_ID = 5;
protected static final int SETTINGS_ID = 6;
private AccountHeader accountHeader; private AccountHeader accountHeader;
private ProfileDrawerItem profileDrawerItem; private ProfileDrawerItem profileDrawerItem;
private PrimaryDrawerItem downloadsItem, loginLogoutItem; private PrimaryDrawerItem downloadsItem, uploadItem, loginLogoutItem;
private IconicsDrawable loginIcon, logoutIcon; private IconicsDrawable loginIcon, logoutIcon;
/** /**
@ -164,7 +166,7 @@ public abstract class BaseActivity extends AppCompatActivity {
final int selectedSecondaryColor = ContextCompat.getColor(this, R.color.accent); final int selectedSecondaryColor = ContextCompat.getColor(this, R.color.accent);
PrimaryDrawerItem homeItem, bookmarksItem, settingsItem, aboutItem; PrimaryDrawerItem homeItem, bookmarksItem, settingsItem, aboutItem;
IconicsDrawable homeIcon, homeIconSelected, downloadsIcon, downloadsIconSelected, settingsIcon, IconicsDrawable homeIcon, homeIconSelected, downloadsIcon, downloadsIconSelected, uploadIcon, uploadIconSelected, settingsIcon,
settingsIconSelected, bookmarksIcon, bookmarksIconSelected, aboutIcon, aboutIconSelected; settingsIconSelected, bookmarksIcon, bookmarksIconSelected, aboutIcon, aboutIconSelected;
//Drawer Icons //Drawer Icons
@ -189,7 +191,15 @@ public abstract class BaseActivity extends AppCompatActivity {
.color(primaryColor); .color(primaryColor);
downloadsIconSelected = new IconicsDrawable(this) 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); .color(selectedSecondaryColor);
settingsIcon = new IconicsDrawable(this) settingsIcon = new IconicsDrawable(this)
@ -244,6 +254,14 @@ public abstract class BaseActivity extends AppCompatActivity {
.withName(R.string.downloads) .withName(R.string.downloads)
.withIcon(downloadsIcon) .withIcon(downloadsIcon)
.withSelectedIcon(downloadsIconSelected); .withSelectedIcon(downloadsIconSelected);
uploadItem = new PrimaryDrawerItem()
.withTextColor(primaryColor)
.withSelectedColor(selectedPrimaryColor)
.withSelectedTextColor(selectedSecondaryColor)
.withIdentifier(UPLOAD_ID)
.withName(R.string.upload)
.withIcon(uploadIcon)
.withSelectedIcon(uploadIconSelected);
} else } else
loginLogoutItem = new PrimaryDrawerItem() loginLogoutItem = new PrimaryDrawerItem()
.withTextColor(primaryColor) .withTextColor(primaryColor)
@ -324,22 +342,27 @@ public abstract class BaseActivity extends AppCompatActivity {
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (drawerItem.equals(HOME_ID)) { if (drawerItem.equals(HOME_ID)) {
if (!(BaseActivity.this instanceof MainActivity)) { if (!(BaseActivity.this instanceof MainActivity)) {
Intent i = new Intent(BaseActivity.this, MainActivity.class); Intent intent = new Intent(BaseActivity.this, MainActivity.class);
startActivity(i); startActivity(intent);
} }
} else if (drawerItem.equals(DOWNLOADS_ID)) { } else if (drawerItem.equals(DOWNLOADS_ID)) {
if (!(BaseActivity.this instanceof DownloadsActivity)) { 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(); Bundle extras = new Bundle();
extras.putString(BUNDLE_DOWNLOADS_URL, ""); extras.putString(BUNDLE_DOWNLOADS_URL, "");
extras.putString(BUNDLE_DOWNLOADS_TITLE, null); extras.putString(BUNDLE_DOWNLOADS_TITLE, null);
i.putExtras(extras); intent.putExtras(extras);
startActivity(i); 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)) { } else if (drawerItem.equals(BOOKMARKS_ID)) {
if (!(BaseActivity.this instanceof BookmarkActivity)) { if (!(BaseActivity.this instanceof BookmarkActivity)) {
Intent i = new Intent(BaseActivity.this, BookmarkActivity.class); Intent intent = new Intent(BaseActivity.this, BookmarkActivity.class);
startActivity(i); startActivity(intent);
} }
} else if (drawerItem.equals(LOG_ID)) { } else if (drawerItem.equals(LOG_ID)) {
if (!sessionManager.isLoggedIn()) //When logged out or if user is guest if (!sessionManager.isLoggedIn()) //When logged out or if user is guest
@ -352,8 +375,8 @@ public abstract class BaseActivity extends AppCompatActivity {
new LogoutTask().execute(); new LogoutTask().execute();
} else if (drawerItem.equals(ABOUT_ID)) { } else if (drawerItem.equals(ABOUT_ID)) {
if (!(BaseActivity.this instanceof AboutActivity)) { if (!(BaseActivity.this instanceof AboutActivity)) {
Intent i = new Intent(BaseActivity.this, AboutActivity.class); Intent intent = new Intent(BaseActivity.this, AboutActivity.class);
startActivity(i); startActivity(intent);
} }
} else if (drawerItem.equals(SETTINGS_ID)) { } else if (drawerItem.equals(SETTINGS_ID)) {
if (!(BaseActivity.this instanceof SettingsActivity)) { if (!(BaseActivity.this instanceof SettingsActivity)) {
@ -368,7 +391,7 @@ public abstract class BaseActivity extends AppCompatActivity {
}); });
if (sessionManager.isLoggedIn()) if (sessionManager.isLoggedIn())
drawerBuilder.addDrawerItems(homeItem, bookmarksItem, downloadsItem, settingsItem, loginLogoutItem, aboutItem); drawerBuilder.addDrawerItems(homeItem, bookmarksItem, downloadsItem, uploadItem, settingsItem, loginLogoutItem, aboutItem);
else else
drawerBuilder.addDrawerItems(homeItem, bookmarksItem, settingsItem, loginLogoutItem, aboutItem); 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 if (!sessionManager.isLoggedIn()) //When logged out or if user is guest
{ {
drawer.removeItem(DOWNLOADS_ID); drawer.removeItem(DOWNLOADS_ID);
drawer.removeItem(UPLOAD_ID);
loginLogoutItem.withName(R.string.login).withIcon(loginIcon); //Swap logout with login loginLogoutItem.withName(R.string.login).withIcon(loginIcon); //Swap logout with login
profileDrawerItem.withName(sessionManager.getUsername()); profileDrawerItem.withName(sessionManager.getUsername());
setDefaultAvatar(); setDefaultAvatar();
} else { } else {
if (!drawer.getDrawerItems().contains(downloadsItem)){ if (!drawer.getDrawerItems().contains(downloadsItem)) {
drawer.addItemAtPosition(downloadsItem, 2); drawer.addItemAtPosition(downloadsItem, 2);
} }
if (!drawer.getDrawerItems().contains(uploadItem)) {
drawer.addItemAtPosition(uploadItem, 3);
}
loginLogoutItem.withName(R.string.logout).withIcon(logoutIcon); //Swap login with logout loginLogoutItem.withName(R.string.logout).withIcon(logoutIcon); //Swap login with logout
profileDrawerItem.withName(sessionManager.getUsername()); profileDrawerItem.withName(sessionManager.getUsername());
if (sessionManager.hasAvatar()) if (sessionManager.hasAvatar())

7
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.mikepenz.materialdrawer.util.DrawerImageLoader;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import net.gotev.uploadservice.UploadService;
import net.gotev.uploadservice.okhttp.OkHttpStack;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; 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 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 //Initialize and create the image loader logic
DrawerImageLoader.init(new AbstractDrawerImageLoader() { DrawerImageLoader.init(new AbstractDrawerImageLoader() {
@Override @Override

37
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<UploadCategory> 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<UploadCategory> getSubCategories() {
return subCategories;
}
public boolean hasSubCategories() {
return !subCategories.isEmpty();
}
}

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 475 B

163
app/src/main/res/layout/activity_upload.xml

@ -0,0 +1,163 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activities.UploadActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/ToolbarTheme">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ToolbarTheme" />
</android.support.design.widget.AppBarLayout>
<ScrollView
android:id="@+id/upload_outer_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top|start"
android:background="@color/background"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="gr.thmmy.mthmmy.activities.UploadActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:focusableInTouchMode="true"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"
android:gravity="center"
android:text="@string/upload_category_pre_text"
android:textAlignment="center"
android:textColor="@color/accent" />
<LinearLayout
android:id="@+id/upload_spinners"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:orientation="vertical">
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/upload_spinner_category_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"
android:popupBackground="@color/primary" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:gravity="center"
android:text="@string/upload_title_description_pre_text"
android:textAlignment="center"
android:textColor="@color/accent" />
<android.support.v7.widget.AppCompatButton
android:id="@+id/upload_title_description_builder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:gravity="center"
android:text="@string/upload_title_description_builder"
android:textAlignment="center"
android:textColor="@color/accent" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp">
<EditText
android:id="@+id/upload_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/upload_title_hint"
android:inputType="text"
android:maxLength="500" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp">
<EditText
android:id="@+id/upload_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/upload_description_hint"
android:inputType="textMultiLine"
android:maxLines="3" />
</android.support.design.widget.TextInputLayout>
<TextView
android:id="@+id/upload_select_file_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"
android:drawablePadding="5dp"
android:drawableStart="@drawable/ic_insert_drive_file"
android:gravity="center_vertical"
android:text="@string/upload_select_file"
android:textAlignment="center"
android:textColor="@color/primary_text" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="bottom|end"
android:layout_weight="4">
<android.support.v7.widget.AppCompatButton
android:id="@+id/upload_upload_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:text="@string/upload_upload_button" />
</FrameLayout>
</LinearLayout>
</ScrollView>
<me.zhanghai.android.materialprogressbar.MaterialProgressBar
android:id="@+id/progressBar"
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal.NoPadding"
android:layout_width="match_parent"
android:layout_height="@dimen/progress_bar_height"
android:indeterminate="true"
android:visibility="invisible"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|center"
app:mpb_indeterminateTint="@color/accent"
app:mpb_progressStyle="horizontal" />
</android.support.design.widget.CoordinatorLayout>

10
app/src/main/res/menu/downloads_menu.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_upload"
android:icon="@drawable/ic_file_upload"
app:showAsAction="ifRoom"
android:title="@string/upload_button">
</item>
</menu>

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

@ -6,6 +6,7 @@
<string name="login_spinner">Authenticating&#8230;</string> <string name="login_spinner">Authenticating&#8230;</string>
<string name="logout">Logout</string> <string name="logout">Logout</string>
<string name="downloads">Downloads</string> <string name="downloads">Downloads</string>
<string name="upload">Upload</string>
<string name="settings">Settings</string> <string name="settings">Settings</string>
<string name="about">About</string> <string name="about">About</string>
<string name="home">Home</string> <string name="home">Home</string>
@ -102,6 +103,18 @@
<string name="open">Open</string> <string name="open">Open</string>
<string name="download">Download</string> <string name="download">Download</string>
<!--Downloads Activity-->
<string name="upload_button">Upload</string>
<!--Upload Activity-->
<string name="upload_category_pre_text">Select the correct category for the file</string>
<string name="upload_title_description_pre_text">Fill in the title and description\nor</string>
<string name="upload_title_description_builder">build them automatically</string>
<string name="upload_title_hint">Title</string>
<string name="upload_description_hint">Description</string>
<string name="upload_select_file">Select file to upload</string>
<string name="upload_upload_button">Upload</string>
<!--Settings Activity--> <!--Settings Activity-->
<string name="action_settings">Settings</string> <string name="action_settings">Settings</string>
<string name="title_activity_settings">Settings</string> <string name="title_activity_settings">Settings</string>

Loading…
Cancel
Save