From daa58c7c6e90747d6eb4c3b1f148d6e3120e926b Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Tue, 25 Jul 2017 18:37:05 +0200 Subject: [PATCH] Add "longContent" to show the full content from the .docx Fix initializing when user navigates back to the list --- .../poitest/DocumentDetailFragment.java | 2 +- .../poitest/DocumentListActivity.java | 5 ++++- .../poitest/dummy/DummyContent.java | 19 ++++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/DocumentDetailFragment.java b/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/DocumentDetailFragment.java index 192bf2d5f..a024d4283 100644 --- a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/DocumentDetailFragment.java +++ b/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/DocumentDetailFragment.java @@ -52,7 +52,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, // Show the dummy content as text in a TextView. if (mItem != null) { - ((TextView) rootView.findViewById(R.id.document_detail)).setText(mItem.content); + ((TextView) rootView.findViewById(R.id.document_detail)).setText(mItem.longContent); } return rootView; diff --git a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/DocumentListActivity.java b/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/DocumentListActivity.java index 6bed78d6e..e0bae71c5 100644 --- a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/DocumentListActivity.java +++ b/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/DocumentListActivity.java @@ -87,6 +87,9 @@ protected void onCreate(Bundle savedInstanceState) { InputStream input = openFileInput("test.xlsx"); wb = WorkbookFactory.create(input); + // refresh the content as we re-enter here if the user navigates back from the detail view + DummyContent.initialize(); + // replace the dummy-content to show that we could write and read the cell-values int i = 0; row = wb.getSheetAt(0).getRow(0); @@ -103,7 +106,7 @@ protected void onCreate(Bundle savedInstanceState) { XWPFDocument doc = new XWPFDocument(docFile); try { for(XWPFParagraph paragraph : doc.getParagraphs()) { - DummyContent.addItem(new DummyContent.DummyItem(Integer.toString(i), StringUtils.abbreviate(paragraph.getText(), 10))); + DummyContent.addItem(new DummyContent.DummyItem(Integer.toString(i), StringUtils.abbreviate(paragraph.getText(), 20), paragraph.getText())); i++; } } finally { diff --git a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/dummy/DummyContent.java b/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/dummy/DummyContent.java index eac57451a..b71a95710 100644 --- a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/dummy/DummyContent.java +++ b/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/dummy/DummyContent.java @@ -21,13 +21,20 @@ public class DummyContent { /** * A map of sample (dummy) items, by ID. */ - public static Map ITEM_MAP = new HashMap(); + public static Map ITEM_MAP = new HashMap<>(); static { + initialize(); + } + + public static void initialize() { + DummyContent.ITEM_MAP.clear(); + DummyContent.ITEMS.clear(); + // Add 3 sample items. - addItem(new DummyItem("1", "Item 1")); - addItem(new DummyItem("2", "Item 2")); - addItem(new DummyItem("3", "Item 3")); + addItem(new DummyItem("1", "Item 1", "Long Item 1")); + addItem(new DummyItem("2", "Item 2", "Long Item 1")); + addItem(new DummyItem("3", "Item 3", "Long Item 1")); } public static void addItem(DummyItem item) { @@ -41,10 +48,12 @@ public static void addItem(DummyItem item) { public static class DummyItem { public String id; public String content; + public String longContent; - public DummyItem(String id, String content) { + public DummyItem(String id, String content, String longContent) { this.id = id; this.content = content; + this.longContent = longContent; } @Override