Skip to content
Permalink
Browse files

CSE-4095-radioRecyclerView

  • Loading branch information
kop16101 committed Apr 28, 2020
1 parent 788e5ef commit 4605cc9eeb4da6ec0996b318ba26498939e1c023
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
@@ -2,6 +2,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.thankstoken.a2020_04_21e">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
@@ -8,17 +8,34 @@
import me.thankstoken.a2020_04_21e.model.Dog;
import me.thankstoken.a2020_04_21e.model.ItemArrayAdapter;

import android.media.MediaPlayer;
import android.os.Bundle;

import java.io.IOException;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

public MediaPlayer radio;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


setContentView(R.layout.activity_main);

String[] radioNames = {"Radio Su-Data - Subotica",
"Radio Corazón",
"Radio North Pole",
"LM Radio - 702 AM - 87.8 FM in Maputo, Matola",
"Rise FM Stereo Hungary"};
String[] radioList = {"http://su-data.com:8009/;*.mp3",
"http://73.46.84.169:8600/;mp3",
"http://streaming.radiostreamlive.com/radionorthpole_devices",
"http://cast.fabrik.fm:8008/",
"https://dancewave.online/dance.mp3"};

ArrayList<Dog> dogList = new ArrayList<Dog>();

ItemArrayAdapter itemArrayAdapter = new ItemArrayAdapter(R.layout.list_item, dogList);
@@ -28,10 +45,10 @@ protected void onCreate(Bundle savedInstanceState) {
recyclerView.setAdapter(itemArrayAdapter);

// Populating list items
for(int i=0; i<100; i++) {
dogList.add(new Dog("Dog: " + i, R.mipmap.ic_launcher));
for(int i=0; i<5; i++) {
dogList.add(new Dog(radioNames[i], radioList[i]));
}


}

}
@@ -3,22 +3,22 @@
public class Dog {

private String name;
private int myPhoto;
private String link;

public Dog(String n, int imageNumber) {
public Dog(String n, String l) {
name = n;
myPhoto = imageNumber;
link = l;
}

public String getName() { return name; }
public int getImage() { return myPhoto; }
public String getImage() { return link; }

public void setName(String name) {
this.name = name;
}

public void setImage(int imageNumber) {
this.myPhoto = imageNumber;
public void setImage(String link) {
this.link = link;
}
}

@@ -1,23 +1,37 @@
package me.thankstoken.a2020_04_21e.model;

import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ImageButton;

import android.widget.TextView;

import java.io.IOException;
import java.util.ArrayList;

import androidx.recyclerview.widget.RecyclerView;
import androidx.cardview.widget.*;

import me.thankstoken.a2020_04_21e.MainActivity;
import me.thankstoken.a2020_04_21e.R;


public class ItemArrayAdapter extends RecyclerView.Adapter<ItemArrayAdapter.ViewHolder> {

//All methods in this adapter are required for a bare minimum recyclerview adapter
private int listItemLayout;
private ArrayList<Dog> dogList;
private ViewHolder holder;

MediaPlayer radio = new MediaPlayer();
String streamURL = "";


// Constructor of the class
public ItemArrayAdapter(int layoutId, ArrayList<Dog> dogList) {
listItemLayout = layoutId;
@@ -40,25 +54,43 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// load data in each row element
@Override
public void onBindViewHolder(final ViewHolder holder, final int listPosition) {

TextView item = holder.item;
ImageView picture = holder.image;
item.setText(dogList.get(listPosition).getName());
picture.setImageResource(dogList.get(listPosition).getImage());
streamURL = dogList.get(listPosition).getImage();
ImageButton playButton = holder.image;
playButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

try {
radio.setDataSource(streamURL);
radio.prepareAsync();
}
catch (IllegalArgumentException e){
Log.d("IllegalArgument", e.getMessage());
}catch (IOException e){
Log.d("IOException", e.getMessage());
}
radio.start();
}
});
}

// Static inner class to initialize the views of rows
static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView item;
public ImageView image;
public ImageButton image;
public ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
item = (TextView) itemView.findViewById(R.id.row_item);
image = (ImageView) itemView.findViewById(R.id.dog_pic);
item = (TextView) itemView.findViewById(R.id.radioName);
image = (ImageButton) itemView.findViewById(R.id.playButton);
}
@Override
public void onClick(View view) {
Log.d("onclick", "onClick " + getLayoutPosition() + " " + item.getText());
}
}

}
@@ -16,27 +16,20 @@
android:orientation="horizontal">

<!-- -->
<ImageView
android:id="@+id/dog_pic"


<ImageButton
android:id="@+id/playButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_margin="20dp"
android:contentDescription="TODO" />


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="20dp"
android:text="Dog: "

android:textSize="17sp" />
android:layout_weight="1"
app:srcCompat="@android:drawable/ic_media_play" />

<TextView
android:id="@+id/row_item"
android:layout_width="wrap_content"
android:id="@+id/radioName"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="20dp"
@@ -8,7 +8,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.android.tools.build:gradle:3.6.3'


// NOTE: Do not place your application dependencies here; they belong

0 comments on commit 4605cc9

Please sign in to comment.
You can’t perform that action at this time.