Skip to content

Commit

Permalink
Merge pull request #446 from Logan676/fix_home_up_error
Browse files Browse the repository at this point in the history
Correct behaviors of home up button when sliding among tabs
  • Loading branch information
Logan676 committed Nov 21, 2015
2 parents 569e088 + 24fe0da commit fcd43eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
36 changes: 20 additions & 16 deletions src/com/seafile/seadroid2/ui/activity/BrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -734,7 +738,7 @@ public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
case android.R.id.home:
if (navContext.inRepo()) {
if (navContext.inRepo() && currentPosition == INDEX_LIBRARY_TAB) {
onBackPressed();
}
return true;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
Expand All @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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())) {
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/com/seafile/seadroid2/ui/fragment/ReposFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ public void refreshView(boolean forceRefresh) {

NavContext navContext = getNavContext();
if (navContext.inRepo()) {
mActivity.enableUpButton();
if (mActivity.getCurrentPosition() == BrowserActivity.INDEX_LIBRARY_TAB) {
mActivity.enableUpButton();
}
navToDirectory(forceRefresh);
} else {
mActivity.disableUpButton();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fcd43eb

Please sign in to comment.