mirror of
https://github.com/nextcloud/talk-android
synced 2025-01-31 03:22:03 +00:00
improve code base from review comments
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
3d0f154d7d
commit
3e99dc065b
@ -54,6 +54,26 @@ class ReadFolderListingOperation(okHttpClient: OkHttpClient, currentUser: UserEn
|
|||||||
private val url: String
|
private val url: String
|
||||||
private val depth: Int
|
private val depth: Int
|
||||||
private val basePath: String
|
private val basePath: String
|
||||||
|
|
||||||
|
init {
|
||||||
|
val okHttpClientBuilder: OkHttpClient.Builder = okHttpClient.newBuilder()
|
||||||
|
okHttpClientBuilder.followRedirects(false)
|
||||||
|
okHttpClientBuilder.followSslRedirects(false)
|
||||||
|
okHttpClientBuilder.authenticator(
|
||||||
|
MagicAuthenticator(
|
||||||
|
ApiUtils.getCredentials(
|
||||||
|
currentUser.username,
|
||||||
|
currentUser.token
|
||||||
|
),
|
||||||
|
"Authorization"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
this.okHttpClient = okHttpClientBuilder.build()
|
||||||
|
basePath = currentUser.baseUrl + DavUtils.DAV_PATH + currentUser.userId
|
||||||
|
url = basePath + path
|
||||||
|
this.depth = depth
|
||||||
|
}
|
||||||
|
|
||||||
fun readRemotePath(): DavResponse {
|
fun readRemotePath(): DavResponse {
|
||||||
val davResponse = DavResponse()
|
val davResponse = DavResponse()
|
||||||
val memberElements: MutableList<Response> = ArrayList()
|
val memberElements: MutableList<Response> = ArrayList()
|
||||||
@ -96,29 +116,6 @@ class ReadFolderListingOperation(okHttpClient: OkHttpClient, currentUser: UserEn
|
|||||||
return davResponse
|
return davResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "ReadFilesystemOperation"
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
val okHttpClientBuilder: OkHttpClient.Builder = okHttpClient.newBuilder()
|
|
||||||
okHttpClientBuilder.followRedirects(false)
|
|
||||||
okHttpClientBuilder.followSslRedirects(false)
|
|
||||||
okHttpClientBuilder.authenticator(
|
|
||||||
MagicAuthenticator(
|
|
||||||
ApiUtils.getCredentials(
|
|
||||||
currentUser.username,
|
|
||||||
currentUser.token
|
|
||||||
),
|
|
||||||
"Authorization"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
this.okHttpClient = okHttpClientBuilder.build()
|
|
||||||
basePath = currentUser.baseUrl + DavUtils.DAV_PATH + currentUser.userId
|
|
||||||
url = basePath + path
|
|
||||||
this.depth = depth
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getModelFromResponse(response: Response, remotePath: String): RemoteFileBrowserItem {
|
private fun getModelFromResponse(response: Response, remotePath: String): RemoteFileBrowserItem {
|
||||||
val remoteFileBrowserItem = RemoteFileBrowserItem()
|
val remoteFileBrowserItem = RemoteFileBrowserItem()
|
||||||
remoteFileBrowserItem.path = Uri.decode(remotePath)
|
remoteFileBrowserItem.path = Uri.decode(remotePath)
|
||||||
@ -127,7 +124,9 @@ class ReadFolderListingOperation(okHttpClient: OkHttpClient, currentUser: UserEn
|
|||||||
for (property in properties) {
|
for (property in properties) {
|
||||||
mapPropertyToBrowserFile(property, remoteFileBrowserItem)
|
mapPropertyToBrowserFile(property, remoteFileBrowserItem)
|
||||||
}
|
}
|
||||||
if (remoteFileBrowserItem.permissions != null && remoteFileBrowserItem.permissions!!.contains("R")) {
|
if (remoteFileBrowserItem.permissions != null &&
|
||||||
|
remoteFileBrowserItem.permissions!!.contains(READ_PERMISSION)
|
||||||
|
) {
|
||||||
remoteFileBrowserItem.isAllowedToReShare = true
|
remoteFileBrowserItem.isAllowedToReShare = true
|
||||||
}
|
}
|
||||||
if (TextUtils.isEmpty(remoteFileBrowserItem.mimeType) && !remoteFileBrowserItem.isFile) {
|
if (TextUtils.isEmpty(remoteFileBrowserItem.mimeType) && !remoteFileBrowserItem.isFile) {
|
||||||
@ -172,4 +171,9 @@ class ReadFolderListingOperation(okHttpClient: OkHttpClient, currentUser: UserEn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "ReadFilesystemOperation"
|
||||||
|
private const val READ_PERMISSION = "R"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -514,11 +514,11 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
|
|||||||
try {
|
try {
|
||||||
FileUtils.removeTempCacheFile(
|
FileUtils.removeTempCacheFile(
|
||||||
this.context!!,
|
this.context!!,
|
||||||
"photos/avatar.png"
|
AVATAR_PATH
|
||||||
)
|
)
|
||||||
file = FileUtils.getTempCacheFile(
|
file = FileUtils.getTempCacheFile(
|
||||||
this.context!!,
|
this.context!!,
|
||||||
"photos/avatar.png"
|
AVATAR_PATH
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
FileOutputStream(file).use { out -> bitmap.compress(Bitmap.CompressFormat.PNG, FULL_QUALITY, out) }
|
FileOutputStream(file).use { out -> bitmap.compress(Bitmap.CompressFormat.PNG, FULL_QUALITY, out) }
|
||||||
@ -558,7 +558,7 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
|
|||||||
} else if (resultCode == ImagePicker.RESULT_ERROR) {
|
} else if (resultCode == ImagePicker.RESULT_ERROR) {
|
||||||
Toast.makeText(activity, getError(intent), Toast.LENGTH_SHORT).show()
|
Toast.makeText(activity, getError(intent), Toast.LENGTH_SHORT).show()
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(activity, "Task Cancelled", Toast.LENGTH_SHORT).show()
|
Log.i(TAG, "Task Cancelled")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -808,6 +808,7 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG: String = "ProfileController"
|
private const val TAG: String = "ProfileController"
|
||||||
|
private const val AVATAR_PATH = "photos/avatar.png"
|
||||||
private const val REQUEST_CODE_SELECT_REMOTE_FILES = 22
|
private const val REQUEST_CODE_SELECT_REMOTE_FILES = 22
|
||||||
private const val DEFAULT_CACHE_SIZE: Int = 20
|
private const val DEFAULT_CACHE_SIZE: Int = 20
|
||||||
private const val DEFAULT_RETRIES: Long = 3
|
private const val DEFAULT_RETRIES: Long = 3
|
||||||
|
@ -113,32 +113,7 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
|
|||||||
showEmpty()
|
showEmpty()
|
||||||
}
|
}
|
||||||
is RemoteFileBrowserItemsViewModel.LoadedState -> {
|
is RemoteFileBrowserItemsViewModel.LoadedState -> {
|
||||||
val remoteFileBrowserItems = state.items
|
loadList(state, mimeTypeSelectionFilter)
|
||||||
Log.d(TAG, "Items received: $remoteFileBrowserItems")
|
|
||||||
|
|
||||||
// TODO make showGrid based on preferences (when available)
|
|
||||||
val showGrid = false
|
|
||||||
val layoutManager = if (showGrid) {
|
|
||||||
GridLayoutManager(this, SPAN_COUNT)
|
|
||||||
} else {
|
|
||||||
LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO do not needlessly recreate adapter if it can be reused
|
|
||||||
val adapter = RemoteFileBrowserItemsAdapter(
|
|
||||||
showGrid = showGrid,
|
|
||||||
mimeTypeSelectionFilter = mimeTypeSelectionFilter,
|
|
||||||
userEntity = currentUserProvider.currentUser!!,
|
|
||||||
selectionInterface = this,
|
|
||||||
onItemClicked = viewModel::onItemClicked
|
|
||||||
)
|
|
||||||
adapter.items = remoteFileBrowserItems
|
|
||||||
|
|
||||||
binding.recyclerView.adapter = adapter
|
|
||||||
binding.recyclerView.layoutManager = layoutManager
|
|
||||||
binding.recyclerView.setHasFixedSize(true)
|
|
||||||
|
|
||||||
showList()
|
|
||||||
}
|
}
|
||||||
is RemoteFileBrowserItemsViewModel.FinishState -> {
|
is RemoteFileBrowserItemsViewModel.FinishState -> {
|
||||||
finishWithResult(state.selectedPaths)
|
finishWithResult(state.selectedPaths)
|
||||||
@ -164,6 +139,38 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadList(
|
||||||
|
state: RemoteFileBrowserItemsViewModel.LoadedState,
|
||||||
|
mimeTypeSelectionFilter: String?
|
||||||
|
) {
|
||||||
|
val remoteFileBrowserItems = state.items
|
||||||
|
Log.d(TAG, "Items received: $remoteFileBrowserItems")
|
||||||
|
|
||||||
|
// TODO make showGrid based on preferences (when available)
|
||||||
|
val showGrid = false
|
||||||
|
val layoutManager = if (showGrid) {
|
||||||
|
GridLayoutManager(this, SPAN_COUNT)
|
||||||
|
} else {
|
||||||
|
LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO do not needlessly recreate adapter if it can be reused
|
||||||
|
val adapter = RemoteFileBrowserItemsAdapter(
|
||||||
|
showGrid = showGrid,
|
||||||
|
mimeTypeSelectionFilter = mimeTypeSelectionFilter,
|
||||||
|
userEntity = currentUserProvider.currentUser!!,
|
||||||
|
selectionInterface = this,
|
||||||
|
onItemClicked = viewModel::onItemClicked
|
||||||
|
)
|
||||||
|
adapter.items = remoteFileBrowserItems
|
||||||
|
|
||||||
|
binding.recyclerView.adapter = adapter
|
||||||
|
binding.recyclerView.layoutManager = layoutManager
|
||||||
|
binding.recyclerView.setHasFixedSize(true)
|
||||||
|
|
||||||
|
showList()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||||
super.onCreateOptionsMenu(menu)
|
super.onCreateOptionsMenu(menu)
|
||||||
menuInflater.inflate(R.menu.menu_share_files, menu)
|
menuInflater.inflate(R.menu.menu_share_files, menu)
|
||||||
@ -171,6 +178,11 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onBackPressed() {
|
||||||
|
setResult(Activity.RESULT_CANCELED)
|
||||||
|
super.onBackPressed()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
refreshCurrentPath()
|
refreshCurrentPath()
|
||||||
|
@ -23,11 +23,9 @@
|
|||||||
package com.nextcloud.talk.remotefilebrowser.model
|
package com.nextcloud.talk.remotefilebrowser.model
|
||||||
|
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import com.bluelinelabs.logansquare.annotation.JsonObject
|
|
||||||
import kotlinx.android.parcel.Parcelize
|
import kotlinx.android.parcel.Parcelize
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
@JsonObject
|
|
||||||
data class RemoteFileBrowserItem(
|
data class RemoteFileBrowserItem(
|
||||||
var path: String? = null,
|
var path: String? = null,
|
||||||
var displayName: String? = null,
|
var displayName: String? = null,
|
||||||
@ -43,7 +41,4 @@ data class RemoteFileBrowserItem(
|
|||||||
var isEncrypted: Boolean = false,
|
var isEncrypted: Boolean = false,
|
||||||
var permissions: String? = null,
|
var permissions: String? = null,
|
||||||
var isAllowedToReShare: Boolean = false
|
var isAllowedToReShare: Boolean = false
|
||||||
) : Parcelable {
|
) : Parcelable
|
||||||
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
|
|
||||||
constructor() : this(null, null, null, 0, 0, false, null, false, false, false, null, false)
|
|
||||||
}
|
|
||||||
|
@ -150,7 +150,7 @@ class RemoteFileBrowserItemsViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun changePath(path: String) {
|
private fun changePath(path: String) {
|
||||||
_currentPath.value = path
|
_currentPath.value = path
|
||||||
loadItems()
|
loadItems()
|
||||||
}
|
}
|
||||||
|
@ -40,17 +40,17 @@ class FileSortOrderByName internal constructor(name: String, ascending: Boolean)
|
|||||||
* Comparator for RemoteFileBrowserItems, sorts by name.
|
* Comparator for RemoteFileBrowserItems, sorts by name.
|
||||||
*/
|
*/
|
||||||
class RemoteFileBrowserItemNameComparator(private val multiplier: Int) : Comparator<RemoteFileBrowserItem> {
|
class RemoteFileBrowserItemNameComparator(private val multiplier: Int) : Comparator<RemoteFileBrowserItem> {
|
||||||
|
private val alphanumComparator = AlphanumComparator<RemoteFileBrowserItem>()
|
||||||
|
|
||||||
override fun compare(left: RemoteFileBrowserItem, right: RemoteFileBrowserItem): Int {
|
override fun compare(left: RemoteFileBrowserItem, right: RemoteFileBrowserItem): Int {
|
||||||
return if (!left.isFile && !right.isFile) {
|
return if (!left.isFile && !right.isFile) {
|
||||||
return multiplier * AlphanumComparator<RemoteFileBrowserItem>()
|
return multiplier * alphanumComparator.compare(left.path, right.path)
|
||||||
.compareRemoteFileBrowserItem(left, right)
|
|
||||||
} else if (!left.isFile) {
|
} else if (!left.isFile) {
|
||||||
-1
|
-1
|
||||||
} else if (!right.isFile) {
|
} else if (!right.isFile) {
|
||||||
1
|
1
|
||||||
} else {
|
} else {
|
||||||
multiplier * AlphanumComparator<RemoteFileBrowserItem>().compareRemoteFileBrowserItem(left, right)
|
multiplier * alphanumComparator.compare(left.path, right.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
package third_parties.daveKoeller;
|
package third_parties.daveKoeller;
|
||||||
|
|
||||||
import com.nextcloud.talk.remotefilebrowser.model.RemoteFileBrowserItem;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
@ -86,13 +84,6 @@ public class AlphanumComparator<T> implements Comparator<T>, Serializable {
|
|||||||
return chunk.toString();
|
return chunk.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareRemoteFileBrowserItem(RemoteFileBrowserItem f1, RemoteFileBrowserItem f2) {
|
|
||||||
String s1 = f1.getPath();
|
|
||||||
String s2 = f2.getPath();
|
|
||||||
|
|
||||||
return compare(s1, s2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compare(T t1, T t2) {
|
public int compare(T t1, T t2) {
|
||||||
return compare(t1.toString(), t2.toString());
|
return compare(t1.toString(), t2.toString());
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
build:
|
build:
|
||||||
maxIssues: 89
|
maxIssues: 88
|
||||||
weights:
|
weights:
|
||||||
# complexity: 2
|
# complexity: 2
|
||||||
# LongParameterList: 1
|
# LongParameterList: 1
|
||||||
|
Loading…
Reference in New Issue
Block a user