From 3c7fd0261320ffbfbec3f390a5e3cc00cf1f0f4d Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Tue, 6 Oct 2015 12:51:09 +0200 Subject: [PATCH] Fixes / Improvements - some fixes for tablets - updated API - removed BitmessageService (I really hope it won't be needed) --- app/src/main/AndroidManifest.xml | 7 -- .../dissem/apps/abit/MessageListActivity.java | 22 +++- .../abit/repositories/AndroidInventory.java | 13 +++ .../AndroidMessageRepository.java | 7 ++ .../apps/abit/service/BitmessageService.java | 104 ------------------ .../dissem/apps/abit/service/Singleton.java | 7 +- .../layout-sw600dp/activity_message_list.xml | 6 +- 7 files changed, 46 insertions(+), 120 deletions(-) delete mode 100644 app/src/main/java/ch/dissem/apps/abit/service/BitmessageService.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5cb1fb1..19861c3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -84,13 +84,6 @@ - - - 0; + } + @Override public void cleanup() { SQLiteDatabase db = sql.getWritableDatabase(); diff --git a/app/src/main/java/ch/dissem/apps/abit/repositories/AndroidMessageRepository.java b/app/src/main/java/ch/dissem/apps/abit/repositories/AndroidMessageRepository.java index b290834..30bacb8 100644 --- a/app/src/main/java/ch/dissem/apps/abit/repositories/AndroidMessageRepository.java +++ b/app/src/main/java/ch/dissem/apps/abit/repositories/AndroidMessageRepository.java @@ -21,6 +21,7 @@ import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteConstraintException; import android.database.sqlite.SQLiteDatabase; + import ch.dissem.apps.abit.R; import ch.dissem.bitmessage.InternalContext; import ch.dissem.bitmessage.entity.BitmessageAddress; @@ -29,6 +30,7 @@ import ch.dissem.bitmessage.entity.valueobject.InventoryVector; import ch.dissem.bitmessage.entity.valueobject.Label; import ch.dissem.bitmessage.ports.MessageRepository; import ch.dissem.bitmessage.utils.Encode; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -184,6 +186,11 @@ public class AndroidMessageRepository implements MessageRepository, InternalCont return find("status='" + status.name() + "' AND recipient='" + recipient.getAddress() + "'"); } + @Override + public List findMessages(BitmessageAddress sender) { + return find("sender=" + sender.getAddress()); + } + @Override public List<Plaintext> findMessages(Plaintext.Status status) { return find("status='" + status.name() + "'"); diff --git a/app/src/main/java/ch/dissem/apps/abit/service/BitmessageService.java b/app/src/main/java/ch/dissem/apps/abit/service/BitmessageService.java deleted file mode 100644 index a55d3e1..0000000 --- a/app/src/main/java/ch/dissem/apps/abit/service/BitmessageService.java +++ /dev/null @@ -1,104 +0,0 @@ -package ch.dissem.apps.abit.service; - -import android.app.Notification; -import android.app.NotificationManager; -import android.app.Service; -import android.content.Context; -import android.content.Intent; -import android.os.Binder; -import android.os.IBinder; -import android.support.v7.app.NotificationCompat; -import ch.dissem.apps.abit.R; -import ch.dissem.bitmessage.BitmessageContext; -import ch.dissem.bitmessage.entity.BitmessageAddress; -import ch.dissem.bitmessage.entity.Plaintext; -import ch.dissem.bitmessage.entity.valueobject.Label; - -import java.util.List; - -public class BitmessageService extends Service { - private static BitmessageContext ctx; - private ServiceBinder binder = new ServiceBinder(); - private NotificationCompat.Builder ongoingNotificationBuilder = new NotificationCompat.Builder(this); - private NotificationManager notifyManager; - - public BitmessageService() { - if (ctx == null) { - ctx = Singleton.getBitmessageContext(this); - } - } - - @Override - public void onCreate() { - super.onCreate(); - ongoingNotificationBuilder.setOngoing(true); - ongoingNotificationBuilder.setContentTitle(getString(R.string.bitmessage_active)); - ongoingNotificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); -// ongoingNotificationBuilder.setSmallIcon(R.drawable.ic_bitmessage); - notifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - } - - public void startService() { - if (!ctx.isRunning()) { - notifyManager.notify(0, ongoingNotificationBuilder.build()); - ctx.startup(new BitmessageContext.Listener() { - @Override - public void receive(Plaintext plaintext) { - Notification notification = new NotificationCompat.Builder(BitmessageService.this) - .setContentTitle(plaintext.getSubject()) - .setContentText(plaintext.getText()) - .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) - .setPriority(plaintext.getType() == Plaintext.Type.BROADCAST - ? NotificationCompat.PRIORITY_DEFAULT - : NotificationCompat.PRIORITY_HIGH) - .build(); - notifyManager.notify(plaintext.getInventoryVector().hashCode(), notification); - } - }); - } - } - - public void stopService() { - ctx.shutdown(); - notifyManager.cancel(0); - } - - public List<BitmessageAddress> getIdentities() { - return ctx.addresses().getIdentities(); - } - - public List<BitmessageAddress> getContacts() { - return ctx.addresses().getContacts(); - } - - public List<Plaintext> getMessages(Label label) { - return ctx.messages().findMessages(label); - } - - @Override - public IBinder onBind(Intent intent) { - return binder; - } - - public class ServiceBinder extends Binder { - public BitmessageService getService() { - return BitmessageService.this; - } - } - - public enum NetworkChoice { - /** - * A full node, receiving and relaying objects all the time. - */ - FULL, - /** - * Connect to a trusted node from time to time to get all new objects and disconnect afterwards - * (see {@link android.content.AbstractThreadedSyncAdapter}) - */ - TRUSTED, - /** - * Offline - */ - NONE - } -} diff --git a/app/src/main/java/ch/dissem/apps/abit/service/Singleton.java b/app/src/main/java/ch/dissem/apps/abit/service/Singleton.java index 46b46e1..76c3301 100644 --- a/app/src/main/java/ch/dissem/apps/abit/service/Singleton.java +++ b/app/src/main/java/ch/dissem/apps/abit/service/Singleton.java @@ -1,6 +1,8 @@ package ch.dissem.apps.abit.service; +import android.app.NotificationManager; import android.content.Context; + import ch.dissem.apps.abit.listeners.MessageListener; import ch.dissem.apps.abit.repositories.AndroidAddressRepository; import ch.dissem.apps.abit.repositories.AndroidInventory; @@ -18,11 +20,11 @@ public class Singleton { private static BitmessageContext bitmessageContext; private static MessageListener messageListener; - public static BitmessageContext getBitmessageContext(Context ctx) { + public static BitmessageContext getBitmessageContext(Context context) { if (bitmessageContext == null) { synchronized (Singleton.class) { if (bitmessageContext == null) { - ctx = ctx.getApplicationContext(); + final Context ctx = context.getApplicationContext(); SqlHelper sqlHelper = new SqlHelper(ctx); bitmessageContext = new BitmessageContext.Builder() .security(new SpongySecurity()) @@ -31,6 +33,7 @@ public class Singleton { .addressRepo(new AndroidAddressRepository(sqlHelper)) .messageRepo(new AndroidMessageRepository(sqlHelper, ctx)) .networkHandler(new DefaultNetworkHandler()) + .listener(getMessageListener(ctx)) .build(); } } diff --git a/app/src/main/res/layout-sw600dp/activity_message_list.xml b/app/src/main/res/layout-sw600dp/activity_message_list.xml index d1b7b00..e955b6b 100644 --- a/app/src/main/res/layout-sw600dp/activity_message_list.xml +++ b/app/src/main/res/layout-sw600dp/activity_message_list.xml @@ -1,4 +1,5 @@ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" android:gravity="center" android:layout_width="match_parent" android:layout_height="match_parent"> @@ -8,7 +9,9 @@ android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" - android:elevation="4dp"/> + android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" + app:popupTheme="@style/ThemeOverlay.AppCompat.Light" + android:elevation="4dp" /> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" @@ -34,6 +37,7 @@ android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" + tools:context=".MessageListActivity" tools:layout="@android:layout/list_content"/> <FrameLayout