From b0145e019232b6c3ce7718c6a2289ac6ea57560e Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Mon, 7 Jun 2021 16:34:50 +0200 Subject: [PATCH] Remove android:onClick properties --- .../sushi/hardcore/droidfs/CameraActivity.kt | 156 +++++++++--------- .../droidfs/ChangePasswordActivity.kt | 24 +-- .../sushi/hardcore/droidfs/ConstValues.kt | 4 +- .../sushi/hardcore/droidfs/CreateActivity.kt | 37 ++--- .../sushi/hardcore/droidfs/MainActivity.kt | 25 ++- .../sushi/hardcore/droidfs/OpenActivity.kt | 24 +-- .../hardcore/droidfs/SettingsActivity.kt | 10 +- .../hardcore/droidfs/VolumeActionActivity.kt | 79 ++++----- .../droidfs/explorers/ExplorerActivity.kt | 133 ++++++++------- .../droidfs/explorers/ExplorerActivityDrop.kt | 9 +- .../droidfs/file_viewers/ImageViewer.kt | 119 +++++++------ .../droidfs/widgets/TakePhotoButton.kt | 7 +- app/src/main/res/layout/activity_camera.xml | 9 +- .../res/layout/activity_change_password.xml | 2 +- app/src/main/res/layout/activity_create.xml | 2 +- app/src/main/res/layout/activity_explorer.xml | 4 +- .../res/layout/activity_explorer_drop.xml | 4 +- .../main/res/layout/activity_image_viewer.xml | 19 +-- app/src/main/res/layout/activity_main.xml | 3 - app/src/main/res/layout/activity_open.xml | 2 +- .../main/res/layout/checkboxes_section.xml | 6 +- .../main/res/layout/volume_path_section.xml | 5 +- 22 files changed, 317 insertions(+), 366 deletions(-) diff --git a/app/src/main/java/sushi/hardcore/droidfs/CameraActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/CameraActivity.kt index a17df5c..dd9ac09 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/CameraActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/CameraActivity.kt @@ -9,7 +9,6 @@ import android.os.Build import android.os.Bundle import android.text.InputType import android.util.DisplayMetrics -import android.util.Log import android.util.Size import android.view.MotionEvent import android.view.ScaleGestureDetector @@ -44,7 +43,7 @@ class CameraActivity : BaseActivity(), SensorOrientationListener.Listener { private const val CAMERA_PERMISSION_REQUEST_CODE = 1 private const val fileNameRandomMin = 100000 private const val fileNameRandomMax = 999999 - private val dateFormat = SimpleDateFormat("yyyyMMdd_HHmmss") + private val dateFormat = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US) private val random = Random() } private var timerDuration = 0 @@ -88,6 +87,74 @@ class CameraActivity : BaseActivity(), SensorOrientationListener.Listener { cameraExecutor = Executors.newSingleThreadExecutor() + image_ratio.setOnClickListener { + resolutions?.let { + ColoredAlertDialogBuilder(this) + .setTitle(R.string.choose_resolution) + .setSingleChoiceItems(DialogSingleChoiceAdapter(this, it.map { size -> size.toString() }.toTypedArray()), currentResolutionIndex) { dialog, which -> + setupCamera(resolutions!![which]) + dialog.dismiss() + currentResolutionIndex = which + } + .setNegativeButton(R.string.cancel, null) + .show() + } + } + image_timer.setOnClickListener { + val dialogEditTextView = layoutInflater.inflate(R.layout.dialog_edit_text, null) + val dialogEditText = dialogEditTextView.findViewById(R.id.dialog_edit_text) + dialogEditText.inputType = InputType.TYPE_CLASS_NUMBER + val dialog = ColoredAlertDialogBuilder(this) + .setView(dialogEditTextView) + .setTitle(getString(R.string.enter_timer_duration)) + .setPositiveButton(R.string.ok) { _, _ -> + val enteredValue = dialogEditText.text.toString() + if (enteredValue.isEmpty()){ + Toast.makeText(this, getString(R.string.timer_empty_error_msg), Toast.LENGTH_SHORT).show() + } else { + timerDuration = enteredValue.toInt() + } + } + .setNegativeButton(R.string.cancel, null) + .create() + dialogEditText.setOnEditorActionListener { _, _, _ -> + timerDuration = dialogEditText.text.toString().toInt() + dialog.dismiss() + true + } + dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) + dialog.show() + } + image_close.setOnClickListener { + isFinishingIntentionally = true + finish() + } + image_flash.setOnClickListener { + image_flash.setImageResource(when (imageCapture?.flashMode) { + ImageCapture.FLASH_MODE_AUTO -> { + imageCapture?.flashMode = ImageCapture.FLASH_MODE_ON + R.drawable.icon_flash_on + } + ImageCapture.FLASH_MODE_ON -> { + imageCapture?.flashMode = ImageCapture.FLASH_MODE_OFF + R.drawable.icon_flash_off + } + else -> { + imageCapture?.flashMode = ImageCapture.FLASH_MODE_AUTO + R.drawable.icon_flash_auto + } + }) + } + image_camera_switch.setOnClickListener { + isBackCamera = if (isBackCamera) { + image_camera_switch.setImageResource(R.drawable.icon_camera_front) + false + } else { + image_camera_switch.setImageResource(R.drawable.icon_camera_back) + true + } + setupCamera() + } take_photo_button.onClick = ::onClickTakePhoto orientedIcons = listOf(image_ratio, image_timer, image_close, image_flash, image_camera_switch) sensorOrientationListener = SensorOrientationListener(this) @@ -99,23 +166,25 @@ class CameraActivity : BaseActivity(), SensorOrientationListener.Listener { return true } }) - camera_preview.setOnTouchListener { _, motionEvent: MotionEvent -> - when (motionEvent.action) { + camera_preview.setOnTouchListener { view, event -> + view.performClick() + when (event.action) { MotionEvent.ACTION_DOWN -> true MotionEvent.ACTION_UP -> { val factory = camera_preview.meteringPointFactory - val point = factory.createPoint(motionEvent.x, motionEvent.y) + val point = factory.createPoint(event.x, event.y) val action = FocusMeteringAction.Builder(point).build() imageCapture?.camera?.cameraControl?.startFocusAndMetering(action) true } - MotionEvent.ACTION_MOVE -> scaleGestureDetector.onTouchEvent(motionEvent) + MotionEvent.ACTION_MOVE -> scaleGestureDetector.onTouchEvent(event) else -> false } } } override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults) when (requestCode) { CAMERA_PERMISSION_REQUEST_CODE -> if (grantResults.size == 1) { if (grantResults[0] != PackageManager.PERMISSION_GRANTED) { @@ -134,7 +203,7 @@ class CameraActivity : BaseActivity(), SensorOrientationListener.Listener { } } - private fun adaptPreviewSize(resolution: Size){ + private fun adaptPreviewSize(resolution: Size) { val metrics = DisplayMetrics() windowManager.defaultDisplay.getMetrics(metrics) //resolution.width and resolution.height seem to be inverted @@ -238,79 +307,6 @@ class CameraActivity : BaseActivity(), SensorOrientationListener.Listener { } } - fun onClickFlash(view: View) { - image_flash.setImageResource(when (imageCapture?.flashMode) { - ImageCapture.FLASH_MODE_AUTO -> { - imageCapture?.flashMode = ImageCapture.FLASH_MODE_ON - R.drawable.icon_flash_on - } - ImageCapture.FLASH_MODE_ON -> { - imageCapture?.flashMode = ImageCapture.FLASH_MODE_OFF - R.drawable.icon_flash_off - } - else -> { - imageCapture?.flashMode = ImageCapture.FLASH_MODE_AUTO - R.drawable.icon_flash_auto - } - }) - } - - fun onClickCameraSwitch(view: View) { - isBackCamera = if (isBackCamera) { - image_camera_switch.setImageResource(R.drawable.icon_camera_front) - false - } else { - image_camera_switch.setImageResource(R.drawable.icon_camera_back) - true - } - setupCamera() - } - - fun onClickTimer(view: View) { - val dialogEditTextView = layoutInflater.inflate(R.layout.dialog_edit_text, null) - val dialogEditText = dialogEditTextView.findViewById(R.id.dialog_edit_text) - dialogEditText.inputType = InputType.TYPE_CLASS_NUMBER - val dialog = ColoredAlertDialogBuilder(this) - .setView(dialogEditTextView) - .setTitle(getString(R.string.enter_timer_duration)) - .setPositiveButton(R.string.ok) { _, _ -> - val enteredValue = dialogEditText.text.toString() - if (enteredValue.isEmpty()){ - Toast.makeText(this, getString(R.string.timer_empty_error_msg), Toast.LENGTH_SHORT).show() - } else { - timerDuration = enteredValue.toInt() - } - } - .setNegativeButton(R.string.cancel, null) - .create() - dialogEditText.setOnEditorActionListener { _, _, _ -> - timerDuration = dialogEditText.text.toString().toInt() - dialog.dismiss() - true - } - dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - dialog.show() - } - - fun onClickRatio(view: View) { - resolutions?.let { - ColoredAlertDialogBuilder(this) - .setTitle(R.string.choose_resolution) - .setSingleChoiceItems(DialogSingleChoiceAdapter(this, it.map { size -> size.toString() }.toTypedArray()), currentResolutionIndex) { dialog, which -> - setupCamera(resolutions!![which]) - dialog.dismiss() - currentResolutionIndex = which - } - .setNegativeButton(R.string.cancel, null) - .show() - } - } - - fun onClickClose(view: View) { - isFinishingIntentionally = true - finish() - } - override fun onDestroy() { super.onDestroy() cameraExecutor.shutdown() diff --git a/app/src/main/java/sushi/hardcore/droidfs/ChangePasswordActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/ChangePasswordActivity.kt index 26a4679..468029d 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/ChangePasswordActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/ChangePasswordActivity.kt @@ -5,7 +5,6 @@ import android.os.Build import android.os.Bundle import android.text.Editable import android.text.TextWatcher -import android.view.View import android.widget.AdapterView.OnItemClickListener import android.widget.Toast import androidx.appcompat.app.AppCompatActivity @@ -25,7 +24,7 @@ class ChangePasswordActivity : VolumeActionActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_change_password) - setupActionBar() + setupLayout() setupFingerprintStuff() savedVolumesAdapter = SavedVolumesAdapter(this, volumeDatabase) if (savedVolumesAdapter.count > 0){ @@ -40,7 +39,7 @@ class ChangePasswordActivity : VolumeActionActivity() { switch_hidden_volume.isChecked = false edit_volume_path.setText(currentVolumeName) } - onClickSwitchHiddenVolume(switch_hidden_volume) + onClickSwitchHiddenVolume() } } else { WidgetUtil.hideWithPadding(saved_path_listview) @@ -71,14 +70,13 @@ class ChangePasswordActivity : VolumeActionActivity() { } edit_volume_path.addTextChangedListener(textWatcher) edit_volume_name.addTextChangedListener(textWatcher) - edit_new_password_confirm.setOnEditorActionListener { v, _, _ -> - onClickChangePassword(v) + edit_new_password_confirm.setOnEditorActionListener { _, _, _ -> + checkVolumePathThenChangePassword() true } - } - - fun pickDirectory(view: View?) { - askPermissionThenPickDirectory() + button_change_password.setOnClickListener { + checkVolumePathThenChangePassword() + } } override fun onDirectoryPicked(uri: Uri) { @@ -102,7 +100,7 @@ class ChangePasswordActivity : VolumeActionActivity() { } } - fun onClickChangePassword(view: View?) { + fun checkVolumePathThenChangePassword() { loadVolumePath { val volumeFile = File(currentVolumePath) if (!GocryptfsVolume.isGocryptfsVolume(volumeFile)){ @@ -209,12 +207,6 @@ class ChangePasswordActivity : VolumeActionActivity() { .show() } - fun onClickRememberPath(view: View) { - if (!checkbox_remember_path.isChecked){ - checkbox_save_password.isChecked = false - } - } - override fun onDestroy() { super.onDestroy() Wiper.wipeEditText(edit_old_password) diff --git a/app/src/main/java/sushi/hardcore/droidfs/ConstValues.kt b/app/src/main/java/sushi/hardcore/droidfs/ConstValues.kt index 83fb3a8..9b64622 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/ConstValues.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/ConstValues.kt @@ -18,11 +18,11 @@ class ConstValues { Pair("image", listOf("png", "jpg", "jpeg", "gif", "bmp")), Pair("video", listOf("mp4", "webm", "mkv", "mov")), Pair("audio", listOf("mp3", "ogg", "m4a", "wav", "flac")), - Pair("text", listOf("txt", "json", "conf", "log", "xml", "java", "kt", "py", "pl", "rb", "go", "c", "h", "cpp", "hpp", "sh", "bat", "js", "html", "css", "php", "yml", "yaml", "ini", "md")) + Pair("text", listOf("txt", "json", "conf", "log", "xml", "java", "kt", "py", "pl", "rb", "go", "c", "h", "cpp", "hpp", "rs", "sh", "bat", "js", "html", "css", "php", "yml", "yaml", "toml", "ini", "md")) ) fun isExtensionType(extensionType: String, path: String): Boolean { - return fileExtensions[extensionType]?.contains(File(path).extension.toLowerCase(Locale.ROOT)) ?: false + return fileExtensions[extensionType]?.contains(File(path).extension.lowercase()) ?: false } fun isImage(path: String): Boolean { diff --git a/app/src/main/java/sushi/hardcore/droidfs/CreateActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/CreateActivity.kt index 5188d13..6b31df4 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/CreateActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/CreateActivity.kt @@ -4,7 +4,6 @@ import android.content.Intent import android.net.Uri import android.os.Build import android.os.Bundle -import android.view.View import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import kotlinx.android.synthetic.main.activity_create.* @@ -23,26 +22,26 @@ class CreateActivity : VolumeActionActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_create) - setupActionBar() + setupLayout() setupFingerprintStuff() - edit_password_confirm.setOnEditorActionListener { v, _, _ -> - onClickCreate(v) + edit_password_confirm.setOnEditorActionListener { _, _, _ -> + createVolume() true } - switch_hidden_volume.setOnClickListener { - onClickSwitchHiddenVolume(it) - if (switch_hidden_volume.isChecked){ - ColoredAlertDialogBuilder(this) - .setTitle(R.string.warning) - .setMessage(R.string.hidden_volume_warning) - .setPositiveButton(R.string.ok, null) - .show() - } + button_create.setOnClickListener { + createVolume() } } - fun pickDirectory(view: View?) { - askPermissionThenPickDirectory() + override fun onClickSwitchHiddenVolume() { + super.onClickSwitchHiddenVolume() + if (switch_hidden_volume.isChecked){ + ColoredAlertDialogBuilder(this) + .setTitle(R.string.warning) + .setMessage(R.string.hidden_volume_warning) + .setPositiveButton(R.string.ok, null) + .show() + } } override fun onDirectoryPicked(uri: Uri) { @@ -66,7 +65,7 @@ class CreateActivity : VolumeActionActivity() { } } - fun onClickCreate(view: View?) { + fun createVolume() { loadVolumePath { val password = edit_password.text.toString().toCharArray() val passwordConfirm = edit_password_confirm.text.toString().toCharArray() @@ -173,12 +172,6 @@ class CreateActivity : VolumeActionActivity() { .show() } - fun onClickRememberPath(view: View) { - if (!checkbox_remember_path.isChecked) { - checkbox_save_password.isChecked = false - } - } - override fun onPause() { super.onPause() //Closing volume if leaving activity while showing dialog diff --git a/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt index 0803535..90c2753 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt @@ -4,7 +4,7 @@ import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem -import android.view.View +import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.toolbar.* import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder @@ -29,6 +29,15 @@ class MainActivity : BaseActivity() { .show() } } + button_open.setOnClickListener { + startActivity(OpenActivity::class.java) + } + button_create.setOnClickListener { + startActivity(CreateActivity::class.java) + } + button_change_password.setOnClickListener { + startActivity(ChangePasswordActivity::class.java) + } } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -47,18 +56,8 @@ class MainActivity : BaseActivity() { return true } - fun onClickCreate(v: View?) { - val intent = Intent(this, CreateActivity::class.java) - startActivity(intent) - } - - fun onClickOpen(v: View?) { - val intent = Intent(this, OpenActivity::class.java) - startActivity(intent) - } - - fun onClickChangePassword(v: View?) { - val intent = Intent(this, ChangePasswordActivity::class.java) + fun startActivity(clazz: Class) { + val intent = Intent(this, clazz) startActivity(intent) } } diff --git a/app/src/main/java/sushi/hardcore/droidfs/OpenActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/OpenActivity.kt index 088538d..1acccaf 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/OpenActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/OpenActivity.kt @@ -7,7 +7,6 @@ import android.os.Bundle import android.text.Editable import android.text.TextWatcher import android.view.MenuItem -import android.view.View import android.widget.AdapterView.OnItemClickListener import androidx.appcompat.app.AppCompatActivity import kotlinx.android.synthetic.main.activity_open.* @@ -34,7 +33,7 @@ class OpenActivity : VolumeActionActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_open) - setupActionBar() + setupLayout() setupFingerprintStuff() savedVolumesAdapter = SavedVolumesAdapter(this, volumeDatabase) if (savedVolumesAdapter.count > 0){ @@ -49,7 +48,7 @@ class OpenActivity : VolumeActionActivity() { switch_hidden_volume.isChecked = false edit_volume_path.setText(currentVolumeName) } - onClickSwitchHiddenVolume(switch_hidden_volume) + onClickSwitchHiddenVolume() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ volume.hash?.let { hash -> volume.iv?.let { iv -> @@ -89,10 +88,13 @@ class OpenActivity : VolumeActionActivity() { } edit_volume_path.addTextChangedListener(textWatcher) edit_volume_name.addTextChangedListener(textWatcher) - edit_password.setOnEditorActionListener { v, _, _ -> - onClickOpen(v) + edit_password.setOnEditorActionListener { _, _, _ -> + checkVolumePathThenOpen() true } + button_open.setOnClickListener { + checkVolumePathThenOpen() + } } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -106,10 +108,6 @@ class OpenActivity : VolumeActionActivity() { } } - fun pickDirectory(view: View?) { - askPermissionThenPickDirectory() - } - override fun onPickingDirectory() { isStartingActivity = true } @@ -127,7 +125,7 @@ class OpenActivity : VolumeActionActivity() { } } - fun onClickOpen(view: View?) { + fun checkVolumePathThenOpen() { loadVolumePath { val volumeFile = File(currentVolumePath) if (!GocryptfsVolume.isGocryptfsVolume(volumeFile)){ @@ -245,12 +243,6 @@ class OpenActivity : VolumeActionActivity() { finish() } - fun onClickRememberPath(view: View) { - if (!checkbox_remember_path.isChecked){ - checkbox_save_password.isChecked = false - } - } - override fun onBackPressed() { super.onBackPressed() isFinishingIntentionally = true diff --git a/app/src/main/java/sushi/hardcore/droidfs/SettingsActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/SettingsActivity.kt index f4fb017..f3f4729 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/SettingsActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/SettingsActivity.kt @@ -10,7 +10,7 @@ import kotlinx.android.synthetic.main.toolbar.* import sushi.hardcore.droidfs.widgets.SimpleActionPreference import sushi.hardcore.droidfs.widgets.ThemeColor -class SettingsActivity : BaseActivity(), PreferenceFragmentCompat.OnPreferenceStartFragmentCallback { +class SettingsActivity : BaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -72,12 +72,4 @@ class SettingsActivity : BaseActivity(), PreferenceFragmentCompat.OnPreferenceSt ThemeColor.tintPreferenceIcons(preferenceScreen, ThemeColor.getThemeColor(requireContext())) } } - - override fun onPreferenceStartFragment(caller: PreferenceFragmentCompat, pref: Preference): Boolean { - val fragment = supportFragmentManager.fragmentFactory.instantiate(classLoader, pref.fragment) - fragment.arguments = pref.extras - fragment.setTargetFragment(caller, 0) - supportFragmentManager.beginTransaction().replace(R.id.settings, fragment).addToBackStack(null).commit() - return true - } } \ No newline at end of file diff --git a/app/src/main/java/sushi/hardcore/droidfs/VolumeActionActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/VolumeActionActivity.kt index 37e227e..ce49b58 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/VolumeActionActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/VolumeActionActivity.kt @@ -10,7 +10,6 @@ import android.os.Build import android.security.keystore.KeyGenParameterSpec import android.security.keystore.KeyPermanentlyInvalidatedException import android.security.keystore.KeyProperties -import android.view.View import android.widget.LinearLayout import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts @@ -59,22 +58,54 @@ abstract class VolumeActionActivity : BaseActivity() { private const val GCM_TAG_LEN = 128 } - protected open fun onPickingDirectory() {} - protected abstract fun onDirectoryPicked(uri: Uri) - - protected fun askPermissionThenPickDirectory() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) + - ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - requestPermissions(arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE), STORAGE_PERMISSIONS_REQUEST) + protected fun setupLayout() { + setSupportActionBar(toolbar) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + button_pick_directory.setOnClickListener { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) + + ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE), STORAGE_PERMISSIONS_REQUEST) + } else { + safePickDirectory() + } } else { safePickDirectory() } - } else { - safePickDirectory() + } + switch_hidden_volume.setOnClickListener { + onClickSwitchHiddenVolume() + } + checkbox_remember_path.setOnClickListener { + if (!checkbox_remember_path.isChecked) { + checkbox_save_password.isChecked = false + } + } + checkbox_save_password.setOnClickListener { + if (checkbox_save_password.isChecked) { + if (biometricCanAuthenticateCode == 0) { + checkbox_remember_path.isChecked = checkbox_remember_path.isEnabled + } else { + checkbox_save_password.isChecked = false + printAuthenticateImpossibleError() + } + } } } + protected open fun onClickSwitchHiddenVolume() { + if (switch_hidden_volume.isChecked){ + WidgetUtil.show(hidden_volume_section, originalHiddenVolumeSectionLayoutParams) + WidgetUtil.hide(normal_volume_section) + } else { + WidgetUtil.show(normal_volume_section, originalNormalVolumeSectionLayoutParams) + WidgetUtil.hide(hidden_volume_section) + } + } + + protected open fun onPickingDirectory() {} + protected abstract fun onDirectoryPicked(uri: Uri) + private fun safePickDirectory() { try { onPickingDirectory() @@ -185,11 +216,6 @@ abstract class VolumeActionActivity : BaseActivity() { } } - protected fun setupActionBar(){ - setSupportActionBar(toolbar) - supportActionBar?.setDisplayHomeAsUpEnabled(true) - } - private fun canAuthenticate(): Int { val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager return if (!keyguardManager.isKeyguardSecure) { @@ -215,17 +241,6 @@ abstract class VolumeActionActivity : BaseActivity() { }, Toast.LENGTH_SHORT).show() } - fun onClickSavePasswordHash(view: View) { - if (checkbox_save_password.isChecked){ - if (biometricCanAuthenticateCode == 0){ - checkbox_remember_path.isChecked = checkbox_remember_path.isEnabled - } else { - checkbox_save_password.isChecked = false - printAuthenticateImpossibleError() - } - } - } - @RequiresApi(Build.VERSION_CODES.M) private fun prepareCipher() { keyStore = KeyStore.getInstance(ANDROID_KEY_STORE) @@ -337,14 +352,4 @@ abstract class VolumeActionActivity : BaseActivity() { callback() } } - - fun onClickSwitchHiddenVolume(view: View){ - if (switch_hidden_volume.isChecked){ - WidgetUtil.show(hidden_volume_section, originalHiddenVolumeSectionLayoutParams) - WidgetUtil.hide(normal_volume_section) - } else { - WidgetUtil.show(normal_volume_section, originalNormalVolumeSectionLayoutParams) - WidgetUtil.hide(hidden_volume_section) - } - } } \ No newline at end of file diff --git a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt index 38e4cd8..60d5ed3 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt @@ -4,11 +4,11 @@ import android.app.Activity import android.content.Intent import android.view.Menu import android.view.MenuItem -import android.view.View import android.view.WindowManager import android.widget.EditText import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts +import kotlinx.android.synthetic.main.activity_explorer.* import sushi.hardcore.droidfs.CameraActivity import sushi.hardcore.droidfs.GocryptfsVolume import sushi.hardcore.droidfs.OpenActivity @@ -146,6 +146,71 @@ class ExplorerActivity : BaseExplorerActivity() { override fun init() { setContentView(R.layout.activity_explorer) + fab.setOnClickListener { + if (currentItemAction != ItemsActions.NONE){ + openDialogCreateFolder() + } else { + val adapter = IconTextDialogAdapter(this) + adapter.items = listOf( + listOf("importFromOtherVolumes", R.string.import_from_other_volume, R.drawable.icon_transfert), + listOf("importFiles", R.string.import_files, R.drawable.icon_encrypt), + listOf("createFile", R.string.new_file, R.drawable.icon_file_unknown), + listOf("createFolder", R.string.mkdir, R.drawable.icon_folder), + listOf("takePhoto", R.string.take_photo, R.drawable.icon_camera) + ) + ColoredAlertDialogBuilder(this) + .setSingleChoiceItems(adapter, -1){ thisDialog, which -> + when (adapter.getItem(which)){ + "importFromOtherVolumes" -> { + val intent = Intent(this, OpenActivity::class.java) + intent.action = "pick" + intent.putExtra("sessionID", gocryptfsVolume.sessionID) + isStartingActivity = true + pickFromOtherVolumes.launch(intent) + } + "importFiles" -> { + isStartingActivity = true + pickFiles.launch(arrayOf("*/*")) + } + "createFile" -> { + val dialogEditTextView = layoutInflater.inflate(R.layout.dialog_edit_text, null) + val dialogEditText = dialogEditTextView.findViewById(R.id.dialog_edit_text) + val dialog = ColoredAlertDialogBuilder(this) + .setView(dialogEditTextView) + .setTitle(getString(R.string.enter_file_name)) + .setPositiveButton(R.string.ok) { _, _ -> + val fileName = dialogEditText.text.toString() + createNewFile(fileName) + } + .setNegativeButton(R.string.cancel, null) + .create() + dialogEditText.setOnEditorActionListener { _, _, _ -> + val fileName = dialogEditText.text.toString() + dialog.dismiss() + createNewFile(fileName) + true + } + dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) + dialog.show() + } + "createFolder" -> { + openDialogCreateFolder() + } + "takePhoto" -> { + val intent = Intent(this, CameraActivity::class.java) + intent.putExtra("path", currentDirectoryPath) + intent.putExtra("sessionID", gocryptfsVolume.sessionID) + isStartingActivity = true + startActivity(intent) + } + } + thisDialog.dismiss() + } + .setTitle(getString(R.string.fab_dialog_title)) + .setNegativeButton(R.string.cancel, null) + .show() + } + } usf_decrypt = sharedPrefs.getBoolean("usf_decrypt", false) usf_share = sharedPrefs.getBoolean("usf_share", false) } @@ -175,72 +240,6 @@ class ExplorerActivity : BaseExplorerActivity() { } } - fun onClickFAB(view: View) { - if (currentItemAction != ItemsActions.NONE){ - openDialogCreateFolder() - } else { - val adapter = IconTextDialogAdapter(this) - adapter.items = listOf( - listOf("importFromOtherVolumes", R.string.import_from_other_volume, R.drawable.icon_transfert), - listOf("importFiles", R.string.import_files, R.drawable.icon_encrypt), - listOf("createFile", R.string.new_file, R.drawable.icon_file_unknown), - listOf("createFolder", R.string.mkdir, R.drawable.icon_folder), - listOf("takePhoto", R.string.take_photo, R.drawable.icon_camera) - ) - ColoredAlertDialogBuilder(this) - .setSingleChoiceItems(adapter, -1){ thisDialog, which -> - when (adapter.getItem(which)){ - "importFromOtherVolumes" -> { - val intent = Intent(this, OpenActivity::class.java) - intent.action = "pick" - intent.putExtra("sessionID", gocryptfsVolume.sessionID) - isStartingActivity = true - pickFromOtherVolumes.launch(intent) - } - "importFiles" -> { - isStartingActivity = true - pickFiles.launch(arrayOf("*/*")) - } - "createFile" -> { - val dialogEditTextView = layoutInflater.inflate(R.layout.dialog_edit_text, null) - val dialogEditText = dialogEditTextView.findViewById(R.id.dialog_edit_text) - val dialog = ColoredAlertDialogBuilder(this) - .setView(dialogEditTextView) - .setTitle(getString(R.string.enter_file_name)) - .setPositiveButton(R.string.ok) { _, _ -> - val fileName = dialogEditText.text.toString() - createNewFile(fileName) - } - .setNegativeButton(R.string.cancel, null) - .create() - dialogEditText.setOnEditorActionListener { _, _, _ -> - val fileName = dialogEditText.text.toString() - dialog.dismiss() - createNewFile(fileName) - true - } - dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - dialog.show() - } - "createFolder" -> { - openDialogCreateFolder() - } - "takePhoto" -> { - val intent = Intent(this, CameraActivity::class.java) - intent.putExtra("path", currentDirectoryPath) - intent.putExtra("sessionID", gocryptfsVolume.sessionID) - isStartingActivity = true - startActivity(intent) - } - } - thisDialog.dismiss() - } - .setTitle(getString(R.string.fab_dialog_title)) - .setNegativeButton(R.string.cancel, null) - .show() - } - } - override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.explorer, menu) if (currentItemAction != ItemsActions.NONE) { diff --git a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityDrop.kt b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityDrop.kt index 233c05b..1ba3e4b 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityDrop.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityDrop.kt @@ -4,17 +4,16 @@ import android.content.Intent import android.net.Uri import android.view.Menu import android.view.MenuItem -import android.view.View +import kotlinx.android.synthetic.main.activity_explorer_drop.* import sushi.hardcore.droidfs.R import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder class ExplorerActivityDrop : BaseExplorerActivity() { override fun init() { setContentView(R.layout.activity_explorer_drop) - } - - fun onClickFAB(view: View) { - openDialogCreateFolder() + fab.setOnClickListener { + openDialogCreateFolder() + } } override fun onCreateOptionsMenu(menu: Menu): Boolean { diff --git a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/ImageViewer.kt b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/ImageViewer.kt index c660013..c16bc28 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/ImageViewer.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/ImageViewer.kt @@ -83,6 +83,64 @@ class ImageViewer: FileViewerActivity() { } } }) + image_delete.setOnClickListener { + ColoredAlertDialogBuilder(this) + .keepFullScreen() + .setTitle(R.string.warning) + .setPositiveButton(R.string.ok) { _, _ -> + createPlaylist() //be sure the playlist is created before deleting if there is only one image + if (gocryptfsVolume.removeFile(filePath)) { + playlistNext(true) + refreshPlaylist() + if (mappedPlaylist.size == 0) { //deleted all images of the playlist + goBackToExplorer() + } else { + loadImage() + } + } else { + ColoredAlertDialogBuilder(this) + .keepFullScreen() + .setTitle(R.string.error) + .setMessage(getString(R.string.remove_failed, fileName)) + .setPositiveButton(R.string.ok, null) + .show() + } + } + .setNegativeButton(R.string.cancel, null) + .setMessage(getString(R.string.single_delete_confirm, fileName)) + .show() + } + image_button_slideshow.setOnClickListener { + if (!slideshowActive){ + slideshowActive = true + handler.postDelayed(slideshowNext, ConstValues.slideshow_delay) + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + hideUI.run() + Toast.makeText(this, R.string.slideshow_started, Toast.LENGTH_SHORT).show() + } else { + stopSlideshow() + } + } + image_previous.setOnClickListener { + askSaveRotation { + image_viewer.resetZoomFactor() + swipeImage(1F) + } + } + image_next.setOnClickListener { + askSaveRotation { + image_viewer.resetZoomFactor() + swipeImage(-1F) + } + } + image_rotate_right.setOnClickListener { + rotationAngle += 90 + rotateImage() + } + image_rotate_left.setOnClickListener { + rotationAngle -= 90 + rotateImage() + } loadImage() handler.postDelayed(hideUI, hideDelay) } @@ -114,46 +172,6 @@ class ImageViewer: FileViewerActivity() { } } - fun onClickDelete(view: View) { - ColoredAlertDialogBuilder(this) - .keepFullScreen() - .setTitle(R.string.warning) - .setPositiveButton(R.string.ok) { _, _ -> - createPlaylist() //be sure the playlist is created before deleting if there is only one image - if (gocryptfsVolume.removeFile(filePath)) { - playlistNext(true) - refreshPlaylist() - if (mappedPlaylist.size == 0) { //deleted all images of the playlist - goBackToExplorer() - } else { - loadImage() - } - } else { - ColoredAlertDialogBuilder(this) - .keepFullScreen() - .setTitle(R.string.error) - .setMessage(getString(R.string.remove_failed, fileName)) - .setPositiveButton(R.string.ok, null) - .show() - } - } - .setNegativeButton(R.string.cancel, null) - .setMessage(getString(R.string.single_delete_confirm, fileName)) - .show() - } - - fun onClickSlideshow(view: View) { - if (!slideshowActive){ - slideshowActive = true - handler.postDelayed(slideshowNext, ConstValues.slideshow_delay) - window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) - hideUI.run() - Toast.makeText(this, R.string.slideshow_started, Toast.LENGTH_SHORT).show() - } else { - stopSlideshow() - } - } - private fun stopSlideshow(){ slideshowActive = false window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) @@ -186,27 +204,6 @@ class ImageViewer: FileViewerActivity() { image_viewer.restoreZoomNormal() glideImage.transform(RotateTransformation(this)).into(image_viewer) } - fun onCLickRotateRight(view: View){ - rotationAngle += 90 - rotateImage() - } - fun onClickRotateLeft(view: View){ - rotationAngle -= 90 - rotateImage() - } - - fun onClickPrevious(view: View){ - askSaveRotation { - image_viewer.resetZoomFactor() - swipeImage(1F) - } - } - fun onClickNext(view: View){ - askSaveRotation { - image_viewer.resetZoomFactor() - swipeImage(-1F) - } - } private fun askSaveRotation(callback: () -> Unit){ if (rotationAngle%360 != 0f && !slideshowActive){ diff --git a/app/src/main/java/sushi/hardcore/droidfs/widgets/TakePhotoButton.kt b/app/src/main/java/sushi/hardcore/droidfs/widgets/TakePhotoButton.kt index c1dd211..e32f0d0 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/widgets/TakePhotoButton.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/widgets/TakePhotoButton.kt @@ -9,10 +9,11 @@ class TakePhotoButton: AppCompatImageView { constructor(context: Context) : super(context) { init() } constructor(context: Context, attrs: AttributeSet): super(context, attrs) { init() } constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int): super(context, attrs, defStyleAttr) { init() } - lateinit var onClick: ()->Unit + lateinit var onClick: () -> Unit - private fun init(){ - setOnTouchListener{ _, event -> + private fun init() { + setOnTouchListener{ view, event -> + view.performClick() when (event.action) { MotionEvent.ACTION_DOWN -> onClick() MotionEvent.ACTION_UP -> isPressed = true diff --git a/app/src/main/res/layout/activity_camera.xml b/app/src/main/res/layout/activity_camera.xml index dc63ec0..7915427 100644 --- a/app/src/main/res/layout/activity_camera.xml +++ b/app/src/main/res/layout/activity_camera.xml @@ -21,7 +21,6 @@ android:id="@+id/image_ratio" android:layout_width="30dp" android:layout_height="30dp" - android:onClick="onClickRatio" android:src="@drawable/icon_aspect_ratio" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@id/image_timer" @@ -32,7 +31,6 @@ android:id="@+id/image_timer" android:layout_width="30dp" android:layout_height="30dp" - android:onClick="onClickTimer" android:src="@drawable/icon_timer_off" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@id/image_close" @@ -43,7 +41,6 @@ android:id="@+id/image_close" android:layout_width="30dp" android:layout_height="30dp" - android:onClick="onClickClose" android:src="@drawable/icon_close" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" @@ -73,8 +70,7 @@ android:src="@drawable/icon_flash_auto" android:layout_alignEnd="@id/take_photo_button" android:layout_marginEnd="120dp" - android:layout_centerVertical="true" - android:onClick="onClickFlash"/> + android:layout_centerVertical="true"/> + android:layout_centerVertical="true"/> diff --git a/app/src/main/res/layout/activity_change_password.xml b/app/src/main/res/layout/activity_change_password.xml index 5d8590a..cb23c8d 100644 --- a/app/src/main/res/layout/activity_change_password.xml +++ b/app/src/main/res/layout/activity_change_password.xml @@ -97,11 +97,11 @@ android:text="@string/create_password_warning"/> diff --git a/app/src/main/res/layout/activity_create.xml b/app/src/main/res/layout/activity_create.xml index 20261a7..fb4e442 100644 --- a/app/src/main/res/layout/activity_create.xml +++ b/app/src/main/res/layout/activity_create.xml @@ -69,10 +69,10 @@ android:text="@string/create_password_warning"/> diff --git a/app/src/main/res/layout/activity_explorer.xml b/app/src/main/res/layout/activity_explorer.xml index 9b335d6..b4bbc33 100644 --- a/app/src/main/res/layout/activity_explorer.xml +++ b/app/src/main/res/layout/activity_explorer.xml @@ -37,13 +37,13 @@ + android:src="@drawable/icon_add"/> diff --git a/app/src/main/res/layout/activity_explorer_drop.xml b/app/src/main/res/layout/activity_explorer_drop.xml index 98f5d8e..a96214f 100644 --- a/app/src/main/res/layout/activity_explorer_drop.xml +++ b/app/src/main/res/layout/activity_explorer_drop.xml @@ -35,13 +35,13 @@ + android:src="@drawable/icon_add"/> diff --git a/app/src/main/res/layout/activity_image_viewer.xml b/app/src/main/res/layout/activity_image_viewer.xml index ba9c467..062665e 100644 --- a/app/src/main/res/layout/activity_image_viewer.xml +++ b/app/src/main/res/layout/activity_image_viewer.xml @@ -1,6 +1,5 @@ @@ -65,40 +62,40 @@ android:gravity="center"> + android:src="@drawable/exo_icon_previous"/> + android:src="@drawable/icon_rotate_left"/> + android:src="@drawable/icon_rotate_right"/> + android:src="@drawable/exo_icon_next"/> diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index b7b7e16..012c9f7 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -29,7 +29,6 @@ app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toTopOf="@id/button_create" android:layout_marginHorizontal="@dimen/main_activity_button_hor_margin" - android:onClick="onClickOpen" android:text="@string/open_volume" style="@style/button"/> @@ -40,7 +39,6 @@ app:layout_constraintTop_toBottomOf="@id/button_open" app:layout_constraintBottom_toTopOf="@id/button_change_password" android:layout_marginHorizontal="@dimen/main_activity_button_hor_margin" - android:onClick="onClickCreate" android:text="@string/create_volume" style="@style/button"/> @@ -51,7 +49,6 @@ app:layout_constraintTop_toBottomOf="@id/button_create" app:layout_constraintBottom_toBottomOf="parent" android:layout_marginHorizontal="@dimen/main_activity_button_hor_margin" - android:onClick="onClickChangePassword" android:text="@string/change_volume_password" style="@style/button"/> diff --git a/app/src/main/res/layout/activity_open.xml b/app/src/main/res/layout/activity_open.xml index cc573fc..864cd2f 100644 --- a/app/src/main/res/layout/activity_open.xml +++ b/app/src/main/res/layout/activity_open.xml @@ -56,11 +56,11 @@ android:text="@string/open_activity_warning"/> diff --git a/app/src/main/res/layout/checkboxes_section.xml b/app/src/main/res/layout/checkboxes_section.xml index 70987e1..0ae9f36 100644 --- a/app/src/main/res/layout/checkboxes_section.xml +++ b/app/src/main/res/layout/checkboxes_section.xml @@ -8,15 +8,13 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - android:text="@string/remember_volume_path" - android:onClick="onClickRememberPath"/> + android:text="@string/remember_volume_path"/> + android:text="@string/fingerprint_save_checkbox_text"/> \ No newline at end of file diff --git a/app/src/main/res/layout/volume_path_section.xml b/app/src/main/res/layout/volume_path_section.xml index a5de4fd..6fa87c0 100644 --- a/app/src/main/res/layout/volume_path_section.xml +++ b/app/src/main/res/layout/volume_path_section.xml @@ -11,8 +11,7 @@ android:layout_height="wrap_content" android:text="@string/hidden_volume" app:switchPadding="10dp" - android:layout_gravity="center_horizontal" - android:onClick="onClickSwitchHiddenVolume"/> + android:layout_gravity="center_horizontal"/>