Browse Source

Uploads improvements, Minor fixes

pull/30/merge
Apostolos Fanakis 7 years ago
parent
commit
553b8a7d4c
  1. 2
      app/src/main/AndroidManifest.xml
  2. 224
      app/src/main/java/gr/thmmy/mthmmy/activities/UploadActivity.java
  3. 11
      app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java
  4. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  5. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java
  6. 15
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java
  7. 7
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  8. 13
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  9. 21
      app/src/main/res/layout/activity_upload.xml
  10. 1
      app/src/main/res/values-v21/styles.xml
  11. 2
      app/src/main/res/values/colors.xml
  12. 16
      app/src/main/res/values/strings.xml
  13. 18
      app/src/main/res/values/styles.xml
  14. 12
      app/src/main/res/xml/app_preferences.xml

2
app/src/main/AndroidManifest.xml

@ -136,7 +136,7 @@
android:name=".services.NotificationService" android:name=".services.NotificationService"
android:exported="false"> android:exported="false">
<intent-filter> <intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/> <action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter> </intent-filter>
</service> </service>
</application> </application>

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

@ -1,18 +1,25 @@
package gr.thmmy.mthmmy.activities; package gr.thmmy.mthmmy.activities;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.AppCompatSpinner; import android.provider.MediaStore;
import android.util.Log; import android.provider.OpenableColumns;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.AppCompatButton;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Spinner; import android.widget.Toast;
import net.gotev.uploadservice.MultipartUploadRequest; import net.gotev.uploadservice.MultipartUploadRequest;
import net.gotev.uploadservice.UploadNotificationConfig; import net.gotev.uploadservice.UploadNotificationConfig;
@ -21,8 +28,8 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseActivity;
@ -34,20 +41,25 @@ import gr.thmmy.mthmmy.utils.parsing.ParseTask;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import timber.log.Timber; import timber.log.Timber;
import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.UPLOADING_APP_SIGNATURE_ENABLE_KEY;
public class UploadActivity extends BaseActivity { public class UploadActivity extends BaseActivity {
/** /**
* The key to use when putting upload's category String to {@link UploadActivity}'s Bundle. * The key to use when putting upload's category String to {@link UploadActivity}'s Bundle.
*/ */
public static final String BUNDLE_UPLOAD_CATEGORY = "UPLOAD_CATEGORY"; 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 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_CHOOSE_FILE = 8;
private static final int REQUEST_CODE_CAMERA = 4;
private static ArrayList<UploadCategory> uploadRootCategories = new ArrayList<>(); private static ArrayList<UploadCategory> uploadRootCategories = new ArrayList<>();
//private String currentUploadCategory = "";
private ParseUploadPageTask parseUploadPageTask; private ParseUploadPageTask parseUploadPageTask;
private ArrayList<String> bundleCategory;
private String categorySelected = "-1"; private String categorySelected = "-1";
private String uploaderProfileIndex = "1"; private String uploaderProfileIndex = "1";
private Uri fileUri; private Uri fileUri;
private String fileIcon;
//UI elements //UI elements
private MaterialProgressBar progressBar; private MaterialProgressBar progressBar;
@ -55,6 +67,8 @@ public class UploadActivity extends BaseActivity {
private AppCompatSpinnerWithoutDefault rootCategorySpinner; private AppCompatSpinnerWithoutDefault rootCategorySpinner;
private EditText uploadTitle; private EditText uploadTitle;
private EditText uploadDescription; private EditText uploadDescription;
private AppCompatButton titleDescriptionBuilderButton;
private AppCompatButton selectFileButton;
//private static AppCompatButton titleDescriptionBuilderButton; //private static AppCompatButton titleDescriptionBuilderButton;
@Override @Override
@ -62,13 +76,22 @@ public class UploadActivity extends BaseActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload); setContentView(R.layout.activity_upload);
/*Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
if (extras != null) { if (extras != null) {
//TODO auto fill category from bundle String tmpUploadCategoryNav = extras.getString(BUNDLE_UPLOAD_CATEGORY);
currentUploadCategory = extras.getString(BUNDLE_UPLOAD_CATEGORY); //something like "THMMY.gr > Downloads > Βασικός Κύκλος > 3ο εξάμηνο > Ηλεκτρικά Κυκλώματα ΙΙ"
if (currentUploadCategory != null && !Objects.equals(currentUploadCategory, "")) { 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 //Initialize toolbar
toolbar = findViewById(R.id.toolbar); toolbar = findViewById(R.id.toolbar);
@ -89,21 +112,37 @@ public class UploadActivity extends BaseActivity {
rootCategorySpinner = findViewById(R.id.upload_spinner_category_root); rootCategorySpinner = findViewById(R.id.upload_spinner_category_root);
rootCategorySpinner.setOnItemSelectedListener(new CustomOnItemSelectedListener(uploadRootCategories)); rootCategorySpinner.setOnItemSelectedListener(new CustomOnItemSelectedListener(uploadRootCategories));
/*titleDescriptionBuilderButton = findViewById(R.id.upload_title_description_builder); titleDescriptionBuilderButton = findViewById(R.id.upload_title_description_builder);
titleDescriptionBuilderButton.setEnabled(false);
titleDescriptionBuilderButton.setOnClickListener(new View.OnClickListener() { titleDescriptionBuilderButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View view) {
//TODO some dialog? if (categorySelected.equals("-1")) {
Toast.makeText(view.getContext(), "Please choose category first", Toast.LENGTH_SHORT).show();
return;
} }
});*/ //TODO else
}
});
titleDescriptionBuilderButton.setEnabled(false);
uploadTitle = findViewById(R.id.upload_title); uploadTitle = findViewById(R.id.upload_title);
uploadDescription = findViewById(R.id.upload_description); uploadDescription = findViewById(R.id.upload_description);
findViewById(R.id.upload_select_file_button).setOnClickListener(new View.OnClickListener() { selectFileButton = findViewById(R.id.upload_select_file_button);
selectFileButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { 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", String[] mimeTypes = {"image/jpeg", "text/html", "image/png", "image/jpg", "image/gif",
"application/pdf", "application/rar", "application/x-tar", "application/zip", "application/pdf", "application/rar", "application/x-tar", "application/zip",
"application/msword", "image/vnd.djvu", "application/gz", "application/tar.gz"}; "application/msword", "image/vnd.djvu", "application/gz", "application/tar.gz"};
@ -114,39 +153,50 @@ public class UploadActivity extends BaseActivity {
.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes); .putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
startActivityForResult(intent, REQUEST_CODE_CHOOSE_FILE); 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() { findViewById(R.id.upload_upload_button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View view) {
String uploadTitleText = uploadTitle.getText().toString(); String uploadTitleText = uploadTitle.getText().toString();
String uploadDescriptionText = uploadDescription.getText().toString(); String uploadDescriptionText = uploadDescription.getText().toString();
if (uploadTitleText.equals("")) { if (uploadTitleText.equals("")) {
uploadTitle.setError("Required"); uploadTitle.setError("Required");
} }
if (uploadDescriptionText.equals("")) { if (fileUri == null) {
uploadDescription.setError("Required"); selectFileButton.setError("Required");
}
if (categorySelected.equals("-1")) {
Toast.makeText(view.getContext(), "Please choose category first", Toast.LENGTH_SHORT).show();
} }
/*if (categorySelected.equals("-1")){
//TODO set error
//rootCategorySpinner
}*/
if (categorySelected.equals("-1") || uploadTitleText.equals("") || if (categorySelected.equals("-1") || uploadTitleText.equals("") || fileUri == null) {
fileUri == null || uploadDescriptionText.equals("")) {
return; return;
} }
String tmpDescriptionText = uploadDescriptionText;
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(view.getContext());
if (sharedPrefs.getBoolean(UPLOADING_APP_SIGNATURE_ENABLE_KEY, true)) {
tmpDescriptionText += uploadedFrommThmmyPromptHtml;
}
try { try {
String uploadId = new MultipartUploadRequest(v.getContext(), uploadIndexUrl) new MultipartUploadRequest(view.getContext(), uploadIndexUrl)
.setUtf8Charset() .setUtf8Charset()
.addParameter("tp-dluploadtitle", uploadTitleText) .addParameter("tp-dluploadtitle", uploadTitleText)
.addParameter("tp-dluploadcat", categorySelected) .addParameter("tp-dluploadcat", categorySelected)
.addParameter("tp-dluploadtext", uploadDescriptionText) .addParameter("tp-dluploadtext", tmpDescriptionText)
.addFileToUpload(fileUri.toString(), "tp-dluploadfile") .addFileToUpload(fileUri.toString(), "tp-dluploadfile")
.addParameter("tp_dluploadicon", "blank.gif") //TODO auto-select this .addParameter("tp_dluploadicon", fileIcon)
.addParameter("tp-uploaduser", uploaderProfileIndex) .addParameter("tp-uploaduser", uploaderProfileIndex)
.setNotificationConfig(new UploadNotificationConfig()) .setNotificationConfig(new UploadNotificationConfig())
.setMaxRetries(2).startUpload(); .setMaxRetries(2).startUpload();
@ -156,7 +206,6 @@ public class UploadActivity extends BaseActivity {
} }
}); });
if (uploadRootCategories.isEmpty()) { if (uploadRootCategories.isEmpty()) {
parseUploadPageTask = new ParseUploadPageTask(); parseUploadPageTask = new ParseUploadPageTask();
parseUploadPageTask.execute(uploadIndexUrl); parseUploadPageTask.execute(uploadIndexUrl);
@ -166,11 +215,28 @@ public class UploadActivity extends BaseActivity {
tmpSpinnerArray[i] = uploadRootCategories.get(i).getCategoryTitle(); tmpSpinnerArray[i] = uploadRootCategories.get(i).getCategoryTitle();
} }
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>( ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(BaseApplication.getInstance().getApplicationContext(),
BaseApplication.getInstance().getApplicationContext(),
android.R.layout.simple_spinner_dropdown_item, tmpSpinnerArray); android.R.layout.simple_spinner_dropdown_item, tmpSpinnerArray);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
rootCategorySpinner.setAdapter(spinnerArrayAdapter); 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);
} }
} }
@ -199,19 +265,65 @@ public class UploadActivity extends BaseActivity {
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_CHOOSE_FILE && data != null) { 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(); 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) {
//TODO
} else { } else {
super.onActivityResult(requestCode, resultCode, data); 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;
}
private class CustomOnItemSelectedListener implements AdapterView.OnItemSelectedListener { private class CustomOnItemSelectedListener implements AdapterView.OnItemSelectedListener {
private ArrayList<UploadCategory> parentCategories, childCategories; private ArrayList<UploadCategory> parentCategories, childCategories;
// Suppresses default constructor
@SuppressWarnings("unused")
private CustomOnItemSelectedListener() { private CustomOnItemSelectedListener() {
//Disable default constructor
} }
CustomOnItemSelectedListener(ArrayList<UploadCategory> parentCategories) { CustomOnItemSelectedListener(ArrayList<UploadCategory> parentCategories) {
@ -220,7 +332,7 @@ public class UploadActivity extends BaseActivity {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//Removes old, unneeded sub categories spinner(s) //Removes old, unneeded sub-category spinner(s)
int viewIndex = categoriesSpinners.indexOfChild((AppCompatSpinnerWithoutDefault) view.getParent()); int viewIndex = categoriesSpinners.indexOfChild((AppCompatSpinnerWithoutDefault) view.getParent());
if (viewIndex + 1 != categoriesSpinners.getChildCount()) { //Makes sure this is not the last child if (viewIndex + 1 != categoriesSpinners.getChildCount()) { //Makes sure this is not the last child
@ -229,7 +341,7 @@ public class UploadActivity extends BaseActivity {
categorySelected = parentCategories.get(position).getValue(); categorySelected = parentCategories.get(position).getValue();
//Adds new sub categories spinner //Adds new sub-category spinner
if (parentCategories.get(position).hasSubCategories()) { if (parentCategories.get(position).hasSubCategories()) {
childCategories = parentCategories.get(position).getSubCategories(); childCategories = parentCategories.get(position).getSubCategories();
@ -243,12 +355,27 @@ public class UploadActivity extends BaseActivity {
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
AppCompatSpinnerWithoutDefault subSpinner = new AppCompatSpinnerWithoutDefault(categoriesSpinners.getContext()); AppCompatSpinnerWithoutDefault subSpinner = new AppCompatSpinnerWithoutDefault(categoriesSpinners.getContext());
subSpinner.setPromptId(R.string.upload_spinners_prompt); subSpinner.setPromptId(R.string.upload_spinners_hint);
subSpinner.setPopupBackgroundResource(R.color.primary); subSpinner.setPopupBackgroundResource(R.color.primary);
subSpinner.setAdapter(spinnerArrayAdapter); subSpinner.setAdapter(spinnerArrayAdapter);
subSpinner.setOnItemSelectedListener(new CustomOnItemSelectedListener(childCategories)); subSpinner.setOnItemSelectedListener(new CustomOnItemSelectedListener(childCategories));
categoriesSpinners.addView(subSpinner); 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);
}
}
} }
} }
@ -320,13 +447,28 @@ public class UploadActivity extends BaseActivity {
tmpSpinnerArray[i] = uploadRootCategories.get(i).getCategoryTitle(); tmpSpinnerArray[i] = uploadRootCategories.get(i).getCategoryTitle();
} }
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>( ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(BaseApplication.getInstance().getApplicationContext(),
BaseApplication.getInstance().getApplicationContext(),
android.R.layout.simple_spinner_dropdown_item, tmpSpinnerArray); android.R.layout.simple_spinner_dropdown_item, tmpSpinnerArray);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
rootCategorySpinner.setAdapter(spinnerArrayAdapter); rootCategorySpinner.setAdapter(spinnerArrayAdapter);
//titleDescriptionBuilderButton.setEnabled(true);
//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); progressBar.setVisibility(ProgressBar.GONE);
} }
} }

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

@ -8,6 +8,7 @@ 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.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -48,6 +49,7 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.
public static final String BUNDLE_DOWNLOADS_TITLE = "DOWNLOADS_TITLE"; 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 static final String downloadsIndexUrl = "https://www.thmmy.gr/smf/index.php?action=tpmod;dl;";
private String downloadsUrl; private String downloadsUrl;
private String downloadsNav;
private String downloadsTitle; private String downloadsTitle;
private final ArrayList<Download> parsedDownloads = new ArrayList<>(); private final ArrayList<Download> parsedDownloads = new ArrayList<>();
@ -143,8 +145,8 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.
case R.id.menu_upload: case R.id.menu_upload:
Intent intent = new Intent(DownloadsActivity.this, UploadActivity.class); Intent intent = new Intent(DownloadsActivity.this, UploadActivity.class);
Bundle extras = new Bundle(); Bundle extras = new Bundle();
/*extras.putString(BUNDLE_UPLOAD_CATEGORY, ""); extras.putString(BUNDLE_UPLOAD_CATEGORY, downloadsNav);
intent.putExtras(extras);*/ intent.putExtras(extras);
startActivity(intent); startActivity(intent);
return true; return true;
default: default:
@ -211,8 +213,11 @@ 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 {
Element downloadsNavElement = downloadPage.select("div.nav").first();
downloadsNav = downloadsNavElement.text();
if (downloadsTitle == null || Objects.equals(downloadsTitle, "")) 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 //Removes loading item
if (isLoadingMore) { if (isLoadingMore) {

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); tabLayout.setupWithViewPager(viewPager);
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); 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); setMainActivity(this);
} }

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 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_LED_KEY = "pref_notification_led_enable_key";
public static final String NOTIFICATION_VIBRATION_KEY = "pref_notification_vibration_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 @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -42,6 +43,8 @@ public class SettingsActivity extends BaseActivity {
protected void onResume() { protected void onResume() {
drawer.setSelection(SETTINGS_ID); drawer.setSelection(SETTINGS_ID);
super.onResume(); 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"; public static final String ARG_IS_LOGGED_IN = "selectedRingtoneKey";
//Preferences xml keys //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 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 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 //SharedPreferences keys
private static final int REQUEST_CODE_ALERT_RINGTONE = 2; 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_CATEGORY).setVisible(isLoggedIn);
findPreference(POSTING_APP_SIGNATURE_ENABLE).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")) { if (!isLoggedIn && defaultHomeTabEntries.contains("Unread")) {
defaultHomeTabEntries.remove("Unread"); defaultHomeTabEntries.remove("Unread");
defaultHomeTabValues.remove("2"); defaultHomeTabValues.remove("2");
@ -148,6 +153,12 @@ public class SettingsFragment extends PreferenceFragmentCompat {
public void updateUserLoginState(boolean isLoggedIn) { public void updateUserLoginState(boolean isLoggedIn) {
this.isLoggedIn = 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")) { if (!isLoggedIn && defaultHomeTabEntries.contains("Unread")) {
defaultHomeTabEntries.remove("Unread"); defaultHomeTabEntries.remove("Unread");
defaultHomeTabValues.remove("2"); defaultHomeTabValues.remove("2");

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

@ -222,7 +222,7 @@ public class TopicActivity extends BaseActivity {
if (sessionManager.isLoggedIn()) { if (sessionManager.isLoggedIn()) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
includeAppSignaturePreference = sharedPrefs.getBoolean(SettingsActivity.APP_SIGNATURE_ENABLE_KEY, true); includeAppSignaturePreference = sharedPrefs.getBoolean(SettingsActivity.POSTING_APP_SIGNATURE_ENABLE_KEY, true);
} }
thisPageBookmark = new Bookmark(topicTitle, ThmmyPage.getTopicId(topicPageUrl), true); thisPageBookmark = new Bookmark(topicTitle, ThmmyPage.getTopicId(topicPageUrl), true);
@ -316,7 +316,7 @@ public class TopicActivity extends BaseActivity {
topicMenuBookmarkClick(); topicMenuBookmarkClick();
return true; return true;
case R.id.menu_info: 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(); LayoutInflater inflater = this.getLayoutInflater();
LinearLayout infoDialog = (LinearLayout) inflater.inflate(R.layout.dialog_topic_info LinearLayout infoDialog = (LinearLayout) inflater.inflate(R.layout.dialog_topic_info
, null); , null);
@ -368,7 +368,7 @@ public class TopicActivity extends BaseActivity {
if (sessionManager.isLoggedIn()) { if (sessionManager.isLoggedIn()) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
includeAppSignaturePreference = sharedPrefs.getBoolean(SettingsActivity.APP_SIGNATURE_ENABLE_KEY, true); includeAppSignaturePreference = sharedPrefs.getBoolean(SettingsActivity.POSTING_APP_SIGNATURE_ENABLE_KEY, true);
} }
} }
@ -559,7 +559,6 @@ public class TopicActivity extends BaseActivity {
topicTask = new TopicTask(); topicTask = new TopicTask();
topicTask.execute(pagesUrls.get(pageRequested)); //Attempt data parsing topicTask.execute(pagesUrls.get(pageRequested)); //Attempt data parsing
} }
} }

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

@ -16,6 +16,7 @@ import android.support.design.widget.BottomSheetDialog;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider; import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -63,7 +64,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_THUMBNAIL_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_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.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.services.DownloadHelper.SAVE_DIR;
import static gr.thmmy.mthmmy.session.SessionManager.SUCCESS;
import static gr.thmmy.mthmmy.utils.FileUtils.getMimeType; import static gr.thmmy.mthmmy.utils.FileUtils.getMimeType;
public abstract class BaseActivity extends AppCompatActivity { public abstract class BaseActivity extends AppCompatActivity {
@ -469,6 +472,14 @@ public abstract class BaseActivity extends AppCompatActivity {
} }
protected void onPostExecute(Integer result) { 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(); updateDrawer();
if (mainActivity != null) if (mainActivity != null)
mainActivity.updateTabs(); mainActivity.updateTabs();
@ -645,7 +656,7 @@ public abstract class BaseActivity extends AppCompatActivity {
return true; 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 private void requestPerms() { //Runtime permissions request for devices with API >= 23
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
String[] PERMISSIONS_STORAGE = { String[] PERMISSIONS_STORAGE = {

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

@ -65,7 +65,7 @@
android:layout_marginBottom="6dp" android:layout_marginBottom="6dp"
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
android:popupBackground="@color/primary" android:popupBackground="@color/primary"
android:prompt="@string/upload_spinners_prompt" /> android:prompt="@string/upload_spinners_hint" />
</LinearLayout> </LinearLayout>
<TextView <TextView
@ -117,33 +117,26 @@
android:maxLines="3" /> android:maxLines="3" />
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
<TextView <android.support.v7.widget.AppCompatButton
android:id="@+id/upload_select_file_button" android:id="@+id/upload_select_file_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"
android:drawablePadding="5dp" android:drawablePadding="5dp"
android:drawableStart="@drawable/ic_insert_drive_file" android:drawableStart="@drawable/ic_insert_drive_file"
android:gravity="center_vertical" android:gravity="center_vertical"
android:text="@string/upload_select_file" android:text="@string/upload_select_file"
android:textAlignment="center"
android:textColor="@color/primary_text" /> 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.support.v7.widget.AppCompatButton
android:id="@+id/upload_upload_button" android:id="@+id/upload_upload_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_gravity="center"
android:text="@string/upload_upload_button" /> android:gravity="center_vertical"
</FrameLayout> android:text="@string/upload_upload_button"
android:textAlignment="center"
android:textColor="@color/accent" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

1
app/src/main/res/values-v21/styles.xml

@ -17,7 +17,6 @@
<item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item> <item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
<item name="android:windowContentTransitions">true</item> <item name="android:windowContentTransitions">true</item>
<item name="popupMenuStyle">@style/PopupMenuStyle</item>
</style> </style>
<style name="AppTheme.NoActionBar"> <style name="AppTheme.NoActionBar">

2
app/src/main/res/values/colors.xml

@ -16,12 +16,12 @@
<color name="background">#323232</color> <color name="background">#323232</color>
<color name="card_background">#3C3F41</color> <color name="card_background">#3C3F41</color>
<color name="divider">#8B8B8B</color> <color name="divider">#8B8B8B</color>
<!--<color name="link_color">#FFC107</color>-->
<color name="link_color">#FF9800</color> <color name="link_color">#FF9800</color>
<color name="white">#FFFFFF</color> <color name="white">#FFFFFF</color>
<color name="iron">#CCCCCC</color> <color name="iron">#CCCCCC</color>
<color name="card_expand_text_color">#E7E7E7</color> <color name="card_expand_text_color">#E7E7E7</color>
<color name="dialog_bg_semi_transparent">#D926A69A</color> <color name="dialog_bg_semi_transparent">#D926A69A</color>
<color name="dialog_bg_semi_transparent_dark">#D92B2B2B</color>
<color name="member_of_the_month">#E91E63</color> <color name="member_of_the_month">#E91E63</color>
</resources> </resources>

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

@ -114,14 +114,22 @@
<string name="upload_description_hint">Description</string> <string name="upload_description_hint">Description</string>
<string name="upload_select_file">Select file to upload</string> <string name="upload_select_file">Select file to upload</string>
<string name="upload_upload_button">Upload</string> <string name="upload_upload_button">Upload</string>
<string name="upload_spinners_prompt">Select one</string> <string name="upload_spinners_hint">Select a category</string>
<!--Upload Dialog-->
<string name="dialog_upload_radio_buttons_title">Select type of upload</string>
<string name="dialog_upload_radio_button_exams">Exam subjects</string>
<string name="dialog_upload_radio_button_exam_solutions">Exam solutions</string>
<string name="dialog_upload_radio_button_notes">Course notes</string>
<string name="dialog_upload_select_lesson_title">Select the course</string>
<string name="dialog_upload_select_semester">Select the semester</string>
<!--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>
<string name="pref_category_app">App</string> <string name="pref_category_app">App</string>
<string name="pref_title_app_main_default_tab">Home default tab</string> <string name="pref_title_app_main_default_tab">Default home tab</string>
<string name="pref_summary_app_main_default_tab">Select your preferred, home screen, default tab</string> <string name="pref_summary_app_main_default_tab">Select your preferred, home screen, default tab</string>
<string name="pref_app_main_default_tab_dialog_title">Default home tab</string> <string name="pref_app_main_default_tab_dialog_title">Default home tab</string>
@ -137,4 +145,8 @@
<string name="pref_category_posting">Posting</string> <string name="pref_category_posting">Posting</string>
<string name="pref_title_posting_app_signature_enable">App signature</string> <string name="pref_title_posting_app_signature_enable">App signature</string>
<string name="pref_summary_posting_app_signature_enable">If enabled, a \"sent from mTHMMY\" message will be inserted at the end of your posts</string> <string name="pref_summary_posting_app_signature_enable">If enabled, a \"sent from mTHMMY\" message will be inserted at the end of your posts</string>
<string name="pref_category_uploading">Uploading</string>
<string name="pref_title_uploading_app_signature_enable">App signature</string>
<string name="pref_summary_uploading_app_signature_enable">If enabled, an \"uploaded from mTHMMY\" message will be inserted at the end of your uploads descriptions</string>
</resources> </resources>

18
app/src/main/res/values/styles.xml

@ -2,7 +2,6 @@
<!-- Dark application theme. --> <!-- Dark application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/primary</item> <item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item> <item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item> <item name="colorAccent">@color/accent</item>
@ -17,9 +16,9 @@
<item name="android:textColorHint">@color/iron</item> <item name="android:textColorHint">@color/iron</item>
<item name="colorButtonNormal">@color/primary</item> <item name="colorButtonNormal">@color/primary</item>
<item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
<item name="popupMenuStyle">@style/PopupMenuStyle</item> <!--Default alert dialog theme-->
<item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
</style> </style>
<style name="AppTheme.NoActionBar"> <style name="AppTheme.NoActionBar">
@ -46,7 +45,18 @@
<item name="android:background">@color/primary</item> <item name="android:background">@color/primary</item>
</style> </style>
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> <style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Dialog">
<item name="android:windowTitleStyle">@style/AppCompatAlertDialogStyleTitle</item>
<item name="colorAccent">@color/accent</item>
<item name="android:textColorPrimary">@color/primary_text</item>
<item name="android:colorBackground">@color/dialog_bg_semi_transparent_dark</item>
</style>
<style name="AppCompatAlertDialogStyleTitle" parent="@android:style/TextAppearance.DialogWindowTitle">
<item name="android:textColor">@color/accent</item>
</style>
<style name="AppCompatAlertDialogStyleAccent" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/iron</item> <item name="colorAccent">@color/iron</item>
<item name="android:textColorPrimary">@color/primary_text</item> <item name="android:textColorPrimary">@color/primary_text</item>
<item name="android:colorBackground">@color/dialog_bg_semi_transparent</item> <item name="android:colorBackground">@color/dialog_bg_semi_transparent</item>

12
app/src/main/res/xml/app_preferences.xml

@ -52,4 +52,16 @@
</android.support.v7.preference.PreferenceCategory> </android.support.v7.preference.PreferenceCategory>
<android.support.v7.preference.PreferenceCategory
android:key="pref_category_uploading_key"
android:title="@string/pref_category_uploading">
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="pref_uploading_app_signature_enable_key"
android:summary="@string/pref_summary_uploading_app_signature_enable"
android:title="@string/pref_title_uploading_app_signature_enable" />
</android.support.v7.preference.PreferenceCategory>
</android.support.v7.preference.PreferenceScreen> </android.support.v7.preference.PreferenceScreen>
Loading…
Cancel
Save