Improve stuff somewhat
This commit is contained in:
parent
ca09fba7f3
commit
e539ce9232
|
@ -56,6 +56,7 @@
|
||||||
<activity
|
<activity
|
||||||
android:name=".postCreation.PostCreationActivity"
|
android:name=".postCreation.PostCreationActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
android:windowSoftInputMode="adjustResize"
|
||||||
android:theme="@style/AppTheme.NoActionBar">
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.SEND_MULTIPLE" />
|
<action android:name="android.intent.action.SEND_MULTIPLE" />
|
||||||
|
|
|
@ -223,11 +223,11 @@ class PostCreationFragment : BaseFragment() {
|
||||||
requireActivity(),
|
requireActivity(),
|
||||||
arrayOf(path.toUri().toFile().absolutePath),
|
arrayOf(path.toUri().toFile().absolutePath),
|
||||||
null
|
null
|
||||||
) { path, uri ->
|
) { tried_path, uri ->
|
||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
Log.e(
|
Log.e(
|
||||||
"NEW IMAGE SCAN FAILED",
|
"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()
|
path = imageUri.toString()
|
||||||
outputStream = resolver.openOutputStream(imageUri)!!
|
outputStream = resolver.openOutputStream(imageUri)!!
|
||||||
} else {
|
} else {
|
||||||
@Suppress("DEPRECATION") val imagesDir =
|
val imagesDir = Environment.getExternalStoragePublicDirectory(getString(R.string.app_name))
|
||||||
Environment.getExternalStoragePublicDirectory(getString(R.string.app_name))
|
|
||||||
imagesDir.mkdir()
|
imagesDir.mkdir()
|
||||||
val file = File(imagesDir, name)
|
val file = File(imagesDir, name)
|
||||||
path = Uri.fromFile(file).toString()
|
path = Uri.fromFile(file).toString()
|
||||||
|
@ -289,7 +288,7 @@ class PostCreationFragment : BaseFragment() {
|
||||||
ActivityResultContracts.StartActivityForResult()){
|
ActivityResultContracts.StartActivityForResult()){
|
||||||
result: ActivityResult? ->
|
result: ActivityResult? ->
|
||||||
if (result?.resultCode == Activity.RESULT_OK && result.data != null) {
|
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!!)
|
model.modifyAt(position, result.data!!)
|
||||||
?: Toast.makeText(requireActivity(), R.string.error_editing, Toast.LENGTH_SHORT).show()
|
?: Toast.makeText(requireActivity(), R.string.error_editing, Toast.LENGTH_SHORT).show()
|
||||||
} else if(result?.resultCode != Activity.RESULT_CANCELED){
|
} else if(result?.resultCode != Activity.RESULT_CANCELED){
|
||||||
|
|
|
@ -102,7 +102,13 @@ data class PhotoData(
|
||||||
var videoEncodeError: Boolean = false,
|
var videoEncodeError: Boolean = false,
|
||||||
) : Parcelable
|
) : 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 {
|
private val photoData: MutableLiveData<MutableList<PhotoData>> by lazy {
|
||||||
MutableLiveData<MutableList<PhotoData>>().also {
|
MutableLiveData<MutableList<PhotoData>>().also {
|
||||||
it.value = clipdata?.let { it1 -> addPossibleImages(it1, mutableListOf()) }
|
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)
|
(application as PixelDroidApplication).getAppComponent().inject(this)
|
||||||
val sharedPreferences =
|
val sharedPreferences =
|
||||||
PreferenceManager.getDefaultSharedPreferences(application)
|
PreferenceManager.getDefaultSharedPreferences(application)
|
||||||
val initialDescription = sharedPreferences.getString("prefill_description", "") ?: ""
|
val templateDescription = sharedPreferences.getString("prefill_description", "") ?: ""
|
||||||
|
|
||||||
_uiState = MutableStateFlow(PostCreationActivityUiState(
|
_uiState = MutableStateFlow(PostCreationActivityUiState(
|
||||||
newPostDescriptionText = existingDescription ?: initialDescription,
|
newPostDescriptionText = existingDescription ?: templateDescription,
|
||||||
nsfw = existingNSFW
|
nsfw = existingNSFW
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ class PostSubmissionFragment : BaseFragment() {
|
||||||
|
|
||||||
private lateinit var accounts: List<UserDatabaseEntity>
|
private lateinit var accounts: List<UserDatabaseEntity>
|
||||||
private var selectedAccount: Int = -1
|
private var selectedAccount: Int = -1
|
||||||
// private lateinit var menu: Menu
|
|
||||||
|
|
||||||
private var user: UserDatabaseEntity? = null
|
private var user: UserDatabaseEntity? = null
|
||||||
private lateinit var instance: InstanceDatabaseEntity
|
private lateinit var instance: InstanceDatabaseEntity
|
||||||
|
@ -46,7 +45,6 @@ class PostSubmissionFragment : BaseFragment() {
|
||||||
|
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
binding = FragmentPostSubmissionBinding.inflate(layoutInflater)
|
binding = FragmentPostSubmissionBinding.inflate(layoutInflater)
|
||||||
// setHasOptionsMenu(true)
|
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +117,7 @@ class PostSubmissionFragment : BaseFragment() {
|
||||||
|
|
||||||
binding.postTextInputLayout.counterMaxLength = instance.maxStatusChars
|
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
|
// Get the description and send the post
|
||||||
binding.postCreationSendButton.setOnClickListener {
|
binding.postCreationSendButton.setOnClickListener {
|
||||||
|
|
|
@ -9,14 +9,13 @@
|
||||||
|
|
||||||
<com.google.android.material.appbar.MaterialToolbar
|
<com.google.android.material.appbar.MaterialToolbar
|
||||||
android:id="@+id/top_bar"
|
android:id="@+id/top_bar"
|
||||||
android:layout_width="409dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="?attr/actionBarSize"
|
android:minHeight="?attr/actionBarSize"
|
||||||
android:theme="?attr/actionBarTheme"
|
android:theme="?attr/actionBarTheme"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
app:layout_constraintBottom_toTopOf="@id/post_preview" />
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/post_preview"
|
android:id="@+id/post_preview"
|
||||||
|
|
Loading…
Reference in New Issue