Addon content in addons activity tabs
This commit is contained in:
parent
dadc34901c
commit
b0f2adb876
|
@ -16,6 +16,8 @@
|
|||
package org.xbmc.kore.ui;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.view.ViewPager;
|
||||
|
@ -31,6 +33,10 @@ import org.xbmc.kore.utils.TabsAdapter;
|
|||
import org.xbmc.kore.utils.UIUtils;
|
||||
import org.xbmc.kore.utils.Utils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
|
||||
|
@ -70,6 +76,18 @@ public class AddonOverviewFragment extends Fragment {
|
|||
return fragment;
|
||||
}
|
||||
|
||||
public Bundle contentArgs(Bundle details) {
|
||||
String name = details.getString(AddonDetailsFragment.BUNDLE_KEY_NAME, "Content");
|
||||
String path = details.getString(AddonDetailsFragment.BUNDLE_KEY_ADDONID);
|
||||
|
||||
Bundle content = new Bundle();
|
||||
content.putString(AddonDetailsFragment.BUNDLE_KEY_NAME, name);
|
||||
MediaFileListFragment.FileLocation rootPath = new MediaFileListFragment.FileLocation(name, "plugin://" + path, true);
|
||||
rootPath.setRootDir(true);
|
||||
content.putParcelable(MediaFileListFragment.ROOT_PATH, rootPath);
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -87,18 +105,10 @@ public class AddonOverviewFragment extends Fragment {
|
|||
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_default_view_pager, container, false);
|
||||
ButterKnife.inject(this, root);
|
||||
|
||||
Bundle plugin = new Bundle();
|
||||
MediaFileListFragment.FileLocation rootPath = new MediaFileListFragment.FileLocation(
|
||||
args.getString(AddonDetailsFragment.BUNDLE_KEY_NAME, "Content"),
|
||||
"plugin://" + args.getString(AddonDetailsFragment.BUNDLE_KEY_ADDONID, ""),
|
||||
true);
|
||||
rootPath.setRootDir(true);
|
||||
plugin.putParcelable(MediaFileListFragment.ROOT_PATH, rootPath);
|
||||
|
||||
long baseFragmentId = 1000;
|
||||
tabsAdapter = new TabsAdapter(getActivity(), getChildFragmentManager())
|
||||
.addTab(AddonDetailsFragment.class, args, R.string.addon_overview, baseFragmentId++)
|
||||
.addTab(MediaFileListFragment.class, plugin, R.string.addon_content, baseFragmentId++)
|
||||
.addTab(MediaFileListFragment.class, contentArgs(args), R.string.addon_content, baseFragmentId++)
|
||||
;
|
||||
viewPager.setAdapter(tabsAdapter);
|
||||
pagerTabStrip.setViewPager(viewPager);
|
||||
|
|
|
@ -70,7 +70,7 @@ public class AddonsActivity extends BaseActivity
|
|||
navigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
AddonListFragment addonListFragment = new AddonListFragment();
|
||||
AddonsOverviewFragment addonListFragment = new AddonsOverviewFragment();
|
||||
|
||||
// Setup animations
|
||||
if (Utils.isLollipopOrLater()) {
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* Copyright 2016 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.
|
||||
*/
|
||||
package org.xbmc.kore.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.astuetz.PagerSlidingTabStrip;
|
||||
|
||||
import org.xbmc.kore.R;
|
||||
import org.xbmc.kore.utils.LogUtils;
|
||||
import org.xbmc.kore.utils.TabsAdapter;
|
||||
import org.xbmc.kore.utils.UIUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
|
||||
/**
|
||||
* Container for the TV Show overview and Episodes list
|
||||
*/
|
||||
public class AddonsOverviewFragment extends Fragment {
|
||||
private static final String TAG = LogUtils.makeLogTag(AddonsOverviewFragment.class);
|
||||
|
||||
private TabsAdapter tabsAdapter;
|
||||
|
||||
@InjectView(R.id.pager_tab_strip) PagerSlidingTabStrip pagerTabStrip;
|
||||
@InjectView(R.id.pager) ViewPager viewPager;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
if (container == null) {
|
||||
// We're not being shown or there's nothing to show
|
||||
return null;
|
||||
}
|
||||
|
||||
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_default_view_pager, container, false);
|
||||
ButterKnife.inject(this, root);
|
||||
|
||||
tabsAdapter = new TabsAdapter(getActivity(), getChildFragmentManager());
|
||||
SharedPreferences prefs = getActivity().getSharedPreferences("addons", Context.MODE_PRIVATE);
|
||||
Set<String> bookmarked = prefs.getStringSet("bookmarked", Collections.<String>emptySet());
|
||||
long baseFragmentId = 70 + bookmarked.size() * 100;
|
||||
for (String path: bookmarked) {
|
||||
String name = prefs.getString("name_" + path, "Content");
|
||||
Bundle addon = new Bundle();
|
||||
addon.putString(AddonDetailsFragment.BUNDLE_KEY_NAME, name);
|
||||
addon.putParcelable(MediaFileListFragment.ROOT_PATH, new MediaFileListFragment.FileLocation(name, "plugin://" + path, true));
|
||||
tabsAdapter.addTab(MediaFileListFragment.class, addon, name, baseFragmentId++);
|
||||
}
|
||||
tabsAdapter.addTab(AddonListFragment.class, new Bundle(), R.string.addons, baseFragmentId);
|
||||
viewPager.setAdapter(tabsAdapter);
|
||||
pagerTabStrip.setViewPager(viewPager);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated (Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
setHasOptionsMenu(false);
|
||||
}
|
||||
|
||||
public Fragment getCurrentTabFragment() {
|
||||
return tabsAdapter.getItem(viewPager.getCurrentItem());
|
||||
}
|
||||
|
||||
public View getSharedElement() {
|
||||
View view = getView();
|
||||
if (view == null)
|
||||
return null;
|
||||
|
||||
//Note: this works as R.id.poster is only used in TVShowOverviewFragment.
|
||||
//If the same id is used in other fragments in the TabsAdapter we
|
||||
//need to check which fragment is currently displayed
|
||||
View artView = view.findViewById(R.id.poster);
|
||||
View scrollView = view.findViewById(R.id.media_panel);
|
||||
if (( artView != null ) &&
|
||||
( scrollView != null ) &&
|
||||
UIUtils.isViewInBounds(scrollView, artView)) {
|
||||
return artView;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -38,12 +38,21 @@ public class TabsAdapter extends FragmentPagerAdapter {
|
|||
private final Bundle args;
|
||||
private final int titleRes;
|
||||
private final long fragmentId;
|
||||
private final String titleString;
|
||||
|
||||
TabInfo(Class<?> fragmentClass, Bundle args, int titleRes, long fragmentId) {
|
||||
this.fragmentClass = fragmentClass;
|
||||
this.args = args;
|
||||
this.titleRes = titleRes;
|
||||
this.fragmentId = fragmentId;
|
||||
this.titleString = null;
|
||||
}
|
||||
TabInfo(Class<?> fragmentClass, Bundle args, String titleString, long fragmentId) {
|
||||
this.fragmentClass = fragmentClass;
|
||||
this.args = args;
|
||||
this.titleRes = 0;
|
||||
this.fragmentId = fragmentId;
|
||||
this.titleString = titleString;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,6 +68,12 @@ public class TabsAdapter extends FragmentPagerAdapter {
|
|||
return this;
|
||||
}
|
||||
|
||||
public TabsAdapter addTab(Class<?> fragmentClass, Bundle args, String titleString, long fragmentId) {
|
||||
TabInfo info = new TabInfo(fragmentClass, args, titleString, fragmentId);
|
||||
tabInfos.add(info);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return tabInfos.size();
|
||||
|
@ -101,7 +116,7 @@ public class TabsAdapter extends FragmentPagerAdapter {
|
|||
TabInfo tabInfo = tabInfos.get(position);
|
||||
if (tabInfo != null) {
|
||||
// return context.getString(tabInfo.titleRes).toUpperCase(Locale.getDefault());
|
||||
return context.getString(tabInfo.titleRes);
|
||||
return tabInfo.titleString == null? context.getString(tabInfo.titleRes) : tabInfo.titleString;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue