Improve stuff somewhat

This commit is contained in:
Matthieu 2022-11-19 23:23:11 +01:00
parent ca09fba7f3
commit e539ce9232
5 changed files with 17 additions and 14 deletions

View File

@ -56,6 +56,7 @@
<activity
android:name=".postCreation.PostCreationActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />

View File

@ -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){

View File

@ -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<MutableList<PhotoData>> by lazy {
MutableLiveData<MutableList<PhotoData>>().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
))
}

View File

@ -30,7 +30,6 @@ class PostSubmissionFragment : BaseFragment() {
private lateinit var accounts: List<UserDatabaseEntity>
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 {

View File

@ -9,14 +9,13 @@
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/top_bar"
android:layout_width="409dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/post_preview" />
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/post_preview"