mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-23 04:41:16 +00:00
Refresh drawer items when opening (fixes #217).
Also close the drawer when navigating away.
This commit is contained in:
parent
489a15edb6
commit
9ed5fe0c20
6 changed files with 50 additions and 26 deletions
|
@ -10,7 +10,7 @@ import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.ActionBarDrawerToggle;
|
import android.support.v7.app.ActionBarDrawerToggle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentPagerAdapter;
|
import android.support.v4.app.FragmentPagerAdapter;
|
||||||
|
@ -20,6 +20,7 @@ import android.support.v4.widget.DrawerLayout;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.ActionBar.Tab;
|
import android.support.v7.app.ActionBar.Tab;
|
||||||
import android.support.v7.app.ActionBar.TabListener;
|
import android.support.v7.app.ActionBar.TabListener;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -193,7 +194,7 @@ public class MainActivity extends SyncthingActivity
|
||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
.replace(R.id.drawer, mDrawerFragment)
|
.replace(R.id.drawer, mDrawerFragment)
|
||||||
.commit();
|
.commit();
|
||||||
mDrawerToggle = new Toggle(this, mDrawerLayout, R.drawable.ic_drawer);
|
mDrawerToggle = new Toggle(this, mDrawerLayout);
|
||||||
mDrawerLayout.setDrawerListener(mDrawerToggle);
|
mDrawerLayout.setDrawerListener(mDrawerToggle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,11 +246,7 @@ public class MainActivity extends SyncthingActivity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
if (mDrawerToggle.onOptionsItemSelected(item)) {
|
return mDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -257,8 +254,8 @@ public class MainActivity extends SyncthingActivity
|
||||||
* Receives drawer opened and closed events.
|
* Receives drawer opened and closed events.
|
||||||
*/
|
*/
|
||||||
public class Toggle extends ActionBarDrawerToggle {
|
public class Toggle extends ActionBarDrawerToggle {
|
||||||
public Toggle(Activity activity, DrawerLayout drawerLayout, int drawerImageRes) {
|
public Toggle(Activity activity, DrawerLayout drawerLayout) {
|
||||||
super(activity, drawerLayout, drawerImageRes, R.string.app_name, R.string.app_name);
|
super(activity, drawerLayout, R.string.app_name, R.string.app_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -278,4 +275,11 @@ public class MainActivity extends SyncthingActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the drawer. Use when navigating away from activity.
|
||||||
|
*/
|
||||||
|
public void closeDrawer() {
|
||||||
|
mDrawerLayout.closeDrawer(Gravity.START);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,8 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
|
||||||
|
|
||||||
private TextView mAnnounceServer;
|
private TextView mAnnounceServer;
|
||||||
|
|
||||||
|
private ListView mList;
|
||||||
|
|
||||||
private Timer mTimer;
|
private Timer mTimer;
|
||||||
|
|
||||||
private MainActivity mActivity;
|
private MainActivity mActivity;
|
||||||
|
@ -88,6 +90,12 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
|
||||||
}, 0, SyncthingService.GUI_UPDATE_INTERVAL);
|
}, 0, SyncthingService.GUI_UPDATE_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
initMenu();
|
||||||
|
}
|
||||||
|
|
||||||
public void onDrawerClosed() {
|
public void onDrawerClosed() {
|
||||||
mTimer.cancel();
|
mTimer.cancel();
|
||||||
mTimer = null;
|
mTimer = null;
|
||||||
|
@ -105,22 +113,30 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
|
||||||
mDownload = (TextView) view.findViewById(R.id.download);
|
mDownload = (TextView) view.findViewById(R.id.download);
|
||||||
mUpload = (TextView) view.findViewById(R.id.upload);
|
mUpload = (TextView) view.findViewById(R.id.upload);
|
||||||
mAnnounceServer = (TextView) view.findViewById(R.id.announce_server);
|
mAnnounceServer = (TextView) view.findViewById(R.id.announce_server);
|
||||||
|
mList = (ListView) view.findViewById(android.R.id.list);
|
||||||
|
|
||||||
ArrayList<Pair<Integer, Integer>> items = new ArrayList<>();
|
initMenu();
|
||||||
items.add(new Pair<>(R.drawable.ic_action_share, R.string.share_device_id));
|
mList.setOnItemClickListener(this);
|
||||||
items.add(new Pair<>(R.drawable.ic_menu_browser, R.string.web_gui_title));
|
|
||||||
items.add(new Pair<>(R.drawable.ic_action_settings, R.string.settings_title));
|
|
||||||
items.add(new Pair<>(R.drawable.ic_action_donate, R.string.donate));
|
|
||||||
if (!SyncthingService.alwaysRunInBackground(getActivity())) {
|
|
||||||
items.add(new Pair<>(R.drawable.ic_menu_close_clear_cancel, R.string.exit));
|
|
||||||
}
|
|
||||||
ListView list = (ListView) view.findViewById(android.R.id.list);
|
|
||||||
list.setAdapter(new MenuAdapter(getActivity(), items));
|
|
||||||
list.setOnItemClickListener(this);
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repopulates menu items.
|
||||||
|
*/
|
||||||
|
private void initMenu() {
|
||||||
|
MenuAdapter adapter =
|
||||||
|
new MenuAdapter(getActivity(), new ArrayList<Pair<Integer, Integer>>());
|
||||||
|
adapter.add(new Pair<>(R.drawable.ic_action_share, R.string.share_device_id));
|
||||||
|
adapter.add(new Pair<>(R.drawable.ic_menu_browser, R.string.web_gui_title));
|
||||||
|
adapter.add(new Pair<>(R.drawable.ic_action_settings, R.string.settings_title));
|
||||||
|
adapter.add(new Pair<>(R.drawable.ic_action_donate, R.string.donate));
|
||||||
|
if (!SyncthingService.alwaysRunInBackground(getActivity()))
|
||||||
|
adapter.add(new Pair<>(R.drawable.ic_menu_close_clear_cancel, R.string.exit));
|
||||||
|
|
||||||
|
mList.setAdapter(adapter);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
@ -197,18 +213,22 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
startActivity(new Intent(mActivity, WebGuiActivity.class));
|
startActivity(new Intent(mActivity, WebGuiActivity.class));
|
||||||
|
mActivity.closeDrawer();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
startActivity(new Intent(mActivity, SettingsActivity.class)
|
startActivity(new Intent(mActivity, SettingsActivity.class)
|
||||||
.setAction(SettingsActivity.ACTION_APP_SETTINGS_FRAGMENT));
|
.setAction(SettingsActivity.ACTION_APP_SETTINGS_FRAGMENT));
|
||||||
|
mActivity.closeDrawer();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
startActivity(new Intent(
|
startActivity(new Intent(
|
||||||
Intent.ACTION_VIEW, Uri.parse(getString(R.string.donate_url))));
|
Intent.ACTION_VIEW, Uri.parse(getString(R.string.donate_url))));
|
||||||
|
mActivity.closeDrawer();
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
mActivity.stopService(new Intent(mActivity, SyncthingService.class));
|
mActivity.stopService(new Intent(mActivity, SyncthingService.class));
|
||||||
mActivity.finish();
|
mActivity.finish();
|
||||||
|
mActivity.closeDrawer();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 202 B |
Loading…
Reference in a new issue