summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt43
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt9
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitOperation.kt3
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt35
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/config/ConnectionMode.kt4
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/config/Protocol.kt3
-rw-r--r--app/src/main/res/drawable/ic_refresh_white_24dp.xml9
-rw-r--r--app/src/main/res/layout/activity_git_clone.xml43
-rw-r--r--app/src/main/res/menu/main_menu_git.xml17
-rw-r--r--app/src/main/res/menu/main_menu_no_auth.xml20
-rw-r--r--app/src/main/res/menu/main_menu_non_git.xml9
-rw-r--r--app/src/main/res/values/strings.xml5
12 files changed, 114 insertions, 86 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt
index ecf1a887..33f3b32f 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt
@@ -6,6 +6,7 @@ package com.zeapo.pwdstore
import android.content.Context
import android.content.Intent
+import android.content.SharedPreferences
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
@@ -19,12 +20,14 @@ import androidx.appcompat.view.ActionMode
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.observe
+import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.snackbar.Snackbar
import com.zeapo.pwdstore.databinding.PasswordRecyclerViewBinding
import com.zeapo.pwdstore.git.BaseGitActivity
import com.zeapo.pwdstore.git.GitOperationActivity
import com.zeapo.pwdstore.git.GitServerConfigActivity
+import com.zeapo.pwdstore.git.config.ConnectionMode
import com.zeapo.pwdstore.ui.OnOffItemAnimator
import com.zeapo.pwdstore.ui.adapters.PasswordItemRecyclerAdapter
import com.zeapo.pwdstore.ui.dialogs.ItemCreationBottomSheet
@@ -37,6 +40,7 @@ import me.zhanghai.android.fastscroll.FastScrollerBuilder
class PasswordFragment : Fragment() {
private lateinit var recyclerAdapter: PasswordItemRecyclerAdapter
private lateinit var listener: OnFragmentInteractionListener
+ private lateinit var settings: SharedPreferences
private var recyclerViewStateToRestore: Parcelable? = null
private var actionMode: ActionMode? = null
@@ -53,6 +57,7 @@ class PasswordFragment : Fragment() {
savedInstanceState: Bundle?
): View? {
_binding = PasswordRecyclerViewBinding.inflate(inflater, container, false)
+ settings = PreferenceManager.getDefaultSharedPreferences(requireContext())
initializePasswordList()
binding.fab.setOnClickListener {
ItemCreationBottomSheet().apply {
@@ -63,20 +68,30 @@ class PasswordFragment : Fragment() {
}
private fun initializePasswordList() {
- binding.swipeRefresher.setOnRefreshListener {
- if (!PasswordRepository.isGitRepo()) {
- Snackbar.make(binding.root, getString(R.string.clone_git_repo), Snackbar.LENGTH_INDEFINITE)
- .setAction(R.string.clone_button) {
- val intent = Intent(context, GitServerConfigActivity::class.java)
- intent.putExtra(BaseGitActivity.REQUEST_ARG_OP, BaseGitActivity.REQUEST_CLONE)
- startActivityForResult(intent, BaseGitActivity.REQUEST_CLONE)
- }
- .show()
- binding.swipeRefresher.isRefreshing = false
- } else {
- val intent = Intent(context, GitOperationActivity::class.java)
- intent.putExtra(BaseGitActivity.REQUEST_ARG_OP, BaseGitActivity.REQUEST_SYNC)
- startActivityForResult(intent, BaseGitActivity.REQUEST_SYNC)
+ val gitDir = File(PasswordRepository.getRepositoryDirectory(requireContext()), ".git")
+ val hasGitDir = gitDir.exists() && gitDir.isDirectory && (gitDir.listFiles()?.isNotEmpty() == true)
+ if (hasGitDir) {
+ binding.swipeRefresher.setOnRefreshListener {
+ if (!PasswordRepository.isGitRepo()) {
+ Snackbar.make(binding.root, getString(R.string.clone_git_repo), Snackbar.LENGTH_INDEFINITE)
+ .setAction(R.string.clone_button) {
+ val intent = Intent(context, GitServerConfigActivity::class.java)
+ intent.putExtra(BaseGitActivity.REQUEST_ARG_OP, BaseGitActivity.REQUEST_CLONE)
+ startActivityForResult(intent, BaseGitActivity.REQUEST_CLONE)
+ }
+ .show()
+ binding.swipeRefresher.isRefreshing = false
+ } else {
+ // When authentication is set to ConnectionMode.None then the only git operation we
+ // can run is a pull, so automatically fallback to that.
+ val operationId = when (ConnectionMode.fromString(settings.getString("git_remote_auth", null))) {
+ ConnectionMode.None -> BaseGitActivity.REQUEST_PULL
+ else -> BaseGitActivity.REQUEST_SYNC
+ }
+ val intent = Intent(context, GitOperationActivity::class.java)
+ intent.putExtra(BaseGitActivity.REQUEST_ARG_OP, operationId)
+ startActivityForResult(intent, operationId)
+ }
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt
index cba24202..b47e2b8e 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt
@@ -53,6 +53,7 @@ import com.zeapo.pwdstore.git.GitAsyncTask
import com.zeapo.pwdstore.git.GitOperation
import com.zeapo.pwdstore.git.GitOperationActivity
import com.zeapo.pwdstore.git.GitServerConfigActivity
+import com.zeapo.pwdstore.git.config.ConnectionMode
import com.zeapo.pwdstore.ui.dialogs.FolderCreationDialogFragment
import com.zeapo.pwdstore.utils.PasswordItem
import com.zeapo.pwdstore.utils.PasswordRepository
@@ -201,7 +202,13 @@ class PasswordStore : AppCompatActivity() {
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
- menuInflater.inflate(if (PasswordRepository.isGitRepo()) R.menu.main_menu_git else R.menu.main_menu_non_git, menu)
+ val menuRes = when {
+ ConnectionMode.fromString(settings.getString("git_remote_auth", null))
+ == ConnectionMode.None -> R.menu.main_menu_no_auth
+ PasswordRepository.isGitRepo() -> R.menu.main_menu_git
+ else -> R.menu.main_menu_non_git
+ }
+ menuInflater.inflate(menuRes, menu)
return super.onCreateOptionsMenu(menu)
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.kt
index 817d9dca..82f3d7f6 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.kt
@@ -247,6 +247,9 @@ abstract class GitOperation(fileDir: File, internal val callingActivity: Activit
dialog.show()
}
}
+ ConnectionMode.None -> {
+ execute()
+ }
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt
index a10f3460..14f9bb62 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt
@@ -24,7 +24,7 @@ import java.io.IOException
*/
class GitServerConfigActivity : BaseGitActivity() {
- lateinit var binding: ActivityGitCloneBinding
+ private lateinit var binding: ActivityGitCloneBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -36,11 +36,10 @@ class GitServerConfigActivity : BaseGitActivity() {
setContentView(binding.root)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
- val protocolIdToCheck = when (protocol) {
+ binding.cloneProtocolGroup.check(when (protocol) {
Protocol.Ssh -> R.id.clone_protocol_ssh
Protocol.Https -> R.id.clone_protocol_https
- }
- binding.cloneProtocolGroup.check(protocolIdToCheck)
+ })
binding.cloneProtocolGroup.addOnButtonCheckedListener { _, checkedId, checked ->
if (checked) {
when (checkedId) {
@@ -51,19 +50,18 @@ class GitServerConfigActivity : BaseGitActivity() {
}
}
- val connectionModeIdToCheck = when (connectionMode) {
+ binding.connectionModeGroup.check(when (connectionMode) {
ConnectionMode.SshKey -> R.id.connection_mode_ssh_key
ConnectionMode.Password -> R.id.connection_mode_password
ConnectionMode.OpenKeychain -> R.id.connection_mode_open_keychain
- }
- binding.connectionModeGroup.check(connectionModeIdToCheck)
- binding.connectionModeGroup.addOnButtonCheckedListener { _, checkedId, checked ->
- if (checked) {
- when (checkedId) {
- R.id.connection_mode_ssh_key -> connectionMode = ConnectionMode.SshKey
- R.id.connection_mode_open_keychain -> connectionMode = ConnectionMode.OpenKeychain
- R.id.connection_mode_password -> connectionMode = ConnectionMode.Password
- }
+ ConnectionMode.None -> R.id.connection_mode_none
+ })
+ binding.connectionModeGroup.setOnCheckedChangeListener { group, _ ->
+ when (group.checkedRadioButtonId) {
+ R.id.connection_mode_ssh_key -> connectionMode = ConnectionMode.SshKey
+ R.id.connection_mode_open_keychain -> connectionMode = ConnectionMode.OpenKeychain
+ R.id.connection_mode_password -> connectionMode = ConnectionMode.Password
+ R.id.connection_mode_none -> connectionMode = ConnectionMode.None
}
}
updateConnectionModeToggleGroup()
@@ -121,15 +119,20 @@ class GitServerConfigActivity : BaseGitActivity() {
private fun updateConnectionModeToggleGroup() {
if (protocol == Protocol.Ssh) {
+ if (binding.connectionModeNone.isChecked)
+ binding.connectionModeGroup.check(R.id.connection_mode_ssh_key)
binding.connectionModeSshKey.isEnabled = true
binding.connectionModeOpenKeychain.isEnabled = true
+ binding.connectionModeNone.isEnabled = false
} else {
- // Reset connection mode to the only one possible via HTTPS: password.
+ // Reset connection mode to password if the current value is not valid for HTTPS
// Important note: This has to happen before disabling the other toggle buttons or they
// won't uncheck.
- binding.connectionModeGroup.check(R.id.connection_mode_password)
+ if (connectionMode !in listOf(ConnectionMode.None, ConnectionMode.Password))
+ binding.connectionModeGroup.check(R.id.connection_mode_password)
binding.connectionModeSshKey.isEnabled = false
binding.connectionModeOpenKeychain.isEnabled = false
+ binding.connectionModeNone.isEnabled = true
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/config/ConnectionMode.kt b/app/src/main/java/com/zeapo/pwdstore/git/config/ConnectionMode.kt
index 9316e89f..8bc3fb18 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/config/ConnectionMode.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/config/ConnectionMode.kt
@@ -7,7 +7,9 @@ package com.zeapo.pwdstore.git.config
enum class ConnectionMode(val pref: String) {
SshKey("ssh-key"),
Password("username/password"),
- OpenKeychain("OpenKeychain");
+ OpenKeychain("OpenKeychain"),
+ None("None"),
+ ;
companion object {
private val map = values().associateBy(ConnectionMode::pref)
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/config/Protocol.kt b/app/src/main/java/com/zeapo/pwdstore/git/config/Protocol.kt
index 1909fe85..eca23800 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/config/Protocol.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/config/Protocol.kt
@@ -6,7 +6,8 @@ package com.zeapo.pwdstore.git.config
enum class Protocol(val pref: String) {
Ssh("ssh://"),
- Https("https://");
+ Https("https://"),
+ ;
companion object {
private val map = values().associateBy(Protocol::pref)
diff --git a/app/src/main/res/drawable/ic_refresh_white_24dp.xml b/app/src/main/res/drawable/ic_refresh_white_24dp.xml
deleted file mode 100644
index 7d391467..00000000
--- a/app/src/main/res/drawable/ic_refresh_white_24dp.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:viewportWidth="24"
- android:viewportHeight="24">
- <path
- android:fillColor="#FFFFFFFF"
- android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
-</vector>
diff --git a/app/src/main/res/layout/activity_git_clone.xml b/app/src/main/res/layout/activity_git_clone.xml
index de9a240e..e5d41059 100644
--- a/app/src/main/res/layout/activity_git_clone.xml
+++ b/app/src/main/res/layout/activity_git_clone.xml
@@ -156,50 +156,39 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/label_server_path" />
- <com.google.android.material.button.MaterialButtonToggleGroup
+ <RadioGroup
android:id="@+id/connection_mode_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_margin="8dp"
+ android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@id/label_connection_mode"
- app:layout_constraintStart_toStartOf="parent"
- app:selectionRequired="true"
- app:singleSelection="true" >
+ app:layout_constraintStart_toStartOf="parent">
- <com.google.android.material.button.MaterialButton
- style="?attr/materialButtonOutlinedStyle"
+ <RadioButton
android:id="@+id/connection_mode_ssh_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/connection_mode_ssh_key"
- android:textColor="?android:attr/textColorPrimary"
- app:rippleColor="@color/ripple_color"
- app:strokeColor="?attr/colorSecondary"
- app:backgroundTint="@color/toggle_button_selector" />
+ android:text="@string/connection_mode_ssh_key" />
- <com.google.android.material.button.MaterialButton
- style="?attr/materialButtonOutlinedStyle"
+ <RadioButton
android:id="@+id/connection_mode_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/connection_mode_basic_authentication"
- android:textColor="?android:attr/textColorPrimary"
- app:rippleColor="@color/ripple_color"
- app:strokeColor="?attr/colorSecondary"
- app:backgroundTint="@color/toggle_button_selector" />
+ android:text="@string/connection_mode_basic_authentication" />
- <com.google.android.material.button.MaterialButton
- style="?attr/materialButtonOutlinedStyle"
+ <RadioButton
android:id="@+id/connection_mode_open_keychain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/connection_mode_openkeychain"
- android:textColor="?android:attr/textColorPrimary"
- app:rippleColor="@color/ripple_color"
- app:strokeColor="?attr/colorSecondary"
- app:backgroundTint="@color/toggle_button_selector" />
+ android:text="@string/connection_mode_openkeychain" />
- </com.google.android.material.button.MaterialButtonToggleGroup>
+ <RadioButton
+ android:id="@+id/connection_mode_none"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/connection_mode_none" />
+
+ </RadioGroup>
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button"
diff --git a/app/src/main/res/menu/main_menu_git.xml b/app/src/main/res/menu/main_menu_git.xml
index 40c99550..90989495 100644
--- a/app/src/main/res/menu/main_menu_git.xml
+++ b/app/src/main/res/menu/main_menu_git.xml
@@ -1,7 +1,6 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- tools:context=".pwdstore" >
+ xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_search"
android:title="@string/action_search"
@@ -10,18 +9,18 @@
app:actionViewClass="androidx.appcompat.widget.SearchView" />
<item android:id="@+id/git_sync"
- android:title="@string/git_sync"/>
+ android:title="@string/git_sync" />
+
<item android:id="@+id/git_pull"
- android:title="@string/git_pull"/>
+ android:title="@string/git_pull" />
+
<item android:id="@+id/git_push"
- android:title="@string/git_push"/>
+ android:title="@string/git_push" />
<item android:id="@+id/refresh"
- android:title="@string/refresh_list"
- android:icon="@drawable/ic_refresh_white_24dp"
- app:showAsAction="never"/>
+ android:title="@string/refresh_list" />
<item android:id="@+id/user_pref"
android:title="@string/action_settings"
- android:orderInCategory="100"/>
+ android:orderInCategory="100" />
</menu>
diff --git a/app/src/main/res/menu/main_menu_no_auth.xml b/app/src/main/res/menu/main_menu_no_auth.xml
new file mode 100644
index 00000000..9036c261
--- /dev/null
+++ b/app/src/main/res/menu/main_menu_no_auth.xml
@@ -0,0 +1,20 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+
+ <item android:id="@+id/action_search"
+ android:title="@string/action_search"
+ android:icon="@drawable/ic_search_white_24dp"
+ app:showAsAction="always|collapseActionView"
+ app:actionViewClass="androidx.appcompat.widget.SearchView" />
+
+ <item android:id="@+id/git_pull"
+ android:title="@string/git_pull"/>
+
+ <item android:id="@+id/refresh"
+ android:title="@string/refresh_list" />
+
+ <item android:id="@+id/user_pref"
+ android:title="@string/action_settings"
+ android:orderInCategory="100" />
+</menu>
diff --git a/app/src/main/res/menu/main_menu_non_git.xml b/app/src/main/res/menu/main_menu_non_git.xml
index dc7d20cc..7745b544 100644
--- a/app/src/main/res/menu/main_menu_non_git.xml
+++ b/app/src/main/res/menu/main_menu_non_git.xml
@@ -1,7 +1,6 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- tools:context=".pwdstore" >
+ xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_search"
android:title="@string/action_search"
@@ -10,11 +9,9 @@
app:actionViewClass="androidx.appcompat.widget.SearchView" />
<item android:id="@+id/refresh"
- android:title="@string/refresh_list"
- android:icon="@drawable/ic_refresh_white_24dp"
- app:showAsAction="never"/>
+ android:title="@string/refresh_list" />
<item android:id="@+id/user_pref"
android:title="@string/action_settings"
- android:orderInCategory="100"/>
+ android:orderInCategory="100" />
</menu>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 5d77ad6a..db8491e8 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -354,9 +354,10 @@
<string name="theme_follow_system">System default</string>
<string name="clone_protocol_ssh" translatable="false">SSH</string>
<string name="clone_protocol_https" translatable="false">HTTPS</string>
- <string name="connection_mode_ssh_key" translatable="false">SSH key</string>
- <string name="connection_mode_basic_authentication" translatable="false">Password</string>
+ <string name="connection_mode_ssh_key">SSH key</string>
+ <string name="connection_mode_basic_authentication">Password</string>
<string name="connection_mode_openkeychain" translatable="false">OpenKeychain</string>
+ <string name="connection_mode_none">None</string>
<string name="git_server_config_save_success">Successfully saved configuration</string>
<string name="git_server_config_save_failure">Configuration error: please verify your settings and try again</string>
<string name="git_operation_unable_to_open_ssh_key_title">Unable to open the ssh-key</string>