Check if the host has PVR enabled and show/hide the side menu entry based on that
This commit is contained in:
parent
9f159460f1
commit
0fd2e621ad
|
@ -17,15 +17,10 @@ package org.xbmc.kore;
|
|||
|
||||
import android.text.format.DateUtils;
|
||||
|
||||
import org.xbmc.kore.jsonrpc.type.PVRType;
|
||||
import org.xbmc.kore.ui.PVRListFragment;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Interface that contains various constants and the keys for settings stored in shared preferences
|
||||
* Class that contains various constants and the keys for settings stored in shared preferences
|
||||
*/
|
||||
public interface Settings {
|
||||
public class Settings {
|
||||
/**
|
||||
* The update interval for the records in the DB. If the last update is older than this value
|
||||
* a refresh will be triggered. Applicable to TV Shows and Movies.
|
||||
|
@ -104,5 +99,11 @@ public interface Settings {
|
|||
public static final String KEY_PREF_CHECKED_EVENT_SERVER_CONNECTION = "checked_event_server_connection";
|
||||
public static final boolean DEFAULT_PREF_CHECKED_EVENT_SERVER_CONNECTION = false;
|
||||
|
||||
public static final String KEY_PREF_CHECKED_PVR_ENABLED = "checked_pvr_enabled";
|
||||
public static final boolean DEFAULT_PREF_CHECKED_PVR_ENABLED = false;
|
||||
|
||||
public static final String KEY_PREF_NAV_DRAWER_ITEMS = "pref_nav_drawer_items";
|
||||
public static String getNavDrawerItemsPrefKey(int hostId) {
|
||||
return Settings.KEY_PREF_NAV_DRAWER_ITEMS + hostId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ public class NavigationDrawerFragment extends Fragment {
|
|||
*/
|
||||
private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned";
|
||||
|
||||
private static final int ACTIVITY_HOSTS = 0,
|
||||
public static final int ACTIVITY_HOSTS = 0,
|
||||
ACTIVITY_REMOTE = 1,
|
||||
ACTIVITY_MOVIES = 2,
|
||||
ACTIVITY_TVSHOWS = 3,
|
||||
|
@ -147,7 +147,7 @@ public class NavigationDrawerFragment extends Fragment {
|
|||
|
||||
Set<String> shownItems = PreferenceManager
|
||||
.getDefaultSharedPreferences(getActivity())
|
||||
.getStringSet(SettingsFragment.getNavDrawerItemsPrefKey(hostId),
|
||||
.getStringSet(Settings.getNavDrawerItemsPrefKey(hostId),
|
||||
new HashSet<>(Arrays.asList(getResources().getStringArray(R.array.entry_values_nav_drawer_items))));
|
||||
|
||||
ArrayList<DrawerItem> items = new ArrayList<>(15);
|
||||
|
|
|
@ -56,6 +56,7 @@ import org.xbmc.kore.jsonrpc.type.PlayerType;
|
|||
import org.xbmc.kore.jsonrpc.type.PlaylistType;
|
||||
import org.xbmc.kore.service.NotificationService;
|
||||
import org.xbmc.kore.ui.hosts.AddHostActivity;
|
||||
import org.xbmc.kore.ui.hosts.AddHostFragmentFinish;
|
||||
import org.xbmc.kore.ui.views.CirclePageIndicator;
|
||||
import org.xbmc.kore.utils.LogUtils;
|
||||
import org.xbmc.kore.utils.TabsAdapter;
|
||||
|
@ -158,6 +159,8 @@ public class RemoteActivity extends BaseActivity
|
|||
hostConnectionObserver.registerPlayerObserver(this, true);
|
||||
// Force a refresh, mainly to update the time elapsed on the fragments
|
||||
hostConnectionObserver.forceRefreshResults();
|
||||
|
||||
checkPVREnabledAndSetMenuItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -167,6 +170,25 @@ public class RemoteActivity extends BaseActivity
|
|||
hostConnectionObserver = null;
|
||||
}
|
||||
|
||||
// TODO: Remove this method after deployment of 2.0.0, as it is only needed to
|
||||
// facilitate the transition by checking if PVR is enabled and set the side menu
|
||||
// items accordingly
|
||||
private void checkPVREnabledAndSetMenuItems() {
|
||||
if (hostManager.getHostInfo() == null) return;
|
||||
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
// Check if PVR is enabled for the current host
|
||||
String prefKey = Settings.KEY_PREF_CHECKED_PVR_ENABLED + String.valueOf(hostManager.getHostInfo().getId());
|
||||
boolean checkedPVREnabled = sp.getBoolean(prefKey, Settings.DEFAULT_PREF_CHECKED_PVR_ENABLED);
|
||||
if (!checkedPVREnabled) {
|
||||
AddHostFragmentFinish.checkPVREnabledAndSetMenuItems(this, new Handler());
|
||||
sp.edit()
|
||||
.putBoolean(prefKey, true)
|
||||
.apply();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Override hardware volume keys and send to Kodi
|
||||
*/
|
||||
|
|
|
@ -54,7 +54,7 @@ public class SettingsFragment extends PreferenceFragment
|
|||
// the current host
|
||||
MultiSelectListPreference sideMenuItens = (MultiSelectListPreference)findPreference(Settings.KEY_PREF_NAV_DRAWER_ITEMS);
|
||||
hostId = HostManager.getInstance(getActivity()).getHostInfo().getId();
|
||||
sideMenuItens.setKey(getNavDrawerItemsPrefKey(hostId));
|
||||
sideMenuItens.setKey(Settings.getNavDrawerItemsPrefKey(hostId));
|
||||
|
||||
// HACK: After changing the key dinamically like above, we need to force the preference
|
||||
// to read its value. This can be done by calling onSetInitialValue, which is protected,
|
||||
|
@ -62,7 +62,7 @@ public class SettingsFragment extends PreferenceFragment
|
|||
// hack changes its access mode.
|
||||
// Furthermore, only do this is nothing is saved yet on the shared preferences,
|
||||
// otherwise the defaults won't be applied
|
||||
if (getPreferenceManager().getSharedPreferences().getStringSet(getNavDrawerItemsPrefKey(hostId), null) != null) {
|
||||
if (getPreferenceManager().getSharedPreferences().getStringSet(Settings.getNavDrawerItemsPrefKey(hostId), null) != null) {
|
||||
Class iterClass = sideMenuItens.getClass();
|
||||
try {
|
||||
Method m = iterClass.getDeclaredMethod("onSetInitialValue", boolean.class, Object.class);
|
||||
|
@ -95,7 +95,7 @@ public class SettingsFragment extends PreferenceFragment
|
|||
// Update summaries
|
||||
setupPreferences();
|
||||
|
||||
if (key.equals(Settings.KEY_PREF_THEME) || key.equals(getNavDrawerItemsPrefKey(hostId))) {
|
||||
if (key.equals(Settings.KEY_PREF_THEME) || key.equals(Settings.getNavDrawerItemsPrefKey(hostId))) {
|
||||
// Explicitly clear cache of resource ids that is maintained in the activity
|
||||
UIUtils.playPauseIconsLoaded = false;
|
||||
|
||||
|
@ -133,8 +133,4 @@ public class SettingsFragment extends PreferenceFragment
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static String getNavDrawerItemsPrefKey(int hostId) {
|
||||
return Settings.KEY_PREF_NAV_DRAWER_ITEMS + hostId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,12 @@
|
|||
package org.xbmc.kore.ui.hosts;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.Html;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
|
@ -27,8 +31,19 @@ import android.view.ViewGroup;
|
|||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
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.HostConnection;
|
||||
import org.xbmc.kore.service.LibrarySyncService;
|
||||
import org.xbmc.kore.ui.NavigationDrawerFragment;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Fragment that presents the welcome message
|
||||
|
@ -74,6 +89,16 @@ public class AddHostFragmentFinish extends Fragment {
|
|||
previous.setText(null);
|
||||
previous.setEnabled(false);
|
||||
|
||||
// Check if PVR is enabled for the current host
|
||||
HostManager hostManager = HostManager.getInstance(getActivity());
|
||||
if (hostManager.getHostInfo() != null) {
|
||||
AddHostFragmentFinish.checkPVREnabledAndSetMenuItems(getActivity(), new Handler());
|
||||
String prefKey = Settings.KEY_PREF_CHECKED_PVR_ENABLED + String.valueOf(hostManager.getHostInfo().getId());
|
||||
PreferenceManager.getDefaultSharedPreferences(getActivity()).edit()
|
||||
.putBoolean(prefKey, true)
|
||||
.apply();
|
||||
}
|
||||
|
||||
// Start the syncing process
|
||||
Intent syncIntent = new Intent(this.getActivity(), LibrarySyncService.class);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_ALL_MOVIES, true);
|
||||
|
@ -100,5 +125,40 @@ public class AddHostFragmentFinish extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks wheter PVR is enabled and sets a Preference that controls the items to show on
|
||||
* the navigation drawer accordingly: if PVR is disabled, hide the PVR item, otherwise show it
|
||||
*
|
||||
* This
|
||||
*
|
||||
* @param context Context
|
||||
*/
|
||||
public static void checkPVREnabledAndSetMenuItems(final Context context, Handler handler) {
|
||||
final HostConnection conn = HostManager.getInstance(context).getConnection();
|
||||
final int hostId = HostManager.getInstance(context).getHostInfo().getId();
|
||||
org.xbmc.kore.jsonrpc.method.Settings.GetSettingValue getSettingValue =
|
||||
new org.xbmc.kore.jsonrpc.method.Settings.GetSettingValue(org.xbmc.kore.jsonrpc.method.Settings.PVRMANAGER_ENABLED);
|
||||
getSettingValue.execute(conn, new ApiCallback<JsonNode>() {
|
||||
@Override
|
||||
public void onSuccess(JsonNode result) {
|
||||
// Result is boolean
|
||||
boolean isEnabled = result.asBoolean(false);
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
Set<String> shownItems = new HashSet<>(Arrays.asList(
|
||||
context.getResources()
|
||||
.getStringArray(R.array.entry_values_nav_drawer_items)));
|
||||
if (!isEnabled)
|
||||
shownItems.remove(String.valueOf(NavigationDrawerFragment.ACTIVITY_PVR));
|
||||
sp.edit()
|
||||
.putStringSet(Settings.getNavDrawerItemsPrefKey(hostId), shownItems)
|
||||
.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int errorCode, String description) {
|
||||
// Ignore, use defaults
|
||||
}
|
||||
}, handler);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue