add option to abort a scan
This commit is contained in:
parent
c270b13296
commit
bb2e707844
@ -85,5 +85,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/empty" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancel_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:text="@android:string/cancel">
|
||||
<requestFocus />
|
||||
</Button>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -83,7 +83,7 @@ public class MediaLibrary {
|
||||
* @param forceFull starts a full / slow scan if true
|
||||
* @param drop drop the existing library if true
|
||||
*/
|
||||
public static void scanLibrary(Context context, boolean forceFull, boolean drop) {
|
||||
public static void startLibraryScan(Context context, boolean forceFull, boolean drop) {
|
||||
MediaLibraryBackend backend = getBackend(context); // also initialized sScanner
|
||||
if (drop) {
|
||||
sScanner.flushDatabase();
|
||||
@ -97,6 +97,16 @@ public class MediaLibrary {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops any running scan
|
||||
*
|
||||
* @param context the context to use
|
||||
*/
|
||||
public static void abortLibraryScan(Context context) {
|
||||
MediaLibraryBackend backend = getBackend(context); // also initialized sScanner
|
||||
sScanner.abortScan();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whacky function to get the current scan progress
|
||||
*
|
||||
|
@ -124,6 +124,15 @@ public class MediaScanner implements Handler.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops a running scan
|
||||
*/
|
||||
public void abortScan() {
|
||||
mHandler.removeMessages(MSG_SCAN_RPC);
|
||||
mScanPlan.clear();
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_SCAN_RPC, RPC_KICKSTART, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops the media library
|
||||
*/
|
||||
@ -547,6 +556,14 @@ public class MediaScanner implements Handler.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes all progress, turning the object into a fresh state
|
||||
*/
|
||||
void clear() {
|
||||
mSteps.clear();
|
||||
mStats.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the next step in our plan
|
||||
*
|
||||
|
@ -41,6 +41,10 @@ public class PreferencesMediaLibrary extends Fragment
|
||||
* Our start button
|
||||
*/
|
||||
private View mStartButton;
|
||||
/**
|
||||
* The cancel button
|
||||
*/
|
||||
private View mCancelButton;
|
||||
/**
|
||||
* The debug / progress text describing the scan status
|
||||
*/
|
||||
@ -72,6 +76,7 @@ public class PreferencesMediaLibrary extends Fragment
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
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);
|
||||
mStatsTracks = (TextView)view.findViewById(R.id.media_stats_tracks);
|
||||
mStatsPlaytime = (TextView)view.findViewById(R.id.media_stats_playtime);
|
||||
@ -84,6 +89,13 @@ public class PreferencesMediaLibrary extends Fragment
|
||||
startButtonPressed(v);
|
||||
}
|
||||
});
|
||||
|
||||
mCancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
cancelButtonPressed(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -120,6 +132,7 @@ public class PreferencesMediaLibrary extends Fragment
|
||||
String scanText = MediaLibrary.describeScanProgress(getActivity());
|
||||
mProgress.setText(scanText);
|
||||
mStartButton.setEnabled(scanText == null);
|
||||
mCancelButton.setVisibility(scanText == null ? View.GONE : View.VISIBLE);
|
||||
|
||||
Integer songCount = MediaLibrary.getLibrarySize(context);
|
||||
mStatsTracks.setText(songCount.toString());
|
||||
@ -152,7 +165,17 @@ public class PreferencesMediaLibrary extends Fragment
|
||||
* @param view the view which was pressed
|
||||
*/
|
||||
public void startButtonPressed(View view) {
|
||||
MediaLibrary.scanLibrary(getActivity(), mFullScanCheck.isChecked(), mDropDbCheck.isChecked());
|
||||
MediaLibrary.startLibraryScan(getActivity(), mFullScanCheck.isChecked(), mDropDbCheck.isChecked());
|
||||
updateProgress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the user hits the cancel button
|
||||
*
|
||||
* @param view the view which was pressed
|
||||
*/
|
||||
public void cancelButtonPressed(View view) {
|
||||
MediaLibrary.abortLibraryScan(getActivity());
|
||||
updateProgress();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user