From 9fbc8efcd19e9a9f9de4273fb7124606a944512d Mon Sep 17 00:00:00 2001 From: Logan Date: Sat, 21 Nov 2015 18:06:38 +0800 Subject: [PATCH 1/2] correct behaviors of home up button among tabs --- src/com/seafile/seadroid2/ui/activity/BrowserActivity.java | 2 +- src/com/seafile/seadroid2/ui/fragment/ReposFragment.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/com/seafile/seadroid2/ui/activity/BrowserActivity.java b/src/com/seafile/seadroid2/ui/activity/BrowserActivity.java index 9535fdc9c..81a5580ba 100644 --- a/src/com/seafile/seadroid2/ui/activity/BrowserActivity.java +++ b/src/com/seafile/seadroid2/ui/activity/BrowserActivity.java @@ -734,7 +734,7 @@ public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: - if (navContext.inRepo()) { + if (navContext.inRepo() && currentPosition == 0) { onBackPressed(); } return true; diff --git a/src/com/seafile/seadroid2/ui/fragment/ReposFragment.java b/src/com/seafile/seadroid2/ui/fragment/ReposFragment.java index a6c6e4a71..cc58c9346 100644 --- a/src/com/seafile/seadroid2/ui/fragment/ReposFragment.java +++ b/src/com/seafile/seadroid2/ui/fragment/ReposFragment.java @@ -439,7 +439,9 @@ public void refreshView(boolean forceRefresh) { NavContext navContext = getNavContext(); if (navContext.inRepo()) { - mActivity.enableUpButton(); + if (mActivity.getCurrentPosition() == 0) { + mActivity.enableUpButton(); + } navToDirectory(forceRefresh); } else { mActivity.disableUpButton(); @@ -488,8 +490,6 @@ public void navToDirectory(boolean forceRefresh) { NavContext nav = getNavContext(); DataManager dataManager = getDataManager(); - mActivity.enableUpButton(); - SeafRepo repo = getDataManager().getCachedRepoByID(nav.getRepoID()); if (repo != null) { adapter.setEncryptedRepo(repo.encrypted); From 24fe0da672c7e7067787f998c3a3eb5c65573578 Mon Sep 17 00:00:00 2001 From: Logan Date: Sat, 21 Nov 2015 18:08:16 +0800 Subject: [PATCH 2/2] improve code style --- .../ui/activity/BrowserActivity.java | 36 ++++++++++--------- .../seadroid2/ui/fragment/ReposFragment.java | 2 +- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/com/seafile/seadroid2/ui/activity/BrowserActivity.java b/src/com/seafile/seadroid2/ui/activity/BrowserActivity.java index 81a5580ba..b4c378493 100644 --- a/src/com/seafile/seadroid2/ui/activity/BrowserActivity.java +++ b/src/com/seafile/seadroid2/ui/activity/BrowserActivity.java @@ -83,6 +83,10 @@ public class BrowserActivity extends SherlockFragmentActivity public static final String CHOOSE_APP_DIALOG_FRAGMENT_TAG = "choose_app_fragment"; public static final String PICK_FILE_DIALOG_FRAGMENT_TAG = "pick_file_fragment"; + public static final int INDEX_LIBRARY_TAB = 0; + public static final int INDEX_STARRED_TAB = 1; + public static final int INDEX_ACTIVITIES_TAB = 2; + private static final int[] ICONS = new int[] { R.drawable.tab_library, R.drawable.tab_starred, R.drawable.tab_activity @@ -231,7 +235,7 @@ public void onPageSelected(final int position) { currentPosition = position; supportInvalidateOptionsMenu(); pager.setCurrentItem(position); - if (currentPosition != 0) { + if (currentPosition != INDEX_LIBRARY_TAB) { disableUpButton(); } else if (navContext.inRepo()) { enableUpButton(); @@ -734,7 +738,7 @@ public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: - if (navContext.inRepo() && currentPosition == 0) { + if (navContext.inRepo() && currentPosition == INDEX_LIBRARY_TAB) { onBackPressed(); } return true; @@ -763,7 +767,7 @@ public boolean onOptionsItemSelected(MenuItem item) { ToastUtils.show(this, R.string.network_down); return true; } - if (currentPosition == 0) { + if (currentPosition == INDEX_LIBRARY_TAB) { if (navContext.inRepo()) { SeafRepo repo = dataManager.getCachedRepoByID(navContext.getRepoID()); if (repo.encrypted && !DataManager.getRepoPasswordSet(repo.id)) { @@ -781,9 +785,9 @@ public void onTaskSuccess() { } getReposFragment().refresh(); - } else if (currentPosition == 2) { + } else if (currentPosition == INDEX_ACTIVITIES_TAB) { getActivitiesFragment().refreshView(); - } else if (currentPosition == 1) { + } else if (currentPosition == INDEX_STARRED_TAB) { getStarredFragment().refresh(); } return true; @@ -794,7 +798,7 @@ public void onTaskSuccess() { ToastUtils.show(this, R.string.network_down); return true; } - if (currentPosition == 0) { + if (currentPosition == INDEX_LIBRARY_TAB) { if (navContext.inRepo()) { SeafRepo repo = dataManager.getCachedRepoByID(navContext.getRepoID()); if (repo.encrypted && !DataManager.getRepoPasswordSet(repo.id)) { @@ -900,7 +904,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) * @param type */ private void sortFiles(final int type, final int order) { - if (currentPosition == 0) { + if (currentPosition == INDEX_LIBRARY_TAB) { if (navContext.inRepo()) { SeafRepo repo = dataManager.getCachedRepoByID(navContext.getRepoID()); if (repo.encrypted && !DataManager.getRepoPasswordSet(repo.id)) { @@ -976,7 +980,7 @@ private void showNewDirDialog() { public void onTaskSuccess() { ToastUtils.show(BrowserActivity.this, "Sucessfully created folder " + dialog.getNewDirName()); ReposFragment reposFragment = getReposFragment(); - if (currentPosition == 0 && reposFragment != null) { + if (currentPosition == INDEX_LIBRARY_TAB && reposFragment != null) { reposFragment.refreshView(); } } @@ -997,7 +1001,7 @@ private void showNewFileDialog() { public void onTaskSuccess() { ToastUtils.show(BrowserActivity.this, "Sucessfully created file " + dialog.getNewFileName()); ReposFragment reposFragment = getReposFragment(); - if (currentPosition == 0 && reposFragment != null) { + if (currentPosition == INDEX_LIBRARY_TAB && reposFragment != null) { reposFragment.refreshView(); } } @@ -1059,7 +1063,7 @@ private void setUpButtonTitleOnSlideTabs(int position) { if (navContext == null) return; - if (position == 0) { + if (position == INDEX_LIBRARY_TAB) { if (navContext.inRepo()) { if (navContext.getDirPath().equals(BrowserActivity.ACTIONBAR_PARENT_PATH)) { setUpButtonTitle(navContext.getRepoName()); @@ -1494,7 +1498,7 @@ public void onBackPressed() { return; } - if (currentSelectedItem == FILES_VIEW && currentPosition == 0) { + if (currentSelectedItem == FILES_VIEW && currentPosition == INDEX_LIBRARY_TAB) { if (navContext.inRepo()) { if (navContext.isRepoRoot()) { navContext.setRepoID(null); @@ -1632,7 +1636,7 @@ private void doRename(String repoID, String repoName, String path, boolean isdir public void onTaskSuccess() { ToastUtils.show(BrowserActivity.this, R.string.rename_successful); ReposFragment reposFragment = getReposFragment(); - if (currentPosition == 0 && reposFragment != null) { + if (currentPosition == INDEX_LIBRARY_TAB && reposFragment != null) { reposFragment.refreshView(); } } @@ -1656,7 +1660,7 @@ private void doDelete(String repoID, String repoName, String path, boolean isdir public void onTaskSuccess() { ToastUtils.show(BrowserActivity.this, R.string.delete_successful); ReposFragment reposFragment = getReposFragment(); - if (currentPosition == 0 && reposFragment != null) { + if (currentPosition == INDEX_LIBRARY_TAB && reposFragment != null) { reposFragment.refreshView(); } } @@ -1723,7 +1727,7 @@ public void onTaskSuccess() { if (copyMoveContext.isMove()) { ReposFragment reposFragment = getReposFragment(); - if (currentPosition == 0 && reposFragment != null) { + if (currentPosition == INDEX_LIBRARY_TAB && reposFragment != null) { reposFragment.refreshView(); } } @@ -1748,7 +1752,7 @@ private void onFileDownloadFailed(int taskID) { if (err != null && err.getCode() == SeafConnection.HTTP_STATUS_REPO_PASSWORD_REQUIRED) { - if (currentPosition == 0 + if (currentPosition == INDEX_LIBRARY_TAB && repoID.equals(navContext.getRepoID()) && Utils.getParentPath(path) .equals(navContext.getDirPath())) { @@ -1782,7 +1786,7 @@ private void onFileUploaded(int taskID) { String repoID = info.repoID; String dir = info.parentDir; - if (currentPosition == 0 + if (currentPosition == INDEX_LIBRARY_TAB && repoID.equals(navContext.getRepoID()) && dir.equals(navContext.getDirPath())) { getReposFragment().refreshView(true); diff --git a/src/com/seafile/seadroid2/ui/fragment/ReposFragment.java b/src/com/seafile/seadroid2/ui/fragment/ReposFragment.java index cc58c9346..71bacb270 100644 --- a/src/com/seafile/seadroid2/ui/fragment/ReposFragment.java +++ b/src/com/seafile/seadroid2/ui/fragment/ReposFragment.java @@ -439,7 +439,7 @@ public void refreshView(boolean forceRefresh) { NavContext navContext = getNavContext(); if (navContext.inRepo()) { - if (mActivity.getCurrentPosition() == 0) { + if (mActivity.getCurrentPosition() == BrowserActivity.INDEX_LIBRARY_TAB) { mActivity.enableUpButton(); } navToDirectory(forceRefresh);