package app.fedilab.fedilabtube.activities; /* Copyright 2020 Thomas Schneider * * This file is a part of TubeLab * * This program is free software; you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * Public License for more details. * * You should have received a copy of the GNU General Public License along with TubeLab; if not, * see . */ import android.content.Intent; import android.os.Bundle; import android.view.MenuItem; import android.widget.Toast; import androidx.fragment.app.FragmentTransaction; import app.fedilab.fedilabtube.R; import app.fedilab.fedilabtube.client.data.PlaylistData; import app.fedilab.fedilabtube.fragment.DisplayVideosFragment; import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.helper.HelperInstance; import app.fedilab.fedilabtube.helper.PlaylistExportHelper; import app.fedilab.fedilabtube.helper.Theme; import app.fedilab.fedilabtube.viewmodel.TimelineVM; import es.dmoral.toasty.Toasty; public class PlaylistsActivity extends BaseActivity { private final int PICK_IMPORT = 5556; @Override protected void onCreate(Bundle savedInstanceState) { Theme.setTheme(this, HelperInstance.getLiveInstance(this),false); super.onCreate(savedInstanceState); if (getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.activity_playlists); PlaylistData.Playlist playlist; Bundle b = getIntent().getExtras(); if (b != null) { playlist = b.getParcelable("playlist"); if (playlist == null) { return; } } else { Toasty.error(PlaylistsActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); return; } setTitle(playlist.getDisplayName()); if (savedInstanceState == null) { DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment(); Bundle bundle = new Bundle(); bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.VIDEOS_IN_PLAYLIST); bundle.putSerializable("playlistId", playlist.getUuid()); displayVideosFragment.setArguments(bundle); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.add(R.id.nav_host_fragment, displayVideosFragment).commit(); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == PICK_IMPORT && resultCode == RESULT_OK) { if (data == null || data.getData() == null) { Toasty.error(PlaylistsActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); return; } PlaylistExportHelper.manageIntentUrl(PlaylistsActivity.this, data); } else if (requestCode == PICK_IMPORT) { Toasty.error(PlaylistsActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); } } @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { finish(); return true; } return super.onOptionsItemSelected(item); } }