Use a progress bar in scanprefs

This commit is contained in:
Adrian Ulrich 2017-04-08 12:43:42 +02:00
parent f2c9bf6b14
commit fee64685bd
4 changed files with 63 additions and 27 deletions

View File

@ -99,10 +99,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:text="@android:string/cancel">
</Button>
<TextView
android:id="@+id/media_stats_progress"
<ProgressBar
android:id="@+id/media_stats_progress_bar"
android:paddingTop="24dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="?android:attr/progressBarStyleHorizontal" />
<TextView
android:id="@+id/media_stats_progress_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/empty" />
</LinearLayout>

View File

@ -64,6 +64,19 @@ public class MediaLibrary {
int _nativeLibraryCount;
int _nativeLastMtime;
}
/**
* The progress of a currently scan, if any
* is running
*/
public static class ScanProgress {
public boolean isRunning;
public String lastFile;
public int seen;
public int changed;
public int total;
}
/**
* Cached preferences, may be null
*/
@ -170,15 +183,11 @@ public class MediaLibrary {
* Whacky function to get the current scan progress
*
* @param context the context to use
* @return a description of the progress, null if no scan is running
* @return a description of the progress
*/
public static String describeScanProgress(Context context) {
public static MediaLibrary.ScanProgress describeScanProgress(Context context) {
MediaLibraryBackend backend = getBackend(context); // also initialized sScanner
MediaScanner.MediaScanPlan.Statistics stats = sScanner.getScanStatistics();
String msg = null;
if (stats.lastFile != null)
msg = stats.lastFile+" ("+stats.changed+" / "+stats.seen+")";
return msg;
return sScanner.describeScanProgress();
}

View File

@ -152,10 +152,20 @@ public class MediaScanner implements Handler.Callback {
/**
* Returns some scan statistics
*
* @return a stats object
* @return a MediaLibrary.ScanProgress object
*/
MediaScanPlan.Statistics getScanStatistics() {
return mScanPlan.getStatistics();
public MediaLibrary.ScanProgress describeScanProgress() {
MediaLibrary.ScanProgress progress = new MediaLibrary.ScanProgress();
MediaLibrary.Preferences prefs = MediaLibrary.getPreferences(mContext);
MediaScanPlan.Statistics stats = mScanPlan.getStatistics();
progress.isRunning = (stats.lastFile != null);
progress.lastFile = stats.lastFile;
progress.seen = stats.seen;
progress.changed = stats.changed;
progress.total = prefs._nativeLibraryCount;
return progress;
}
private static final int MSG_SCAN_RPC = 0;
@ -242,8 +252,7 @@ public class MediaScanner implements Handler.Callback {
* @param visible if true, the notification is visible (and will get updated)
*/
private void updateNotification(boolean visible) {
MediaScanPlan.Statistics stats = mScanPlan.getStatistics();
MediaLibrary.Preferences prefs = MediaLibrary.getPreferences(mContext);
MediaLibrary.ScanProgress progress = describeScanProgress();
NotificationManager manager = (NotificationManager) mContext.getSystemService(mContext.NOTIFICATION_SERVICE);
if (visible) {
@ -252,10 +261,10 @@ public class MediaScanner implements Handler.Callback {
mLastNotification = nowTime;
int icon = R.drawable.status_scan_0 + (mLastNotification % 5);
String title = mContext.getResources().getString(R.string.media_library_scan_running);
String content = stats.lastFile;
String content = progress.lastFile;
Notification notification = new Notification.Builder(mContext)
.setProgress(prefs._nativeLibraryCount, stats.seen, false)
.setProgress(progress.total, progress.seen, false)
.setContentTitle(title)
.setContentText(content)
.setSmallIcon(icon)

View File

@ -29,6 +29,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.util.Timer;
@ -51,7 +52,11 @@ public class PreferencesMediaLibrary extends Fragment implements View.OnClickLis
/**
* The debug / progress text describing the scan status
*/
private TextView mProgress;
private TextView mProgressText;
/**
* The progress bar
*/
private ProgressBar mProgressBar;
/**
* The number of tracks on this device
*/;
@ -92,7 +97,8 @@ public class PreferencesMediaLibrary extends Fragment implements View.OnClickLis
mStartButton = (View)view.findViewById(R.id.start_button);
mCancelButton = (View)view.findViewById(R.id.cancel_button);
mProgress = (TextView)view.findViewById(R.id.media_stats_progress);
mProgressText = (TextView)view.findViewById(R.id.media_stats_progress_text);
mProgressBar = (ProgressBar)view.findViewById(R.id.media_stats_progress_bar);
mStatsTracks = (TextView)view.findViewById(R.id.media_stats_tracks);
mStatsPlaytime = (TextView)view.findViewById(R.id.media_stats_playtime);
mFullScanCheck = (CheckBox)view.findViewById(R.id.media_scan_full);
@ -213,16 +219,22 @@ public class PreferencesMediaLibrary extends Fragment implements View.OnClickLis
*/
private void updateProgress() {
Context context = getActivity();
String scanText = MediaLibrary.describeScanProgress(getActivity());
boolean scanIdle = scanText == null;
MediaLibrary.ScanProgress progress = MediaLibrary.describeScanProgress(getActivity());
mProgress.setText(scanText);
mStartButton.setEnabled(scanIdle);
mDropDbCheck.setEnabled(scanIdle);
mFullScanCheck.setEnabled(scanIdle);
mForceBastpCheck.setEnabled(scanIdle);
mGroupAlbumsCheck.setEnabled(scanIdle);
mCancelButton.setVisibility(scanIdle ? View.GONE : View.VISIBLE);
boolean idle = !progress.isRunning;
mProgressText.setText(progress.lastFile);
mProgressBar.setMax(progress.total);
mProgressBar.setProgress(progress.seen);
mStartButton.setEnabled(idle);
mDropDbCheck.setEnabled(idle);
mFullScanCheck.setEnabled(idle);
mForceBastpCheck.setEnabled(idle);
mGroupAlbumsCheck.setEnabled(idle);
mCancelButton.setVisibility(idle ? View.GONE : View.VISIBLE);
mProgressText.setVisibility(idle ? View.GONE : View.VISIBLE);
mProgressBar.setVisibility(idle ? View.GONE : View.VISIBLE);
Integer songCount = MediaLibrary.getLibrarySize(context);
mStatsTracks.setText(songCount.toString());