Refactoring on Media list UI, for functions related with the Sync Service.
Removed AbstractMusicListFragment.java dur to the refactor
This commit is contained in:
parent
05d7cd5401
commit
80fb10e534
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.xbmc.kore.ui;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
|
@ -38,8 +39,11 @@ import android.widget.Toast;
|
|||
import org.xbmc.kore.R;
|
||||
import org.xbmc.kore.host.HostInfo;
|
||||
import org.xbmc.kore.host.HostManager;
|
||||
import org.xbmc.kore.jsonrpc.ApiException;
|
||||
import org.xbmc.kore.jsonrpc.event.MediaSyncEvent;
|
||||
import org.xbmc.kore.service.LibrarySyncService;
|
||||
import org.xbmc.kore.service.SyncUtils;
|
||||
import org.xbmc.kore.utils.LogUtils;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
|
@ -50,6 +54,7 @@ public abstract class AbstractListFragment extends Fragment
|
|||
SyncUtils.OnServiceListener,
|
||||
SearchView.OnQueryTextListener,
|
||||
SwipeRefreshLayout.OnRefreshListener {
|
||||
private static final String TAG = LogUtils.makeLogTag(AbstractListFragment.class);
|
||||
|
||||
private ServiceConnection serviceConnection;
|
||||
private CursorAdapter adapter;
|
||||
|
@ -71,15 +76,8 @@ public abstract class AbstractListFragment extends Fragment
|
|||
|
||||
abstract protected AdapterView.OnItemClickListener createOnItemClickListener();
|
||||
abstract protected CursorAdapter createAdapter();
|
||||
abstract protected void onSwipeRefresh();
|
||||
abstract protected CursorLoader createCursorLoader();
|
||||
|
||||
/**
|
||||
* Called each time a MediaSyncEvent is received.
|
||||
* @param event
|
||||
*/
|
||||
abstract protected void onSyncProcessEnded(MediaSyncEvent event);
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
@ -151,6 +149,13 @@ public abstract class AbstractListFragment extends Fragment
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Should return the {@link org.xbmc.kore.service.LibrarySyncService} SyncType that
|
||||
* this list initiates
|
||||
* @return {@link org.xbmc.kore.service.LibrarySyncService} SyncType
|
||||
*/
|
||||
abstract protected String getListSyncType();
|
||||
|
||||
/**
|
||||
* Event bus post. Called when the syncing process ended
|
||||
*
|
||||
|
@ -161,8 +166,53 @@ public abstract class AbstractListFragment extends Fragment
|
|||
}
|
||||
|
||||
/**
|
||||
* Search view callbacks
|
||||
* Called each time a MediaSyncEvent is received.
|
||||
* @param event
|
||||
*/
|
||||
protected void onSyncProcessEnded(MediaSyncEvent event) {
|
||||
boolean silentSync = false;
|
||||
if (event.syncExtras != null) {
|
||||
silentSync = event.syncExtras.getBoolean(LibrarySyncService.SILENT_SYNC, false);
|
||||
}
|
||||
|
||||
if (event.syncType.equals(getListSyncType())) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
if (event.status == MediaSyncEvent.STATUS_SUCCESS) {
|
||||
refreshList();
|
||||
if (!silentSync) {
|
||||
Toast.makeText(getActivity(), R.string.sync_successful, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
} else if (!silentSync) {
|
||||
String msg = (event.errorCode == ApiException.API_ERROR) ?
|
||||
String.format(getString(R.string.error_while_syncing), event.errorMessage) :
|
||||
getString(R.string.unable_to_connect_to_xbmc);
|
||||
Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(LibrarySyncService librarySyncService) {
|
||||
if(SyncUtils.isLibrarySyncing(
|
||||
librarySyncService,
|
||||
HostManager.getInstance(getActivity()).getHostInfo(),
|
||||
getListSyncType())) {
|
||||
showRefreshAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onSwipeRefresh() {
|
||||
LogUtils.LOGD(TAG, "Swipe, starting sync for: " + getListSyncType());
|
||||
// Start the syncing process
|
||||
Intent syncIntent = new Intent(this.getActivity(), LibrarySyncService.class);
|
||||
syncIntent.putExtra(getListSyncType(), true);
|
||||
getActivity().startService(syncIntent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search view callbacks
|
||||
*/
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Copyright 2015 Martijn Brekhof. 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.Intent;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.xbmc.kore.R;
|
||||
import org.xbmc.kore.host.HostManager;
|
||||
import org.xbmc.kore.jsonrpc.ApiException;
|
||||
import org.xbmc.kore.jsonrpc.event.MediaSyncEvent;
|
||||
import org.xbmc.kore.service.LibrarySyncService;
|
||||
import org.xbmc.kore.service.SyncUtils;
|
||||
import org.xbmc.kore.utils.UIUtils;
|
||||
|
||||
public abstract class AbstractMusicListFragment extends AbstractListFragment {
|
||||
@Override
|
||||
protected void onSwipeRefresh() {
|
||||
// Start the syncing process
|
||||
Intent syncIntent = new Intent(this.getActivity(), LibrarySyncService.class);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_ALL_MUSIC, true);
|
||||
getActivity().startService(syncIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSyncProcessEnded(MediaSyncEvent event) {
|
||||
if (event.syncType.equals(LibrarySyncService.SYNC_ALL_MUSIC)) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
if (event.status == MediaSyncEvent.STATUS_SUCCESS) {
|
||||
refreshList();
|
||||
Toast.makeText(getActivity(), R.string.sync_successful, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
} else {
|
||||
String msg = (event.errorCode == ApiException.API_ERROR) ?
|
||||
String.format(getString(R.string.error_while_syncing), event.errorMessage) :
|
||||
getString(R.string.unable_to_connect_to_xbmc);
|
||||
Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(LibrarySyncService librarySyncService) {
|
||||
if(SyncUtils.isLibrarySyncing(librarySyncService, HostManager.getInstance(getActivity()).getHostInfo(),
|
||||
LibrarySyncService.SYNC_ALL_MUSIC, LibrarySyncService.SYNC_ALL_MUSIC_VIDEOS)) {
|
||||
showRefreshAnimation();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,18 +17,13 @@ package org.xbmc.kore.ui;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.BaseColumns;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -39,17 +34,13 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.xbmc.kore.R;
|
||||
import org.xbmc.kore.host.HostInfo;
|
||||
import org.xbmc.kore.host.HostManager;
|
||||
import org.xbmc.kore.jsonrpc.ApiException;
|
||||
import org.xbmc.kore.jsonrpc.event.MediaSyncEvent;
|
||||
import org.xbmc.kore.jsonrpc.type.PlaylistType;
|
||||
import org.xbmc.kore.provider.MediaContract;
|
||||
import org.xbmc.kore.provider.MediaDatabase;
|
||||
|
@ -58,14 +49,10 @@ import org.xbmc.kore.utils.LogUtils;
|
|||
import org.xbmc.kore.utils.MediaPlayerUtils;
|
||||
import org.xbmc.kore.utils.UIUtils;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Fragment that presents the albums list
|
||||
*/
|
||||
public class AlbumListFragment extends AbstractMusicListFragment {
|
||||
public class AlbumListFragment extends AbstractListFragment {
|
||||
private static final String TAG = LogUtils.makeLogTag(AlbumListFragment.class);
|
||||
|
||||
public interface OnAlbumSelectedListener {
|
||||
|
@ -81,6 +68,8 @@ public class AlbumListFragment extends AbstractMusicListFragment {
|
|||
// Activity listener
|
||||
private OnAlbumSelectedListener listenerActivity;
|
||||
|
||||
@Override
|
||||
protected String getListSyncType() { return LibrarySyncService.SYNC_ALL_MUSIC; }
|
||||
|
||||
/**
|
||||
* Create a new instance of this, initialized to show albums of genres
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.xbmc.kore.host.HostManager;
|
|||
import org.xbmc.kore.jsonrpc.type.PlaylistType;
|
||||
import org.xbmc.kore.provider.MediaContract;
|
||||
import org.xbmc.kore.provider.MediaDatabase;
|
||||
import org.xbmc.kore.service.LibrarySyncService;
|
||||
import org.xbmc.kore.utils.LogUtils;
|
||||
import org.xbmc.kore.utils.MediaPlayerUtils;
|
||||
import org.xbmc.kore.utils.UIUtils;
|
||||
|
@ -50,7 +51,7 @@ import org.xbmc.kore.utils.UIUtils;
|
|||
/**
|
||||
* Fragment that presents the artists list
|
||||
*/
|
||||
public class ArtistListFragment extends AbstractMusicListFragment {
|
||||
public class ArtistListFragment extends AbstractListFragment {
|
||||
private static final String TAG = LogUtils.makeLogTag(ArtistListFragment.class);
|
||||
|
||||
public interface OnArtistSelectedListener {
|
||||
|
@ -60,6 +61,9 @@ public class ArtistListFragment extends AbstractMusicListFragment {
|
|||
// Activity listener
|
||||
private OnArtistSelectedListener listenerActivity;
|
||||
|
||||
@Override
|
||||
protected String getListSyncType() { return LibrarySyncService.SYNC_ALL_MUSIC; }
|
||||
|
||||
@Override
|
||||
protected AdapterView.OnItemClickListener createOnItemClickListener() {
|
||||
return new AdapterView.OnItemClickListener() {
|
||||
|
|
|
@ -17,18 +17,12 @@ package org.xbmc.kore.ui;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.BaseColumns;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -39,17 +33,13 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.xbmc.kore.R;
|
||||
import org.xbmc.kore.host.HostInfo;
|
||||
import org.xbmc.kore.host.HostManager;
|
||||
import org.xbmc.kore.jsonrpc.ApiException;
|
||||
import org.xbmc.kore.jsonrpc.event.MediaSyncEvent;
|
||||
import org.xbmc.kore.jsonrpc.type.PlaylistType;
|
||||
import org.xbmc.kore.provider.MediaContract;
|
||||
import org.xbmc.kore.service.LibrarySyncService;
|
||||
|
@ -57,14 +47,10 @@ import org.xbmc.kore.utils.LogUtils;
|
|||
import org.xbmc.kore.utils.MediaPlayerUtils;
|
||||
import org.xbmc.kore.utils.UIUtils;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Fragment that presents the album genres list
|
||||
*/
|
||||
public class AudioGenresListFragment extends AbstractMusicListFragment {
|
||||
public class AudioGenresListFragment extends AbstractListFragment {
|
||||
private static final String TAG = LogUtils.makeLogTag(AudioGenresListFragment.class);
|
||||
|
||||
public interface OnAudioGenreSelectedListener {
|
||||
|
@ -74,6 +60,9 @@ public class AudioGenresListFragment extends AbstractMusicListFragment {
|
|||
// Activity listener
|
||||
private OnAudioGenreSelectedListener listenerActivity;
|
||||
|
||||
@Override
|
||||
protected String getListSyncType() { return LibrarySyncService.SYNC_ALL_MUSIC; }
|
||||
|
||||
@Override
|
||||
protected AdapterView.OnItemClickListener createOnItemClickListener() {
|
||||
return new AdapterView.OnItemClickListener() {
|
||||
|
|
|
@ -17,7 +17,6 @@ package org.xbmc.kore.ui;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
|
@ -38,18 +37,14 @@ import android.widget.AdapterView;
|
|||
import android.widget.CursorAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.xbmc.kore.R;
|
||||
import org.xbmc.kore.Settings;
|
||||
import org.xbmc.kore.host.HostInfo;
|
||||
import org.xbmc.kore.host.HostManager;
|
||||
import org.xbmc.kore.jsonrpc.ApiException;
|
||||
import org.xbmc.kore.jsonrpc.event.MediaSyncEvent;
|
||||
import org.xbmc.kore.provider.MediaContract;
|
||||
import org.xbmc.kore.provider.MediaDatabase;
|
||||
import org.xbmc.kore.service.LibrarySyncService;
|
||||
import org.xbmc.kore.service.SyncUtils;
|
||||
import org.xbmc.kore.utils.LogUtils;
|
||||
import org.xbmc.kore.utils.UIUtils;
|
||||
|
||||
|
@ -66,6 +61,9 @@ public class MovieListFragment extends AbstractListFragment {
|
|||
// Activity listener
|
||||
private OnMovieSelectedListener listenerActivity;
|
||||
|
||||
@Override
|
||||
protected String getListSyncType() { return LibrarySyncService.SYNC_ALL_MOVIES; }
|
||||
|
||||
@Override
|
||||
protected AdapterView.OnItemClickListener createOnItemClickListener() {
|
||||
return new AdapterView.OnItemClickListener() {
|
||||
|
@ -84,13 +82,6 @@ public class MovieListFragment extends AbstractListFragment {
|
|||
return new MoviesAdapter(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSwipeRefresh() {
|
||||
Intent syncIntent = new Intent(this.getActivity(), LibrarySyncService.class);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_ALL_MOVIES, true);
|
||||
getActivity().startService(syncIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CursorLoader createCursorLoader() {
|
||||
HostInfo hostInfo = HostManager.getInstance(getActivity()).getHostInfo();
|
||||
|
@ -129,39 +120,6 @@ public class MovieListFragment extends AbstractListFragment {
|
|||
MovieListQuery.PROJECTION, selection.toString(), selectionArgs, sortOrderStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSyncProcessEnded(MediaSyncEvent event) {
|
||||
boolean silentSync = false;
|
||||
if (event.syncExtras != null) {
|
||||
silentSync = event.syncExtras.getBoolean(LibrarySyncService.SILENT_SYNC, false);
|
||||
}
|
||||
|
||||
if (event.syncType.equals(LibrarySyncService.SYNC_SINGLE_MOVIE) ||
|
||||
event.syncType.equals(LibrarySyncService.SYNC_ALL_MOVIES)) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
if (event.status == MediaSyncEvent.STATUS_SUCCESS) {
|
||||
refreshList();
|
||||
if (!silentSync) {
|
||||
Toast.makeText(getActivity(), R.string.sync_successful, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
} else if (!silentSync) {
|
||||
String msg = (event.errorCode == ApiException.API_ERROR) ?
|
||||
String.format(getString(R.string.error_while_syncing), event.errorMessage) :
|
||||
getString(R.string.unable_to_connect_to_xbmc);
|
||||
Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(LibrarySyncService librarySyncService) {
|
||||
if(SyncUtils.isLibrarySyncing(librarySyncService, HostManager.getInstance(getActivity()).getHostInfo(),
|
||||
LibrarySyncService.SYNC_ALL_MOVIES, LibrarySyncService.SYNC_SINGLE_MOVIE)) {
|
||||
showRefreshAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
|
|
@ -17,15 +17,12 @@ package org.xbmc.kore.ui;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.BaseColumns;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -38,17 +35,13 @@ import android.widget.AdapterView;
|
|||
import android.widget.CursorAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.xbmc.kore.R;
|
||||
import org.xbmc.kore.host.HostInfo;
|
||||
import org.xbmc.kore.host.HostManager;
|
||||
import org.xbmc.kore.jsonrpc.ApiException;
|
||||
import org.xbmc.kore.jsonrpc.event.MediaSyncEvent;
|
||||
import org.xbmc.kore.provider.MediaContract;
|
||||
import org.xbmc.kore.provider.MediaDatabase;
|
||||
import org.xbmc.kore.service.LibrarySyncService;
|
||||
import org.xbmc.kore.service.SyncUtils;
|
||||
import org.xbmc.kore.utils.LogUtils;
|
||||
import org.xbmc.kore.utils.UIUtils;
|
||||
|
||||
|
@ -65,6 +58,9 @@ public class MusicVideoListFragment extends AbstractListFragment {
|
|||
// Activity listener
|
||||
private OnMusicVideoSelectedListener listenerActivity;
|
||||
|
||||
@Override
|
||||
protected String getListSyncType() { return LibrarySyncService.SYNC_ALL_MUSIC_VIDEOS; }
|
||||
|
||||
@Override
|
||||
protected AdapterView.OnItemClickListener createOnItemClickListener() {
|
||||
return new AdapterView.OnItemClickListener() {
|
||||
|
@ -83,13 +79,6 @@ public class MusicVideoListFragment extends AbstractListFragment {
|
|||
return new MusicVideosAdapter(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSwipeRefresh() {
|
||||
Intent syncIntent = new Intent(this.getActivity(), LibrarySyncService.class);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_ALL_MUSIC_VIDEOS, true);
|
||||
getActivity().startService(syncIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CursorLoader createCursorLoader() {
|
||||
HostInfo hostInfo = HostManager.getInstance(getActivity()).getHostInfo();
|
||||
|
@ -107,31 +96,6 @@ public class MusicVideoListFragment extends AbstractListFragment {
|
|||
MusicVideosListQuery.PROJECTION, selection, selectionArgs, MusicVideosListQuery.SORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSyncProcessEnded(MediaSyncEvent event) {
|
||||
if (event.syncType.equals(LibrarySyncService.SYNC_ALL_MUSIC_VIDEOS)) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
if (event.status == MediaSyncEvent.STATUS_SUCCESS) {
|
||||
refreshList();
|
||||
Toast.makeText(getActivity(), R.string.sync_successful, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
} else {
|
||||
String msg = (event.errorCode == ApiException.API_ERROR) ?
|
||||
String.format(getString(R.string.error_while_syncing), event.errorMessage) :
|
||||
getString(R.string.unable_to_connect_to_xbmc);
|
||||
Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(LibrarySyncService librarySyncService) {
|
||||
if(SyncUtils.isLibrarySyncing(librarySyncService, HostManager.getInstance(getActivity()).getHostInfo(),
|
||||
LibrarySyncService.SYNC_ALL_MUSIC_VIDEOS)) {
|
||||
showRefreshAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
|
|
@ -17,20 +17,14 @@ package org.xbmc.kore.ui;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.BaseColumns;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -41,28 +35,19 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.xbmc.kore.R;
|
||||
import org.xbmc.kore.Settings;
|
||||
import org.xbmc.kore.host.HostInfo;
|
||||
import org.xbmc.kore.host.HostManager;
|
||||
import org.xbmc.kore.jsonrpc.ApiException;
|
||||
import org.xbmc.kore.jsonrpc.event.MediaSyncEvent;
|
||||
import org.xbmc.kore.provider.MediaContract;
|
||||
import org.xbmc.kore.provider.MediaDatabase;
|
||||
import org.xbmc.kore.service.LibrarySyncService;
|
||||
import org.xbmc.kore.service.SyncUtils;
|
||||
import org.xbmc.kore.utils.LogUtils;
|
||||
import org.xbmc.kore.utils.UIUtils;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Fragment that presents the tv show list
|
||||
*/
|
||||
|
@ -76,6 +61,9 @@ public class TVShowListFragment extends AbstractListFragment {
|
|||
// Activity listener
|
||||
private OnTVShowSelectedListener listenerActivity;
|
||||
|
||||
@Override
|
||||
protected String getListSyncType() { return LibrarySyncService.SYNC_ALL_TVSHOWS; }
|
||||
|
||||
@Override
|
||||
protected AdapterView.OnItemClickListener createOnItemClickListener() {
|
||||
return new AdapterView.OnItemClickListener() {
|
||||
|
@ -94,13 +82,6 @@ public class TVShowListFragment extends AbstractListFragment {
|
|||
return new TVShowsAdapter(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSwipeRefresh() {
|
||||
Intent syncIntent = new Intent(this.getActivity(), LibrarySyncService.class);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_ALL_TVSHOWS, true);
|
||||
getActivity().startService(syncIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CursorLoader createCursorLoader() {
|
||||
HostInfo hostInfo = HostManager.getInstance(getActivity()).getHostInfo();
|
||||
|
@ -143,39 +124,6 @@ public class TVShowListFragment extends AbstractListFragment {
|
|||
selectionArgs, sortOrderStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSyncProcessEnded(MediaSyncEvent event) {
|
||||
boolean silentSync = false;
|
||||
if (event.syncExtras != null) {
|
||||
silentSync = event.syncExtras.getBoolean(LibrarySyncService.SILENT_SYNC, false);
|
||||
}
|
||||
|
||||
if (event.syncType.equals(LibrarySyncService.SYNC_SINGLE_TVSHOW) ||
|
||||
event.syncType.equals(LibrarySyncService.SYNC_ALL_TVSHOWS)) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
if (event.status == MediaSyncEvent.STATUS_SUCCESS) {
|
||||
refreshList();
|
||||
if (!silentSync) {
|
||||
Toast.makeText(getActivity(), R.string.sync_successful, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
} else if (!silentSync) {
|
||||
String msg = (event.errorCode == ApiException.API_ERROR) ?
|
||||
String.format(getString(R.string.error_while_syncing), event.errorMessage) :
|
||||
getString(R.string.unable_to_connect_to_xbmc);
|
||||
Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(LibrarySyncService librarySyncService) {
|
||||
if(SyncUtils.isLibrarySyncing(librarySyncService, HostManager.getInstance(getActivity()).getHostInfo(),
|
||||
LibrarySyncService.SYNC_ALL_TVSHOWS, LibrarySyncService.SYNC_SINGLE_TVSHOW)) {
|
||||
showRefreshAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
|
Loading…
Reference in New Issue