Skip to content
Snippets Groups Projects
Commit 43c800f4 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Remove scan progress display in MainActivity

parent d1ecf3e4
No related branches found
No related tags found
No related merge requests found
......@@ -103,7 +103,7 @@ import org.videolan.vlc.util.WeakHandler;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AudioPlayerContainerActivity implements DevicesDiscoveryCb, FilterQueryProvider, NavigationView.OnNavigationItemSelectedListener, ExtensionManagerService.ExtensionManagerActivity, SearchView.OnQueryTextListener, MenuItemCompat.OnActionExpandListener {
public class MainActivity extends AudioPlayerContainerActivity implements FilterQueryProvider, NavigationView.OnNavigationItemSelectedListener, ExtensionManagerService.ExtensionManagerActivity, SearchView.OnQueryTextListener, MenuItemCompat.OnActionExpandListener {
public final static String TAG = "VLC/MainActivity";
private static final String PREF_FIRST_RUN = "first_run";
......@@ -124,18 +124,13 @@ public class MainActivity extends AudioPlayerContainerActivity implements Device
private NavigationView mNavigationView;
private ActionBarDrawerToggle mDrawerToggle;
private View mInfoLayout;
private ProgressBar mInfoProgress;
private TextView mInfoText;
private int mCurrentFragmentId;
private int mVersionNumber = -1;
private boolean mFirstRun = false;
private boolean mScanNeeded = false;
private boolean mParsing = false;
private Handler mHandler = new MainActivityHandler(this);
Menu mMenu;
private Menu mMenu;
private SearchView mSearchView;
// Extensions management
......@@ -182,12 +177,6 @@ public class MainActivity extends AudioPlayerContainerActivity implements Device
mNavigationView.setCheckedItem(mCurrentFragmentId);
}
/* Initialize UI variables */
mInfoLayout = findViewById(R.id.info_layout);
mInfoProgress = (ProgressBar) findViewById(R.id.info_progress);
mInfoText = (TextView) findViewById(R.id.info_text);
/* Set up the action bar */
prepareActionBar();
......@@ -223,7 +212,7 @@ public class MainActivity extends AudioPlayerContainerActivity implements Device
* the info dialog. If (for any reason) the dialog is not shown,
* open the menu after a short delay.
*/
mHandler.postDelayed(new Runnable() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mDrawerLayout.openDrawer(mNavigationView);
......@@ -357,30 +346,17 @@ public class MainActivity extends AudioPlayerContainerActivity implements Device
protected void onResume() {
super.onResume();
if (mMediaLibrary.isInitiated()) {
mMediaLibrary.addDeviceDiscoveryCb(this);
/* Load media items from database and storage */
if (mScanNeeded && Permissions.canReadStorage())
mMediaLibrary.reload();
else
restoreCurrentList();
} else
setupMediaLibraryReceiver();
}
mNavigationView.setNavigationItemSelectedListener(this);
mNavigationView.setCheckedItem(mCurrentFragmentId);
mCurrentFragmentId = mSettings.getInt("fragment_id", R.id.nav_video);
}
private void setupMediaLibraryReceiver() {
final BroadcastReceiver libraryReadyReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
LocalBroadcastManager.getInstance(MainActivity.this).unregisterReceiver(this);
mMediaLibrary.addDeviceDiscoveryCb(MainActivity.this);
}
};
LocalBroadcastManager.getInstance(this).registerReceiver(libraryReadyReceiver, new IntentFilter(VLCApplication.ACTION_MEDIALIBRARY_READY));
}
@Override
protected void onResumeFragments() {
super.onResumeFragments();
......@@ -418,7 +394,6 @@ public class MainActivity extends AudioPlayerContainerActivity implements Device
@Override
protected void onPause() {
super.onPause();
mMediaLibrary.removeDeviceDiscoveryCb(this);
mNavigationView.setNavigationItemSelectedListener(null);
if (getChangingConfigurations() == 0) {
/* Check for an ongoing scan that needs to be resumed during onResume */
......@@ -818,99 +793,6 @@ public class MainActivity extends AudioPlayerContainerActivity implements Device
((Filterable) current).setSearchVisibility(visible);
}
private static class MainActivityHandler extends WeakHandler<MainActivity> {
public MainActivityHandler(MainActivity owner) {
super(owner);
}
@Override
public void handleMessage(Message msg) {
MainActivity ma = getOwner();
if(ma == null) return;
switch (msg.what) {
case ACTIVITY_SHOW_INFOLAYOUT:
if (ma.mInfoLayout.getVisibility() != View.VISIBLE)
ma.mInfoLayout.setVisibility(View.VISIBLE);
break;
case ACTIVITY_HIDE_INFOLAYOUT:
removeMessages(ACTIVITY_SHOW_INFOLAYOUT);
ma.mInfoLayout.setVisibility(View.GONE);
break;
case ACTIVITY_SHOW_PROGRESSBAR:
ma.mInfoProgress.setVisibility(View.VISIBLE);
ma.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
break;
case ACTIVITY_HIDE_PROGRESSBAR:
ma.mInfoProgress.setVisibility(View.GONE);
ma.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
break;
case ACTIVITY_UPDATE_PROGRESS:
ma.mInfoProgress.setVisibility(View.VISIBLE);
ma.mInfoLayout.setVisibility(View.VISIBLE);
int max = msg.arg1;
int progress = msg.arg2;
ma.mInfoProgress.setMax(max);
ma.mInfoProgress.setProgress(progress);
ma.mInfoText.setText("");
break;
case ACTIVITY_SHOW_TEXTINFO:
String info = (String) msg.obj;
ma.mInfoText.setText(info);
if (info == null) {
/* Cancel any upcoming visibility change */
removeMessages(ACTIVITY_SHOW_INFOLAYOUT);
ma.mInfoLayout.setVisibility(View.GONE);
} else {
/* Slightly delay the appearance of the progress bar to avoid unnecessary flickering */
if (!hasMessages(ACTIVITY_SHOW_INFOLAYOUT))
sendEmptyMessageDelayed(ACTIVITY_SHOW_INFOLAYOUT, 300);
}
break;
}
}
}
public void showProgressBar() {
mHandler.obtainMessage(ACTIVITY_SHOW_PROGRESSBAR).sendToTarget();
}
public void hideProgressBar() {
mHandler.obtainMessage(ACTIVITY_HIDE_PROGRESSBAR).sendToTarget();
}
public void sendTextInfo(String info, int progress, int max) {
mHandler.obtainMessage(ACTIVITY_SHOW_TEXTINFO, max, progress, info).sendToTarget();
}
public void clearTextInfo() {
mHandler.obtainMessage(ACTIVITY_SHOW_TEXTINFO, 0, 100, null).sendToTarget();
}
@Override
public void onDiscoveryStarted(String entryPoint) {}
@Override
public void onDiscoveryProgress(String entryPoint) {
mHandler.obtainMessage(ACTIVITY_SHOW_TEXTINFO, entryPoint).sendToTarget();
}
@Override
public void onDiscoveryCompleted(String entryPoint) {
if (!mParsing)
mHandler.obtainMessage(ACTIVITY_HIDE_INFOLAYOUT).sendToTarget();
}
@Override
public void onParsingStatsUpdated(int percent) {
mParsing = percent < 100;
if (mParsing)
mHandler.obtainMessage(ACTIVITY_UPDATE_PROGRESS, 100, percent).sendToTarget();
else
mHandler.obtainMessage(ACTIVITY_HIDE_INFOLAYOUT).sendToTarget();
}
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// This should not happen
......
......@@ -61,7 +61,6 @@ import org.videolan.vlc.gui.view.ContextMenuRecyclerView;
import org.videolan.vlc.gui.view.FastScroller;
import org.videolan.vlc.gui.view.SwipeRefreshLayout;
import org.videolan.vlc.interfaces.Filterable;
import org.videolan.vlc.interfaces.IBrowser;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.FileUtils;
import org.videolan.vlc.util.WeakHandler;
......@@ -71,7 +70,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Random;
public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDiscoveryCb, SwipeRefreshLayout.OnRefreshListener, MediaBrowser.EventListener, IBrowser, ViewPager.OnPageChangeListener, Medialibrary.ArtistsAddedCb, Medialibrary.ArtistsModifiedCb, Medialibrary.AlbumsAddedCb, Medialibrary.AlbumsModifiedCb, MediaAddedCb, MediaUpdatedCb, TabLayout.OnTabSelectedListener, Filterable {
public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDiscoveryCb, SwipeRefreshLayout.OnRefreshListener, MediaBrowser.EventListener, ViewPager.OnPageChangeListener, Medialibrary.ArtistsAddedCb, Medialibrary.ArtistsModifiedCb, Medialibrary.AlbumsAddedCb, Medialibrary.AlbumsModifiedCb, MediaAddedCb, MediaUpdatedCb, TabLayout.OnTabSelectedListener, Filterable {
public final static String TAG = "VLC/AudioBrowserFragment";
private MediaBrowser mMediaBrowser;
......@@ -475,26 +474,6 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis
mService.append(mTracksToAppend);
}
@Override
public void showProgressBar() {
mMainActivity.showProgressBar();
}
@Override
public void hideProgressBar() {
mMainActivity.hideProgressBar();
}
@Override
public void clearTextInfo() {
mMainActivity.clearTextInfo();
}
@Override
public void sendTextInfo(String info, int progress, int max) {
mMainActivity.sendTextInfo(info, progress, max);
}
TabLayout.TabLayoutOnPageChangeListener tcl = new TabLayout.TabLayoutOnPageChangeListener(mTabLayout);
@Override
......@@ -745,7 +724,6 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis
mParsing = percent < 100;
if (percent == 100) {
mHandler.sendEmptyMessage(UPDATE_LIST);
hideProgressBar();
} else if (!mSwipeRefreshLayout.isRefreshing())
mHandler.sendEmptyMessage(SET_REFRESHING);
}
......
/*
* *************************************************************************
* IBrowser.java
* **************************************************************************
* Copyright © 2015 VLC authors and VideoLAN
*
* 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* ***************************************************************************
*/
package org.videolan.vlc.interfaces;
public interface IBrowser {
void showProgressBar();
void hideProgressBar();
void clearTextInfo();
void sendTextInfo(String info, int progress, int max);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment