Skip to content

Commit 06a7b05

Browse files
committed
Support dynamic icons for common platforms
1 parent b27e169 commit 06a7b05

10 files changed

Lines changed: 104 additions & 4 deletions

File tree

app/src/main/java/com/amrdeveloper/linkhub/ui/components/Links.kt

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,18 @@ fun LinkItem(
7979
), verticalAlignment = Alignment.CenterVertically
8080
) {
8181
Icon(
82-
painter = painterResource(id = R.drawable.ic_link),
82+
painter = painterResource(id = findPlatformDomainIcon(link.url)),
8383
contentDescription = "Link Icon",
8484
tint = Color.Unspecified
8585
)
8686

8787
Spacer(modifier = Modifier.width(8.dp))
8888

89-
Column(modifier = Modifier
90-
.weight(1f)
91-
.padding(3.dp)) {
89+
Column(
90+
modifier = Modifier
91+
.weight(1f)
92+
.padding(3.dp)
93+
) {
9294
Text(
9395
link.title,
9496
maxLines = 1,
@@ -148,6 +150,28 @@ fun LinkItem(
148150
}
149151
}
150152

153+
private val platformDomainIconsForUrl = mutableMapOf(
154+
"instagram.com" to R.drawable.ic_platform_instagram,
155+
"facebook.com" to R.drawable.ic_platform_facebook,
156+
"reddit.com" to R.drawable.ic_platform_reddit,
157+
"twitch.com" to R.drawable.ic_platform_twitch,
158+
"youtube.com" to R.drawable.ic_platform_youtube,
159+
160+
"github.com" to R.drawable.ic_platform_github,
161+
"linkedin.com" to R.drawable.ic_platform_linkedin,
162+
"www.amazon" to R.drawable.ic_platform_amazon,
163+
"google.com" to R.drawable.ic_platform_google
164+
)
165+
166+
private fun findPlatformDomainIcon(url: String): Int {
167+
for (domain in platformDomainIconsForUrl.keys) {
168+
if (url.contains(other = domain)) {
169+
return platformDomainIconsForUrl[domain]!!
170+
}
171+
}
172+
return R.drawable.ic_link
173+
}
174+
151175
@Preview(showBackground = true)
152176
@Composable
153177
fun LinkListPreview() {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="25dp" android:viewportHeight="1024" android:viewportWidth="1024" android:width="25dp">
2+
3+
<path android:fillColor="#f90" android:pathData="M512,512m-512,0a512,512 0,1 1,1024 0a512,512 0,1 1,-1024 0"/>
4+
5+
<path android:fillColor="#fff" android:pathData="M256.9,640.5c1.5,-2.5 4,-2.6 7.4,-0.5 77.6,45 162.1,67.6 253.3,67.6 60.9,0 121,-11.4 180.3,-34l6.7,-3c2.9,-1.3 5,-2.1 6.3,-2.8 4.8,-1.9 8.3,-1 11.2,2.8 2.6,3.7 1.9,7.2 -2.6,10.2 -5.5,4.1 -12.8,8.8 -21.5,14 -26.5,15.9 -56.3,28.1 -89.3,36.8 -32.7,8.7 -65,13 -96.4,13 -48.3,0 -94.1,-8.5 -137.3,-25.3 -43.1,-16.9 -81.5,-40.8 -115.9,-71.5 -2.1,-1.6 -3.2,-3.2 -3.2,-4.7 0,-1 0.4,-1.9 1.1,-2.8l-0.1,0.2zM397.1,507.8c0,-21.4 5.3,-39.8 15.9,-55 10.6,-15.2 25,-26.7 43.5,-34.5 17,-7.1 37.5,-12.3 62.1,-15.4 8.3,-1 22,-2.2 41,-3.7v-7.9c0,-19.8 -2.2,-33.3 -6.4,-40 -6.4,-9.2 -16.6,-13.9 -30.7,-13.9h-3.9c-10.2,1 -19.1,4.2 -26.6,9.8 -7.5,5.8 -12.3,13.4 -14.4,23.4 -1.3,6.4 -4.4,9.9 -9.3,10.9l-53.8,-6.7c-5.3,-1.3 -7.9,-3.8 -7.9,-8.3 0,-1 0.1,-1.9 0.5,-3.2 5.3,-27.5 18.2,-48 38.8,-61.5 20.8,-13.1 44.8,-20.8 72.4,-22.4h11.5c35.2,0 63.1,9.3 83,27.5 2.9,3.2 5.8,6.4 8.6,10.2 2.6,3.5 4.8,6.7 6,9.6 1.6,2.9 3.2,7 4.2,12.2 1.3,5.4 2.2,9 2.9,10.9 0.6,2.2 1.3,6.4 1.6,13.1 0.2,6.7 0.4,10.5 0.4,11.8v112.7c0,8 1.3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2,-0.3 -3.8,-0.9 -0.6,-0.6 -0.8,-1 -0.4,-1.6 0,-0.4 0.1,-0.6 0.4,-1.3v-1.3l0.3,-0.2z"/>
6+
7+
</vector>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="25dp" android:viewportHeight="16" android:viewportWidth="16" android:width="25dp">
2+
3+
<path android:fillColor="#1877F2" android:pathData="M15,8a7,7 0,0 0,-7 -7,7 7,0 0,0 -1.094,13.915v-4.892H5.13V8h1.777V6.458c0,-1.754 1.045,-2.724 2.644,-2.724 0.766,0 1.567,0.137 1.567,0.137v1.723h-0.883c-0.87,0 -1.14,0.54 -1.14,1.093V8h1.941l-0.31,2.023H9.094v4.892A7.001,7.001 0,0 0,15 8z"/>
4+
5+
<path android:fillColor="#ffffff" android:pathData="M10.725,10.023L11.035,8H9.094V6.687c0,-0.553 0.27,-1.093 1.14,-1.093h0.883V3.87s-0.801,-0.137 -1.567,-0.137c-1.6,0 -2.644,0.97 -2.644,2.724V8H5.13v2.023h1.777v4.892a7.037,7.037 0,0 0,2.188 0v-4.892h1.63z"/>
6+
7+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="25dp" android:viewportHeight="16" android:viewportWidth="16" android:width="25dp">
2+
3+
<path android:fillColor="#161514" android:fillType="evenOdd" android:pathData="M8,1C4.133,1 1,4.13 1,7.993c0,3.09 2.006,5.71 4.787,6.635 0.35,0.064 0.478,-0.152 0.478,-0.337 0,-0.166 -0.006,-0.606 -0.01,-1.19 -1.947,0.423 -2.357,-0.937 -2.357,-0.937 -0.319,-0.808 -0.778,-1.023 -0.778,-1.023 -0.635,-0.434 0.048,-0.425 0.048,-0.425 0.703,0.05 1.073,0.72 1.073,0.72 0.624,1.07 1.638,0.76 2.037,0.582 0.063,-0.452 0.244,-0.76 0.444,-0.935 -1.554,-0.176 -3.188,-0.776 -3.188,-3.456 0,-0.763 0.273,-1.388 0.72,-1.876 -0.072,-0.177 -0.312,-0.888 0.07,-1.85 0,0 0.586,-0.189 1.924,0.716A6.711,6.711 0,0 1,8 4.381c0.595,0.003 1.194,0.08 1.753,0.236 1.336,-0.905 1.923,-0.717 1.923,-0.717 0.382,0.963 0.142,1.674 0.07,1.85 0.448,0.49 0.72,1.114 0.72,1.877 0,2.686 -1.638,3.278 -3.197,3.45 0.251,0.216 0.475,0.643 0.475,1.296 0,0.934 -0.009,1.688 -0.009,1.918 0,0.187 0.127,0.404 0.482,0.336A6.996,6.996 0,0 0,15 7.993,6.997 6.997,0 0,0 8,1z"/>
4+
5+
</vector>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="64dp"
3+
android:height="64dp"
4+
android:viewportWidth="16"
5+
android:viewportHeight="16">
6+
<path
7+
android:pathData="M14.9,8.161c0,-0.476 -0.039,-0.954 -0.121,-1.422h-6.64v2.695h3.802a3.24,3.24 0,0 1,-1.407 2.127v1.75h2.269c1.332,-1.22 2.097,-3.02 2.097,-5.15z"
8+
android:fillColor="#4285F4"/>
9+
<path
10+
android:pathData="M8.14,15c1.898,0 3.499,-0.62 4.665,-1.69l-2.268,-1.749c-0.631,0.427 -1.446,0.669 -2.395,0.669 -1.836,0 -3.393,-1.232 -3.952,-2.888H1.85v1.803A7.044,7.044 0,0 0,8.14 15z"
11+
android:fillColor="#34A853"/>
12+
<path
13+
android:pathData="M4.187,9.342a4.17,4.17 0,0 1,0 -2.68V4.859H1.849a6.97,6.97 0,0 0,0 6.286l2.338,-1.803z"
14+
android:fillColor="#FBBC04"/>
15+
<path
16+
android:pathData="M8.14,3.77a3.837,3.837 0,0 1,2.7 1.05l2.01,-1.999a6.786,6.786 0,0 0,-4.71 -1.82,7.042 7.042,0 0,0 -6.29,3.858L4.186,6.66c0.556,-1.658 2.116,-2.89 3.952,-2.89z"
17+
android:fillColor="#EA4335"/>
18+
</vector>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="25dp" android:viewportHeight="48" android:viewportWidth="48" android:width="25dp">
2+
3+
<path android:fillColor="#C13584" android:pathData="M24,24m-20,0a20,20 0,1 1,40 0a20,20 0,1 1,-40 0"/>
4+
5+
<path android:fillColor="#ffffff" android:pathData="M24,14.162C27.204,14.162 27.584,14.174 28.849,14.232C30.019,14.285 30.654,14.481 31.077,14.645C31.637,14.863 32.037,15.123 32.457,15.543C32.877,15.963 33.137,16.363 33.355,16.923C33.519,17.346 33.715,17.981 33.768,19.151C33.826,20.416 33.838,20.796 33.838,24C33.838,27.204 33.826,27.584 33.768,28.849C33.715,30.019 33.519,30.654 33.355,31.077C33.137,31.637 32.877,32.037 32.457,32.457C32.037,32.877 31.637,33.137 31.077,33.355C30.654,33.519 30.019,33.714 28.849,33.768C27.584,33.826 27.204,33.838 24,33.838C20.796,33.838 20.416,33.826 19.151,33.768C17.981,33.714 17.346,33.519 16.923,33.355C16.363,33.137 15.963,32.877 15.543,32.457C15.123,32.037 14.863,31.637 14.645,31.077C14.481,30.654 14.285,30.019 14.232,28.849C14.174,27.584 14.162,27.204 14.162,24C14.162,20.796 14.174,20.416 14.232,19.151C14.285,17.981 14.481,17.346 14.645,16.923C14.863,16.363 15.123,15.963 15.543,15.543C15.963,15.123 16.363,14.863 16.923,14.645C17.346,14.481 17.981,14.285 19.151,14.232C20.416,14.174 20.796,14.162 24,14.162ZM24,12C20.741,12 20.332,12.014 19.052,12.072C17.775,12.13 16.903,12.333 16.139,12.63C15.35,12.937 14.681,13.347 14.014,14.014C13.347,14.681 12.937,15.35 12.63,16.139C12.333,16.903 12.13,17.775 12.072,19.052C12.014,20.332 12,20.741 12,24C12,27.259 12.014,27.668 12.072,28.948C12.13,30.225 12.333,31.097 12.63,31.86C12.937,32.65 13.347,33.319 14.014,33.986C14.681,34.653 15.35,35.063 16.139,35.37C16.903,35.667 17.775,35.869 19.052,35.928C20.332,35.986 20.741,36 24,36C27.259,36 27.668,35.986 28.948,35.928C30.225,35.869 31.097,35.667 31.861,35.37C32.65,35.063 33.319,34.653 33.986,33.986C34.653,33.319 35.063,32.65 35.37,31.86C35.667,31.097 35.869,30.225 35.928,28.948C35.986,27.668 36,27.259 36,24C36,20.741 35.986,20.332 35.928,19.052C35.869,17.775 35.667,16.903 35.37,16.139C35.063,15.35 34.653,14.681 33.986,14.014C33.319,13.347 32.65,12.937 31.861,12.63C31.097,12.333 30.225,12.13 28.948,12.072C27.668,12.014 27.259,12 24,12Z"/>
6+
7+
<path android:fillColor="#ffffff" android:pathData="M24.006,17.843C20.603,17.843 17.844,20.602 17.844,24.005C17.844,27.409 20.603,30.167 24.006,30.167C27.409,30.167 30.168,27.409 30.168,24.005C30.168,20.602 27.409,17.843 24.006,17.843ZM24.006,28.005C21.797,28.005 20.006,26.215 20.006,24.005C20.006,21.796 21.797,20.005 24.006,20.005C26.215,20.005 28.006,21.796 28.006,24.005C28.006,26.215 26.215,28.005 24.006,28.005Z"/>
8+
9+
<path android:fillColor="#ffffff" android:pathData="M31.851,17.596C31.851,18.392 31.206,19.036 30.411,19.036C29.615,19.036 28.971,18.392 28.971,17.596C28.971,16.801 29.615,16.156 30.411,16.156C31.206,16.156 31.851,16.801 31.851,17.596Z"/>
10+
11+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="25dp" android:viewportHeight="16" android:viewportWidth="16" android:width="25dp">
2+
3+
<path android:fillColor="#0A66C2" android:pathData="M12.225,12.225h-1.778L10.447,9.44c0,-0.664 -0.012,-1.519 -0.925,-1.519 -0.926,0 -1.068,0.724 -1.068,1.47v2.834L6.676,12.225L6.676,6.498h1.707v0.783h0.024c0.348,-0.594 0.996,-0.95 1.684,-0.925 1.802,0 2.135,1.185 2.135,2.728l-0.001,3.14zM4.67,5.715a1.037,1.037 0,0 1,-1.032 -1.031c0,-0.566 0.466,-1.032 1.032,-1.032 0.566,0 1.031,0.466 1.032,1.032 0,0.566 -0.466,1.032 -1.032,1.032zM5.559,12.225h-1.78L3.779,6.498h1.78v5.727zM13.11,2L2.885,2A0.88,0.88 0,0 0,2 2.866v10.268a0.88,0.88 0,0 0,0.885 0.866h10.226a0.882,0.882 0,0 0,0.889 -0.866L14,2.865a0.88,0.88 0,0 0,-0.889 -0.864z"/>
4+
5+
</vector>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="25dp" android:viewportHeight="32" android:viewportWidth="32" android:width="25dp">
2+
3+
<path android:fillColor="#FC471E" android:pathData="M16,2C8.278,2 2,8.278 2,16C2,23.722 8.278,30 16,30C23.722,30 30,23.722 30,16C30,8.278 23.722,2 16,2Z"/>
4+
5+
<path android:fillColor="#ffffff" android:fillType="evenOdd" android:pathData="M20.019,8.91C20.007,8.99 20,9.072 20,9.156C20,10.004 20.672,10.692 21.5,10.692C22.328,10.692 23,10.004 23,9.156C23,8.308 22.328,7.621 21.5,7.621C21.131,7.621 20.793,7.757 20.531,7.984L16.636,7L15.228,12.765C13.355,12.891 11.671,13.472 10.4,14.349C10.04,13.986 9.545,13.763 9,13.763C7.895,13.763 7,14.68 7,15.81C7,16.597 7.434,17.281 8.07,17.623C8.024,17.867 8,18.117 8,18.37C8,21.479 11.582,24 16,24C20.418,24 24,21.479 24,18.37C24,18.117 23.976,17.867 23.93,17.623C24.566,17.281 25,16.597 25,15.81C25,14.68 24.105,13.763 23,13.763C22.455,13.763 21.961,13.986 21.6,14.349C20.215,13.394 18.34,12.79 16.265,12.742L17.364,8.241L20.019,8.91ZM12.5,18.882C13.328,18.882 14,18.194 14,17.346C14,16.498 13.328,15.81 12.5,15.81C11.672,15.81 11,16.498 11,17.346C11,18.194 11.672,18.882 12.5,18.882ZM19.5,18.882C20.328,18.882 21,18.194 21,17.346C21,16.498 20.328,15.81 19.5,15.81C18.672,15.81 18,16.498 18,17.346C18,18.194 18.672,18.882 19.5,18.882ZM12.777,20.503C12.548,20.346 12.237,20.41 12.084,20.645C11.931,20.88 11.993,21.198 12.223,21.355C13.311,22.097 14.655,22.469 16,22.469C17.345,22.469 18.689,22.097 19.777,21.355C20.007,21.198 20.069,20.88 19.916,20.645C19.763,20.41 19.452,20.346 19.223,20.503C18.302,21.131 17.151,21.445 16,21.445C15.317,21.445 14.634,21.334 14,21.114C13.565,20.962 13.152,20.758 12.777,20.503Z"/>
6+
7+
</vector>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="25dp" android:viewportHeight="16" android:viewportWidth="16" android:width="25dp">
2+
3+
<path android:fillColor="#ffffff" android:pathData="M13,7.5l-2,2H9l-1.75,1.75V9.5H5V2h8v5.5z"/>
4+
5+
<path android:fillColor="#9146FF" android:pathData="M4.5,1L2,3.5v9h3V15l2.5,-2.5h2L14,8V1H4.5zM13,7.5l-2,2H9l-1.75,1.75V9.5H5V2h8v5.5z"/>
6+
7+
<path android:fillColor="#9146FF" android:pathData="M11.5,3.75h-1v3h1v-3zM8.75,3.75h-1v3h1v-3z"/>
8+
9+
</vector>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="25dp" android:viewportHeight="100" android:viewportWidth="100" android:width="25dp">
2+
3+
<path android:fillColor="#FF0000" android:pathData="M94.76,27.37c-1.08,-4.05 -4.24,-7.23 -8.26,-8.31C79.22,17.09 50,17.09 50,17.09s-29.22,0 -36.5,1.97c-4.02,1.08 -7.19,4.27 -8.26,8.31C3.29,34.7 3.29,50 3.29,50s0,15.3 1.95,22.63c1.07,4.05 4.24,7.23 8.26,8.31C20.78,82.91 50,82.91 50,82.91s29.22,0 36.5,-1.97c4.02,-1.08 7.18,-4.27 8.26,-8.31C96.71,65.3 96.71,50 96.71,50S96.71,34.7 94.76,27.37z"/>
4+
5+
<path android:fillColor="#F1F1F1" android:pathData="M40.28,35.88l0,28.25l24.83,-14.12z"/>
6+
7+
</vector>

0 commit comments

Comments
 (0)