1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-23 04:41:16 +00:00

Use ActionBar icon instead of preference item for delete repo/node.

This commit is contained in:
Felix Ableitner 2014-08-04 00:55:33 +02:00
parent d78319ee00
commit 76e87932f9
10 changed files with 44 additions and 49 deletions

View file

@ -68,8 +68,6 @@ public class NodeSettingsFragment extends PreferenceFragment implements
private Preference mCurrentAddress; private Preference mCurrentAddress;
private Preference mDelete;
private boolean mIsCreate; private boolean mIsCreate;
@Override @Override
@ -96,9 +94,7 @@ public class NodeSettingsFragment extends PreferenceFragment implements
mVersion = findPreference("version"); mVersion = findPreference("version");
mVersion.setSummary("?"); mVersion.setSummary("?");
mCurrentAddress = findPreference("current_address"); mCurrentAddress = findPreference("current_address");
mDelete = findPreference("delete");
mCurrentAddress.setSummary("?"); mCurrentAddress.setSummary("?");
mDelete.setOnPreferenceClickListener(this);
} }
getActivity().bindService(new Intent(getActivity(), SyncthingService.class), getActivity().bindService(new Intent(getActivity(), SyncthingService.class),
@ -152,6 +148,7 @@ public class NodeSettingsFragment extends PreferenceFragment implements
public void onPrepareOptionsMenu(Menu menu) { public void onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.create).setVisible(mIsCreate); menu.findItem(R.id.create).setVisible(mIsCreate);
menu.findItem(R.id.share_node_id).setVisible(!mIsCreate); menu.findItem(R.id.share_node_id).setVisible(!mIsCreate);
menu.findItem(R.id.delete).setVisible(!mIsCreate);
} }
@Override @Override
@ -173,6 +170,19 @@ public class NodeSettingsFragment extends PreferenceFragment implements
case R.id.share_node_id: case R.id.share_node_id:
RestApi.shareNodeId(getActivity(), mNode.NodeID); RestApi.shareNodeId(getActivity(), mNode.NodeID);
return true; return true;
case R.id.delete:
new AlertDialog.Builder(getActivity())
.setMessage(R.string.delete_node_confirm)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
mSyncthingService.getApi().deleteNode(mNode, getActivity());
getActivity().finish();
}
})
.setNegativeButton(android.R.string.no, null)
.show();
return true;
case android.R.id.home: case android.R.id.home:
getActivity().finish(); getActivity().finish();
return true; return true;
@ -214,21 +224,7 @@ public class NodeSettingsFragment extends PreferenceFragment implements
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
if (preference.equals(mDelete)) { if (preference.equals(mNodeId)) {
new AlertDialog.Builder(getActivity())
.setMessage(R.string.delete_node_confirm)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
mSyncthingService.getApi().deleteNode(mNode, getActivity());
getActivity().finish();
}
})
.setNegativeButton(android.R.string.no, null)
.show();
return true;
}
else if (preference.equals(mNodeId)) {
mSyncthingService.getApi().copyNodeId(mNode.NodeID); mSyncthingService.getApi().copyNodeId(mNode.NodeID);
return true; return true;
} }

View file

@ -77,8 +77,6 @@ public class RepoSettingsFragment extends PreferenceFragment
private EditTextPreference mVersioningKeep; private EditTextPreference mVersioningKeep;
private Preference mDelete;
private boolean mIsCreate; private boolean mIsCreate;
@Override @Override
@ -107,10 +105,6 @@ public class RepoSettingsFragment extends PreferenceFragment
mVersioning.setOnPreferenceChangeListener(this); mVersioning.setOnPreferenceChangeListener(this);
mVersioningKeep = (EditTextPreference) findPreference("versioning_keep"); mVersioningKeep = (EditTextPreference) findPreference("versioning_keep");
mVersioningKeep.setOnPreferenceChangeListener(this); mVersioningKeep.setOnPreferenceChangeListener(this);
if (!mIsCreate) {
mDelete = findPreference("delete");
mDelete.setOnPreferenceClickListener(this);
}
getActivity().bindService(new Intent(getActivity(), SyncthingService.class), getActivity().bindService(new Intent(getActivity(), SyncthingService.class),
mSyncthingServiceConnection, Context.BIND_AUTO_CREATE); mSyncthingServiceConnection, Context.BIND_AUTO_CREATE);
@ -182,6 +176,7 @@ public class RepoSettingsFragment extends PreferenceFragment
@Override @Override
public void onPrepareOptionsMenu(Menu menu) { public void onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.create).setVisible(mIsCreate); menu.findItem(R.id.create).setVisible(mIsCreate);
menu.findItem(R.id.delete).setVisible(!mIsCreate);
} }
@Override @Override
@ -201,6 +196,19 @@ public class RepoSettingsFragment extends PreferenceFragment
mSyncthingService.getApi().editRepo(mRepo, true, getActivity()); mSyncthingService.getApi().editRepo(mRepo, true, getActivity());
getActivity().finish(); getActivity().finish();
return true; return true;
case R.id.delete:
new AlertDialog.Builder(getActivity())
.setMessage(R.string.delete_repo_confirm)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
mSyncthingService.getApi().deleteRepo(mRepo, getActivity());
getActivity().finish();
}
})
.setNegativeButton(android.R.string.no, null)
.show();
return true;
case android.R.id.home: case android.R.id.home:
getActivity().finish(); getActivity().finish();
return true; return true;
@ -291,20 +299,6 @@ public class RepoSettingsFragment extends PreferenceFragment
Toast.makeText(getActivity(), R.string.no_nodes, Toast.LENGTH_SHORT) Toast.makeText(getActivity(), R.string.no_nodes, Toast.LENGTH_SHORT)
.show(); .show();
} }
else if (preference.equals(mDelete)) {
new AlertDialog.Builder(getActivity())
.setMessage(R.string.delete_repo_confirm)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
mSyncthingService.getApi().deleteRepo(mRepo, getActivity());
getActivity().finish();
}
})
.setNegativeButton(android.R.string.no, null)
.show();
return true;
}
return false; return false;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 765 B

View file

@ -12,6 +12,12 @@
android:id="@+id/share_node_id" android:id="@+id/share_node_id"
android:icon="@android:drawable/ic_menu_share" android:icon="@android:drawable/ic_menu_share"
android:title="@string/share_node_id" android:title="@string/share_node_id"
app:showAsAction="always" /> app:showAsAction="ifRoom" />
<item
android:id="@+id/delete"
android:icon="@drawable/ic_delete"
android:title="@string/delete_node"
app:showAsAction="ifRoom" />
</menu> </menu>

View file

@ -7,4 +7,11 @@
android:id="@+id/create" android:id="@+id/create"
android:title="@string/create" android:title="@string/create"
app:showAsAction="always" /> app:showAsAction="always" />
<item
android:id="@+id/delete"
android:icon="@drawable/ic_delete"
android:title="@string/delete_repo"
app:showAsAction="ifRoom" />
</menu> </menu>

View file

@ -24,8 +24,4 @@
android:title="@string/current_address" android:title="@string/current_address"
style="?android:preferenceInformationStyle" /> style="?android:preferenceInformationStyle" />
<Preference
android:key="delete"
android:title="@string/delete_node" />
</PreferenceScreen> </PreferenceScreen>

View file

@ -31,8 +31,4 @@
android:title="@string/keep_versions" android:title="@string/keep_versions"
android:inputType="numberDecimal" /> android:inputType="numberDecimal" />
<Preference
android:key="delete"
android:title="@string/delete_repo" />
</PreferenceScreen> </PreferenceScreen>