mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Fixed bugs
This commit is contained in:
parent
520baedace
commit
3b660da0e2
10 changed files with 96 additions and 67 deletions
|
|
@ -267,19 +267,21 @@ public class ContributionsFragment
|
|||
pendingUploadsCountTextView = uploadMenuItemActionView.findViewById(R.id.pending_uploads_count_badge);
|
||||
uploadsErrorTextView = uploadMenuItemActionView.findViewById(R.id.uploads_error_count_badge);
|
||||
final ImageView pendingUploadsImageView = uploadMenuItemActionView.findViewById(R.id.pending_uploads_image_view);
|
||||
|
||||
pendingUploadsImageView.setOnClickListener(view -> {
|
||||
startActivity(new Intent(getContext(), UploadProgressActivity.class));
|
||||
});
|
||||
|
||||
pendingUploadsCountTextView.setOnClickListener(view -> {
|
||||
startActivity(new Intent(getContext(), UploadProgressActivity.class));
|
||||
});
|
||||
|
||||
uploadsErrorTextView.setOnClickListener(view -> {
|
||||
startActivity(new Intent(getContext(), UploadProgressActivity.class));
|
||||
});
|
||||
|
||||
if (pendingUploadsImageView != null){
|
||||
pendingUploadsImageView.setOnClickListener(view -> {
|
||||
startActivity(new Intent(getContext(), UploadProgressActivity.class));
|
||||
});
|
||||
}
|
||||
if (pendingUploadsCountTextView != null) {
|
||||
pendingUploadsCountTextView.setOnClickListener(view -> {
|
||||
startActivity(new Intent(getContext(), UploadProgressActivity.class));
|
||||
});
|
||||
}
|
||||
if (uploadsErrorTextView != null) {
|
||||
uploadsErrorTextView.setOnClickListener(view -> {
|
||||
startActivity(new Intent(getContext(), UploadProgressActivity.class));
|
||||
});
|
||||
}
|
||||
notification.setOnClickListener(view -> {
|
||||
NotificationActivity.startYourself(getContext(), "unread");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -17,9 +17,10 @@ import timber.log.Timber
|
|||
import java.io.File
|
||||
|
||||
|
||||
class FailedUploadsAdapter(items: List<Contribution>) :
|
||||
class FailedUploadsAdapter(items: List<Contribution>, callback: Callback) :
|
||||
RecyclerView.Adapter<FailedUploadsAdapter.ViewHolder>() {
|
||||
private val items: List<Contribution> = items
|
||||
private var callback: FailedUploadsAdapter.Callback = callback
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view: View =
|
||||
|
|
@ -51,6 +52,12 @@ class FailedUploadsAdapter(items: List<Contribution>) :
|
|||
holder.errorTextView.visibility = View.VISIBLE
|
||||
holder.itemProgress.visibility = View.GONE
|
||||
}
|
||||
holder.deleteButton.setOnClickListener {
|
||||
callback.deleteUpload(item)
|
||||
}
|
||||
holder.retryButton.setOnClickListener {
|
||||
callback.restartUpload(position)
|
||||
}
|
||||
holder.itemImage.setImageRequest(imageRequest)
|
||||
}
|
||||
|
||||
|
|
@ -67,9 +74,11 @@ class FailedUploadsAdapter(items: List<Contribution>) :
|
|||
var itemProgress: ProgressBar = itemView.findViewById<ProgressBar>(R.id.itemProgress)
|
||||
var errorTextView: TextView = itemView.findViewById<TextView>(R.id.errorTextView)
|
||||
var deleteButton: ImageView = itemView.findViewById(R.id.deleteButton)
|
||||
var retryButton: ImageView = itemView.findViewById(R.id.retryButton)
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
fun deleteUpload(contribution: Contribution?)
|
||||
fun restartUpload(index : Int)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.view.ViewGroup
|
|||
import androidx.fragment.app.Fragment
|
||||
import androidx.paging.PagedList
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import fr.free.nrw.commons.CommonsApplication
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.auth.SessionManager
|
||||
import fr.free.nrw.commons.contributions.Contribution
|
||||
|
|
@ -26,7 +27,7 @@ import javax.inject.Inject
|
|||
* Use the [FailedUploadsFragment.newInstance] factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContract.View {
|
||||
class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContract.View, FailedUploadsAdapter.Callback {
|
||||
private var param1: String? = null
|
||||
private var param2: String? = null
|
||||
private val ARG_PARAM1 = "param1"
|
||||
|
|
@ -107,7 +108,7 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContr
|
|||
} else {
|
||||
binding.nofailedTextView.visibility = View.GONE
|
||||
binding.failedUplaodsLl.visibility = View.VISIBLE
|
||||
val adapter = FailedUploadsAdapter(contributionsList)
|
||||
val adapter = FailedUploadsAdapter(contributionsList, this)
|
||||
binding.failedUploadsRecyclerView.setAdapter(adapter)
|
||||
}
|
||||
}
|
||||
|
|
@ -126,6 +127,7 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContr
|
|||
|
||||
fun restartUploads() {
|
||||
if (contributionsList != null) {
|
||||
uploadProgressActivity.resetProgressBar()
|
||||
pendingUploadsPresenter.restartUploads(
|
||||
contributionsList,
|
||||
0,
|
||||
|
|
@ -134,6 +136,42 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContr
|
|||
}
|
||||
}
|
||||
|
||||
override fun restartUpload(index : Int) {
|
||||
if (contributionsList != null) {
|
||||
uploadProgressActivity.resetProgressBar()
|
||||
pendingUploadsPresenter.restartUpload(
|
||||
contributionsList,
|
||||
index,
|
||||
this.requireContext().applicationContext
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun deleteUpload(contribution: Contribution?) {
|
||||
DialogUtil.showAlertDialog(
|
||||
requireActivity(),
|
||||
String.format(
|
||||
Locale.getDefault(),
|
||||
getString(R.string.cancelling_upload)
|
||||
),
|
||||
String.format(
|
||||
Locale.getDefault(),
|
||||
getString(R.string.cancel_upload_dialog)
|
||||
),
|
||||
String.format(Locale.getDefault(), getString(R.string.yes)),
|
||||
String.format(Locale.getDefault(), getString(R.string.no)),
|
||||
{
|
||||
ViewUtil.showShortToast(context, R.string.cancelling_upload)
|
||||
pendingUploadsPresenter.deleteUpload(
|
||||
contribution,
|
||||
this.requireContext().applicationContext
|
||||
)
|
||||
CommonsApplication.cancelledUploads.add(contribution!!.pageId)
|
||||
},
|
||||
{}
|
||||
)
|
||||
}
|
||||
|
||||
fun deleteUploads() {
|
||||
if (contributionsList != null) {
|
||||
DialogUtil.showAlertDialog(
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package fr.free.nrw.commons.upload;
|
|||
import android.content.Context;
|
||||
import fr.free.nrw.commons.BasePresenter;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract;
|
||||
import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract.View;
|
||||
|
||||
public class PendingUploadsContract {
|
||||
|
||||
|
|
@ -10,7 +12,6 @@ public class PendingUploadsContract {
|
|||
|
||||
public interface UserActionListener extends
|
||||
BasePresenter<fr.free.nrw.commons.upload.PendingUploadsContract.View> {
|
||||
|
||||
void deleteUpload(Contribution contribution, Context context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -191,6 +191,7 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
|||
ViewUtil.showShortToast(context, R.string.cancelling_upload)
|
||||
pendingUploadsPresenter.deleteUpload(contribution, this.requireContext().applicationContext)
|
||||
CommonsApplication.cancelledUploads.add(contribution!!.pageId)
|
||||
resetProgressBar()
|
||||
},
|
||||
{}
|
||||
)
|
||||
|
|
@ -242,4 +243,8 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun resetProgressBar() {
|
||||
totalUploads = 0
|
||||
}
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ import fr.free.nrw.commons.contributions.ContributionBoundaryCallback;
|
|||
import fr.free.nrw.commons.contributions.ContributionsRemoteDataSource;
|
||||
import fr.free.nrw.commons.contributions.ContributionsRepository;
|
||||
import fr.free.nrw.commons.di.CommonsApplicationModule;
|
||||
import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract;
|
||||
import fr.free.nrw.commons.upload.PendingUploadsContract.UserActionListener;
|
||||
import fr.free.nrw.commons.upload.PendingUploadsContract.View;
|
||||
import fr.free.nrw.commons.upload.worker.WorkRequestHelper;
|
||||
|
|
@ -96,7 +97,6 @@ public class PendingUploadsPresenter implements UserActionListener {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDetachView() {
|
||||
compositeDisposable.clear();
|
||||
|
|
@ -178,4 +178,19 @@ public class PendingUploadsPresenter implements UserActionListener {
|
|||
));
|
||||
}
|
||||
|
||||
public void restartUpload(List<Contribution> l, int index, Context context) {
|
||||
if (index >= l.size()) {
|
||||
return;
|
||||
}
|
||||
Contribution it = l.get(index);
|
||||
it.setState(Contribution.STATE_QUEUED);
|
||||
compositeDisposable.add(repository
|
||||
.save(it)
|
||||
.subscribeOn(ioThreadScheduler)
|
||||
.subscribe(() ->
|
||||
WorkRequestHelper.Companion.makeOneTimeWorkRequest(
|
||||
context, ExistingWorkPolicy.KEEP)
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,4 +154,9 @@ class UploadProgressActivity : BaseActivity() {
|
|||
updateMenuItems(binding.uploadProgressViewPager.currentItem)
|
||||
}
|
||||
|
||||
fun resetProgressBar(){
|
||||
pendingUploadsFragment!!.resetProgressBar()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,9 +27,10 @@
|
|||
android:layout_alignEnd="@id/pending_uploads_image_view"
|
||||
android:layout_alignRight="@id/pending_uploads_image_view"
|
||||
android:background="@drawable/notification_badge"
|
||||
android:backgroundTint="@color/button_blue"
|
||||
android:gravity="center"
|
||||
android:padding="@dimen/miniscule_margin"
|
||||
android:textColor="?attr/notification_icon_text_color"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="7sp"
|
||||
android:textStyle="bold"
|
||||
android:visibility="gone"
|
||||
|
|
@ -47,10 +48,9 @@
|
|||
android:layout_marginEnd="0dp"
|
||||
android:layout_marginRight="0dp"
|
||||
android:background="@drawable/notification_badge"
|
||||
android:backgroundTint="@color/button_blue"
|
||||
android:gravity="center"
|
||||
android:padding="@dimen/miniscule_margin"
|
||||
android:textColor="@color/white"
|
||||
android:textColor="?attr/notification_icon_text_color"
|
||||
android:textSize="7sp"
|
||||
android:textStyle="bold"
|
||||
android:visibility="gone"
|
||||
|
|
|
|||
|
|
@ -92,50 +92,6 @@ class ContributionViewHolderUnitTests {
|
|||
Assert.assertNotNull(contributionViewHolder)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetResume() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = ContributionViewHolder::class.java.getDeclaredMethod(
|
||||
"setResume"
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(contributionViewHolder)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetPaused() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = ContributionViewHolder::class.java.getDeclaredMethod(
|
||||
"setPaused"
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(contributionViewHolder)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testPause() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = ContributionViewHolder::class.java.getDeclaredMethod(
|
||||
"pause"
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(contributionViewHolder)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testResume() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = ContributionViewHolder::class.java.getDeclaredMethod(
|
||||
"resume"
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(contributionViewHolder)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testWikipediaButtonClicked() {
|
||||
|
|
|
|||
|
|
@ -162,9 +162,7 @@ class UploadClientTest {
|
|||
whenever(contribution.fileKey).thenReturn(filekey)
|
||||
whenever(fileUtilsWrapper.getMimeType(anyOrNull<File>())).thenReturn("image/png")
|
||||
whenever(fileUtilsWrapper.getFileChunks(anyOrNull<File>(), eq(expectedChunkSize))).thenReturn(emptyList())
|
||||
|
||||
val result = uploadClient.uploadFileToStash(filename, contribution, mock()).test()
|
||||
|
||||
result.assertNoErrors()
|
||||
verify(contribution, times(1)).unpause()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue