Make Downloader class a Singleton
This commit is contained in:
parent
58bc0c17d0
commit
b4f595eb75
|
@ -62,7 +62,7 @@ public class App extends Application {
|
|||
}
|
||||
|
||||
//init NewPipe
|
||||
NewPipe.init(new Downloader());
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
|
||||
// Initialize image loader
|
||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).build();
|
||||
|
|
|
@ -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 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),
|
||||
* 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
|
||||
|
|
|
@ -473,7 +473,7 @@ public class ErrorActivity extends AppCompatActivity {
|
|||
public void run() {
|
||||
String ipRange = "none";
|
||||
try {
|
||||
Downloader dl = new Downloader();
|
||||
Downloader dl = Downloader.getInstance();
|
||||
String ip = dl.download("https://ifcfg.me/ip");
|
||||
|
||||
ipRange = Parser.matchGroup1("([0-9]*\\.[0-9]*\\.)[0-9]*\\.[0-9]*", ip)
|
||||
|
|
Loading…
Reference in New Issue