-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
563f813
commit ed6d797
Showing
34 changed files
with
739 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
actions/src/main/kotlin/com/alfresco/content/actions/ActionMoveFilesFolders.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.alfresco.content.actions | ||
|
||
import android.content.Context | ||
import android.view.View | ||
import com.alfresco.content.data.BrowseRepository | ||
import com.alfresco.content.data.Entry | ||
import kotlin.coroutines.cancellation.CancellationException | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
|
||
/** | ||
* Mark as ActionMoveFilesFolders | ||
*/ | ||
data class ActionMoveFilesFolders( | ||
override var entry: Entry, | ||
override val icon: Int = R.drawable.ic_move, | ||
override val title: Int = R.string.action_move_title | ||
) : Action { | ||
|
||
override suspend fun execute(context: Context): Entry { | ||
|
||
val result = ActionMoveFragment.moveItem(context) | ||
if (!result.isNullOrEmpty()) { | ||
withContext(Dispatchers.IO) { | ||
BrowseRepository().moveNode(entry.id, result) | ||
} | ||
} else { | ||
throw CancellationException("User Cancellation") | ||
} | ||
return entry | ||
} | ||
|
||
override fun copy(_entry: Entry): Action = copy(entry = _entry) | ||
|
||
override fun showToast(view: View, anchorView: View?) = | ||
Action.showToast(view, anchorView, R.string.action_move_toast, entry.name) | ||
} |
48 changes: 48 additions & 0 deletions
48
actions/src/main/kotlin/com/alfresco/content/actions/ActionMoveFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.alfresco.content.actions | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import androidx.activity.result.ActivityResultLauncher | ||
import androidx.fragment.app.Fragment | ||
import com.alfresco.content.withFragment | ||
import kotlinx.coroutines.CancellableContinuation | ||
import kotlinx.coroutines.suspendCancellableCoroutine | ||
|
||
/** | ||
* Mark as ActionMoveFragment | ||
*/ | ||
class ActionMoveFragment : Fragment() { | ||
private lateinit var requestLauncher: ActivityResultLauncher<Unit> | ||
private var onResult: CancellableContinuation<String?>? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
requestLauncher = registerForActivityResult(MoveResultContract()) { | ||
onResult?.resume(it, null) | ||
} | ||
} | ||
|
||
private suspend fun moveItems(): String? = | ||
suspendCancellableCoroutine { continuation -> | ||
onResult = continuation | ||
requestLauncher.launch(Unit) | ||
} | ||
|
||
companion object { | ||
private val TAG = ActionMoveFragment::class.java.simpleName | ||
|
||
/** | ||
* Generating ActionMoveFragment | ||
*/ | ||
suspend fun moveItem( | ||
context: Context | ||
): String? = | ||
withFragment( | ||
context, | ||
TAG, | ||
{ it.moveItems() }, | ||
{ ActionMoveFragment() } | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
actions/src/main/kotlin/com/alfresco/content/actions/MoveResultContract.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.alfresco.content.actions | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.activity.result.contract.ActivityResultContract | ||
import androidx.annotation.CallSuper | ||
|
||
/** | ||
* Mark as MoveResultContract | ||
*/ | ||
class MoveResultContract : ActivityResultContract<Unit, String?>() { | ||
@CallSuper | ||
override fun createIntent(context: Context, input: Unit): Intent { | ||
return intent | ||
} | ||
|
||
override fun parseResult(resultCode: Int, intent: Intent?): String? { | ||
return if (intent == null || resultCode != Activity.RESULT_OK) null | ||
else intent.extras?.getString(OUTPUT_KEY) | ||
} | ||
|
||
companion object { | ||
const val OUTPUT_KEY = "targetParentId" | ||
lateinit var intent: Intent | ||
|
||
/** | ||
* adding intent for MoveActivity | ||
*/ | ||
fun addMoveIntent(moveIntent: Intent) { | ||
intent = moveIntent | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:pathData="M20,6h-8l-2,-2H4C2.9,4 2,4.9 2,6v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8C22,6.9 21.1,6 20,6zM20,18H4V6h5.17l1.41,1.41L11.17,8H20V18zM12.16,12H8v2h4.16l-1.59,1.59L11.99,17L16,13.01L11.99,9l-1.41,1.41L12.16,12z" | ||
android:fillColor="?attr/colorControlNormal"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
app/src/main/java/com/alfresco/content/app/activity/MoveActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.alfresco.content.app.activity | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.lifecycle.lifecycleScope | ||
import androidx.navigation.findNavController | ||
import com.airbnb.mvrx.MavericksView | ||
import com.airbnb.mvrx.withState | ||
import com.alfresco.auth.activity.LoginViewModel | ||
import com.alfresco.content.actions.Action | ||
import com.alfresco.content.activityViewModel | ||
import com.alfresco.content.app.R | ||
import com.alfresco.content.app.widget.ActionBarController | ||
import com.alfresco.content.session.SessionManager | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
import java.lang.ref.WeakReference | ||
|
||
/** | ||
* Marked as MoveActivity class | ||
*/ | ||
class MoveActivity : AppCompatActivity(), MavericksView { | ||
|
||
private val viewModel: MainActivityViewModel by activityViewModel() | ||
private val navController by lazy { findNavController(R.id.nav_host_fragment) } | ||
private val bottomView by lazy { findViewById<View>(R.id.bottom_view) } | ||
private lateinit var actionBarController: ActionBarController | ||
private var signedOutDialog = WeakReference<AlertDialog>(null) | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_move) | ||
|
||
configure() | ||
} | ||
|
||
private fun configure() { | ||
val graph = navController.navInflater.inflate(R.navigation.nav_move_paths) | ||
graph.startDestination = R.id.nav_move | ||
val bundle = Bundle().apply { | ||
} | ||
navController.setGraph(graph, bundle) | ||
setupActionToasts() | ||
actionBarController = ActionBarController(findViewById(R.id.toolbar)) | ||
actionBarController.setupActionBar(this, navController) | ||
} | ||
|
||
override fun onSupportNavigateUp(): Boolean { | ||
return if (navController.currentDestination?.id == R.id.nav_browse_move) { | ||
finish() | ||
false | ||
} else navController.navigateUp() | ||
} | ||
|
||
override fun invalidate() = withState(viewModel) { state -> | ||
if (state.requiresReLogin) { | ||
if (state.isOnline) { | ||
showSignedOutPrompt() | ||
} | ||
} else { | ||
// Only when logged in otherwise triggers re-login prompts | ||
actionBarController.setProfileIcon(viewModel.profileIcon) | ||
} | ||
|
||
actionBarController.setOnline(state.isOnline) | ||
} | ||
|
||
private fun showSignedOutPrompt() { | ||
val oldDialog = signedOutDialog.get() | ||
if (oldDialog != null && oldDialog.isShowing) return | ||
val dialog = MaterialAlertDialogBuilder(this) | ||
.setTitle(resources.getString(R.string.auth_signed_out_title)) | ||
.setMessage(resources.getString(R.string.auth_signed_out_subtitle)) | ||
.setNegativeButton(resources.getString(R.string.sign_out_confirmation_negative), null) | ||
.setPositiveButton(resources.getString(R.string.auth_basic_sign_in_button)) { _, _ -> | ||
navigateToReLogin() | ||
} | ||
.show() | ||
signedOutDialog = WeakReference(dialog) | ||
} | ||
|
||
private fun navigateToReLogin() { | ||
val i = Intent(this, LoginActivity::class.java) | ||
val acc = SessionManager.requireSession.account | ||
i.putExtra(LoginViewModel.EXTRA_IS_EXTENSION, false) | ||
i.putExtra(LoginViewModel.EXTRA_ENDPOINT, acc.serverUrl) | ||
i.putExtra(LoginViewModel.EXTRA_AUTH_TYPE, acc.authType) | ||
i.putExtra(LoginViewModel.EXTRA_AUTH_CONFIG, acc.authConfig) | ||
i.putExtra(LoginViewModel.EXTRA_AUTH_STATE, acc.authState) | ||
startActivity(i) | ||
} | ||
|
||
private fun setupActionToasts() = Action.showActionToasts( | ||
lifecycleScope, | ||
findViewById(android.R.id.content), | ||
bottomView | ||
) | ||
|
||
override fun onBackPressed() { | ||
super.onBackPressed() | ||
finish() | ||
} | ||
} |
Oops, something went wrong.