From 572ecf1577d2f303349c642e206473d6af2d7510 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Thu, 20 Apr 2017 07:23:21 +0200 Subject: [PATCH] Some minor fixes for working with extended encoding --- .../apps/abit/ComposeMessageActivity.java | 2 +- .../apps/abit/ComposeMessageFragment.java | 17 +++++++++++++++++ .../dissem/apps/abit/MessageDetailFragment.java | 7 +++++-- .../repository/AndroidMessageRepository.java | 4 ++-- .../main/res/layout/fragment_message_detail.xml | 5 +++-- 5 files changed, 28 insertions(+), 7 deletions(-) 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 2df2a68..1cde1b0 100644 --- a/app/src/main/java/ch/dissem/apps/abit/ComposeMessageActivity.java +++ b/app/src/main/java/ch/dissem/apps/abit/ComposeMessageActivity.java @@ -87,8 +87,8 @@ public class ComposeMessageActivity extends AppCompatActivity { // so features like threading can be supported if (item.getEncoding() == EXTENDED) { replyIntent.putExtra(EXTRA_ENCODING, EXTENDED); - replyIntent.putExtra(EXTRA_PARENT, item); } + replyIntent.putExtra(EXTRA_PARENT, item); String prefix; if (item.getSubject().length() >= 3 && item.getSubject().substring(0, 3) .equalsIgnoreCase("RE:")) { 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 4413933..142e8f8 100644 --- a/app/src/main/java/ch/dissem/apps/abit/ComposeMessageFragment.java +++ b/app/src/main/java/ch/dissem/apps/abit/ComposeMessageFragment.java @@ -16,6 +16,7 @@ package ch.dissem.apps.abit; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -79,6 +80,11 @@ public class ComposeMessageFragment extends Fragment { if (getArguments() != null) { if (getArguments().containsKey(EXTRA_IDENTITY)) { identity = (BitmessageAddress) getArguments().getSerializable(EXTRA_IDENTITY); + if (getActivity() != null) { + if (identity == null || identity.getPrivateKey() == null) { + identity = Singleton.getIdentity(getActivity()); + } + } } else { throw new RuntimeException("No identity set for ComposeMessageFragment"); } @@ -156,6 +162,14 @@ public class ComposeMessageFragment extends Fragment { return rootView; } + @Override + public void onAttach(Context context) { + super.onAttach(context); + if (identity == null || identity.getPrivateKey() == null) { + identity = Singleton.getIdentity(context); + } + } + @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.compose, menu); @@ -170,6 +184,9 @@ public class ComposeMessageFragment extends Fragment { return true; case R.id.select_encoding: SelectEncodingDialogFragment encodingDialog = new SelectEncodingDialogFragment(); + Bundle args = new Bundle(); + args.putSerializable(EXTRA_ENCODING, encoding); + encodingDialog.setArguments(args); encodingDialog.setTargetFragment(this, 0); encodingDialog.show(getFragmentManager(), "select encoding dialog"); return true; diff --git a/app/src/main/java/ch/dissem/apps/abit/MessageDetailFragment.java b/app/src/main/java/ch/dissem/apps/abit/MessageDetailFragment.java index 0552cb6..90137ed 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MessageDetailFragment.java +++ b/app/src/main/java/ch/dissem/apps/abit/MessageDetailFragment.java @@ -156,7 +156,10 @@ public class MessageDetailFragment extends Fragment { } List parents = new ArrayList<>(item.getParents().size()); for (InventoryVector parentIV : item.getParents()) { - parents.add(messageRepo.getMessage(parentIV)); + Plaintext parent = messageRepo.getMessage(parentIV); + if (parent != null) { + parents.add(parent); + } } showRelatedMessages(rootView, R.id.parents, parents); showRelatedMessages(rootView, R.id.responses, messageRepo.findResponses(item)); @@ -165,7 +168,7 @@ public class MessageDetailFragment extends Fragment { } private void showRelatedMessages(View rootView, @IdRes int id, List<Plaintext> messages) { - RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.parents); + RecyclerView recyclerView = (RecyclerView) rootView.findViewById(id); RelatedMessageAdapter adapter = new RelatedMessageAdapter(getActivity(), messages); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); diff --git a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java index b38cb1d..f305ffb 100644 --- a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java +++ b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java @@ -201,9 +201,9 @@ public class AndroidMessageRepository extends AbstractMessageRepository { // There are no parents to save yet (they are saved in the extended data, that's enough for now) return; } - db.delete(PARENTS_TABLE_NAME, "child=?", new String[]{hex(message.getInitialHash()).toString()}); - byte[] childIV = message.getInventoryVector().getHash(); + db.delete(PARENTS_TABLE_NAME, "child=?", new String[]{hex(childIV).toString()}); + // save new parents int order = 0; for (InventoryVector parentIV : message.getParents()) { diff --git a/app/src/main/res/layout/fragment_message_detail.xml b/app/src/main/res/layout/fragment_message_detail.xml index e698bf5..73bb3d9 100644 --- a/app/src/main/res/layout/fragment_message_detail.xml +++ b/app/src/main/res/layout/fragment_message_detail.xml @@ -105,13 +105,14 @@ android:layout_height="wrap_content" android:layout_below="@+id/text" android:layout_marginLeft="16dp" - android:layout_marginRight="16dp" /> + android:layout_marginRight="16dp" + android:layout_marginBottom="16dp"/> <android.support.v7.widget.RecyclerView android:id="@+id/responses" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:layout_below="@+id/text" + android:layout_below="@+id/labels" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" /> </RelativeLayout>