Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove room deps playlist #27081

Open
wants to merge 3 commits into
base: migrate_playlist_kotlin_module
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions android/java/org/chromium/base/BravePreferenceKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public final class BravePreferenceKeys {
"remember_list_playback_position";
public static final String PREF_CONTINUOUS_LISTENING = "continuous_listening";
public static final String PREF_RESET_PLAYLIST = "reset_playlist";
public static final String PLAYLIST_DB_REMOVAL = "playlist_db_removal";

// These are dynamic keys
public static final String BRAVE_RECYCLERVIEW_POSITION = "recyclerview_visible_position_";
Expand Down
30 changes: 30 additions & 0 deletions android/java/org/chromium/chrome/browser/app/BraveActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
import org.chromium.ui.KeyboardUtils;
import org.chromium.ui.widget.Toast;

import java.io.File;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
Expand Down Expand Up @@ -294,6 +295,8 @@ public abstract class BraveActivity extends ChromeActivity
public static final String BING_SEARCH_ENGINE_KEYWORD = ":b";
public static final String STARTPAGE_SEARCH_ENGINE_KEYWORD = ":sp";

private static final String PLAYLIST_DB_NAME = "playlist.db";

private static final boolean ENABLE_IN_APP_UPDATE =
Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE;

Expand Down Expand Up @@ -1027,6 +1030,33 @@ public void maybeSolveAdaptiveCaptcha() {
@Override
public void finishNativeInitialization() {
super.finishNativeInitialization();

// Check and remove legacy playlist database if needed
PostTask.postTask(
TaskTraits.BEST_EFFORT_MAY_BLOCK,
() -> {
// Only attempt removal if we haven't done it before
boolean shouldRemoveDb =
ChromeSharedPreferences.getInstance()
.readBoolean(BravePreferenceKeys.PLAYLIST_DB_REMOVAL, true);

if (shouldRemoveDb) {
// Get path to playlist database
File playlistDatabasePath =
ContextUtils.getApplicationContext()
.getDatabasePath(PLAYLIST_DB_NAME);

// Delete the database file if it exists
if (playlistDatabasePath.exists()) {
ContextUtils.getApplicationContext().deleteDatabase(PLAYLIST_DB_NAME);
}

// Mark database removal as completed
ChromeSharedPreferences.getInstance()
.writeBoolean(BravePreferenceKeys.PLAYLIST_DB_REMOVAL, false);
}
});

boolean isFirstInstall = PackageUtils.isFirstInstall(this);

BraveVpnNativeWorker.getInstance().reloadPurchasedState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package org.chromium.chrome.browser.playlist;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;

Expand All @@ -16,19 +15,14 @@
import org.chromium.base.BravePreferenceKeys;
import org.chromium.base.Log;
import org.chromium.base.supplier.OneshotSupplier;
import org.chromium.base.task.PostTask;
import org.chromium.base.task.TaskTraits;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.init.ActivityProfileProvider;
import org.chromium.chrome.browser.init.AsyncInitializationActivity;
import org.chromium.chrome.browser.playlist.PlaylistServiceObserverImpl.PlaylistServiceObserverImplDelegate;
import org.chromium.chrome.browser.playlist.fragment.AllPlaylistFragment;
import org.chromium.chrome.browser.playlist.fragment.PlaylistFragment;
import org.chromium.chrome.browser.playlist.hls_content.HlsService;
import org.chromium.chrome.browser.playlist.hls_content.HlsServiceImpl;
import org.chromium.chrome.browser.playlist.listener.PlaylistOptionsListener;
import org.chromium.chrome.browser.playlist.local_database.PlaylistRepository;
import org.chromium.chrome.browser.playlist.model.HlsContentProgressModel;
import org.chromium.chrome.browser.playlist.model.MoveOrCopyModel;
import org.chromium.chrome.browser.playlist.model.PlaylistItemModel;
Expand Down Expand Up @@ -178,7 +172,6 @@ public void finishNativeInitialization() {
return;
}
for (PlaylistItemModel playlistItem : playlistItems.getItems()) {
deleteHLSContent(playlistItem.getId());
mPlaylistService.removeItemFromPlaylist(
playlistItems.getId(), playlistItem.getId());
}
Expand Down Expand Up @@ -282,7 +275,6 @@ public void finishNativeInitialization() {
playlistItemOption.getPlaylistItemModel().getPageSource());
} else if (option
== PlaylistModel.PlaylistOptionsEnum.DELETE_PLAYLIST_ITEM) {
deleteHLSContent(playlistItemOption.getPlaylistItemModel().getId());
mPlaylistService.removeItemFromPlaylist(
playlistItemOption.getPlaylistId(),
playlistItemOption.getPlaylistItemModel().getId());
Expand Down Expand Up @@ -464,25 +456,6 @@ private void updatePlaylistItem(String playlistId, PlaylistItem playlistItem) {
mPlaylistViewModel.updatePlaylistItem(playlistItemModel);
}

private void deleteHLSContent(String playlistItemId) {
PostTask.postTask(
TaskTraits.BEST_EFFORT_MAY_BLOCK,
() -> {
PlaylistRepository playlistRepository =
new PlaylistRepository(PlaylistHostActivity.this);
if (playlistRepository != null
&& playlistRepository.isHlsContentQueueModelExists(playlistItemId)) {
playlistRepository.deleteHlsContentQueueModel(playlistItemId);
}
if (HlsServiceImpl.currentDownloadingPlaylistItemId.equals(playlistItemId)) {
HlsServiceImpl.currentDownloadingPlaylistItemId = "";
mPlaylistService.cancelQuery(playlistItemId);
stopService(new Intent(PlaylistHostActivity.this, HlsService.class));
PlaylistUtils.checkAndStartHlsDownload(PlaylistHostActivity.this);
}
});
}

@Override
public void onItemCached(PlaylistItem playlistItem) {
loadPlaylist(ConstantUtils.DEFAULT_PLAYLIST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.chromium.base.task.PostTask;
import org.chromium.base.task.TaskTraits;
import org.chromium.chrome.browser.playlist.PlaylistServiceFactoryAndroid;
import org.chromium.chrome.browser.playlist.local_database.PlaylistRepository;
import org.chromium.chrome.browser.playlist.model.HlsContentProgressModel;
import org.chromium.chrome.browser.playlist.model.HlsContentQueueModel;
import org.chromium.chrome.browser.playlist.model.PlaylistItemModel;
Expand Down Expand Up @@ -70,26 +69,14 @@ private void startHlsContentFromQueue() {
PostTask.postTask(
TaskTraits.BEST_EFFORT_MAY_BLOCK,
() -> {
PlaylistRepository playlistRepository = new PlaylistRepository(mContext);
if (playlistRepository == null) {
return;
}
HlsContentQueueModel hlsContentQueueModel =
playlistRepository.getFirstHlsContentQueueModel();
HlsContentQueueModel hlsContentQueueModel = null;
if (hlsContentQueueModel == null || mPlaylistService == null) {
return;
}
String playlistItemId = hlsContentQueueModel.getPlaylistItemId();
mPlaylistService.getPlaylistItem(
playlistItemId,
playlistItem -> {
if (playlistItem == null) {
PostTask.postTask(
TaskTraits.USER_VISIBLE_MAY_BLOCK,
() -> {
removeContentAndStartNextDownload(playlistItemId);
});
}
currentDownloadingPlaylistItemId = playlistItemId;
HlsUtils.getManifestFile(
mContext,
Expand Down Expand Up @@ -152,9 +139,6 @@ public void onReady(String mediaPath) {
addNewPlaylistItemModel(
playlistItem
.id);
removeContentAndStartNextDownload(
playlistItem
.id);
});
}
});
Expand All @@ -164,20 +148,6 @@ public void onReady(String mediaPath) {
});
}

private void removeContentAndStartNextDownload(String playlistItemId) {
PlaylistRepository playlistRepository = new PlaylistRepository(mContext);
if (playlistRepository == null) {
return;
}
playlistRepository.deleteHlsContentQueueModel(playlistItemId);
currentDownloadingPlaylistItemId = "";
if (playlistRepository.getFirstHlsContentQueueModel() != null) {
startHlsContentFromQueue();
} else {
getService().stopSelf();
}
}

private void addNewPlaylistItemModel(String playlistItemId) {
mPlaylistService.getPlaylistItem(
playlistItemId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.chromium.chrome.R;
import org.chromium.chrome.browser.BraveRelaunchUtils;
import org.chromium.chrome.browser.playlist.PlaylistServiceFactoryAndroid;
import org.chromium.chrome.browser.playlist.local_database.PlaylistRepository;
import org.chromium.chrome.browser.playlist.util.PlaylistPreferenceUtils;
import org.chromium.chrome.browser.preferences.ChromeSharedPreferences;
import org.chromium.chrome.browser.settings.ChromeBaseSettingsFragment;
Expand Down Expand Up @@ -73,10 +72,6 @@ public void onActivityCreated(Bundle savedInstanceState) {
() -> {
mPlaylistService.clearAllQueries();
mPlaylistService.resetAll();
PlaylistRepository playlistRepository =
new PlaylistRepository(getActivity());
playlistRepository.deleteAllLastPlayedPosition();
playlistRepository.deleteAllHlsContentQueueModel();
PlaylistPreferenceUtils.resetPlaylistPrefs(getActivity());
getActivity()
.runOnUiThread(
Expand Down
4 changes: 0 additions & 4 deletions browser/playlist/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ android_library("java") {
"java/src/org/chromium/chrome/browser/playlist/listener/PlaylistOnboardingActionClickListener.kt",
"java/src/org/chromium/chrome/browser/playlist/listener/PlaylistOptionsListener.kt",
"java/src/org/chromium/chrome/browser/playlist/listener/StartDragListener.kt",
"java/src/org/chromium/chrome/browser/playlist/local_database/PlaylistDatabase.kt",
"java/src/org/chromium/chrome/browser/playlist/local_database/PlaylistItemModelDao.kt",
"java/src/org/chromium/chrome/browser/playlist/local_database/PlaylistRepository.kt",
"java/src/org/chromium/chrome/browser/playlist/model/CreatePlaylistModel.kt",
"java/src/org/chromium/chrome/browser/playlist/model/HlsContentProgressModel.kt",
"java/src/org/chromium/chrome/browser/playlist/model/HlsContentQueueModel.kt",
Expand Down Expand Up @@ -75,7 +72,6 @@ android_library("java") {
deps = [
":java_resources",
"//brave/third_party/android_deps:androidx_media3_media3_exoplayer_hls_java",
"//brave/third_party/android_deps:androidx_room_room_runtime_java",
"//brave/third_party/android_deps:com_github_bumptech_glide_java",
"//third_party/android_deps:com_google_code_gson_gson_java",
"//third_party/android_deps:google_play_services_cast_framework_java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import org.chromium.chrome.browser.playlist.listener.PlaylistItemClickListener
import org.chromium.chrome.browser.playlist.listener.PlaylistItemOptionsListener
import org.chromium.chrome.browser.playlist.listener.PlaylistOptionsListener
import org.chromium.chrome.browser.playlist.listener.StartDragListener
import org.chromium.chrome.browser.playlist.local_database.PlaylistRepository
import org.chromium.chrome.browser.playlist.model.HlsContentQueueModel
import org.chromium.chrome.browser.playlist.model.MoveOrCopyModel
import org.chromium.chrome.browser.playlist.model.PlaylistItemModel
Expand Down Expand Up @@ -100,10 +99,6 @@ class PlaylistFragment : Fragment(R.layout.fragment_playlist), ItemInteractionLi
private lateinit var mPlaylistView: View
private var isFirstRun: Boolean = true

private val mPlaylistRepository: PlaylistRepository by lazy {
PlaylistRepository(requireContext())
}

private fun initializeBrowser() {
mBrowserFuture =
MediaBrowser.Builder(
Expand Down Expand Up @@ -281,25 +276,6 @@ class PlaylistFragment : Fragment(R.layout.fragment_playlist), ItemInteractionLi
totalFileSize += it.mediaFileBytes
}
}
mPlaylistModel.items.forEach { playlistItemModel ->
if (!PlaylistUtils.isPlaylistItemCached(playlistItemModel)) {
val isDownloadQueueModelExists =
mPlaylistRepository.isHlsContentQueueModelExists(playlistItemModel.id)
?: false
if (playlistItemModel.isCached && MediaUtils.isHlsFile(playlistItemModel.mediaPath) && !isDownloadQueueModelExists) {
mPlaylistRepository.insertHlsContentQueueModel(
HlsContentQueueModel(
playlistItemModel.id,
HlsContentQueueModel.HlsContentStatus.NOT_READY.name
)
)
}
}
}
if (isFirstRun) {
PlaylistUtils.checkAndStartHlsDownload(requireContext())
isFirstRun = false
}

activity?.runOnUiThread {
if (totalFileSize > 0) {
Expand Down Expand Up @@ -491,13 +467,11 @@ class PlaylistFragment : Fragment(R.layout.fragment_playlist), ItemInteractionLi
}
mScope.launch {
val selectedPlaylistItem = mPlaylistModel.items[position]
val lastPlayedPositionModel =
mPlaylistRepository.getLastPlayedPositionByPlaylistItemId(selectedPlaylistItem.id)

activity?.runOnUiThread {
browser.clearMediaItems()
browser.addMediaItems(subItemMediaList)
browser.seekTo(position, lastPlayedPositionModel?.lastPlayedPosition ?: 0)
browser.seekTo(position, 0)
browser.shuffleModeEnabled = isShuffle
browser.prepare()
browser.play()
Expand Down

This file was deleted.

This file was deleted.

Loading
Loading