1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2025-01-11 04:25:53 +00:00

Added restart icon to drawer (fixes #420).

This commit is contained in:
Felix Ableitner 2015-11-25 12:18:12 +01:00
parent 4abf49af61
commit af9c1421cd
11 changed files with 64 additions and 28 deletions

View file

@ -90,14 +90,14 @@ public class MainActivity extends SyncthingActivity
public void onApiChange(SyncthingService.State currentState) { public void onApiChange(SyncthingService.State currentState) {
switch (currentState) { switch (currentState) {
case INIT: case INIT:
mLoadingDialog.show(); showLoadingDialog();
// Make sure the first start dialog is shown on top. // Make sure the first start dialog is shown on top.
if (isFirstStart()) { if (isFirstStart()) {
showFirstStartDialog(); showFirstStartDialog();
} }
break; break;
case STARTING: case STARTING:
mLoadingDialog.show(); showLoadingDialog();
dismissDisabledDialog(); dismissDisabledDialog();
int permissionState = ContextCompat.checkSelfPermission(this, int permissionState = ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE); Manifest.permission.WRITE_EXTERNAL_STORAGE);
@ -108,8 +108,8 @@ public class MainActivity extends SyncthingActivity
} }
break; break;
case ACTIVE: case ACTIVE:
mLoadingDialog.hide();
dismissDisabledDialog(); dismissDisabledDialog();
dismissLoadingDialog();
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
mDrawerFragment.requestGuiUpdate(); mDrawerFragment.requestGuiUpdate();
if (new Date().getTime() > getFirstStartTime() + USAGE_REPORTING_DIALOG_DELAY && if (new Date().getTime() > getFirstStartTime() + USAGE_REPORTING_DIALOG_DELAY &&
@ -121,7 +121,7 @@ public class MainActivity extends SyncthingActivity
finish(); finish();
break; break;
case DISABLED: case DISABLED:
mLoadingDialog.hide(); dismissLoadingDialog();
if (!isFinishing()) { if (!isFinishing()) {
mDisabledDialog = SyncthingService.showDisabledDialog(MainActivity.this); mDisabledDialog = SyncthingService.showDisabledDialog(MainActivity.this);
} }
@ -131,7 +131,7 @@ public class MainActivity extends SyncthingActivity
private void dismissDisabledDialog() { private void dismissDisabledDialog() {
if (mDisabledDialog != null) { if (mDisabledDialog != null) {
mDisabledDialog.cancel(); mDisabledDialog.dismiss();
mDisabledDialog = null; mDisabledDialog = null;
} }
} }
@ -170,6 +170,34 @@ public class MainActivity extends SyncthingActivity
.show(); .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 = private final FragmentPagerAdapter mSectionsPagerAdapter =
new FragmentPagerAdapter(getSupportFragmentManager()) { new FragmentPagerAdapter(getSupportFragmentManager()) {
@ -242,28 +270,13 @@ public class MainActivity extends SyncthingActivity
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.setDrawerListener(mDrawerToggle);
setOptimalDrawerWidth(findViewById(R.id.drawer)); 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 @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
mLoadingDialog.dismiss(); dismissDisabledDialog();
if (mDisabledDialog != null) { dismissLoadingDialog();
mDisabledDialog.dismiss();
}
if (getService() != null) { if (getService() != null) {
getService().unregisterOnApiChangeListener(this); getService().unregisterOnApiChangeListener(this);
getService().unregisterOnApiChangeListener(mFolderListFragment); getService().unregisterOnApiChangeListener(mFolderListFragment);

View file

@ -101,6 +101,8 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
.setOnClickListener(this); .setOnClickListener(this);
view.findViewById(R.id.drawerActionDonate) view.findViewById(R.id.drawerActionDonate)
.setOnClickListener(this); .setOnClickListener(this);
view.findViewById(R.id.drawerActionRestart)
.setOnClickListener(this);
view.findViewById(R.id.drawerActionSettings) view.findViewById(R.id.drawerActionSettings)
.setOnClickListener(this); .setOnClickListener(this);
mExitButton.setOnClickListener(this); mExitButton.setOnClickListener(this);
@ -190,26 +192,31 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
switch (v.getId()) { switch (v.getId()) {
case R.id.deviceIdContainer: case R.id.deviceIdContainer:
RestApi.shareDeviceId(getActivity(), mDeviceId.getText().toString()); RestApi.shareDeviceId(getActivity(), mDeviceId.getText().toString());
return; break;
case R.id.drawerActionWebGui: case R.id.drawerActionWebGui:
startActivity(new Intent(mActivity, WebGuiActivity.class)); startActivity(new Intent(mActivity, WebGuiActivity.class));
mActivity.closeDrawer(); mActivity.closeDrawer();
return; break;
case R.id.drawerActionDonate: case R.id.drawerActionDonate:
startActivity(new Intent(ACTION_VIEW, Uri.parse( startActivity(new Intent(ACTION_VIEW, Uri.parse(
getString(R.string.donate_url)))); getString(R.string.donate_url))));
mActivity.closeDrawer(); mActivity.closeDrawer();
return; break;
case R.id.drawerActionSettings: case R.id.drawerActionSettings:
startActivity(new Intent(mActivity, SettingsActivity.class) startActivity(new Intent(mActivity, SettingsActivity.class)
.setAction(SettingsActivity.ACTION_APP_SETTINGS_FRAGMENT)); .setAction(SettingsActivity.ACTION_APP_SETTINGS_FRAGMENT));
mActivity.closeDrawer(); 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: case R.id.drawerActionExit:
mActivity.stopService(new Intent(mActivity, SyncthingService.class)); mActivity.stopService(new Intent(mActivity, SyncthingService.class));
mActivity.finish(); mActivity.finish();
mActivity.closeDrawer(); mActivity.closeDrawer();
return; break;
} }
} }
} }

View file

@ -443,7 +443,7 @@ public class SyncthingService extends Service implements
shutdown(); shutdown();
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
sp.unregisterOnSharedPreferenceChangeListener(this); sp.unregisterOnSharedPreferenceChangeListener(this);
LocalBroadcastManager.getInstance(this).unregisterReceiver(this.mItemFinishedBroadcastReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(mItemFinishedBroadcastReceiver);
} }
private void shutdown() { private void shutdown() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 514 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 929 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_autorenew_black_24dp" android:state_enabled="false" />
<item android:drawable="@drawable/ic_autorenew_black_24dp" />
</selector>

View file

@ -217,6 +217,15 @@
android:drawableStart="@drawable/ic_attach_money_black_24dp" android:drawableStart="@drawable/ic_attach_money_black_24dp"
android:text="@string/donate" /> android:text="@string/donate" />
<TextView
android:id="@+id/drawerActionRestart"
style="@style/Widget.Syncthing.TextView.Label"
android:layout_width="match_parent"
android:layout_height="48dp"
android:drawableLeft="@drawable/ic_autorenew_black_24dp"
android:drawableStart="@drawable/ic_autorenew_black_24dp"
android:text="@string/restart" />
<TextView <TextView
android:id="@+id/drawerActionExit" android:id="@+id/drawerActionExit"
style="@style/Widget.Syncthing.TextView.Label" style="@style/Widget.Syncthing.TextView.Label"

View file

@ -97,6 +97,8 @@
<string name="donate_url" translatable="false">https://tip4commit.com/github/syncthing/syncthing-android</string> <string name="donate_url" translatable="false">https://tip4commit.com/github/syncthing/syncthing-android</string>
<string name="restart">Restart</string>
<!-- FolderSettingsFragment --> <!-- FolderSettingsFragment -->