-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
10 changed files
with
218 additions
and
3 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
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
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/example/pp/podcastplayer/DataRSSmp3.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,18 @@ | ||
package com.example.pp.podcastplayer; | ||
|
||
/** | ||
* Created by Logar on 28.12.2017. | ||
*/ | ||
|
||
public class DataRSSmp3 { | ||
|
||
public String naslov; | ||
public String mp3; | ||
public String opis; | ||
|
||
public DataRSSmp3(String naslov, String mp3, String opis) { | ||
this.naslov = naslov; | ||
this.mp3 = mp3; | ||
this.opis = opis; | ||
} | ||
} |
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
122 changes: 122 additions & 0 deletions
122
app/src/main/java/com/example/pp/podcastplayer/ParserMP3.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,122 @@ | ||
package com.example.pp.podcastplayer; | ||
|
||
import android.util.Xml; | ||
|
||
import org.xmlpull.v1.XmlPullParser; | ||
import org.xmlpull.v1.XmlPullParserException; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by Logar on 28.12.2017. | ||
*/ | ||
|
||
public class ParserMP3 { | ||
|
||
DataRSSmp3 data; | ||
String urlRSS; | ||
|
||
|
||
// Razclenjevanje podatkov | ||
public DataRSSmp3 parseData(InputStream inputStream) throws XmlPullParserException, | ||
IOException { | ||
|
||
String naslov = null; | ||
String mp3 = null; | ||
String opis = null; | ||
|
||
boolean itemObj = false; | ||
DataRSSmp3 item = new DataRSSmp3(naslov,mp3,opis); | ||
|
||
|
||
List<DataRSS> items = new ArrayList<>(); | ||
|
||
try { | ||
// Uporabimo xmlPullParser | ||
XmlPullParser xmlPullParser = Xml.newPullParser(); | ||
xmlPullParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); | ||
xmlPullParser.setInput(inputStream, null); | ||
|
||
// Pregledujemo znacke do konca dokumenta | ||
xmlPullParser.nextTag(); | ||
while (xmlPullParser.next() != XmlPullParser.END_DOCUMENT) { | ||
// prebermo tip dogodka (zacetek dokumenta, konec) | ||
int event = xmlPullParser.getEventType(); | ||
|
||
// Preberemo ime znacke (item) | ||
String tagName = xmlPullParser.getName(); | ||
|
||
if( tagName == null ) { | ||
continue; | ||
} | ||
|
||
// Zacetek dokumenta | ||
if (event == XmlPullParser.START_TAG) { | ||
if(tagName.equalsIgnoreCase("item")) { | ||
itemObj = true; | ||
continue; | ||
} | ||
} | ||
|
||
// Konec dokumenta | ||
if(event == XmlPullParser.END_TAG) { | ||
if(tagName.equalsIgnoreCase("item")) { | ||
itemObj = false; | ||
} | ||
continue; | ||
} | ||
|
||
|
||
// Log.d("MyXmlParser", "Parsing name ==> " + name); | ||
String res = ""; | ||
|
||
|
||
if (xmlPullParser.next() == XmlPullParser.TEXT) { | ||
res = xmlPullParser.getText(); | ||
xmlPullParser.nextTag(); | ||
} | ||
|
||
// Pridobivanje podatkov iz znack | ||
|
||
switch (tagName){ | ||
case "title": | ||
//Log.d("Add", res); | ||
naslov = res; | ||
|
||
break; | ||
case "enclosure": | ||
mp3 = xmlPullParser.getAttributeValue(null, "url"); | ||
// Log.d("Add", slika); | ||
break; | ||
|
||
case "description": | ||
opis = res; | ||
break; | ||
} | ||
|
||
|
||
if (naslov != null && opis != null && mp3 != null) { | ||
if(itemObj) { | ||
// Log.d("Add", naslov + opis); | ||
// Dodamo oddajo samo v primeru da so vse ustrezne znacke pridobljene | ||
item = new DataRSSmp3(naslov, mp3, opis); | ||
} | ||
|
||
naslov = null; | ||
mp3 = null; | ||
opis = null; | ||
|
||
itemObj = false; | ||
} | ||
} | ||
|
||
return item; | ||
} finally { | ||
inputStream.close(); | ||
} | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/example/pp/podcastplayer/PodcastList.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,29 @@ | ||
package com.example.pp.podcastplayer; | ||
|
||
import android.os.Bundle; | ||
import android.support.design.widget.FloatingActionButton; | ||
import android.support.design.widget.Snackbar; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.View; | ||
|
||
public class PodcastList extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_podcast_list); | ||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
|
||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); | ||
fab.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) | ||
.setAction("Action", null).show(); | ||
} | ||
}); | ||
} | ||
|
||
} |
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,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.design.widget.CoordinatorLayout 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="match_parent" | ||
tools:context="com.example.pp.podcastplayer.PodcastList"> | ||
|
||
<android.support.design.widget.AppBarLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:theme="@style/AppTheme.AppBarOverlay"> | ||
|
||
<android.support.v7.widget.Toolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
android:background="?attr/colorPrimary" | ||
app:popupTheme="@style/AppTheme.PopupOverlay" /> | ||
|
||
</android.support.design.widget.AppBarLayout> | ||
|
||
<include layout="@layout/content_podcast_list" /> | ||
|
||
|
||
</android.support.design.widget.CoordinatorLayout> |
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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.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="match_parent" | ||
app:layout_behavior="@string/appbar_scrolling_view_behavior" | ||
tools:context="com.example.pp.podcastplayer.PodcastList" | ||
tools:showIn="@layout/activity_podcast_list"> | ||
|
||
</android.support.constraint.ConstraintLayout> |
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