|
12 | 12 | import android.view.LayoutInflater;
|
13 | 13 | import android.view.View;
|
14 | 14 | import android.view.ViewGroup;
|
| 15 | +import android.widget.RelativeLayout; |
| 16 | +import android.widget.TextView; |
15 | 17 |
|
16 | 18 | import com.iterable.iterableapi.IterableActivityMonitor;
|
17 | 19 | import com.iterable.iterableapi.IterableApi;
|
| 20 | +import com.iterable.iterableapi.IterableConstants; |
18 | 21 | import com.iterable.iterableapi.IterableInAppDeleteActionType;
|
19 | 22 | import com.iterable.iterableapi.IterableInAppLocation;
|
20 | 23 | import com.iterable.iterableapi.IterableInAppManager;
|
@@ -45,6 +48,11 @@ public class IterableInboxFragment extends Fragment implements IterableInAppMana
|
45 | 48 |
|
46 | 49 | private InboxMode inboxMode = InboxMode.POPUP;
|
47 | 50 | 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; |
48 | 56 |
|
49 | 57 | private final SessionManager sessionManager = new SessionManager();
|
50 | 58 | private IterableInboxAdapterExtension adapterExtension = new DefaultAdapterExtension();
|
@@ -72,10 +80,16 @@ public class IterableInboxFragment extends Fragment implements IterableInAppMana
|
72 | 80 | * @return {@link IterableInboxFragment} instance
|
73 | 81 | */
|
74 | 82 | @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) { |
75 | 87 | IterableInboxFragment inboxFragment = new IterableInboxFragment();
|
76 | 88 | Bundle bundle = new Bundle();
|
77 | 89 | bundle.putSerializable(INBOX_MODE, inboxMode);
|
78 | 90 | bundle.putInt(ITEM_LAYOUT_ID, itemLayoutId);
|
| 91 | + bundle.putString(IterableConstants.NO_MESSAGES_TITLE, noMessagesTitle); |
| 92 | + bundle.putString(IterableConstants.NO_MESSAGES_BODY, noMessagesBody); |
79 | 93 | inboxFragment.setArguments(bundle);
|
80 | 94 |
|
81 | 95 | return inboxFragment;
|
@@ -153,15 +167,26 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
|
153 | 167 | if (arguments.getInt(ITEM_LAYOUT_ID, 0) != 0) {
|
154 | 168 | itemLayoutId = arguments.getInt(ITEM_LAYOUT_ID);
|
155 | 169 | }
|
| 170 | + if (arguments.getString(IterableConstants.NO_MESSAGES_TITLE) != null) { |
| 171 | + noMessagesTitle = arguments.getString(IterableConstants.NO_MESSAGES_TITLE); |
| 172 | + } |
| 173 | + if (arguments.getString(IterableConstants.NO_MESSAGES_BODY) != null) { |
| 174 | + noMessagesBody = arguments.getString(IterableConstants.NO_MESSAGES_BODY); |
| 175 | + } |
156 | 176 | }
|
157 | 177 |
|
158 |
| - RecyclerView view = (RecyclerView) inflater.inflate(R.layout.iterable_inbox_fragment, container, false); |
159 |
| - view.setLayoutManager(new LinearLayoutManager(getContext())); |
| 178 | + RelativeLayout relativeLayout = (RelativeLayout) inflater.inflate(R.layout.iterable_inbox_fragment, container, false); |
| 179 | + recyclerView = relativeLayout.findViewById(R.id.list); |
| 180 | + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); |
160 | 181 | IterableInboxAdapter adapter = new IterableInboxAdapter(IterableApi.getInstance().getInAppManager().getInboxMessages(), IterableInboxFragment.this, adapterExtension, comparator, filter, dateMapper);
|
161 |
| - view.setAdapter(adapter); |
| 182 | + recyclerView.setAdapter(adapter); |
| 183 | + noMessagesTitleTextView = relativeLayout.findViewById(R.id.emptyInboxTitle); |
| 184 | + noMessagesBodyTextView = relativeLayout.findViewById(R.id.emptyInboxMessage); |
| 185 | + noMessagesTitleTextView.setText(noMessagesTitle); |
| 186 | + noMessagesBodyTextView.setText(noMessagesBody); |
162 | 187 | ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new IterableInboxTouchHelper(getContext(), adapter));
|
163 |
| - itemTouchHelper.attachToRecyclerView(view); |
164 |
| - return view; |
| 188 | + itemTouchHelper.attachToRecyclerView(recyclerView); |
| 189 | + return relativeLayout; |
165 | 190 | }
|
166 | 191 |
|
167 | 192 | @Override
|
@@ -213,9 +238,21 @@ private void stopSession() {
|
213 | 238 | }
|
214 | 239 |
|
215 | 240 | private void updateList() {
|
216 |
| - RecyclerView recyclerView = (RecyclerView) getView(); |
217 | 241 | IterableInboxAdapter adapter = (IterableInboxAdapter) recyclerView.getAdapter();
|
218 | 242 | adapter.setInboxItems(IterableApi.getInstance().getInAppManager().getInboxMessages());
|
| 243 | + handleEmptyInbox(adapter); |
| 244 | + } |
| 245 | + |
| 246 | + private void handleEmptyInbox(IterableInboxAdapter adapter) { |
| 247 | + if (adapter.getItemCount() == 0) { |
| 248 | + noMessagesTitleTextView.setVisibility(View.VISIBLE); |
| 249 | + noMessagesBodyTextView.setVisibility(View.VISIBLE); |
| 250 | + recyclerView.setVisibility(View.INVISIBLE); |
| 251 | + } else { |
| 252 | + noMessagesTitleTextView.setVisibility(View.INVISIBLE); |
| 253 | + noMessagesBodyTextView.setVisibility(View.INVISIBLE); |
| 254 | + recyclerView.setVisibility(View.VISIBLE); |
| 255 | + } |
219 | 256 | }
|
220 | 257 |
|
221 | 258 | @Override
|
|
0 commit comments