Merge branch 'develop' of git@github.com:Amab/SWADroid.git into develop

This commit is contained in:
Juan Miguel Boyero Corral 2012-12-15 16:06:16 +01:00
commit d241b47148
5 changed files with 119 additions and 44 deletions

View File

@ -180,7 +180,6 @@
android:name=".modules.downloads.DownloadsManager" android:name=".modules.downloads.DownloadsManager"
android:label="@string/documentsDownloadModuleLabel" android:label="@string/documentsDownloadModuleLabel"
android:theme="@android:style/Theme.NoTitleBar" android:theme="@android:style/Theme.NoTitleBar"
android:configChanges="orientation|keyboardHidden"
> >
</activity> </activity>
<activity <activity
@ -231,4 +230,4 @@
</service> </service>
</application> </application>
</manifest> </manifest>

View File

@ -8,5 +8,5 @@
# project structure. # project structure.
# Project target. # Project target.
target=android-17 target=android-14
android.library=false android.library=false

View File

@ -316,11 +316,11 @@ public class Test extends Model {
s = buff.toString().trim(); s = buff.toString().trim();
//Remove accents //Remove accents
s = s.replace('á', 'a'); s = s.replace('', 'a');
s = s.replace('e', 'e'); s = s.replace('Ž', 'e');
s = s.replace('í', 'i'); s = s.replace('', 'i');
s = s.replace('ó', 'o'); s = s.replace('', 'o');
s = s.replace('ú', 'u'); s = s.replace('œ', 'u');
return s; return s;
} }

View File

@ -82,6 +82,10 @@ public class DirectoryNavigator
return currentItems; return currentItems;
} }
public ArrayList<DirectoryItem> goToCurrentDirectory(){
return currentItems;
}
/** /**
* Travel inside a subdirectory. * Travel inside a subdirectory.
* @param directoryPosition The position of the subdirectory where we will travel. * @param directoryPosition The position of the subdirectory where we will travel.

View File

@ -123,6 +123,8 @@ public class DownloadsManager extends MenuActivity {
private TextView currentPathText; private TextView currentPathText;
String chosenNodeName = null; String chosenNodeName = null;
/** /**
* fileSize stores the size of the last file name chosen to be downloaded * fileSize stores the size of the last file name chosen to be downloaded
* */ * */
@ -137,7 +139,15 @@ public class DownloadsManager extends MenuActivity {
* Indicates if the menu no connection is visible * Indicates if the menu no connection is visible
* */ * */
private boolean noConnectionView = false; private boolean noConnectionView = false;
/**
* Indicates that the current state should be saved in case the activity is brought to background
* */
private boolean saveState = false;
/**
* Indicates if the state before the activity was brought to background has o not connection
* */
private boolean previousConnection = false;
@Override @Override
protected void onStart() { protected void onStart() {
@ -145,18 +155,28 @@ public class DownloadsManager extends MenuActivity {
List<Group> allGroups = dbHelper.getGroups(Global.getSelectedCourseCode()); List<Group> allGroups = dbHelper.getGroups(Global.getSelectedCourseCode());
int nGroups = allGroups.size(); int nGroups = allGroups.size();
if(nGroups != 0 || groupsRequested){ //groupsRequested is used to avoid continue requests of groups on courses that have not any group. if(!saveState){
myGroups = getFilteredGroups(); //only groups where the user is enrolled. if(nGroups != 0 || groupsRequested){ //groupsRequested is used to avoid continue requests of groups on courses that have not any group.
int nMyGroups = myGroups.size(); myGroups = getFilteredGroups(); //only groups where the user is enrolled.
this.loadGroupsSpinner(myGroups); int nMyGroups = myGroups.size();
// the tree request must be explicit only when there are not any groups(where the user is enrolled), and therefore any Spinner. this.loadGroupsSpinner(myGroups);
//in case there are groups(where the user is enrolled), it will be a spinner, and the tree request will be automatic made by OnItemSelectedListener // the tree request must be explicit only when there are not any groups(where the user is enrolled), and therefore any Spinner.
if(nMyGroups == 0 && tree == null) //in case there are groups(where the user is enrolled), it will be a spinner, and the tree request will be automatic made by OnItemSelectedListener
requestDirectoryTree(); if(nMyGroups == 0 && tree == null)
requestDirectoryTree();
}else{
Intent activity = new Intent(getBaseContext(),GroupTypes.class);
activity.putExtra("courseCode", Global.getSelectedCourseCode());
startActivityForResult(activity,Global.GROUPTYPES_REQUEST_CODE);
}
}else{ }else{
Intent activity = new Intent(getBaseContext(),GroupTypes.class); myGroups = getFilteredGroups();
activity.putExtra("courseCode", Global.getSelectedCourseCode()); this.loadGroupsSpinner(myGroups);
startActivityForResult(activity,Global.GROUPTYPES_REQUEST_CODE); if(previousConnection){
setMainView();
}else{
setNoConnectionView();
}
} }
} }
@ -164,6 +184,32 @@ public class DownloadsManager extends MenuActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if(savedInstanceState != null){
this.saveState = savedInstanceState.getBoolean("saveState", false);
if(saveState){
this.groupsRequested = true;
this.previousConnection = savedInstanceState.getBoolean("previousConnection", false);
this.chosenGroupCode = savedInstanceState.getLong("chosenGroupCode",0);
this.groupPosition = savedInstanceState.getInt("groupPosition",0);
if(previousConnection){
this.tree = savedInstanceState.getString("tree");
String path = savedInstanceState.getString("path");
this.navigator = new DirectoryNavigator(this.tree);
if(path.compareTo("/") !=0){
int firstBar = path.indexOf('/',0);
int nextBar = path.indexOf('/', firstBar+1);
while(nextBar != -1){
String dir = path.substring(firstBar+1, nextBar);
this.navigator.goToSubDirectory(dir);
firstBar = nextBar;
nextBar = path.indexOf('/', firstBar+1);
}
}
}
}
}
setContentView(R.layout.navigation); setContentView(R.layout.navigation);
downloadsAreaCode = getIntent().getIntExtra("downloadsAreaCode", downloadsAreaCode = getIntent().getIntExtra("downloadsAreaCode",
@ -234,6 +280,23 @@ public class DownloadsManager extends MenuActivity {
} }
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean("saveState", this.saveState);
if(this.saveState){
outState.putBoolean("previousConnection", this.previousConnection);
outState.putLong("chosenGroupCode", this.chosenGroupCode);
outState.putInt("groupPosition", this.groupPosition);
if(this.previousConnection){
outState.putString("tree", this.tree);
outState.putString("path", this.navigator.getPath());
}
}
}
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
@ -243,10 +306,9 @@ public class DownloadsManager extends MenuActivity {
// course // course
case Global.DIRECTORY_TREE_REQUEST_CODE: case Global.DIRECTORY_TREE_REQUEST_CODE:
tree = data.getStringExtra("tree"); tree = data.getStringExtra("tree");
setMainView(); if (!refresh){
if (!refresh)
setMainView(); setMainView();
else { }else {
refresh = false; refresh = false;
updateButton.setVisibility(View.VISIBLE); updateButton.setVisibility(View.VISIBLE);
progressbar.setVisibility(View.GONE); progressbar.setVisibility(View.GONE);
@ -254,8 +316,6 @@ public class DownloadsManager extends MenuActivity {
refresh(); refresh();
else else
setMainView(); setMainView();
} }
break; break;
case Global.GETFILE_REQUEST_CODE: case Global.GETFILE_REQUEST_CODE:
@ -284,7 +344,8 @@ public class DownloadsManager extends MenuActivity {
groupsRequested = true; groupsRequested = true;
myGroups = getFilteredGroups(); //only groups where the user is enrolled. myGroups = getFilteredGroups(); //only groups where the user is enrolled.
this.loadGroupsSpinner(myGroups); this.loadGroupsSpinner(myGroups);
requestDirectoryTree(); if(myGroups.size() == 0)
requestDirectoryTree();
break; break;
case Global.GROUPTYPES_REQUEST_CODE: case Global.GROUPTYPES_REQUEST_CODE:
Intent activity = new Intent(getBaseContext(),Groups.class); Intent activity = new Intent(getBaseContext(),Groups.class);
@ -319,6 +380,9 @@ public class DownloadsManager extends MenuActivity {
TextView courseNameText = (TextView) this.findViewById(R.id.courseSelectedText); TextView courseNameText = (TextView) this.findViewById(R.id.courseSelectedText);
courseNameText.setText(Global.getSelectedCourseShortName()); courseNameText.setText(Global.getSelectedCourseShortName());
this.saveState = true;
this.previousConnection = false;
} }
/** /**
* This method set the grid of nodes visible and paints the directory tree in its root node * This method set the grid of nodes visible and paints the directory tree in its root node
@ -332,12 +396,20 @@ public class DownloadsManager extends MenuActivity {
currentPathText = (TextView) this.findViewById(R.id.path); currentPathText = (TextView) this.findViewById(R.id.path);
navigator = new DirectoryNavigator(tree); ArrayList<DirectoryItem> items;
// GridView if(!(this.saveState && this.previousConnection)){
ArrayList<DirectoryItem> items = (ArrayList<DirectoryItem>) navigator navigator = new DirectoryNavigator(tree);
.goToRoot(); items = (ArrayList<DirectoryItem>) navigator
.goToRoot();
}else{
items = (ArrayList<DirectoryItem>) navigator.goToCurrentDirectory();
}
currentPathText.setText(navigator.getPath()); currentPathText.setText(navigator.getPath());
grid.setAdapter(new NodeAdapter(this, items)); grid.setAdapter(new NodeAdapter(this, items));
//this is used for the activity restart in case it was taken background
this.saveState = true;
this.previousConnection = true;
} }
/** /**
@ -564,19 +636,19 @@ public class DownloadsManager extends MenuActivity {
} }
/** // /**
* This method is launched instead of onCreate when device rotates // * This method is launched instead of onCreate when device rotates
* It prevents from repeating calls to web services when they are not necessary // * It prevents from repeating calls to web services when they are not necessary
* */ // * */
@Override // @Override
public void onConfigurationChanged(Configuration newConfig) { // public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig); // super.onConfigurationChanged(newConfig);
// Log.i(TAG,"Device rotation");
// Checks the orientation of the screen // // Checks the orientation of the screen
/* if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { ///* if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Log.i(TAG,"onConfigChanged - Landscape"); // Log.i(TAG,"onConfigChanged - Landscape");
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){ // } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Log.i(TAG,"onConfigChanged - Portrait"); // Log.i(TAG,"onConfigChanged - Portrait");
}*/ // }*/
} // }
} }