From e539ce92322d779ddad53d4a5805b708fd0bb795 Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Sat, 19 Nov 2022 23:23:11 +0100 Subject: [PATCH] Improve stuff somewhat --- app/src/main/AndroidManifest.xml | 1 + .../app/postCreation/PostCreationFragment.kt | 9 ++++----- .../app/postCreation/PostCreationViewModel.kt | 12 +++++++++--- .../app/postCreation/PostSubmissionFragment.kt | 4 +--- app/src/main/res/layout/fragment_post_submission.xml | 5 ++--- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 915bc2c3..80dfee89 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -56,6 +56,7 @@ diff --git a/app/src/main/java/org/pixeldroid/app/postCreation/PostCreationFragment.kt b/app/src/main/java/org/pixeldroid/app/postCreation/PostCreationFragment.kt index e0d722b8..4d24cdbc 100644 --- a/app/src/main/java/org/pixeldroid/app/postCreation/PostCreationFragment.kt +++ b/app/src/main/java/org/pixeldroid/app/postCreation/PostCreationFragment.kt @@ -223,11 +223,11 @@ class PostCreationFragment : BaseFragment() { requireActivity(), arrayOf(path.toUri().toFile().absolutePath), null - ) { path, uri -> + ) { tried_path, uri -> if (uri == null) { Log.e( "NEW IMAGE SCAN FAILED", - "Tried to scan $path, but it failed" + "Tried to scan $tried_path, but it failed" ) } } @@ -263,8 +263,7 @@ class PostCreationFragment : BaseFragment() { path = imageUri.toString() outputStream = resolver.openOutputStream(imageUri)!! } else { - @Suppress("DEPRECATION") val imagesDir = - Environment.getExternalStoragePublicDirectory(getString(R.string.app_name)) + val imagesDir = Environment.getExternalStoragePublicDirectory(getString(R.string.app_name)) imagesDir.mkdir() val file = File(imagesDir, name) path = Uri.fromFile(file).toString() @@ -289,7 +288,7 @@ class PostCreationFragment : BaseFragment() { ActivityResultContracts.StartActivityForResult()){ result: ActivityResult? -> if (result?.resultCode == Activity.RESULT_OK && result.data != null) { - val position: Int = result.data!!.getIntExtra(org.pixeldroid.media_editor.photoEdit.PhotoEditActivity.PICTURE_POSITION, 0) + val position: Int = result.data!!.getIntExtra(PhotoEditActivity.PICTURE_POSITION, 0) model.modifyAt(position, result.data!!) ?: Toast.makeText(requireActivity(), R.string.error_editing, Toast.LENGTH_SHORT).show() } else if(result?.resultCode != Activity.RESULT_CANCELED){ diff --git a/app/src/main/java/org/pixeldroid/app/postCreation/PostCreationViewModel.kt b/app/src/main/java/org/pixeldroid/app/postCreation/PostCreationViewModel.kt index 4f9c214f..7ed6e672 100644 --- a/app/src/main/java/org/pixeldroid/app/postCreation/PostCreationViewModel.kt +++ b/app/src/main/java/org/pixeldroid/app/postCreation/PostCreationViewModel.kt @@ -102,7 +102,13 @@ data class PhotoData( var videoEncodeError: Boolean = false, ) : Parcelable -class PostCreationViewModel(application: Application, clipdata: ClipData? = null, val instance: InstanceDatabaseEntity? = null, val existingDescription: String? = null, val existingNSFW: Boolean = false) : AndroidViewModel(application) { +class PostCreationViewModel( + application: Application, + clipdata: ClipData? = null, + val instance: InstanceDatabaseEntity? = null, + existingDescription: String? = null, + existingNSFW: Boolean = false +) : AndroidViewModel(application) { private val photoData: MutableLiveData> by lazy { MutableLiveData>().also { it.value = clipdata?.let { it1 -> addPossibleImages(it1, mutableListOf()) } @@ -118,10 +124,10 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null (application as PixelDroidApplication).getAppComponent().inject(this) val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(application) - val initialDescription = sharedPreferences.getString("prefill_description", "") ?: "" + val templateDescription = sharedPreferences.getString("prefill_description", "") ?: "" _uiState = MutableStateFlow(PostCreationActivityUiState( - newPostDescriptionText = existingDescription ?: initialDescription, + newPostDescriptionText = existingDescription ?: templateDescription, nsfw = existingNSFW )) } diff --git a/app/src/main/java/org/pixeldroid/app/postCreation/PostSubmissionFragment.kt b/app/src/main/java/org/pixeldroid/app/postCreation/PostSubmissionFragment.kt index 371f41e3..bda9bac7 100644 --- a/app/src/main/java/org/pixeldroid/app/postCreation/PostSubmissionFragment.kt +++ b/app/src/main/java/org/pixeldroid/app/postCreation/PostSubmissionFragment.kt @@ -30,7 +30,6 @@ class PostSubmissionFragment : BaseFragment() { private lateinit var accounts: List private var selectedAccount: Int = -1 -// private lateinit var menu: Menu private var user: UserDatabaseEntity? = null private lateinit var instance: InstanceDatabaseEntity @@ -46,7 +45,6 @@ class PostSubmissionFragment : BaseFragment() { // Inflate the layout for this fragment binding = FragmentPostSubmissionBinding.inflate(layoutInflater) -// setHasOptionsMenu(true) return binding.root } @@ -119,7 +117,7 @@ class PostSubmissionFragment : BaseFragment() { binding.postTextInputLayout.counterMaxLength = instance.maxStatusChars - setSquareImageFromURL(View(requireActivity()), model.getPhotoData()!!.value?.get(0)?.imageUri.toString(), binding.postPreview) + setSquareImageFromURL(View(requireActivity()), model.getPhotoData().value?.get(0)?.imageUri.toString(), binding.postPreview) // Get the description and send the post binding.postCreationSendButton.setOnClickListener { diff --git a/app/src/main/res/layout/fragment_post_submission.xml b/app/src/main/res/layout/fragment_post_submission.xml index 47044b6b..4c418050 100644 --- a/app/src/main/res/layout/fragment_post_submission.xml +++ b/app/src/main/res/layout/fragment_post_submission.xml @@ -9,14 +9,13 @@ + app:layout_constraintTop_toTopOf="parent" />