Commit 91a37474 authored by Geoffrey Métais's avatar Geoffrey Métais

Setup DialogActivity for subs DL on TV

parent d0567165
......@@ -14,6 +14,27 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<org.videolan.vlc.gui.MultiSelectionSpinner
android:id="@+id/language_list_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:focusable="true"
app:layout_constraintEnd_toStartOf="@+id/right_vertical_guideline"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintTop_toTopOf="@+id/top_horizontal_guideline" />
<TextView
android:id="@+id/languages_list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/language_to_download"
android:textColor="?attr/font_default"
app:layout_constraintStart_toStartOf="@+id/left_vertical_guideline"
app:layout_constraintEnd_toStartOf="@+id/language_list_spinner"
app:layout_constraintTop_toTopOf="@+id/top_horizontal_guideline" />
<CheckBox
android:id="@+id/manual_search_checkBox"
android:layout_width="wrap_content"
......@@ -155,26 +176,5 @@
app:layout_constraintStart_toStartOf="@+id/left_vertical_guideline"
app:layout_goneMarginTop="40dp" />
<org.videolan.vlc.gui.MultiSelectionSpinner
android:id="@+id/language_list_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:focusable="true"
app:layout_constraintEnd_toStartOf="@+id/right_vertical_guideline"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintTop_toTopOf="@+id/top_horizontal_guideline" />
<TextView
android:id="@+id/languages_list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/language_to_download"
android:textColor="?attr/font_default"
app:layout_constraintStart_toStartOf="@+id/left_vertical_guideline"
app:layout_constraintEnd_toStartOf="@+id/language_list_spinner"
app:layout_constraintTop_toTopOf="@+id/top_horizontal_guideline" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
......@@ -24,15 +24,20 @@
package org.videolan.vlc.gui;
import android.os.Bundle;
import androidx.fragment.app.FragmentManager;
import android.text.TextUtils;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.gui.dialogs.NetworkServerDialog;
import org.videolan.vlc.gui.dialogs.VlcDialog;
import org.videolan.vlc.gui.dialogs.VlcLoginDialog;
import org.videolan.vlc.gui.dialogs.VlcProgressDialog;
import org.videolan.vlc.gui.dialogs.VlcQuestionDialog;
import org.videolan.vlc.gui.network.MRLPanelFragment;
import org.videolan.vlc.media.MediaUtils;
import java.util.List;
import androidx.fragment.app.FragmentManager;
public class DialogActivity extends BaseActivity {
......@@ -41,6 +46,8 @@ public class DialogActivity extends BaseActivity {
public static final String KEY_PROGRESS = "ProgressDialog";
public static final String KEY_STREAM = "streamDialog";
public static final String KEY_SERVER = "serverDialog";
public static final String KEY_SUBS_DL = "subsdlDialog";
public static final String EXTRA_MEDIALIST = "extra_media";
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -50,16 +57,12 @@ public class DialogActivity extends BaseActivity {
finish();
return;
}
if (key.startsWith(KEY_LOGIN))
setupLoginDialog(key);
else if (key.startsWith(KEY_QUESTION))
setupQuestionDialog(key);
else if (key.startsWith(KEY_PROGRESS))
setupProgressDialog(key);
else if (KEY_STREAM.equals(key))
setupStreamDialog();
else if (KEY_SERVER.equals(key))
setupServerDialog();
if (key.startsWith(KEY_LOGIN)) setupLoginDialog(key);
else if (key.startsWith(KEY_QUESTION)) setupQuestionDialog(key);
else if (key.startsWith(KEY_PROGRESS)) setupProgressDialog(key);
else if (KEY_STREAM.equals(key)) setupStreamDialog();
else if (KEY_SERVER.equals(key)) setupServerDialog();
else if (KEY_SUBS_DL.equals(key)) setupSubsDialog();
}
private void setupStreamDialog() {
......@@ -70,6 +73,12 @@ public class DialogActivity extends BaseActivity {
new NetworkServerDialog().show(getSupportFragmentManager(), "fragment_mrl");
}
private void setupSubsDialog() {
final List<MediaWrapper> medialist = getIntent().getParcelableArrayListExtra(EXTRA_MEDIALIST);
if (medialist != null) MediaUtils.INSTANCE.getSubs(this, medialist);
else finish();
}
private void setupLoginDialog(String key) {
VlcLoginDialog dialog = new VlcLoginDialog();
startVlcDialog(key, dialog);
......
package org.videolan.vlc.gui.dialogs
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import org.videolan.vlc.R
import org.videolan.vlc.databinding.SubtitleDownloadFragmentBinding
import org.videolan.vlc.gui.OnItemSelectListener
......@@ -65,13 +65,9 @@ class SubtitleDownloadFragment : androidx.fragment.app.Fragment() {
}
companion object {
lateinit var subtitleDownloadFragment: SubtitleDownloadFragment
fun newInstance(mediaPath: String): SubtitleDownloadFragment {
subtitleDownloadFragment = SubtitleDownloadFragment()
val args = Bundle()
args.putString(MEDIA_PATH, mediaPath)
subtitleDownloadFragment.arguments = args
val subtitleDownloadFragment = SubtitleDownloadFragment()
subtitleDownloadFragment.arguments = Bundle(1).apply { putString(MEDIA_PATH, mediaPath) }
return subtitleDownloadFragment
}
}
......
......@@ -4,9 +4,6 @@ import android.content.Context
import android.net.Uri
import android.os.Bundle
import android.view.Gravity
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
......@@ -18,6 +15,7 @@ import kotlinx.coroutines.experimental.isActive
import org.videolan.tools.coroutineScope
import org.videolan.vlc.R
import org.videolan.vlc.databinding.SubtitleDownloaderDialogBinding
import org.videolan.vlc.gui.DialogActivity
import org.videolan.vlc.gui.helpers.UiTools.deleteSubtitleDialog
import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.util.VLCDownloadManager
......@@ -28,20 +26,16 @@ const val MEDIA_PATH = "MEDIA_PATH"
class SubtitleDownloaderDialogFragment: androidx.fragment.app.DialogFragment() {
private lateinit var adapter: ViewPagerAdapter
lateinit var paths: List<String>
private lateinit var paths: List<String>
private lateinit var viewModel: SubtitlesModel
private lateinit var toast: Toast
val listEventActor = coroutineScope.actor<SubtitleEvent> {
for (subtitleEvent in channel) if(isActive) when (subtitleEvent) {
is Click -> {
when(subtitleEvent.item.state) {
State.NotDownloaded -> {
VLCDownloadManager.download(context!!, subtitleEvent.item)
}
State.Downloaded -> deleteSubtitleDialog(context,
{ _, _ -> viewModel.deleteSubtitle(subtitleEvent.item.mediaPath, subtitleEvent.item.idSubtitle) }, { _, _ -> })
}
is Click -> when(subtitleEvent.item.state) {
State.NotDownloaded -> VLCDownloadManager.download(context!!, subtitleEvent.item)
State.Downloaded -> deleteSubtitleDialog(context,
{ _, _ -> viewModel.deleteSubtitle(subtitleEvent.item.mediaPath, subtitleEvent.item.idSubtitle) }, { _, _ -> })
}
is LongClick -> {
@StringRes val message = when(subtitleEvent.item.state) {
......@@ -51,8 +45,7 @@ class SubtitleDownloaderDialogFragment: androidx.fragment.app.DialogFragment() {
else -> return@actor
}
if (::toast.isInitialized)
toast.cancel()
if (::toast.isInitialized) toast.cancel()
toast = Toast.makeText(activity, message, Toast.LENGTH_SHORT)
toast.setGravity(Gravity.TOP,0,100)
toast.show()
......@@ -94,6 +87,11 @@ class SubtitleDownloaderDialogFragment: androidx.fragment.app.DialogFragment() {
outState.putStringArrayList(MEDIA_PATHS, ArrayList(paths))
}
override fun onDestroy() {
super.onDestroy()
(activity as? DialogActivity)?.finish()
}
companion object {
fun newInstance(mediaPaths: List<String>): SubtitleDownloaderDialogFragment {
val subtitleDownloaderDialogFragment = SubtitleDownloaderDialogFragment()
......
......@@ -27,18 +27,6 @@ import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import androidx.leanback.app.BackgroundManager;
import androidx.leanback.app.DetailsSupportFragment;
import androidx.leanback.widget.Action;
import androidx.leanback.widget.ArrayObjectAdapter;
import androidx.leanback.widget.ClassPresenterSelector;
import androidx.leanback.widget.DetailsOverviewRow;
import androidx.leanback.widget.FullWidthDetailsOverviewRowPresenter;
import androidx.leanback.widget.ListRow;
import androidx.leanback.widget.ListRowPresenter;
import androidx.leanback.widget.OnActionClickedListener;
import androidx.fragment.app.FragmentActivity;
import androidx.core.content.ContextCompat;
import android.text.TextUtils;
import android.widget.Toast;
......@@ -58,6 +46,19 @@ import org.videolan.vlc.util.WorkersKt;
import java.util.List;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.leanback.app.BackgroundManager;
import androidx.leanback.app.DetailsSupportFragment;
import androidx.leanback.widget.Action;
import androidx.leanback.widget.ArrayObjectAdapter;
import androidx.leanback.widget.ClassPresenterSelector;
import androidx.leanback.widget.DetailsOverviewRow;
import androidx.leanback.widget.FullWidthDetailsOverviewRowPresenter;
import androidx.leanback.widget.ListRow;
import androidx.leanback.widget.ListRowPresenter;
import androidx.leanback.widget.OnActionClickedListener;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public class MediaItemDetailsFragment extends DetailsSupportFragment implements PlaybackService.Client.Callback {
private static final String TAG = "MediaItemDetailsFragment";
......@@ -170,7 +171,7 @@ public class MediaItemDetailsFragment extends DetailsSupportFragment implements
TvUtil.INSTANCE.openMedia(activity, media, null);
break;
case ID_DL_SUBS:
MediaUtils.INSTANCE.getSubs(getActivity(), media);
MediaUtils.INSTANCE.getSubs(requireActivity(), media);
break;
case ID_PLAY_ALL:
if (mediaList != null) {
......
......@@ -3,13 +3,15 @@ package org.videolan.vlc.media
import android.app.ProgressDialog
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.net.Uri
import android.os.Handler
import android.os.Looper
import android.provider.MediaStore
import android.provider.OpenableColumns
import androidx.fragment.app.FragmentActivity
import android.text.TextUtils
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.channels.actor
......@@ -22,6 +24,7 @@ import org.videolan.medialibrary.media.Playlist
import org.videolan.vlc.PlaybackService
import org.videolan.vlc.R
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.gui.DialogActivity
import org.videolan.vlc.gui.dialogs.SubtitleDownloaderDialogFragment
import org.videolan.vlc.util.FileUtils
import org.videolan.vlc.util.Permissions
......@@ -29,6 +32,7 @@ import org.videolan.vlc.util.Util
import org.videolan.vlc.util.getFromMl
import org.videolan.vlc.viewmodels.paged.MLPagedModel
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.min
private const val TAG = "VLC/MediaUtils"
......@@ -39,18 +43,23 @@ object MediaUtils : CoroutineScope {
override val coroutineContext = Dispatchers.Main.immediate
fun getSubs(activity: androidx.fragment.app.FragmentActivity, mediaList: List<MediaWrapper>) {
showSubtitleDownloaderDialogFragment(activity, mediaList.map { it.uri.path })
if (activity is AppCompatActivity) showSubtitleDownloaderDialogFragment(activity, mediaList.map { it.uri.path })
else {
val intent = Intent(activity, DialogActivity::class.java).setAction(DialogActivity.KEY_SUBS_DL)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.putParcelableArrayListExtra(DialogActivity.EXTRA_MEDIALIST, mediaList as? ArrayList ?: ArrayList(mediaList))
ContextCompat.startActivity(activity, intent, null)
}
}
fun getSubs(activity: androidx.fragment.app.FragmentActivity, media: MediaWrapper) {
showSubtitleDownloaderDialogFragment(activity, listOf(media.uri.path))
getSubs(activity, listOf(media))
}
fun showSubtitleDownloaderDialogFragment(activity: androidx.fragment.app.FragmentActivity, mediaPaths: List<String>) {
val callBack = java.lang.Runnable {
SubtitleDownloaderDialogFragment.newInstance(mediaPaths).show(activity.supportFragmentManager, "Subtitle_downloader")
}
if (Permissions.canWriteStorage()) callBack.run()
else Permissions.askWriteStoragePermission(activity, false, callBack)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment