diff --git a/SWADroid/res/layout/main.xml b/SWADroid/res/layout/main.xml index 4464ad90..04bf94f8 100644 --- a/SWADroid/res/layout/main.xml +++ b/SWADroid/res/layout/main.xml @@ -5,11 +5,17 @@ android:layout_height="match_parent" android:background="@color/background"> - + + \ No newline at end of file diff --git a/SWADroid/src/es/ugr/swad/swadroid/Global.java b/SWADroid/src/es/ugr/swad/swadroid/Global.java index b0ac3e76..eb70ec89 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/Global.java +++ b/SWADroid/src/es/ugr/swad/swadroid/Global.java @@ -27,7 +27,7 @@ public class Global { /** * SWAD application key */ - private static final String AppKey = ""; + private static final String AppKey = "HTC-Desire"; /** * Server URL */ @@ -40,6 +40,11 @@ public class Global { * Time of application's last login */ 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 */ @@ -200,4 +205,18 @@ public class Global { public static String parseBoolString(boolean b) { 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; + } } diff --git a/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java b/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java index ba54ba98..f85520c3 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java +++ b/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java @@ -19,19 +19,29 @@ package es.ugr.swad.swadroid; + import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; +import android.database.Cursor; import android.os.Bundle; import android.view.View; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.ArrayAdapter; import android.widget.ExpandableListView; import android.widget.ImageView; +import android.widget.SimpleCursorAdapter; +import android.widget.Spinner; import android.widget.TextView; +import es.ugr.swad.swadroid.model.Course; 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.notifications.Notifications; import es.ugr.swad.swadroid.modules.tests.Tests; @@ -55,6 +65,18 @@ public class SWADMain extends MenuExpandableListActivity { * Function text field */ final String IMAGE = "listIcon"; + /** + * Code of selected course + * */ + long courseCode; + /** + * Cursor for database access + */ + private Cursor dbCursor; + /** + * User courses list + */ + private ListlistCourses; /** * Gets the database helper @@ -139,7 +161,7 @@ public class SWADMain extends MenuExpandableListActivity { /** * Create main menu with an expandable list */ - private void createMainMenu() + private void createTeacherMenu() { //Construct Expandable List final ArrayList> headerData = new ArrayList>(); @@ -198,6 +220,63 @@ public class SWADMain extends MenuExpandableListActivity { getExpandableListView().setOnChildClickListener(this); } + /** + * Create main menu with an expandable list + */ + private void createStudentMenu() + { + //Construct Expandable List + final ArrayList> headerData = new ArrayList>(); + + final HashMap messages = new HashMap(); + messages.put(NAME, getString(R.string.messages)); + messages.put(IMAGE, getResources().getDrawable(R.drawable.msg)); + headerData.add( messages ); + + final HashMap evaluation = new HashMap(); + evaluation.put(NAME, getString(R.string.evaluation)); + evaluation.put(IMAGE, getResources().getDrawable(R.drawable.grades)); + headerData.add( evaluation); + + final ArrayList>> childData = new ArrayList>>(); + + final ArrayList> messagesData = new ArrayList>(); + childData.add(messagesData); + + final ArrayList> evaluationData = new ArrayList>(); + childData.add(evaluationData); + + //Messages category + HashMap map = new HashMap(); + map.put(NAME, getString(R.string.notificationsModuleLabel) ); + map.put(IMAGE, getResources().getDrawable(R.drawable.notif)); + messagesData.add(map); + + map = new HashMap(); + map.put(NAME, getString(R.string.messagesModuleLabel) ); + map.put(IMAGE, getResources().getDrawable(R.drawable.msg)); + messagesData.add(map); + + //Evaluation category + map = new HashMap(); + 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) * @see android.app.Activity#onCreate() @@ -217,8 +296,22 @@ public class SWADMain extends MenuExpandableListActivity { text = (TextView)this.findViewById(R.id.moduleName); 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 { //Initialize database @@ -255,4 +348,25 @@ public class SWADMain extends MenuExpandableListActivity { 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 + + } + + } } diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/Login.java b/SWADroid/src/es/ugr/swad/swadroid/modules/Login.java index 38e61142..8d56bddf 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/modules/Login.java +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/Login.java @@ -110,14 +110,12 @@ public class Login extends Module { md.update(prefs.getUserPassword().getBytes()); userPassword = new String(Base64.encodeBytes(md.digest())); 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 createRequest(); addParam("userID", prefs.getUserID()); addParam("userPassword", userPassword); addParam("appKey", Global.getAppKey()); sendRequest(User.class, true); - Log.i("Login", "sended login"); if (result != null) { SoapObject soap = (SoapObject) result; diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/Module.java b/SWADroid/src/es/ugr/swad/swadroid/modules/Module.java index 56b54604..39dd7fa5 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/modules/Module.java +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/Module.java @@ -412,6 +412,7 @@ public abstract class Module extends MenuActivity { * 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. */ + String u =prefs.getServer(); URL = prefs.getServer(); connection = new KeepAliveHttpsTransportSE(URL, 443, "", TIMEOUT); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/Notices.java b/SWADroid/src/es/ugr/swad/swadroid/modules/Notices.java index 85a33cc4..8812398b 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/modules/Notices.java +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/Notices.java @@ -25,8 +25,6 @@ import java.util.List; import org.ksoap2.SoapFault; import org.xmlpull.v1.XmlPullParserException; -import android.app.Activity; -import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; @@ -42,7 +40,6 @@ import android.widget.Toast; import es.ugr.swad.swadroid.Global; import es.ugr.swad.swadroid.Preferences; 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.User; @@ -55,10 +52,7 @@ public class Notices extends Module { * Messages tag name for Logcat */ public static final String TAG = Global.APP_TAG + " Notice"; - /** - * Course code - */ - private Long courseCode; + /** * Notice's body */ @@ -70,15 +64,6 @@ public class Notices extends Module { */ protected static Preferences prefs = new Preferences(); - /** - * Cursor for database access - */ - private Cursor dbCursor; - - /** - * User courses list - */ - private ListlistCourses; /** * Selected course code */ @@ -120,11 +105,7 @@ public class Notices extends Module { noticeDialog = new Dialog(this); Button acceptButton, cancelButton; - //Course selectedCourse = (Course)listCourses.get(selectedCourseCode); - //String selectedCourseName = selectedCourse.getName(); - noticeDialog.setTitle(R.string.noticesModuleLabel); - //TODO noticeDialog.setTitle(R.string.noticeModuleLabel + listCourses.get(selectedCourseCode)); noticeDialog.setContentView(R.layout.notice_dialog); noticeDialog.setCancelable(true); @@ -198,7 +179,7 @@ public class Notices extends Module { @Override protected void onPause() { super.onPause(); - //noticeDialog.dismiss(); + noticeDialog.dismiss(); } @Override @@ -207,91 +188,11 @@ public class Notices extends Module { super.onStart(); prefs.getPreferences(getBaseContext()); - activity = new Intent(getBaseContext(), Courses.class ); - Toast.makeText(getBaseContext(), R.string.coursesProgressDescription, Toast.LENGTH_LONG).show(); - startActivityForResult(activity,Global.COURSES_REQUEST_CODE); + selectedCourseCode = Global.getSelectedCourseCode(); + launchNoticeDialog(); } - @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 protected void onError() { // TODO Auto-generated method stub diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/tests/TestsConfigDownload.java b/SWADroid/src/es/ugr/swad/swadroid/modules/tests/TestsConfigDownload.java index b4bd7294..cd98ab59 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/modules/tests/TestsConfigDownload.java +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/tests/TestsConfigDownload.java @@ -50,18 +50,6 @@ import es.ugr.swad.swadroid.modules.Module; * @author Juan Miguel Boyero Corral */ public class TestsConfigDownload extends Module { - /** - * Cursor for database access - */ - private Cursor dbCursor; - /** - * User courses list - */ - private ListlistCourses; - /** - * Selected course code - */ - private long selectedCourseCode = 0; /** * Flag for detect if the teacher allows questions download */ @@ -93,88 +81,27 @@ public class TestsConfigDownload extends Module { */ @Override protected void onStart() { - Intent activity; - super.onStart(); prefs.getPreferences(getBaseContext()); - activity = new Intent(getBaseContext(), Courses.class); - 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(); - } - }; + try { - super.onActivityResult(requestCode, resultCode, data); - if (resultCode == Activity.RESULT_OK) { - switch(requestCode) { - case Global.COURSES_REQUEST_CODE: - final AlertDialog.Builder alert = new AlertDialog.Builder(this); - dbCursor = dbHelper.getDb().getCursor(Global.DB_TABLE_COURSES); - listCourses = dbHelper.getAllRows(Global.DB_TABLE_COURSES); - lastCourseSelected = prefs.getLastCourseSelected(); - alert.setSingleChoiceItems(dbCursor, lastCourseSelected, "name", - singleChoiceItemsClickListener); - - alert.setTitle(R.string.selectCourseTitle); - alert.setPositiveButton(R.string.acceptMsg, positiveClickListener); - alert.setNegativeButton(R.string.cancelMsg, negativeClickListener); - alert.show(); - break; - } - } else { - setResult(RESULT_CANCELED); - finish(); - } + if(isDebuggable) { + Log.d(TAG, "selectedCourseCode = " + Long.toString(Global.getSelectedCourseCode())); + } + + runConnection(); + } catch (Exception ex) { + String errorMsg = getString(R.string.errorServerResponseMsg); + error(errorMsg); + + if(isDebuggable) { + Log.e(ex.getClass().getSimpleName(), errorMsg); + ex.printStackTrace(); + } + } } + /* (non-Javadoc) * @see es.ugr.swad.swadroid.modules.Module#requestService() */ @@ -184,13 +111,13 @@ public class TestsConfigDownload extends Module { IllegalAccessException, InstantiationException { //Calculates next timestamp to be requested - Long timestamp = new Long(dbHelper.getTimeOfLastTestUpdate(selectedCourseCode)); + Long timestamp = new Long(dbHelper.getTimeOfLastTestUpdate(Global.getSelectedCourseCode())); timestamp++; //Creates webservice request, adds required params and sends request to webservice createRequest(); addParam("wsKey", User.getWsKey()); - addParam("courseCode", (int)selectedCourseCode); + addParam("courseCode", (int)Global.getSelectedCourseCode()); sendRequest(Test.class, false); if (result != null) { @@ -216,11 +143,11 @@ public class TestsConfigDownload extends Module { Integer maxQuestions = new Integer(res.get(4).toString()); String feedback = res.get(5).toString(); 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(tDB == null) { - Test t = new Test(selectedCourseCode, minQuestions, defQuestions, maxQuestions, feedback); + Test t = new Test(Global.getSelectedCourseCode(), minQuestions, defQuestions, maxQuestions, feedback); dbHelper.insertTestConfig(t); } @@ -232,7 +159,6 @@ public class TestsConfigDownload extends Module { } Intent activity = new Intent(getBaseContext(), TestsQuestionsDownload.class); - activity.putExtra("selectedCourseCode", selectedCourseCode); activity.putExtra("timestamp", timestamp); startActivityForResult(activity, Global.TESTS_QUESTIONS_DOWNLOAD_REQUEST_CODE); } diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/tests/TestsMake.java b/SWADroid/src/es/ugr/swad/swadroid/modules/tests/TestsMake.java index 84cae17d..a65775a0 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/modules/tests/TestsMake.java +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/tests/TestsMake.java @@ -67,18 +67,6 @@ import es.ugr.swad.swadroid.widget.TextProgressBar; * @author Juan Miguel Boyero Corral */ public class TestsMake extends Module { - /** - * Cursor for database access - */ - private Cursor dbCursor; - /** - * User courses list - */ - private ListlistCourses; - /** - * Selected course code - */ - private long selectedCourseCode = 0; /** * Test's number of questions */ @@ -95,18 +83,6 @@ public class TestsMake extends Module { * Answer types's list of the test */ private List 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 */ @@ -115,10 +91,6 @@ public class TestsMake extends Module { * Adapter for answer TF questions */ private ArrayAdapter tfAdapter; - /** - * Course selection dialog - */ - private AlertDialog.Builder coursesDialog; /** * Test question being showed */ @@ -183,7 +155,7 @@ public class TestsMake extends Module { Button acceptButton; final ListView checkBoxesList; final TagsArrayAdapter tagsAdapter; - final List allTagsList = dbHelper.getOrderedCourseTags(selectedCourseCode); + final List allTagsList = dbHelper.getOrderedCourseTags(Global.getSelectedCourseCode()); //Add "All tags" item in list's top allTagsList.add(0, new TestTag(0, getResources().getString(R.string.allMsg), 0)); @@ -528,7 +500,7 @@ public class TestsMake extends Module { List questions; //Generates the test - questions = dbHelper.getRandomCourseQuestionsByTagAndAnswerType(selectedCourseCode, tagsList, answerTypesList, + questions = dbHelper.getRandomCourseQuestionsByTagAndAnswerType(Global.getSelectedCourseCode(), tagsList, answerTypesList, numQuestions); if(!questions.isEmpty()) { test.setQuestions(questions); @@ -626,47 +598,7 @@ public class TestsMake extends Module { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 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() { public void onItemClick(AdapterView parent, View v, int position, 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(this, android.R.layout.simple_spinner_item); tfAdapter.add(getString(R.string.trueMsg)); tfAdapter.add(getString(R.string.falseMsg)); @@ -719,21 +646,26 @@ public class TestsMake extends Module { super.onStart(); prefs.getPreferences(getBaseContext()); - - if(dbHelper.getDb().getCursor(Global.DB_TABLE_TEST_CONFIG).getCount() > 0) { - dbCursor = dbHelper.getDb().getCursor(Global.DB_TABLE_COURSES); - listCourses = dbHelper.getAllRows(Global.DB_TABLE_COURSES); - lastCourseSelected = prefs.getLastCourseSelected(); - c = (Course) listCourses.get(lastCourseSelected); - selectedCourseCode = c.getId(); - coursesDialog.setSingleChoiceItems(dbCursor, lastCourseSelected, "name", - coursesDialogSingleChoiceItemsClickListener); + String selection ="id=" + Long.toString(Global.getSelectedCourseCode()); + if(dbHelper.getDb().getCursor(Global.DB_TABLE_TEST_CONFIG,selection,null).getCount() > 0) { + if(isDebuggable) { + Log.d(TAG, "selectedCourseCode = " + Long.toString(Global.getSelectedCourseCode())); + } + + test = (Test) dbHelper.getRow(Global.DB_TABLE_TEST_CONFIG, "id", + Long.toString(Global.getSelectedCourseCode())); - coursesDialog.show(); + if(test != null) { + setNumQuestions(); + } else { + Toast.makeText(getBaseContext(), R.string.testNoQuestionsCourseMsg, Toast.LENGTH_LONG).show(); + finish(); + } } else { Toast.makeText(getBaseContext(), R.string.testNoQuestionsMsg, Toast.LENGTH_LONG).show(); finish(); } + } /* (non-Javadoc) diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/tests/TestsQuestionsDownload.java b/SWADroid/src/es/ugr/swad/swadroid/modules/tests/TestsQuestionsDownload.java index 0689db6f..4986d9be 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/modules/tests/TestsQuestionsDownload.java +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/tests/TestsQuestionsDownload.java @@ -47,10 +47,6 @@ import es.ugr.swad.swadroid.modules.Module; * @author Juan Miguel Boyero Corral */ public class TestsQuestionsDownload extends Module { - /** - * Selected course code - */ - private long selectedCourseCode; /** * Next timestamp to be requested */ @@ -75,7 +71,6 @@ public class TestsQuestionsDownload extends Module { @Override protected void onStart() { super.onStart(); - selectedCourseCode = getIntent().getLongExtra("selectedCourseCode", 0); timestamp = getIntent().getLongExtra("timestamp", 0); runConnection(); } @@ -91,7 +86,7 @@ public class TestsQuestionsDownload extends Module { //Creates webservice request, adds required params and sends request to webservice createRequest(); addParam("wsKey", User.getWsKey()); - addParam("courseCode", (int)selectedCourseCode); + addParam("courseCode", (int)Global.getSelectedCourseCode()); addParam("beginTime", timestamp); sendRequest(Test.class, false); @@ -137,7 +132,7 @@ public class TestsQuestionsDownload extends Module { //If it's a new question, insert in database try { - dbHelper.insertTestQuestion(q, selectedCourseCode); + dbHelper.insertTestQuestion(q, Global.getSelectedCourseCode()); if(isDebuggable) 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 } catch (SQLException e) { TestQuestion old = (TestQuestion) questionsListDB.get(questionsListDB.indexOf(q)); - dbHelper.updateTestQuestion(old, q, selectedCourseCode); + dbHelper.updateTestQuestion(old, q, Global.getSelectedCourseCode()); if(isDebuggable) 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"); //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; testConfig.setEditTime(System.currentTimeMillis() / 1000L); dbHelper.updateTestConfig(oldTestConfigDB, testConfig);