Introduces new class AbstractDetailsFragment to reduce code duplication.
* Moved showRefreshAnimation() from AbstractListFragment to UIUtils as it is now used for detailed fragments as well.
This commit is contained in:
parent
cc3ecdd5f5
commit
2f0dd67761
|
@ -0,0 +1,217 @@
|
|||
/*
|
||||
* 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.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
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.utils.LogUtils;
|
||||
import org.xbmc.kore.utils.UIUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
abstract public class AbstractDetailsFragment extends Fragment
|
||||
implements SwipeRefreshLayout.OnRefreshListener {
|
||||
private static final String TAG = LogUtils.makeLogTag(AbstractDetailsFragment.class);
|
||||
|
||||
private HostManager hostManager;
|
||||
private HostInfo hostInfo;
|
||||
private EventBus bus;
|
||||
private String syncType;
|
||||
|
||||
private SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
||||
abstract protected View createView(LayoutInflater inflater, ViewGroup container);
|
||||
|
||||
/**
|
||||
* Should return {@link org.xbmc.kore.service.LibrarySyncService} SyncType that
|
||||
* this fragment initiates
|
||||
* @return {@link org.xbmc.kore.service.LibrarySyncService} SyncType
|
||||
*/
|
||||
abstract protected String getSyncType();
|
||||
|
||||
/**
|
||||
* Should return the {@link org.xbmc.kore.service.LibrarySyncService} syncID if this fragment
|
||||
* synchronizes a single item. The itemId that should be synced must returned by {@link #getSyncItemID()}
|
||||
* @return {@link org.xbmc.kore.service.LibrarySyncService} SyncID
|
||||
*/
|
||||
abstract protected String getSyncID();
|
||||
|
||||
/**
|
||||
* Should return the item ID for SyncID returned by {@link #getSyncID()}
|
||||
* @return -1 if not used.
|
||||
*/
|
||||
abstract protected int getSyncItemID();
|
||||
|
||||
/**
|
||||
* Should return the SwipeRefreshLayout if the fragment's view uses one.
|
||||
* Used to notify the user if a sync for synctype returned by {@link #getSyncType()}
|
||||
* is currently in progress
|
||||
* @return
|
||||
*/
|
||||
abstract protected SwipeRefreshLayout getSwipeRefreshLayout();
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
bus = EventBus.getDefault();
|
||||
hostManager = HostManager.getInstance(getActivity());
|
||||
hostInfo = hostManager.getHostInfo();
|
||||
syncType = getSyncType();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@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;
|
||||
}
|
||||
|
||||
View view = createView(inflater, container);
|
||||
if( view != null ) {
|
||||
swipeRefreshLayout = getSwipeRefreshLayout();
|
||||
if( swipeRefreshLayout != null ) {
|
||||
swipeRefreshLayout.setOnRefreshListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
bus.register(this);
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
bus.unregister(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
// outState.putInt(ITEMID, itemId);
|
||||
}
|
||||
|
||||
protected void startSync(boolean silentRefresh) {
|
||||
if (getHostInfo() != null) {
|
||||
if( ( swipeRefreshLayout != null ) && ( ! silentRefresh ) ){
|
||||
UIUtils.showRefreshAnimation(swipeRefreshLayout);
|
||||
}
|
||||
// Start the syncing process
|
||||
Intent syncIntent = new Intent(this.getActivity(), LibrarySyncService.class);
|
||||
|
||||
if(syncType != null) {
|
||||
syncIntent.putExtra(syncType, true);
|
||||
}
|
||||
|
||||
String syncID = getSyncID();
|
||||
int itemId = getSyncItemID();
|
||||
if( ( syncID != null ) && ( itemId != -1 ) ) {
|
||||
syncIntent.putExtra(syncID, itemId);
|
||||
}
|
||||
|
||||
Bundle syncExtras = new Bundle();
|
||||
syncExtras.putBoolean(LibrarySyncService.SILENT_SYNC, silentRefresh);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_EXTRAS, syncExtras);
|
||||
|
||||
getActivity().startService(syncIntent);
|
||||
} else {
|
||||
if( swipeRefreshLayout != null ) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
Toast.makeText(getActivity(), R.string.no_xbmc_configured, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Swipe refresh layout callback
|
||||
*/
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void onRefresh () {
|
||||
startSync(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event bus post. Called when the syncing process ended
|
||||
*
|
||||
* @param event Refreshes data
|
||||
*/
|
||||
public void onEventMainThread(MediaSyncEvent event) {
|
||||
if ((syncType == null) || (! event.syncType.equals(syncType)))
|
||||
return;
|
||||
|
||||
boolean silentSync = false;
|
||||
if (event.syncExtras != null) {
|
||||
silentSync = event.syncExtras.getBoolean(LibrarySyncService.SILENT_SYNC, false);
|
||||
}
|
||||
|
||||
|
||||
if( swipeRefreshLayout != null ) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
onSyncProcessEnded(event);
|
||||
if (event.status == MediaSyncEvent.STATUS_SUCCESS) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when sync process for type set through {@link #getSyncType()} ends
|
||||
* @param event
|
||||
*/
|
||||
abstract protected void onSyncProcessEnded(MediaSyncEvent event);
|
||||
|
||||
protected HostManager getHostManager() {
|
||||
return hostManager;
|
||||
}
|
||||
|
||||
protected HostInfo getHostInfo() {
|
||||
return hostInfo;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,6 @@ package org.xbmc.kore.ui;
|
|||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.Cursor;
|
||||
|
@ -26,7 +25,6 @@ import android.os.Bundle;
|
|||
import android.os.Handler;
|
||||
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;
|
||||
|
@ -37,7 +35,6 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.Button;
|
||||
import android.widget.GridLayout;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
|
@ -49,10 +46,7 @@ import com.melnykov.fab.FloatingActionButton;
|
|||
import com.melnykov.fab.ObservableScrollView;
|
||||
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.ApiCallback;
|
||||
import org.xbmc.kore.jsonrpc.ApiException;
|
||||
import org.xbmc.kore.jsonrpc.event.MediaSyncEvent;
|
||||
import org.xbmc.kore.jsonrpc.method.Player;
|
||||
import org.xbmc.kore.jsonrpc.method.Playlist;
|
||||
|
@ -68,19 +62,16 @@ import org.xbmc.kore.utils.Utils;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import butterknife.OnClick;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Presents movie details
|
||||
*/
|
||||
public class MovieDetailsFragment extends Fragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor>,
|
||||
SwipeRefreshLayout.OnRefreshListener {
|
||||
public class MovieDetailsFragment extends AbstractDetailsFragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
private static final String TAG = LogUtils.makeLogTag(MovieDetailsFragment.class);
|
||||
|
||||
public static final String MOVIEID = "movie_id";
|
||||
|
@ -89,10 +80,6 @@ public class MovieDetailsFragment extends Fragment
|
|||
private static final int LOADER_MOVIE = 0,
|
||||
LOADER_CAST = 1;
|
||||
|
||||
private HostManager hostManager;
|
||||
private HostInfo hostInfo;
|
||||
private EventBus bus;
|
||||
|
||||
/**
|
||||
* Handler on which to post RPC callbacks
|
||||
*/
|
||||
|
@ -152,27 +139,17 @@ public class MovieDetailsFragment extends Fragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
protected View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
movieId = getArguments().getInt(MOVIEID, -1);
|
||||
|
||||
if ((container == null) || (movieId == -1)) {
|
||||
// We're not being shown or there's nothing to show
|
||||
if (movieId == -1) {
|
||||
// There's nothing to show
|
||||
return null;
|
||||
}
|
||||
|
||||
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_movie_details, container, false);
|
||||
ButterKnife.inject(this, root);
|
||||
|
||||
bus = EventBus.getDefault();
|
||||
hostManager = HostManager.getInstance(getActivity());
|
||||
hostInfo = hostManager.getHostInfo();
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(this);
|
||||
//UIUtils.setSwipeRefreshLayoutColorScheme(swipeRefreshLayout);
|
||||
|
||||
// Setup dim the fanart when scroll changes. Full dim on 4 * iconSize dp
|
||||
|
@ -197,6 +174,26 @@ public class MovieDetailsFragment extends Fragment
|
|||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSyncType() {
|
||||
return LibrarySyncService.SYNC_SINGLE_MOVIE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSyncID() {
|
||||
return LibrarySyncService.SYNC_MOVIEID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSyncItemID() {
|
||||
return movieId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SwipeRefreshLayout getSwipeRefreshLayout() {
|
||||
return swipeRefreshLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated (Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
@ -212,80 +209,16 @@ public class MovieDetailsFragment extends Fragment
|
|||
|
||||
@Override
|
||||
public void onResume() {
|
||||
bus.register(this);
|
||||
// Force the exit view to invisible
|
||||
exitTransitionView.setVisibility(View.INVISIBLE);
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
bus.unregister(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
// outState.putInt(MOVIEID, movieId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Swipe refresh layout callback
|
||||
*/
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void onRefresh () {
|
||||
if (hostInfo != null) {
|
||||
startSync(false);
|
||||
} else {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
Toast.makeText(getActivity(), R.string.no_xbmc_configured, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
private void startSync(boolean silentRefresh) {
|
||||
// Start the syncing process
|
||||
Intent syncIntent = new Intent(this.getActivity(), LibrarySyncService.class);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_SINGLE_MOVIE, true);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_MOVIEID, movieId);
|
||||
|
||||
Bundle syncExtras = new Bundle();
|
||||
syncExtras.putBoolean(LibrarySyncService.SILENT_SYNC, silentRefresh);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_EXTRAS, syncExtras);
|
||||
|
||||
getActivity().startService(syncIntent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event bus post. Called when the syncing process ended
|
||||
*
|
||||
* @param event Refreshes data
|
||||
*/
|
||||
public void onEventMainThread(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) {
|
||||
getLoaderManager().restartLoader(LOADER_MOVIE, null, this);
|
||||
getLoaderManager().restartLoader(LOADER_CAST, null, this);
|
||||
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();
|
||||
}
|
||||
protected void onSyncProcessEnded(MediaSyncEvent event) {
|
||||
if (event.status == MediaSyncEvent.STATUS_SUCCESS) {
|
||||
getLoaderManager().restartLoader(LOADER_MOVIE, null, this);
|
||||
getLoaderManager().restartLoader(LOADER_CAST, null, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,11 +231,11 @@ public class MovieDetailsFragment extends Fragment
|
|||
Uri uri;
|
||||
switch (i) {
|
||||
case LOADER_MOVIE:
|
||||
uri = MediaContract.Movies.buildMovieUri(hostInfo.getId(), movieId);
|
||||
uri = MediaContract.Movies.buildMovieUri(getHostInfo().getId(), movieId);
|
||||
return new CursorLoader(getActivity(), uri,
|
||||
MovieDetailsQuery.PROJECTION, null, null, null);
|
||||
case LOADER_CAST:
|
||||
uri = MediaContract.MovieCast.buildMovieCastListUri(hostInfo.getId(), movieId);
|
||||
uri = MediaContract.MovieCast.buildMovieCastListUri(getHostInfo().getId(), movieId);
|
||||
return new CursorLoader(getActivity(), uri,
|
||||
MovieCastListQuery.PROJECTION, null, null, MovieCastListQuery.SORT);
|
||||
default:
|
||||
|
@ -340,7 +273,7 @@ public class MovieDetailsFragment extends Fragment
|
|||
PlaylistType.Item item = new PlaylistType.Item();
|
||||
item.movieid = movieId;
|
||||
Player.Open action = new Player.Open(item);
|
||||
action.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
||||
action.execute(getHostManager().getConnection(), new ApiCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
if (!isAdded()) return;
|
||||
|
@ -361,7 +294,7 @@ public class MovieDetailsFragment extends Fragment
|
|||
if (!isAdded()) return;
|
||||
// Got an error, show toast
|
||||
Toast.makeText(getActivity(), R.string.unable_to_connect_to_xbmc, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
.show();
|
||||
}
|
||||
}, callbackHandler);
|
||||
}
|
||||
|
@ -370,7 +303,7 @@ public class MovieDetailsFragment extends Fragment
|
|||
public void onAddToPlaylistClicked(View v) {
|
||||
Playlist.GetPlaylists getPlaylists = new Playlist.GetPlaylists();
|
||||
|
||||
getPlaylists.execute(hostManager.getConnection(), new ApiCallback<ArrayList<PlaylistType.GetPlaylistsReturnType>>() {
|
||||
getPlaylists.execute(getHostManager().getConnection(), new ApiCallback<ArrayList<PlaylistType.GetPlaylistsReturnType>>() {
|
||||
@Override
|
||||
public void onSuccess(ArrayList<PlaylistType.GetPlaylistsReturnType> result) {
|
||||
if (!isAdded()) return;
|
||||
|
@ -387,13 +320,13 @@ public class MovieDetailsFragment extends Fragment
|
|||
PlaylistType.Item item = new PlaylistType.Item();
|
||||
item.movieid = movieId;
|
||||
Playlist.Add action = new Playlist.Add(videoPlaylistId, item);
|
||||
action.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
||||
action.execute(getHostManager().getConnection(), new ApiCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
if (!isAdded()) return;
|
||||
// Got an error, show toast
|
||||
Toast.makeText(getActivity(), R.string.item_added_to_playlist, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -401,12 +334,12 @@ public class MovieDetailsFragment extends Fragment
|
|||
if (!isAdded()) return;
|
||||
// Got an error, show toast
|
||||
Toast.makeText(getActivity(), R.string.unable_to_connect_to_xbmc, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
.show();
|
||||
}
|
||||
}, callbackHandler);
|
||||
} else {
|
||||
Toast.makeText(getActivity(), R.string.no_suitable_playlist, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -415,7 +348,7 @@ public class MovieDetailsFragment extends Fragment
|
|||
if (!isAdded()) return;
|
||||
// Got an error, show toast
|
||||
Toast.makeText(getActivity(), R.string.unable_to_connect_to_xbmc, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
.show();
|
||||
}
|
||||
}, callbackHandler);
|
||||
}
|
||||
|
@ -437,7 +370,7 @@ public class MovieDetailsFragment extends Fragment
|
|||
|
||||
VideoLibrary.SetMovieDetails action =
|
||||
new VideoLibrary.SetMovieDetails(movieId, newPlaycount, null);
|
||||
action.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
||||
action.execute(getHostManager().getConnection(), new ApiCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
if (!isAdded()) return;
|
||||
|
@ -473,27 +406,27 @@ public class MovieDetailsFragment extends Fragment
|
|||
if (file.exists()) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.download)
|
||||
.setMessage(R.string.download_file_exists)
|
||||
.setPositiveButton(R.string.overwrite,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FileDownloadHelper.downloadFiles(getActivity(), hostInfo,
|
||||
movieDownloadInfo, FileDownloadHelper.OVERWRITE_FILES,
|
||||
callbackHandler);
|
||||
}
|
||||
})
|
||||
.setNeutralButton(R.string.download_with_new_name,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FileDownloadHelper.downloadFiles(getActivity(), hostInfo,
|
||||
movieDownloadInfo, FileDownloadHelper.DOWNLOAD_WITH_NEW_NAME,
|
||||
callbackHandler);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, noopClickListener)
|
||||
.show();
|
||||
.setMessage(R.string.download_file_exists)
|
||||
.setPositiveButton(R.string.overwrite,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FileDownloadHelper.downloadFiles(getActivity(), getHostInfo(),
|
||||
movieDownloadInfo, FileDownloadHelper.OVERWRITE_FILES,
|
||||
callbackHandler);
|
||||
}
|
||||
})
|
||||
.setNeutralButton(R.string.download_with_new_name,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FileDownloadHelper.downloadFiles(getActivity(), getHostInfo(),
|
||||
movieDownloadInfo, FileDownloadHelper.DOWNLOAD_WITH_NEW_NAME,
|
||||
callbackHandler);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, noopClickListener)
|
||||
.show();
|
||||
} else {
|
||||
// Confirm that the user really wants to download the file
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
|
@ -503,7 +436,7 @@ public class MovieDetailsFragment extends Fragment
|
|||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FileDownloadHelper.downloadFiles(getActivity(), hostInfo,
|
||||
FileDownloadHelper.downloadFiles(getActivity(), getHostInfo(),
|
||||
movieDownloadInfo, FileDownloadHelper.OVERWRITE_FILES,
|
||||
callbackHandler);
|
||||
}
|
||||
|
@ -527,9 +460,9 @@ public class MovieDetailsFragment extends Fragment
|
|||
|
||||
int runtime = cursor.getInt(MovieDetailsQuery.RUNTIME) / 60;
|
||||
String durationYear = runtime > 0 ?
|
||||
String.format(getString(R.string.minutes_abbrev), String.valueOf(runtime)) +
|
||||
" | " + String.valueOf(cursor.getInt(MovieDetailsQuery.YEAR)) :
|
||||
String.valueOf(cursor.getInt(MovieDetailsQuery.YEAR));
|
||||
String.format(getString(R.string.minutes_abbrev), String.valueOf(runtime)) +
|
||||
" | " + String.valueOf(cursor.getInt(MovieDetailsQuery.YEAR)) :
|
||||
String.valueOf(cursor.getInt(MovieDetailsQuery.YEAR));
|
||||
mediaYear.setText(durationYear);
|
||||
mediaGenres.setText(cursor.getString(MovieDetailsQuery.GENRES));
|
||||
|
||||
|
@ -542,7 +475,7 @@ public class MovieDetailsFragment extends Fragment
|
|||
mediaMaxRating.setText(getString(R.string.max_rating_video));
|
||||
String votes = cursor.getString(MovieDetailsQuery.VOTES);
|
||||
mediaRatingVotes.setText((TextUtils.isEmpty(votes)) ?
|
||||
"" : String.format(getString(R.string.votes), votes));
|
||||
"" : String.format(getString(R.string.votes), votes));
|
||||
} else {
|
||||
mediaRating.setVisibility(View.INVISIBLE);
|
||||
mediaMaxRating.setVisibility(View.INVISIBLE);
|
||||
|
@ -564,11 +497,11 @@ public class MovieDetailsFragment extends Fragment
|
|||
|
||||
int posterWidth = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_width);
|
||||
int posterHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_height);
|
||||
UIUtils.loadImageWithCharacterAvatar(getActivity(), hostManager,
|
||||
UIUtils.loadImageWithCharacterAvatar(getActivity(), getHostManager(),
|
||||
cursor.getString(MovieDetailsQuery.THUMBNAIL), movieTitle,
|
||||
mediaPoster, posterWidth, posterHeight);
|
||||
int artHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_art_height);
|
||||
UIUtils.loadImageIntoImageview(hostManager,
|
||||
UIUtils.loadImageIntoImageview(getHostManager(),
|
||||
cursor.getString(MovieDetailsQuery.FANART),
|
||||
mediaArt, displayMetrics.widthPixels, artHeight);
|
||||
|
||||
|
@ -619,13 +552,13 @@ public class MovieDetailsFragment extends Fragment
|
|||
castArrayList = new ArrayList<VideoType.Cast>(cursor.getCount());
|
||||
do {
|
||||
castArrayList.add(new VideoType.Cast(cursor.getString(MovieCastListQuery.NAME),
|
||||
cursor.getInt(MovieCastListQuery.ORDER),
|
||||
cursor.getString(MovieCastListQuery.ROLE),
|
||||
cursor.getString(MovieCastListQuery.THUMBNAIL)));
|
||||
cursor.getInt(MovieCastListQuery.ORDER),
|
||||
cursor.getString(MovieCastListQuery.ROLE),
|
||||
cursor.getString(MovieCastListQuery.THUMBNAIL)));
|
||||
} while (cursor.moveToNext());
|
||||
|
||||
UIUtils.setupCastInfo(getActivity(), castArrayList, videoCastList,
|
||||
AllCastActivity.buildLaunchIntent(getActivity(), movieTitle, castArrayList));
|
||||
AllCastActivity.buildLaunchIntent(getActivity(), movieTitle, castArrayList));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ package org.xbmc.kore.ui;
|
|||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.Cursor;
|
||||
|
@ -26,7 +25,6 @@ import android.os.Bundle;
|
|||
import android.os.Handler;
|
||||
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;
|
||||
|
@ -47,10 +45,7 @@ import com.melnykov.fab.FloatingActionButton;
|
|||
import com.melnykov.fab.ObservableScrollView;
|
||||
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.ApiCallback;
|
||||
import org.xbmc.kore.jsonrpc.ApiException;
|
||||
import org.xbmc.kore.jsonrpc.event.MediaSyncEvent;
|
||||
import org.xbmc.kore.jsonrpc.method.Player;
|
||||
import org.xbmc.kore.jsonrpc.method.Playlist;
|
||||
|
@ -67,14 +62,12 @@ import java.util.ArrayList;
|
|||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import butterknife.OnClick;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Presents music videos details
|
||||
*/
|
||||
public class MusicVideoDetailsFragment extends Fragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor>,
|
||||
SwipeRefreshLayout.OnRefreshListener {
|
||||
public class MusicVideoDetailsFragment extends AbstractDetailsFragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
private static final String TAG = LogUtils.makeLogTag(MusicVideoDetailsFragment.class);
|
||||
|
||||
public static final String MUSICVIDEOID = "music_video_id";
|
||||
|
@ -82,10 +75,6 @@ public class MusicVideoDetailsFragment extends Fragment
|
|||
// Loader IDs
|
||||
private static final int LOADER_MUSIC_VIDEO = 0;
|
||||
|
||||
private HostManager hostManager;
|
||||
private HostInfo hostInfo;
|
||||
private EventBus bus;
|
||||
|
||||
/**
|
||||
* Handler on which to post RPC callbacks
|
||||
*/
|
||||
|
@ -135,27 +124,17 @@ public class MusicVideoDetailsFragment extends Fragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
protected View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
musicVideoId = getArguments().getInt(MUSICVIDEOID, -1);
|
||||
|
||||
if ((container == null) || (musicVideoId == -1)) {
|
||||
// We're not being shown or there's nothing to show
|
||||
if (musicVideoId == -1) {
|
||||
// There's nothing to show
|
||||
return null;
|
||||
}
|
||||
|
||||
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_music_video_details, container, false);
|
||||
ButterKnife.inject(this, root);
|
||||
|
||||
bus = EventBus.getDefault();
|
||||
hostManager = HostManager.getInstance(getActivity());
|
||||
hostInfo = hostManager.getHostInfo();
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(this);
|
||||
//UIUtils.setSwipeRefreshLayoutColorScheme(swipeRefreshLayout);
|
||||
|
||||
// Setup dim the fanart when scroll changes. Full dim on 4 * iconSize dp
|
||||
|
@ -180,6 +159,26 @@ public class MusicVideoDetailsFragment extends Fragment
|
|||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSyncType() {
|
||||
return LibrarySyncService.SYNC_ALL_MUSIC_VIDEOS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSyncID() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSyncItemID() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SwipeRefreshLayout getSwipeRefreshLayout() {
|
||||
return swipeRefreshLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated (Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
@ -192,65 +191,15 @@ public class MusicVideoDetailsFragment extends Fragment
|
|||
|
||||
@Override
|
||||
public void onResume() {
|
||||
bus.register(this);
|
||||
// Force the exit view to invisible
|
||||
exitTransitionView.setVisibility(View.INVISIBLE);
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
bus.unregister(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
// outState.putInt(MUSICVIDEOID, musicVideoId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Swipe refresh layout callback
|
||||
*/
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void onRefresh () {
|
||||
if (hostInfo != null) {
|
||||
// Start the syncing process
|
||||
Intent syncIntent = new Intent(this.getActivity(), LibrarySyncService.class);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_ALL_MUSIC_VIDEOS, true);
|
||||
getActivity().startService(syncIntent);
|
||||
} else {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
Toast.makeText(getActivity(), R.string.no_xbmc_configured, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event bus post. Called when the syncing process ended
|
||||
*
|
||||
* @param event Refreshes data
|
||||
*/
|
||||
public void onEventMainThread(MediaSyncEvent event) {
|
||||
if (event.syncType.equals(LibrarySyncService.SYNC_ALL_MUSIC_VIDEOS)) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
if (event.status == MediaSyncEvent.STATUS_SUCCESS) {
|
||||
getLoaderManager().restartLoader(LOADER_MUSIC_VIDEO, null, this);
|
||||
if (showRefreshStatusMessage) {
|
||||
Toast.makeText(getActivity(),
|
||||
R.string.sync_successful, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
} else if (showRefreshStatusMessage) {
|
||||
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();
|
||||
}
|
||||
// Reset
|
||||
showRefreshStatusMessage = true;
|
||||
protected void onSyncProcessEnded(MediaSyncEvent event) {
|
||||
if (event.status == MediaSyncEvent.STATUS_SUCCESS) {
|
||||
getLoaderManager().restartLoader(LOADER_MUSIC_VIDEO, null, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,7 +212,7 @@ public class MusicVideoDetailsFragment extends Fragment
|
|||
Uri uri;
|
||||
switch (i) {
|
||||
case LOADER_MUSIC_VIDEO:
|
||||
uri = MediaContract.MusicVideos.buildMusicVideoUri(hostInfo.getId(), musicVideoId);
|
||||
uri = MediaContract.MusicVideos.buildMusicVideoUri(getHostInfo().getId(), musicVideoId);
|
||||
return new CursorLoader(getActivity(), uri,
|
||||
MusicVideoDetailsQuery.PROJECTION, null, null, null);
|
||||
default:
|
||||
|
@ -297,7 +246,7 @@ public class MusicVideoDetailsFragment extends Fragment
|
|||
PlaylistType.Item item = new PlaylistType.Item();
|
||||
item.musicvideoid = musicVideoId;
|
||||
Player.Open action = new Player.Open(item);
|
||||
action.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
||||
action.execute(getHostManager().getConnection(), new ApiCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
if (!isAdded()) return;
|
||||
|
@ -318,7 +267,7 @@ public class MusicVideoDetailsFragment extends Fragment
|
|||
if (!isAdded()) return;
|
||||
// Got an error, show toast
|
||||
Toast.makeText(getActivity(), R.string.unable_to_connect_to_xbmc, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
.show();
|
||||
}
|
||||
}, callbackHandler);
|
||||
}
|
||||
|
@ -327,7 +276,7 @@ public class MusicVideoDetailsFragment extends Fragment
|
|||
public void onAddToPlaylistClicked(View v) {
|
||||
Playlist.GetPlaylists getPlaylists = new Playlist.GetPlaylists();
|
||||
|
||||
getPlaylists.execute(hostManager.getConnection(), new ApiCallback<ArrayList<PlaylistType.GetPlaylistsReturnType>>() {
|
||||
getPlaylists.execute(getHostManager().getConnection(), new ApiCallback<ArrayList<PlaylistType.GetPlaylistsReturnType>>() {
|
||||
@Override
|
||||
public void onSuccess(ArrayList<PlaylistType.GetPlaylistsReturnType> result) {
|
||||
if (!isAdded()) return;
|
||||
|
@ -344,7 +293,7 @@ public class MusicVideoDetailsFragment extends Fragment
|
|||
PlaylistType.Item item = new PlaylistType.Item();
|
||||
item.musicvideoid = musicVideoId;
|
||||
Playlist.Add action = new Playlist.Add(videoPlaylistId, item);
|
||||
action.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
||||
action.execute(getHostManager().getConnection(), new ApiCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
if (!isAdded()) return;
|
||||
|
@ -390,35 +339,35 @@ public class MusicVideoDetailsFragment extends Fragment
|
|||
if (file.exists()) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.download)
|
||||
.setMessage(R.string.download_file_exists)
|
||||
.setPositiveButton(R.string.overwrite,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FileDownloadHelper.downloadFiles(getActivity(), hostInfo,
|
||||
musicVideoDownloadInfo, FileDownloadHelper.OVERWRITE_FILES,
|
||||
callbackHandler);
|
||||
}
|
||||
})
|
||||
.setNeutralButton(R.string.download_with_new_name,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FileDownloadHelper.downloadFiles(getActivity(), hostInfo,
|
||||
musicVideoDownloadInfo, FileDownloadHelper.DOWNLOAD_WITH_NEW_NAME,
|
||||
callbackHandler);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// Nothing to do
|
||||
}
|
||||
})
|
||||
.show();
|
||||
.setMessage(R.string.download_file_exists)
|
||||
.setPositiveButton(R.string.overwrite,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FileDownloadHelper.downloadFiles(getActivity(), getHostInfo(),
|
||||
musicVideoDownloadInfo, FileDownloadHelper.OVERWRITE_FILES,
|
||||
callbackHandler);
|
||||
}
|
||||
})
|
||||
.setNeutralButton(R.string.download_with_new_name,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FileDownloadHelper.downloadFiles(getActivity(), getHostInfo(),
|
||||
musicVideoDownloadInfo, FileDownloadHelper.DOWNLOAD_WITH_NEW_NAME,
|
||||
callbackHandler);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// Nothing to do
|
||||
}
|
||||
})
|
||||
.show();
|
||||
} else {
|
||||
FileDownloadHelper.downloadFiles(getActivity(), hostInfo,
|
||||
FileDownloadHelper.downloadFiles(getActivity(), getHostInfo(),
|
||||
musicVideoDownloadInfo, FileDownloadHelper.DOWNLOAD_WITH_NEW_NAME,
|
||||
callbackHandler);
|
||||
}
|
||||
|
@ -434,14 +383,14 @@ public class MusicVideoDetailsFragment extends Fragment
|
|||
String musicVideoTitle = cursor.getString(MusicVideoDetailsQuery.TITLE);
|
||||
mediaTitle.setText(musicVideoTitle);
|
||||
String artistAlbum = cursor.getString(MusicVideoDetailsQuery.ARTIST) + " | " +
|
||||
cursor.getString(MusicVideoDetailsQuery.ALBUM);
|
||||
cursor.getString(MusicVideoDetailsQuery.ALBUM);
|
||||
mediaUndertitle.setText(artistAlbum);
|
||||
|
||||
int runtime = cursor.getInt(MusicVideoDetailsQuery.RUNTIME);
|
||||
String durationYear = runtime > 0 ?
|
||||
UIUtils.formatTime(runtime) + " | " +
|
||||
String.valueOf(cursor.getInt(MusicVideoDetailsQuery.YEAR)) :
|
||||
String.valueOf(cursor.getInt(MusicVideoDetailsQuery.YEAR));
|
||||
UIUtils.formatTime(runtime) + " | " +
|
||||
String.valueOf(cursor.getInt(MusicVideoDetailsQuery.YEAR)) :
|
||||
String.valueOf(cursor.getInt(MusicVideoDetailsQuery.YEAR));
|
||||
mediaYear.setText(durationYear);
|
||||
mediaGenres.setText(cursor.getString(MusicVideoDetailsQuery.GENRES));
|
||||
|
||||
|
@ -461,16 +410,16 @@ public class MusicVideoDetailsFragment extends Fragment
|
|||
int posterWidth = resources.getDimensionPixelOffset(R.dimen.musicvideodetail_poster_width);
|
||||
int posterHeight = resources.getDimensionPixelOffset(R.dimen.musicvideodetail_poster_heigth);
|
||||
mediaPoster.setVisibility(View.VISIBLE);
|
||||
UIUtils.loadImageWithCharacterAvatar(getActivity(), hostManager,
|
||||
UIUtils.loadImageWithCharacterAvatar(getActivity(), getHostManager(),
|
||||
poster, musicVideoTitle,
|
||||
mediaPoster, posterWidth, posterHeight);
|
||||
UIUtils.loadImageIntoImageview(hostManager,
|
||||
UIUtils.loadImageIntoImageview(getHostManager(),
|
||||
fanart,
|
||||
mediaArt, artWidth, artHeight);
|
||||
} else {
|
||||
// No fanart, just present the poster
|
||||
mediaPoster.setVisibility(View.GONE);
|
||||
UIUtils.loadImageIntoImageview(hostManager,
|
||||
UIUtils.loadImageIntoImageview(getHostManager(),
|
||||
poster,
|
||||
mediaArt, artWidth, artHeight);
|
||||
// Reset padding
|
||||
|
|
|
@ -17,7 +17,6 @@ package org.xbmc.kore.ui;
|
|||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.Cursor;
|
||||
|
@ -26,7 +25,6 @@ import android.os.Bundle;
|
|||
import android.os.Handler;
|
||||
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;
|
||||
|
@ -46,10 +44,7 @@ import com.melnykov.fab.FloatingActionButton;
|
|||
import com.melnykov.fab.ObservableScrollView;
|
||||
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.ApiCallback;
|
||||
import org.xbmc.kore.jsonrpc.ApiException;
|
||||
import org.xbmc.kore.jsonrpc.event.MediaSyncEvent;
|
||||
import org.xbmc.kore.jsonrpc.method.Player;
|
||||
import org.xbmc.kore.jsonrpc.method.Playlist;
|
||||
|
@ -67,14 +62,12 @@ import java.util.ArrayList;
|
|||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import butterknife.OnClick;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Presents movie details
|
||||
*/
|
||||
public class TVShowEpisodeDetailsFragment extends Fragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor>,
|
||||
SwipeRefreshLayout.OnRefreshListener {
|
||||
public class TVShowEpisodeDetailsFragment extends AbstractDetailsFragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
private static final String TAG = LogUtils.makeLogTag(TVShowEpisodeDetailsFragment.class);
|
||||
|
||||
public static final String TVSHOWID = "tvshow_id";
|
||||
|
@ -84,10 +77,6 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
private static final int LOADER_EPISODE = 0;
|
||||
// private static final int LOADER_CAST = 1;
|
||||
|
||||
private HostManager hostManager;
|
||||
private HostInfo hostInfo;
|
||||
private EventBus bus;
|
||||
|
||||
/**
|
||||
* Handler on which to post RPC callbacks
|
||||
*/
|
||||
|
@ -143,28 +132,18 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
protected View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
tvshowId = getArguments().getInt(TVSHOWID, -1);
|
||||
episodeId = getArguments().getInt(EPISODEID, -1);
|
||||
|
||||
if ((container == null) || (episodeId == -1)) {
|
||||
// We're not being shown or there's nothing to show
|
||||
if(episodeId == -1) {
|
||||
// There's nothing to show
|
||||
return null;
|
||||
}
|
||||
|
||||
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_episode_details, container, false);
|
||||
ButterKnife.inject(this, root);
|
||||
|
||||
bus = EventBus.getDefault();
|
||||
hostManager = HostManager.getInstance(getActivity());
|
||||
hostInfo = hostManager.getHostInfo();
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(this);
|
||||
//UIUtils.setSwipeRefreshLayoutColorScheme(swipeRefreshLayout);
|
||||
|
||||
// Setup dim the fanart when scroll changes. Full dim on 4 * iconSize dp
|
||||
|
@ -189,6 +168,25 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSyncType() {
|
||||
return LibrarySyncService.SYNC_SINGLE_TVSHOW;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSyncID() {
|
||||
return LibrarySyncService.SYNC_TVSHOWID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSyncItemID() {
|
||||
return tvshowId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SwipeRefreshLayout getSwipeRefreshLayout() {
|
||||
return swipeRefreshLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated (Bundle savedInstanceState) {
|
||||
|
@ -203,81 +201,15 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
|
||||
@Override
|
||||
public void onResume() {
|
||||
bus.register(this);
|
||||
// Force the exit view to invisible
|
||||
exitTransitionView.setVisibility(View.INVISIBLE);
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
bus.unregister(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
// outState.putInt(TVSHOWID, tvshowId);
|
||||
// outState.putInt(EPISODEID, episodeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Swipe refresh layout callback
|
||||
*/
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void onRefresh () {
|
||||
if (hostInfo != null) {
|
||||
// Start the syncing process
|
||||
startSync(false);
|
||||
} else {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
Toast.makeText(getActivity(), R.string.no_xbmc_configured, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
private void startSync(boolean silentRefresh) {
|
||||
Intent syncIntent = new Intent(this.getActivity(), LibrarySyncService.class);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_SINGLE_TVSHOW, true);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_TVSHOWID, tvshowId);
|
||||
|
||||
Bundle syncExtras = new Bundle();
|
||||
syncExtras.putBoolean(LibrarySyncService.SILENT_SYNC, silentRefresh);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_EXTRAS, syncExtras);
|
||||
|
||||
getActivity().startService(syncIntent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event bus post. Called when the syncing process ended
|
||||
*
|
||||
* @param event Refreshes data
|
||||
*/
|
||||
public void onEventMainThread(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) {
|
||||
getLoaderManager().restartLoader(LOADER_EPISODE, null, this);
|
||||
// getLoaderManager().restartLoader(LOADER_CAST, null, this);
|
||||
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();
|
||||
}
|
||||
protected void onSyncProcessEnded(MediaSyncEvent event) {
|
||||
if (event.status == MediaSyncEvent.STATUS_SUCCESS) {
|
||||
getLoaderManager().restartLoader(LOADER_EPISODE, null, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -290,7 +222,7 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
Uri uri;
|
||||
switch (i) {
|
||||
case LOADER_EPISODE:
|
||||
uri = MediaContract.Episodes.buildTVShowEpisodeUri(hostInfo.getId(), tvshowId, episodeId);
|
||||
uri = MediaContract.Episodes.buildTVShowEpisodeUri(getHostInfo().getId(), tvshowId, episodeId);
|
||||
return new CursorLoader(getActivity(), uri,
|
||||
EpisodeDetailsQuery.PROJECTION, null, null, null);
|
||||
// case LOADER_CAST:
|
||||
|
@ -331,7 +263,7 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
PlaylistType.Item item = new PlaylistType.Item();
|
||||
item.episodeid = episodeId;
|
||||
Player.Open action = new Player.Open(item);
|
||||
action.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
||||
action.execute(getHostManager().getConnection(), new ApiCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
if (!isAdded()) return;
|
||||
|
@ -352,7 +284,7 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
if (!isAdded()) return;
|
||||
// Got an error, show toast
|
||||
Toast.makeText(getActivity(), R.string.unable_to_connect_to_xbmc, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
.show();
|
||||
}
|
||||
}, callbackHandler);
|
||||
}
|
||||
|
@ -361,7 +293,7 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
public void onAddToPlaylistClicked(View v) {
|
||||
Playlist.GetPlaylists getPlaylists = new Playlist.GetPlaylists();
|
||||
|
||||
getPlaylists.execute(hostManager.getConnection(), new ApiCallback<ArrayList<PlaylistType.GetPlaylistsReturnType>>() {
|
||||
getPlaylists.execute(getHostManager().getConnection(), new ApiCallback<ArrayList<PlaylistType.GetPlaylistsReturnType>>() {
|
||||
@Override
|
||||
public void onSuccess(ArrayList<PlaylistType.GetPlaylistsReturnType> result) {
|
||||
if (!isAdded()) return;
|
||||
|
@ -378,13 +310,13 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
PlaylistType.Item item = new PlaylistType.Item();
|
||||
item.episodeid = episodeId;
|
||||
Playlist.Add action = new Playlist.Add(videoPlaylistId, item);
|
||||
action.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
||||
action.execute(getHostManager().getConnection(), new ApiCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
if (!isAdded()) return;
|
||||
// Got an error, show toast
|
||||
Toast.makeText(getActivity(), R.string.item_added_to_playlist, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -392,12 +324,12 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
if (!isAdded()) return;
|
||||
// Got an error, show toast
|
||||
Toast.makeText(getActivity(), R.string.unable_to_connect_to_xbmc, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
.show();
|
||||
}
|
||||
}, callbackHandler);
|
||||
} else {
|
||||
Toast.makeText(getActivity(), R.string.no_suitable_playlist, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -406,7 +338,7 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
if (!isAdded()) return;
|
||||
// Got an error, show toast
|
||||
Toast.makeText(getActivity(), R.string.unable_to_connect_to_xbmc, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
.show();
|
||||
}
|
||||
}, callbackHandler);
|
||||
}
|
||||
|
@ -419,7 +351,7 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
|
||||
VideoLibrary.SetEpisodeDetails action =
|
||||
new VideoLibrary.SetEpisodeDetails(episodeId, newPlaycount, null);
|
||||
action.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
||||
action.execute(getHostManager().getConnection(), new ApiCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
// Force a refresh, but don't show a message
|
||||
|
@ -455,27 +387,27 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
if (file.exists()) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.download)
|
||||
.setMessage(R.string.download_file_exists)
|
||||
.setPositiveButton(R.string.overwrite,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FileDownloadHelper.downloadFiles(getActivity(), hostInfo,
|
||||
tvshowDownloadInfo, FileDownloadHelper.OVERWRITE_FILES,
|
||||
callbackHandler);
|
||||
}
|
||||
})
|
||||
.setNeutralButton(R.string.download_with_new_name,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FileDownloadHelper.downloadFiles(getActivity(), hostInfo,
|
||||
tvshowDownloadInfo, FileDownloadHelper.DOWNLOAD_WITH_NEW_NAME,
|
||||
callbackHandler);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, noopClickListener)
|
||||
.show();
|
||||
.setMessage(R.string.download_file_exists)
|
||||
.setPositiveButton(R.string.overwrite,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FileDownloadHelper.downloadFiles(getActivity(), getHostInfo(),
|
||||
tvshowDownloadInfo, FileDownloadHelper.OVERWRITE_FILES,
|
||||
callbackHandler);
|
||||
}
|
||||
})
|
||||
.setNeutralButton(R.string.download_with_new_name,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FileDownloadHelper.downloadFiles(getActivity(), getHostInfo(),
|
||||
tvshowDownloadInfo, FileDownloadHelper.DOWNLOAD_WITH_NEW_NAME,
|
||||
callbackHandler);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, noopClickListener)
|
||||
.show();
|
||||
} else {
|
||||
// Confirm that the user really wants to download the file
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
|
@ -485,7 +417,7 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FileDownloadHelper.downloadFiles(getActivity(), hostInfo,
|
||||
FileDownloadHelper.downloadFiles(getActivity(), getHostInfo(),
|
||||
tvshowDownloadInfo, FileDownloadHelper.OVERWRITE_FILES,
|
||||
callbackHandler);
|
||||
}
|
||||
|
@ -507,9 +439,9 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
|
||||
int runtime = cursor.getInt(EpisodeDetailsQuery.RUNTIME) / 60;
|
||||
String durationPremiered = runtime > 0 ?
|
||||
String.format(getString(R.string.minutes_abbrev), String.valueOf(runtime)) +
|
||||
" | " + cursor.getString(EpisodeDetailsQuery.FIRSTAIRED) :
|
||||
cursor.getString(EpisodeDetailsQuery.FIRSTAIRED);
|
||||
String.format(getString(R.string.minutes_abbrev), String.valueOf(runtime)) +
|
||||
" | " + cursor.getString(EpisodeDetailsQuery.FIRSTAIRED) :
|
||||
cursor.getString(EpisodeDetailsQuery.FIRSTAIRED);
|
||||
mediaPremiered.setText(durationPremiered);
|
||||
String season = String.format(getString(R.string.season_episode),
|
||||
cursor.getInt(EpisodeDetailsQuery.SEASON),
|
||||
|
@ -543,7 +475,7 @@ public class TVShowEpisodeDetailsFragment extends Fragment
|
|||
// cursor.getString(EpisodeDetailsQuery.THUMBNAIL),
|
||||
// mediaPoster, posterWidth, posterHeight);
|
||||
int artHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_art_height);
|
||||
UIUtils.loadImageIntoImageview(hostManager,
|
||||
UIUtils.loadImageIntoImageview(getHostManager(),
|
||||
cursor.getString(EpisodeDetailsQuery.THUMBNAIL),
|
||||
mediaArt, displayMetrics.widthPixels, artHeight);
|
||||
|
||||
|
|
|
@ -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.content.res.TypedArray;
|
||||
|
@ -26,7 +25,6 @@ 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;
|
||||
|
@ -42,29 +40,26 @@ import android.widget.ExpandableListView;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
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.event.MediaSyncEvent;
|
||||
import org.xbmc.kore.provider.MediaContract;
|
||||
import org.xbmc.kore.service.LibrarySyncService;
|
||||
import org.xbmc.kore.utils.LogUtils;
|
||||
import org.xbmc.kore.utils.UIUtils;
|
||||
import org.xbmc.kore.utils.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Presents a list of episodes for a TV show
|
||||
*/
|
||||
public class TVShowEpisodeListFragment extends Fragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor>,
|
||||
SwipeRefreshLayout.OnRefreshListener {
|
||||
public class TVShowEpisodeListFragment extends AbstractDetailsFragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
private static final String TAG = LogUtils.makeLogTag(TVShowEpisodeListFragment.class);
|
||||
|
||||
public interface OnEpisodeSelectedListener {
|
||||
|
@ -85,41 +80,47 @@ public class TVShowEpisodeListFragment extends Fragment
|
|||
|
||||
private CursorTreeAdapter adapter;
|
||||
|
||||
private HostManager hostManager;
|
||||
private HostInfo hostInfo;
|
||||
private EventBus bus;
|
||||
|
||||
@InjectView(R.id.list) ExpandableListView seasonsEpisodesListView;
|
||||
@InjectView(R.id.swipe_refresh_layout) SwipeRefreshLayout swipeRefreshLayout;
|
||||
@InjectView(android.R.id.empty) TextView emptyView;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
protected View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
tvshowId = getArguments().getInt(TVSHOWID, -1);
|
||||
if ((container == null) || (tvshowId == -1)) {
|
||||
// We're not being shown or there's nothing to show
|
||||
if (tvshowId == -1) {
|
||||
// There's nothing to show
|
||||
return null;
|
||||
}
|
||||
|
||||
bus = EventBus.getDefault();
|
||||
hostManager = HostManager.getInstance(getActivity());
|
||||
hostInfo = hostManager.getHostInfo();
|
||||
|
||||
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_tvshow_episodes_list, container, false);
|
||||
ButterKnife.inject(this, root);
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(this);
|
||||
//UIUtils.setSwipeRefreshLayoutColorScheme(swipeRefreshLayout);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSyncType() {
|
||||
return LibrarySyncService.SYNC_SINGLE_TVSHOW;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSyncID() {
|
||||
return LibrarySyncService.SYNC_TVSHOWID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSyncItemID() {
|
||||
return tvshowId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SwipeRefreshLayout getSwipeRefreshLayout() {
|
||||
return swipeRefreshLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated (Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
@ -171,25 +172,6 @@ public class TVShowEpisodeListFragment extends Fragment
|
|||
listenerActivity = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
bus.register(this);
|
||||
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
bus.unregister(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
// LogUtils.LOGD(TAG, "onSaveInstanceState");
|
||||
// outState.putInt(TVSHOWID, tvshowId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
|
@ -198,7 +180,7 @@ public class TVShowEpisodeListFragment extends Fragment
|
|||
// Setup filters
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
menu.findItem(R.id.action_hide_watched)
|
||||
.setChecked(preferences.getBoolean(Settings.KEY_PREF_TVSHOW_EPISODES_FILTER_HIDE_WATCHED, Settings.DEFAULT_PREF_TVSHOW_EPISODES_FILTER_HIDE_WATCHED));
|
||||
.setChecked(preferences.getBoolean(Settings.KEY_PREF_TVSHOW_EPISODES_FILTER_HIDE_WATCHED, Settings.DEFAULT_PREF_TVSHOW_EPISODES_FILTER_HIDE_WATCHED));
|
||||
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
@ -221,57 +203,10 @@ public class TVShowEpisodeListFragment extends Fragment
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Swipe refresh layout callback
|
||||
*/
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void onRefresh () {
|
||||
if (hostInfo != null) {
|
||||
startSync(false);
|
||||
} else {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
Toast.makeText(getActivity(), R.string.no_xbmc_configured, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
private void startSync(boolean silentRefresh) {
|
||||
// Start the syncing process
|
||||
Intent syncIntent = new Intent(this.getActivity(), LibrarySyncService.class);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_SINGLE_TVSHOW, true);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_TVSHOWID, tvshowId);
|
||||
|
||||
Bundle syncExtras = new Bundle();
|
||||
syncExtras.putBoolean(LibrarySyncService.SILENT_SYNC, silentRefresh);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_EXTRAS, syncExtras);
|
||||
|
||||
getActivity().startService(syncIntent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event bus post. Called when the syncing process ended
|
||||
*
|
||||
* @param event Refreshes data
|
||||
*/
|
||||
public void onEventMainThread(MediaSyncEvent event) {
|
||||
if (event.syncType.equals(LibrarySyncService.SYNC_SINGLE_TVSHOW) ||
|
||||
event.syncType.equals(LibrarySyncService.SYNC_ALL_TVSHOWS)) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
if (event.status == MediaSyncEvent.STATUS_SUCCESS) {
|
||||
getLoaderManager().restartLoader(LOADER_SEASONS, null, this);
|
||||
// This message will be displayed by the fragment TVShowOverview,
|
||||
// which is already loaded, and this event also gets handled by it,
|
||||
// so there's no need to show this message here.
|
||||
// Toast.makeText(getActivity(), R.string.sync_successful, Toast.LENGTH_SHORT)
|
||||
// .show();
|
||||
// } else {
|
||||
// Toast.makeText(getActivity(),
|
||||
// String.format(getString(R.string.error_while_syncing), event.errorMessage),
|
||||
// Toast.LENGTH_SHORT)
|
||||
// .show();
|
||||
}
|
||||
protected void onSyncProcessEnded(MediaSyncEvent event) {
|
||||
if (event.status == MediaSyncEvent.STATUS_SUCCESS) {
|
||||
getLoaderManager().restartLoader(LOADER_SEASONS, null, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,7 +218,7 @@ public class TVShowEpisodeListFragment extends Fragment
|
|||
public Loader<Cursor> onCreateLoader(int id, Bundle bundle) {
|
||||
if (!isAdded()) {
|
||||
LogUtils.LOGD(TAG, "Trying to create a loader, but the fragment isn't added. " +
|
||||
"Loader Id: " + id);
|
||||
"Loader Id: " + id);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -295,13 +230,13 @@ public class TVShowEpisodeListFragment extends Fragment
|
|||
switch (id) {
|
||||
case LOADER_SEASONS:
|
||||
// Load seasons
|
||||
uri = MediaContract.Seasons.buildTVShowSeasonsListUri(hostInfo.getId(), tvshowId);
|
||||
uri = MediaContract.Seasons.buildTVShowSeasonsListUri(getHostInfo().getId(), tvshowId);
|
||||
|
||||
// Filters
|
||||
if (tvshowEpisodesFilterHideWatched) {
|
||||
selection.append(MediaContract.SeasonsColumns.WATCHEDEPISODES)
|
||||
.append("!=")
|
||||
.append(MediaContract.SeasonsColumns.EPISODE);
|
||||
.append("!=")
|
||||
.append(MediaContract.SeasonsColumns.EPISODE);
|
||||
}
|
||||
|
||||
return new CursorLoader(getActivity(), uri,
|
||||
|
@ -309,12 +244,12 @@ public class TVShowEpisodeListFragment extends Fragment
|
|||
default:
|
||||
// Load episodes for a season. Season is in bundle
|
||||
int season = bundle.getInt(SEASON);
|
||||
uri = MediaContract.Episodes.buildTVShowSeasonEpisodesListUri(hostInfo.getId(), tvshowId, season);
|
||||
uri = MediaContract.Episodes.buildTVShowSeasonEpisodesListUri(getHostInfo().getId(), tvshowId, season);
|
||||
|
||||
// Filters
|
||||
if (tvshowEpisodesFilterHideWatched) {
|
||||
selection.append(MediaContract.EpisodesColumns.PLAYCOUNT)
|
||||
.append("=0");
|
||||
.append("=0");
|
||||
}
|
||||
|
||||
return new CursorLoader(getActivity(), uri,
|
||||
|
@ -326,7 +261,7 @@ public class TVShowEpisodeListFragment extends Fragment
|
|||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
|
||||
LogUtils.LOGD(TAG, "onLoadFinished, Loader id: " + cursorLoader.getId() + ". Rows: " +
|
||||
cursor.getCount());
|
||||
cursor.getCount());
|
||||
switch (cursorLoader.getId()) {
|
||||
case LOADER_SEASONS:
|
||||
adapter.setGroupCursor(cursor);
|
||||
|
@ -467,23 +402,23 @@ public class TVShowEpisodeListFragment extends Fragment
|
|||
// Get the art dimensions
|
||||
Resources resources = context.getResources();
|
||||
artWidth = (int)(resources.getDimension(R.dimen.seasonlist_art_width) /
|
||||
UIUtils.IMAGE_RESIZE_FACTOR);
|
||||
UIUtils.IMAGE_RESIZE_FACTOR);
|
||||
artHeight = (int)(resources.getDimension(R.dimen.seasonlist_art_heigth) /
|
||||
UIUtils.IMAGE_RESIZE_FACTOR);
|
||||
UIUtils.IMAGE_RESIZE_FACTOR);
|
||||
separatorPadding = resources.getDimensionPixelSize(R.dimen.small_padding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View newGroupView(Context context, Cursor cursor, boolean isExpanded, ViewGroup parent) {
|
||||
final View view = LayoutInflater.from(context)
|
||||
.inflate(R.layout.list_item_season, parent, false);
|
||||
.inflate(R.layout.list_item_season, parent, false);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View newChildView(Context context, Cursor cursor, boolean isLastChild, ViewGroup parent) {
|
||||
final View view = LayoutInflater.from(context)
|
||||
.inflate(R.layout.list_item_episode, parent, false);
|
||||
.inflate(R.layout.list_item_episode, parent, false);
|
||||
|
||||
// Setup View holder pattern
|
||||
EpisodeViewHolder viewHolder = new EpisodeViewHolder();
|
||||
|
@ -535,12 +470,12 @@ public class TVShowEpisodeListFragment extends Fragment
|
|||
|
||||
viewHolder.episodenumberView.setText(
|
||||
String.format(context.getString(R.string.episode_number),
|
||||
cursor.getInt(EpisodesListQuery.EPISODE)));
|
||||
cursor.getInt(EpisodesListQuery.EPISODE)));
|
||||
int runtime = cursor.getInt(EpisodesListQuery.RUNTIME) / 60;
|
||||
String duration = runtime > 0 ?
|
||||
String.format(context.getString(R.string.minutes_abbrev), String.valueOf(runtime)) +
|
||||
" | " + cursor.getString(EpisodesListQuery.FIRSTAIRED) :
|
||||
cursor.getString(EpisodesListQuery.FIRSTAIRED);
|
||||
String.format(context.getString(R.string.minutes_abbrev), String.valueOf(runtime)) +
|
||||
" | " + cursor.getString(EpisodesListQuery.FIRSTAIRED) :
|
||||
cursor.getString(EpisodesListQuery.FIRSTAIRED);
|
||||
viewHolder.titleView.setText(cursor.getString(EpisodesListQuery.TITLE));
|
||||
viewHolder.detailsView.setText(duration);
|
||||
|
||||
|
@ -576,7 +511,7 @@ public class TVShowEpisodeListFragment extends Fragment
|
|||
// will be used as the loader's id
|
||||
LoaderManager loaderManager = getLoaderManager();
|
||||
if ((loaderManager.getLoader(groupPositon) == null) ||
|
||||
(loaderManager.getLoader(groupPositon).isReset())) {
|
||||
(loaderManager.getLoader(groupPositon).isReset())) {
|
||||
loaderManager.initLoader(groupPositon, bundle, TVShowEpisodeListFragment.this);
|
||||
} else {
|
||||
loaderManager.restartLoader(groupPositon, bundle, TVShowEpisodeListFragment.this);
|
||||
|
@ -594,7 +529,7 @@ public class TVShowEpisodeListFragment extends Fragment
|
|||
TextView titleView;
|
||||
TextView detailsView;
|
||||
TextView episodenumberView;
|
||||
// ImageView artView;
|
||||
// ImageView artView;
|
||||
ImageView checkmarkView;
|
||||
|
||||
int episodeId;
|
||||
|
|
|
@ -15,35 +15,27 @@
|
|||
*/
|
||||
package org.xbmc.kore.ui;
|
||||
|
||||
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.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.AppCompatButton;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.Button;
|
||||
import android.widget.GridLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ScrollView;
|
||||
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.jsonrpc.type.VideoType;
|
||||
import org.xbmc.kore.provider.MediaContract;
|
||||
|
@ -51,21 +43,16 @@ import org.xbmc.kore.service.LibrarySyncService;
|
|||
import org.xbmc.kore.utils.LogUtils;
|
||||
import org.xbmc.kore.utils.UIUtils;
|
||||
|
||||
import java.lang.System;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import butterknife.OnClick;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Presents a TV Show overview
|
||||
*/
|
||||
public class TVShowOverviewFragment extends Fragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor>,
|
||||
SwipeRefreshLayout.OnRefreshListener {
|
||||
public class TVShowOverviewFragment extends AbstractDetailsFragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
private static final String TAG = LogUtils.makeLogTag(TVShowOverviewFragment.class);
|
||||
|
||||
public static final String TVSHOWID = "tvshow_id";
|
||||
|
@ -74,10 +61,6 @@ public class TVShowOverviewFragment extends Fragment
|
|||
private static final int LOADER_TVSHOW = 0,
|
||||
LOADER_CAST = 1;
|
||||
|
||||
private HostManager hostManager;
|
||||
private HostInfo hostInfo;
|
||||
private EventBus bus;
|
||||
|
||||
// Displayed movie id
|
||||
private int tvshowId = -1;
|
||||
private String tvshowTitle;
|
||||
|
@ -122,27 +105,17 @@ public class TVShowOverviewFragment extends Fragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
protected View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
tvshowId = getArguments().getInt(TVSHOWID, -1);
|
||||
|
||||
if ((container == null) || (tvshowId == -1)) {
|
||||
// We're not being shown or there's nothing to show
|
||||
if (tvshowId == -1) {
|
||||
// There's nothing to show
|
||||
return null;
|
||||
}
|
||||
|
||||
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_tvshow_overview, container, false);
|
||||
ButterKnife.inject(this, root);
|
||||
|
||||
bus = EventBus.getDefault();
|
||||
hostManager = HostManager.getInstance(getActivity());
|
||||
hostInfo = hostManager.getHostInfo();
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(this);
|
||||
//UIUtils.setSwipeRefreshLayoutColorScheme(swipeRefreshLayout);
|
||||
|
||||
// Setup dim the fanart when scroll changes. Full dim on 4 * iconSize dp
|
||||
|
@ -164,6 +137,26 @@ public class TVShowOverviewFragment extends Fragment
|
|||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSyncType() {
|
||||
return LibrarySyncService.SYNC_SINGLE_TVSHOW;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSyncID() {
|
||||
return LibrarySyncService.SYNC_TVSHOWID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSyncItemID() {
|
||||
return tvshowId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SwipeRefreshLayout getSwipeRefreshLayout() {
|
||||
return swipeRefreshLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated (Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
@ -178,79 +171,10 @@ public class TVShowOverviewFragment extends Fragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
bus.register(this);
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
bus.unregister(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
// outState.putInt(TVSHOWID, tvshowId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Swipe refresh layout callback
|
||||
*/
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void onRefresh () {
|
||||
if (hostInfo != null) {
|
||||
// Start the syncing process
|
||||
startSync(false);
|
||||
} else {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
Toast.makeText(getActivity(), R.string.no_xbmc_configured, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
private void startSync(boolean silentRefresh) {
|
||||
Intent syncIntent = new Intent(this.getActivity(), LibrarySyncService.class);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_SINGLE_TVSHOW, true);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_TVSHOWID, tvshowId);
|
||||
|
||||
Bundle syncExtras = new Bundle();
|
||||
syncExtras.putBoolean(LibrarySyncService.SILENT_SYNC, silentRefresh);
|
||||
syncIntent.putExtra(LibrarySyncService.SYNC_EXTRAS, syncExtras);
|
||||
|
||||
getActivity().startService(syncIntent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event bus post. Called when the syncing process ended
|
||||
*
|
||||
* @param event Refreshes data
|
||||
*/
|
||||
public void onEventMainThread(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) {
|
||||
getLoaderManager().restartLoader(LOADER_TVSHOW, null, this);
|
||||
getLoaderManager().restartLoader(LOADER_CAST, null, this);
|
||||
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();
|
||||
}
|
||||
protected void onSyncProcessEnded(MediaSyncEvent event) {
|
||||
if (event.status == MediaSyncEvent.STATUS_SUCCESS) {
|
||||
getLoaderManager().restartLoader(LOADER_TVSHOW, null, this);
|
||||
getLoaderManager().restartLoader(LOADER_CAST, null, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,11 +187,11 @@ public class TVShowOverviewFragment extends Fragment
|
|||
Uri uri;
|
||||
switch (i) {
|
||||
case LOADER_TVSHOW:
|
||||
uri = MediaContract.TVShows.buildTVShowUri(hostInfo.getId(), tvshowId);
|
||||
uri = MediaContract.TVShows.buildTVShowUri(getHostInfo().getId(), tvshowId);
|
||||
return new CursorLoader(getActivity(), uri,
|
||||
TVShowDetailsQuery.PROJECTION, null, null, null);
|
||||
case LOADER_CAST:
|
||||
uri = MediaContract.TVShowCast.buildTVShowCastListUri(hostInfo.getId(), tvshowId);
|
||||
uri = MediaContract.TVShowCast.buildTVShowCastListUri(getHostInfo().getId(), tvshowId);
|
||||
return new CursorLoader(getActivity(), uri,
|
||||
TVShowCastListQuery.PROJECTION, null, null, TVShowCastListQuery.SORT);
|
||||
default:
|
||||
|
@ -278,6 +202,7 @@ public class TVShowOverviewFragment extends Fragment
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
|
||||
LogUtils.LOGD(TAG, "onLoadFinished");
|
||||
if (cursor != null && cursor.getCount() > 0) {
|
||||
switch (cursorLoader.getId()) {
|
||||
case LOADER_TVSHOW:
|
||||
|
@ -315,6 +240,7 @@ public class TVShowOverviewFragment extends Fragment
|
|||
* @param cursor Cursor with the data
|
||||
*/
|
||||
private void displayTVShowDetails(Cursor cursor) {
|
||||
LogUtils.LOGD(TAG, "displayTVShowDetails");
|
||||
cursor.moveToFirst();
|
||||
tvshowTitle = cursor.getString(TVShowDetailsQuery.TITLE);
|
||||
mediaTitle.setText(tvshowTitle);
|
||||
|
@ -353,11 +279,11 @@ public class TVShowOverviewFragment extends Fragment
|
|||
|
||||
int posterWidth = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_width);
|
||||
int posterHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_height);
|
||||
UIUtils.loadImageWithCharacterAvatar(getActivity(), hostManager,
|
||||
UIUtils.loadImageWithCharacterAvatar(getActivity(), getHostManager(),
|
||||
cursor.getString(TVShowDetailsQuery.THUMBNAIL), tvshowTitle,
|
||||
mediaPoster, posterWidth, posterHeight);
|
||||
int artHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_art_height);
|
||||
UIUtils.loadImageIntoImageview(hostManager,
|
||||
UIUtils.loadImageIntoImageview(getHostManager(),
|
||||
cursor.getString(TVShowDetailsQuery.FANART),
|
||||
mediaArt, displayMetrics.widthPixels, artHeight);
|
||||
}
|
||||
|
@ -380,7 +306,7 @@ public class TVShowOverviewFragment extends Fragment
|
|||
} while (cursor.moveToNext());
|
||||
|
||||
UIUtils.setupCastInfo(getActivity(), castArrayList, videoCastList,
|
||||
AllCastActivity.buildLaunchIntent(getActivity(), tvshowTitle, castArrayList));
|
||||
AllCastActivity.buildLaunchIntent(getActivity(), tvshowTitle, castArrayList));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.content.res.Resources;
|
|||
import android.content.res.TypedArray;
|
||||
import android.os.Vibrator;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
|
@ -446,4 +447,19 @@ public class UIUtils {
|
|||
context.startActivity(launchIntent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this to manually start the swiperefreshlayout refresh animation.
|
||||
* 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
|
||||
* @param layout
|
||||
*/
|
||||
public static void showRefreshAnimation(@NonNull final SwipeRefreshLayout layout) {
|
||||
layout.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
layout.setRefreshing(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue