Remove two actions dialog due to inconsistency of upload

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2023-12-11 14:27:09 +01:00
parent 50e45380b7
commit 1461da205c
No known key found for this signature in database
GPG key ID: 4E577DC593B59BDF
5 changed files with 6 additions and 182 deletions

View file

@ -104,7 +104,6 @@ import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
import com.owncloud.android.ui.dialog.StoragePermissionDialogFragment;
import com.owncloud.android.ui.dialog.SyncFileNotEnoughSpaceDialogFragment;
import com.owncloud.android.ui.dialog.SyncedFolderPreferencesDialogFragment;
import com.owncloud.android.ui.dialog.TwoActionDialogFragment;
import com.owncloud.android.ui.fragment.ExtendedListFragment;
import com.owncloud.android.ui.fragment.FeatureFragment;
import com.owncloud.android.ui.fragment.FileDetailActivitiesFragment;
@ -270,9 +269,6 @@ abstract class ComponentsModule {
@ContributesAndroidInjector
abstract ChooseTemplateDialogFragment chooseTemplateDialogFragment();
@ContributesAndroidInjector
abstract TwoActionDialogFragment twoActionDialogFragment();
@ContributesAndroidInjector
abstract AccountRemovalDialog accountRemovalDialog();

View file

@ -20,7 +20,6 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.nextcloud.client.account.User
import com.nextcloud.model.HTTPStatusCodes
import com.nextcloud.utils.extensions.getParcelableArgument
@ -208,21 +207,11 @@ class ConflictsResolveActivity : FileActivity(), OnConflictDecisionMadeListener
private fun showErrorAndFinish(code: Int? = null) {
val message = parseErrorMessage(code)
runOnUiThread {
if (code != null) {
sendHandleFileExistenceEventBroadcast()
} else {
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
}
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
finish()
}
}
private fun sendHandleFileExistenceEventBroadcast() {
val intent = Intent(UploadListActivity.HANDLE_FILE_EXISTENCE_RECEIVER)
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
}
private fun parseErrorMessage(code: Int?): String {
return if (code == HTTPStatusCodes.NOT_FOUND.code) {
getString(R.string.uploader_file_not_found_on_server_message)

View file

@ -44,7 +44,6 @@ import com.nextcloud.client.device.PowerManagementService;
import com.nextcloud.client.jobs.BackgroundJobManager;
import com.nextcloud.client.network.ConnectivityService;
import com.nextcloud.client.utils.Throttler;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.databinding.UploadListLayoutBinding;
import com.owncloud.android.datamodel.OCFile;
@ -58,12 +57,10 @@ import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.operations.CheckCurrentCredentialsOperation;
import com.owncloud.android.ui.adapter.UploadListAdapter;
import com.owncloud.android.ui.decoration.MediaGridItemDecoration;
import com.owncloud.android.ui.dialog.TwoActionDialogFragment;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.FilesSyncHelper;
import com.owncloud.android.utils.theme.ViewThemeUtils;
import java.util.Collections;
import javax.inject.Inject;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -78,7 +75,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
public class UploadListActivity extends FileActivity {
private static final String TAG = UploadListActivity.class.getSimpleName();
public static final String HANDLE_FILE_EXISTENCE_RECEIVER = "HANDLE_FILE_EXISTENCE_RECEIVER";
private UploadMessagesReceiver uploadMessagesReceiver;
@ -150,52 +146,6 @@ public class UploadListActivity extends FileActivity {
setupDrawer(R.id.nav_uploads);
setupContent();
registerHandleFileExistenceDialogReceiver();
}
private void registerHandleFileExistenceDialogReceiver() {
IntentFilter filter = new IntentFilter(HANDLE_FILE_EXISTENCE_RECEIVER);
LocalBroadcastManager.getInstance(this).registerReceiver(handleFileExistenceReceiver, filter);
}
private final BroadcastReceiver handleFileExistenceReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
showHandleFileExistenceDialog();
}
};
private void showHandleFileExistenceDialog() {
TwoActionDialogFragment dialog = TwoActionDialogFragment
.Companion
.newInstance(R.string.uploader_handle_not_existed_file_dialog_title,
R.string.uploader_handle_not_existed_file_dialog_message,
R.string.uploader_handle_not_existed_file_dialog_negative_button_text,
R.string.uploader_handle_not_existed_file_dialog_positive_button_text,
new TwoActionDialogFragment.TwoActionDialogActionListener() {
final OCUpload upload = uploadListAdapter.selectedOCUpload;
@Override
public void positiveAction() {
upload.setLastResult(null);
FileUploader.retryUpload(MainApp.getAppContext(), userAccountManager.getUser(), upload);
}
@Override
public void negativeAction() {
OCFile fileOnlyExistOnLocalStorage = getStorageManager().getFileByEncryptedRemotePath(upload.getRemotePath());
getFileOperationsHelper().removeFiles(Collections.singletonList(fileOnlyExistOnLocalStorage), false, false);
uploadListAdapter.removeUpload(upload);
}
});
dialog.show(this.getSupportFragmentManager(), null);
}
@Override
protected void onDestroy() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(handleFileExistenceReceiver);
super.onDestroy();
}
private void setupContent() {
@ -252,11 +202,13 @@ public class UploadListActivity extends FileActivity {
uploadsStorageManager,
connectivityService,
userAccountManager,
powerManagementService)).start();
powerManagementService))
.start();
// update UI
uploadListAdapter.loadUploadItemsFromDb();
swipeListRefreshLayout.setRefreshing(false);
DisplayUtils.showSnackMessage(this, R.string.uploader_local_files_uploaded);
}
@Override

View file

@ -1,110 +0,0 @@
/*
* Nextcloud Android client application
*
* @author Alper Ozturk
* Copyright (C) 2023 Alper Ozturk
* Copyright (C) 2023 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.owncloud.android.ui.dialog
import android.app.Dialog
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import com.google.android.material.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.nextcloud.client.di.Injectable
import com.owncloud.android.utils.theme.ViewThemeUtils
import javax.inject.Inject
class TwoActionDialogFragment(val listener: TwoActionDialogActionListener) : DialogFragment(), Injectable {
@Inject
lateinit var viewThemeUtils: ViewThemeUtils
interface TwoActionDialogActionListener {
fun positiveAction()
fun negativeAction()
}
companion object {
const val titleArgument = "titleArgument"
const val messageArgument = "messageArgument"
const val negativeButtonArgument = "negativeButtonArgument"
const val positiveButtonArgument = "positiveButtonArgument"
fun newInstance(
titleId: Int,
messageId: Int?,
negativeButtonTextId: Int,
positiveButtonTextId: Int,
listener: TwoActionDialogActionListener
): TwoActionDialogFragment {
return TwoActionDialogFragment(listener).apply {
arguments = Bundle().apply {
putInt(titleArgument, titleId)
messageId?.let { putInt(messageArgument, it) }
putInt(positiveButtonArgument, positiveButtonTextId)
putInt(negativeButtonArgument, negativeButtonTextId)
}
}
}
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val title = requireContext().getString(requireArguments().getInt(titleArgument))
val messageId: Int? = arguments?.getInt(messageArgument)
val positiveButtonText = requireContext().getString(requireArguments().getInt(positiveButtonArgument))
val negativeButtonText = requireContext().getString(requireArguments().getInt(negativeButtonArgument))
val builder = MaterialAlertDialogBuilder(requireContext())
.setTitle(title)
.setNegativeButton(negativeButtonText) { dialog, _ ->
dialog.dismiss()
listener.negativeAction()
}
.setPositiveButton(positiveButtonText) { dialog, _ ->
dialog.dismiss()
listener.positiveAction()
}
messageId?.let {
builder.setMessage(requireContext().getString(messageId))
}
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(requireContext(), builder)
return builder.create()
}
override fun onStart() {
super.onStart()
val alertDialog = dialog as AlertDialog?
alertDialog?.let {
val positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE) as MaterialButton?
if (positiveButton != null) {
viewThemeUtils.material.colorMaterialButtonPrimaryTonal(positiveButton)
}
val negativeButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE) as MaterialButton?
if (negativeButton != null) {
viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(negativeButton)
}
}
}
}

View file

@ -913,10 +913,7 @@
<string name="failed_to_start_editor">Failed to start editor</string>
<string name="create_rich_workspace">Add folder info</string>
<string name="creates_rich_workspace">creates folder info</string>
<string name="uploader_handle_not_existed_file_dialog_title">File Not Found</string>
<string name="uploader_handle_not_existed_file_dialog_positive_button_text">Re-upload Local File</string>
<string name="uploader_handle_not_existed_file_dialog_negative_button_text">Delete Local File</string>
<string name="uploader_handle_not_existed_file_dialog_message">This file does not longer exist in server still want to upload?</string>
<string name="uploader_local_files_uploaded">All local files uploaded</string>
<string name="uploader_file_not_found_on_server_message">We couldnt locate the file on server. Another user may have deleted the file</string>
<string name="uploader_file_not_found_message">File not found. Are you sure this file exist or conflict not solved before?</string>
<string name="uploader_upload_failed_sync_conflict_error">File upload conflict</string>