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