Added Marks module. Closes #190

This commit is contained in:
Juan Miguel Boyero Corral 2015-08-28 21:46:53 +02:00
parent 7c7cef6072
commit a1013f1de3
12 changed files with 341 additions and 21 deletions

View File

@ -259,6 +259,21 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="es.ugr.swad.swadroid.SWADMain" />
</activity>
<activity
android:name="es.ugr.swad.swadroid.modules.marks.Marks"
android:configChanges="orientation|screenSize"
android:theme="@style/Theme.AppCompat.Light"
android:label="@string/marksModuleLabel"
android:parentActivityName="es.ugr.swad.swadroid.SWADMain" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="es.ugr.swad.swadroid.SWADMain" />
</activity>
<activity
android:name="es.ugr.swad.swadroid.modules.marks.GetMarks"
android:label="@string/marksModuleLabel"
android:theme="@style/Theme.AppCompat.Translucent" >
</activity>
<activity
android:name="es.ugr.swad.swadroid.modules.notifications.NotificationsMarkAllAsRead"
android:label="@string/notificationsMarkAllAsReadModuleLabel"

View File

@ -208,6 +208,14 @@ public class Constants {
* Request code for recover Password
*/
public static final int RECOVER_PASSWORD_REQUEST_CODE = 36;
/**
* Request code for get marks
*/
public static final int GETMARKS_REQUEST_CODE = 37;
/**
* Request code for show marks
*/
public static final int MARKS_REQUEST_CODE = 38;
/**
* Prefix tag name for Logcat
*/
@ -228,6 +236,10 @@ public class Constants {
* Code to access to the documents in share area
*/
public static final int SHARE_AREA_CODE = 2;
/**
* Code to access to the marks area
*/
public static final int MARKS_AREA_CODE = 3;
/**
* Group position inside the main menu for Course group
*/

View File

@ -583,6 +583,11 @@ public class SWADMain extends MenuExpandableListActivity {
map.put(NAME, getString(R.string.testsModuleLabel));
map.put(IMAGE, getResources().getDrawable(R.drawable.test));
evaluationData.add(map);
//Marks
map = new HashMap<String, Object>();
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());

View File

@ -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);

View File

@ -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();
}

View File

@ -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;
}
}
}

View File

@ -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());

View File

@ -0,0 +1,156 @@
/*
* This file is part of SWADroid.
*
* Copyright (C) 2010 Juan Miguel Boyero Corral <juanmi1982@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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 <juanmi1982@gmail.com>
*/
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;
}
}

View File

@ -0,0 +1,68 @@
/**
* Information module for get courses's information
*
* @author Jose Antonio Guerrero Aviles <cany20@gmail.com>
*/
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 <juanmi1982@gmail.com>
*/
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("<![CDATA[")) {
content = content.substring(9, content.length() - 3);
}
webview = WebViewFactory.getMathJaxWebView(webview);
webview.setWebViewClient(WebViewFactory.getMathJaxExpression(content));
}
}

View File

@ -0,0 +1,7 @@
<html>
<head>
</head>
<body>
Marks package.
</body>
</html>

View File

@ -294,5 +294,9 @@
<string name="updatePendingEventsMsg">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?</string>
<string name="follower">Nuevo seguidor</string>
<string name="messageSentMsg">Mensaje enviado</string>
<string name="marksModuleLabel">Calificaciones</string>
<string name="marksProgressTitle">Calificaciones</string>
<string name="marksProgressDescription">Obteniendo calificaciones…\nPor favor, espere…</string>
<string name="errorBadFileCodeMsg">Usted no puede consultar calificaciones en este fichero</string>
</resources>

View File

@ -303,5 +303,9 @@
<string name="functionHoneycombMsg">This function requires Android 3.0 (Honeycomb) or higher</string>
<string name="updatePendingEventsMsg">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?</string>
<string name="follower">New follower</string>
<string name="marksModuleLabel">Marks</string>
<string name="marksProgressTitle">Marks</string>
<string name="marksProgressDescription">Getting marks…\nWait, please…</string>
<string name="errorBadFileCodeMsg">You can not get marks from this file</string>
</resources>