-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added setting to change favicon provider
- Loading branch information
1 parent
7a99028
commit 6ebd0fe
Showing
10 changed files
with
90 additions
and
29 deletions.
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
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
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/simon/harmonichackernews/network/FaviconLoader.java
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,42 @@ | ||
package com.simon.harmonichackernews.network; | ||
|
||
import android.content.Context; | ||
import android.widget.ImageView; | ||
|
||
import androidx.core.content.ContextCompat; | ||
|
||
import com.simon.harmonichackernews.R; | ||
import com.simon.harmonichackernews.utils.SettingsUtils; | ||
import com.simon.harmonichackernews.utils.Utils; | ||
import com.squareup.picasso.Picasso; | ||
|
||
import java.util.Objects; | ||
|
||
public class FaviconLoader { | ||
|
||
public static void loadFavicon(String url, ImageView into, Context ctx, String faviconProvider) { | ||
try { | ||
String host = Utils.getDomainName(url); | ||
|
||
Picasso.get() | ||
.load(getFaviconUrl(host, faviconProvider)) | ||
.resize(80, 80) | ||
.onlyScaleDown() | ||
.placeholder(Objects.requireNonNull(ContextCompat.getDrawable(ctx, R.drawable.ic_action_web))) | ||
.into(into); | ||
} catch (Exception ignored){}; | ||
} | ||
|
||
private static String getFaviconUrl(String host, String faviconProvider) { | ||
switch (faviconProvider) { | ||
case "Faviconkit": | ||
return "https://api.faviconkit.com/" + host; | ||
case "Google": | ||
return "https://www.google.com/s2/favicons?domain="+ host + "&sz=80"; | ||
case "DuckDuckGo": | ||
return "https://icons.duckduckgo.com/ip3/" + host + ".ico"; | ||
} | ||
return null; | ||
} | ||
|
||
} |
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