Android Open Source - EnklawaPlayer Episode Files Scope From Project Back to project page EnklawaPlayer .
License The source code is released under:
GNU General Public License
If you think the Android project EnklawaPlayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package macbury.pod.db.scopes;
/ / f r o m w w w . j a v a 2 s . c o m
import android.util.Log;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.QueryBuilder;
import java.io.File;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import macbury.pod.db.models.Episode;
import macbury.pod.db.models.EpisodeFile;
import macbury.pod.managers.App;
/**
* Created by macbury on 11.09.14.
*/
public class EpisodeFilesScope extends AbstractScope<EpisodeFile> {
private static final String TAG = "EpisodeFilesScope" ;
public EpisodeFilesScope(Dao<EpisodeFile, Integer > dao) {
super (dao);
}
public boolean createFromEpisode(Episode episode) {
EpisodeFile file = findByEpisodeId(episode.id);
if (file == null) {
file = new EpisodeFile();
file.episode = episode;
file.status = EpisodeFile.Status.Pending;
file.createdAt = new Date();
}
file.retryCount = 0;
return update(file);
}
public EpisodeFile findByEpisodeId(int id) {
try {
return dao.queryBuilder().where().eq("episode_id" , id).queryForFirst();
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
public List<EpisodeFile> pending() {
QueryBuilder<EpisodeFile, Integer > builder = dao.queryBuilder();
try {
return builder.where().in("status" , EpisodeFile.Status.Failed, EpisodeFile.Status.Pending).and().le("retry_count" , EpisodeFile.MAX_RETRY).query();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public List<EpisodeFile> downloading() {
QueryBuilder<EpisodeFile, Integer > builder = dao.queryBuilder();
try {
return builder.where().in("status" , EpisodeFile.Status.Downloading).query();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public void markDownloadingAsFailed() {
for (EpisodeFile file : downloading()) {
markAsFailed(file);
}
}
public void markAsRunning(EpisodeFile epf) {
epf.status = EpisodeFile.Status.Downloading;
update(epf);
}
public void markAsFailed(EpisodeFile epf) {
epf.status = EpisodeFile.Status.Failed;
epf.retryCount++;
update(epf);
}
public void markAsSuccess(EpisodeFile epf) {
epf.status = EpisodeFile.Status.Ready;
epf.retryCount = 0;
update(epf);
}
public List<EpisodeFile> downloadedOrPendingOrFailed() {
QueryBuilder<EpisodeFile, Integer > builder = dao.queryBuilder();
try {
return builder.orderBy("id" , true).where().in("status" , EpisodeFile.Status.Pending, EpisodeFile.Status.Ready, EpisodeFile.Status.Failed).query();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public List<EpisodeFile> downloaded() {
QueryBuilder<EpisodeFile, Integer > builder = dao.queryBuilder();
try {
return builder.orderBy("id" , true).where().in("status" , EpisodeFile.Status.Ready).query();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public int countDownloadedOrPendingOrFailed() {
QueryBuilder<EpisodeFile, Integer > builder = dao.queryBuilder();
try {
return (int )builder.where().in("status" , EpisodeFile.Status.Pending, EpisodeFile.Status.Ready, EpisodeFile.Status.Failed).countOf();
} catch (SQLException e) {
e.printStackTrace();
}
return 0;
}
@Override
public void afterCreate(EpisodeFile model) {
}
@Override
public void afterDestroy(EpisodeFile object) {
Log.i(TAG, "Deleting file for: " + object.episode.name);
File file = App.current().storage.getEpisodeFile(object);
if (file.exists()) {
file.delete();
}
}
@Override
public void afterSave(EpisodeFile object) {
}
}
Java Source Code List macbury.pod.ApplicationTest.java macbury.pod.activities.DonateActivity.java macbury.pod.activities.ProgramEpisodesActivity.java macbury.pod.activities.SettingsActivity.java macbury.pod.activities.ext.AccentFragmentActivity.java macbury.pod.activities.main.MainActivityActionBarToggle.java macbury.pod.activities.main.MainActivity.java macbury.pod.activities.main.NavigationController.java macbury.pod.activities.main.NavigationListener.java macbury.pod.activities.player.PlayerActivity.java macbury.pod.activities.player.RadioActivity.java macbury.pod.adapters.EpisodesAdapterListener.java macbury.pod.adapters.EpisodesAdapter.java macbury.pod.adapters.ProgramsAdapter.java macbury.pod.api.APICategory.java macbury.pod.api.APIEpisode.java macbury.pod.api.APIProgram.java macbury.pod.api.APIResponse.java macbury.pod.api.APIThread.java macbury.pod.db.DatabaseCRUDListener.java macbury.pod.db.models.EnqueueEpisode.java macbury.pod.db.models.EpisodeFile.java macbury.pod.db.models.Episode.java macbury.pod.db.models.ForumThread.java macbury.pod.db.models.Program.java macbury.pod.db.scopes.AbstractScope.java macbury.pod.db.scopes.EnqueueEpisodeScope.java macbury.pod.db.scopes.EpisodeFilesScope.java macbury.pod.db.scopes.EpisodesScope.java macbury.pod.db.scopes.ProgramsScope.java macbury.pod.db.scopes.ThreadScope.java macbury.pod.dialogs.EpisodeAboutDialog.java macbury.pod.dialogs.ProgramAboutDialog.java macbury.pod.extensions.Converter.java macbury.pod.extensions.DateDeserializer.java macbury.pod.extensions.SleepTimer.java macbury.pod.fragments.SettingsFragment.java macbury.pod.fragments.main.AbstractEpisodesFragment.java macbury.pod.fragments.main.AllProgramsFragment.java macbury.pod.fragments.main.EnklawaBaseAbstractListFragment.java macbury.pod.fragments.main.episodes.DownloadedEpisodesFragment.java macbury.pod.fragments.main.episodes.NewestEpisodesFragment.java macbury.pod.fragments.main.episodes.PlaylistFragment.java macbury.pod.fragments.main.episodes.ProgramEpisodesFragment.java macbury.pod.fragments.player.ExternalPlayerFragment.java macbury.pod.fragments.player.PlayerArtworkAndInfoFragment.java macbury.pod.fragments.player.PlayerControllerFragment.java macbury.pod.managers.AlarmsManager.java macbury.pod.managers.App.java macbury.pod.managers.BroadcastsManager.java macbury.pod.managers.DatabaseManager.java macbury.pod.managers.IntentManager.java macbury.pod.managers.NotificationsManager.java macbury.pod.managers.ServiceManager.java macbury.pod.managers.SettingsManager.java macbury.pod.managers.StorageManager.java macbury.pod.managers.download.DownloadEpisode.java macbury.pod.managers.download.DownloadManagerListener.java macbury.pod.managers.download.DownloadManager.java macbury.pod.managers.player.PlaybackStatus.java macbury.pod.managers.player.PlayerManagerListener.java macbury.pod.managers.player.PlayerManager.java macbury.pod.managers.player.sources.AbstractMediaSource.java macbury.pod.managers.player.sources.EpisodeMediaSource.java macbury.pod.managers.player.sources.RadioMediaSource.java macbury.pod.navigation_drawer.NavAdapter.java macbury.pod.navigation_drawer.NavBaseItem.java macbury.pod.navigation_drawer.NavDivider.java macbury.pod.navigation_drawer.items.AllProgramsNavItem.java macbury.pod.navigation_drawer.items.DownloadedEpisodesNavItem.java macbury.pod.navigation_drawer.items.FavoriteProgramNavItem.java macbury.pod.navigation_drawer.items.ForumNavItem.java macbury.pod.navigation_drawer.items.NavItemFragment.java macbury.pod.navigation_drawer.items.NewestEpisodesNavItem.java macbury.pod.navigation_drawer.items.PlayQueueNavItem.java macbury.pod.receivers.BootReceiver.java macbury.pod.receivers.MediaButtonReceiver.java macbury.pod.services.DownloadService.java macbury.pod.services.PlayerService.java macbury.pod.services.SyncPodService.java macbury.pod.tutorial.MainActivityTutorial.java macbury.pod.views.TappableFrameLayout.java