mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-23 05:25:31 +03:00
remove legacy references and fix avatar upload permission issues
...by using a different location and remove previous avatars upfront Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
80eccf3176
commit
5bf90157bc
5 changed files with 64 additions and 43 deletions
|
@ -55,7 +55,6 @@ import com.nextcloud.talk.R
|
|||
import com.nextcloud.talk.api.NcApi
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
|
||||
import com.nextcloud.talk.components.filebrowser.controllers.BrowserController.BrowserType
|
||||
import com.nextcloud.talk.controllers.base.NewBaseController
|
||||
import com.nextcloud.talk.controllers.util.viewBinding
|
||||
import com.nextcloud.talk.databinding.ControllerProfileBinding
|
||||
|
@ -72,11 +71,7 @@ import com.nextcloud.talk.ui.dialog.ScopeDialog
|
|||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
import com.nextcloud.talk.utils.FileUtils
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_BROWSER_TYPE
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_MIME_TYPE_FILTER
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SINGLE_SELECTION
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils
|
||||
import io.reactivex.Observer
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
|
@ -86,7 +81,6 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
|||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.ResponseBody
|
||||
import org.parceler.Parcels
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
|
@ -199,7 +193,7 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
|
|||
currentUser = userUtils.currentUser
|
||||
val credentials = ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token)
|
||||
binding.avatarUpload.setOnClickListener { sendSelectLocalFileIntent() }
|
||||
binding.avatarChoose.setOnClickListener { showBrowserScreen(BrowserType.DAV_BROWSER) }
|
||||
binding.avatarChoose.setOnClickListener { showBrowserScreen() }
|
||||
binding.avatarDelete.setOnClickListener {
|
||||
ncApi.deleteAvatar(
|
||||
credentials,
|
||||
|
@ -486,32 +480,14 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
|
|||
startActivityForResult(intent, 1)
|
||||
}
|
||||
|
||||
private fun showBrowserScreen(browserType: BrowserType) {
|
||||
private fun showBrowserScreen() {
|
||||
val bundle = Bundle()
|
||||
bundle.putParcelable(
|
||||
KEY_BROWSER_TYPE,
|
||||
Parcels.wrap(BrowserType::class.java, browserType)
|
||||
)
|
||||
bundle.putParcelable(
|
||||
KEY_USER_ENTITY,
|
||||
Parcels.wrap(UserEntity::class.java, currentUser)
|
||||
)
|
||||
bundle.putBoolean(KEY_SINGLE_SELECTION, true)
|
||||
bundle.putString(KEY_MIME_TYPE_FILTER, "image/")
|
||||
bundle.putString(KEY_ROOM_TOKEN, "123")
|
||||
|
||||
val avatarIntent = Intent(activity, RemoteFileBrowserActivity::class.java)
|
||||
avatarIntent.putExtras(bundle)
|
||||
|
||||
startActivityForResult(avatarIntent, RemoteFileBrowserActivity.REQUEST_CODE_SELECT_AVATAR)
|
||||
|
||||
/*
|
||||
router.pushController(
|
||||
RouterTransaction.with(BrowserForAvatarController(bundle, this))
|
||||
.pushChangeHandler(VerticalChangeHandler())
|
||||
.popChangeHandler(VerticalChangeHandler())
|
||||
)
|
||||
*/
|
||||
}
|
||||
|
||||
fun handleAvatar(remotePath: String?) {
|
||||
|
@ -536,7 +512,14 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
|
|||
private fun saveBitmapAndPassToImagePicker(bitmap: Bitmap) {
|
||||
var file: File? = null
|
||||
try {
|
||||
file = FileUtils.getTempCacheFile(context!!, "avatar/avatar.png")
|
||||
FileUtils.removeTempCacheFile(
|
||||
this.context!!,
|
||||
"photos/avatar.png"
|
||||
)
|
||||
file = FileUtils.getTempCacheFile(
|
||||
this.context!!,
|
||||
"photos/avatar.png"
|
||||
)
|
||||
try {
|
||||
FileOutputStream(file).use { out -> bitmap.compress(Bitmap.CompressFormat.PNG, FULL_QUALITY, out) }
|
||||
} catch (e: IOException) {
|
||||
|
@ -560,12 +543,18 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
|
|||
startActivityForResult(intent, REQUEST_CODE_IMAGE_PICKER)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
|
||||
uploadAvatar(getFile(data))
|
||||
if (requestCode == REQUEST_CODE_IMAGE_PICKER) {
|
||||
uploadAvatar(getFile(intent))
|
||||
} else {
|
||||
val pathList = intent?.getStringArrayListExtra(RemoteFileBrowserActivity.EXTRA_SELECTED_PATHS)
|
||||
if (pathList?.size!! >= 1) {
|
||||
handleAvatar(pathList[0])
|
||||
}
|
||||
}
|
||||
} else if (resultCode == ImagePicker.RESULT_ERROR) {
|
||||
Toast.makeText(activity, getError(data), Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(activity, getError(intent), Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
Toast.makeText(activity, "Task Cancelled", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
|
|
@ -45,8 +45,9 @@ import com.nextcloud.talk.remotefilebrowser.adapters.RemoteFileBrowserItemsAdapt
|
|||
import com.nextcloud.talk.remotefilebrowser.viewmodels.RemoteFileBrowserItemsViewModel
|
||||
import com.nextcloud.talk.ui.dialog.SortingOrderDialogFragment
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
import com.nextcloud.talk.utils.LegacyFileSortOrder
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils
|
||||
import com.nextcloud.talk.utils.FileSortOrder
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_MIME_TYPE_FILTER
|
||||
import com.nextcloud.talk.utils.database.user.CurrentUserProvider
|
||||
import javax.inject.Inject
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication::class)
|
||||
|
@ -55,9 +56,8 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
|
|||
@Inject
|
||||
lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
|
||||
// TODO use CurrentUserProvider instead for narrower scope
|
||||
@Inject
|
||||
lateinit var userUtils: UserUtils
|
||||
lateinit var currentUserProvider: CurrentUserProvider
|
||||
|
||||
private lateinit var binding: ActivityRemoteFileBrowserBinding
|
||||
private lateinit var viewModel: RemoteFileBrowserItemsViewModel
|
||||
|
@ -85,7 +85,10 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
|
|||
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
initViewModel()
|
||||
val extras = intent.extras
|
||||
val mimeTypeSelectionFilter = extras?.getString(KEY_MIME_TYPE_FILTER, null)
|
||||
|
||||
initViewModel(mimeTypeSelectionFilter)
|
||||
|
||||
binding.swipeRefreshList.setOnRefreshListener(this)
|
||||
binding.swipeRefreshList.setColorSchemeResources(R.color.colorPrimary)
|
||||
|
@ -97,7 +100,7 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
|
|||
viewModel.loadItems()
|
||||
}
|
||||
|
||||
private fun initViewModel() {
|
||||
private fun initViewModel(mimeTypeSelectionFilter: String?) {
|
||||
viewModel = ViewModelProvider(this, viewModelFactory)[RemoteFileBrowserItemsViewModel::class.java]
|
||||
|
||||
viewModel.viewState.observe(this) { state ->
|
||||
|
@ -113,7 +116,7 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
|
|||
val remoteFileBrowserItems = state.items
|
||||
Log.d(TAG, "Items received: $remoteFileBrowserItems")
|
||||
|
||||
// TODO make shwoGrid based on preferences
|
||||
// TODO make showGrid based on preferences (when available)
|
||||
val showGrid = false
|
||||
val layoutManager = if (showGrid) {
|
||||
GridLayoutManager(this, SPAN_COUNT)
|
||||
|
@ -121,13 +124,11 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
|
|||
LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
|
||||
}
|
||||
|
||||
// TODO make mimeTypeSelectionFilter a bundled arg for the activity
|
||||
val mimeTypeSelectionFilter = "image/"
|
||||
// TODO do not needlessly recreate adapter if it can be reused
|
||||
val adapter = RemoteFileBrowserItemsAdapter(
|
||||
showGrid = showGrid,
|
||||
mimeTypeSelectionFilter = mimeTypeSelectionFilter,
|
||||
userEntity = userUtils.currentUser!!,
|
||||
userEntity = currentUserProvider.currentUser!!,
|
||||
selectionInterface = this,
|
||||
onItemClicked = viewModel::onItemClicked
|
||||
)
|
||||
|
@ -177,7 +178,7 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
|
|||
|
||||
private fun changeSorting() {
|
||||
val newFragment: DialogFragment = SortingOrderDialogFragment
|
||||
.newInstance(LegacyFileSortOrder.getFileSortOrder(viewModel.fileSortOrder.value!!.name))
|
||||
.newInstance(FileSortOrder.getFileSortOrder(viewModel.fileSortOrder.value!!.name))
|
||||
newFragment.show(
|
||||
supportFragmentManager,
|
||||
SortingOrderDialogFragment.SORTING_ORDER_FRAGMENT
|
||||
|
|
|
@ -36,9 +36,13 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
|||
import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.databinding.SortingOrderFragmentBinding;
|
||||
import com.nextcloud.talk.utils.FileSortOrder;
|
||||
import com.nextcloud.talk.utils.LegacyFileSortOrder;
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -67,6 +71,7 @@ public class SortingOrderDialogFragment extends DialogFragment implements View.O
|
|||
private View[] taggedViews;
|
||||
private String currentSortOrderName;
|
||||
|
||||
@Deprecated
|
||||
public static SortingOrderDialogFragment newInstance(LegacyFileSortOrder sortOrder) {
|
||||
SortingOrderDialogFragment dialogFragment = new SortingOrderDialogFragment();
|
||||
|
||||
|
@ -77,6 +82,16 @@ public class SortingOrderDialogFragment extends DialogFragment implements View.O
|
|||
return dialogFragment;
|
||||
}
|
||||
|
||||
public static SortingOrderDialogFragment newInstance(@NotNull FileSortOrder sortOrder) {
|
||||
SortingOrderDialogFragment dialogFragment = new SortingOrderDialogFragment();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putString(KEY_SORT_ORDER, sortOrder.getName());
|
||||
dialogFragment.setArguments(args);
|
||||
|
||||
return dialogFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
|
@ -65,4 +65,21 @@ public class FileUtils {
|
|||
|
||||
return cacheFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link File}
|
||||
*/
|
||||
public static void removeTempCacheFile(@NonNull Context context, String fileName) throws IOException {
|
||||
File cacheFile = new File(context.getApplicationContext().getFilesDir().getAbsolutePath() + "/" + fileName);
|
||||
|
||||
Log.v(TAG, "Full path for new cache file:" + cacheFile.getAbsolutePath());
|
||||
|
||||
if (cacheFile.exists()) {
|
||||
if(cacheFile.delete()) {
|
||||
Log.v(TAG, "Deletion successful");
|
||||
} else {
|
||||
throw new IOException("Directory for temporary file does not exist and could not be created.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,6 +74,5 @@ object BundleKeys {
|
|||
val KEY_FORWARD_HIDE_SOURCE_ROOM = "KEY_FORWARD_HIDE_SOURCE_ROOM"
|
||||
val KEY_SYSTEM_NOTIFICATION_ID = "KEY_SYSTEM_NOTIFICATION_ID"
|
||||
const val KEY_MESSAGE_ID = "KEY_MESSAGE_ID"
|
||||
const val KEY_SINGLE_SELECTION = "KEY_SINGLE_SELECTION"
|
||||
const val KEY_MIME_TYPE_FILTER = "KEY_MIME_TYPE_FILTER"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue