1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 11:21:29 +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) {
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);

View file

@ -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;
}
}
}

View file

@ -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() {

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: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
android:id="@+id/drawerActionExit"
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="restart">Restart</string>
<!-- FolderSettingsFragment -->