Search in sources :

Example 1 with AddToListsDialogFragment

use of com.odysee.app.dialog.AddToListsDialogFragment in project odysee-android by OdyseeTeam.

the class MainActivity method handleAddUrlToList.

public void handleAddUrlToList(String url, String builtInId) {
    if (!Arrays.asList(OdyseeCollection.BUILT_IN_ID_FAVORITES, OdyseeCollection.BUILT_IN_ID_WATCHLATER).contains(builtInId)) {
        // add to list. show bottom sheet dialog with playlists
        AddToListsDialogFragment dialog = AddToListsDialogFragment.newInstance();
        dialog.setUrl(url);
        dialog.show(getSupportFragmentManager(), AddToListsDialogFragment.TAG);
        return;
    }
    Executors.newSingleThreadExecutor().execute(new Runnable() {

        @Override
        public void run() {
            try {
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                DatabaseHelper.addCollectionItem(builtInId, url, db);
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        showMessage(getString(R.string.added_to_list, OdyseeCollection.BUILT_IN_ID_FAVORITES.equalsIgnoreCase(builtInId) ? getString(R.string.favorites) : getString(R.string.watch_later)), getString(R.string.see_list), new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                // open the playlist fragment with the id
                                openPlaylistFragment(builtInId);
                            }
                        });
                    }
                });
                // initiate sync afterwards
                saveSharedUserState();
            } catch (SQLiteException ex) {
                // failed
                showError(getString(R.string.could_not_add_to_list, OdyseeCollection.BUILT_IN_ID_FAVORITES.equalsIgnoreCase(builtInId) ? getString(R.string.favorites) : getString(R.string.watch_later)));
            }
        }
    });
}
Also used : AddToListsDialogFragment(com.odysee.app.dialog.AddToListsDialogFragment) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteException(android.database.sqlite.SQLiteException) PlayerView(com.google.android.exoplayer2.ui.PlayerView) RecyclerView(androidx.recyclerview.widget.RecyclerView) ListView(android.widget.ListView) NavigationBarView(com.google.android.material.navigation.NavigationBarView) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) TextView(android.widget.TextView)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 SQLiteException (android.database.sqlite.SQLiteException)1 View (android.view.View)1 WebView (android.webkit.WebView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 PlayerView (com.google.android.exoplayer2.ui.PlayerView)1 BottomNavigationView (com.google.android.material.bottomnavigation.BottomNavigationView)1 NavigationBarView (com.google.android.material.navigation.NavigationBarView)1 AddToListsDialogFragment (com.odysee.app.dialog.AddToListsDialogFragment)1