Prevent the refresh animation from appearing in a sylent sync
When a silent sync is running the refresh animation shouldn't appear and this wasn't being repected in some situations. For instance, when not connected to Kodi, starting from a TV Show details, selecting one episode or season and hitting back, the animation would appear. This PR makes sure that it is only shown if it isn't silent.
This commit is contained in:
parent
246693a7cc
commit
cda70ce109
|
@ -457,29 +457,28 @@ public class SyncUtils {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a running LibrarySyncService is syncing any given SyncType from a specific host
|
* Returns the first {@link SyncItem} of the given type that is currently
|
||||||
|
* syncing in a running {@link LibrarySyncService} for a specific host
|
||||||
* @param service running LibrarySyncService. Use {@link #connectToLibrarySyncService(Context, OnServiceListener)} to connect to a running LibrarySyncService
|
* @param service running LibrarySyncService. Use {@link #connectToLibrarySyncService(Context, OnServiceListener)} to connect to a running LibrarySyncService
|
||||||
* @param hostInfo host to check for sync items currently running or queued
|
* @param hostInfo host to check for sync items currently running or queued
|
||||||
* @param syncTypes sync types to check
|
* @param syncType sync type to check
|
||||||
* @return true if any of the given syncTypes is running or queued, false otherwise
|
* @return The first {@link SyncItem} of the given syncType if any is running or queued, null otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean isLibrarySyncing(LibrarySyncService service, HostInfo hostInfo, String... syncTypes) {
|
public static SyncItem getCurrentSyncItem(LibrarySyncService service, HostInfo hostInfo, String syncType) {
|
||||||
if (service == null || hostInfo == null || syncTypes == null)
|
if (service == null || hostInfo == null || syncType == null)
|
||||||
return false;
|
return null;
|
||||||
|
|
||||||
ArrayList<SyncItem> itemsSyncing = service.getItemsSyncing(hostInfo);
|
ArrayList<SyncItem> itemsSyncing = service.getItemsSyncing(hostInfo);
|
||||||
if( itemsSyncing == null )
|
if (itemsSyncing == null)
|
||||||
return false;
|
return null;
|
||||||
|
|
||||||
for (SyncItem syncItem : itemsSyncing) {
|
for (SyncItem syncItem : itemsSyncing) {
|
||||||
for( String syncType : syncTypes ) {
|
if (syncItem.getSyncType().equals(syncType)) {
|
||||||
if (syncItem.getSyncType().equals(syncType)) {
|
return syncItem;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,8 +46,10 @@ import org.xbmc.kore.host.HostManager;
|
||||||
import org.xbmc.kore.jsonrpc.ApiException;
|
import org.xbmc.kore.jsonrpc.ApiException;
|
||||||
import org.xbmc.kore.jsonrpc.event.MediaSyncEvent;
|
import org.xbmc.kore.jsonrpc.event.MediaSyncEvent;
|
||||||
import org.xbmc.kore.service.library.LibrarySyncService;
|
import org.xbmc.kore.service.library.LibrarySyncService;
|
||||||
|
import org.xbmc.kore.service.library.SyncItem;
|
||||||
import org.xbmc.kore.service.library.SyncUtils;
|
import org.xbmc.kore.service.library.SyncUtils;
|
||||||
import org.xbmc.kore.utils.LogUtils;
|
import org.xbmc.kore.utils.LogUtils;
|
||||||
|
import org.xbmc.kore.utils.UIUtils;
|
||||||
|
|
||||||
import de.greenrobot.event.EventBus;
|
import de.greenrobot.event.EventBus;
|
||||||
|
|
||||||
|
@ -217,7 +219,7 @@ public abstract class AbstractCursorListFragment extends AbstractListFragment
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
} else if (!silentSync) {
|
} else if (!silentSync) {
|
||||||
String msg = (event.errorCode == ApiException.API_ERROR) ?
|
String msg = (event.errorCode == ApiException.API_ERROR) ?
|
||||||
String.format(getString(R.string.error_while_syncing), event.errorMessage) :
|
String.format(getString(R.string.error_while_syncing), event.errorMessage) :
|
||||||
getString(R.string.unable_to_connect_to_xbmc);
|
getString(R.string.unable_to_connect_to_xbmc);
|
||||||
Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
|
||||||
|
@ -228,8 +230,12 @@ public abstract class AbstractCursorListFragment extends AbstractListFragment
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(LibrarySyncService librarySyncService) {
|
public void onServiceConnected(LibrarySyncService librarySyncService) {
|
||||||
HostInfo hostInfo = HostManager.getInstance(getActivity()).getHostInfo();
|
HostInfo hostInfo = HostManager.getInstance(getActivity()).getHostInfo();
|
||||||
if(SyncUtils.isLibrarySyncing(librarySyncService, hostInfo, getListSyncType())) {
|
SyncItem syncItem = SyncUtils.getCurrentSyncItem(librarySyncService, hostInfo, getListSyncType());
|
||||||
showRefreshAnimation();
|
if (syncItem != null) {
|
||||||
|
boolean silentRefresh = (syncItem.getSyncExtras() != null) &&
|
||||||
|
syncItem.getSyncExtras().getBoolean(LibrarySyncService.SILENT_SYNC, false);
|
||||||
|
if (!silentRefresh)
|
||||||
|
UIUtils.showRefreshAnimation(swipeRefreshLayout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +253,7 @@ public abstract class AbstractCursorListFragment extends AbstractListFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefresh() {
|
public void onRefresh() {
|
||||||
showRefreshAnimation();
|
UIUtils.showRefreshAnimation(swipeRefreshLayout);
|
||||||
Intent syncIntent = new Intent(this.getActivity(), LibrarySyncService.class);
|
Intent syncIntent = new Intent(this.getActivity(), LibrarySyncService.class);
|
||||||
syncIntent.putExtra(getListSyncType(), true);
|
syncIntent.putExtra(getListSyncType(), true);
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ import org.xbmc.kore.jsonrpc.ApiCallback;
|
||||||
import org.xbmc.kore.jsonrpc.method.Player;
|
import org.xbmc.kore.jsonrpc.method.Player;
|
||||||
import org.xbmc.kore.jsonrpc.type.PlaylistType;
|
import org.xbmc.kore.jsonrpc.type.PlaylistType;
|
||||||
import org.xbmc.kore.service.library.LibrarySyncService;
|
import org.xbmc.kore.service.library.LibrarySyncService;
|
||||||
|
import org.xbmc.kore.service.library.SyncItem;
|
||||||
import org.xbmc.kore.service.library.SyncUtils;
|
import org.xbmc.kore.service.library.SyncUtils;
|
||||||
import org.xbmc.kore.ui.generic.RefreshItem;
|
import org.xbmc.kore.ui.generic.RefreshItem;
|
||||||
import org.xbmc.kore.ui.widgets.fabspeeddial.FABSpeedDial;
|
import org.xbmc.kore.ui.widgets.fabspeeddial.FABSpeedDial;
|
||||||
|
@ -282,10 +283,14 @@ abstract public class AbstractInfoFragment extends AbstractFragment
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SyncUtils.isLibrarySyncing(librarySyncService,
|
SyncItem syncItem = SyncUtils.getCurrentSyncItem(librarySyncService,
|
||||||
HostManager.getInstance(getActivity()).getHostInfo(),
|
HostManager.getInstance(getActivity()).getHostInfo(),
|
||||||
refreshItem.getSyncType())) {
|
refreshItem.getSyncType());
|
||||||
UIUtils.showRefreshAnimation(swipeRefreshLayout);
|
if (syncItem != null) {
|
||||||
|
boolean silentRefresh = (syncItem.getSyncExtras() != null) &&
|
||||||
|
syncItem.getSyncExtras().getBoolean(LibrarySyncService.SILENT_SYNC, false);
|
||||||
|
if (!silentRefresh)
|
||||||
|
UIUtils.showRefreshAnimation(swipeRefreshLayout);
|
||||||
refreshItem.setSwipeRefreshLayout(swipeRefreshLayout);
|
refreshItem.setSwipeRefreshLayout(swipeRefreshLayout);
|
||||||
refreshItem.register();
|
refreshItem.register();
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ public abstract class AbstractListFragment extends Fragment implements
|
||||||
|
|
||||||
private boolean gridViewUsesMultipleColumns;
|
private boolean gridViewUsesMultipleColumns;
|
||||||
|
|
||||||
@InjectView(R.id.swipe_refresh_layout) SwipeRefreshLayout swipeRefreshLayout;
|
protected @InjectView(R.id.swipe_refresh_layout) SwipeRefreshLayout swipeRefreshLayout;
|
||||||
@InjectView(R.id.list) GridView gridView;
|
@InjectView(R.id.list) GridView gridView;
|
||||||
@InjectView(android.R.id.empty) TextView emptyView;
|
@InjectView(android.R.id.empty) TextView emptyView;
|
||||||
|
|
||||||
|
@ -175,19 +175,6 @@ public abstract class AbstractListFragment extends Fragment implements
|
||||||
adapter.notifyDataSetChanged(); //force gridView to redraw
|
adapter.notifyDataSetChanged(); //force gridView to redraw
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showRefreshAnimation() {
|
|
||||||
/**
|
|
||||||
* Fixes issue with refresh animation not showing when using appcompat library (from version 20?)
|
|
||||||
* See https://code.google.com/p/android/issues/detail?id=77712
|
|
||||||
*/
|
|
||||||
swipeRefreshLayout.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
swipeRefreshLayout.setRefreshing(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hideRefreshAnimation() {
|
public void hideRefreshAnimation() {
|
||||||
swipeRefreshLayout.setRefreshing(false);
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,8 @@ public class AddonListFragment extends AbstractListFragment {
|
||||||
private void callGetAddonsAndSetup() {
|
private void callGetAddonsAndSetup() {
|
||||||
final AddonsAdapter adapter = (AddonsAdapter) getAdapter();
|
final AddonsAdapter adapter = (AddonsAdapter) getAdapter();
|
||||||
|
|
||||||
showRefreshAnimation();
|
UIUtils.showRefreshAnimation(swipeRefreshLayout);
|
||||||
|
|
||||||
// Get the addon list, this is done asyhnchronously
|
// Get the addon list, this is done asyhnchronously
|
||||||
String[] properties = new String[] {
|
String[] properties = new String[] {
|
||||||
AddonType.Fields.NAME, AddonType.Fields.VERSION, AddonType.Fields.SUMMARY,
|
AddonType.Fields.NAME, AddonType.Fields.VERSION, AddonType.Fields.SUMMARY,
|
||||||
|
@ -141,51 +142,52 @@ public class AddonListFragment extends AbstractListFragment {
|
||||||
};
|
};
|
||||||
Addons.GetAddons action = new Addons.GetAddons(properties);
|
Addons.GetAddons action = new Addons.GetAddons(properties);
|
||||||
action.execute(HostManager.getInstance(getActivity()).getConnection(),
|
action.execute(HostManager.getInstance(getActivity()).getConnection(),
|
||||||
new ApiCallback<List<AddonType.Details>>() {
|
new ApiCallback<List<AddonType.Details>>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(List<AddonType.Details> result) {
|
public void onSuccess(List<AddonType.Details> result) {
|
||||||
if (!isAdded()) return;
|
if (!isAdded()) return;
|
||||||
|
|
||||||
for (AddonType.Details addon : result) {
|
for (AddonType.Details addon : result) {
|
||||||
String regex = "\\[.*?\\]";
|
String regex = "\\[.*?\\]";
|
||||||
addon.name = addon.name.replaceAll(regex, "");
|
addon.name = addon.name.replaceAll(regex, "");
|
||||||
addon.description = addon.description.replaceAll(regex, "");
|
addon.description = addon.description.replaceAll(regex, "");
|
||||||
addon.summary = addon.summary.replaceAll(regex, "");
|
addon.summary = addon.summary.replaceAll(regex, "");
|
||||||
addon.author = addon.author.replaceAll(regex, "");
|
addon.author = addon.author.replaceAll(regex, "");
|
||||||
}
|
}
|
||||||
Collections.sort(result, new AddonNameComparator());
|
Collections.sort(result, new AddonNameComparator());
|
||||||
|
|
||||||
adapter.clear();
|
adapter.clear();
|
||||||
for (AddonType.Details addon : result) {
|
for (AddonType.Details addon : result) {
|
||||||
if (addon.type.equals(AddonType.Types.UNKNOWN) ||
|
if (addon.type.equals(AddonType.Types.UNKNOWN) ||
|
||||||
addon.type.equals(AddonType.Types.XBMC_PYTHON_PLUGINSOURCE) ||
|
addon.type.equals(AddonType.Types.XBMC_PYTHON_PLUGINSOURCE) ||
|
||||||
addon.type.equals(AddonType.Types.XBMC_PYTHON_SCRIPT) ||
|
addon.type.equals(AddonType.Types.XBMC_PYTHON_SCRIPT) ||
|
||||||
addon.type.equals(AddonType.Types.XBMC_ADDON_AUDIO) ||
|
addon.type.equals(AddonType.Types.XBMC_ADDON_AUDIO) ||
|
||||||
addon.type.equals(AddonType.Types.XBMC_ADDON_EXECUTABLE) ||
|
addon.type.equals(AddonType.Types.XBMC_ADDON_EXECUTABLE) ||
|
||||||
addon.type.equals(AddonType.Types.XBMC_ADDON_VIDEO) ||
|
addon.type.equals(AddonType.Types.XBMC_ADDON_VIDEO) ||
|
||||||
addon.type.equals(AddonType.Types.XBMC_ADDON_IMAGE)) {
|
addon.type.equals(AddonType.Types.XBMC_ADDON_IMAGE)) {
|
||||||
adapter.add(addon);
|
adapter.add(addon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
hideRefreshAnimation();
|
hideRefreshAnimation();
|
||||||
|
|
||||||
if(adapter.getCount() == 0) {
|
if (adapter.getCount() == 0) {
|
||||||
getEmptyView().setText(R.string.no_addons_found_refresh);
|
getEmptyView().setText(R.string.no_addons_found_refresh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(int errorCode, String description) {
|
public void onError(int errorCode, String description) {
|
||||||
if (!isAdded()) return;
|
if (!isAdded()) return;
|
||||||
|
|
||||||
Toast.makeText(getActivity(),
|
Toast.makeText(getActivity(),
|
||||||
String.format(getString(R.string.error_getting_addon_info), description),
|
String.format(getString(R.string.error_getting_addon_info), description),
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
hideRefreshAnimation();
|
hideRefreshAnimation();
|
||||||
}
|
}
|
||||||
}, callbackHandler);
|
},
|
||||||
|
callbackHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AddonsAdapter extends ArrayAdapter<AddonType.Details> {
|
private class AddonsAdapter extends ArrayAdapter<AddonType.Details> {
|
||||||
|
|
Loading…
Reference in New Issue