Commit fad3db8f authored by Sven Eric Panitz's avatar Sven Eric Panitz
Browse files

more layouting, especially explanation

parent c529f959
......@@ -20,9 +20,9 @@ class AnswerSelectionListAdapter(private val answers: List<Answer>,val overview:
override fun isCorrect():Pair<Boolean,String>{
var correctAnswers=0
var vs = inputs.values
val buf = StringBuffer("<h4>Ihre Lösung:</h4>")
for (v in vs) buf.append(v+"\n")
val buf = StringBuffer("<h4>Ihre Lösung:</h4><ul>")
for (v in vs) buf.append("<li>"+v+"</li>\n")
buf.append("</ul>\n")
for (answer in answers)if (answer.isCorrect)correctAnswers++
return Pair(correctAnswers==correctChecked,buf.toString())
......
......@@ -21,9 +21,11 @@ class AnswerValueListAdapter(private val answers: List<Answer>,val overview:Prac
override fun isCorrect():Pair<Boolean,String>{
var vs = inputs.values
var rs:MutableSet<String> = mutableSetOf()
val buf = StringBuffer("<h4>Ihre Lösung:</h4>")
for (v in vs) buf.append(v+"\n")
val buf = StringBuffer("<h4>Ihre Lösung:</h4><ul>")
for (v in vs) buf.append("<li>"+v+"</li>\n")
buf.append("</ul>\n")
for (ans in answers) rs.add(ans.antwort?.trim()?.toLowerCase()?:"")
//why does equals of sets nit work????
......
......@@ -22,7 +22,7 @@ class ViewFiller(val view:ViewGroup) : DefaultHandler (){
override fun startElement( uri:String, localName: String, qName :String,attributes:Attributes){
when (qName.toLowerCase()) {
"div" -> {
if (buf.length!=0){
if (!inPre and (buf.length!=0)){
val tv = TextView(view.context)
tv.setLayoutParams(
LinearLayout.LayoutParams(
......@@ -47,7 +47,7 @@ class ViewFiller(val view:ViewGroup) : DefaultHandler (){
)
)
tv.setText(HtmlCompat.fromHtml("<div>"+buf.toString().trim()+"</div>", HtmlCompat.FROM_HTML_MODE_COMPACT))
tv.setText(HtmlCompat.fromHtml("<div>"+buf.toString()+"</div>", HtmlCompat.FROM_HTML_MODE_COMPACT))
view.addView(tv)
buf = StringBuffer()
}
......@@ -66,7 +66,7 @@ class ViewFiller(val view:ViewGroup) : DefaultHandler (){
override fun endElement( uri:String, localName: String, qName :String){
when (qName.toLowerCase()) {
"div" -> {
if (buf.length!=0){
if (!inPre and (buf.length!=0)){
val tv = TextView(view.context)
tv.setLayoutParams(
LinearLayout.LayoutParams(
......@@ -74,7 +74,7 @@ class ViewFiller(val view:ViewGroup) : DefaultHandler (){
LinearLayout.LayoutParams.MATCH_PARENT
)
)
tv.setText(HtmlCompat.fromHtml("<div>"+buf.toString().trim()+"</div>", HtmlCompat.FROM_HTML_MODE_COMPACT))
tv.setText(HtmlCompat.fromHtml("<div>"+buf.toString()+"</div>", HtmlCompat.FROM_HTML_MODE_COMPACT))
view.addView(tv)
buf = StringBuffer()
}
......@@ -115,22 +115,30 @@ class ViewFiller(val view:ViewGroup) : DefaultHandler (){
}
override fun characters(ch:CharArray , start:Int, length:Int){
//buf.append("<![CDATA[")
buf.append(String(ch,start,length))
//buf.append("]]>");
}
}
fun fillView(view :ViewGroup,xml:String ){
val viewfiller=ViewFiller(view)
val x="<div>"+xml+"</div>"
Log.v("TTTTT",x)
SAXParserFactory
.newInstance()
.newSAXParser()
.parse(InputSource(StringReader(x)) ,viewfiller)
fun fillView(view :ViewGroup,xml:String ){
try {
val viewfiller=ViewFiller(view)
val x="<div>"+xml+"</div>"
Log.v("TTTTT",x)
SAXParserFactory
.newInstance()
.newSAXParser()
.parse(InputSource(StringReader(x)) ,viewfiller)
}catch(e:Exception){
val tv = TextView(view.context)
tv.setLayoutParams(
LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
)
)
tv.setText(HtmlCompat.fromHtml("<div>"+e.toString()+"</div>", HtmlCompat.FROM_HTML_MODE_COMPACT))
view.addView(tv)
}
}
}
......@@ -47,19 +47,19 @@ class ResultFragment : Fragment() {
HtmlFiller.fillView(solutionView, "<div><div><div><h4>Beispiellösung:</h4></div><pre><![CDATA[" + exercise!!.solution+"]]></pre></div></div>")
// solutionTextView.text =
}else{
val buf = StringBuffer("<div><h4>Korrekte Antwort:</h4>")
val buf = StringBuffer("<div><h4>Korrekte Antwort:</h4><ul>")
for (ans in (exercise as MultipleChoice).answers){
if(ans.isCorrect||exercise!!.typ==CardType.ValueList){
buf.append((ans?.antwort?:"")+"\n")
buf.append("<li>"+(ans?.antwort?:"")+"</li>\n")
}
}
buf.append("</div>")
buf.append("</ul></div>")
HtmlFiller.fillView(solutionView, buf.toString())
//solutionTextView.text = buf.toString()
}
explainationTextView.text = exercise!!.explanation
HtmlFiller.fillView(explainationTextView, "<div><h4>Erläuterung</h4>" +exercise!!.explanation +"</div>")
HtmlFiller.fillView(userAnswerView,"<div>\n\n" + userAnswer!! +"</div>")
}
......
......@@ -22,11 +22,12 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
<LinearLayout
android:id="@+id/explainationTextView"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:orientation="vertical"
android:layout_marginBottom="16dp"
android:scrollHorizontally="false"
app:layout_constraintBottom_toBottomOf="parent"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment