Skip to content

Commit 09f0a2f

Browse files
committed
Revision 4
Added recommended changes 1. Added constructor to IterableInboxFragment. Now setArguments wont overwrite arguments set by newInstance method. 2. Removed `this` while referencing global variable 3. Updated message TextView in XML to have layout below Title textView. No more hardcoded placement of views. 4. Added nullable notations
1 parent 5a24d19 commit 09f0a2f

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

iterableapi-ui/src/main/java/com/iterable/iterableapi/ui/inbox/IterableInboxActivity.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import androidx.annotation.Nullable;
66
import androidx.appcompat.app.AppCompatActivity;
77

8+
import com.iterable.iterableapi.IterableConstants;
89
import com.iterable.iterableapi.IterableLogger;
910
import com.iterable.iterableapi.ui.R;
1011

@@ -37,8 +38,14 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
3738
if (inboxModeExtra instanceof InboxMode) {
3839
inboxMode = (InboxMode) inboxModeExtra;
3940
}
40-
inboxFragment = IterableInboxFragment.newInstance(inboxMode, itemLayoutId);
41-
inboxFragment.setArguments(intent.getExtras());
41+
String noMessageTitle = null;
42+
String noMessageBody = null;
43+
Bundle extraBundle = getIntent().getExtras();
44+
if (extraBundle != null) {
45+
noMessageTitle = extraBundle.getString(IterableConstants.NO_MESSAGES_TITLE, null);
46+
noMessageBody = extraBundle.getString(IterableConstants.NO_MESSAGES_BODY, null);
47+
}
48+
inboxFragment = IterableInboxFragment.newInstance(inboxMode, itemLayoutId, noMessageTitle, noMessageBody);
4249

4350
if (intent.getStringExtra(ACTIVITY_TITLE) != null) {
4451
setTitle(intent.getStringExtra(ACTIVITY_TITLE));

iterableapi-ui/src/main/java/com/iterable/iterableapi/ui/inbox/IterableInboxFragment.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ public class IterableInboxFragment extends Fragment implements IterableInAppMana
4848

4949
private InboxMode inboxMode = InboxMode.POPUP;
5050
private @LayoutRes int itemLayoutId = R.layout.iterable_inbox_item;
51+
private String noMessagesTitle;
52+
private String noMessagesBody;
53+
TextView noMessagesTitleTextView;
54+
TextView noMessagesBodyTextView;
55+
RecyclerView recyclerView;
5156

5257
private final SessionManager sessionManager = new SessionManager();
5358
private IterableInboxAdapterExtension adapterExtension = new DefaultAdapterExtension();
5459
private IterableInboxComparator comparator = new DefaultInboxComparator();
5560
private IterableInboxFilter filter = new DefaultInboxFilter();
5661
private IterableInboxDateMapper dateMapper = new DefaultInboxDateMapper();
5762
private boolean sessionStarted = false;
58-
private String noMessagesTitle;
59-
private String noMessagesBody;
6063

61-
TextView noMessagesTitleTextView;
62-
TextView noMessagesBodyTextView;
63-
RecyclerView recyclerView;
6464
/**
6565
* Create an Inbox fragment with default parameters
6666
*
@@ -80,10 +80,16 @@ public class IterableInboxFragment extends Fragment implements IterableInAppMana
8080
* @return {@link IterableInboxFragment} instance
8181
*/
8282
@NonNull public static IterableInboxFragment newInstance(@NonNull InboxMode inboxMode, @LayoutRes int itemLayoutId) {
83+
return newInstance(inboxMode, itemLayoutId, null, null);
84+
}
85+
86+
@NonNull public static IterableInboxFragment newInstance(@NonNull InboxMode inboxMode, @LayoutRes int itemLayoutId, @Nullable String noMessagesTitle, @Nullable String noMessagesBody) {
8387
IterableInboxFragment inboxFragment = new IterableInboxFragment();
8488
Bundle bundle = new Bundle();
8589
bundle.putSerializable(INBOX_MODE, inboxMode);
8690
bundle.putInt(ITEM_LAYOUT_ID, itemLayoutId);
91+
bundle.putString(IterableConstants.NO_MESSAGES_TITLE, noMessagesTitle);
92+
bundle.putString(IterableConstants.NO_MESSAGES_BODY, noMessagesBody);
8793
inboxFragment.setArguments(bundle);
8894

8995
return inboxFragment;
@@ -162,10 +168,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
162168
itemLayoutId = arguments.getInt(ITEM_LAYOUT_ID);
163169
}
164170
if (arguments.getString(IterableConstants.NO_MESSAGES_TITLE) != null) {
165-
this.noMessagesTitle = arguments.getString(IterableConstants.NO_MESSAGES_TITLE);
171+
noMessagesTitle = arguments.getString(IterableConstants.NO_MESSAGES_TITLE);
166172
}
167173
if (arguments.getString(IterableConstants.NO_MESSAGES_BODY) != null) {
168-
this.noMessagesBody = arguments.getString(IterableConstants.NO_MESSAGES_BODY);
174+
noMessagesBody = arguments.getString(IterableConstants.NO_MESSAGES_BODY);
169175
}
170176
}
171177

iterableapi-ui/src/main/res/layout/iterable_inbox_fragment.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
<TextView
2020
android:id="@+id/emptyInboxTitle"
2121
android:layout_width="match_parent"
22-
android:layout_height="match_parent"
22+
android:layout_height="wrap_content"
23+
android:layout_centerInParent="true"
2324
android:gravity="center"
2425
android:textSize="18sp"
25-
android:textStyle="bold"
26-
android:translationY="-16sp" />
26+
android:textStyle="bold" />
2727

2828
<TextView
29+
android:layout_below="@id/emptyInboxTitle"
2930
android:id="@+id/emptyInboxMessage"
3031
android:layout_width="match_parent"
31-
android:layout_height="match_parent"
32-
android:gravity="center"
33-
android:translationY="16sp" />
32+
android:layout_height="wrap_content"
33+
android:gravity="center" />
3434
</RelativeLayout>

0 commit comments

Comments
 (0)