Skip to content

Commit

Permalink
orgzly#38 WebDAV sync support
Browse files Browse the repository at this point in the history
DataBindingUtil is used
Small formatting fixes
  • Loading branch information
bemyak committed Sep 1, 2019
1 parent bd1133d commit 6a87dac
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 56 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/orgzly/android/repos/WebdavRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ class WebdavRepo(private val uri: Uri, username: String?, password: String?) : S
}
}
}
}
}
20 changes: 11 additions & 9 deletions app/src/main/java/com/orgzly/android/ui/repo/WebdavRepoActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ import android.os.Bundle
import android.text.TextUtils
import android.view.Menu
import android.view.MenuItem
import androidx.databinding.DataBindingUtil
import com.orgzly.R
import com.orgzly.android.prefs.RepoPreferences
import com.orgzly.android.repos.RepoFactory
import com.orgzly.android.repos.WebdavRepo.Companion.PASSWORD_PREF_KEY
import com.orgzly.android.repos.WebdavRepo.Companion.USERNAME_PREF_KEY
import com.orgzly.android.ui.CommonActivity
import kotlinx.android.synthetic.main.activity_repo_webdav.*
import com.orgzly.databinding.ActivityRepoWebdavBinding
import javax.inject.Inject

class WebdavRepoActivity : CommonActivity() {
private lateinit var binding: ActivityRepoWebdavBinding

@Inject
lateinit var repoFactory: RepoFactory
Expand All @@ -28,19 +30,19 @@ class WebdavRepoActivity : CommonActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_repo_webdav)
binding = DataBindingUtil.setContentView(this, R.layout.activity_repo_webdav)

setupActionBar(R.string.webdav)

repoId = intent.getLongExtra(ARG_REPO_ID, 0)

if (repoId != 0L) {
val prefs = RepoPreferences.fromId(this, repoId, dataRepository)
activity_repo_webdav_url.setText(prefs.repoUri.toString())
binding.activityRepoWebdavUrl.setText(prefs.repoUri.toString())
val username = prefs.getStringValue(USERNAME_PREF_KEY, "")
activity_repo_webdav_username.setText(username)
binding.activityRepoWebdavUsername.setText(username)
val password = prefs.getStringValue(PASSWORD_PREF_KEY, "")
activity_repo_webdav_password.setText(password)
binding.activityRepoWebdavPassword.setText(password)
}
}

Expand Down Expand Up @@ -70,17 +72,17 @@ class WebdavRepoActivity : CommonActivity() {
}

private fun saveAndFinish() {
val uriString = activity_repo_webdav_url.text.toString().trim { it <= ' ' }.let {
val uriString = binding.activityRepoWebdavUrl.text.toString().trim { it <= ' ' }.let {
if (it.startsWith("http")) {
it.replaceFirst("http", "webdav")
}
it
}
val username = activity_repo_webdav_username.text.toString().trim { it <= ' ' }
val password = activity_repo_webdav_password.text.toString().trim { it <= ' ' }
val username = binding.activityRepoWebdavUsername.text.toString().trim { it <= ' ' }
val password = binding.activityRepoWebdavPassword.text.toString().trim { it <= ' ' }

val urlError = getWebdavUrlError(uriString)
activity_repo_webdav_url_layout.error = urlError
binding.activityRepoWebdavUrlLayout.error = urlError
if (urlError != null) {
return
}
Expand Down
92 changes: 47 additions & 45 deletions app/src/main/res/layout/activity_repo_webdav.xml
Original file line number Diff line number Diff line change
@@ -1,74 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>

<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
xmlns:tools="http://schemas.android.com/tools">

<ScrollView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/screen_edge"
android:orientation="vertical"
tools:context=".android.ui.main.MainActivity">
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/activity_repo_webdav_url_layout"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true">
android:orientation="vertical"
android:padding="@dimen/screen_edge"
tools:context=".android.ui.main.MainActivity">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/activity_repo_webdav_url"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/activity_repo_webdav_url_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="@string/webdav_url_hint"/>
app:errorEnabled="true">

</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/activity_repo_webdav_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/webdav_url_hint"
android:inputType="text" />

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/activity_repo_webdav_username_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true">
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/activity_repo_webdav_username"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/activity_repo_webdav_username_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/webdav_auth_username_hint"
android:inputType="text" />
app:errorEnabled="true">

</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/activity_repo_webdav_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/webdav_auth_username_hint"
android:inputType="text" />

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/activity_repo_webdav_password_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true">
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/activity_repo_webdav_password"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/activity_repo_webdav_password_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/webdav_auth_password_hint"
android:inputType="textPassword" />
app:errorEnabled="true">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/activity_repo_webdav_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/webdav_auth_password_hint"
android:inputType="textPassword" />

</com.google.android.material.textfield.TextInputLayout>
</com.google.android.material.textfield.TextInputLayout>

</LinearLayout>
</LinearLayout>

</ScrollView>
</ScrollView>

<include layout="@layout/app_bar"/>
<include layout="@layout/app_bar" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ glide_version = 4.9.0

jgit_version = 4.4.1.201607150455-r

sardine_version = 0.4
sardine_version = 0.4

0 comments on commit 6a87dac

Please sign in to comment.