diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..c83a369 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index b483a8c..6374795 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,4 +44,7 @@ dependencies { testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + implementation 'com.android.volley:volley:1.2.0' + implementation "com.squareup.okhttp3:okhttp:4.9.0" + } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index eda71cb..48d335b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + + + \ No newline at end of file diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt index c64abc8..99f6fb0 100644 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt +++ b/app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt @@ -1,13 +1,17 @@ package com.nareshkumarrao.eiweblog import android.os.Bundle +import android.util.Log import android.view.Menu import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar import androidx.viewpager.widget.ViewPager +import com.android.volley.VolleyLog import com.google.android.material.tabs.TabLayout +import com.nareshkumarrao.eiweblog.ui.main.Article import com.nareshkumarrao.eiweblog.ui.main.SectionsPagerAdapter +import okhttp3.OkHttpClient class MainActivity : AppCompatActivity() { @@ -15,6 +19,7 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) + val sectionsPagerAdapter = SectionsPagerAdapter(this, supportFragmentManager) val viewPager: ViewPager = findViewById(R.id.view_pager) viewPager.adapter = sectionsPagerAdapter @@ -23,9 +28,47 @@ class MainActivity : AppCompatActivity() { val myToolbar = findViewById(R.id.toolbar) as Toolbar setSupportActionBar(myToolbar) + + VolleyLog.DEBUG = true + + /*val queue = Volley.newRequestQueue(this) + val url = "https://www.reddit.com" + val stringRequest = StringRequest( + Request.Method.GET, url, + { response -> + Log.d("XMLLIST", "got response!") + Log.d("XMLLIST", "$response") + }, + { error -> Log.e("XMLLIST", error.toString()) }) + stringRequest.retryPolicy = DefaultRetryPolicy( + DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2, + DefaultRetryPolicy.DEFAULT_MAX_RETRIES, + DefaultRetryPolicy.DEFAULT_BACKOFF_MULT + ) + queue.add(stringRequest)*/ + + val thread = Thread { + try { + Log.d("XMLLIST", "Starting network request thread.") + val client = OkHttpClient() + val request = okhttp3.Request.Builder().url("https://google.com/").build() + val response = client.newCall(request).execute() + Log.d("XMLLIST", response.toString()) + } catch (e: Exception) { + e.printStackTrace() + } + } + + thread.start() + + } + + fun logArticles(articles: List
){ + Log.i("XMLLIST", articles.toString()) } override fun onCreateOptionsMenu(menu: Menu?): Boolean { + //Utilities.weblogXML(baseContext, ::logArticles) menuInflater.inflate(R.menu.toolbar_menu, menu); return true; } diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/Utilities.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/Utilities.kt new file mode 100644 index 0000000..199cc08 --- /dev/null +++ b/app/src/main/java/com/nareshkumarrao/eiweblog/Utilities.kt @@ -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
) -> 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
{ + parser.require(XmlPullParser.START_TAG, null, "xml") + var articles: List
= 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
{ + val articles = mutableListOf
() + 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++ + } + } + } +} diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/ItemArticleAdapter.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/ItemArticleAdapter.kt new file mode 100644 index 0000000..ed6d1fa --- /dev/null +++ b/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/ItemArticleAdapter.kt @@ -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
) : RecyclerView.Adapter() { + 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 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/PageViewModel.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/PageViewModel.kt deleted file mode 100644 index de63d07..0000000 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/PageViewModel.kt +++ /dev/null @@ -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() - val text: LiveData = Transformations.map(_index) { - "Hello world from section: $it" - } - - fun setIndex(index: Int) { - _index.value = index - } -} \ No newline at end of file diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/PlaceholderFragment.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/PlaceholderFragment.kt deleted file mode 100644 index adfcca0..0000000 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/PlaceholderFragment.kt +++ /dev/null @@ -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) - } - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsFragment.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsFragment.kt new file mode 100644 index 0000000..59c49c0 --- /dev/null +++ b/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsFragment.kt @@ -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(R.id.sectionsRecylerView).apply { + layoutManager = LinearLayoutManager(activity) + adapter = ItemArticleAdapter(listOf()) + } + + } + fun updateView(get_articles: List
){ + view?.findViewById(R.id.sectionsRecylerView)?.apply { + layoutManager = LinearLayoutManager(activity) + adapter = ItemArticleAdapter(get_articles) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsPagerAdapter.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsPagerAdapter.kt index 6d1f006..74bcc15 100644 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsPagerAdapter.kt +++ b/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsPagerAdapter.kt @@ -12,17 +12,11 @@ private val TAB_TITLES = arrayOf( R.string.tab_sonstiges ) -/** - * A [FragmentPagerAdapter] that returns a fragment corresponding to - * one of the sections/tabs/pages. - */ class SectionsPagerAdapter(private val context: Context, fm: FragmentManager) : FragmentPagerAdapter(fm) { override fun getItem(position: Int): Fragment { - // getItem is called to instantiate the fragment for the given page. - // Return a PlaceholderFragment (defined as a static inner class below). - return PlaceholderFragment.newInstance(position + 1) + return SectionsFragment() } override fun getPageTitle(position: Int): CharSequence? { @@ -30,6 +24,6 @@ class SectionsPagerAdapter(private val context: Context, fm: FragmentManager) } override fun getCount(): Int { - return 3 + return TAB_TITLES.size } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml deleted file mode 100644 index ae30217..0000000 --- a/app/src/main/res/layout/fragment_main.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_sections.xml b/app/src/main/res/layout/fragment_sections.xml new file mode 100644 index 0000000..c11783f --- /dev/null +++ b/app/src/main/res/layout/fragment_sections.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_article.xml b/app/src/main/res/layout/item_article.xml new file mode 100644 index 0000000..ad28ccd --- /dev/null +++ b/app/src/main/res/layout/item_article.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/toolbar_menu.xml b/app/src/main/res/menu/toolbar_menu.xml index e72259a..7b29204 100644 --- a/app/src/main/res/menu/toolbar_menu.xml +++ b/app/src/main/res/menu/toolbar_menu.xml @@ -1,6 +1,6 @@ - - + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f2c4815..256f5e1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,9 +1,12 @@ EI Weblog - Tab 1 - Tab 2 Lehre Prüfungen Sonstiges HSD + + Benachrichtigungen + Information \ No newline at end of file