[Android] Fix browser not going back on login cancel
Geoffrey Métais
git at videolan.org
Tue Jul 11 17:48:50 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jul 11 16:37:29 2017 +0200| [aacaf88a2cdcec3174d2dcb213ae13486c28c377] | committer: Geoffrey Métais
Fix browser not going back on login cancel
> https://code.videolan.org/videolan/vlc-android/commit/aacaf88a2cdcec3174d2dcb213ae13486c28c377
---
.../vlc/gui/browser/BaseBrowserFragment.java | 42 ++++++++++++++++++---
.../videolan/vlc/gui/dialogs/VlcLoginDialog.java | 9 +++++
.../vlc/gui/tv/browser/MediaSortedFragment.java | 43 ++++++++++++++++------
3 files changed, 76 insertions(+), 18 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index d501948a0..5628254e3 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -24,7 +24,10 @@ package org.videolan.vlc.gui.browser;
import android.annotation.TargetApi;
import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -37,6 +40,7 @@ import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
+import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.LinearLayoutManager;
@@ -64,6 +68,7 @@ import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.InfoActivity;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.dialogs.SavePlaylistDialog;
+import org.videolan.vlc.gui.dialogs.VlcLoginDialog;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.view.ContextMenuRecyclerView;
import org.videolan.vlc.gui.view.SwipeRefreshLayout;
@@ -108,7 +113,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
protected MediaWrapper mCurrentMedia;
protected int mSavedPosition = -1, mFavorites = 0;
public boolean mRoot;
- boolean goBack = false;
+ private boolean goBack = false;
private final boolean mShowHiddenFiles;
private SparseArray<ArrayList<MediaWrapper>> mFoldersContentLists;
@@ -190,18 +195,34 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
}
@Override
+ public void onStart() {
+ super.onStart();
+ LocalBroadcastManager.getInstance(VLCApplication.getAppContext()).registerReceiver(mLocalReceiver, new IntentFilter(VlcLoginDialog.ACTION_DIALOG_CANCELED));
+ }
+
+ @Override
public void onResume() {
super.onResume();
+ if (mCurrentMedia != null)
+ setSearchVisibility(false);
if (goBack)
goBack();
- setSearchVisibility(false);
- restoreList();
+ else
+ restoreList();
}
@Override
public void onHiddenChanged(boolean hidden) {
super.onHiddenChanged(hidden);
- if (!hidden && !mRoot && mFabPlay != null) {
+ if (mRoot) {
+ LocalBroadcastManager.getInstance(VLCApplication.getAppContext()).unregisterReceiver(mLocalReceiver);
+ runOnBrowserThread(new Runnable() {
+ @Override
+ public void run() {
+ releaseBrowser();
+ }
+ });
+ } else if (!hidden && mFabPlay != null) {
mFabPlay.setImageResource(R.drawable.ic_fab_play);
updateFab();
}
@@ -209,6 +230,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
public void onStop(){
super.onStop();
+ LocalBroadcastManager.getInstance(VLCApplication.getAppContext()).unregisterReceiver(mLocalReceiver);
runOnBrowserThread(new Runnable() {
@Override
public void run() {
@@ -338,8 +360,6 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
@Override
public void run() {
onUpdateFinished(mAdapter);
- if (!isResumed())
- goBack = true;
}
});
}
@@ -908,4 +928,14 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
public int sortDirection(int sortby) {
return mAdapter.sortDirection(sortby);
}
+
+ private BroadcastReceiver mLocalReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (isResumed())
+ goBack();
+ else
+ goBack = true;
+ }
+ };
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcLoginDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcLoginDialog.java
index 19b54f422..142fedbe0 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcLoginDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcLoginDialog.java
@@ -25,9 +25,11 @@
package org.videolan.vlc.gui.dialogs;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
+import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.preference.PreferenceManager;
import android.view.View;
import android.widget.EditText;
@@ -43,6 +45,7 @@ import org.videolan.vlc.util.AndroidDevices;
public class VlcLoginDialog extends VlcDialog<Dialog.LoginDialog, VlcLoginDialogBinding> implements View.OnFocusChangeListener {
SharedPreferences mSettings;
+ public final static String ACTION_DIALOG_CANCELED = "action_dialog_canceled";
@Override
int getLayout() {
@@ -81,4 +84,10 @@ public class VlcLoginDialog extends VlcDialog<Dialog.LoginDialog, VlcLoginDialog
if (hasFocus)
UiTools.setKeyboardVisibility(v, v instanceof EditText);
}
+
+ @Override
+ public void onDestroy() {
+ LocalBroadcastManager.getInstance(VLCApplication.getAppContext()).sendBroadcast(new Intent(ACTION_DIALOG_CANCELED));
+ super.onDestroy();
+ }
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaSortedFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaSortedFragment.java
index 4fac44bda..98012b8db 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaSortedFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaSortedFragment.java
@@ -25,7 +25,10 @@
package org.videolan.vlc.gui.tv.browser;
import android.annotation.TargetApi;
+import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -33,6 +36,7 @@ import android.os.Handler;
import android.os.HandlerThread;
import android.os.Process;
import android.support.annotation.NonNull;
+import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.preference.PreferenceManager;
import org.videolan.libvlc.Media;
@@ -40,6 +44,7 @@ import org.videolan.libvlc.util.MediaBrowser;
import org.videolan.medialibrary.Medialibrary;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.VLCApplication;
+import org.videolan.vlc.gui.dialogs.VlcLoginDialog;
import org.videolan.vlc.gui.tv.browser.interfaces.BrowserActivityInterface;
import org.videolan.vlc.util.VLCInstance;
@@ -97,6 +102,12 @@ public abstract class MediaSortedFragment extends SortedBrowserFragment implemen
}
@Override
+ public void onStart() {
+ super.onStart();
+ LocalBroadcastManager.getInstance(VLCApplication.getAppContext()).registerReceiver(mLocalReceiver, new IntentFilter(VlcLoginDialog.ACTION_DIALOG_CANCELED));
+ }
+
+ @Override
public void onResume() {
super.onResume();
if (goBack)
@@ -108,19 +119,10 @@ public abstract class MediaSortedFragment extends SortedBrowserFragment implemen
((BrowserActivityInterface)getActivity()).updateEmptyView(false);
}
- private Runnable releaseBrowser = new Runnable() {
- @Override
- public void run() {
- if (mMediaBrowser != null) {
- mMediaBrowser.release();
- mMediaBrowser = null;
- }
- }
- };
-
@Override
public void onStop() {
super.onStop();
+ LocalBroadcastManager.getInstance(VLCApplication.getAppContext()).unregisterReceiver(mLocalReceiver);
runOnBrowserThread(releaseBrowser);
}
@@ -168,9 +170,26 @@ public abstract class MediaSortedFragment extends SortedBrowserFragment implemen
if (isResumed()) {
sort();
mHandler.sendEmptyMessage(HIDE_LOADING);
- } else
- goBack = true;
+ }
}
});
}
+
+ private Runnable releaseBrowser = new Runnable() {
+ @Override
+ public void run() {
+ if (mMediaBrowser != null) {
+ mMediaBrowser.release();
+ mMediaBrowser = null;
+ }
+ }
+ };
+
+ private BroadcastReceiver mLocalReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (!isResumed())
+ goBack = true;
+ }
+ };
}
More information about the Android
mailing list