-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a1f961
commit a16777c
Showing
8 changed files
with
159 additions
and
24 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
88 changes: 88 additions & 0 deletions
88
src-capacitor/android/app/src/main/java/com/benoiteirik/theochrone/BridgePlugin.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,88 @@ | ||
package com.benoiteirik.theochrone; | ||
|
||
import android.os.AsyncTask; | ||
import android.util.Log; | ||
|
||
import com.getcapacitor.JSObject; | ||
import com.getcapacitor.Plugin; | ||
import com.getcapacitor.PluginCall; | ||
import com.getcapacitor.PluginMethod; | ||
import com.getcapacitor.annotation.CapacitorPlugin; | ||
|
||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.nodes.Element; | ||
import org.jsoup.select.Elements; | ||
|
||
import java.io.IOException; | ||
|
||
@CapacitorPlugin(name = "Bridge") | ||
public class BridgePlugin extends Plugin { | ||
private JSObject dataHTML; | ||
|
||
// Bridge data between back and front | ||
private PluginCall festTextesCall; | ||
|
||
|
||
@PluginMethod() | ||
public void echo(PluginCall call) { | ||
String value = call.getString("value"); | ||
Log.d("MSG:", " " + value); | ||
JSObject ret = new JSObject(); | ||
ret.put("value", value); | ||
call.resolve(ret); | ||
} | ||
|
||
@PluginMethod() | ||
public void getFestTextes(PluginCall call) { | ||
String festURL = call.getString("url"); | ||
festTextesCall = call; | ||
AsyncTask<String, Void, Void> fetch = new fetchFestTextes().execute(festURL); | ||
} | ||
|
||
private class fetchFestTextes extends AsyncTask<String, Void, Void> { | ||
|
||
@Override | ||
protected Void doInBackground(String... params) { | ||
try { | ||
dataHTML = new JSObject(); | ||
Document doc = Jsoup.connect(params[0]) | ||
.timeout(0) | ||
.header("Content-Type", "text/html; charset=ISO-8859-1") | ||
.get(); | ||
|
||
Elements imgs = doc.select("img[src]"); | ||
for (Element img : imgs) { | ||
String src = img.attr("src"); | ||
if (!src.startsWith("http")) { | ||
src = "https://introibo.fr/" + src; | ||
} | ||
img.attr("src", src); | ||
img.attr("style", "width:100%; object-fit: contain;"); | ||
} | ||
|
||
Elements links = doc.select("a[href]"); | ||
for (Element link : links) { | ||
link.removeAttr("href"); | ||
} | ||
|
||
Elements cells = doc.select("td"); | ||
for (Element cell : cells) { | ||
cell.attr("valign", "top"); | ||
} | ||
|
||
String textes = doc.select("#principal .texte").html(); | ||
|
||
dataHTML.put("data", textes); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected void onPostExecute(Void result) { | ||
festTextesCall.resolve(dataHTML); | ||
} | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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