mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-27 13:21:30 +00:00
Only show "add folder/device" in that tab, and hide either in drawer (ref #110).
This commit is contained in:
parent
d7d35eb61e
commit
8d676855da
8 changed files with 108 additions and 69 deletions
|
@ -1,6 +1,7 @@
|
|||
package com.nutomic.syncthingandroid.activities;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ComponentName;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -194,8 +195,7 @@ public class MainActivity extends SyncthingActivity
|
|||
.beginTransaction()
|
||||
.replace(R.id.drawer, mLocalDeviceInfoFragment)
|
||||
.commit();
|
||||
mDrawerToggle = mLocalDeviceInfoFragment.new Toggle(this, mDrawerLayout,
|
||||
R.drawable.ic_drawer);
|
||||
mDrawerToggle = new Toggle(this, mDrawerLayout, R.drawable.ic_drawer);
|
||||
mDrawerLayout.setDrawerListener(mDrawerToggle);
|
||||
}
|
||||
|
||||
|
@ -259,18 +259,6 @@ public class MainActivity extends SyncthingActivity
|
|||
}
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.add_folder:
|
||||
Intent intent = new Intent(this, SettingsActivity.class)
|
||||
.setAction(SettingsActivity.ACTION_REPO_SETTINGS_FRAGMENT)
|
||||
.putExtra(SettingsActivity.EXTRA_IS_CREATE, true);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.add_device:
|
||||
intent = new Intent(this, SettingsActivity.class)
|
||||
.setAction(SettingsActivity.ACTION_NODE_SETTINGS_FRAGMENT)
|
||||
.putExtra(SettingsActivity.EXTRA_IS_CREATE, true);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.web_gui:
|
||||
startActivity(new Intent(this, WebGuiActivity.class));
|
||||
return true;
|
||||
|
@ -298,4 +286,29 @@ public class MainActivity extends SyncthingActivity
|
|||
mDrawerToggle.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives drawer opened and closed events.
|
||||
*/
|
||||
public class Toggle extends ActionBarDrawerToggle {
|
||||
public Toggle(Activity activity, DrawerLayout drawerLayout, int drawerImageRes) {
|
||||
super(activity, drawerLayout, drawerImageRes, R.string.app_name, R.string.app_name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
super.onDrawerOpened(drawerView);
|
||||
mLocalDeviceInfoFragment.onDrawerOpened();
|
||||
mFolderFragment.setHasOptionsMenu(false);
|
||||
mDevicesFragment.setHasOptionsMenu(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawerClosed(View view) {
|
||||
super.onDrawerClosed(view);
|
||||
mLocalDeviceInfoFragment.onDrawerClosed();
|
||||
mFolderFragment.setHasOptionsMenu(true);
|
||||
mDevicesFragment.setHasOptionsMenu(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@ package com.nutomic.syncthingandroid.fragments;
|
|||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
|
@ -46,6 +49,7 @@ public class DevicesFragment extends ListFragment implements SyncthingService.On
|
|||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
initAdapter();
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
private void initAdapter() {
|
||||
|
@ -96,4 +100,23 @@ public class DevicesFragment extends ListFragment implements SyncthingService.On
|
|||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.device_list, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.add_device:
|
||||
Intent intent = new Intent(getActivity(), SettingsActivity.class)
|
||||
.setAction(SettingsActivity.ACTION_NODE_SETTINGS_FRAGMENT)
|
||||
.putExtra(SettingsActivity.EXTRA_IS_CREATE, true);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.nutomic.syncthingandroid.fragments;
|
|||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
|
||||
|
@ -47,6 +48,7 @@ public class FoldersFragment extends ListFragment implements SyncthingService.On
|
|||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
initAdapter();
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
private void initAdapter() {
|
||||
|
@ -110,4 +112,23 @@ public class FoldersFragment extends ListFragment implements SyncthingService.On
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.folder_list, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.add_folder:
|
||||
Intent intent = new Intent(getActivity(), SettingsActivity.class)
|
||||
.setAction(SettingsActivity.ACTION_REPO_SETTINGS_FRAGMENT)
|
||||
.putExtra(SettingsActivity.EXTRA_IS_CREATE, true);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package com.nutomic.syncthingandroid.fragments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ActionBarDrawerToggle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
|
@ -44,31 +41,22 @@ public class LocalDeviceInfoFragment extends Fragment
|
|||
|
||||
private MainActivity mActivity;
|
||||
|
||||
/**
|
||||
* Starts polling for status when opened, stops when closed.
|
||||
*/
|
||||
public class Toggle extends ActionBarDrawerToggle {
|
||||
public Toggle(Activity activity, DrawerLayout drawerLayout, int drawerImageRes) {
|
||||
super(activity, drawerLayout, drawerImageRes, R.string.app_name, R.string.system_info);
|
||||
}
|
||||
public void onDrawerOpened() {
|
||||
mTimer = new Timer();
|
||||
mTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawerClosed(View view) {
|
||||
super.onDrawerClosed(view);
|
||||
mTimer.cancel();
|
||||
mTimer = null;
|
||||
mActivity.getSupportActionBar().setTitle(R.string.app_name);
|
||||
mActivity.supportInvalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
super.onDrawerOpened(drawerView);
|
||||
LocalDeviceInfoFragment.this.onDrawerOpened();
|
||||
}
|
||||
}, 0, SyncthingService.GUI_UPDATE_INTERVAL);
|
||||
mActivity.supportInvalidateOptionsMenu();
|
||||
}
|
||||
|
||||
;
|
||||
public void onDrawerClosed() {
|
||||
mTimer.cancel();
|
||||
mTimer = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
@ -99,19 +87,6 @@ public class LocalDeviceInfoFragment extends Fragment
|
|||
outState.putBoolean("active", mTimer != null);
|
||||
}
|
||||
|
||||
private void onDrawerOpened() {
|
||||
mTimer = new Timer();
|
||||
mTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateGui();
|
||||
}
|
||||
|
||||
}, 0, SyncthingService.GUI_UPDATE_INTERVAL);
|
||||
mActivity.getSupportActionBar().setTitle(R.string.system_info);
|
||||
mActivity.supportInvalidateOptionsMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes status callbacks.
|
||||
*/
|
||||
|
|
11
src/main/res/menu/device_list.xml
Normal file
11
src/main/res/menu/device_list.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/add_device"
|
||||
android:title="@string/add_device"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
</menu>
|
11
src/main/res/menu/folder_list.xml
Normal file
11
src/main/res/menu/folder_list.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/add_folder"
|
||||
android:title="@string/add_folder"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
</menu>
|
|
@ -9,17 +9,6 @@
|
|||
android:title="@string/share_device_id"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/add_folder"
|
||||
android:title="@string/add_folder"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/add_device"
|
||||
android:title="@string/add_device"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
|
||||
<item
|
||||
android:id="@+id/web_gui"
|
||||
android:title="@string/web_gui_title" />
|
||||
|
|
|
@ -59,10 +59,6 @@
|
|||
|
||||
<!-- LocalDeviceInfoFragment -->
|
||||
|
||||
|
||||
<!-- ActionBar title shown when the drawer is open -->
|
||||
<string name="system_info">System Info</string>
|
||||
|
||||
<!-- Same as download_title with a colon and space appended -->
|
||||
<string name="download_title_colon">Download:\u0020</string>
|
||||
|
||||
|
|
Loading…
Reference in a new issue