Skip to content

Commit 258dfee

Browse files
committed
add mention,hashtag sample
1 parent d66e8c5 commit 258dfee

8 files changed

Lines changed: 196 additions & 130 deletions

File tree

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/hasankucuk/socialtextviewsample/MainActivity.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,52 @@ package com.hasankucuk.socialtextviewsample
22

33
import androidx.appcompat.app.AppCompatActivity
44
import android.os.Bundle
5+
import android.widget.Toast
6+
import com.hasankucuk.socialtextview.SocialTextView
7+
import com.hasankucuk.socialtextview.model.LinkedType
8+
import com.hasankucuk.socialtextview.model.LinkedType.*
9+
import kotlinx.android.synthetic.main.activity_main.*
510

611
class MainActivity : AppCompatActivity() {
712

813
override fun onCreate(savedInstanceState: Bundle?) {
914
super.onCreate(savedInstanceState)
1015
setContentView(R.layout.activity_main)
1116

17+
18+
val mentions: MutableList<String> = arrayListOf()
19+
mentions.add("@hasann.kucuk")
20+
socialTextView.setLinkedMention(mentions)
21+
22+
val hashtags: MutableList<String> = arrayListOf()
23+
hashtags.add("developed")
24+
socialTextView.setLinkedHashtag(hashtags)
25+
26+
socialTextView.setLinkClickListener(object : SocialTextView.LinkClickListener {
27+
override fun onLinkClicked(linkType: LinkedType, matchedText: String) {
28+
29+
when (linkType) {
30+
TEXT -> {
31+
Toast.makeText(this@MainActivity, "You are clicked type -> TEXT and value ->$matchedText", Toast.LENGTH_SHORT).show()
32+
}
33+
HASHTAG -> {
34+
Toast.makeText(this@MainActivity, "You are clicked type -> HASHTAG and value ->$matchedText", Toast.LENGTH_SHORT).show()
35+
}
36+
MENTION -> {
37+
Toast.makeText(this@MainActivity, "You are clicked type -> MENTION and value ->$matchedText", Toast.LENGTH_SHORT).show()
38+
}
39+
URL -> {
40+
Toast.makeText(this@MainActivity, "You are clicked type -> URL and value ->$matchedText", Toast.LENGTH_SHORT).show()
41+
}
42+
EMAIL -> {
43+
Toast.makeText(this@MainActivity, "You are clicked type -> EMAIL and value ->$matchedText", Toast.LENGTH_SHORT).show()
44+
}
45+
PHONE -> {
46+
Toast.makeText(this@MainActivity, "You are clicked type -> PHONE and value ->$matchedText", Toast.LENGTH_SHORT).show()
47+
}
48+
}
49+
}
50+
})
51+
1252
}
1353
}
Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,64 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7+
android:orientation="vertical"
78
tools:context=".MainActivity">
89

10+
<TextView
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:layout_marginTop="50dp"
14+
android:paddingStart="15dp"
15+
android:text="*Example that links the values added with 'setLinkedMention' and 'setLinkedHashtag'."
16+
android:textColor="@android:color/black"
17+
android:textStyle="italic" />
18+
19+
<com.hasankucuk.socialtextview.SocialTextView
20+
android:id="@+id/socialTextView"
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content"
23+
android:padding="15dp"
24+
android:text="This project was #developed by @hasankucuk as #opensource. \n
25+
hasann.kucuk@yandex.ru \n
26+
https://medium.com/@hasann.kucuk \n
27+
hasan@gmail.com \n
28+
+1 123456789"
29+
app:emailColor="#FF9E80"
30+
app:hashtagColor="#82B1FF"
31+
app:linkType="mention|hashtag|phone|email|url"
32+
app:mentionColor="#BCBCCF"
33+
app:normalTextColor="#18181F"
34+
app:phoneColor="#03A9F4"
35+
app:urlColor="#8BC34A" />
36+
37+
<TextView
38+
android:layout_width="match_parent"
39+
android:layout_height="wrap_content"
40+
android:paddingStart="15dp"
41+
android:text="Linked example by selected 'linkType' "
42+
android:textColor="@android:color/black"
43+
android:textStyle="italic" />
44+
945
<com.hasankucuk.socialtextview.SocialTextView
46+
android:id="@+id/socialTextView2"
1047
android:layout_width="match_parent"
11-
android:layout_height="match_parent"
12-
android:text="Bu projece @hasankucuk tarafından #opensource olarak geliştirilmiştir."
13-
app:linkType="mention" />
48+
android:layout_height="wrap_content"
49+
android:padding="15dp"
50+
android:text="This project was #developed by @hasankucuk as #opensource. \n
51+
hasann.kucuk@yandex.ru \n
52+
https://medium.com/@hasann.kucuk \n
53+
hasan@gmail.com \n
54+
+1 123456789"
55+
app:emailColor="#FF9E80"
56+
app:hashtagColor="#82B1FF"
57+
app:linkType="mention|hashtag|phone|email|url"
58+
app:mentionColor="#BCBCCF"
59+
app:normalTextColor="#18181F"
60+
app:phoneColor="#03A9F4"
61+
app:urlColor="#8BC34A" />
1462

1563

16-
</androidx.constraintlayout.widget.ConstraintLayout>
64+
</LinearLayout>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<resources>
2-
<string name="app_name">app</string>
2+
<string name="app_name">SocialTextView</string>
33
</resources>

0 commit comments

Comments
 (0)