Add support for radio channels in PVR

This commit is contained in:
Synced Synapse 2015-11-12 22:44:03 +00:00
parent 0f11f3132f
commit c1e5424675
5 changed files with 119 additions and 16 deletions

View File

@ -17,6 +17,8 @@ package org.xbmc.kore;
import android.text.format.DateUtils;
import org.xbmc.kore.jsonrpc.type.PVRType;
import java.util.Set;
/**
@ -99,4 +101,7 @@ public interface Settings {
public static final boolean DEFAULT_PREF_CHECKED_EVENT_SERVER_CONNECTION = false;
public static final String KEY_PREF_NAV_DRAWER_ITEMS = "pref_nav_drawer_items";
public static final String KEY_PREF_PVR_LIST_CHANNEL_TYPE = "pref_pvr_list_channel_type";
public static final String DEFAULT_PREF_PVR_LIST_CHANNEL_TYPE = PVRType.ChannelType.TV;
}

View File

@ -17,7 +17,9 @@ package org.xbmc.kore.ui;
import android.annotation.TargetApi;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
@ -28,6 +30,7 @@ import android.view.MenuItem;
import android.view.Window;
import org.xbmc.kore.R;
import org.xbmc.kore.Settings;
import org.xbmc.kore.utils.LogUtils;
import org.xbmc.kore.utils.Utils;
@ -52,6 +55,7 @@ public class PVRActivity extends BaseActivity
private int selectedChannelId = -1;
private String selectedChannelTitle = null;
private String selectedChannelType;
private NavigationDrawerFragment navigationDrawerFragment;
@ -93,7 +97,10 @@ public class PVRActivity extends BaseActivity
selectedChannelTitle = savedInstanceState.getString(CHANNELTITLE, null);
}
setupActionBar(selectedChannelGroupTitle);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
selectedChannelType = preferences.getString(Settings.KEY_PREF_PVR_LIST_CHANNEL_TYPE, Settings.DEFAULT_PREF_PVR_LIST_CHANNEL_TYPE);
setupActionBar(selectedChannelType, selectedChannelGroupTitle);
}
@Override
@ -140,7 +147,7 @@ public class PVRActivity extends BaseActivity
if (selectedChannelId != -1) {
selectedChannelId = -1;
selectedChannelTitle = null;
setupActionBar(null);
setupActionBar(selectedChannelType, null);
getSupportFragmentManager().popBackStack();
return true;
} else if (returnToChannelGroupList && (selectedChannelGroupId != -1)) {
@ -161,11 +168,11 @@ public class PVRActivity extends BaseActivity
if (selectedChannelId != -1) {
selectedChannelId = -1;
selectedChannelTitle = null;
setupActionBar(null);
setupActionBar(selectedChannelType, null);
} else if ((selectedChannelGroupId != -1) && returnToChannelGroupList) {
selectedChannelGroupId = -1;
selectedChannelGroupTitle = null;
setupActionBar(null);
setupActionBar(selectedChannelType, null);
Fragment listFragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
if ((listFragment != null) &&
(listFragment instanceof PVRListFragment)) {
@ -176,20 +183,25 @@ public class PVRActivity extends BaseActivity
super.onBackPressed();
}
private void setupActionBar(String channelTitle) {
private void setupActionBar(String channelType, String channelTitle) {
Toolbar toolbar = (Toolbar)findViewById(R.id.default_toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar == null) return;
actionBar.setDisplayHomeAsUpEnabled(true);
String title;
boolean drawerIndicatorEnabled;
if (channelTitle != null) {
navigationDrawerFragment.setDrawerIndicatorEnabled(!returnToChannelGroupList);
actionBar.setTitle(channelTitle);
drawerIndicatorEnabled = !returnToChannelGroupList;
title = String.format("%s - %s", PVRListFragment.getChannelTypeTitle(this, channelType), channelTitle);
} else {
navigationDrawerFragment.setDrawerIndicatorEnabled(true);
actionBar.setTitle(R.string.tv_radio);
drawerIndicatorEnabled = true;
title = PVRListFragment.getChannelTypeTitle(this, channelType);
}
navigationDrawerFragment.setDrawerIndicatorEnabled(drawerIndicatorEnabled);
actionBar.setTitle(title);
}
/**
@ -203,7 +215,7 @@ public class PVRActivity extends BaseActivity
selectedChannelGroupTitle = channelGroupTitle;
this.returnToChannelGroupList = canReturnToChannelGroupList;
setupActionBar(selectedChannelGroupTitle);
setupActionBar(selectedChannelType, selectedChannelGroupTitle);
}
/**
@ -234,6 +246,15 @@ public class PVRActivity extends BaseActivity
// fragTrans.replace(R.id.fragment_container, pvrDetailsFragment)
// .addToBackStack(null)
// .commit();
setupActionBar(selectedChannelTitle);
setupActionBar(selectedChannelType, selectedChannelTitle);
}
/**
* Callback from list fragment when the channel type is changed
* @param channelType Channel type selected
*/
public void onChannelTypeSelected(String channelType) {
selectedChannelType = channelType;
setupActionBar(selectedChannelType, selectedChannelTitle);
}
}

View File

@ -17,12 +17,17 @@ package org.xbmc.kore.ui;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
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.AdapterView;
@ -33,6 +38,7 @@ import android.widget.TextView;
import android.widget.Toast;
import org.xbmc.kore.R;
import org.xbmc.kore.Settings;
import org.xbmc.kore.host.HostManager;
import org.xbmc.kore.jsonrpc.ApiCallback;
import org.xbmc.kore.jsonrpc.ApiException;
@ -57,6 +63,7 @@ public class PVRListFragment extends Fragment
public static final String CHANNELGROUPID = "channel_group_id";
public interface OnPVRSelectedListener {
public void onChannelTypeSelected(String channelType);
public void onChannelGroupSelected(int channelGroupId, String channelGroupTitle, boolean canReturnToChannelGroupList);
public void onChannelGuideSelected(int channelId, String channelTitle);
}
@ -79,6 +86,7 @@ public class PVRListFragment extends Fragment
private ChannelAdapter channelAdapter = null;
private int selectedChannelGroupId = -1;
private String selectedChannelType;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -94,6 +102,9 @@ public class PVRListFragment extends Fragment
selectedChannelGroupId = savedInstanceState.getInt(CHANNELGROUPID);
}
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
selectedChannelType = preferences.getString(Settings.KEY_PREF_PVR_LIST_CHANNEL_TYPE, Settings.DEFAULT_PREF_PVR_LIST_CHANNEL_TYPE);
hostManager = HostManager.getInstance(getActivity());
swipeRefreshLayout.setOnRefreshListener(this);
@ -112,7 +123,7 @@ public class PVRListFragment extends Fragment
@Override
public void onActivityCreated (Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(false);
setHasOptionsMenu(true);
if (selectedChannelGroupId == -1) {
if ((channelGroupAdapter == null) ||
@ -155,6 +166,47 @@ public class PVRListFragment extends Fragment
outState.putInt(CHANNELGROUPID, selectedChannelGroupId);
}
public static String getChannelTypeTitle(Context context, String ChannelType) {
return (ChannelType.equals(PVRType.ChannelType.TV)) ?
context.getResources().getString(R.string.tv) :
context.getResources().getString(R.string.radio);
}
private void setupChannelTypeMenuItem(MenuItem item, String channelType) {
item.setTitle(getChannelTypeTitle(getActivity(), channelType));
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.pvr_list, menu);
String switchChannelType = (selectedChannelType.equals(PVRType.ChannelType.TV)) ?
PVRType.ChannelType.RADIO : PVRType.ChannelType.TV;
setupChannelTypeMenuItem(menu.findItem(R.id.action_switch_channel_type), switchChannelType);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
switch (item.getItemId()) {
case R.id.action_switch_channel_type:
selectedChannelType = (selectedChannelType.equals(PVRType.ChannelType.TV)) ?
PVRType.ChannelType.RADIO : PVRType.ChannelType.TV;
preferences.edit()
.putString(Settings.KEY_PREF_PVR_LIST_CHANNEL_TYPE, selectedChannelType)
.apply();
setupChannelTypeMenuItem(item, selectedChannelType);
browseChannelGroups();
listenerActivity.onChannelTypeSelected(selectedChannelType);
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
/**
* Swipe refresh layout callback
*/
@ -186,9 +238,8 @@ public class PVRListFragment extends Fragment
* Get the channel groups list and setup the gridview
*/
private void browseChannelGroups() {
// TODO: Make the channel type selectable
LogUtils.LOGD(TAG, "Getting channel groups");
PVR.GetChannelGroups action = new PVR.GetChannelGroups(PVRType.ChannelType.TV);
PVR.GetChannelGroups action = new PVR.GetChannelGroups(selectedChannelType);
action.execute(hostManager.getConnection(), new ApiCallback<List<PVRType.DetailsChannelGroup>>() {
@Override
public void onSuccess(List<PVRType.DetailsChannelGroup> result) {

View File

@ -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_switch_channel_type"
android:title="@string/tv"
android:orderInCategory="1"
app:showAsAction="never" />
</menu>

View File

@ -240,8 +240,8 @@
<string name="no_genres_found_refresh">No genres found\n\nSwipe down to refresh</string>
<string name="no_addons_found_refresh">No addons found or not connected\n\nSwipe down to refresh</string>
<string name="no_music_videos_found_refresh">No videos found\n\nSwipe down to refresh</string>
<string name="no_channel_groups_found_refresh">No channel groups found or not connected\n\nSwipe down to refresh</string>
<string name="no_channels_found_refresh">No channel groups found or not connected\n\nSwipe down to refresh</string>
<string name="no_channel_groups_found_refresh">No channel groups found.\n\nSwipe down to refresh</string>
<string name="no_channels_found_refresh">No channels found.\n\nSwipe down to refresh</string>
<string name="pull_to_refresh">Pull to refresh</string>
<string name="no_cast_info">No cast info to display</string>
@ -343,4 +343,7 @@
<string name="error_starting_channel">An error occurred starting channel playback: %1$s</string>
<string name="channel_switching">Switching to channel %1$s</string>
<string name="tv">TV</string>
<string name="radio">Radio</string>
</resources>