This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ClickableSpan for user mentions
- Loading branch information
Showing
5 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.zulip.android.util; | ||
|
||
import android.content.Context; | ||
import android.text.TextPaint; | ||
import android.text.style.ClickableSpan; | ||
import android.view.View; | ||
|
||
import com.zulip.android.ZulipApp; | ||
import com.zulip.android.filters.NarrowFilterPM; | ||
import com.zulip.android.models.Person; | ||
|
||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ProfileSpan extends ClickableSpan { | ||
private String email; | ||
private int userMentionColor; | ||
|
||
public ProfileSpan(String email, int color) { | ||
this.email = email; | ||
userMentionColor = color; | ||
} | ||
|
||
@Override | ||
public void onClick(View widget) { | ||
Context context = widget.getContext().getApplicationContext(); | ||
List<Person> people = new ArrayList<Person>(); | ||
if (email.equals("*")) { //This is for "@all" | ||
try { | ||
people = Person.getAllPeople(ZulipApp.get()); | ||
} catch (SQLException e) { | ||
ZLog.logException(e); | ||
return; | ||
} | ||
} else { | ||
for (String email : this.email.split(",")) { | ||
people.add(Person.getByEmail(ZulipApp.get(), email)); | ||
} | ||
} | ||
(((ZulipApp) context).getZulipActivity()).doNarrow(new NarrowFilterPM(people)); | ||
} | ||
|
||
@Override | ||
public void updateDrawState(TextPaint ds) { | ||
ds.setColor(userMentionColor); | ||
} | ||
} |