Nareshkumar Rao
4 years ago
15 changed files with 295 additions and 107 deletions
@ -0,0 +1,6 @@ |
|||
<component name="InspectionProjectProfileManager"> |
|||
<profile version="1.0"> |
|||
<option name="myName" value="Project Default" /> |
|||
<inspection_tool class="MarkdownUnresolvedFileReference" enabled="true" level="WARNING" enabled_by_default="true" /> |
|||
</profile> |
|||
</component> |
@ -0,0 +1,91 @@ |
|||
package com.nareshkumarrao.eiweblog |
|||
|
|||
import android.content.ContentValues |
|||
import android.content.Context |
|||
import android.util.Log |
|||
import android.util.Xml |
|||
import com.android.volley.Request |
|||
import com.android.volley.Response |
|||
import com.android.volley.toolbox.StringRequest |
|||
import com.android.volley.toolbox.Volley |
|||
import com.nareshkumarrao.eiweblog.ui.main.Article |
|||
import org.xmlpull.v1.XmlPullParser |
|||
import java.io.StringReader |
|||
|
|||
internal object Utilities { |
|||
fun weblogXML(context: Context, function: (d: List<Article>) -> Unit) { |
|||
|
|||
val queue = Volley.newRequestQueue(context) |
|||
|
|||
val url = "https://www.google.com" |
|||
|
|||
val stringRequest = StringRequest(Request.Method.GET, url, |
|||
{ response -> |
|||
Log.d("XMLLIST", "got response!") |
|||
// Display the first 500 characters of the response string. |
|||
Log.d("XMLLIST", "$response") |
|||
}, |
|||
{ error -> Log.e("XMLLIST", error.toString()) }) |
|||
|
|||
|
|||
queue.add(stringRequest) |
|||
Log.e("XMLLIST", "Adding request to queue from: $url") |
|||
} |
|||
|
|||
private fun parseXML(parser: XmlPullParser): List<Article> { |
|||
parser.require(XmlPullParser.START_TAG, null, "xml") |
|||
var articles: List<Article> = listOf() |
|||
while (parser.next() != XmlPullParser.END_TAG) { |
|||
if (parser.eventType != XmlPullParser.START_TAG) { |
|||
continue |
|||
} |
|||
if (parser.name == "rs:data") { |
|||
articles = parseRSDATA(parser) |
|||
} else { |
|||
parseSkip(parser) |
|||
} |
|||
} |
|||
return articles |
|||
} |
|||
|
|||
private fun parseRSDATA(parser: XmlPullParser): List<Article> { |
|||
val articles = mutableListOf<Article>() |
|||
parser.require(XmlPullParser.START_TAG, null, "rs:data") |
|||
while (parser.next() != XmlPullParser.END_TAG) { |
|||
if (parser.eventType != XmlPullParser.START_TAG) { |
|||
continue |
|||
} |
|||
if (parser.name == "z:row") { |
|||
articles.add(parseZROW(parser)) |
|||
} else { |
|||
parseSkip(parser) |
|||
} |
|||
} |
|||
return articles |
|||
} |
|||
|
|||
private fun parseZROW(parser: XmlPullParser): Article { |
|||
parser.require(XmlPullParser.START_TAG, null, "z:row") |
|||
val title = parser.getAttributeValue(null, "ows_Title") |
|||
val content = parser.getAttributeValue(null, "ows_Body") |
|||
val date = parser.getAttributeValue(null, "ows_Created") |
|||
val author = parser.getAttributeValue(null, "ows_Autor2") |
|||
parser.nextTag() |
|||
parser.require(XmlPullParser.END_TAG, null, "link") |
|||
|
|||
return Article(title, content, date, author) |
|||
} |
|||
|
|||
private fun parseSkip(parser: XmlPullParser) { |
|||
if (parser.eventType != XmlPullParser.START_TAG) { |
|||
throw IllegalStateException() |
|||
} |
|||
var depth = 1 |
|||
while (depth != 0) { |
|||
when (parser.next()) { |
|||
XmlPullParser.END_TAG -> depth-- |
|||
XmlPullParser.START_TAG -> depth++ |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,41 @@ |
|||
package com.nareshkumarrao.eiweblog.ui.main |
|||
|
|||
import android.view.LayoutInflater |
|||
import android.view.ViewGroup |
|||
import android.widget.TextView |
|||
import androidx.recyclerview.widget.RecyclerView |
|||
import com.nareshkumarrao.eiweblog.R |
|||
|
|||
data class Article(val title: String, val content: String, val date: String, val author: String) |
|||
|
|||
class ItemArticleAdapter(private val articles: List<Article>) : RecyclerView.Adapter<ItemArticleAdapter.ViewHolder>() { |
|||
inner class ViewHolder(inflater: LayoutInflater, parent: ViewGroup) : RecyclerView.ViewHolder(inflater.inflate(R.layout.item_article, parent, false)) { |
|||
private var title: TextView? = null |
|||
private var content: TextView? = null |
|||
|
|||
init { |
|||
title = itemView.findViewById(R.id.titleText) |
|||
content = itemView.findViewById(R.id.contentText) |
|||
} |
|||
|
|||
fun bind(article: Article) { |
|||
title?.text = article.title |
|||
content?.text = article.content |
|||
} |
|||
|
|||
} |
|||
|
|||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemArticleAdapter.ViewHolder { |
|||
var inflater = LayoutInflater.from(parent.context) |
|||
return ViewHolder(inflater, parent) |
|||
} |
|||
|
|||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { |
|||
val article: Article = articles[position] |
|||
holder.bind(article) |
|||
} |
|||
|
|||
override fun getItemCount(): Int { |
|||
return articles.size |
|||
} |
|||
} |
@ -1,19 +0,0 @@ |
|||
package com.nareshkumarrao.eiweblog.ui.main |
|||
|
|||
import androidx.lifecycle.LiveData |
|||
import androidx.lifecycle.MutableLiveData |
|||
import androidx.lifecycle.Transformations |
|||
import androidx.lifecycle.ViewModel |
|||
import androidx.lifecycle.ViewModelProvider |
|||
|
|||
class PageViewModel : ViewModel() { |
|||
|
|||
private val _index = MutableLiveData<Int>() |
|||
val text: LiveData<String> = Transformations.map(_index) { |
|||
"Hello world from section: $it" |
|||
} |
|||
|
|||
fun setIndex(index: Int) { |
|||
_index.value = index |
|||
} |
|||
} |
@ -1,55 +0,0 @@ |
|||
package com.nareshkumarrao.eiweblog.ui.main |
|||
|
|||
import android.os.Bundle |
|||
import android.view.LayoutInflater |
|||
import android.view.View |
|||
import android.view.ViewGroup |
|||
import android.widget.TextView |
|||
import androidx.fragment.app.Fragment |
|||
import androidx.lifecycle.Observer |
|||
import androidx.lifecycle.ViewModelProvider |
|||
import com.nareshkumarrao.eiweblog.R |
|||
|
|||
/** |
|||
* A placeholder fragment containing a simple view. |
|||
*/ |
|||
class PlaceholderFragment : Fragment() { |
|||
|
|||
private lateinit var pageViewModel: PageViewModel |
|||
|
|||
override fun onCreate(savedInstanceState: Bundle?) { |
|||
super.onCreate(savedInstanceState) |
|||
pageViewModel = ViewModelProvider(this).get(PageViewModel::class.java).apply { |
|||
setIndex(arguments?.getInt(ARG_SECTION_NUMBER) ?: 1) |
|||
} |
|||
} |
|||
|
|||
override fun onCreateView( |
|||
inflater: LayoutInflater, container: ViewGroup?, |
|||
savedInstanceState: Bundle? |
|||
): View? { |
|||
val root = inflater.inflate(R.layout.fragment_main, container, false) |
|||
return root |
|||
} |
|||
|
|||
companion object { |
|||
/** |
|||
* The fragment argument representing the section number for this |
|||
* fragment. |
|||
*/ |
|||
private const val ARG_SECTION_NUMBER = "section_number" |
|||
|
|||
/** |
|||
* Returns a new instance of this fragment for the given section |
|||
* number. |
|||
*/ |
|||
@JvmStatic |
|||
fun newInstance(sectionNumber: Int): PlaceholderFragment { |
|||
return PlaceholderFragment().apply { |
|||
arguments = Bundle().apply { |
|||
putInt(ARG_SECTION_NUMBER, sectionNumber) |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,31 @@ |
|||
package com.nareshkumarrao.eiweblog.ui.main |
|||
|
|||
import android.os.Bundle |
|||
import android.view.LayoutInflater |
|||
import android.view.View |
|||
import android.view.ViewGroup |
|||
import androidx.fragment.app.Fragment |
|||
import androidx.recyclerview.widget.LinearLayoutManager |
|||
import androidx.recyclerview.widget.RecyclerView |
|||
import com.nareshkumarrao.eiweblog.R |
|||
|
|||
class SectionsFragment : Fragment() { |
|||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|||
return inflater.inflate(R.layout.fragment_sections, container, false) |
|||
} |
|||
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|||
super.onViewCreated(view, savedInstanceState) |
|||
view.findViewById<RecyclerView>(R.id.sectionsRecylerView).apply { |
|||
layoutManager = LinearLayoutManager(activity) |
|||
adapter = ItemArticleAdapter(listOf()) |
|||
} |
|||
|
|||
} |
|||
fun updateView(get_articles: List<Article>){ |
|||
view?.findViewById<RecyclerView>(R.id.sectionsRecylerView)?.apply { |
|||
layoutManager = LinearLayoutManager(activity) |
|||
adapter = ItemArticleAdapter(get_articles) |
|||
} |
|||
} |
|||
} |
@ -1,21 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|||
xmlns:app="http://schemas.android.com/apk/res-auto" |
|||
xmlns:tools="http://schemas.android.com/tools" |
|||
android:id="@+id/constraintLayout" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent" |
|||
tools:context=".ui.main.PlaceholderFragment"> |
|||
|
|||
<LinearLayout |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent" |
|||
android:orientation="vertical" |
|||
tools:layout_editor_absoluteX="173dp" |
|||
tools:layout_editor_absoluteY="241dp"> |
|||
|
|||
<ListView |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent" /> |
|||
</LinearLayout> |
|||
</androidx.constraintlayout.widget.ConstraintLayout> |
@ -0,0 +1,10 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<androidx.constraintlayout.widget.ConstraintLayout |
|||
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" |
|||
android:layout_height="match_parent"> |
|||
|
|||
<androidx.recyclerview.widget.RecyclerView |
|||
android:id="@+id/sectionsRecylerView" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent" /> |
|||
</androidx.constraintlayout.widget.ConstraintLayout> |
@ -0,0 +1,58 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|||
xmlns:app="http://schemas.android.com/apk/res-auto" |
|||
xmlns:tools="http://schemas.android.com/tools" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content"> |
|||
|
|||
<TextView |
|||
android:id="@+id/dateText" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginStart="16dp" |
|||
android:layout_marginLeft="16dp" |
|||
android:layout_marginTop="8dp" |
|||
android:text="01.01.2001" |
|||
android:textColor="@color/black" |
|||
android:textStyle="bold" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toTopOf="parent" /> |
|||
|
|||
<TextView |
|||
android:id="@+id/authorText" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginEnd="16dp" |
|||
android:layout_marginRight="16dp" |
|||
android:text="Prof. Max Mustermann" |
|||
android:textColor="@color/black" |
|||
app:layout_constraintBottom_toBottomOf="@+id/dateText" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintTop_toTopOf="@+id/dateText" /> |
|||
|
|||
<TextView |
|||
android:id="@+id/titleText" |
|||
android:layout_width="0dp" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginTop="8dp" |
|||
android:text="Klausurergebnis Android Programmierung - New Android Version" |
|||
android:textColor="@color/black" |
|||
android:textSize="18sp" |
|||
android:textStyle="bold" |
|||
app:layout_constraintEnd_toEndOf="@+id/authorText" |
|||
app:layout_constraintStart_toStartOf="@+id/dateText" |
|||
app:layout_constraintTop_toBottomOf="@+id/dateText" /> |
|||
|
|||
<TextView |
|||
android:id="@+id/contentText" |
|||
android:layout_width="0dp" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginTop="8dp" |
|||
android:layout_marginBottom="8dp" |
|||
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer risus nibh, viverra non dapibus vel, ullamcorper et nulla. Ut semper ullamcorper tellus eget pulvinar. Quisque nisl dolor, porttitor quis leo at, vehicula aliquet tellus. Nulla vulputate libero at tincidunt blandit. Ut et mi diam. Duis eu nibh dapibus, feugiat nibh nec, tempus ligula. Suspendisse mattis porta accumsan. " |
|||
app:layout_constraintBottom_toBottomOf="parent" |
|||
app:layout_constraintEnd_toEndOf="@+id/titleText" |
|||
app:layout_constraintHorizontal_bias="0.498" |
|||
app:layout_constraintStart_toStartOf="@+id/titleText" |
|||
app:layout_constraintTop_toBottomOf="@+id/titleText" /> |
|||
</androidx.constraintlayout.widget.ConstraintLayout> |
@ -1,6 +1,6 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<menu xmlns:app="http://schemas.android.com/apk/res-auto" |
|||
xmlns:android="http://schemas.android.com/apk/res/android"> |
|||
<item android:title="Benachrichtigungen" app:showAsAction="never"/> |
|||
<item android:title="Information" app:showAsAction="never"/> |
|||
<item android:title="@string/notifications" app:showAsAction="never"/> |
|||
<item android:title="@string/about" app:showAsAction="never"/> |
|||
</menu> |
@ -1,9 +1,12 @@ |
|||
<resources> |
|||
<string name="app_name">EI Weblog</string> |
|||
<string name="tab_text_1">Tab 1</string> |
|||
<string name="tab_text_2">Tab 2</string> |
|||
<string name="tab_lehre">Lehre</string> |
|||
<string name="tab_pruefungen">Prüfungen</string> |
|||
<string name="tab_sonstiges">Sonstiges</string> |
|||
<string name="hsd_symbol">HSD</string> |
|||
<string name="weblog_xml_url"><![CDATA[ |
|||
https://ei.hs-duesseldorf.de/weblog/_vti_bin/owssvr.dll?Cmd=Display&List=%7B169417ED-6982-4CDA-9CAC-F63FCB1757EF%7D&XMLDATA=TRUE&RowLimit=0&Queue=* |
|||
]]></string> |
|||
<string name="notifications">Benachrichtigungen</string> |
|||
<string name="about">Information</string> |
|||
</resources> |
Loading…
Reference in new issue