Adapted all Modules to work with a global actual course. It is

functional, however, initial states should be revised and better
defined. The appearance should be also improved.

git-svn-id: https://forja.rediris.es/svn/cusl6-swadroid/trunk@276 5bc14d19-1e4b-4ba2-aa50-860af135f48c
This commit is contained in:
Juan Miguel Boyero Corral 2012-04-13 14:44:53 +00:00
parent e6621d23b5
commit 9d58178baa
9 changed files with 191 additions and 299 deletions

View File

@ -5,11 +5,17 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/background"> android:background="@color/background">
<include layout="@layout/action_bar"/> <include layout="@layout/action_bar"/>
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/selectCourseTitle"
/>
<ExpandableListView <ExpandableListView
android:id="@+id/android:list" android:id="@+id/android:list"
android:cacheColorHint="@color/background" android:cacheColorHint="@color/background"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
</ExpandableListView> </ExpandableListView>
</LinearLayout> </LinearLayout>

View File

@ -27,7 +27,7 @@ public class Global {
/** /**
* SWAD application key * SWAD application key
*/ */
private static final String AppKey = ""; private static final String AppKey = "HTC-Desire";
/** /**
* Server URL * Server URL
*/ */
@ -40,6 +40,11 @@ public class Global {
* Time of application's last login * Time of application's last login
*/ */
private static long lastLoginTime; private static long lastLoginTime;
/**
* Code of the chosen course. All next actions are referred to this course.
*/
private static long selectedCourseCode = -1;
/** /**
* Time to force relogin * Time to force relogin
*/ */
@ -200,4 +205,18 @@ public class Global {
public static String parseBoolString(boolean b) { public static String parseBoolString(boolean b) {
return b ? "Y" : "N"; return b ? "Y" : "N";
} }
/**
* Gets code of actual course
* return -1 if no course chosen; code of actual course in other case
* */
public static long getSelectedCourseCode(){
return selectedCourseCode;
}
/**
* Sets code of actual course
* @param courseCode. Code of the chosen course. It should be courseCode>0. Otherwise nothing will change
* */
public static void setSelectedCourseCode(long actualCourseCode){
if(actualCourseCode >0) selectedCourseCode = actualCourseCode;
}
} }

View File

@ -19,19 +19,29 @@
package es.ugr.swad.swadroid; package es.ugr.swad.swadroid;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ExpandableListView; import android.widget.ExpandableListView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import es.ugr.swad.swadroid.model.Course;
import es.ugr.swad.swadroid.model.DataBaseHelper; import es.ugr.swad.swadroid.model.DataBaseHelper;
import es.ugr.swad.swadroid.model.Model;
import es.ugr.swad.swadroid.modules.Messages; import es.ugr.swad.swadroid.modules.Messages;
import es.ugr.swad.swadroid.modules.notifications.Notifications; import es.ugr.swad.swadroid.modules.notifications.Notifications;
import es.ugr.swad.swadroid.modules.tests.Tests; import es.ugr.swad.swadroid.modules.tests.Tests;
@ -55,6 +65,18 @@ public class SWADMain extends MenuExpandableListActivity {
* Function text field * Function text field
*/ */
final String IMAGE = "listIcon"; final String IMAGE = "listIcon";
/**
* Code of selected course
* */
long courseCode;
/**
* Cursor for database access
*/
private Cursor dbCursor;
/**
* User courses list
*/
private List<Model>listCourses;
/** /**
* Gets the database helper * Gets the database helper
@ -139,7 +161,7 @@ public class SWADMain extends MenuExpandableListActivity {
/** /**
* Create main menu with an expandable list * Create main menu with an expandable list
*/ */
private void createMainMenu() private void createTeacherMenu()
{ {
//Construct Expandable List //Construct Expandable List
final ArrayList<HashMap<String, Object>> headerData = new ArrayList<HashMap<String, Object>>(); final ArrayList<HashMap<String, Object>> headerData = new ArrayList<HashMap<String, Object>>();
@ -198,6 +220,63 @@ public class SWADMain extends MenuExpandableListActivity {
getExpandableListView().setOnChildClickListener(this); getExpandableListView().setOnChildClickListener(this);
} }
/**
* Create main menu with an expandable list
*/
private void createStudentMenu()
{
//Construct Expandable List
final ArrayList<HashMap<String, Object>> headerData = new ArrayList<HashMap<String, Object>>();
final HashMap<String, Object> messages = new HashMap<String, Object>();
messages.put(NAME, getString(R.string.messages));
messages.put(IMAGE, getResources().getDrawable(R.drawable.msg));
headerData.add( messages );
final HashMap<String, Object> evaluation = new HashMap<String, Object>();
evaluation.put(NAME, getString(R.string.evaluation));
evaluation.put(IMAGE, getResources().getDrawable(R.drawable.grades));
headerData.add( evaluation);
final ArrayList<ArrayList<HashMap<String, Object>>> childData = new ArrayList<ArrayList<HashMap<String, Object>>>();
final ArrayList<HashMap<String, Object>> messagesData = new ArrayList<HashMap<String, Object>>();
childData.add(messagesData);
final ArrayList<HashMap<String, Object>> evaluationData = new ArrayList<HashMap<String, Object>>();
childData.add(evaluationData);
//Messages category
HashMap<String, Object> map = new HashMap<String,Object>();
map.put(NAME, getString(R.string.notificationsModuleLabel) );
map.put(IMAGE, getResources().getDrawable(R.drawable.notif));
messagesData.add(map);
map = new HashMap<String,Object>();
map.put(NAME, getString(R.string.messagesModuleLabel) );
map.put(IMAGE, getResources().getDrawable(R.drawable.msg));
messagesData.add(map);
//Evaluation category
map = new HashMap<String,Object>();
map.put(NAME, getString(R.string.testsModuleLabel) );
map.put(IMAGE, getResources().getDrawable(R.drawable.test));
evaluationData.add(map);
setListAdapter( new ImageExpandableListAdapter(
this,
headerData,
R.layout.image_list_item,
new String[] { NAME }, // the name of the field data
new int[] { R.id.listText }, // the text field to populate with the field data
childData,
0,
null,
new int[] {}
));
getExpandableListView().setOnChildClickListener(this);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see android.app.Activity#onCreate() * @see android.app.Activity#onCreate()
@ -217,8 +296,22 @@ public class SWADMain extends MenuExpandableListActivity {
text = (TextView)this.findViewById(R.id.moduleName); text = (TextView)this.findViewById(R.id.moduleName);
text.setText(R.string.app_name); text.setText(R.string.app_name);
Spinner spinner = (Spinner) this.findViewById(R.id.spinner);
listCourses = dbHelper.getAllRows(Global.DB_TABLE_COURSES,"","name");
dbCursor = dbHelper.getDb().getCursor(Global.DB_TABLE_COURSES,"","name");
// if(dbCursor.getCount()==0)
SimpleCursorAdapter adapter = new SimpleCursorAdapter (this,
android.R.layout.simple_spinner_item,
dbCursor,
new String[]{"name"},
new int[]{android.R.id.text1},0);
createMainMenu(); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new onItemSelectedListener());
//createMainMenu();
try { try {
//Initialize database //Initialize database
@ -255,4 +348,25 @@ public class SWADMain extends MenuExpandableListActivity {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
private class onItemSelectedListener implements OnItemSelectedListener{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
Course courseSelected = (Course)listCourses.get(position);
courseCode = courseSelected.getId();
Global.setSelectedCourseCode(courseCode);
int userRole = courseSelected.getUserRole();
if(userRole == 3) createTeacherMenu();
if(userRole == 2) createStudentMenu();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
} }

View File

@ -110,14 +110,12 @@ public class Login extends Module {
md.update(prefs.getUserPassword().getBytes()); md.update(prefs.getUserPassword().getBytes());
userPassword = new String(Base64.encodeBytes(md.digest())); userPassword = new String(Base64.encodeBytes(md.digest()));
userPassword = userPassword.replace('+','-').replace('/','_').replace('=', ' ').replaceAll("\\s+", "").trim(); userPassword = userPassword.replace('+','-').replace('/','_').replace('=', ' ').replaceAll("\\s+", "").trim();
Log.i("Login", "pre send login");
//Creates webservice request, adds required params and sends request to webservice //Creates webservice request, adds required params and sends request to webservice
createRequest(); createRequest();
addParam("userID", prefs.getUserID()); addParam("userID", prefs.getUserID());
addParam("userPassword", userPassword); addParam("userPassword", userPassword);
addParam("appKey", Global.getAppKey()); addParam("appKey", Global.getAppKey());
sendRequest(User.class, true); sendRequest(User.class, true);
Log.i("Login", "sended login");
if (result != null) { if (result != null) {
SoapObject soap = (SoapObject) result; SoapObject soap = (SoapObject) result;

View File

@ -412,6 +412,7 @@ public abstract class Module extends MenuActivity {
* Use of KeepAliveHttpsTransport deals with the problems with the Android ssl libraries having trouble * Use of KeepAliveHttpsTransport deals with the problems with the Android ssl libraries having trouble
* with certificates and certificate authorities somehow messing up connecting/needing reconnects. * with certificates and certificate authorities somehow messing up connecting/needing reconnects.
*/ */
String u =prefs.getServer();
URL = prefs.getServer(); URL = prefs.getServer();
connection = new KeepAliveHttpsTransportSE(URL, 443, "", TIMEOUT); connection = new KeepAliveHttpsTransportSE(URL, 443, "", TIMEOUT);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

View File

@ -25,8 +25,6 @@ import java.util.List;
import org.ksoap2.SoapFault; import org.ksoap2.SoapFault;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
@ -42,7 +40,6 @@ import android.widget.Toast;
import es.ugr.swad.swadroid.Global; import es.ugr.swad.swadroid.Global;
import es.ugr.swad.swadroid.Preferences; import es.ugr.swad.swadroid.Preferences;
import es.ugr.swad.swadroid.R; import es.ugr.swad.swadroid.R;
import es.ugr.swad.swadroid.model.Course;
import es.ugr.swad.swadroid.model.Model; import es.ugr.swad.swadroid.model.Model;
import es.ugr.swad.swadroid.model.User; import es.ugr.swad.swadroid.model.User;
@ -55,10 +52,7 @@ public class Notices extends Module {
* Messages tag name for Logcat * Messages tag name for Logcat
*/ */
public static final String TAG = Global.APP_TAG + " Notice"; public static final String TAG = Global.APP_TAG + " Notice";
/**
* Course code
*/
private Long courseCode;
/** /**
* Notice's body * Notice's body
*/ */
@ -70,15 +64,6 @@ public class Notices extends Module {
*/ */
protected static Preferences prefs = new Preferences(); protected static Preferences prefs = new Preferences();
/**
* Cursor for database access
*/
private Cursor dbCursor;
/**
* User courses list
*/
private List<Model>listCourses;
/** /**
* Selected course code * Selected course code
*/ */
@ -120,11 +105,7 @@ public class Notices extends Module {
noticeDialog = new Dialog(this); noticeDialog = new Dialog(this);
Button acceptButton, cancelButton; Button acceptButton, cancelButton;
//Course selectedCourse = (Course)listCourses.get(selectedCourseCode);
//String selectedCourseName = selectedCourse.getName();
noticeDialog.setTitle(R.string.noticesModuleLabel); noticeDialog.setTitle(R.string.noticesModuleLabel);
//TODO noticeDialog.setTitle(R.string.noticeModuleLabel + listCourses.get(selectedCourseCode));
noticeDialog.setContentView(R.layout.notice_dialog); noticeDialog.setContentView(R.layout.notice_dialog);
noticeDialog.setCancelable(true); noticeDialog.setCancelable(true);
@ -198,7 +179,7 @@ public class Notices extends Module {
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
//noticeDialog.dismiss(); noticeDialog.dismiss();
} }
@Override @Override
@ -207,91 +188,11 @@ public class Notices extends Module {
super.onStart(); super.onStart();
prefs.getPreferences(getBaseContext()); prefs.getPreferences(getBaseContext());
activity = new Intent(getBaseContext(), Courses.class ); selectedCourseCode = Global.getSelectedCourseCode();
Toast.makeText(getBaseContext(), R.string.coursesProgressDescription, Toast.LENGTH_LONG).show(); launchNoticeDialog();
startActivityForResult(activity,Global.COURSES_REQUEST_CODE);
} }
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
int lastCourseSelected;
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == Activity.RESULT_OK){
switch(requestCode){
//After get the list of courses, a dialog is launched to choice the course
case Global.COURSES_REQUEST_CODE:
final AlertDialog.Builder coursesDialog = new AlertDialog.Builder(this);
dbCursor = dbHelper.getDb().getCursor(Global.DB_TABLE_COURSES, "userRole>=3", "name");
listCourses = dbHelper.getAllRows(Global.DB_TABLE_COURSES, "userRole>=3", "name");
lastCourseSelected = prefs.getLastCourseSelected();
coursesDialog.setSingleChoiceItems(dbCursor, lastCourseSelected, "name", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Course c = (Course) listCourses.get(whichButton);
selectedCourseCode = c.getId();
prefs.setLastCourseSelected(whichButton);
if(isDebuggable){
Integer s = whichButton;
Log.i(TAG, "singleChoice = " + s.toString());
}
}
});
coursesDialog.setTitle(R.string.selectCourseTitle);
coursesDialog.setPositiveButton(R.string.acceptMsg, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
try {
if(selectedCourseCode == 0) {
Course c = (Course) listCourses.get(prefs.getLastCourseSelected());
selectedCourseCode = c.getId();
}
if(isDebuggable) {
Log.i(TAG, "selectedCourseCode = " + Long.toString(selectedCourseCode));
}
dialog.dismiss();
launchNoticeDialog();
} catch (Exception ex) {
String errorMsg = getString(R.string.errorServerResponseMsg);
error(errorMsg);
if(isDebuggable) {
Log.e(ex.getClass().getSimpleName(), errorMsg);
ex.printStackTrace();
}
}
}
});
coursesDialog.setNegativeButton(R.string.cancelMsg, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
setResult(RESULT_CANCELED);
finish();
}
});
coursesDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
//dialog.cancel();
setResult(RESULT_CANCELED);
finish();
}
});
coursesDialog.show();
break;
}
} else {
setResult(RESULT_CANCELED);
finish();
}
}
@Override @Override
protected void onError() { protected void onError() {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View File

@ -50,18 +50,6 @@ import es.ugr.swad.swadroid.modules.Module;
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com> * @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
*/ */
public class TestsConfigDownload extends Module { public class TestsConfigDownload extends Module {
/**
* Cursor for database access
*/
private Cursor dbCursor;
/**
* User courses list
*/
private List<Model>listCourses;
/**
* Selected course code
*/
private long selectedCourseCode = 0;
/** /**
* Flag for detect if the teacher allows questions download * Flag for detect if the teacher allows questions download
*/ */
@ -93,88 +81,27 @@ public class TestsConfigDownload extends Module {
*/ */
@Override @Override
protected void onStart() { protected void onStart() {
Intent activity;
super.onStart(); super.onStart();
prefs.getPreferences(getBaseContext()); prefs.getPreferences(getBaseContext());
activity = new Intent(getBaseContext(), Courses.class); try {
Toast.makeText(getBaseContext(), R.string.coursesProgressDescription, Toast.LENGTH_LONG).show();
startActivityForResult(activity, Global.COURSES_REQUEST_CODE);
}
/* (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) {
int lastCourseSelected;
OnClickListener singleChoiceItemsClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Course c = (Course) listCourses.get(whichButton);
selectedCourseCode = c.getId();
prefs.setLastCourseSelected(whichButton);
if(isDebuggable) {
Integer s = whichButton;
Log.d(TAG, "singleChoice = " + s.toString());
}
}
};
OnClickListener positiveClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try {
if(selectedCourseCode == 0) {
//Toast.makeText(getBaseContext(), R.string.noCourseSelectedMsg, Toast.LENGTH_LONG).show();
Course c = (Course) listCourses.get(0);
selectedCourseCode = c.getId();
}
if(isDebuggable) {
Log.d(TAG, "selectedCourseCode = " + Long.toString(selectedCourseCode));
}
runConnection();
} catch (Exception ex) {
String errorMsg = getString(R.string.errorServerResponseMsg);
error(errorMsg);
if(isDebuggable) {
Log.e(ex.getClass().getSimpleName(), errorMsg);
ex.printStackTrace();
}
}
}
};
OnClickListener negativeClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
finish();
}
};
super.onActivityResult(requestCode, resultCode, data); if(isDebuggable) {
if (resultCode == Activity.RESULT_OK) { Log.d(TAG, "selectedCourseCode = " + Long.toString(Global.getSelectedCourseCode()));
switch(requestCode) { }
case Global.COURSES_REQUEST_CODE:
final AlertDialog.Builder alert = new AlertDialog.Builder(this); runConnection();
dbCursor = dbHelper.getDb().getCursor(Global.DB_TABLE_COURSES); } catch (Exception ex) {
listCourses = dbHelper.getAllRows(Global.DB_TABLE_COURSES); String errorMsg = getString(R.string.errorServerResponseMsg);
lastCourseSelected = prefs.getLastCourseSelected(); error(errorMsg);
alert.setSingleChoiceItems(dbCursor, lastCourseSelected, "name",
singleChoiceItemsClickListener); if(isDebuggable) {
Log.e(ex.getClass().getSimpleName(), errorMsg);
alert.setTitle(R.string.selectCourseTitle); ex.printStackTrace();
alert.setPositiveButton(R.string.acceptMsg, positiveClickListener); }
alert.setNegativeButton(R.string.cancelMsg, negativeClickListener); }
alert.show();
break;
}
} else {
setResult(RESULT_CANCELED);
finish();
}
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see es.ugr.swad.swadroid.modules.Module#requestService() * @see es.ugr.swad.swadroid.modules.Module#requestService()
*/ */
@ -184,13 +111,13 @@ public class TestsConfigDownload extends Module {
IllegalAccessException, InstantiationException { IllegalAccessException, InstantiationException {
//Calculates next timestamp to be requested //Calculates next timestamp to be requested
Long timestamp = new Long(dbHelper.getTimeOfLastTestUpdate(selectedCourseCode)); Long timestamp = new Long(dbHelper.getTimeOfLastTestUpdate(Global.getSelectedCourseCode()));
timestamp++; timestamp++;
//Creates webservice request, adds required params and sends request to webservice //Creates webservice request, adds required params and sends request to webservice
createRequest(); createRequest();
addParam("wsKey", User.getWsKey()); addParam("wsKey", User.getWsKey());
addParam("courseCode", (int)selectedCourseCode); addParam("courseCode", (int)Global.getSelectedCourseCode());
sendRequest(Test.class, false); sendRequest(Test.class, false);
if (result != null) { if (result != null) {
@ -216,11 +143,11 @@ public class TestsConfigDownload extends Module {
Integer maxQuestions = new Integer(res.get(4).toString()); Integer maxQuestions = new Integer(res.get(4).toString());
String feedback = res.get(5).toString(); String feedback = res.get(5).toString();
Test tDB = (Test) dbHelper.getRow(Global.DB_TABLE_TEST_CONFIG, "id", Test tDB = (Test) dbHelper.getRow(Global.DB_TABLE_TEST_CONFIG, "id",
Long.toString(selectedCourseCode)); Long.toString(Global.getSelectedCourseCode()));
//If not exists a test configuration for this course, insert to database //If not exists a test configuration for this course, insert to database
if(tDB == null) { if(tDB == null) {
Test t = new Test(selectedCourseCode, minQuestions, defQuestions, maxQuestions, feedback); Test t = new Test(Global.getSelectedCourseCode(), minQuestions, defQuestions, maxQuestions, feedback);
dbHelper.insertTestConfig(t); dbHelper.insertTestConfig(t);
} }
@ -232,7 +159,6 @@ public class TestsConfigDownload extends Module {
} }
Intent activity = new Intent(getBaseContext(), TestsQuestionsDownload.class); Intent activity = new Intent(getBaseContext(), TestsQuestionsDownload.class);
activity.putExtra("selectedCourseCode", selectedCourseCode);
activity.putExtra("timestamp", timestamp); activity.putExtra("timestamp", timestamp);
startActivityForResult(activity, Global.TESTS_QUESTIONS_DOWNLOAD_REQUEST_CODE); startActivityForResult(activity, Global.TESTS_QUESTIONS_DOWNLOAD_REQUEST_CODE);
} }

View File

@ -67,18 +67,6 @@ import es.ugr.swad.swadroid.widget.TextProgressBar;
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com> * @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
*/ */
public class TestsMake extends Module { public class TestsMake extends Module {
/**
* Cursor for database access
*/
private Cursor dbCursor;
/**
* User courses list
*/
private List<Model>listCourses;
/**
* Selected course code
*/
private long selectedCourseCode = 0;
/** /**
* Test's number of questions * Test's number of questions
*/ */
@ -95,18 +83,6 @@ public class TestsMake extends Module {
* Answer types's list of the test * Answer types's list of the test
*/ */
private List<String> answerTypesList; private List<String> answerTypesList;
/**
* Click listener for courses dialog items
*/
private OnClickListener coursesDialogSingleChoiceItemsClickListener;
/**
* Click listener for courses dialog accept button
*/
private OnClickListener coursesDialogPositiveClickListener;
/**
* Click listener for courses dialog cancel button
*/
private OnClickListener coursesDialogNegativeClickListener;
/** /**
* Click listener for courses dialog cancel button * Click listener for courses dialog cancel button
*/ */
@ -115,10 +91,6 @@ public class TestsMake extends Module {
* Adapter for answer TF questions * Adapter for answer TF questions
*/ */
private ArrayAdapter<String> tfAdapter; private ArrayAdapter<String> tfAdapter;
/**
* Course selection dialog
*/
private AlertDialog.Builder coursesDialog;
/** /**
* Test question being showed * Test question being showed
*/ */
@ -183,7 +155,7 @@ public class TestsMake extends Module {
Button acceptButton; Button acceptButton;
final ListView checkBoxesList; final ListView checkBoxesList;
final TagsArrayAdapter tagsAdapter; final TagsArrayAdapter tagsAdapter;
final List<TestTag> allTagsList = dbHelper.getOrderedCourseTags(selectedCourseCode); final List<TestTag> allTagsList = dbHelper.getOrderedCourseTags(Global.getSelectedCourseCode());
//Add "All tags" item in list's top //Add "All tags" item in list's top
allTagsList.add(0, new TestTag(0, getResources().getString(R.string.allMsg), 0)); allTagsList.add(0, new TestTag(0, getResources().getString(R.string.allMsg), 0));
@ -528,7 +500,7 @@ public class TestsMake extends Module {
List<TestQuestion> questions; List<TestQuestion> questions;
//Generates the test //Generates the test
questions = dbHelper.getRandomCourseQuestionsByTagAndAnswerType(selectedCourseCode, tagsList, answerTypesList, questions = dbHelper.getRandomCourseQuestionsByTagAndAnswerType(Global.getSelectedCourseCode(), tagsList, answerTypesList,
numQuestions); numQuestions);
if(!questions.isEmpty()) { if(!questions.isEmpty()) {
test.setQuestions(questions); test.setQuestions(questions);
@ -626,47 +598,7 @@ public class TestsMake extends Module {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setLayout(R.layout.layout_with_action_bar); setLayout(R.layout.layout_with_action_bar);
coursesDialogSingleChoiceItemsClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Course c = (Course) listCourses.get(whichButton);
selectedCourseCode = c.getId();
prefs.setLastCourseSelected(whichButton);
if(isDebuggable) {
Integer s = whichButton;
Log.d(TAG, "singleChoice = " + s.toString());
}
}
};
coursesDialogPositiveClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if(selectedCourseCode != 0) {
if(isDebuggable) {
Log.d(TAG, "selectedCourseCode = " + Long.toString(selectedCourseCode));
}
test = (Test) dbHelper.getRow(Global.DB_TABLE_TEST_CONFIG, "id",
Long.toString(selectedCourseCode));
if(test != null) {
setNumQuestions();
} else {
Toast.makeText(getBaseContext(), R.string.testNoQuestionsCourseMsg, Toast.LENGTH_LONG).show();
finish();
}
} else {
Toast.makeText(getBaseContext(), R.string.noCourseSelectedMsg, Toast.LENGTH_LONG).show();
finish();
}
}
};
coursesDialogNegativeClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
finish();
}
};
tagsAnswersTypeItemClickListener = new OnItemClickListener() { tagsAnswersTypeItemClickListener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, public void onItemClick(AdapterView<?> parent, View v, int position,
long id) { long id) {
@ -697,11 +629,6 @@ public class TestsMake extends Module {
} }
}; };
coursesDialog = new AlertDialog.Builder(this);
coursesDialog.setTitle(R.string.selectCourseTitle);
coursesDialog.setPositiveButton(R.string.acceptMsg, coursesDialogPositiveClickListener);
coursesDialog.setNegativeButton(R.string.cancelMsg, coursesDialogNegativeClickListener);
tfAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item); tfAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
tfAdapter.add(getString(R.string.trueMsg)); tfAdapter.add(getString(R.string.trueMsg));
tfAdapter.add(getString(R.string.falseMsg)); tfAdapter.add(getString(R.string.falseMsg));
@ -719,21 +646,26 @@ public class TestsMake extends Module {
super.onStart(); super.onStart();
prefs.getPreferences(getBaseContext()); prefs.getPreferences(getBaseContext());
String selection ="id=" + Long.toString(Global.getSelectedCourseCode());
if(dbHelper.getDb().getCursor(Global.DB_TABLE_TEST_CONFIG).getCount() > 0) { if(dbHelper.getDb().getCursor(Global.DB_TABLE_TEST_CONFIG,selection,null).getCount() > 0) {
dbCursor = dbHelper.getDb().getCursor(Global.DB_TABLE_COURSES); if(isDebuggable) {
listCourses = dbHelper.getAllRows(Global.DB_TABLE_COURSES); Log.d(TAG, "selectedCourseCode = " + Long.toString(Global.getSelectedCourseCode()));
lastCourseSelected = prefs.getLastCourseSelected(); }
c = (Course) listCourses.get(lastCourseSelected);
selectedCourseCode = c.getId(); test = (Test) dbHelper.getRow(Global.DB_TABLE_TEST_CONFIG, "id",
coursesDialog.setSingleChoiceItems(dbCursor, lastCourseSelected, "name", Long.toString(Global.getSelectedCourseCode()));
coursesDialogSingleChoiceItemsClickListener);
coursesDialog.show(); if(test != null) {
setNumQuestions();
} else {
Toast.makeText(getBaseContext(), R.string.testNoQuestionsCourseMsg, Toast.LENGTH_LONG).show();
finish();
}
} else { } else {
Toast.makeText(getBaseContext(), R.string.testNoQuestionsMsg, Toast.LENGTH_LONG).show(); Toast.makeText(getBaseContext(), R.string.testNoQuestionsMsg, Toast.LENGTH_LONG).show();
finish(); finish();
} }
} }
/* (non-Javadoc) /* (non-Javadoc)

View File

@ -47,10 +47,6 @@ import es.ugr.swad.swadroid.modules.Module;
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com> * @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
*/ */
public class TestsQuestionsDownload extends Module { public class TestsQuestionsDownload extends Module {
/**
* Selected course code
*/
private long selectedCourseCode;
/** /**
* Next timestamp to be requested * Next timestamp to be requested
*/ */
@ -75,7 +71,6 @@ public class TestsQuestionsDownload extends Module {
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
selectedCourseCode = getIntent().getLongExtra("selectedCourseCode", 0);
timestamp = getIntent().getLongExtra("timestamp", 0); timestamp = getIntent().getLongExtra("timestamp", 0);
runConnection(); runConnection();
} }
@ -91,7 +86,7 @@ public class TestsQuestionsDownload extends Module {
//Creates webservice request, adds required params and sends request to webservice //Creates webservice request, adds required params and sends request to webservice
createRequest(); createRequest();
addParam("wsKey", User.getWsKey()); addParam("wsKey", User.getWsKey());
addParam("courseCode", (int)selectedCourseCode); addParam("courseCode", (int)Global.getSelectedCourseCode());
addParam("beginTime", timestamp); addParam("beginTime", timestamp);
sendRequest(Test.class, false); sendRequest(Test.class, false);
@ -137,7 +132,7 @@ public class TestsQuestionsDownload extends Module {
//If it's a new question, insert in database //If it's a new question, insert in database
try { try {
dbHelper.insertTestQuestion(q, selectedCourseCode); dbHelper.insertTestQuestion(q, Global.getSelectedCourseCode());
if(isDebuggable) if(isDebuggable)
Log.d(TAG, "INSERTED: " + q.toString()); Log.d(TAG, "INSERTED: " + q.toString());
@ -145,7 +140,7 @@ public class TestsQuestionsDownload extends Module {
//If it's an updated question, update it's row in database //If it's an updated question, update it's row in database
} catch (SQLException e) { } catch (SQLException e) {
TestQuestion old = (TestQuestion) questionsListDB.get(questionsListDB.indexOf(q)); TestQuestion old = (TestQuestion) questionsListDB.get(questionsListDB.indexOf(q));
dbHelper.updateTestQuestion(old, q, selectedCourseCode); dbHelper.updateTestQuestion(old, q, Global.getSelectedCourseCode());
if(isDebuggable) if(isDebuggable)
Log.d(TAG, "UPDATED: " + q.toString()); Log.d(TAG, "UPDATED: " + q.toString());
@ -217,7 +212,7 @@ public class TestsQuestionsDownload extends Module {
Log.i(TAG, "Retrieved " + listSize + " relationships between questions and tags"); Log.i(TAG, "Retrieved " + listSize + " relationships between questions and tags");
//Update last time test was updated //Update last time test was updated
Test oldTestConfigDB = (Test) dbHelper.getRow(Global.DB_TABLE_TEST_CONFIG, "id", Long.toString(selectedCourseCode)); Test oldTestConfigDB = (Test) dbHelper.getRow(Global.DB_TABLE_TEST_CONFIG, "id", Long.toString(Global.getSelectedCourseCode()));
Test testConfig = oldTestConfigDB; Test testConfig = oldTestConfigDB;
testConfig.setEditTime(System.currentTimeMillis() / 1000L); testConfig.setEditTime(System.currentTimeMillis() / 1000L);
dbHelper.updateTestConfig(oldTestConfigDB, testConfig); dbHelper.updateTestConfig(oldTestConfigDB, testConfig);