From 96a67a44acbbf2e4d1f60af31c270b44eea69fb8 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 2 Apr 2019 15:59:36 +0200 Subject: [PATCH] Media: grab some code from Riot legacy --- .../core/dialogs/DialogAdapter.kt | 41 ++ .../core/dialogs/DialogCallAdapter.kt | 29 ++ .../core/dialogs/DialogListItem.kt | 36 ++ .../core/dialogs/DialogListItemHolder.kt | 37 ++ .../riotredesign/core/dialogs/DialogLocker.kt | 66 +++ .../core/dialogs/DialogSendItemAdapter.kt | 28 ++ .../core/dialogs/ExportKeysDialog.kt | 84 ++++ .../core/utils/PermissionsTools.kt | 397 ++++++++++++++++++ .../home/room/detail/RoomDetailFragment.kt | 64 +++ .../drawable-hdpi/ic_attach_file_white.png | Bin 0 -> 394 bytes .../drawable-mdpi/ic_attach_file_white.png | Bin 0 -> 285 bytes .../res/drawable-mdpi/ic_material_camera.png | Bin 0 -> 539 bytes .../res/drawable-mdpi/ic_material_file.png | Bin 0 -> 545 bytes .../drawable-mdpi/ic_material_videocam.png | Bin 0 -> 3120 bytes .../res/drawable-mdpi/ic_send_sticker.png | Bin 0 -> 7243 bytes .../res/drawable-mdpi/vector_micro_green.png | Bin 0 -> 399 bytes .../res/drawable-mdpi/video_call_black.png | Bin 0 -> 224 bytes .../res/drawable-mdpi/video_call_green.png | Bin 0 -> 298 bytes .../res/drawable-mdpi/voice_call_black.png | Bin 0 -> 574 bytes .../drawable-mdpi/voice_call_end_fushia.png | Bin 0 -> 331 bytes .../res/drawable-mdpi/voice_call_green.png | Bin 0 -> 432 bytes .../drawable-mdpi/voice_call_start_green.png | Bin 0 -> 684 bytes .../drawable-xhdpi/ic_attach_file_white.png | Bin 0 -> 507 bytes .../drawable-xxhdpi/ic_attach_file_white.png | Bin 0 -> 809 bytes .../drawable-xxxhdpi/ic_attach_file_white.png | Bin 0 -> 1059 bytes .../res/layout/dialog_export_e2e_keys.xml | 62 +++ .../main/res/layout/fragment_room_detail.xml | 15 +- vector/src/main/res/layout/item_dialog.xml | 53 +++ 28 files changed, 910 insertions(+), 2 deletions(-) create mode 100644 vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogAdapter.kt create mode 100644 vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogCallAdapter.kt create mode 100644 vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogListItem.kt create mode 100644 vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogListItemHolder.kt create mode 100644 vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogLocker.kt create mode 100644 vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogSendItemAdapter.kt create mode 100644 vector/src/main/java/im/vector/riotredesign/core/dialogs/ExportKeysDialog.kt create mode 100644 vector/src/main/java/im/vector/riotredesign/core/utils/PermissionsTools.kt create mode 100644 vector/src/main/res/drawable-hdpi/ic_attach_file_white.png create mode 100644 vector/src/main/res/drawable-mdpi/ic_attach_file_white.png create mode 100755 vector/src/main/res/drawable-mdpi/ic_material_camera.png create mode 100755 vector/src/main/res/drawable-mdpi/ic_material_file.png create mode 100755 vector/src/main/res/drawable-mdpi/ic_material_videocam.png create mode 100644 vector/src/main/res/drawable-mdpi/ic_send_sticker.png create mode 100755 vector/src/main/res/drawable-mdpi/vector_micro_green.png create mode 100755 vector/src/main/res/drawable-mdpi/video_call_black.png create mode 100755 vector/src/main/res/drawable-mdpi/video_call_green.png create mode 100755 vector/src/main/res/drawable-mdpi/voice_call_black.png create mode 100755 vector/src/main/res/drawable-mdpi/voice_call_end_fushia.png create mode 100755 vector/src/main/res/drawable-mdpi/voice_call_green.png create mode 100755 vector/src/main/res/drawable-mdpi/voice_call_start_green.png create mode 100644 vector/src/main/res/drawable-xhdpi/ic_attach_file_white.png create mode 100644 vector/src/main/res/drawable-xxhdpi/ic_attach_file_white.png create mode 100644 vector/src/main/res/drawable-xxxhdpi/ic_attach_file_white.png create mode 100644 vector/src/main/res/layout/dialog_export_e2e_keys.xml create mode 100644 vector/src/main/res/layout/item_dialog.xml diff --git a/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogAdapter.kt b/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogAdapter.kt new file mode 100644 index 00000000..5f51350e --- /dev/null +++ b/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogAdapter.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2019 New Vector Ltd + * + * 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 im.vector.riotredesign.core.dialogs + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ArrayAdapter +import im.vector.riotredesign.R + +internal abstract class DialogAdapter(context: Context) : ArrayAdapter(context, R.layout.item_dialog) { + + override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View { + var view = convertView + if (view == null) { + view = LayoutInflater.from(context).inflate(R.layout.item_dialog, parent, false) + view.tag = DialogListItemHolder(view) + } + (view!!.tag as DialogListItemHolder).let { + it.icon.setImageResource(getItem(position).iconRes) + it.text.setText(getItem(position).titleRes) + } + return view + } + +} diff --git a/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogCallAdapter.kt b/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogCallAdapter.kt new file mode 100644 index 00000000..5f0a954d --- /dev/null +++ b/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogCallAdapter.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2019 New Vector Ltd + * + * 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 im.vector.riotredesign.core.dialogs + +import android.content.Context +import im.vector.riotredesign.core.dialogs.DialogAdapter +import im.vector.riotredesign.core.dialogs.DialogListItem + +internal class DialogCallAdapter(context: Context) : DialogAdapter(context) { + + init { + add(DialogListItem.StartVoiceCall) + add(DialogListItem.StartVideoCall) + } +} diff --git a/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogListItem.kt b/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogListItem.kt new file mode 100644 index 00000000..d070b526 --- /dev/null +++ b/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogListItem.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2019 New Vector Ltd + * + * 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 im.vector.riotredesign.core.dialogs + +import androidx.annotation.DrawableRes +import androidx.annotation.StringRes +import im.vector.riotredesign.R + +internal sealed class DialogListItem(@DrawableRes val iconRes: Int, + @StringRes val titleRes: Int) { + + object StartVoiceCall : DialogListItem(R.drawable.voice_call_green, R.string.action_voice_call) + object StartVideoCall : DialogListItem(R.drawable.video_call_green, R.string.action_video_call) + + object SendFile : DialogListItem(R.drawable.ic_material_file, R.string.option_send_files) + object SendVoice : DialogListItem(R.drawable.vector_micro_green, R.string.option_send_voice) + object SendSticker : DialogListItem(R.drawable.ic_send_sticker, R.string.option_send_sticker) + object TakePhoto : DialogListItem(R.drawable.ic_material_camera, R.string.option_take_photo) + object TakeVideo : DialogListItem(R.drawable.ic_material_videocam, R.string.option_take_video) + object TakePhotoVideo : DialogListItem(R.drawable.ic_material_camera, R.string.option_take_photo_video) + +} diff --git a/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogListItemHolder.kt b/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogListItemHolder.kt new file mode 100644 index 00000000..f6ec5522 --- /dev/null +++ b/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogListItemHolder.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2019 New Vector Ltd + * + * 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 im.vector.riotredesign.core.dialogs + +import android.view.View +import android.widget.ImageView +import android.widget.TextView +import butterknife.BindView +import butterknife.ButterKnife +import im.vector.riotredesign.R + +class DialogListItemHolder(view: View) { + + @BindView(R.id.adapter_item_dialog_icon) + lateinit var icon: ImageView + + @BindView(R.id.adapter_item_dialog_text) + lateinit var text: TextView + + init { + ButterKnife.bind(this, view) + } +} \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogLocker.kt b/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogLocker.kt new file mode 100644 index 00000000..19e75ce0 --- /dev/null +++ b/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogLocker.kt @@ -0,0 +1,66 @@ +/* + * Copyright 2019 New Vector Ltd + * + * 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 im.vector.riotredesign.core.dialogs + +import android.os.Bundle +import androidx.appcompat.app.AlertDialog +import im.vector.riotredesign.core.platform.Restorable +import timber.log.Timber + +private const val KEY_DIALOG_IS_DISPLAYED = "DialogLocker.KEY_DIALOG_IS_DISPLAYED" + +/** + * Class to avoid displaying twice the same dialog + */ +class DialogLocker() : Restorable { + + private var isDialogDisplayed: Boolean = false + + private fun unlock() { + isDialogDisplayed = false + } + + private fun lock() { + isDialogDisplayed = true + } + + fun displayDialog(builder: () -> AlertDialog.Builder): AlertDialog? { + return if (isDialogDisplayed) { + Timber.w("Filtered dialog request") + null + } else { + builder + .invoke() + .create() + .apply { + setOnShowListener { lock() } + setOnCancelListener { unlock() } + setOnDismissListener { unlock() } + show() + } + } + } + + override fun onSaveInstanceState(outState: Bundle) { + outState.putBoolean(KEY_DIALOG_IS_DISPLAYED, isDialogDisplayed) + } + + override fun onRestoreInstanceState(savedInstanceState: Bundle?) { + isDialogDisplayed = savedInstanceState?.getBoolean(KEY_DIALOG_IS_DISPLAYED, false) == true + } + +} \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogSendItemAdapter.kt b/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogSendItemAdapter.kt new file mode 100644 index 00000000..e1acddea --- /dev/null +++ b/vector/src/main/java/im/vector/riotredesign/core/dialogs/DialogSendItemAdapter.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2019 New Vector Ltd + * + * 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 im.vector.riotredesign.core.dialogs + +import android.content.Context +import im.vector.riotredesign.core.dialogs.DialogAdapter +import im.vector.riotredesign.core.dialogs.DialogListItem + +internal class DialogSendItemAdapter(context: Context, items: MutableList) : DialogAdapter(context) { + + init { + addAll(items) + } +} diff --git a/vector/src/main/java/im/vector/riotredesign/core/dialogs/ExportKeysDialog.kt b/vector/src/main/java/im/vector/riotredesign/core/dialogs/ExportKeysDialog.kt new file mode 100644 index 00000000..90c12de4 --- /dev/null +++ b/vector/src/main/java/im/vector/riotredesign/core/dialogs/ExportKeysDialog.kt @@ -0,0 +1,84 @@ +/* + * Copyright 2019 New Vector Ltd + * + * 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 im.vector.riotredesign.core.dialogs + +import android.app.Activity +import android.text.Editable +import android.text.TextUtils +import android.text.TextWatcher +import android.widget.Button +import androidx.appcompat.app.AlertDialog +import com.google.android.material.textfield.TextInputEditText +import com.google.android.material.textfield.TextInputLayout +import im.vector.riotredesign.R + +class ExportKeysDialog { + + fun show(activity: Activity, exportKeyDialogListener: ExportKeyDialogListener) { + val dialogLayout = activity.layoutInflater.inflate(R.layout.dialog_export_e2e_keys, null) + val builder = AlertDialog.Builder(activity) + .setTitle(R.string.encryption_export_room_keys) + .setView(dialogLayout) + + val passPhrase1EditText = dialogLayout.findViewById(R.id.dialog_e2e_keys_passphrase_edit_text) + val passPhrase2EditText = dialogLayout.findViewById(R.id.dialog_e2e_keys_confirm_passphrase_edit_text) + val passPhrase2Til = dialogLayout.findViewById(R.id.dialog_e2e_keys_confirm_passphrase_til) + val exportButton = dialogLayout.findViewById