From c4d76fc8ce6022f20dbde368968b596190db166c Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Tue, 19 Jan 2016 20:50:58 +0100 Subject: [PATCH] Code cleanup - most notably BitmessageService was cleaned up and doesn't use messaging anymore --- app/src/main/AndroidManifest.xml | 9 +- .../apps/abit/AbstractItemListFragment.java | 13 +- .../apps/abit/ComposeMessageActivity.java | 18 ++- .../apps/abit/ComposeMessageFragment.java | 17 +- .../java/ch/dissem/apps/abit/Identicon.java | 6 +- .../ch/dissem/apps/abit/MainActivity.java | 144 ++++++----------- .../apps/abit/MessageDetailActivity.java | 1 + .../apps/abit/MessageDetailFragment.java | 45 ++++-- .../dissem/apps/abit/MessageListFragment.java | 16 ++ .../apps/abit/OpenBitmessageLinkActivity.java | 71 +-------- .../ch/dissem/apps/abit/SettingsActivity.java | 1 + .../ch/dissem/apps/abit/SettingsFragment.java | 16 ++ .../ch/dissem/apps/abit/StatusActivity.java | 18 ++- .../apps/abit/SubscriptionDetailActivity.java | 1 + .../abit/adapter/AndroidCryptography.java | 37 ++--- .../apps/abit/adapter/ContactAdapter.java | 16 ++ .../adapter/SwitchingProofOfWorkEngine.java | 19 ++- .../apps/abit/listener/ActionBarListener.java | 2 +- .../abit/listener/ListSelectionListener.java | 2 +- .../apps/abit/listener/MessageListener.java | 41 +---- .../apps/abit/listener/WifiReceiver.java | 16 ++ .../notification/AbstractNotification.java | 16 ++ .../abit/notification/ErrorNotification.java | 21 ++- .../notification/NetworkNotification.java | 16 ++ .../notification/NewMessageNotification.java | 45 +++++- .../notification/ProofOfWorkNotification.java | 16 ++ .../dissem/apps/abit/pow/ServerPowEngine.java | 16 ++ .../abit/repository/AndroidInventory.java | 26 ++-- .../AndroidProofOfWorkRepository.java | 16 ++ .../apps/abit/service/BitmessageService.java | 146 ++++-------------- .../apps/abit/service/ProofOfWorkService.java | 16 ++ .../apps/abit/service/ServicePowEngine.java | 16 ++ .../dissem/apps/abit/service/Singleton.java | 16 ++ .../abit/synchronization/Authenticator.java | 16 ++ .../synchronization/AuthenticatorService.java | 16 ++ .../abit/synchronization/StubProvider.java | 27 +++- .../abit/synchronization/SyncAdapter.java | 16 ++ .../abit/synchronization/SyncService.java | 20 ++- .../java/ch/dissem/apps/abit/util/Assets.java | 9 -- .../ch/dissem/apps/abit/util/Constants.java | 16 ++ .../ch/dissem/apps/abit/util/Drawables.java | 2 +- .../ch/dissem/apps/abit/util/PRNGFixes.java | 7 +- .../ch/dissem/apps/abit/util/Preferences.java | 16 ++ .../layout-w720dp/activity_message_list.xml | 4 +- .../main/res/layout/activity_message_list.xml | 4 +- .../layout/activity_open_bitmessage_link.xml | 7 +- app/src/main/res/layout/activity_status.xml | 3 +- app/src/main/res/layout/contact_row.xml | 15 +- .../res/layout/fragment_contact_detail.xml | 10 +- .../main/res/layout/fragment_contact_list.xml | 2 - .../res/layout/fragment_message_detail.xml | 20 ++- .../main/res/layout/fragment_message_list.xml | 2 - app/src/main/res/layout/message_row.xml | 14 +- app/src/main/res/layout/subscription_row.xml | 14 +- app/src/main/res/layout/toolbar_layout.xml | 6 +- app/src/main/res/menu/compose.xml | 2 +- app/src/main/res/menu/main.xml | 4 - .../main/res/values/library_jabit_strings.xml | 2 +- 58 files changed, 661 insertions(+), 468 deletions(-) delete mode 100644 app/src/main/res/menu/main.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5738a48..1eb392b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,7 +15,7 @@ @@ -114,7 +114,9 @@ android:exported="false" android:syncable="true"/> - + @@ -125,7 +127,8 @@ + android:exported="true" + tools:ignore="ExportedService"> diff --git a/app/src/main/java/ch/dissem/apps/abit/AbstractItemListFragment.java b/app/src/main/java/ch/dissem/apps/abit/AbstractItemListFragment.java index 7b03a55..5895277 100644 --- a/app/src/main/java/ch/dissem/apps/abit/AbstractItemListFragment.java +++ b/app/src/main/java/ch/dissem/apps/abit/AbstractItemListFragment.java @@ -16,7 +16,6 @@ package ch.dissem.apps.abit; -import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.support.v4.app.ListFragment; @@ -27,7 +26,7 @@ import ch.dissem.apps.abit.listener.ListSelectionListener; import ch.dissem.bitmessage.entity.valueobject.Label; /** - * Created by chris on 07.09.15. + * @author Christian Basler */ public abstract class AbstractItemListFragment extends ListFragment { /** @@ -39,7 +38,8 @@ public abstract class AbstractItemListFragment extends ListFragment { * A dummy implementation of the {@link ListSelectionListener} interface that does * nothing. Used only when this fragment is not attached to an activity. */ - private static ListSelectionListener dummyCallbacks = new ListSelectionListener() { + private static ListSelectionListener dummyCallbacks = new + ListSelectionListener() { @Override public void onItemSelected(Object plaintext) { } @@ -84,11 +84,13 @@ public abstract class AbstractItemListFragment extends ListFragment { super.onAttach(context); // Activities containing this fragment must implement its callbacks. - if (!(context instanceof ListSelectionListener)) { + if (context instanceof ListSelectionListener) { + //noinspection unchecked + callbacks = (ListSelectionListener) context; + } else { throw new IllegalStateException("Activity must implement fragment's callbacks."); } - callbacks = (ListSelectionListener) context; } @Override @@ -105,6 +107,7 @@ public abstract class AbstractItemListFragment extends ListFragment { // Notify the active callbacks interface (the activity, if the // fragment is attached to one) that an item has been selected. + //noinspection unchecked callbacks.onItemSelected((T) listView.getItemAtPosition(position)); } diff --git a/app/src/main/java/ch/dissem/apps/abit/ComposeMessageActivity.java b/app/src/main/java/ch/dissem/apps/abit/ComposeMessageActivity.java index a8f35fc..f6a2e38 100644 --- a/app/src/main/java/ch/dissem/apps/abit/ComposeMessageActivity.java +++ b/app/src/main/java/ch/dissem/apps/abit/ComposeMessageActivity.java @@ -1,9 +1,24 @@ +/* + * Copyright 2016 Christian Basler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package ch.dissem.apps.abit; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; -import ch.dissem.bitmessage.entity.BitmessageAddress; /** * Compose a new message. @@ -20,6 +35,7 @@ public class ComposeMessageActivity extends AppCompatActivity { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); + //noinspection ConstantConditions getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_action_close); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(false); diff --git a/app/src/main/java/ch/dissem/apps/abit/ComposeMessageFragment.java b/app/src/main/java/ch/dissem/apps/abit/ComposeMessageFragment.java index e262d29..9184996 100644 --- a/app/src/main/java/ch/dissem/apps/abit/ComposeMessageFragment.java +++ b/app/src/main/java/ch/dissem/apps/abit/ComposeMessageFragment.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 Christian Basler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package ch.dissem.apps.abit; import android.os.Bundle; @@ -8,7 +24,6 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.view.inputmethod.EditorInfo; import android.widget.AdapterView; import android.widget.AutoCompleteTextView; import android.widget.EditText; diff --git a/app/src/main/java/ch/dissem/apps/abit/Identicon.java b/app/src/main/java/ch/dissem/apps/abit/Identicon.java index 08ad67e..288e27e 100644 --- a/app/src/main/java/ch/dissem/apps/abit/Identicon.java +++ b/app/src/main/java/ch/dissem/apps/abit/Identicon.java @@ -16,13 +16,12 @@ package ch.dissem.apps.abit; - import android.graphics.*; import android.graphics.drawable.Drawable; import ch.dissem.bitmessage.entity.BitmessageAddress; /** - * + * @author Christian Basler */ public class Identicon extends Drawable { private static final int SIZE = 9; @@ -34,7 +33,6 @@ public class Identicon extends Drawable { private float cellWidth; private float cellHeight; - private byte[] hash; private int color; private int background; private boolean[][] fields; @@ -44,7 +42,7 @@ public class Identicon extends Drawable { paint.setStyle(Paint.Style.FILL); paint.setAntiAlias(true); - hash = input.getRipe(); + byte[] hash = input.getRipe(); fields = new boolean[SIZE][SIZE]; color = Color.HSVToColor(new float[]{Math.abs(hash[0] * hash[1] + hash[2]) % 360, 0.8f, 1.0f}); diff --git a/app/src/main/java/ch/dissem/apps/abit/MainActivity.java b/app/src/main/java/ch/dissem/apps/abit/MainActivity.java index c6e9296..f493cb3 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MainActivity.java +++ b/app/src/main/java/ch/dissem/apps/abit/MainActivity.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 Christian Basler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package ch.dissem.apps.abit; import android.app.AlertDialog; @@ -7,11 +23,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; -import android.os.Handler; import android.os.IBinder; -import android.os.Message; -import android.os.Messenger; -import android.os.RemoteException; import android.support.v4.app.Fragment; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; @@ -39,7 +51,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.Serializable; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -47,18 +58,16 @@ import java.util.List; import ch.dissem.apps.abit.listener.ActionBarListener; import ch.dissem.apps.abit.listener.ListSelectionListener; import ch.dissem.apps.abit.service.BitmessageService; +import ch.dissem.apps.abit.service.BitmessageService.BitmessageBinder; import ch.dissem.apps.abit.service.Singleton; import ch.dissem.apps.abit.synchronization.SyncAdapter; import ch.dissem.apps.abit.util.Preferences; +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 ch.dissem.bitmessage.ports.AddressRepository; -import ch.dissem.bitmessage.ports.MessageRepository; -import static ch.dissem.apps.abit.service.BitmessageService.DATA_FIELD_IDENTITY; -import static ch.dissem.apps.abit.service.BitmessageService.MSG_START_NODE; -import static ch.dissem.apps.abit.service.BitmessageService.MSG_STOP_NODE; +import static ch.dissem.apps.abit.service.BitmessageService.isRunning; /** @@ -92,14 +101,12 @@ public class MainActivity extends AppCompatActivity */ private boolean twoPane; - private static IncomingHandler incomingHandler = new IncomingHandler(); - private static Messenger messenger = new Messenger(incomingHandler); - private static Messenger service; + private static BitmessageBinder service; private static boolean bound; private static ServiceConnection connection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { - MainActivity.service = new Messenger(service); + MainActivity.service = (BitmessageBinder) service; MainActivity.bound = true; } @@ -112,16 +119,15 @@ public class MainActivity extends AppCompatActivity private Label selectedLabel; - private MessageRepository messageRepo; - private AddressRepository addressRepo; + private BitmessageContext bmc; private BitmessageAddress selectedIdentity; + private AccountHeader accountHeader; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - messageRepo = Singleton.getMessageRepository(this); - addressRepo = Singleton.getAddressRepository(this); - List