Merge branch 'post_template' into 'master'

Implement post template

Closes #299

See merge request pixeldroid/PixelDroid!485
This commit is contained in:
Matthieu 2022-10-23 22:46:13 +00:00
commit 631e5324b5
5 changed files with 27 additions and 4 deletions

View File

@ -99,6 +99,9 @@ class PostCreationActivity : BaseThemedWithoutBarActivity() {
)
}
//Get initial text value from model (for template)
binding.newPostDescriptionInputField.setText(model.uiState.value.newPostDescriptionText)
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
model.uiState.collect { uiState ->

View File

@ -11,6 +11,7 @@ import android.widget.Toast
import androidx.core.net.toFile
import androidx.core.net.toUri
import androidx.lifecycle.*
import androidx.preference.PreferenceManager
import com.arthenica.ffmpegkit.FFmpegKit
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.disposables.Disposable
@ -76,19 +77,25 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null
@Inject
lateinit var apiHolder: PixelfedAPIHolder
private val _uiState: MutableStateFlow<PostCreationActivityUiState>
init {
(application as PixelDroidApplication).getAppComponent().inject(this)
val sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(application)
val initialDescription = sharedPreferences.getString("prefill_description", "") ?: ""
_uiState = MutableStateFlow(PostCreationActivityUiState(newPostDescriptionText = initialDescription))
}
val uiState: StateFlow<PostCreationActivityUiState> = _uiState
// Map photoData indexes to FFmpeg Session IDs
private val sessionMap: MutableMap<Int, Long> = mutableMapOf()
// Keep track of temporary files to delete them (avoids filling cache super fast with videos)
private val tempFiles: java.util.ArrayList<File> = java.util.ArrayList()
private val _uiState = MutableStateFlow(PostCreationActivityUiState())
val uiState: StateFlow<PostCreationActivityUiState> = _uiState
fun userMessageShown() {
_uiState.update { currentUiState ->
currentUiState.copy(userMessage = null)

View File

@ -0,0 +1,5 @@
<vector android:height="24dp"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,10h11v2H3V10zM3,8h11V6H3V8zM3,16h7v-2H3V16zM18.01,12.87l0.71,-0.71c0.39,-0.39 1.02,-0.39 1.41,0l0.71,0.71c0.39,0.39 0.39,1.02 0,1.41l-0.71,0.71L18.01,12.87zM17.3,13.58l-5.3,5.3V21h2.12l5.3,-5.3L17.3,13.58z"/>
</vector>

View File

@ -300,6 +300,8 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"</string>
<string name="add_images_error">Error while adding images</string>
<string name="notification_thumbnail">"Thumbnail of image in this notification's post"</string>
<string name="post_preview">Preview of a post</string>
<string name="description_template_summary">"Prefill new posts' description with this"</string>
<string name="description_template">Description template</string>
<plurals name="replies_count">
<item quantity="one">%d reply</item>
<item quantity="other">%d replies</item>

View File

@ -37,6 +37,12 @@
</intent>
</Preference>
<EditTextPreference android:title="@string/description_template"
android:key="prefill_description"
android:summary="@string/description_template_summary"
app:icon="@drawable/note"
/>
<Preference android:title="@string/about"
android:key="about"
android:summary="@string/about_pixeldroid"