From 4b8f47155c92a138f9336eb663afb4e1523f26fb Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Sun, 10 Jan 2021 22:30:35 +0100 Subject: [PATCH] Make buttons prettier, defer uploading to when the image is posted, add remove button --- .../postCreation/PostCreationActivity.kt | 183 +++++++++--------- ...xml => add_photo_alternate_white_30dp.xml} | 6 +- app/src/main/res/drawable/delete_30dp.xml | 9 + ...d_file_24dp.xml => download_file_30dp.xml} | 6 +- ...ne_edit_24.xml => ic_baseline_edit_30.xml} | 6 +- .../res/layout/activity_post_creation.xml | 117 ++++++----- .../res/layout/add_more_album_creation.xml | 2 +- .../main/res/layout/image_album_creation.xml | 2 +- 8 files changed, 178 insertions(+), 153 deletions(-) rename app/src/main/res/drawable/{add_photo_alternate_black_24dp.xml => add_photo_alternate_white_30dp.xml} (78%) create mode 100644 app/src/main/res/drawable/delete_30dp.xml rename app/src/main/res/drawable/{download_file_24dp.xml => download_file_30dp.xml} (68%) rename app/src/main/res/drawable/{ic_baseline_edit_24.xml => ic_baseline_edit_30.xml} (77%) diff --git a/app/src/main/java/com/h/pixeldroid/postCreation/PostCreationActivity.kt b/app/src/main/java/com/h/pixeldroid/postCreation/PostCreationActivity.kt index 454cf265..61259dfc 100644 --- a/app/src/main/java/com/h/pixeldroid/postCreation/PostCreationActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/postCreation/PostCreationActivity.kt @@ -4,7 +4,6 @@ import android.app.Activity import android.content.ContentResolver import android.content.ContentValues import android.content.Intent -import android.graphics.Bitmap import android.media.MediaScannerConnection import android.net.Uri import android.os.Build @@ -13,17 +12,13 @@ import android.os.Environment import android.provider.MediaStore import android.provider.OpenableColumns import android.util.Log -import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup import android.widget.Button +import android.widget.ImageButton import android.widget.Toast import androidx.core.net.toFile import androidx.core.net.toUri import androidx.lifecycle.lifecycleScope -import androidx.recyclerview.widget.GridLayoutManager -import androidx.recyclerview.widget.RecyclerView -import com.bumptech.glide.Glide import com.google.android.material.snackbar.Snackbar import com.google.android.material.textfield.TextInputLayout import com.h.pixeldroid.utils.BaseActivity @@ -34,7 +29,6 @@ import com.h.pixeldroid.postCreation.camera.CameraActivity import com.h.pixeldroid.utils.db.entities.UserDatabaseEntity import com.h.pixeldroid.utils.api.objects.Attachment import com.h.pixeldroid.utils.api.objects.Instance -import com.h.pixeldroid.utils.api.objects.Status import com.h.pixeldroid.postCreation.photoEdit.PhotoEditActivity import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable @@ -44,10 +38,7 @@ import kotlinx.android.synthetic.main.image_album_creation.view.* import okhttp3.MultipartBody import org.imaginativeworld.whynotimagecarousel.CarouselItem import org.imaginativeworld.whynotimagecarousel.ImageCarousel -import retrofit2.Call -import retrofit2.Callback import retrofit2.HttpException -import retrofit2.Response import java.io.File import java.io.IOException import java.io.OutputStream @@ -58,20 +49,21 @@ import kotlin.collections.ArrayList private const val TAG = "Post Creation Activity" private const val MORE_PICTURES_REQUEST_CODE = 0xffff +data class PhotoData( + var imageUri: Uri, + var uploadId: String? = null, + var progress: Int? = null +) class PostCreationActivity : BaseActivity() { private lateinit var accessToken: String private lateinit var pixelfedAPI: PixelfedAPI - private var muListOfIds: MutableList = mutableListOf() - private var progressList: ArrayList = arrayListOf() - - private var positionResult = 0 private var user: UserDatabaseEntity? = null - private var posts: ArrayList = ArrayList() + private val photoData: ArrayList = ArrayList() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -81,8 +73,9 @@ class PostCreationActivity : BaseActivity() { if(intent.clipData != null) { val count = intent.clipData!!.itemCount for (i in 0 until count) { - val imageUri: String = intent.clipData!!.getItemAt(i).uri.toString() - posts.add(imageUri) + intent.clipData!!.getItemAt(i).uri.let { + photoData.add(PhotoData(it)) + } } } @@ -105,76 +98,84 @@ class PostCreationActivity : BaseActivity() { accessToken = user?.accessToken.orEmpty() pixelfedAPI = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) - // check if the pictures are alright - // TODO - - //upload the picture and display progress while doing so - muListOfIds = posts.map { "" }.toMutableList() - progressList = posts.map { 0 } as ArrayList - upload() - - val carousel: ImageCarousel = findViewById(R.id.carousel) - carousel.addData(posts.map { CarouselItem(it) }) + carousel.addData(photoData.map { CarouselItem(it.imageUri.toString()) }) // get the description and send the post findViewById