Skip to content

Commit

Permalink
Merge branch 'connection-indicator'
Browse files Browse the repository at this point in the history
  • Loading branch information
arturdryomov committed Jun 20, 2014
2 parents 11188c2 + 36d341e commit c1ba936
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 49 deletions.
16 changes: 0 additions & 16 deletions src/main/java/org/amahi/anywhere/activity/ServerFilesActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,6 @@ protected void onPostCreate(Bundle savedInstanceState) {
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.action_bar_navigation, menu);

return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if (isNavigationDrawerAvailable()) {
Expand All @@ -310,25 +303,16 @@ public boolean onPrepareOptionsMenu(Menu menu) {

private void setUpMenu(Menu menu) {
MenuItem sortMenuItem = menu.findItem(R.id.menu_sort);
MenuItem connectionMenuItem = menu.findItem(R.id.menu_connection);

if (sortMenuItem != null) {
sortMenuItem.setVisible(!isNavigationDrawerOpen());
}

if (connectionMenuItem != null) {
connectionMenuItem.setVisible(!isNavigationDrawerOpen() && !isConnectionLocal());
}
}

private boolean isNavigationDrawerOpen() {
return getDrawer().isDrawerOpen(findViewById(R.id.container_navigation));
}

private boolean isConnectionLocal() {
return serverClient.isConnected() && serverClient.isConnectionLocal();
}

@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (isNavigationDrawerAvailable() && navigationDrawerToggle.onOptionsItemSelected(menuItem)) {
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/org/amahi/anywhere/fragment/NavigationFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.app.Fragment;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -150,7 +151,7 @@ private void setUpServers(String authenticationToken) {
setUpServersContent(authenticationToken);

setUpServersListener();
setUpServersConnectionListener();
setUpServerConnectionListener();
}

private void setUpServersAdapter() {
Expand Down Expand Up @@ -244,6 +245,7 @@ private void setUpSharesListener() {
private void setUpServerConnection(Server server) {
if (serverClient.isConnected(server)) {
setUpServerConnection();
setUpServerConnectionIndicator();
} else {
serverClient.connect(server);
}
Expand All @@ -252,6 +254,7 @@ private void setUpServerConnection(Server server) {
@Subscribe
public void onServerConnected(ServerConnectedEvent event) {
setUpServerConnection();
setUpServerConnectionIndicator();
}

private void setUpServerConnection() {
Expand All @@ -272,6 +275,18 @@ private Switch getConnectionSwitch() {
return (Switch) getView().findViewById(R.id.switch_connection);
}

private void setUpServerConnectionIndicator() {
getActivity().getActionBar().setBackgroundDrawable(getServerConnectionIndicator());
}

private Drawable getServerConnectionIndicator() {
if (isConnectionLocal()) {
return getResources().getDrawable(R.drawable.bg_action_bar);
} else {
return getResources().getDrawable(R.drawable.bg_action_bar_warning);
}
}

private void setUpSharesContent() {
serverClient.getShares();
}
Expand Down Expand Up @@ -320,13 +335,14 @@ public void onItemClick(AdapterView<?> listView, View view, int position, long i
BusProvider.getBus().post(new ShareSelectedEvent(share));
}

private void setUpServersConnectionListener() {
private void setUpServerConnectionListener() {
getConnectionSwitch().setOnCheckedChangeListener(this);
}

@Override
public void onCheckedChanged(CompoundButton button, boolean isChecked) {
setUpServerConnection();
setUpServerConnectionIndicator();
}

@Override
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
31 changes: 0 additions & 31 deletions src/main/res/menu/action_bar_navigation.xml

This file was deleted.

0 comments on commit c1ba936

Please sign in to comment.