Cleanup GitActivity

- Rename to GitOperationActivity.
- Ensure identityBuilder is always closed regardless of what fragment uses it.
- Remove hardcoded "Operation" strings and replace with REQUEST_ARG_OP.
- Apply a transparent theme to GitOperationActivity make the UI less jarring.

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-04-12 02:44:15 +05:30
parent 0395189ee6
commit d064674765
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
9 changed files with 44 additions and 35 deletions

View file

@ -39,7 +39,8 @@
</intent-filter>
</activity>
<activity android:name=".git.GitActivity" />
<activity android:name=".git.GitOperationActivity"
android:theme="@style/NoBackgroundTheme" />
<activity android:name=".git.GitServerConfigActivity"
android:windowSoftInputMode="adjustResize"

View file

@ -24,7 +24,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.snackbar.Snackbar
import com.zeapo.pwdstore.databinding.PasswordRecyclerViewBinding
import com.zeapo.pwdstore.git.BaseGitActivity
import com.zeapo.pwdstore.git.GitActivity
import com.zeapo.pwdstore.git.GitOperationActivity
import com.zeapo.pwdstore.ui.OnOffItemAnimator
import com.zeapo.pwdstore.ui.adapters.PasswordItemRecyclerAdapter
import com.zeapo.pwdstore.utils.PasswordItem
@ -78,8 +78,8 @@ class PasswordFragment : Fragment() {
.show()
swipeRefresher.isRefreshing = false
} else {
val intent = Intent(context, GitActivity::class.java)
intent.putExtra("Operation", BaseGitActivity.REQUEST_SYNC)
val intent = Intent(context, GitOperationActivity::class.java)
intent.putExtra(BaseGitActivity.REQUEST_ARG_OP, BaseGitActivity.REQUEST_SYNC)
startActivityForResult(intent, BaseGitActivity.REQUEST_SYNC)
}
}

View file

@ -39,7 +39,7 @@ import com.zeapo.pwdstore.autofill.oreo.AutofillMatcher
import com.zeapo.pwdstore.crypto.PgpActivity
import com.zeapo.pwdstore.crypto.PgpActivity.Companion.getLongName
import com.zeapo.pwdstore.git.BaseGitActivity
import com.zeapo.pwdstore.git.GitActivity
import com.zeapo.pwdstore.git.GitOperationActivity
import com.zeapo.pwdstore.git.GitAsyncTask
import com.zeapo.pwdstore.git.GitOperation
import com.zeapo.pwdstore.git.GitServerConfigActivity
@ -251,8 +251,8 @@ class PasswordStore : AppCompatActivity() {
initBefore.show()
return false
}
intent = Intent(this, GitActivity::class.java)
intent.putExtra("Operation", BaseGitActivity.REQUEST_PUSH)
intent = Intent(this, GitOperationActivity::class.java)
intent.putExtra(BaseGitActivity.REQUEST_ARG_OP, BaseGitActivity.REQUEST_PUSH)
startActivityForResult(intent, BaseGitActivity.REQUEST_PUSH)
return true
}
@ -261,8 +261,8 @@ class PasswordStore : AppCompatActivity() {
initBefore.show()
return false
}
intent = Intent(this, GitActivity::class.java)
intent.putExtra("Operation", BaseGitActivity.REQUEST_PULL)
intent = Intent(this, GitOperationActivity::class.java)
intent.putExtra(BaseGitActivity.REQUEST_ARG_OP, BaseGitActivity.REQUEST_PULL)
startActivityForResult(intent, BaseGitActivity.REQUEST_PULL)
return true
}
@ -271,8 +271,8 @@ class PasswordStore : AppCompatActivity() {
initBefore.show()
return false
}
intent = Intent(this, GitActivity::class.java)
intent.putExtra("Operation", BaseGitActivity.REQUEST_SYNC)
intent = Intent(this, GitOperationActivity::class.java)
intent.putExtra(BaseGitActivity.REQUEST_ARG_OP, BaseGitActivity.REQUEST_SYNC)
startActivityForResult(intent, BaseGitActivity.REQUEST_SYNC)
return true
}
@ -551,7 +551,7 @@ class PasswordStore : AppCompatActivity() {
fileLocations.add(file.absolutePath)
}
intent.putExtra("Files", fileLocations)
intent.putExtra("Operation", "SELECTFOLDER")
intent.putExtra(BaseGitActivity.REQUEST_ARG_OP, "SELECTFOLDER")
startActivityForResult(intent, REQUEST_CODE_SELECT_FOLDER)
}
@ -640,8 +640,8 @@ class PasswordStore : AppCompatActivity() {
return // if not empty, just show me the passwords!
}
}
val intent = Intent(activity, GitActivity::class.java)
intent.putExtra("Operation", BaseGitActivity.REQUEST_CLONE)
val intent = Intent(activity, GitOperationActivity::class.java)
intent.putExtra(BaseGitActivity.REQUEST_ARG_OP, BaseGitActivity.REQUEST_CLONE)
startActivityForResult(intent, BaseGitActivity.REQUEST_CLONE)
}
REQUEST_CODE_SELECT_FOLDER -> {

View file

@ -64,6 +64,15 @@ abstract class BaseGitActivity : AppCompatActivity() {
}
}
override fun onDestroy() {
// Do not leak the service connection
if (identityBuilder != null) {
identityBuilder!!.close()
identityBuilder = null
}
super.onDestroy()
}
/**
* Update the [hostname] field with the values that build it up. This function returns a boolean
* indicating whether or not the values are valid or not, and only adds the `origin` remote when

View file

@ -14,18 +14,12 @@ import com.zeapo.pwdstore.UserPreference
import com.zeapo.pwdstore.git.config.SshApiSessionFactory
import com.zeapo.pwdstore.utils.PasswordRepository
open class GitActivity : BaseGitActivity() {
open class GitOperationActivity : BaseGitActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val operationCode = intent.extras!!.getInt("Operation")
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
when (operationCode) {
when (intent.extras?.getInt(REQUEST_ARG_OP)) {
REQUEST_PULL -> syncRepository(REQUEST_PULL)
REQUEST_PUSH -> syncRepository(REQUEST_PUSH)
REQUEST_SYNC -> syncRepository(REQUEST_SYNC)
}
}
@ -34,15 +28,6 @@ open class GitActivity : BaseGitActivity() {
super.onResume()
}
override fun onDestroy() {
// Do not leak the service connection
if (identityBuilder != null) {
identityBuilder!!.close()
identityBuilder = null
}
super.onDestroy()
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.git_clone, menu)
@ -91,7 +76,6 @@ open class GitActivity : BaseGitActivity() {
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
// In addition to the pre-operation-launch series of intents for OpenKeychain auth
// that will pass through here and back to launchGitOperation, there is one
// synchronous operation that happens /after/ the operation has been launched in the

View file

@ -4,7 +4,7 @@
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="@dimen/activity_horizontal_margin"
tools:context="com.zeapo.pwdstore.git.GitActivity"
tools:context="com.zeapo.pwdstore.git.GitOperationActivity"
android:background="?android:attr/windowBackground">
<androidx.appcompat.widget.AppCompatTextView

View file

@ -5,7 +5,7 @@
android:layout_height="match_parent"
android:padding="@dimen/activity_horizontal_margin"
android:background="?android:attr/windowBackground"
tools:context="com.zeapo.pwdstore.git.GitActivity"
tools:context="com.zeapo.pwdstore.git.GitConfigActivity"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="81dp">

View file

@ -1,7 +1,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:pwstore="http://schemas.android.com/apk/res-auto"
tools:context="com.zeapo.pwdstore.git.GitActivity" >
tools:context="com.zeapo.pwdstore.git.GitServerConfigActivity" >
<item android:id="@+id/user_pref"
android:title="@string/action_settings"
android:orderInCategory="100"

View file

@ -33,6 +33,21 @@
<item name="background">@color/primary_color</item>
</style>
<style name="NoBackgroundTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:background">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:navigationBarColor">@color/navigation_bar_color</item>
<item name="android:statusBarColor">@color/status_bar_color</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
<item name="android:windowExitAnimation">@android:anim/fade_out</item>
<item name="colorPrimaryDark">@android:color/transparent</item>
<item name="windowNoTitle">true</item>
</style>
<style name="ThemeOverlay.AppTheme.TextInputEditText.OutlinedBox" parent="ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<item name="colorControlActivated">@color/color_control_normal</item>
</style>