Previously, we queried for the extra view's stats during the rebuild. The full rebuild can take an arduous amount of time. By moving the background calculation outside of the rebuild code path, we can load the stats in the background and update the view outside of the app loading cycle. Bug: 35144044 Test: Manual -- this was race condition-y, so I just tested several times. Change-Id: Id2f92e32c3b3f9c5d5cf4a7308cca38c2e52789c
78 lines
2.6 KiB
Java
78 lines
2.6 KiB
Java
/*
|
|
* Copyright (C) 2016 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License
|
|
*/
|
|
|
|
package com.android.settings.applications;
|
|
|
|
import android.app.Fragment;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.UserHandle;
|
|
import android.provider.DocumentsContract;
|
|
import android.support.annotation.WorkerThread;
|
|
import android.text.format.Formatter;
|
|
|
|
import com.android.settings.R;
|
|
import com.android.settings.Utils;
|
|
import com.android.settings.deviceinfo.storage.StorageStatsSource;
|
|
|
|
/**
|
|
* MusicViewHolderController controls an Audio/Music file view in the ManageApplications view.
|
|
*/
|
|
public class MusicViewHolderController implements FileViewHolderController {
|
|
private static final String AUTHORITY_MEDIA = "com.android.providers.media.documents";
|
|
|
|
private Context mContext;
|
|
private StorageStatsSource mSource;
|
|
private String mVolumeUuid;
|
|
private long mMusicSize;
|
|
private UserHandle mUser;
|
|
|
|
public MusicViewHolderController(
|
|
Context context, StorageStatsSource source, String volumeUuid, UserHandle user) {
|
|
mContext = context;
|
|
mSource = source;
|
|
mVolumeUuid = volumeUuid;
|
|
mUser = user;
|
|
}
|
|
|
|
@Override
|
|
@WorkerThread
|
|
public void queryStats() {
|
|
mMusicSize = mSource.getExternalStorageStats(mVolumeUuid, mUser).audioBytes;
|
|
}
|
|
|
|
@Override
|
|
public boolean shouldShow() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void setupView(AppViewHolder holder) {
|
|
holder.appIcon.setImageDrawable(mContext.getDrawable(R.drawable.empty_icon));
|
|
holder.appName.setText(mContext.getText(R.string.audio_files_title));
|
|
holder.summary.setText(Formatter.formatFileSize(mContext, mMusicSize));
|
|
}
|
|
|
|
@Override
|
|
public void onClick(Fragment fragment) {
|
|
Intent intent = new Intent(DocumentsContract.ACTION_BROWSE);
|
|
intent.setData(DocumentsContract.buildRootUri(AUTHORITY_MEDIA, "audio_root"));
|
|
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
|
intent.putExtra(Intent.EXTRA_USER_ID, mUser);
|
|
Utils.launchIntent(fragment, intent);
|
|
}
|
|
}
|