1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-09-29 07:20:50 +00:00

Make Downloader class a Singleton

This commit is contained in:
Benoît Mauduit 2016-12-07 22:09:24 +01:00
parent 58bc0c17d0
commit b4f595eb75
3 changed files with 17 additions and 2 deletions

View File

@ -62,7 +62,7 @@ public class App extends Application {
} }
//init NewPipe //init NewPipe
NewPipe.init(new Downloader()); NewPipe.init(Downloader.getInstance());
// Initialize image loader // Initialize image loader
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).build();

View File

@ -36,6 +36,21 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader {
private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"; private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0";
private static Downloader instance = null;
private Downloader() {}
public static Downloader getInstance() {
if(instance == null) {
synchronized (Downloader.class) {
if (instance == null) {
instance = new Downloader();
}
}
}
return instance;
}
/**Download the text file at the supplied URL as in download(String), /**Download the text file at the supplied URL as in download(String),
* but set the HTTP header field "Accept-Language" to the supplied string. * but set the HTTP header field "Accept-Language" to the supplied string.
* @param siteUrl the URL of the text file to return the contents of * @param siteUrl the URL of the text file to return the contents of

View File

@ -473,7 +473,7 @@ public class ErrorActivity extends AppCompatActivity {
public void run() { public void run() {
String ipRange = "none"; String ipRange = "none";
try { try {
Downloader dl = new Downloader(); Downloader dl = Downloader.getInstance();
String ip = dl.download("https://ifcfg.me/ip"); String ip = dl.download("https://ifcfg.me/ip");
ipRange = Parser.matchGroup1("([0-9]*\\.[0-9]*\\.)[0-9]*\\.[0-9]*", ip) ipRange = Parser.matchGroup1("([0-9]*\\.[0-9]*\\.)[0-9]*\\.[0-9]*", ip)