Skip to content

Commit

Permalink
MOBILEAPPS-2120 (#296)
Browse files Browse the repository at this point in the history
* fixed move crash

* fixed move crash
  • Loading branch information
aman-alfresco authored Oct 17, 2023
1 parent 9d03819 commit f03d838
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.content.Context
import android.os.Bundle
import androidx.activity.result.ActivityResultLauncher
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.alfresco.content.actions.MoveResultContract.Companion.ENTRY_OBJ_KEY
import com.alfresco.content.data.Entry
import com.alfresco.content.withNewFragment
Expand All @@ -15,21 +17,23 @@ import kotlinx.coroutines.suspendCancellableCoroutine
*/
class ActionMoveFragment : Fragment() {
private lateinit var requestLauncher: ActivityResultLauncher<Unit>
private var onResult: CancellableContinuation<String?>? = null
private lateinit var viewModel: ActionMoveViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewModel = ViewModelProvider(this)[ActionMoveViewModel::class.java]

arguments?.let { bundle ->
val entryObj = bundle.getParcelable(ENTRY_OBJ_KEY) as Entry?
requestLauncher = registerForActivityResult(MoveResultContract(entryObj)) {
onResult?.resume(it, null)
viewModel.onResult?.resume(it, null)
}
}
}

private suspend fun moveItems(): String? =
suspendCancellableCoroutine { continuation ->
onResult = continuation
viewModel.onResult = continuation
requestLauncher.launch(Unit)
}

Expand Down Expand Up @@ -57,3 +61,10 @@ class ActionMoveFragment : Fragment() {
}
}
}

/**
* ViewModel to retain the continuation
*/
class ActionMoveViewModel : ViewModel() {
var onResult: CancellableContinuation<String?>? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import com.alfresco.content.data.Entry
class MoveResultContract(private val entryObj: Entry?) : ActivityResultContract<Unit, String?>() {
@CallSuper
override fun createIntent(context: Context, input: Unit): Intent {
val intent = Intent(
context,
Class.forName("com.alfresco.content.app.activity.MoveActivity"),
)
intent.putExtra(ENTRY_OBJ_KEY, entryObj)
return intent
}
Expand All @@ -29,13 +33,5 @@ class MoveResultContract(private val entryObj: Entry?) : ActivityResultContract<
const val OUTPUT_KEY = "targetParentId"
const val ENTRY_OBJ_KEY = "entryObj"
const val MOVE_ID_KEY = "moveId"
lateinit var intent: Intent

/**
* adding intent for MoveActivity
*/
fun addMoveIntent(moveIntent: Intent) {
intent = moveIntent
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.alfresco.auth.activity.LoginViewModel
import com.alfresco.auth.ui.observe
import com.alfresco.content.actions.Action
import com.alfresco.content.actions.ContextualActionsSheet
import com.alfresco.content.actions.MoveResultContract
import com.alfresco.content.activityViewModel
import com.alfresco.content.app.R
import com.alfresco.content.app.widget.ActionBarController
Expand Down Expand Up @@ -195,7 +194,7 @@ class MainActivity : AppCompatActivity(), MavericksView, ActionMode.Callback {
bottomNav.setupWithNavController(navController)

setupActionToasts()
MoveResultContract.addMoveIntent(Intent(this, MoveActivity::class.java))
// MoveResultContract.addMoveIntent(Intent(this, MoveActivity::class.java))
setupDownloadNotifications()

bottomNav.setOnItemSelectedListener { item ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.alfresco.content.data.rooted

import android.content.Context
import com.scottyab.rootbeer.RootBeer
import com.scottyab.rootbeer.util.Utils

class CheckForRootWorker(context: Context) {

Expand All @@ -16,12 +15,12 @@ class CheckForRootWorker(context: Context) {
RootItemResult("Root Cloaking Apps", rootBeer.detectRootCloakingApps()),
RootItemResult("TestKeys", rootBeer.detectTestKeys()),
RootItemResult("BusyBoxBinary", rootBeer.checkForBusyBoxBinary()),
RootItemResult("SU Binary", rootBeer.checkForSuBinary()),
// RootItemResult("SU Binary", rootBeer.checkForSuBinary()),
RootItemResult("2nd SU Binary check", rootBeer.checkSuExists()),
RootItemResult("For RW Paths", rootBeer.checkForRWPaths()),
RootItemResult("Dangerous Props", rootBeer.checkForDangerousProps()),
// RootItemResult("Dangerous Props", rootBeer.checkForDangerousProps()),
RootItemResult("Root via native check", rootBeer.checkForRootNative()),
RootItemResult("SE linux Flag Is Enabled", !Utils.isSelinuxFlagInEnabled()),
// RootItemResult("SE linux Flag Is Enabled", !Utils.isSelinuxFlagInEnabled()),
RootItemResult("Magisk specific checks", rootBeer.checkForMagiskBinary()),
)
}
18 changes: 14 additions & 4 deletions move/src/main/java/com/alfresco/content/move/MoveFragment.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.alfresco.content.move

import android.content.Context
import android.os.Bundle
import android.os.Parcelable
import androidx.fragment.app.Fragment
Expand Down Expand Up @@ -45,17 +46,26 @@ class MoveFragment : Fragment(), MavericksView {
@OptIn(InternalMavericksApi::class)
val viewModel: MoveViewModel by fragmentViewModelWithArgs { args }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

args = MoveArgs.with(requireArguments())
override fun onAttach(context: Context) {
super.onAttach(context)
println("MoveFragment.onAttach")
}

override fun onStart() {
super.onStart()
println("MoveFragment.onStart")
val nodeId = viewModel.getMyFilesNodeId()
args.entryObj?.let {
findNavController().navigateToMoveParent(nodeId, it.id, getString(R.string.browse_menu_personal))
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
println("MoveFragment.onCreate")
args = MoveArgs.with(requireArguments())
}

override fun invalidate() = withState(viewModel) { state ->
}
}

0 comments on commit f03d838

Please sign in to comment.