@@ -7,6 +7,7 @@ import android.content.*
7
7
import android.content.pm.PackageManager
8
8
import android.content.res.Configuration
9
9
import android.database.Cursor
10
+ import android.graphics.Point
10
11
import android.net.Uri
11
12
import android.os.Build
12
13
import android.os.Bundle
@@ -26,40 +27,10 @@ import androidx.appcompat.app.AppCompatActivity
26
27
import androidx.appcompat.app.AppCompatDelegate
27
28
import androidx.core.app.ActivityCompat
28
29
import androidx.core.content.ContextCompat
29
- import androidx.core.content.FileProvider
30
30
import com.google.android.material.chip.Chip
31
31
import com.mikhailgrigorev.quickpass.dbhelpers.DataBaseHelper
32
32
import com.mikhailgrigorev.quickpass.dbhelpers.PasswordsDataBaseHelper
33
- import kotlinx.android.synthetic.main.activity_edit_pass.*
34
33
import kotlinx.android.synthetic.main.activity_new_password.*
35
- import kotlinx.android.synthetic.main.activity_new_password.accountAvatar
36
- import kotlinx.android.synthetic.main.activity_new_password.accountAvatarText
37
- import kotlinx.android.synthetic.main.activity_new_password.attachedImage
38
- import kotlinx.android.synthetic.main.activity_new_password.authToggle
39
- import kotlinx.android.synthetic.main.activity_new_password.back
40
- import kotlinx.android.synthetic.main.activity_new_password.cardPass
41
- import kotlinx.android.synthetic.main.activity_new_password.cryptToggle
42
- import kotlinx.android.synthetic.main.activity_new_password.email
43
- import kotlinx.android.synthetic.main.activity_new_password.emailField
44
- import kotlinx.android.synthetic.main.activity_new_password.emailSwitch
45
- import kotlinx.android.synthetic.main.activity_new_password.genPasswordId
46
- import kotlinx.android.synthetic.main.activity_new_password.genPasswordIdField
47
- import kotlinx.android.synthetic.main.activity_new_password.generatePassword
48
- import kotlinx.android.synthetic.main.activity_new_password.keyWordsField
49
- import kotlinx.android.synthetic.main.activity_new_password.lengthToggle
50
- import kotlinx.android.synthetic.main.activity_new_password.lettersToggle
51
- import kotlinx.android.synthetic.main.activity_new_password.newName
52
- import kotlinx.android.synthetic.main.activity_new_password.newNameField
53
- import kotlinx.android.synthetic.main.activity_new_password.noteField
54
- import kotlinx.android.synthetic.main.activity_new_password.numbersToggle
55
- import kotlinx.android.synthetic.main.activity_new_password.passQuality
56
- import kotlinx.android.synthetic.main.activity_new_password.passSettings
57
- import kotlinx.android.synthetic.main.activity_new_password.savePass
58
- import kotlinx.android.synthetic.main.activity_new_password.seekBar
59
- import kotlinx.android.synthetic.main.activity_new_password.symToggles
60
- import kotlinx.android.synthetic.main.activity_new_password.timeLimit
61
- import kotlinx.android.synthetic.main.activity_new_password.upload
62
- import kotlinx.android.synthetic.main.activity_new_password.upperCaseToggle
63
34
import java.io.File
64
35
import java.io.FileInputStream
65
36
import java.io.FileOutputStream
@@ -80,6 +51,7 @@ class NewPasswordActivity : AppCompatActivity() {
80
51
private var useUC = false
81
52
private var useLetters = false
82
53
private var useNumbers = false
54
+ private var imageName: String = " "
83
55
84
56
private lateinit var login: String
85
57
@@ -498,57 +470,39 @@ class NewPasswordActivity : AppCompatActivity() {
498
470
499
471
pdbHelper.close()
500
472
setResult(1 , intent)
501
- finish()
502
- }
503
- }
504
- }
505
-
506
- upload.setOnClickListener{
507
- checkPermissionForImage()
508
- }
509
473
510
474
475
+ val mediaStorageDir = File (
476
+ applicationContext.getExternalFilesDir(" QuickPassPhotos" )!! .absolutePath
477
+ )
478
+ if (! mediaStorageDir.exists()) {
479
+ mediaStorageDir.mkdirs()
480
+ Toast .makeText(applicationContext, " Directory Created" , Toast .LENGTH_LONG ).show()
481
+ }
511
482
512
- val mediaStorageDir = File (
513
- applicationContext.getExternalFilesDir(" QuickPassPhotos" )!! .absolutePath
514
- )
515
- if (! mediaStorageDir.exists()) {
516
- mediaStorageDir.mkdirs()
517
- Toast .makeText(applicationContext, " Directory Created" , Toast .LENGTH_LONG ).show()
518
- }
483
+ if (! mediaStorageDir.exists()) {
484
+ if (! mediaStorageDir.mkdirs()) {
485
+ Log .d(" App" , " failed to create directory" )
486
+ }
487
+ }
519
488
520
- if (! mediaStorageDir.exists()) {
521
- if (! mediaStorageDir.mkdirs()) {
522
- Log .d(" App" , " failed to create directory" )
489
+ if (mediaStorageDir.exists()) {
490
+ if (imageName != " " ) {
491
+ val from = File (mediaStorageDir, " $imageName .jpg" )
492
+ val to = File (mediaStorageDir, " ${newNameField.text} .jpg" )
493
+ if (from.exists())
494
+ from.renameTo(to)
495
+ }
496
+ }
497
+ finish()
498
+ }
523
499
}
524
500
}
525
501
526
- val file = File (mediaStorageDir, " ${newNameField.text} .jpg" )
527
- if (file.exists()){
528
- val uri = Uri .fromFile(file)
529
- attachedImage.setImageURI(uri)
530
- clearImage.visibility = View .VISIBLE
531
-
532
- val width = attachedImage.drawable.minimumWidth/ 2
533
- val height = attachedImage.drawable.minimumHeight/ 2
534
- attachedImage.layoutParams.height = height
535
- attachedImage.layoutParams.width = width
536
-
537
- attachedImage.setOnClickListener {
538
- val uriForOpen = FileProvider .getUriForFile(
539
- this ,
540
- this .applicationContext.packageName.toString() + " .provider" ,
541
- file
542
- )
543
- val intent = Intent ()
544
- intent.action = Intent .ACTION_VIEW
545
- intent.setDataAndType(uriForOpen, " image/*" )
546
- intent.addFlags(Intent .FLAG_GRANT_READ_URI_PERMISSION )
547
- startActivity(intent)
548
- }
502
+ upload.setOnClickListener{
503
+ checkPermissionForImage()
549
504
}
550
505
551
-
552
506
}
553
507
554
508
@@ -648,19 +602,25 @@ class NewPasswordActivity : AppCompatActivity() {
648
602
if (resultCode == Activity .RESULT_OK && requestCode == IMAGE_PICK_CODE ) {
649
603
// I'M GETTING THE URI OF THE IMAGE AS DATA AND SETTING IT TO THE IMAGEVIEW
650
604
attachedImage.setImageURI(data?.data)
651
- val width = attachedImage.drawable.minimumWidth/ 2
652
- val height = attachedImage.drawable.minimumHeight/ 2
605
+ val display = windowManager.defaultDisplay
606
+ val size = Point ()
607
+ display.getSize(size)
608
+ val widthMax: Int = size.x
609
+ val width = (widthMax/ 1.3 ).toInt()
610
+ val height = attachedImage.drawable.minimumHeight * width / attachedImage.drawable.minimumWidth
611
+ attachedImage.layoutParams.height = height
612
+ attachedImage.layoutParams.width = width
653
613
attachedImage.layoutParams.height = height
654
614
attachedImage.layoutParams.width = width
655
615
if (ContextCompat .checkSelfPermission(
656
616
this ,
657
- android. Manifest .permission.WRITE_EXTERNAL_STORAGE
617
+ Manifest .permission.WRITE_EXTERNAL_STORAGE
658
618
)
659
619
!= PackageManager .PERMISSION_GRANTED
660
620
) {
661
621
ActivityCompat .requestPermissions(
662
622
this ,
663
- arrayOf(android. Manifest .permission.WRITE_EXTERNAL_STORAGE ),
623
+ arrayOf(Manifest .permission.WRITE_EXTERNAL_STORAGE ),
664
624
PackageManager .PERMISSION_GRANTED
665
625
)
666
626
}
@@ -681,7 +641,11 @@ class NewPasswordActivity : AppCompatActivity() {
681
641
}
682
642
}
683
643
684
- val file = File (mediaStorageDir, " ${newNameField.text} .jpg" )
644
+ imageName = if (newNameField.text.toString() == " " ){
645
+ " 000000001tmp000000001"
646
+ } else
647
+ newNameField.text.toString()
648
+ val file = File (mediaStorageDir, " ${imageName} .jpg" )
685
649
686
650
copyFile(File (getRealPathFromURI(selectedImageURI)), file)
687
651
isImage = true
0 commit comments