Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 7eaacdc

Browse files
kunall17niftynei
authored andcommitted
Setup a ViewBinder for the Adapter
1 parent f0be056 commit 7eaacdc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

app/src/main/java/com/zulip/android/activities/ZulipActivity.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ public class ZulipActivity extends AppCompatActivity implements
9191

9292
public static final String NARROW = "narrow";
9393
public static final String PARAMS = "params";
94+
//At these many letters the emoji/person hint will not show now on
95+
private static final int MAX_THRESOLD_EMOJI_HINT = 5;
96+
//At these many letters the emoji/person hint starts to show up
97+
private static final int MIN_THRESOLD_EMOJI_HINT = 1;
9498
ZulipApp app;
9599
List<Message> mutedTopics;
96100

@@ -383,6 +387,35 @@ public void onClick(View v) {
383387
new String[]{Emoji.NAME_FIELD, Emoji.NAME_FIELD},
384388
new int[]{R.id.emojiImageView, R.id.nameTV}, 0);
385389

390+
combinedAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
391+
@Override
392+
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
393+
//TODO - columnIndex is 6 for Person table and columnIndex is 1 for Emoji table, Confirm this will be perfect to distinguish between these two tables! It seems alphabetical ordering of columns!
394+
boolean personTable = !(columnIndex == 1);
395+
String name = cursor.getString(cursor.getColumnIndex(Emoji.NAME_FIELD));
396+
switch (view.getId()) {
397+
case R.id.emojiImageView:
398+
if (personTable) {
399+
view.setVisibility(View.GONE);
400+
} else {
401+
try {
402+
Drawable drawable = Drawable.createFromStream(getApplicationContext().getAssets().open("emoji/" + name),
403+
"emoji/" + name);
404+
((ImageView) view).setImageDrawable(drawable);
405+
} catch (Exception e) {
406+
ZLog.logException(e);
407+
}
408+
}
409+
return true;
410+
case R.id.nameTV:
411+
((TextView) view).setText(name);
412+
return true;
413+
}
414+
if (BuildConfig.DEBUG)
415+
ZLog.logException(new RuntimeException(getResources().getResourceName(view.getId()) + " - this view not binded!"));
416+
return false;
417+
}
418+
});
386419
combinedAdapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() {
387420
@Override
388421
public CharSequence convertToString(Cursor cursor) {

0 commit comments

Comments
 (0)