From af9c1421cdca2b9e73f2f01464963092b6e13970 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 25 Nov 2015 12:18:12 +0100 Subject: [PATCH] Added restart icon to drawer (fixes #420). --- .../activities/MainActivity.java | 57 +++++++++++------- .../fragments/DrawerFragment.java | 17 ++++-- .../syncthing/SyncthingService.java | 2 +- .../drawable-hdpi/ic_autorenew_black_24dp.png | Bin 0 -> 514 bytes .../drawable-mdpi/ic_autorenew_black_24dp.png | Bin 0 -> 375 bytes .../ic_autorenew_black_24dp.png | Bin 0 -> 675 bytes .../ic_autorenew_black_24dp.png | Bin 0 -> 929 bytes .../ic_autorenew_black_24dp.png | Bin 0 -> 1194 bytes .../res/drawable/ic_autorenew_black_24dp.xml | 5 ++ src/main/res/layout/fragment_drawer.xml | 9 +++ src/main/res/values/strings.xml | 2 + 11 files changed, 64 insertions(+), 28 deletions(-) create mode 100644 src/main/res/drawable-hdpi/ic_autorenew_black_24dp.png create mode 100644 src/main/res/drawable-mdpi/ic_autorenew_black_24dp.png create mode 100644 src/main/res/drawable-xhdpi/ic_autorenew_black_24dp.png create mode 100644 src/main/res/drawable-xxhdpi/ic_autorenew_black_24dp.png create mode 100644 src/main/res/drawable-xxxhdpi/ic_autorenew_black_24dp.png create mode 100644 src/main/res/drawable/ic_autorenew_black_24dp.xml diff --git a/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java b/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java index 483cb11f..d46ed172 100644 --- a/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java @@ -90,14 +90,14 @@ public class MainActivity extends SyncthingActivity public void onApiChange(SyncthingService.State currentState) { switch (currentState) { case INIT: - mLoadingDialog.show(); + showLoadingDialog(); // Make sure the first start dialog is shown on top. if (isFirstStart()) { showFirstStartDialog(); } break; case STARTING: - mLoadingDialog.show(); + showLoadingDialog(); dismissDisabledDialog(); int permissionState = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE); @@ -108,8 +108,8 @@ public class MainActivity extends SyncthingActivity } break; case ACTIVE: - mLoadingDialog.hide(); dismissDisabledDialog(); + dismissLoadingDialog(); mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); mDrawerFragment.requestGuiUpdate(); if (new Date().getTime() > getFirstStartTime() + USAGE_REPORTING_DIALOG_DELAY && @@ -121,7 +121,7 @@ public class MainActivity extends SyncthingActivity finish(); break; case DISABLED: - mLoadingDialog.hide(); + dismissLoadingDialog(); if (!isFinishing()) { mDisabledDialog = SyncthingService.showDisabledDialog(MainActivity.this); } @@ -131,7 +131,7 @@ public class MainActivity extends SyncthingActivity private void dismissDisabledDialog() { if (mDisabledDialog != null) { - mDisabledDialog.cancel(); + mDisabledDialog.dismiss(); mDisabledDialog = null; } } @@ -170,6 +170,34 @@ public class MainActivity extends SyncthingActivity .show(); } + /** + * Shows the loading dialog with the correct text ("creating keys" or "loading"). + */ + private void showLoadingDialog() { + if (mLoadingDialog != null) + return; + + LayoutInflater inflater = getLayoutInflater(); + @SuppressLint("InflateParams") + View dialogLayout = inflater.inflate(R.layout.dialog_loading, null); + TextView loadingText = (TextView) dialogLayout.findViewById(R.id.loading_text); + loadingText.setText((isFirstStart()) + ? R.string.web_gui_creating_key + : R.string.api_loading); + + mLoadingDialog = new AlertDialog.Builder(MainActivity.this) + .setCancelable(false) + .setView(dialogLayout) + .show(); + } + + private void dismissLoadingDialog() { + if (mLoadingDialog != null) { + mLoadingDialog.dismiss(); + mLoadingDialog = null; + } + } + private final FragmentPagerAdapter mSectionsPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) { @@ -242,28 +270,13 @@ public class MainActivity extends SyncthingActivity mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); mDrawerLayout.setDrawerListener(mDrawerToggle); setOptimalDrawerWidth(findViewById(R.id.drawer)); - - LayoutInflater inflater = getLayoutInflater(); - @SuppressLint("InflateParams") - View dialogLayout = inflater.inflate(R.layout.dialog_loading, null); - TextView loadingText = (TextView) dialogLayout.findViewById(R.id.loading_text); - loadingText.setText((isFirstStart()) - ? R.string.web_gui_creating_key - : R.string.api_loading); - - mLoadingDialog = new AlertDialog.Builder(MainActivity.this) - .setCancelable(false) - .setView(dialogLayout) - .create(); } @Override public void onDestroy() { super.onDestroy(); - mLoadingDialog.dismiss(); - if (mDisabledDialog != null) { - mDisabledDialog.dismiss(); - } + dismissDisabledDialog(); + dismissLoadingDialog(); if (getService() != null) { getService().unregisterOnApiChangeListener(this); getService().unregisterOnApiChangeListener(mFolderListFragment); diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java index a7b0c368..b991002c 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java @@ -101,6 +101,8 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI .setOnClickListener(this); view.findViewById(R.id.drawerActionDonate) .setOnClickListener(this); + view.findViewById(R.id.drawerActionRestart) + .setOnClickListener(this); view.findViewById(R.id.drawerActionSettings) .setOnClickListener(this); mExitButton.setOnClickListener(this); @@ -190,26 +192,31 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI switch (v.getId()) { case R.id.deviceIdContainer: RestApi.shareDeviceId(getActivity(), mDeviceId.getText().toString()); - return; + break; case R.id.drawerActionWebGui: startActivity(new Intent(mActivity, WebGuiActivity.class)); mActivity.closeDrawer(); - return; + break; case R.id.drawerActionDonate: startActivity(new Intent(ACTION_VIEW, Uri.parse( getString(R.string.donate_url)))); mActivity.closeDrawer(); - return; + break; case R.id.drawerActionSettings: startActivity(new Intent(mActivity, SettingsActivity.class) .setAction(SettingsActivity.ACTION_APP_SETTINGS_FRAGMENT)); mActivity.closeDrawer(); - return; + break; + case R.id.drawerActionRestart: + getContext().startService(new Intent(getContext(), SyncthingService.class) + .setAction(SyncthingService.ACTION_RESTART)); + mActivity.closeDrawer(); + break; case R.id.drawerActionExit: mActivity.stopService(new Intent(mActivity, SyncthingService.class)); mActivity.finish(); mActivity.closeDrawer(); - return; + break; } } } diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java index f431da82..49a2db44 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java @@ -443,7 +443,7 @@ public class SyncthingService extends Service implements shutdown(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); sp.unregisterOnSharedPreferenceChangeListener(this); - LocalBroadcastManager.getInstance(this).unregisterReceiver(this.mItemFinishedBroadcastReceiver); + LocalBroadcastManager.getInstance(this).unregisterReceiver(mItemFinishedBroadcastReceiver); } private void shutdown() { diff --git a/src/main/res/drawable-hdpi/ic_autorenew_black_24dp.png b/src/main/res/drawable-hdpi/ic_autorenew_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..9207cd986641b7f73950dcc7b3ad06d408585e7a GIT binary patch literal 514 zcmV+d0{#7oP)I!cY{z@xN9PEEsigvxu7@d4aBV6YOdyAEZm)#I1A_H^HZ{=~ThC(xp0>ickcJ zLsB)#{R)-dN#n`Sb8harH}J2cs1HdSK|MWX23dM4ZCIR^N*m9UhDs@JEzzV#h5X^~ zT>7k%K}A|L1i!x17vGQ(UbShH6k1QPWCzTW0iU646igf{ z(gxs-N45$kLynE=@wdnVOD)r-rCLWN8UPGJ46&lR)UheZp(ZI{8k!qGI5#Ppa;OHt zM7zrUh`JoA05I1=A1Bd5C=b9|3w;A{DTn;!=^3`MCx`r%Q83sEj?qHs3xKK?@*@^< zXcjbyZrCT$Lg*P!Fh|kt?20A38D%c8sA3;B(94#tIMmshv zm_?tI>A7~K9{%<{907*qoM6N<$ Ef-y(Y`2YX_ literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-mdpi/ic_autorenew_black_24dp.png b/src/main/res/drawable-mdpi/ic_autorenew_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..3211b64d5dad664f8a58328b713ce36f795c925a GIT binary patch literal 375 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_*1rX+877l!}s{b%+Ad7K3vkw8&y zVGw3ym^BBap1s7=*OmP~k1(H^sM~(eeGCkY9G)(YAr`0CPTAOX$UvfD|E;Fv(ttTE zvawxTcAqQqSGe;m`OXXH9Xs!M@3^|tinH(NRjUww8Ie}$b!xejxt0D!Pk!(H>Hp8* zifEp%ho{!JHpZ=#_;x|7&*+lUg67$p0<&1!1#645!WjQAIosR8%Nc)Q)1JD*cEQ}b zAI~P#dha>)l=0@y&GiMzdIjDOO4W|cIUUN?;PK#RN^K0&)-|#Ti_aEwmxLZ<6_-0R;lS!lD~{a&q>o7OYz{<}C&%m2-~M_~Ut7IRCD TLIhrJ zazF&0kq{#S?_diNDUn#374qcBFm(?BC0o-8tN0?X31d4_wjolMU*EDef*UO(SYU^2 zV(aoKF3Rzq8U5Cx&IwJf_~0TR@1li1`Ew3A;?}+Q@qkC{X!#mnX!|%PX&w}`?<*XL z<)29bi>&G1e-($ez%H5L&y$9#TRc&||4i4A7H0W%0#bapk6?;WJsldHW1hRuSqI=1 zX**z91-`|RcsBjyk4lbZJ0P#h`cPuV+bwnV^ui9vsq(~WMffq$Isp)6LemKl)qX4q za?h@u0GFzqwgaNosq3|9cI|*`Rn9m8W(Qg)0M1ppkzc}-X_`&F`nDy@b%icPz8U2=3}3gI z1E51iwxj*#V@&T&^6ywxPu1ZZirX@!@@clU{Hb{pO$oy|EI&cWrg9EkuusPy&@Vs9 zELrk8b9(Zh^aOQ2I>!0Fe`@Z>$x8sq@*S#_%+7I(fyvs`sF*TmG#7Qaro|b@G>nG= zj}esAU7%-sLj+A1 zks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b@hOG~~DK!*N^yPt5Ejr8Q(tOvRyX5C5dh{*5bgzp|`iCBWnaYtm@ z>Z6zM%$W@eraf>`E7=wq7JB-b0UCNEr6bhEpVS}LA2E!V86Cpc_#+&mZcc)2>|ve*RMr4 z8Ps2Ia|bACPf5}iV!S5+*shfjlBTXJcDMtmY4lkX;A@Qc1ORFgw<-#-6yrSsKu#O2 zCGCf8xgQUZ(dtl1%liL>s$bg~lhg?S)PZfc zD1bU~eQ^i)Xj`2)S-W!m$sORma@`>c&=KQ30l>U+z0L8h%x1Pv8zSc20lsV9ctQ-| zq!zwa9}~w*%}qf>eu3jk%PT)K->f!PcZmRW(Guf1A;5wbL>U43Oj zq+%?qY;mVrIveeMm;pTftDtyjv8h$&lHr|g^e8QBO#1_n2Vg3{i84KrLr8@eHV*SC$S-h~^L2K7X1QnQG9Os} zK2CC6t9kwuZ?|ln=EddbXr{6XAOx9m4jPS{Myz#fUEo(x9w8b zFMzB3Hw@bhoW23v&bRFMQ%X^YI%c>Eyr&)Iqo@n@IjnaEvgT#z^4v2udmle$UXPfZ+QOP;dnQr + + + + diff --git a/src/main/res/layout/fragment_drawer.xml b/src/main/res/layout/fragment_drawer.xml index 88feb033..4b71e9a0 100644 --- a/src/main/res/layout/fragment_drawer.xml +++ b/src/main/res/layout/fragment_drawer.xml @@ -217,6 +217,15 @@ android:drawableStart="@drawable/ic_attach_money_black_24dp" android:text="@string/donate" /> + + https://tip4commit.com/github/syncthing/syncthing-android + Restart +