Commit f58308f8 authored by Geoffrey Métais's avatar Geoffrey Métais

Extensions API: Set refresh callback

parent 0ee8743d
......@@ -5,7 +5,7 @@ import android.net.Uri;
interface IExtensionHost {
// Protocol version 1
oneway void updateList(in String title, in List<VLCExtensionItem> items, boolean showParams);
oneway void updateList(in String title, in List<VLCExtensionItem> items, boolean showParams, boolean isRefresh);
oneway void playUri(in Uri uri, String title);
oneway void unBind(int index);
}
......@@ -93,9 +93,9 @@ public abstract class VLCExtensionService extends Service{
* @param items The items to show.
* @param showParams Wether you want to show the FAB to launch your extension settings activity.
*/
protected void updateList(String title, List<VLCExtensionItem> items, boolean showParams){
protected void updateList(String title, List<VLCExtensionItem> items, boolean showParams, boolean isrefresh){
try {
mHost.updateList(title, items, showParams);
mHost.updateList(title, items, showParams, isrefresh);
} catch (RemoteException e) {
e.printStackTrace();
}
......@@ -103,7 +103,7 @@ public abstract class VLCExtensionService extends Service{
/**
* Called once VLC is binded to your service.
* Use it to call {@link #updateList(String, List, boolean)} with root level elements
* Use it to call {@link #updateList(String, List, boolean, boolean)} with root level elements
* if you want VLC to handle your extension browsing.
*/
protected void onInitialize() {};
......
......@@ -70,7 +70,7 @@ public class ExtensionManagerService extends Service {
int mCurrentIndex = -1;
public interface ExtensionManagerActivity {
void displayExtensionItems(String title, List<VLCExtensionItem> items, boolean showParams);
void displayExtensionItems(String title, List<VLCExtensionItem> items, boolean showParams, boolean isRefresh);
}
public void setExtensionManagerActivity(ExtensionManagerActivity activity) {
......@@ -239,12 +239,12 @@ public class ExtensionManagerService extends Service {
return new IExtensionHost.Stub(){
@Override
public void updateList(final String title, final List<VLCExtensionItem> items, final boolean showParams) throws RemoteException {
public void updateList(final String title, final List<VLCExtensionItem> items, final boolean showParams, final boolean isRefresh) throws RemoteException {
mHandler.post(new Runnable() {
@Override
public void run() {
if (mExtensionManagerActivity != null)
mExtensionManagerActivity.displayExtensionItems(title, items, showParams);
mExtensionManagerActivity.displayExtensionItems(title, items, showParams, isRefresh);
}
});
}
......
......@@ -468,25 +468,31 @@ public class MainActivity extends AudioPlayerContainerActivity implements Search
}
@Override
public void displayExtensionItems(String title, List<VLCExtensionItem> items, boolean showParams) {
ExtensionBrowser fragment = new ExtensionBrowser();
ArrayList<VLCExtensionItem> list = new ArrayList<>(items);
Bundle args = new Bundle();
args.putParcelableArrayList(ExtensionBrowser.KEY_ITEMS_LIST, list);
args.putBoolean(ExtensionBrowser.KEY_SHOW_FAB, showParams);
args.putString(ExtensionBrowser.KEY_TITLE, title);
fragment.setArguments(args);
fragment.setExtensionService(mExtensionManagerService);
public void displayExtensionItems(String title, List<VLCExtensionItem> items, boolean showParams, boolean refresh) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.setCustomAnimations(R.anim.anim_enter_right, 0, R.anim.anim_enter_left, 0);
ft.replace(R.id.fragment_placeholder, fragment, title);
if (!(fm.findFragmentById(R.id.fragment_placeholder) instanceof ExtensionBrowser))
ft.addToBackStack(getTag(mCurrentFragmentId));
else
ft.addToBackStack(title);
ft.commit();
if (refresh && fm.findFragmentById(R.id.fragment_placeholder) instanceof ExtensionBrowser) {
ExtensionBrowser browser = (ExtensionBrowser) fm.findFragmentById(R.id.fragment_placeholder);
browser.doRefresh(title, items);
} else {
ExtensionBrowser fragment = new ExtensionBrowser();
ArrayList<VLCExtensionItem> list = new ArrayList<>(items);
Bundle args = new Bundle();
args.putParcelableArrayList(ExtensionBrowser.KEY_ITEMS_LIST, list);
args.putBoolean(ExtensionBrowser.KEY_SHOW_FAB, showParams);
args.putString(ExtensionBrowser.KEY_TITLE, title);
fragment.setArguments(args);
fragment.setExtensionService(mExtensionManagerService);
FragmentTransaction ft = fm.beginTransaction();
ft.setCustomAnimations(R.anim.anim_enter_right, 0, R.anim.anim_enter_left, 0);
ft.replace(R.id.fragment_placeholder, fragment, title);
if (!(fm.findFragmentById(R.id.fragment_placeholder) instanceof ExtensionBrowser))
ft.addToBackStack(getTag(mCurrentFragmentId));
else
ft.addToBackStack(title);
ft.commit();
}
}
/**
......
......@@ -32,11 +32,12 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class ExtensionAdapter extends RecyclerView.Adapter<ExtensionAdapter.ViewHolder> {
ExtensionBrowser mFragment;
ArrayList<VLCExtensionItem> mItemsList = new ArrayList<>();
List<VLCExtensionItem> mItemsList = new ArrayList<>();
static HashMap<String, SoftReference<Bitmap>> iconsMap = new HashMap<>();
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener {
......@@ -171,7 +172,7 @@ public class ExtensionAdapter extends RecyclerView.Adapter<ExtensionAdapter.View
return mItemsList.get(position);
}
public ArrayList<VLCExtensionItem> getAll() {
public List<VLCExtensionItem> getAll() {
return mItemsList;
}
......@@ -180,7 +181,7 @@ public class ExtensionAdapter extends RecyclerView.Adapter<ExtensionAdapter.View
return mItemsList.size();
}
public void addAll(ArrayList<VLCExtensionItem> list) {
public void addAll(List<VLCExtensionItem> list) {
mItemsList.clear();
mItemsList.addAll(list);
notifyDataSetChanged();
......
......@@ -16,17 +16,18 @@ import android.widget.TextView;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.extensions.ExtensionListing;
import org.videolan.vlc.extensions.ExtensionManagerService;
import org.videolan.vlc.extensions.Utils;
import org.videolan.vlc.extensions.api.VLCExtensionItem;
import org.videolan.vlc.gui.view.ContextMenuRecyclerView;
import org.videolan.vlc.gui.view.DividerItemDecoration;
import org.videolan.vlc.gui.view.SwipeRefreshLayout;
import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.media.MediaWrapper;
import org.videolan.vlc.extensions.ExtensionListing;
import org.videolan.vlc.extensions.ExtensionManagerService;
import org.videolan.vlc.extensions.Utils;
import org.videolan.vlc.extensions.api.VLCExtensionItem;
import java.util.ArrayList;
import java.util.List;
public class ExtensionBrowser extends Fragment implements View.OnClickListener, android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener {
......@@ -92,12 +93,16 @@ public class ExtensionBrowser extends Fragment implements View.OnClickListener,
@Override
public void onStart() {
super.onStart();
setTitle(mTitle);
updateDisplay();
}
private void setTitle(String title) {
final AppCompatActivity activity = (AppCompatActivity)getActivity();
if (activity != null && activity.getSupportActionBar() != null) {
activity.getSupportActionBar().setTitle(mTitle);
activity.getSupportActionBar().setTitle(title);
getActivity().supportInvalidateOptionsMenu();
}
updateDisplay();
}
public void goBack(){
......@@ -107,6 +112,11 @@ public class ExtensionBrowser extends Fragment implements View.OnClickListener,
getActivity().getSupportFragmentManager().popBackStack();
}
public void doRefresh(String title, List<VLCExtensionItem> items) {
setTitle(title);
mAdapter.addAll(items);
}
private void updateDisplay() {
if (mAdapter.getItemCount() > 0) {
mEmptyView.setVisibility(View.GONE);
......@@ -182,7 +192,7 @@ public class ExtensionBrowser extends Fragment implements View.OnClickListener,
protected boolean handleContextItemSelected(MenuItem item, final int position) {
switch (item.getItemId()) {
case R.id.extension_item_view_play_all:
ArrayList<VLCExtensionItem> items = mAdapter.getAll();
List<VLCExtensionItem> items = mAdapter.getAll();
ArrayList<MediaWrapper> medias = new ArrayList<>(items.size());
for (VLCExtensionItem vlcItem : items) {
medias.add(Utils.mediawrapperFromExtension(vlcItem));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment