diff --git a/SWADroid/res/layout/navigation.xml b/SWADroid/res/layout/navigation.xml index 4e7901d5..ede7079a 100644 --- a/SWADroid/res/layout/navigation.xml +++ b/SWADroid/res/layout/navigation.xml @@ -16,7 +16,9 @@ android:background="@color/title_background" android:textColor="@android:color/white" android:textSize="18sp" - android:textStyle="bold" > + android:textStyle="bold" + android:ellipsize="start" + android:singleLine="true"> diff --git a/SWADroid/res/values/strings.xml b/SWADroid/res/values/strings.xml index 6b7d24f4..63d09cda 100644 --- a/SWADroid/res/values/strings.xml +++ b/SWADroid/res/values/strings.xml @@ -21,7 +21,7 @@ Password Password Preferences have been saved - Save actual preferences + Save current preferences Save preferences Preferences Share SWADroid diff --git a/SWADroid/src/es/ugr/swad/swadroid/Global.java b/SWADroid/src/es/ugr/swad/swadroid/Global.java index cb6fdaa8..9b9f12c1 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/Global.java +++ b/SWADroid/src/es/ugr/swad/swadroid/Global.java @@ -297,18 +297,18 @@ public class Global { return b ? "Y" : "N"; } /** - * Gets code of actual course - * return -1 if no course chosen; code of actual course in other case + * Gets code of current course + * return -1 if no course chosen; code of current course in other case * */ public static long getSelectedCourseCode(){ return selectedCourseCode; } /** - * Sets code of actual course + * Sets code of current 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; + public static void setSelectedCourseCode(long currentCourseCode){ + if(currentCourseCode >0) selectedCourseCode = currentCourseCode; } public static boolean isPreferencesChanged(){ @@ -322,12 +322,12 @@ public class Global { preferencesChanged = newState; } - public static void setSelectedCourseShortName(String actualCourseShortName){ - selectedCourseShortName = actualCourseShortName; + public static void setSelectedCourseShortName(String currentCourseShortName){ + selectedCourseShortName = currentCourseShortName; } - public static void setSelectedCourseFullName(String actualCourseFullName){ - selectedCourseFullName = actualCourseFullName; + public static void setSelectedCourseFullName(String currentCourseFullName){ + selectedCourseFullName = currentCourseFullName; } public static String getSelectedCourseShortName(){ diff --git a/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java b/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java index 3bb66ec8..110ca3af 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java +++ b/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java @@ -104,7 +104,7 @@ public class SWADMain extends MenuExpandableListActivity { private boolean firstRun = false; /** - * Actual role 2 - student 3 - teacher -1 - none role was chosen + * Current role 2 - student 3 - teacher -1 - none role was chosen * */ private int currentRole = -1; /** @@ -253,7 +253,7 @@ public class SWADMain extends MenuExpandableListActivity { createMenu(); } }else{ - getActualCourses(); + getCurrentCourses(); Global.setPreferencesChanged(false); } } @@ -335,7 +335,7 @@ public class SWADMain extends MenuExpandableListActivity { Global.setSelectedCourseCode(-1); Global.setSelectedCourseShortName(""); Global.setSelectedCourseFullName(""); - if(!firstRun && Module.connectionAvailable(this)) getActualCourses(); //at the first run, this will be launched after the preferences menu + if(!firstRun && Module.connectionAvailable(this)) getCurrentCourses(); //at the first run, this will be launched after the preferences menu } currentRole = -1; } catch (Exception ex) { @@ -427,7 +427,7 @@ public class SWADMain extends MenuExpandableListActivity { if(dbHelper.getAllRows(Global.DB_TABLE_COURSES).size()==0){ if(Module.connectionAvailable(getBaseContext())) - getActualCourses(); + getCurrentCourses(); //else }else{ @@ -439,7 +439,7 @@ public class SWADMain extends MenuExpandableListActivity { } }; - private void getActualCourses(){ + private void getCurrentCourses(){ Intent activity; activity = new Intent(getBaseContext(), Courses.class ); Toast.makeText(getBaseContext(), R.string.coursesProgressDescription, Toast.LENGTH_LONG).show(); diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DirectoryNavigator.java b/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DirectoryNavigator.java index a11b3894..af68f235 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DirectoryNavigator.java +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DirectoryNavigator.java @@ -1,3 +1,21 @@ +/* + * This file is part of SWADroid. + * + * Copyright (C) 2012 Helena Rodriguez Gijon + * + * 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.downloads; import java.io.StringReader; @@ -17,12 +35,13 @@ import org.xml.sax.InputSource; * Class used to navigate around the XML file. That XML file contains the information of all the directory. * @author Sergio Ropero Oliver. + * @author Helena Rodríguez Gijón * @version 1.0 */ public class DirectoryNavigator { private String XMLinfo; - ArrayList path; + private ArrayList path; /** * Constructor. @@ -40,7 +59,7 @@ public class DirectoryNavigator * @return Return a list of items that are inside the subdirectory. * @throws InvalidPath When the directory don't exist. */ - public ArrayList subDirectory(String subDirectory) throws InvalidPath + public ArrayList goToSubDirectory(String subDirectory) throws InvalidPath { //We increase the path. path.add(subDirectory); @@ -58,16 +77,18 @@ public class DirectoryNavigator * @return Return a list of items that are inside the parent directory. * @throws InvalidPath When the directory does not exist. */ - public List parentDirectory() throws InvalidPath + public ArrayList goToParentDirectory() throws InvalidPath { - //We decrease the path. - path.remove(path.size()-1); - - Node node = goToDirectory(); - - List itemsToShow; - itemsToShow = new ArrayList(getItems(node)); - + ArrayList itemsToShow; + + if(path.size() !=0){ + //We decrease the path. + path.remove(path.size()-1); + Node node = goToDirectory(); + itemsToShow = new ArrayList(getItems(node)); + }else + itemsToShow = goToRoot(); + return itemsToShow; } @@ -76,13 +97,13 @@ public class DirectoryNavigator * @return Return a list of items in the current directory. * @throws InvalidPath When the directory don't exist. */ - public List refresh(String fileXML) throws InvalidPath + public ArrayList refresh(String fileXML) throws InvalidPath { this.XMLinfo = fileXML; Node node = goToDirectory(); - List itemsToShow; + ArrayList itemsToShow; itemsToShow = new ArrayList(getItems(node)); return itemsToShow; @@ -93,13 +114,13 @@ public class DirectoryNavigator * @return The items of the root directory. * @throws InvalidPath When the directory don't exist. */ - public List goToRoot() throws InvalidPath + public ArrayList goToRoot() throws InvalidPath { path.clear(); Node node = goToDirectory(); - List itemsToShow; + ArrayList itemsToShow; itemsToShow = new ArrayList(getItems(node)); return itemsToShow; @@ -205,7 +226,7 @@ public class DirectoryNavigator DocumentBuilder builder; int directoryLevel = 0; - Node actualNode = null; + Node currentNode = null; try { @@ -214,15 +235,15 @@ public class DirectoryNavigator //We read the entire XML file. Document dom = builder.parse(new InputSource(new StringReader(XMLinfo))); - //We put the actual node in the root Element. - actualNode = dom.getDocumentElement(); + //We put the current node in the root Element. + currentNode = dom.getDocumentElement(); System.out.println("XML: " + XMLinfo); System.out.println("path size "+path.size()); //We change the current node. for(int i=0; i getActual - //public List getActual(){} + //TODO List getcurrent + //public List getcurrent(){} } /** diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DownloadsManager.java b/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DownloadsManager.java index 71179909..468a6deb 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DownloadsManager.java +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DownloadsManager.java @@ -24,149 +24,177 @@ import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; +import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; -import android.widget.AdapterView.OnItemSelectedListener; import android.widget.GridView; +import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; -import android.widget.Toast; import es.ugr.swad.swadroid.Global; import es.ugr.swad.swadroid.MenuActivity; import es.ugr.swad.swadroid.R; -import es.ugr.swad.swadroid.model.Course; - /** - * Activity to navigate through the directory tree of documents and to manage the downloads of documents + * Activity to navigate through the directory tree of documents and to manage + * the downloads of documents + * * @author Helena Rodríguez Gijon * */ public class DownloadsManager extends MenuActivity { /** - * Class that contains the directory tree and gives information of each level + * Class that contains the directory tree and gives information of each + * level * */ - private DirectoryNavigator navigator; - + private DirectoryNavigator navigator; + /** - * Specifies whether to display the documents or the shared area of the subject - * 1 specifies documents area - * 2 specifies shared area + * Specifies whether to display the documents or the shared area of the + * subject 1 specifies documents area 2 specifies shared area * */ private int downloadsCode = 0; /** - * String that contains the xml files recevied from the web service + * String that contains the xml files recevied from the web service * */ private String tree; - - /** - * Downloads tag name for Logcat - */ - public static final String TAG = Global.APP_TAG + " Downloads"; - - private GridView grid; - - ImageView moduleIcon = null; - TextView moduleText = null; - - TextView actualPathText; + + /** + * Downloads tag name for Logcat + */ + public static final String TAG = Global.APP_TAG + " Downloads"; + + /** + * Indicates whether the refresh button was pressed + * */ + private boolean refresh = false; + private GridView grid; + + private ImageView moduleIcon = null; + private TextView moduleText = null; + private TextView currentPathText; @Override protected void onStart() { super.onStart(); Intent activity; - activity = new Intent(getBaseContext(),DirectoryTreeDownload.class); - activity.putExtra("treeCode",downloadsCode); - startActivityForResult(activity,Global.DIRECTORY_TREE_REQUEST_CODE); + activity = new Intent(getBaseContext(), DirectoryTreeDownload.class); + activity.putExtra("treeCode", downloadsCode); + startActivityForResult(activity, Global.DIRECTORY_TREE_REQUEST_CODE); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.navigation); - downloadsCode = getIntent().getIntExtra("downloadsCode", Global.DOCUMENTS_AREA_CODE); + downloadsCode = getIntent().getIntExtra("downloadsCode", + Global.DOCUMENTS_AREA_CODE); grid = (GridView) this.findViewById(R.id.gridview); grid.setOnItemClickListener((new OnItemClickListener() { - public void onItemClick(AdapterView parent, View v, int position, long id) { - TextView text = (TextView) v.findViewById(R.id.icon_text); - String path = text.getText().toString(); - - ArrayList newBrowser = navigator.subDirectory(path); - ((NodeAdapter)grid.getAdapter()).change(newBrowser); - actualPathText.setText(navigator.getPath()); - - ((NodeAdapter)grid.getAdapter()).change(newBrowser); - } - })); - + public void onItemClick(AdapterView parent, View v, + int position, long id) { + TextView text = (TextView) v.findViewById(R.id.icon_text); + String chosenNodeName = text.getText().toString(); + updateView(navigator.goToSubDirectory(chosenNodeName)); + } + })); + + ImageButton homeButton = (ImageButton) this + .findViewById(R.id.home_button); + homeButton.setOnClickListener((new OnClickListener() { + + @Override + public void onClick(View v) { + updateView(navigator.goToRoot()); + } + + })); + + ImageButton parentButton = (ImageButton) this + .findViewById(R.id.parent_button); + parentButton.setOnClickListener((new OnClickListener() { + + @Override + public void onClick(View v) { + updateView(navigator.goToParentDirectory()); + } + + })); + + ImageButton refreshButton = (ImageButton) this + .findViewById(R.id.refresh_button); + refreshButton.setOnClickListener((new OnClickListener() { + + @Override + public void onClick(View v) { + + refresh = true; + Intent activity; + activity = new Intent(getBaseContext(), DirectoryTreeDownload.class); + activity.putExtra("treeCode", downloadsCode); + startActivityForResult(activity, Global.DIRECTORY_TREE_REQUEST_CODE); + + } + + })); + } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { 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 + if (resultCode == Activity.RESULT_OK) { + switch (requestCode) { + // After get the list of courses, a dialog is launched to choice the + // course case Global.DIRECTORY_TREE_REQUEST_CODE: tree = data.getStringExtra("tree"); - setMainView(); + if (!refresh) + setMainView(); + else { + refresh = false; + refresh(); + } break; } } } - - private void setMainView(){ - if(moduleIcon == null){ - if(downloadsCode == Global.DOCUMENTS_AREA_CODE){ - moduleIcon = (ImageView)this.findViewById(R.id.moduleIcon); - moduleIcon.setBackgroundResource(R.drawable.folder); - - moduleText = (TextView)this.findViewById(R.id.moduleName); - moduleText.setText(R.string.documentsDownloadModuleLabel); - }else{ //SHARE_AREA_CODE - moduleIcon = (ImageView)this.findViewById(R.id.moduleIcon); + + private void setMainView() { + if (moduleIcon == null) { + if (downloadsCode == Global.DOCUMENTS_AREA_CODE) { + moduleIcon = (ImageView) this.findViewById(R.id.moduleIcon); + moduleIcon.setBackgroundResource(R.drawable.folder); + + moduleText = (TextView) this.findViewById(R.id.moduleName); + moduleText.setText(R.string.documentsDownloadModuleLabel); + } else { // SHARE_AREA_CODE + moduleIcon = (ImageView) this.findViewById(R.id.moduleIcon); moduleIcon.setBackgroundResource(R.drawable.folderusers); - - moduleText = (TextView)this.findViewById(R.id.moduleName); - moduleText.setText(R.string.sharedsDownloadModuleLabel); + + moduleText = (TextView) this.findViewById(R.id.moduleName); + moduleText.setText(R.string.sharedsDownloadModuleLabel); } } - - - actualPathText= (TextView) this.findViewById(R.id.path); - + + currentPathText = (TextView) this.findViewById(R.id.path); + navigator = new DirectoryNavigator(tree); - //GridView - ArrayList r = (ArrayList) navigator.goToRoot(); - - String path = navigator.getPath() ; - actualPathText.setText(path); - - grid.setAdapter(new NodeAdapter(this,r)); + // GridView + ArrayList items = (ArrayList) navigator + .goToRoot(); + currentPathText.setText(navigator.getPath()); + grid.setAdapter(new NodeAdapter(this, items)); } - - - /*private OnClickListener homeClickListener = new OnClickListener(){ - - }*/ - -/* public class GridViewOnItemSelectedListener implements OnItemSelectedListener { - public void onItemSelected(AdapterView parent, - View view, int pos, long id) { - - String directoryName = parent.getItemAtPosition(pos).toString(); - - ArrayList newBrowser = navigator.subDirectory(directoryName); - String path = navigator.getPath(); - actualPathText.setText(path); - - ((NodeAdapter)grid.getAdapter()).change(newBrowser); - } + private void refresh() { + navigator.refresh(tree); - public void onNothingSelected(AdapterView parent) { - // Do nothing. - } - }*/ + } + private void updateView(ArrayList items) { + currentPathText.setText(navigator.getPath()); + ((NodeAdapter) grid.getAdapter()).change(items); + + } }