blob: 18c87dbcc62c5c8b5dc696bc6ca14d29fb037b00 [file] [log] [blame]
/*
* 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;
public MusicViewHolderController(
Context context, StorageStatsSource source, String volumeUuid) {
mContext = context;
mSource = source;
mVolumeUuid = volumeUuid;
}
@Override
@WorkerThread
public void queryStats() {
mMusicSize = mSource.getExternalStorageStats(mVolumeUuid, UserHandle.CURRENT).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, UserHandle.CURRENT);
Utils.launchIntent(fragment, intent);
}
}