Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2 from LaQuay/develop
Browse files Browse the repository at this point in the history
Update to 0.2.0
  • Loading branch information
LaQuay authored Mar 3, 2019
2 parents e3f8a70 + 079f16e commit f5f3a58
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 71 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.3.1'


// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Feb 16 12:42:05 CET 2019
#Sun Mar 03 14:15:14 CET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
2 changes: 1 addition & 1 deletion mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "0.1.0"
versionName "0.2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,39 @@
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;

import java.util.ArrayList;

import laquay.com.canalestdt.component.ChannelList;
import laquay.com.canalestdt.model.Channel;
import laquay.com.canalestdt.model.ChannelOptions;

public class DetailChannelActivity extends AppCompatActivity {
public static final String TAG = DetailChannelActivity.class.getSimpleName();
public static final String EXTRA_MESSAGE = "laquay.com.canalestdt.CHANNEL_DETAIL";
private Channel channel;
private SimpleExoPlayer player;
private DefaultDataSourceFactory dataSourceFactory;

private PlayerView channelVideoView;
private TextView channelMockTV;
private TextView channelNameTV;
private TextView channelURLTV;
private TextView channelSourceTV;
private ListView channelSourceLV;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -54,9 +64,18 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void setUpElements() {
channelVideoView = findViewById(R.id.channel_video_detail_tv);
channelVideoView = findViewById(R.id.channel_video_detail_exoplayer);
channelMockTV = findViewById(R.id.channel_mock_detail_tv);
channelNameTV = findViewById(R.id.channel_name_detail_tv);
channelURLTV = findViewById(R.id.channel_url_detail_tv);
channelSourceTV = findViewById(R.id.channel_source_detail_tv);
channelSourceLV = findViewById(R.id.channel_source_detail_lv);

player = ExoPlayerFactory.newSimpleInstance(this);

// Produces DataSource instances through which media data is loaded.
dataSourceFactory = new DefaultDataSourceFactory(this,
Util.getUserAgent(this, "laquay.com.canalestdt"));
}

private void setUpListeners() {
Expand All @@ -68,19 +87,40 @@ private void loadChannel() {
channelURLTV.setText(channel.getWeb());

// Load first option
// TODO Select different option
Uri channelUri = Uri.parse(channel.getOptions().get(0).getUrl());
if (!channel.getOptions().isEmpty()) {
// Fill available options
ArrayList<String> sources = new ArrayList<>();
for (ChannelOptions channelOption : channel.getOptions()) {
sources.add(channelOption.getUrl());
}

ArrayAdapter<String> sourcesAdapter = new ArrayAdapter<>(this,
R.layout.item_list_detail_channel, android.R.id.text1, sources);
channelSourceLV.setAdapter(sourcesAdapter);

channelSourceLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String source = (String) channelSourceLV.getItemAtPosition(position);
loadVideo(source, position);
}
});

loadVideo(sources.get(0), 0);
} else {
channelVideoView.setVisibility(View.GONE);
channelSourceTV.setVisibility(View.GONE);
channelMockTV.setVisibility(View.VISIBLE);
}
}

player = ExoPlayerFactory.newSimpleInstance(this);
public void loadVideo(String streamURL, int sourceNumber) {
channelSourceTV.setText(getString(R.string.channel_detail_currenty_playing) + " - Source: " + (sourceNumber + 1));
channelVideoView.setPlayer(player);

// Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
Util.getUserAgent(this, "laquay.com.canalestdt"));

// This is the MediaSource representing the media to be played.
MediaSource videoSource = new HlsMediaSource.Factory(dataSourceFactory)
.createMediaSource(channelUri);
.createMediaSource(Uri.parse(streamURL));

// Prepare the player with the source.
player.prepare(videoSource);
Expand All @@ -90,7 +130,9 @@ private void loadChannel() {
@Override
public void onStop() {
super.onStop();
player.release();
if (player != null) {
player.release();
}
}

@Override
Expand Down
23 changes: 0 additions & 23 deletions mobile/src/main/java/laquay/com/canalestdt/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

Expand Down Expand Up @@ -49,28 +48,6 @@ public void onBackPressed() {
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
Expand Down
101 changes: 93 additions & 8 deletions mobile/src/main/java/laquay/com/canalestdt/MainFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
Expand All @@ -35,6 +44,7 @@ public class MainFragment extends Fragment implements APIController.ResponseServ
public static final String TAG = MainFragment.class.getSimpleName();
private View rootView;
private ListView channelListView;
private CountryArrayAdapter arrayAdapter;

public static MainFragment newInstance() {
return new MainFragment();
Expand All @@ -45,6 +55,7 @@ public static MainFragment newInstance() {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_main, container, false);

setHasOptionsMenu(true);
setUpElements();
setUpListeners();

Expand Down Expand Up @@ -81,20 +92,63 @@ public void onChannelLoadServer(ArrayList<Country> countries) {
}
}

CountryArrayAdapter arrayAdapter = new CountryArrayAdapter(getContext(), channelLists);
arrayAdapter = new CountryArrayAdapter(getContext(), channelLists);
channelListView.setAdapter(arrayAdapter);
arrayAdapter.notifyDataSetChanged();
}

Log.i(TAG, "Redrawing channels - End");
}

public class CountryArrayAdapter extends ArrayAdapter<ChannelList> {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
menuInflater.inflate(R.menu.fragment_main, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);

// Change color of the search button
if (getContext() != null) {
Drawable drawable = DrawableCompat.wrap(searchItem.getIcon());
DrawableCompat.setTint(drawable, ContextCompat.getColor(getContext(), R.color.white));
menu.findItem(R.id.action_search).setIcon(drawable);
}

SearchView searchView = (SearchView) searchItem.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}

@Override
public boolean onQueryTextChange(String newText) {
// This will be fired every time you input any character.
if (arrayAdapter != null) {
arrayAdapter.getFilter().filter(newText);
}
return false;
}
});
}

public class CountryArrayAdapter extends ArrayAdapter<ChannelList> implements Filterable {
private final ArrayList<ChannelList> channels;
private ArrayList<ChannelList> filteredChannels;
private ItemFilter mFilter = new ItemFilter();

public CountryArrayAdapter(@NonNull Context context, ArrayList<ChannelList> channels) {
super(context, 0, channels);
this.channels = channels;
this.filteredChannels = channels;
}

@NonNull
public Filter getFilter() {
return mFilter;
}

@Override
public int getCount() {
return filteredChannels.size();
}

@NonNull
Expand All @@ -103,7 +157,7 @@ public View getView(final int position, @Nullable View convertView, @NonNull Vie
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewHolder holder = new ViewHolder();
if (convertView == null) {
convertView = inflater.inflate(R.layout.item_list, parent, false);
convertView = inflater.inflate(R.layout.item_list_channels, parent, false);

holder.imageView = convertView.findViewById(R.id.channel_icon);
holder.titleView = convertView.findViewById(R.id.channel_title);
Expand All @@ -114,11 +168,11 @@ public View getView(final int position, @Nullable View convertView, @NonNull Vie
holder = (ViewHolder) convertView.getTag();
}

holder.titleView.setText(channels.get(position).getChannel().getName());
holder.subtitleView.setText(channels.get(position).getCountryName() + " - " + channels.get(position).getCommunityName());
holder.titleView.setText(filteredChannels.get(position).getChannel().getName());
holder.subtitleView.setText(filteredChannels.get(position).getCountryName() + " - " + filteredChannels.get(position).getCommunityName());
holder.imageView.setImageResource(R.drawable.ic_launcher_foreground);

String imageUrl = channels.get(position).getChannel().getLogo();
String imageUrl = filteredChannels.get(position).getChannel().getLogo();
// Temporary fix
imageUrl = imageUrl.replace("http://graph.facebook.com", "https://graph.facebook.com");

Expand All @@ -140,16 +194,47 @@ public void onErrorResponse(VolleyError error) {
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG, "onClick " + channels.get(position).getChannel().getName());
Log.d(TAG, "onClick " + filteredChannels.get(position).getChannel().getName());
Intent intent = new Intent(getActivity(), DetailChannelActivity.class);
intent.putExtra(EXTRA_MESSAGE, channels.get(position));
intent.putExtra(EXTRA_MESSAGE, filteredChannels.get(position));
startActivity(intent);
}
});

return convertView;
}

private class ItemFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
String filterString = constraint.toString().toLowerCase();
FilterResults results = new FilterResults();

final ArrayList<ChannelList> filteredChannels = new ArrayList<>();

String channelNameToFilter;
for (int i = 0; i < channels.size(); i++) {
ChannelList channelList = channels.get(i);
channelNameToFilter = channelList.getChannel().getName();

if (channelNameToFilter.toLowerCase().contains(filterString)) {
filteredChannels.add(channelList);
}
}

results.values = filteredChannels;
results.count = filteredChannels.size();
return results;
}

@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
filteredChannels = (ArrayList<ChannelList>) results.values;
notifyDataSetChanged();
}
}

class ViewHolder {
ImageView imageView;
TextView titleView;
Expand Down
10 changes: 10 additions & 0 deletions mobile/src/main/res/drawable/ic_menu_search.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- drawable/magnify.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#000"
android:pathData="M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z" />
</vector>
Loading

0 comments on commit f5f3a58

Please sign in to comment.