Search in sources :

Example 1 with Asset

use of com.waz.api.Asset in project wire-android by wireapp.

the class MessageBottomSheetDialog method init.

@SuppressLint("InflateParams")
private void init(final boolean isMemberOfConversation, final boolean isCollection, final boolean deleteCollapsed) {
    final LinearLayout view = (LinearLayout) getLayoutInflater().inflate(R.layout.message__bottom__menu, null);
    ModelObserver<Asset> assetModelObserver = new ModelObserver<Asset>() {

        @Override
        public void updated(Asset model) {
            if (!model.isEmpty()) {
                updateOptions(view, isMemberOfConversation, isCollection, deleteCollapsed);
            }
        }
    };
    assetModelObserver.setAndUpdate(message.getAsset());
    updateOptions(view, isMemberOfConversation, isCollection, deleteCollapsed);
    setContentView(view);
}
Also used : ModelObserver(com.waz.zclient.core.api.scala.ModelObserver) Asset(com.waz.api.Asset) LinearLayout(android.widget.LinearLayout) SuppressLint(android.annotation.SuppressLint)

Example 2 with Asset

use of com.waz.api.Asset in project wire-android by wireapp.

the class AssetDialogUtils method showFileActionSheet.

public static void showFileActionSheet(final Context context, final Asset asset, final Uri uri, boolean fileCanBeOpened, final AssetDialogCallback callback) {
    final AppCompatDialog fileActionSheetDialog = new AppCompatDialog(context);
    fileActionSheetDialog.setTitle(asset.getName());
    fileActionSheetDialog.setContentView(R.layout.file_action_sheet_dialog);
    TextView title = ViewUtils.getView(fileActionSheetDialog, R.id.title);
    title.setEllipsize(TextUtils.TruncateAt.MIDDLE);
    title.setTypeface(TypefaceUtils.getTypeface(context.getResources().getString(R.string.wire__typeface__medium)));
    title.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimensionPixelSize(R.dimen.wire__text_size__regular));
    title.setGravity(Gravity.CENTER);
    TextView openButton = ViewUtils.getView(fileActionSheetDialog, R.id.ttv__file_action_dialog__open);
    View noAppFoundLabel = ViewUtils.getView(fileActionSheetDialog, R.id.ttv__file_action_dialog__open__no_app_found);
    View saveButton = ViewUtils.getView(fileActionSheetDialog, R.id.ttv__file_action_dialog__save);
    // Opening file
    if (fileCanBeOpened) {
        noAppFoundLabel.setVisibility(View.GONE);
        openButton.setAlpha(1f);
        openButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                callback.onOpenedFile(uri);
                fileActionSheetDialog.dismiss();
            }
        });
    } else {
        noAppFoundLabel.setVisibility(View.VISIBLE);
        float disabledAlpha = ResourceUtils.getResourceFloat(context.getResources(), R.dimen.button__disabled_state__alpha);
        openButton.setAlpha(disabledAlpha);
    }
    // Saving file
    final Asset.LoadCallback<Uri> saveFileLoadCallback = new Asset.LoadCallback<Uri>() {

        @Override
        public void onLoaded(Uri uri) {
            callback.onSavedFile(uri);
        }

        @Override
        public void onLoadFailed() {
        }
    };
    saveButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            fileActionSheetDialog.dismiss();
            asset.saveToDownloads(saveFileLoadCallback);
        }
    });
    fileActionSheetDialog.show();
}
Also used : AppCompatDialog(android.support.v7.app.AppCompatDialog) Asset(com.waz.api.Asset) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) Uri(android.net.Uri)

Aggregations

Asset (com.waz.api.Asset)2 SuppressLint (android.annotation.SuppressLint)1 Uri (android.net.Uri)1 AppCompatDialog (android.support.v7.app.AppCompatDialog)1 View (android.view.View)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 ModelObserver (com.waz.zclient.core.api.scala.ModelObserver)1