Skip to content

Commit

Permalink
feat: support onedrive
Browse files Browse the repository at this point in the history
  • Loading branch information
hpp2334 committed Nov 24, 2024
1 parent 79e12d9 commit 3efbc87
Show file tree
Hide file tree
Showing 37 changed files with 798 additions and 183 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ app.*.map.json


rust-libs/ease-client-backend/src/controllers/generated.rs
rust-libs/ease-client-shared/src/backends/generated.rs
rust-libs/ease-client-shared/src/backends/generated.rs
rust-libs/ease-remote-storage/src/generated.rs
9 changes: 9 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="OAuth2 Redirect">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:scheme="easem"
android:host="oauth2redirect" />
</intent-filter>
</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import com.kutedev.easemusicplayer.widgets.playlists.CreatePlaylistsDialog
import com.kutedev.easemusicplayer.widgets.playlists.EditPlaylistsDialog
import uniffi.ease_client.MainAction
import uniffi.ease_client.RoutesKey
import uniffi.ease_client.StorageUpsertAction
import uniffi.ease_client.ViewAction

inline fun <reified T> MainActivity.registerViewModel(bridge: UIBridge)
Expand All @@ -79,7 +80,7 @@ class MainActivity : ComponentActivity() {
}

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

LocalBroadcastManager.getInstance(this).registerReceiver(uiReceiver, IntentFilter(
Expand Down Expand Up @@ -120,6 +121,17 @@ class MainActivity : ComponentActivity() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(uiReceiver)
}

override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
intent?.data?.let { uri ->
println(uri)
val code = uri.getQueryParameter("code")
if (code != null) {
uiBridge?.dispatchAction(ViewAction.StorageUpsert(StorageUpsertAction.OAuth(code)))
}
}
}

@Composable
fun Root() {
val evm: EaseViewModel by viewModels()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,10 @@ fun SimpleFormText(
}

@Composable
fun FormText(
fun FormWidget(
label: String,
value: String,
onChange: (value: String) -> Unit,
error: Int? = null,
isPassword: Boolean = false
block: @Composable () -> Unit,
) {
var passwordVisibleState = remember { mutableStateOf(false) }
val passwordVisible = passwordVisibleState.value

Column(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -67,6 +61,24 @@ fun FormText(
fontSize = 10.sp,
letterSpacing = 1.sp,
)
block()
}
}

@Composable
fun FormText(
label: String,
value: String,
onChange: (value: String) -> Unit,
error: Int? = null,
isPassword: Boolean = false
) {
var passwordVisibleState = remember { mutableStateOf(false) }
val passwordVisible = passwordVisibleState.value

FormWidget(
label = label
) {
if (!isPassword) {
TextField(
modifier = Modifier
Expand Down Expand Up @@ -109,19 +121,15 @@ fun FormText(
}
}


@Composable
fun FormSwitch(
label: String,
value: Boolean,
onChange: (value: Boolean) -> Unit,
) {
Column {
Text(
text = label,
fontSize = 10.sp,
letterSpacing = 1.sp,
)
FormWidget(
label = label
) {
Switch(
checked = value,
onCheckedChange = onChange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.ui.unit.sp

enum class EaseTextButtonType {
Primary,
PrimaryVariant,
Error,
Default,
}
Expand Down Expand Up @@ -47,6 +48,12 @@ fun EaseTextButton(
contentColor = MaterialTheme.colorScheme.primary
)
}
EaseTextButtonType.PrimaryVariant -> {
ButtonDefaults.textButtonColors().copy(
contentColor = MaterialTheme.colorScheme.surface,
containerColor = MaterialTheme.colorScheme.primary
)
}
EaseTextButtonType.Error -> {
ButtonDefaults.textButtonColors().copy(
contentColor = MaterialTheme.colorScheme.error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import android.Manifest.permission.READ_EXTERNAL_STORAGE
import android.Manifest.permission.READ_MEDIA_AUDIO
import android.annotation.SuppressLint
import android.content.ComponentName
import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import androidx.activity.result.ActivityResultLauncher
import androidx.compose.ui.graphics.ImageBitmap
Expand Down Expand Up @@ -118,6 +121,12 @@ private class PermissionService : IPermissionServiceForeign {
this.requestPermissionLauncher = requestPermissionLauncher
}

override fun openUrl(url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
intent.flags = FLAG_ACTIVITY_NEW_TASK
context?.startActivity(intent)
}

override fun haveStoragePermission(): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context?.checkSelfPermission(READ_MEDIA_AUDIO) == PackageManager.PERMISSION_GRANTED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ val DefaultEditStorageState =
),
validated =
EditStorageFormValidated(
alias = FormFieldStatus.OK,
address = FormFieldStatus.OK,
username = FormFieldStatus.OK,
password = FormFieldStatus.OK
password = FormFieldStatus.OK,
),
test = StorageConnectionTestResult.NONE,
musicCount = 0u,
Expand Down
Loading

0 comments on commit 3efbc87

Please sign in to comment.