Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Oct 31, 2023
2 parents 3bae1d7 + 1868d03 commit 8b749f1
Show file tree
Hide file tree
Showing 66 changed files with 1,031 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
import java.io.File
import java.security.SecureRandom
import java.util.AbstractList
import java.util.Vector
import javax.inject.Inject

class FileDownloader : Service(), OnDatatransferProgressListener, OnAccountsUpdateListener {
Expand Down Expand Up @@ -184,54 +183,75 @@ class FileDownloader : Service(), OnDatatransferProgressListener, OnAccountsUpda
if (!intent.hasExtra(EXTRA_USER) || !intent.hasExtra(EXTRA_FILE)) {
Log_OC.e(TAG, "Not enough information provided in intent")
return START_NOT_STICKY
} else {
val user = intent.getParcelableExtra<User>(EXTRA_USER)
val file = intent.getParcelableExtra<OCFile>(EXTRA_FILE)
val behaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR)
var downloadType: DownloadType? = DownloadType.DOWNLOAD
if (intent.hasExtra(DOWNLOAD_TYPE)) {
downloadType = intent.getSerializableExtra(DOWNLOAD_TYPE) as DownloadType?
}
val activityName = intent.getStringExtra(SendShareDialog.ACTIVITY_NAME)
val packageName = intent.getStringExtra(SendShareDialog.PACKAGE_NAME)
conflictUploadId = intent.getLongExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, -1)
val requestedDownloads: AbstractList<String> = Vector()
try {
val newDownload = DownloadFileOperation(
user,
file,
behaviour,
activityName,
packageName,
baseContext,
downloadType
)
newDownload.addDatatransferProgressListener(this)
newDownload.addDatatransferProgressListener(mBinder as FileDownloaderBinder?)
val putResult = mPendingDownloads.putIfAbsent(
user!!.accountName,
file!!.remotePath,
newDownload
)
if (putResult != null) {
val downloadKey = putResult.first
requestedDownloads.add(downloadKey)
sendBroadcastNewDownload(newDownload, putResult.second)
} // else, file already in the queue of downloads; don't repeat the request
} catch (e: IllegalArgumentException) {
Log_OC.e(TAG, "Not enough information provided in intent: " + e.message)
return START_NOT_STICKY
}
if (requestedDownloads.size > 0) {
val msg = mServiceHandler!!.obtainMessage()
msg.arg1 = startId
msg.obj = requestedDownloads
mServiceHandler!!.sendMessage(msg)
}

val user = intent.getParcelableExtra<User>(EXTRA_USER)
val file = intent.getParcelableExtra<OCFile>(EXTRA_FILE)
val behaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR)
var downloadType: DownloadType? = DownloadType.DOWNLOAD
if (intent.hasExtra(DOWNLOAD_TYPE)) {
downloadType = intent.getSerializableExtra(DOWNLOAD_TYPE) as DownloadType?
}
val activityName = intent.getStringExtra(SendShareDialog.ACTIVITY_NAME)
val packageName = intent.getStringExtra(SendShareDialog.PACKAGE_NAME)
conflictUploadId = intent.getLongExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, -1)

val requestedDownloads = handleDownloadRequest(user, file, behaviour, downloadType, activityName, packageName)

if (requestedDownloads.isNotEmpty()) {
val msg = mServiceHandler?.obtainMessage()
msg?.arg1 = startId
msg?.obj = requestedDownloads
msg?.let {
mServiceHandler?.sendMessage(it)
}
}

return START_NOT_STICKY
}

@Suppress("LongParameterList")
private fun handleDownloadRequest(
user: User?,
file: OCFile?,
behaviour: String?,
downloadType: DownloadType?,
activityName: String?,
packageName: String?
): List<String> {
val requestedDownloads: MutableList<String> = ArrayList()

if (user == null || file == null) {
return requestedDownloads
}

try {
val newDownload = DownloadFileOperation(
user,
file,
behaviour,
activityName,
packageName,
baseContext,
downloadType
)
newDownload.addDatatransferProgressListener(this)
newDownload.addDatatransferProgressListener(mBinder as FileDownloaderBinder?)

val putResult = mPendingDownloads.putIfAbsent(user.accountName, file.remotePath, newDownload)

if (putResult != null) {
val downloadKey = putResult.first
requestedDownloads.add(downloadKey)
sendBroadcastNewDownload(newDownload, putResult.second)
}
} catch (e: IllegalArgumentException) {
Log_OC.e(TAG, "Not enough information provided in intent: " + e.message)
}

return requestedDownloads
}

/**
* Provides a binder object that clients can use to perform operations on the queue of downloads,
* excepting the addition of new files.
Expand Down Expand Up @@ -286,13 +306,9 @@ class FileDownloader : Service(), OnDatatransferProgressListener, OnAccountsUpda
if (download != null) {
download.cancel()
} else {
if (mCurrentDownload != null && currentUser.isPresent &&
mCurrentDownload!!
.remotePath
.startsWith(file.remotePath) && account.name == currentUser.get().accountName
) {
mCurrentDownload!!.cancel()
}
mCurrentDownload?.takeIf {
it.remotePath.startsWith(file.remotePath) && account.name == currentUser?.get()?.accountName
}?.cancel()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,31 +399,34 @@ open class FolderPickerActivity :
}

override fun onClick(v: View) {
if (v == mCancelBtn) {
finish()
} else if (v == mCopyBtn || v == mMoveBtn) {
val i = intent
val resultData = Intent()
resultData.putExtra(EXTRA_FOLDER, listOfFilesFragment!!.currentFile)
val targetFiles = i.getParcelableArrayListExtra<Parcelable>(EXTRA_FILES)
if (targetFiles != null) {
resultData.putParcelableArrayListExtra(EXTRA_FILES, targetFiles)
}
when (v) {
mCancelBtn -> finish()
mCopyBtn, mMoveBtn -> copyOrMove(v)
}
}

mTargetFilePaths.let {
if (it != null) {
if (v == mCopyBtn) {
fileOperationsHelper.moveOrCopyFiles(OperationsService.ACTION_COPY_FILE, it, file)
} else {
fileOperationsHelper.moveOrCopyFiles(OperationsService.ACTION_MOVE_FILE, it, file)
}
}
private fun copyOrMove(v: View) {
val i = intent
val resultData = Intent()
resultData.putExtra(EXTRA_FOLDER, listOfFilesFragment?.currentFile)

i.getParcelableArrayListExtra<Parcelable>(EXTRA_FILES)?.let { targetFiles ->
resultData.putParcelableArrayListExtra(EXTRA_FILES, targetFiles)
}

resultData.putStringArrayListExtra(EXTRA_FILE_PATHS, it)
mTargetFilePaths?.let {
val action = when (v) {
mCopyBtn -> OperationsService.ACTION_COPY_FILE
mMoveBtn -> OperationsService.ACTION_MOVE_FILE
else -> throw IllegalArgumentException("Unknown operation")
}
setResult(RESULT_OK, resultData)
finish()

fileOperationsHelper.moveOrCopyFiles(action, it, file)
resultData.putStringArrayListExtra(EXTRA_FILE_PATHS, it)
}

setResult(RESULT_OK, resultData)
finish()
}

override fun onRemoteOperationFinish(operation: RemoteOperation<*>?, result: RemoteOperationResult<*>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,22 @@ open class ConfirmationDialogFragment : DialogFragment(), Injectable {
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
var messageArguments = requireArguments().getStringArray(ARG_MESSAGE_ARGUMENTS)
val messageArguments = requireArguments().getStringArray(ARG_MESSAGE_ARGUMENTS) ?: arrayOf<String>()
val titleId = requireArguments().getInt(ARG_TITLE_ID, -1)
val messageId = requireArguments().getInt(ARG_MESSAGE_RESOURCE_ID, -1)
val positiveButtonTextId = requireArguments().getInt(ARG_POSITIVE_BTN_RES, -1)
val negativeButtonTextId = requireArguments().getInt(ARG_NEGATIVE_BTN_RES, -1)
val neutralButtonTextId = requireArguments().getInt(ARG_NEUTRAL_BTN_RES, -1)

if (messageArguments == null) {
messageArguments = arrayOf<String?>()
}
@Suppress("SpreadOperator")
val message = getString(messageId, *messageArguments)

val builder = MaterialAlertDialogBuilder(requireActivity())
.setTitle(if (titleId == 0) { R.string.dialog_alert_title } else { titleId })
.setIcon(com.owncloud.android.R.drawable.ic_warning)
.setIconAttribute(R.attr.alertDialogIcon)
.setMessage(String.format(getString(messageId), messageArguments))
.setMessage(message)

if (titleId == 0) {
builder.setTitle(R.string.dialog_alert_title)
} else if (titleId != -1) {
builder.setTitle(titleId)
}
if (positiveButtonTextId != -1) {
builder.setPositiveButton(positiveButtonTextId) { dialog: DialogInterface, _: Int ->
mListener?.onConfirmation(tag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,20 @@ import android.os.Build
import android.os.Bundle
import android.os.storage.StorageManager
import androidx.annotation.RequiresApi
import com.nextcloud.client.di.Injectable
import com.owncloud.android.R
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener
import com.owncloud.android.ui.fragment.OCFileListFragment
import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.theme.ViewThemeUtils
import javax.inject.Inject

/**
* Dialog requiring confirmation when a file/folder is too "big" to be synchronized/downloaded on device.
*/
class SyncFileNotEnoughSpaceDialogFragment :
ConfirmationDialogFragment(),
ConfirmationDialogFragmentListener,
Injectable {
private var targetFile: OCFile? = null
ConfirmationDialogFragmentListener {

@JvmField
@Inject
var viewThemeUtils: ViewThemeUtils? = null
private var targetFile: OCFile? = null

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
targetFile = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Expand All @@ -62,7 +55,7 @@ class SyncFileNotEnoughSpaceDialogFragment :
/**
* (Only if file is a folder), will access the destination folder to allow user to choose what to synchronize
*/
override fun onConfirmation(callerTag: String) {
override fun onConfirmation(callerTag: String?) {
val frag = targetFragment as OCFileListFragment?

if (frag != null && targetFile != null) {
Expand All @@ -73,15 +66,15 @@ class SyncFileNotEnoughSpaceDialogFragment :
/**
* Will abort/cancel the process (is neutral to "hack" android button position ._.)
*/
override fun onNeutral(callerTag: String) {
override fun onNeutral(callerTag: String?) {
// Nothing
}

/**
* Will access to storage manager in order to empty useless files
*/
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
override fun onCancel(callerTag: String) {
override fun onCancel(callerTag: String?) {
val storageIntent = Intent(StorageManager.ACTION_MANAGE_STORAGE)
startActivityForResult(storageIntent, REQUEST_CODE_STORAGE)
}
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<string name="action_switch_grid_view">عرض شبكي</string>
<string name="action_switch_list_view">عرض على شكل قائمة</string>
<string name="actionbar_calendar_contacts_restore">استعادة جهات الاتصال &amp; التقويم</string>
<string name="actionbar_copy">نسخ</string>
<string name="actionbar_mkdir">مجلد جديد</string>
<string name="actionbar_move">نقل</string>
<string name="actionbar_open_with">فتح باستخدام</string>
<string name="actionbar_search">بحث</string>
<string name="actionbar_see_details">تفاصيل</string>
Expand Down Expand Up @@ -90,6 +92,7 @@
<string name="check_back_later_or_reload">عُد إليه فيما بعد أو أعد تحميله</string>
<string name="checkbox">مربع تحقق</string>
<string name="choose_local_folder">اختر المجلد المحلي…</string>
<string name="choose_location">اختر الموقع</string>
<string name="choose_remote_folder">اختر مجلد عن بُعد…</string>
<string name="choose_template_helper_text">اختر قالب وادخل اسم الملف</string>
<string name="choose_which_file">اختر أي من أياً من الملفات التالية التي تريد الإحتفاظ بها!</string>
Expand Down Expand Up @@ -119,6 +122,7 @@
<string name="common_remove">إزالة</string>
<string name="common_rename">إعادة التسمية</string>
<string name="common_save">حفظ</string>
<string name="common_select">تحديد</string>
<string name="common_send">إرسال</string>
<string name="common_share">مشاركة</string>
<string name="common_skip">تخطي</string>
Expand Down Expand Up @@ -170,6 +174,7 @@
<string name="copy_file_not_found">تعذّر النسخ. يرجى التحقق من وجود الملف.</string>
<string name="copy_link">نسخ الرابط</string>
<string name="copy_move_to_encrypted_folder_not_supported">النسخ أو النقل إلى مجلد مشفر حالياً غير مدعوم.</string>
<string name="copy_to">انسخه إلى…</string>
<string name="could_not_download_image">لايمكن تحميل الصورة بأكملها</string>
<string name="could_not_retrieve_shares">لايمكن استعادة المشاركات</string>
<string name="could_not_retrieve_url">لا يمكن استرجاع الرابط</string>
Expand Down Expand Up @@ -386,6 +391,7 @@
<string name="folder_already_exists">المجلد موجود مسبقاً</string>
<string name="folder_confirm_create">إنشاء</string>
<string name="folder_list_empty_headline">لا توجد مجلدات</string>
<string name="folder_picker_choose_button_text">اختيار</string>
<string name="forbidden_permissions">غير مسموح لك أن %s</string>
<string name="forbidden_permissions_copy">لنسخ هذا الملف</string>
<string name="forbidden_permissions_create">لإنشاء هذا الملف</string>
Expand Down Expand Up @@ -491,6 +497,7 @@
<string name="move_file_invalid_into_descendent">لا يمكن نقل مجلد في مجلدات هوَّ يتضمنها</string>
<string name="move_file_invalid_overwrite">هذا الملف موجود حالياً في المجلد المُّسّتَقبِل</string>
<string name="move_file_not_found">غير قادر على نقل الملف. يرجى التحقق مما إذا كان موجوداً.</string>
<string name="move_to">نقل إلى…</string>
<string name="network_error_connect_timeout_exception">حدث خطأ أثناء انتظار الخادم. تعذر إكمال العملية.</string>
<string name="network_error_socket_exception">حدث خطأ أثناء الاتصال بالخادم</string>
<string name="network_error_socket_timeout_exception">حدث خطأ أثناء انتظار الخادم. تعذر إكمال العملية.</string>
Expand Down Expand Up @@ -735,6 +742,12 @@
<string name="signup_with_provider">التسجيل عبر مزوّد خدمة</string>
<string name="single_sign_on_request_token" formatted="true">هل تسمح لـ%1$s بالوصول إلى حسابك %2$s في Nextcloud؟</string>
<string name="sort_by">ترتيب</string>
<string name="sort_by_modification_date_ascending">الأحدث أولا</string>
<string name="sort_by_modification_date_descending">الأقدم أولا</string>
<string name="sort_by_name_ascending">أ - ى</string>
<string name="sort_by_name_descending">ى -أ</string>
<string name="sort_by_size_ascending">الأصغر حجما أولا</string>
<string name="sort_by_size_descending">الأكبر حجما أولا</string>
<string name="ssl_validator_btn_details_hide">إخفاء</string>
<string name="ssl_validator_btn_details_see">تفاصيل</string>
<string name="ssl_validator_header">لا يمكن التحقق من هوية الخادم</string>
Expand Down
Loading

0 comments on commit 8b749f1

Please sign in to comment.