mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-26 14:21:16 +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;
|
package com.nutomic.syncthingandroid.activities;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
@ -194,8 +195,7 @@ public class MainActivity extends SyncthingActivity
|
||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
.replace(R.id.drawer, mLocalDeviceInfoFragment)
|
.replace(R.id.drawer, mLocalDeviceInfoFragment)
|
||||||
.commit();
|
.commit();
|
||||||
mDrawerToggle = mLocalDeviceInfoFragment.new Toggle(this, mDrawerLayout,
|
mDrawerToggle = new Toggle(this, mDrawerLayout, R.drawable.ic_drawer);
|
||||||
R.drawable.ic_drawer);
|
|
||||||
mDrawerLayout.setDrawerListener(mDrawerToggle);
|
mDrawerLayout.setDrawerListener(mDrawerToggle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,18 +259,6 @@ public class MainActivity extends SyncthingActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
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:
|
case R.id.web_gui:
|
||||||
startActivity(new Intent(this, WebGuiActivity.class));
|
startActivity(new Intent(this, WebGuiActivity.class));
|
||||||
return true;
|
return true;
|
||||||
|
@ -298,4 +286,29 @@ public class MainActivity extends SyncthingActivity
|
||||||
mDrawerToggle.onConfigurationChanged(newConfig);
|
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.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.ListFragment;
|
import android.support.v4.app.ListFragment;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
@ -46,6 +49,7 @@ public class DevicesFragment extends ListFragment implements SyncthingService.On
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
initAdapter();
|
initAdapter();
|
||||||
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initAdapter() {
|
private void initAdapter() {
|
||||||
|
@ -96,4 +100,23 @@ public class DevicesFragment extends ListFragment implements SyncthingService.On
|
||||||
startActivity(intent);
|
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.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
|
||||||
import android.support.v4.app.ListFragment;
|
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.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ public class FoldersFragment extends ListFragment implements SyncthingService.On
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
initAdapter();
|
initAdapter();
|
||||||
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initAdapter() {
|
private void initAdapter() {
|
||||||
|
@ -110,4 +112,23 @@ public class FoldersFragment extends ListFragment implements SyncthingService.On
|
||||||
return true;
|
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;
|
package com.nutomic.syncthingandroid.fragments;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.ActionBarDrawerToggle;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
@ -44,31 +41,22 @@ public class LocalDeviceInfoFragment extends Fragment
|
||||||
|
|
||||||
private MainActivity mActivity;
|
private MainActivity mActivity;
|
||||||
|
|
||||||
/**
|
public void onDrawerOpened() {
|
||||||
* Starts polling for status when opened, stops when closed.
|
mTimer = new Timer();
|
||||||
*/
|
mTimer.schedule(new TimerTask() {
|
||||||
public class Toggle extends ActionBarDrawerToggle {
|
@Override
|
||||||
public Toggle(Activity activity, DrawerLayout drawerLayout, int drawerImageRes) {
|
public void run() {
|
||||||
super(activity, drawerLayout, drawerImageRes, R.string.app_name, R.string.system_info);
|
updateGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
}, 0, SyncthingService.GUI_UPDATE_INTERVAL);
|
||||||
public void onDrawerClosed(View view) {
|
|
||||||
super.onDrawerClosed(view);
|
|
||||||
mTimer.cancel();
|
|
||||||
mTimer = null;
|
|
||||||
mActivity.getSupportActionBar().setTitle(R.string.app_name);
|
|
||||||
mActivity.supportInvalidateOptionsMenu();
|
mActivity.supportInvalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void onDrawerClosed() {
|
||||||
public void onDrawerOpened(View drawerView) {
|
mTimer.cancel();
|
||||||
super.onDrawerOpened(drawerView);
|
mTimer = null;
|
||||||
LocalDeviceInfoFragment.this.onDrawerOpened();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
@ -99,19 +87,6 @@ public class LocalDeviceInfoFragment extends Fragment
|
||||||
outState.putBoolean("active", mTimer != null);
|
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.
|
* 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"
|
android:title="@string/share_device_id"
|
||||||
app:showAsAction="ifRoom" />
|
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
|
<item
|
||||||
android:id="@+id/web_gui"
|
android:id="@+id/web_gui"
|
||||||
android:title="@string/web_gui_title" />
|
android:title="@string/web_gui_title" />
|
||||||
|
|
|
@ -59,10 +59,6 @@
|
||||||
|
|
||||||
<!-- LocalDeviceInfoFragment -->
|
<!-- 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 -->
|
<!-- Same as download_title with a colon and space appended -->
|
||||||
<string name="download_title_colon">Download:\u0020</string>
|
<string name="download_title_colon">Download:\u0020</string>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue