From 725089c604b0a50d80f1755912c1bf3beea83a78 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Sat, 24 Oct 2015 20:59:24 +0200 Subject: [PATCH] Fixed NullPointerException and minor improvements --- .../dissem/apps/abit/MessageListActivity.java | 26 ++-- .../notification/NewMessageNotification.java | 1 - .../synchronization/BitmessageService.java | 2 +- .../res/layout/fragment_message_detail.xml | 130 +++++++++--------- 4 files changed, 80 insertions(+), 79 deletions(-) diff --git a/app/src/main/java/ch/dissem/apps/abit/MessageListActivity.java b/app/src/main/java/ch/dissem/apps/abit/MessageListActivity.java index 3899a60..1797d17 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MessageListActivity.java +++ b/app/src/main/java/ch/dissem/apps/abit/MessageListActivity.java @@ -280,25 +280,27 @@ public class MessageListActivity extends AppCompatActivity new SwitchDrawerItem() .withName(R.string.full_node) .withIcon(CommunityMaterial.Icon.cmd_cloud_outline) + .withChecked(BitmessageService.isRunning()) .withOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(IDrawerItem drawerItem, CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - try { - service.send(Message.obtain(null, MSG_START_NODE)); - } catch (RemoteException e) { - LOG.error(e.getMessage(), e); - } - } else { - try { - service.send(Message.obtain(null, MSG_STOP_NODE)); - } catch (RemoteException e) { - LOG.error(e.getMessage(), e); + if (messenger != null) { + if (isChecked) { + try { + service.send(Message.obtain(null, MSG_START_NODE)); + } catch (RemoteException e) { + LOG.error(e.getMessage(), e); + } + } else { + try { + service.send(Message.obtain(null, MSG_STOP_NODE)); + } catch (RemoteException e) { + LOG.error(e.getMessage(), e); + } } } } }) - .withChecked(BitmessageService.isRunning()) ) .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override diff --git a/app/src/main/java/ch/dissem/apps/abit/notification/NewMessageNotification.java b/app/src/main/java/ch/dissem/apps/abit/notification/NewMessageNotification.java index 2bb63df..4e66ab1 100644 --- a/app/src/main/java/ch/dissem/apps/abit/notification/NewMessageNotification.java +++ b/app/src/main/java/ch/dissem/apps/abit/notification/NewMessageNotification.java @@ -1,6 +1,5 @@ package ch.dissem.apps.abit.notification; -import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; diff --git a/app/src/main/java/ch/dissem/apps/abit/synchronization/BitmessageService.java b/app/src/main/java/ch/dissem/apps/abit/synchronization/BitmessageService.java index 76176fb..f611630 100644 --- a/app/src/main/java/ch/dissem/apps/abit/synchronization/BitmessageService.java +++ b/app/src/main/java/ch/dissem/apps/abit/synchronization/BitmessageService.java @@ -91,7 +91,7 @@ public class BitmessageService extends Service { @Override public void onDestroy() { - bmc.shutdown(); + if (bmc.isRunning()) bmc.shutdown(); running = false; } diff --git a/app/src/main/res/layout/fragment_message_detail.xml b/app/src/main/res/layout/fragment_message_detail.xml index b10bfab..55e0516 100644 --- a/app/src/main/res/layout/fragment_message_detail.xml +++ b/app/src/main/res/layout/fragment_message_detail.xml @@ -1,82 +1,82 @@ - + + + - - + android:layout_alignParentLeft="true" + android:layout_alignParentStart="true" + android:layout_alignParentTop="true" + android:elegantTextHeight="false" + android:enabled="false" + android:gravity="center_vertical" + android:padding="16dp" + android:text="Subject" + android:textAppearance="?android:attr/textAppearanceLarge" /> + android:id="@+id/divider" + android:layout_width="fill_parent" + android:layout_height="2dip" + android:layout_below="@id/subject" + android:background="@color/divider" /> + android:id="@+id/avatar" + android:layout_width="40dp" + android:layout_height="40dp" + android:layout_alignParentLeft="true" + android:layout_alignParentStart="true" + android:layout_below="@+id/divider" + android:layout_margin="16dp" + android:src="@color/accent" /> + android:id="@+id/sender" + android:layout_width="wrap_content" + android:layout_height="20dp" + android:layout_alignTop="@+id/avatar" + android:layout_toEndOf="@+id/avatar" + android:layout_toRightOf="@+id/avatar" + android:gravity="center_vertical" + android:paddingLeft="8dp" + android:paddingRight="8dp" + android:text="Sender" + android:textStyle="bold" /> + android:id="@+id/recipient" + android:layout_width="wrap_content" + android:layout_height="20dp" + android:layout_alignBottom="@+id/avatar" + android:layout_toEndOf="@+id/avatar" + android:layout_toRightOf="@+id/avatar" + android:gravity="center_vertical" + android:paddingLeft="8dp" + android:paddingRight="8dp" + android:text="Recipient" /> + android:id="@+id/text" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:layout_alignParentStart="true" + android:layout_below="@+id/avatar" + android:layout_marginLeft="16dp" + android:layout_marginRight="16dp" + android:layout_marginTop="32dp" + android:paddingBottom="64dp" + android:text="New Text" + android:textIsSelectable="true" /> \ No newline at end of file