Browse Source

Fixed navigation behavior

Lennart Rosam 13 years ago
parent
commit
a66be3bc47

+ 18 - 12
src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java

@@ -137,9 +137,26 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
 			showDialog(0);
 			break;
 		}
+		case android.R.id.home: {
+			navigateUp();
+			break;
+		}
+			
 		}
 		return true;
 	}
+	
+	public void navigateUp(){
+		popPath();
+		if(mDirectories.getCount() == 0) {
+			Intent intent = new Intent(this, LandingActivity.class);
+			intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+			startActivity(intent);
+			return;
+		}
+		((FileList) getSupportFragmentManager().findFragmentById(R.id.fileList))
+				.onNavigateUp();
+	}
 
 	@Override
 	protected Dialog onCreateDialog(int id) {
@@ -191,22 +208,11 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
 	public boolean onNavigationItemSelected(int itemPosition, long itemId) {
 		int i = itemPosition;
 		while (i-- != 0) {
-			onBackPressed();
+			navigateUp();
 		}
 		return true;
 	}
 
-	@Override
-	public void onBackPressed() {
-		popPath();
-		if (mDirectories.getCount() == 0) {
-			super.onBackPressed();
-			return;
-		}
-		((FileList) getSupportFragmentManager().findFragmentById(R.id.fileList))
-				.onBackPressed();
-	}
-
 	private class DirectoryCreator implements Runnable {
 		private String mTargetPath;
 		private Account mAccount;

+ 8 - 0
src/eu/alefzero/owncloud/ui/activity/Preferences.java

@@ -36,6 +36,7 @@ import android.view.ContextMenu.ContextMenuInfo;
 import android.view.View;
 import android.widget.AdapterView.AdapterContextMenuInfo;
 
+import com.actionbarsherlock.app.ActionBar;
 import com.actionbarsherlock.app.SherlockPreferenceActivity;
 import com.actionbarsherlock.view.Menu;
 import com.actionbarsherlock.view.MenuInflater;
@@ -70,6 +71,8 @@ public class Preferences extends SherlockPreferenceActivity implements OnPrefere
     addPreferencesFromResource(R.xml.preferences);
     registerForContextMenu(getListView());
     populateAccountList();
+    ActionBar actionBar = getSherlock().getActionBar();
+    actionBar.setDisplayHomeAsUpEnabled(true);
     //populateSessionList();
   }
   
@@ -151,6 +154,11 @@ public class Preferences extends SherlockPreferenceActivity implements OnPrefere
         mSessions.remove(ocs);
         getPreferenceScreen().removePreference(getPreferenceScreen().getPreference(mSelectedMenuItem+1));
         break;
+      case android.R.id.home:
+    	  intent = new Intent(getBaseContext(), LandingActivity.class);
+    	  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+    	  startActivity(intent);
+    	  break;
       default:
         Log.w(TAG, "Unknown menu item triggered");
         return false;

+ 1 - 0
src/eu/alefzero/owncloud/ui/adapter/LandingScreenAdapter.java

@@ -75,6 +75,7 @@ public class LandingScreenAdapter extends BaseAdapter {
 			 */
 			intent.setClass(mContext, FileDisplayActivity.class);	
 			intent.putExtra("ACCOUNT", AuthUtils.getCurrentOwnCloudAccount(mContext));
+			intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 			break;
 		case 5:
 			intent.setClass(mContext, Preferences.class);

+ 11 - 8
src/eu/alefzero/owncloud/ui/fragment/FileList.java

@@ -17,17 +17,12 @@
  */
 package eu.alefzero.owncloud.ui.fragment;
 
-import java.util.ArrayList;
 import java.util.Stack;
 import java.util.Vector;
 
 import android.accounts.Account;
-import android.content.ContentProviderOperation;
 import android.content.Intent;
 import android.os.Bundle;
-import android.provider.ContactsContract;
-import android.provider.ContactsContract.RawContacts;
-import android.util.Log;
 import android.view.View;
 import android.widget.AdapterView;
 import eu.alefzero.owncloud.R;
@@ -58,6 +53,7 @@ public class FileList extends FragmentListView {
 
     mAccount = AuthUtils.getCurrentOwnCloudAccount(getActivity());
     populateFileList();
+    // TODO: Remove this testing stuff
     //addContact(mAccount, "Bartek Przybylski", "czlowiek");
   }
   
@@ -90,11 +86,17 @@ public class FileList extends FragmentListView {
     }
   }
 
-  public void onBackPressed() {
+  /**
+   * Call this, when the user presses the up button
+   */
+  public void onNavigateUp() {
     mDirNames.pop();
     populateFileList();
   }
 
+  /**
+   * Lists the directory
+   */
   private void populateFileList() {
     String s = "/";
     for (String a : mDirNames)
@@ -105,7 +107,8 @@ public class FileList extends FragmentListView {
     setListAdapter(new FileListListAdapter(file, getActivity()));
   }
   
-  private  void addContact(Account account, String name, String username) {
+  //TODO: Delete this testing stuff.
+  /*private  void addContact(Account account, String name, String username) {
     Log.i("ASD", "Adding contact: " + name);
     ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
     
@@ -138,6 +141,6 @@ public class FileList extends FragmentListView {
      Log.e("ASD", "Something went wrong during creation! " + e);
      e.printStackTrace();
     }
-   }
+   }*/
   
 }