From 76e87932f9c6923a33e90fa504707ebe39068ed9 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 4 Aug 2014 00:55:33 +0200 Subject: [PATCH] Use ActionBar icon instead of preference item for delete repo/node. --- .../fragments/NodeSettingsFragment.java | 34 ++++++++---------- .../fragments/RepoSettingsFragment.java | 34 ++++++++---------- src/main/res/drawable-hdpi/ic_delete.png | Bin 0 -> 450 bytes src/main/res/drawable-mdpi/ic_delete.png | Bin 0 -> 324 bytes src/main/res/drawable-xhdpi/ic_delete.png | Bin 0 -> 543 bytes src/main/res/drawable-xxhdpi/ic_delete.png | Bin 0 -> 765 bytes src/main/res/menu/node_settings.xml | 8 ++++- src/main/res/menu/repo_settings.xml | 7 ++++ src/main/res/xml/node_settings_edit.xml | 6 +--- src/main/res/xml/repo_settings_edit.xml | 4 --- 10 files changed, 44 insertions(+), 49 deletions(-) create mode 100644 src/main/res/drawable-hdpi/ic_delete.png create mode 100644 src/main/res/drawable-mdpi/ic_delete.png create mode 100644 src/main/res/drawable-xhdpi/ic_delete.png create mode 100644 src/main/res/drawable-xxhdpi/ic_delete.png diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/NodeSettingsFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/NodeSettingsFragment.java index c8d0b684..6e83dd46 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/NodeSettingsFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/NodeSettingsFragment.java @@ -68,8 +68,6 @@ public class NodeSettingsFragment extends PreferenceFragment implements private Preference mCurrentAddress; - private Preference mDelete; - private boolean mIsCreate; @Override @@ -96,9 +94,7 @@ public class NodeSettingsFragment extends PreferenceFragment implements mVersion = findPreference("version"); mVersion.setSummary("?"); mCurrentAddress = findPreference("current_address"); - mDelete = findPreference("delete"); mCurrentAddress.setSummary("?"); - mDelete.setOnPreferenceClickListener(this); } getActivity().bindService(new Intent(getActivity(), SyncthingService.class), @@ -152,6 +148,7 @@ public class NodeSettingsFragment extends PreferenceFragment implements public void onPrepareOptionsMenu(Menu menu) { menu.findItem(R.id.create).setVisible(mIsCreate); menu.findItem(R.id.share_node_id).setVisible(!mIsCreate); + menu.findItem(R.id.delete).setVisible(!mIsCreate); } @Override @@ -173,6 +170,19 @@ public class NodeSettingsFragment extends PreferenceFragment implements case R.id.share_node_id: RestApi.shareNodeId(getActivity(), mNode.NodeID); 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: getActivity().finish(); return true; @@ -214,21 +224,7 @@ public class NodeSettingsFragment extends PreferenceFragment implements @Override public boolean onPreferenceClick(Preference preference) { - if (preference.equals(mDelete)) { - 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)) { + if (preference.equals(mNodeId)) { mSyncthingService.getApi().copyNodeId(mNode.NodeID); return true; } diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/RepoSettingsFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/RepoSettingsFragment.java index 707d7178..397ccf9f 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/RepoSettingsFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/RepoSettingsFragment.java @@ -77,8 +77,6 @@ public class RepoSettingsFragment extends PreferenceFragment private EditTextPreference mVersioningKeep; - private Preference mDelete; - private boolean mIsCreate; @Override @@ -107,10 +105,6 @@ public class RepoSettingsFragment extends PreferenceFragment mVersioning.setOnPreferenceChangeListener(this); mVersioningKeep = (EditTextPreference) findPreference("versioning_keep"); mVersioningKeep.setOnPreferenceChangeListener(this); - if (!mIsCreate) { - mDelete = findPreference("delete"); - mDelete.setOnPreferenceClickListener(this); - } getActivity().bindService(new Intent(getActivity(), SyncthingService.class), mSyncthingServiceConnection, Context.BIND_AUTO_CREATE); @@ -182,6 +176,7 @@ public class RepoSettingsFragment extends PreferenceFragment @Override public void onPrepareOptionsMenu(Menu menu) { menu.findItem(R.id.create).setVisible(mIsCreate); + menu.findItem(R.id.delete).setVisible(!mIsCreate); } @Override @@ -201,6 +196,19 @@ public class RepoSettingsFragment extends PreferenceFragment mSyncthingService.getApi().editRepo(mRepo, true, getActivity()); getActivity().finish(); 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: getActivity().finish(); return true; @@ -291,20 +299,6 @@ public class RepoSettingsFragment extends PreferenceFragment Toast.makeText(getActivity(), R.string.no_nodes, Toast.LENGTH_SHORT) .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; } diff --git a/src/main/res/drawable-hdpi/ic_delete.png b/src/main/res/drawable-hdpi/ic_delete.png new file mode 100644 index 0000000000000000000000000000000000000000..703b31f8027859b5810937a5c2da2b97428c68ed GIT binary patch literal 450 zcmV;z0X_bSP)3kAs1qih2LP}sp1f-fdKLlLI zKM9>014mq!#s;4VM$Y&&F`b*7>b5h szZOL!<(tn#I`>~o3WY)u2Oa_p0K4L5a@AHer~m)}07*qoM6N<$g3So4vj6}9 literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-mdpi/ic_delete.png b/src/main/res/drawable-mdpi/ic_delete.png new file mode 100644 index 0000000000000000000000000000000000000000..248fb09cd0c918955323e790c4c3250997c99819 GIT binary patch literal 324 zcmV-K0lWT*P)F4>9Waur;s5{tYCy^X zhxBqrM#j&in8!kfqlTV4U*;DIaLCs{^ql z0WHsg_$Cma1>!A)(gZOM*bk(5$qgl-0~{%h0$vJ2n3o!9;4B3WI7^js0GjvF(|{Bb z8x-%)(9-}g_-|3Av;sQ7msWa+4S_QxMhCc{0)~JIwF@F+YS#r!3b z00013D4d29@BNw{`GK#!IOpow6F|uq^msku)shH!j2+*Z;nkUHI5}5Nsv{e#>K)mw zWRtU)n_#)>@#_cBs7qLY32z9U;|@$3;jm;{jsQ;j zp6rI~B688%utk!+Ns!?Ll3&qdHPOu25DA;93HY2;$~t%TUxm;jx4~Hw&`ubCYk`0V zvh4)PZ`rpE9l!!7Y=gx>1Bl9Kwu(=Ro%!Q1k&?5z%YNvC;tx_dEbp+-cN*UX0D)>h zam8c%$%8L*XMuqr3QKp#{VH+7>)R!ed)c?rsRAe_0kcqm5JDh8o&Zfn*jgl@Q6!*2 z3xEI+fFXz>h!y|=AYiFOu(L>j<`AsW0w4ecm?NN5jN9H2)ckZU=?g6Y0%TDt#9Ue? z;5mtV)2m`1a`Plcl-~Pr;qf~8{#hzj^$!|;@8SbB_Il;ZkNr>5;($tj-3}YOSP1|C h00000oPfOm0|4WXd=hHbFpB^H002ovPDHLkV1n%A=T`s# literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xxhdpi/ic_delete.png b/src/main/res/drawable-xxhdpi/ic_delete.png new file mode 100644 index 0000000000000000000000000000000000000000..cb1260a4c68d931cb7dbe80341355c1c2438bd9a GIT binary patch literal 765 zcmVB@;q-4;5x(4O!H>0yB=;Q#$Or{N(AUGz{)g5kGI?# z0Ui;cy8yf1A2iSJH9qSNVK6MWk@WNE$FKPPm!9GW0ys07&Oy|;u&rsHVtBArT~HHC zM~MLlKoE`wo1jfnaX)JE0LQR}ZHEY;62vPjko?@3z+R0`0AuXd&~nXs&UpVLjI^ci zb)(#);R`#m=gPf;Okvl)){b&dBmPyvNdL>5u^jr1@FBn|LgSxAFaj)M7hsn~%+QN? z5SCnD_MqUX_q3lzIRUqUyQSYOzoS|3Nn;1rPIntuS0KF(Y`Tjdgihw_RYC8nqAi+ zTT*J~TL7cSxRi~#o~>(9=k9FZHp#|-vxT{K<{@qE(^osOW$MhvPO-)3F1nBcTuOra zPJp_6PeuR@_!NM}xWM=ppp3vKWy%5o0w4e&06~}_%o~6U0t7$+1n~U#st9aSr7S=U zr&pSk1pov<03ZmDGze=hoD`~$xFBKx0>H=w(0pKHKL!CbZ + app:showAsAction="ifRoom" /> + + diff --git a/src/main/res/menu/repo_settings.xml b/src/main/res/menu/repo_settings.xml index 1ea63153..2162c78e 100644 --- a/src/main/res/menu/repo_settings.xml +++ b/src/main/res/menu/repo_settings.xml @@ -7,4 +7,11 @@ android:id="@+id/create" android:title="@string/create" app:showAsAction="always" /> + + + diff --git a/src/main/res/xml/node_settings_edit.xml b/src/main/res/xml/node_settings_edit.xml index 430a58c8..7aaada4c 100644 --- a/src/main/res/xml/node_settings_edit.xml +++ b/src/main/res/xml/node_settings_edit.xml @@ -24,8 +24,4 @@ android:title="@string/current_address" style="?android:preferenceInformationStyle" /> - - - \ No newline at end of file + diff --git a/src/main/res/xml/repo_settings_edit.xml b/src/main/res/xml/repo_settings_edit.xml index 8bdbd45f..46a34073 100644 --- a/src/main/res/xml/repo_settings_edit.xml +++ b/src/main/res/xml/repo_settings_edit.xml @@ -31,8 +31,4 @@ android:title="@string/keep_versions" android:inputType="numberDecimal" /> - -