1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 22:31:16 +00:00

DrawerFragment improvements.

This commit is contained in:
George Venios 2015-09-07 01:25:43 +01:00
parent 507e841864
commit 7f9e773eaa
3 changed files with 72 additions and 79 deletions

View file

@ -28,7 +28,7 @@ import static android.content.Intent.ACTION_VIEW;
* Displays information about the local device.
*/
public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemInfoListener,
RestApi.OnReceiveConnectionsListener {
RestApi.OnReceiveConnectionsListener, View.OnClickListener {
private TextView mDeviceId;
@ -48,48 +48,6 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
private MainActivity mActivity;
private View.OnClickListener mShareIdListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
RestApi.shareDeviceId(getActivity(), mDeviceId.getText().toString());
}
};
private View.OnClickListener mWebGuiClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(mActivity, WebGuiActivity.class));
mActivity.closeDrawer();
}
};
private View.OnClickListener mDonateButtonClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(ACTION_VIEW, Uri.parse(
getString(R.string.donate_url))));
mActivity.closeDrawer();
}
};
private View.OnClickListener mSettingsClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(mActivity, SettingsActivity.class)
.setAction(SettingsActivity.ACTION_APP_SETTINGS_FRAGMENT));
mActivity.closeDrawer();
}
};
private View.OnClickListener mExitClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
mActivity.stopService(new Intent(mActivity, SyncthingService.class));
mActivity.finish();
mActivity.closeDrawer();
}
};
public void onDrawerOpened() {
mTimer = new Timer();
mTimer.schedule(new TimerTask() {
@ -139,21 +97,21 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
mExitButton = (TextView) view.findViewById(R.id.drawerActionExit);
view.findViewById(R.id.deviceIdContainer)
.setOnClickListener(mShareIdListener);
.setOnClickListener(this);
view.findViewById(R.id.drawerActionWebGui)
.setOnClickListener(mWebGuiClickListener);
.setOnClickListener(this);
view.findViewById(R.id.drawerActionDonate)
.setOnClickListener(mDonateButtonClickListener);
.setOnClickListener(this);
view.findViewById(R.id.drawerActionSettings)
.setOnClickListener(mSettingsClickListener);
mExitButton.setOnClickListener(mExitClickListener);
.setOnClickListener(this);
mExitButton.setOnClickListener(this);
updateExitButtonVisibility();
}
private void updateExitButtonVisibility() {
boolean alwaysInBackground = SyncthingService.alwaysRunInBackground(getActivity());
mExitButton.setVisibility(alwaysInBackground ? View.VISIBLE : View.GONE);
mExitButton.setVisibility(alwaysInBackground ? View.GONE : View.VISIBLE);
}
@Override
@ -231,4 +189,32 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
mDownload.setText(RestApi.readableTransferRate(mActivity, c.inBits));
mUpload.setText(RestApi.readableTransferRate(mActivity, c.outBits));
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.deviceIdContainer:
RestApi.shareDeviceId(getActivity(), mDeviceId.getText().toString());
return;
case R.id.drawerActionWebGui:
startActivity(new Intent(mActivity, WebGuiActivity.class));
mActivity.closeDrawer();
return;
case R.id.drawerActionDonate:
startActivity(new Intent(ACTION_VIEW, Uri.parse(
getString(R.string.donate_url))));
mActivity.closeDrawer();
return;
case R.id.drawerActionSettings:
startActivity(new Intent(mActivity, SettingsActivity.class)
.setAction(SettingsActivity.ACTION_APP_SETTINGS_FRAGMENT));
mActivity.closeDrawer();
return;
case R.id.drawerActionExit:
mActivity.stopService(new Intent(mActivity, SyncthingService.class));
mActivity.finish();
mActivity.closeDrawer();
return;
}
}
}

View file

@ -42,7 +42,7 @@
style="@style/Widget.Syncthing.TextView.Label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginTop="8dp"
android:gravity="center_vertical"
android:minHeight="48dp"
android:orientation="vertical"
@ -65,34 +65,6 @@
android:visibility="invisible" />
</LinearLayout>
<TextView
android:id="@+id/drawerActionWebGui"
style="@style/Widget.Syncthing.TextView.Label"
android:layout_width="match_parent"
android:layout_height="48dp"
android:drawableLeft="@drawable/ic_web_black_24dp"
android:drawableStart="@drawable/ic_web_black_24dp"
android:text="@string/web_gui_title" />
<TextView
android:id="@+id/drawerActionDonate"
style="@style/Widget.Syncthing.TextView.Label"
android:layout_width="match_parent"
android:layout_height="48dp"
android:drawableLeft="@drawable/ic_attach_money_black_24dp"
android:drawableStart="@drawable/ic_attach_money_black_24dp"
android:text="@string/donate" />
<TextView
android:id="@+id/drawerActionExit"
style="@style/Widget.Syncthing.TextView.Label"
android:layout_width="match_parent"
android:layout_height="48dp"
android:drawableLeft="@drawable/ic_close_black_24dp"
android:drawableStart="@drawable/ic_close_black_24dp"
android:text="@string/exit"
android:visibility="gone" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
@ -219,6 +191,41 @@
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="@drawable/list_divider" />
<TextView
android:id="@+id/drawerActionWebGui"
style="@style/Widget.Syncthing.TextView.Label"
android:layout_width="match_parent"
android:layout_height="48dp"
android:drawableLeft="@drawable/ic_web_black_24dp"
android:drawableStart="@drawable/ic_web_black_24dp"
android:text="@string/web_gui_title" />
<TextView
android:id="@+id/drawerActionDonate"
style="@style/Widget.Syncthing.TextView.Label"
android:layout_width="match_parent"
android:layout_height="48dp"
android:drawableLeft="@drawable/ic_attach_money_black_24dp"
android:drawableStart="@drawable/ic_attach_money_black_24dp"
android:text="@string/donate" />
<TextView
android:id="@+id/drawerActionExit"
style="@style/Widget.Syncthing.TextView.Label"
android:layout_width="match_parent"
android:layout_height="48dp"
android:drawableLeft="@drawable/ic_close_black_24dp"
android:drawableStart="@drawable/ic_close_black_24dp"
android:text="@string/exit"
android:visibility="gone" />
</LinearLayout>
</ScrollView>
</RelativeLayout>