Add recording to channels list
This commit is contained in:
parent
b89d4f4531
commit
7991d64581
|
@ -209,6 +209,14 @@ public class PVR {
|
|||
addParameterToRequest("record", "toggle");
|
||||
}
|
||||
|
||||
/**
|
||||
* Records a channel
|
||||
*/
|
||||
public Record(int channelId) {
|
||||
super();
|
||||
addParameterToRequest("channel", channelId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return METHOD_NAME;
|
||||
|
|
|
@ -19,6 +19,7 @@ import android.app.Activity;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.media.Image;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
|
@ -34,6 +35,7 @@ import android.widget.AdapterView;
|
|||
import android.widget.ArrayAdapter;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -401,6 +403,46 @@ public class PVRChannelsListFragment extends Fragment
|
|||
private HostManager hostManager;
|
||||
private int artWidth, artHeight;
|
||||
|
||||
private View.OnClickListener channelItemMenuClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final int channelId = (Integer)v.getTag();
|
||||
|
||||
final PopupMenu popupMenu = new PopupMenu(getActivity(), v);
|
||||
popupMenu.getMenuInflater().inflate(R.menu.pvr_channel_list_item, popupMenu.getMenu());
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_record_item:
|
||||
PVR.Record action = new PVR.Record(channelId);
|
||||
action.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
if (!isAdded()) return;
|
||||
LogUtils.LOGD(TAG, "Started recording");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int errorCode, String description) {
|
||||
if (!isAdded()) return;
|
||||
LogUtils.LOGD(TAG, "Error starting to record: " + description);
|
||||
|
||||
Toast.makeText(getActivity(),
|
||||
String.format(getString(R.string.error_starting_to_record), description),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
}, callbackHandler);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
popupMenu.show();
|
||||
}
|
||||
};
|
||||
|
||||
public ChannelAdapter(Context context, int resource) {
|
||||
super(context, resource);
|
||||
this.hostManager = HostManager.getInstance(context);
|
||||
|
@ -425,6 +467,7 @@ public class PVRChannelsListFragment extends Fragment
|
|||
viewHolder.titleView = (TextView)convertView.findViewById(R.id.title);
|
||||
viewHolder.detailsView = (TextView)convertView.findViewById(R.id.details);
|
||||
viewHolder.artView = (ImageView)convertView.findViewById(R.id.art);
|
||||
viewHolder.contextMenu = (ImageView)convertView.findViewById(R.id.list_context_menu);
|
||||
convertView.setTag(viewHolder);
|
||||
}
|
||||
|
||||
|
@ -441,6 +484,11 @@ public class PVRChannelsListFragment extends Fragment
|
|||
UIUtils.loadImageWithCharacterAvatar(getContext(), hostManager,
|
||||
channelDetails.thumbnail, channelDetails.channel,
|
||||
viewHolder.artView, artWidth, artHeight);
|
||||
|
||||
// For the popupmenu
|
||||
viewHolder.contextMenu.setTag(channelDetails.channelid);
|
||||
viewHolder.contextMenu.setOnClickListener(channelItemMenuClickListener);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
|
@ -450,7 +498,7 @@ public class PVRChannelsListFragment extends Fragment
|
|||
*/
|
||||
private static class ChannelViewHolder {
|
||||
TextView titleView, detailsView;
|
||||
ImageView artView;
|
||||
ImageView artView, contextMenu;
|
||||
|
||||
int channelId;
|
||||
String channelName;
|
||||
|
|
|
@ -23,34 +23,50 @@
|
|||
card_view:cardElevation="@dimen/default_card_elevation"
|
||||
card_view:cardBackgroundColor="?attr/appCardBackgroundColor">
|
||||
|
||||
<LinearLayout
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/art"
|
||||
android:layout_width="@dimen/channellist_art_width"
|
||||
android:layout_height="@dimen/channellist_art_heigth"
|
||||
android:contentDescription="@string/poster"/>
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:contentDescription="@string/poster"
|
||||
android:scaleType="centerCrop"/>
|
||||
|
||||
<LinearLayout
|
||||
<ImageView
|
||||
android:id="@+id/list_context_menu"
|
||||
android:layout_width="@dimen/default_icon_size"
|
||||
android:layout_height="@dimen/default_icon_size"
|
||||
android:layout_alignTop="@id/art"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:padding="@dimen/default_icon_padding"
|
||||
android:src="?attr/iconOverflow"
|
||||
android:contentDescription="@string/action_options"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_vertical">
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/TextAppearance.Medialist.Title"
|
||||
android:paddingTop="0dp"/>
|
||||
<TextView
|
||||
android:id="@+id/details"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/TextAppearance.Medialist.Details"
|
||||
android:paddingBottom="0dp"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toRightOf="@id/art"
|
||||
android:layout_toEndOf="@+id/art"
|
||||
android:layout_toLeftOf="@id/list_context_menu"
|
||||
android:layout_toStartOf="@id/list_context_menu"
|
||||
android:layout_alignTop="@id/art"
|
||||
style="@style/TextAppearance.Medialist.Title"/>
|
||||
<TextView
|
||||
android:id="@+id/details"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignLeft="@id/title"
|
||||
android:layout_alignStart="@id/title"
|
||||
android:layout_below="@id/title"
|
||||
android:layout_toRightOf="@id/art"
|
||||
android:layout_toEndOf="@id/art"
|
||||
style="@style/TextAppearance.Medialist.Details"/>
|
||||
</RelativeLayout>
|
||||
</android.support.v7.widget.CardView>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2015 Synced Synapse. All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item android:id="@+id/action_record_item"
|
||||
android:title="@string/record"
|
||||
android:orderInCategory="1"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
|
@ -343,6 +343,7 @@
|
|||
<string name="might_not_have_pvr">An error occurred while getting channels info, probably because your media center doesn\'t have a tuner or it isn\'t configured.\n\nIf that\'s the case and you\'d like to remove this entry from the side menu, you can do it in the Settings.</string>
|
||||
<string name="error_starting_channel">An error occurred starting channel playback: %1$s</string>
|
||||
<string name="error_starting_recording">An error occurred starting a recording: %1$s</string>
|
||||
<string name="error_starting_to_record">An error occurred while recording: %1$s</string>
|
||||
<string name="channel_switching">Switching to channel %1$s</string>
|
||||
<string name="starting_recording">Starting recording %1$s</string>
|
||||
<string name="refresh">refresh</string>
|
||||
|
@ -353,4 +354,6 @@
|
|||
<string name="tv_channels">TV Channels</string>
|
||||
<string name="radio_channels">Radio Channels</string>
|
||||
|
||||
<string name="record">Record</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue