use of oscar.riksdagskollen.Utilities.JSONModels.Representative in project Riksdagskollen by OAndell.
the class RiksdagenAPIManager method getRepresentative.
/**
* Get representative(ledamot) information by intressent_id.
* @param iid intressent_id for the representative
* @param callback callback function which the a Representative JSON model is returned.
*/
public void getRepresentative(String iid, final RepresentativeCallback callback) {
String subURL = "/personlista/?iid=" + iid + "&utformat=json";
requestManager.doGetRequest(subURL, new JSONRequestCallback() {
@Override
public void onRequestSuccess(JSONObject response) {
try {
JSONObject jsonDocuments = response.getJSONObject("personlista").getJSONObject("person");
Representative representative = gson.fromJson(jsonDocuments.toString(), Representative.class);
callback.onPersonFetched(representative);
} catch (JSONException e) {
e.printStackTrace();
callback.onFail(new VolleyError("Failed to parse JSON"));
}
}
@Override
public void onRequestFail(VolleyError error) {
callback.onFail(error);
}
});
}
use of oscar.riksdagskollen.Utilities.JSONModels.Representative in project Riksdagskollen by OAndell.
the class DocumentReaderActivity method populateViewWithDocumentInformation.
/**
* Fills contentview with content as soon as it has been fethced from the server
*/
private void populateViewWithDocumentInformation() {
TextView titleTV = findViewById(R.id.act_doc_reader_title);
TextView authorTV = findViewById(R.id.act_doc_reader_author);
final TextView recipientTV = findViewById(R.id.act_doc_reader_recipient);
TextView body = findViewById(R.id.act_doc_reader_body);
portaitContainer = findViewById(R.id.act_doc_reader_portrait_container);
for (Intressent i : document.getDokintressent().getIntressenter()) {
final View portraitView;
TextView nameTv;
if (i.getRoll().equals("undertecknare")) {
portraitView = LayoutInflater.from(this).inflate(R.layout.intressent_layout, null);
final NetworkImageView portrait = portraitView.findViewById(R.id.intressent_portait);
portrait.setDefaultImageResId(R.mipmap.ic_default_person);
nameTv = portraitView.findViewById(R.id.intressent_name);
nameTv.setText(i.getNamn() + " (" + i.getPartibet() + ")");
app.getRiksdagenAPIManager().getRepresentative(i.getIntressent_id(), new RepresentativeCallback() {
@Override
public void onPersonFetched(Representative representative) {
portrait.setImageUrl(representative.getBild_url_192(), app.getRequestManager().getmImageLoader());
}
@Override
public void onFail(VolleyError error) {
}
});
portaitContainer.addView(portraitView);
}
}
titleTV.setText(document.getTitel());
authorTV.setText(String.format("av %s", document.getUndertitel()));
// TODO: ta ut den riktiga mottagaren ur texten och sätt den här
recipientTV.setText("Till en person");
body.setText(docBody);
}
use of oscar.riksdagskollen.Utilities.JSONModels.Representative in project Riksdagskollen by OAndell.
the class MotionActivity method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_motion);
document = getIntent().getParcelableExtra("document");
TextView titleTV = findViewById(R.id.act_doc_reader_title);
TextView authorTV = findViewById(R.id.act_doc_reader_author);
loadingView = findViewById(R.id.loading_view);
context = this;
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("Motion");
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
titleTV.setText(document.getTitel());
authorTV.setText(document.getUndertitel());
WebViewClient webViewClient = new CustomWebViewClient();
final WebView webView = findViewById(R.id.webview);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, final int newProgress) {
if (newProgress == 100) {
loadingView.setVisibility(View.GONE);
}
}
});
webView.setWebViewClient(webViewClient);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setInitialScale(1);
// Disable text-select to make consistent with rest of app
webView.setLongClickable(false);
webView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
final RikdagskollenApp app = RikdagskollenApp.getInstance();
app.getRiksdagenAPIManager().getDocumentBody(document, new StringRequestCallback() {
@Override
public void onResponse(String response) {
Document doc = Jsoup.parse(response);
// Remove title
doc.head().append("<meta name=\"viewport\" content='width=device-width, initial-scale=2.0,text/html, charset='utf-8'>\n");
doc.head().appendElement("link").attr("rel", "stylesheet").attr("type", "text/css").attr("href", "motion_style.css");
doc.select("div>span.sidhuvud_publikation").remove();
doc.select("div>span.sidhuvud_beteckning").remove();
doc.select("div>span.MotionarLista").remove();
doc.select("div.pconf>h1").remove();
doc.select("div>hr.sidhuvud_linje").remove();
doc.select("head>style").remove();
doc.select("body>div>br").remove();
// Clear default styling
String result = doc.toString().replaceAll("class=\\\"[A-Öa-ö0-9]+\\\"", "");
result = result.replaceAll("style=\"[A-Öa-ö-_:;\\s0-9.%']+\"", "");
webView.loadDataWithBaseURL("file:///android_asset/", result, "text/html", "UTF-8", null);
System.out.println(result);
}
@Override
public void onFail(VolleyError error) {
}
});
LinearLayout portaitContainer = findViewById(R.id.act_doc_reader_portrait_container);
for (Intressent i : document.getDokintressent().getIntressenter()) {
final View portraitView;
TextView nameTv;
if (i.getRoll().equals("undertecknare")) {
portraitView = LayoutInflater.from(this).inflate(R.layout.intressent_layout, null);
final NetworkImageView portrait = portraitView.findViewById(R.id.intressent_portait);
portrait.setDefaultImageResId(R.mipmap.ic_default_person);
nameTv = portraitView.findViewById(R.id.intressent_name);
nameTv.setText(i.getNamn() + " (" + i.getPartibet() + ")");
app.getRiksdagenAPIManager().getRepresentative(i.getIntressent_id(), new RepresentativeCallback() {
@Override
public void onPersonFetched(Representative representative) {
portrait.setImageUrl(representative.getBild_url_192(), app.getRequestManager().getmImageLoader());
}
@Override
public void onFail(VolleyError error) {
}
});
portaitContainer.addView(portraitView);
}
}
}
Aggregations