diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 588ea8f4..ab0733f5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -259,6 +259,21 @@ android:name="android.support.PARENT_ACTIVITY" android:value="es.ugr.swad.swadroid.SWADMain" /> + + + + + (); + map.put(NAME, getString(R.string.marksModuleLabel)); + map.put(IMAGE, getResources().getDrawable(R.drawable.grades)); + evaluationData.add(map); //Users category //Groups @@ -761,6 +766,14 @@ public class SWADMain extends MenuExpandableListActivity { } else { Toast.makeText(ctx, R.string.functionHoneycombMsg, Toast.LENGTH_LONG).show(); } + } else if (keyword.equals(getString(R.string.marksModuleLabel))) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + activity = new Intent(ctx, DownloadsManager.class); + activity.putExtra("downloadsAreaCode", Constants.MARKS_AREA_CODE); + startActivityForResult(activity, Constants.DOWNLOADSMANAGER_REQUEST_CODE); + } else { + Toast.makeText(ctx, R.string.functionHoneycombMsg, Toast.LENGTH_LONG).show(); + } } else if (keyword.equals(getString(R.string.myGroupsModuleLabel))) { activity = new Intent(ctx, MyGroupsManager.class); activity.putExtra("courseCode", Courses.getSelectedCourseCode()); diff --git a/app/src/main/java/es/ugr/swad/swadroid/gui/WebViewFactory.java b/app/src/main/java/es/ugr/swad/swadroid/gui/WebViewFactory.java index 6eb88ae2..13d48ce8 100644 --- a/app/src/main/java/es/ugr/swad/swadroid/gui/WebViewFactory.java +++ b/app/src/main/java/es/ugr/swad/swadroid/gui/WebViewFactory.java @@ -31,6 +31,7 @@ import android.webkit.WebViewClient; public class WebViewFactory { public static WebView getMathJaxWebView(WebView view) { WebSettings settings = view.getSettings(); + settings.setDefaultTextEncodingName("utf-8"); settings.setJavaScriptEnabled(true); settings.setBuiltInZoomControls(true); diff --git a/app/src/main/java/es/ugr/swad/swadroid/modules/Module.java b/app/src/main/java/es/ugr/swad/swadroid/modules/Module.java index 9ea144f4..6ccafeac 100644 --- a/app/src/main/java/es/ugr/swad/swadroid/modules/Module.java +++ b/app/src/main/java/es/ugr/swad/swadroid/modules/Module.java @@ -402,6 +402,11 @@ public abstract class Module extends MenuActivity { Preferences.setUserPassword(""); } else if (es.faultstring.equals("Unknown application key")) { errorMsg = getString(R.string.errorBadAppKeyMsg); + + //For Marks module + } else if (es.faultstring.equals("Bad file code")) { + errorMsg = getString(R.string.errorBadFileCodeMsg); + sendException = false; } else { errorMsg = "Server error: " + es.getMessage(); } diff --git a/app/src/main/java/es/ugr/swad/swadroid/modules/downloads/DownloadsManager.java b/app/src/main/java/es/ugr/swad/swadroid/modules/downloads/DownloadsManager.java index b1edd37b..97e49a42 100644 --- a/app/src/main/java/es/ugr/swad/swadroid/modules/downloads/DownloadsManager.java +++ b/app/src/main/java/es/ugr/swad/swadroid/modules/downloads/DownloadsManager.java @@ -58,6 +58,10 @@ import es.ugr.swad.swadroid.model.GroupType; import es.ugr.swad.swadroid.modules.Courses; import es.ugr.swad.swadroid.modules.GroupTypes; import es.ugr.swad.swadroid.modules.Groups; +import es.ugr.swad.swadroid.modules.Login; +import es.ugr.swad.swadroid.modules.marks.GetMarks; +import es.ugr.swad.swadroid.modules.marks.Marks; +import es.ugr.swad.swadroid.utils.Utils; /** * Activity to navigate through the directory tree of documents and to manage @@ -75,7 +79,8 @@ public class DownloadsManager extends MenuActivity { /** * Specifies whether to display the documents or the shared area of the - * subject 1 specifies documents area 2 specifies shared area + * subject 1 specifies documents area, 2 specifies shared area, + * 3 specifies marks area */ private int downloadsAreaCode = 0; /** @@ -165,6 +170,8 @@ public class DownloadsManager extends MenuActivity { } else { myGroups = getFilteredGroups(); this.loadGroupsSpinner(myGroups); + this.previousConnection = Utils.connectionAvailable(getApplicationContext()); + if (previousConnection) { setMainView(); } else { @@ -221,11 +228,19 @@ public class DownloadsManager extends MenuActivity { chosenNodeName = node.getName(); fileSize = node.getSize(); File f = new File(Constants.DOWNLOADS_PATH + File.separator + chosenNodeName); - if (isDownloaded(f)) { - viewFile(f); - } else { - AlertDialog fileInfoDialog = createFileInfoDialog(node.getName(), node.getSize(), node.getTime(), node.getPublisher(), node.getFileCode(), node.getLicense()); - fileInfoDialog.show(); + + //If a student is requesting the marks, gets the marks and call the Marks module + if((downloadsAreaCode == Constants.MARKS_AREA_CODE) + && (Login.getLoggedUser().getUserRole() == Constants.STUDENT_TYPE_CODE)) { + + requestGetMarks(node.getFileCode()); + } else { //Otherwise treat as a regular file + if (isDownloaded(f)) { + viewFile(f); + } else { + AlertDialog fileInfoDialog = createFileInfoDialog(node.getName(), node.getSize(), node.getTime(), node.getPublisher(), node.getFileCode(), node.getLicense()); + fileInfoDialog.show(); + } } } } @@ -312,6 +327,8 @@ public class DownloadsManager extends MenuActivity { protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { + Intent activity; + switch (requestCode) { // After get the list of courses, a dialog is launched to choice the // course @@ -351,6 +368,11 @@ public class DownloadsManager extends MenuActivity { dialog.show(); } break; + case Constants.GETMARKS_REQUEST_CODE: + activity = new Intent(this, Marks.class); + activity.putExtra("content", GetMarks.getMarks()); + startActivityForResult(activity, Constants.MARKS_REQUEST_CODE); + break; case Constants.GROUPS_REQUEST_CODE: groupsRequested = true; myGroups = getFilteredGroups(); //only groups where the user is enrolled. @@ -359,14 +381,13 @@ public class DownloadsManager extends MenuActivity { requestDirectoryTree(); break; case Constants.GROUPTYPES_REQUEST_CODE: - Intent activity = new Intent(this, Groups.class); + activity = new Intent(this, Groups.class); activity.putExtra("courseCode", Courses.getSelectedCourseCode()); startActivityForResult(activity, Constants.GROUPS_REQUEST_CODE); break; } } else { - setNoConnectionView(); if (refresh) { refresh = false; } @@ -604,10 +625,21 @@ public class DownloadsManager extends MenuActivity { Intent activity; activity = new Intent(this, GetFile.class); activity.putExtra("fileCode", fileCode); - //activity.putExtra("path", navigator.getPath() + fileName); startActivityForResult(activity, Constants.GETFILE_REQUEST_CODE); } + /** + * Method to request info file identified with @a fileCode to SWAD thought the web services GETMARKS + * + * @param fileCode file code + */ + private void requestGetMarks(long fileCode) { + Intent activity; + activity = new Intent(this, GetMarks.class); + activity.putExtra("fileCode", fileCode); + startActivityForResult(activity, Constants.GETMARKS_REQUEST_CODE); + } + /** * Method that shows information file and allows its download * It has a button to confirm the download. If It is confirmed getFile will be requested to get the link @@ -697,13 +729,20 @@ public class DownloadsManager extends MenuActivity { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } - - if(downloadsAreaCode == 1) { - setTitle(R.string.documentsDownloadModuleLabel); - getSupportActionBar().setIcon(R.drawable.folder); - } else { - setTitle(R.string.sharedsDownloadModuleLabel); - getSupportActionBar().setIcon(R.drawable.folder_users); - } + + switch (downloadsAreaCode) { + case 1: + setTitle(R.string.documentsDownloadModuleLabel); + getSupportActionBar().setIcon(R.drawable.folder); + break; + case 2: + setTitle(R.string.sharedsDownloadModuleLabel); + getSupportActionBar().setIcon(R.drawable.folder_users); + break; + case 3: + setTitle(R.string.marksModuleLabel); + getSupportActionBar().setIcon(R.drawable.grades); + break; + } } } diff --git a/app/src/main/java/es/ugr/swad/swadroid/modules/information/Information.java b/app/src/main/java/es/ugr/swad/swadroid/modules/information/Information.java index aae1a84c..f3787e72 100644 --- a/app/src/main/java/es/ugr/swad/swadroid/modules/information/Information.java +++ b/app/src/main/java/es/ugr/swad/swadroid/modules/information/Information.java @@ -8,7 +8,6 @@ package es.ugr.swad.swadroid.modules.information; import android.os.Build; import android.os.Bundle; -import android.webkit.WebSettings; import android.webkit.WebView; import org.ksoap2.serialization.SoapObject; @@ -55,9 +54,6 @@ public class Information extends Module { webview = (WebView) this.findViewById(R.id.info_webview_dialog); - WebSettings settings = webview.getSettings(); - settings.setDefaultTextEncodingName("utf-8"); - int requestCode = this.getIntent().getIntExtra("requestCode", 0); getSupportActionBar().setSubtitle(Courses.getSelectedCourseShortName()); diff --git a/app/src/main/java/es/ugr/swad/swadroid/modules/marks/GetMarks.java b/app/src/main/java/es/ugr/swad/swadroid/modules/marks/GetMarks.java new file mode 100644 index 00000000..9d845474 --- /dev/null +++ b/app/src/main/java/es/ugr/swad/swadroid/modules/marks/GetMarks.java @@ -0,0 +1,156 @@ +/* + * This file is part of SWADroid. + * + * Copyright (C) 2010 Juan Miguel Boyero Corral + * + * SWADroid is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SWADroid is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with SWADroid. If not, see . + */ +package es.ugr.swad.swadroid.modules.marks; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; + +import org.ksoap2.serialization.SoapObject; + +import es.ugr.swad.swadroid.Constants; +import es.ugr.swad.swadroid.R; +import es.ugr.swad.swadroid.SWADroidTracker; +import es.ugr.swad.swadroid.model.User; +import es.ugr.swad.swadroid.modules.Login; +import es.ugr.swad.swadroid.modules.Module; +import es.ugr.swad.swadroid.webservices.SOAPClient; + +/** + * Marks module for get user's marks + * + * @author Juan Miguel Boyero Corral + */ +public class GetMarks extends Module { + /** + * Marks tag name for Logcat + */ + private static final String TAG = Constants.APP_TAG + " Marks"; + + private static String marks; + private long fileCode; + + @Override + protected void runConnection() { + super.runConnection(); + if (!isConnected) { + setResult(RESULT_CANCELED); + finish(); + } + } + + /* (non-Javadoc) + * @see android.app.Activity#onCreate() + */ + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setMETHOD_NAME("getMarks"); + getSupportActionBar().hide(); + } + + /* (non-Javadoc) + * @see android.app.Activity#onStart() + */ + @Override + protected void onStart() { + super.onStart(); + + SWADroidTracker.sendScreenView(getApplicationContext(), TAG); + + fileCode = this.getIntent().getLongExtra("fileCode", 0); + runConnection(); + } + + /* (non-Javadoc) + * @see es.ugr.swad.swadroid.modules.Module#onActivityResult(int, int, android.content.Intent) + */ + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == Activity.RESULT_CANCELED) { + setResult(RESULT_CANCELED); + finish(); + } + } + + /* (non-Javadoc) + * @see es.ugr.swad.swadroid.modules.Module#connect() + */ + @Override + protected void connect() { + String progressDescription = getString(R.string.marksProgressDescription); + int progressTitle = R.string.marksProgressTitle; + + startConnection(true, progressDescription, progressTitle); + } + + /* (non-Javadoc) + * @see es.ugr.swad.swadroid.modules.Module#requestService() + */ + @Override + protected void requestService() + throws Exception { + + //Creates webservice request, adds required params and sends request to webservice + createRequest(SOAPClient.CLIENT_TYPE); + addParam("wsKey", Login.getLoggedUser().getWsKey()); + addParam("fileCode", fileCode); + sendRequest(User.class, true); + + if (result != null) { + //Stores courses data returned by webservice response + SoapObject soap = (SoapObject) result; + marks = soap.getProperty("content").toString(); + + Log.i(TAG, "Retrieved marks [user=" + Login.getLoggedUser().getUserNickname() + + ", fileCode=" + fileCode + "]"); + + //Request finalized without errors + setResult(RESULT_OK); + } else { + setResult(RESULT_CANCELED); + } + } + + /* (non-Javadoc) + * @see es.ugr.swad.swadroid.modules.Module#postConnect() + */ + @Override + protected void postConnect() { + finish(); + } + + /* (non-Javadoc) + * @see es.ugr.swad.swadroid.modules.Module#onError() + */ + @Override + protected void onError() { + + } + + /** + * Get user marks + * @return User marks + */ + public static String getMarks() { + return marks; + } +} diff --git a/app/src/main/java/es/ugr/swad/swadroid/modules/marks/Marks.java b/app/src/main/java/es/ugr/swad/swadroid/modules/marks/Marks.java new file mode 100644 index 00000000..25c5a9a1 --- /dev/null +++ b/app/src/main/java/es/ugr/swad/swadroid/modules/marks/Marks.java @@ -0,0 +1,68 @@ +/** + * Information module for get courses's information + * + * @author Jose Antonio Guerrero Aviles + */ + +package es.ugr.swad.swadroid.modules.marks; + +import android.os.Build; +import android.os.Bundle; +import android.webkit.WebView; + +import es.ugr.swad.swadroid.Constants; +import es.ugr.swad.swadroid.R; +import es.ugr.swad.swadroid.SWADroidTracker; +import es.ugr.swad.swadroid.gui.MenuActivity; +import es.ugr.swad.swadroid.gui.WebViewFactory; +import es.ugr.swad.swadroid.modules.Courses; +import es.ugr.swad.swadroid.utils.Utils; + +/** + * Marks module for show user's marks + * + * @author Juan Miguel Boyero Corral + */ +public class Marks extends MenuActivity { + + public static final String TAG = Constants.APP_TAG + " Marks"; + + /** + * Webview to show marks + */ + WebView webview; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.webview_information_screen_layout); + + webview = (WebView) this.findViewById(R.id.info_webview_dialog); + + getSupportActionBar().setSubtitle(Courses.getSelectedCourseShortName()); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + } + + setTitle(R.string.marksModuleLabel); + getSupportActionBar().setIcon(R.drawable.grades); + } + + @Override + protected void onStart() { + super.onStart(); + + SWADroidTracker.sendScreenView(getApplicationContext(), TAG); + + String content = this.getIntent().getStringExtra("content"); + + content = Utils.fixLinks(content); + if (content.startsWith(" + + + +Marks package. + + diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 3a75aba2..148029ed 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -294,5 +294,9 @@ Hay eventos con cambios pendientes de enviar al servidor. Si actualiza el listado de eventos puede perder los cambios que no haya enviado.\n\n¿Está seguro de que quiere actualizar el listado de eventos? Nuevo seguidor Mensaje enviado + Calificaciones + Calificaciones + Obteniendo calificaciones…\nPor favor, espere… + Usted no puede consultar calificaciones en este fichero \ 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 f67d5f52..b0e73cfd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -303,5 +303,9 @@ This function requires Android 3.0 (Honeycomb) or higher There are pending changes waiting to be sent to the server. If you update the list of events can lose the changes.\n\nAre you sure you want to update the list of events? New follower + Marks + Marks + Getting marks…\nWait, please… + You can not get marks from this file \ No newline at end of file