From e1ae4978ec1c9842448f21a00be2359121a3c73b Mon Sep 17 00:00:00 2001 From: Mohamed Zenadi Date: Sat, 29 Jul 2017 15:14:25 +0100 Subject: Extract Select folder (moving) into its own activity more work needed --- app/src/main/AndroidManifest.xml | 3 +- .../com/zeapo/pwdstore/SelectFolderActivity.kt | 63 ++++++++++++++++++++++ .../main/res/menu/pgp_handler_select_folder.xml | 2 +- 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/zeapo/pwdstore/SelectFolderActivity.kt (limited to 'app') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 15b4c743..808606cd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -86,6 +86,7 @@ - + + diff --git a/app/src/main/java/com/zeapo/pwdstore/SelectFolderActivity.kt b/app/src/main/java/com/zeapo/pwdstore/SelectFolderActivity.kt new file mode 100644 index 00000000..c3c53998 --- /dev/null +++ b/app/src/main/java/com/zeapo/pwdstore/SelectFolderActivity.kt @@ -0,0 +1,63 @@ +package com.zeapo.pwdstore + +import android.app.Activity +import android.app.FragmentManager +import android.os.Bundle +import android.os.PersistableBundle +import android.support.v7.app.AppCompatActivity +import android.view.Menu +import android.view.MenuItem +import com.zeapo.pwdstore.utils.PasswordRepository + +// TODO more work needed, this is just an extraction from PgpHandler + +class SelectFolderActivity : AppCompatActivity() { + internal var passwordList: SelectFolderFragment? = null + + override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) { + super.onCreate(savedInstanceState, persistentState) + + setContentView(R.layout.select_folder_layout) + + val fragmentManager = supportFragmentManager + val fragmentTransaction = fragmentManager.beginTransaction() + + + passwordList = SelectFolderFragment() + val args = Bundle() + args.putString("Path", PasswordRepository.getRepositoryDirectory(applicationContext).absolutePath) + + passwordList?.arguments = args + + supportActionBar?.show() + + fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE) + + fragmentTransaction.replace(R.id.pgp_handler_linearlayout, passwordList, "PasswordsList") + fragmentTransaction.commit() + } + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.pgp_handler_select_folder, menu) + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + val id = item.itemId + when (id) { + android.R.id.home -> { + setResult(Activity.RESULT_CANCELED) + finish() + return true + } + R.id.crypto_select -> selectFolder() + } + return super.onOptionsItemSelected(item) + } + + private fun selectFolder() { + intent.putExtra("SELECTED_FOLDER_PATH", passwordList?.currentDir?.absolutePath) + setResult(Activity.RESULT_OK, intent) + finish() + } +} \ No newline at end of file diff --git a/app/src/main/res/menu/pgp_handler_select_folder.xml b/app/src/main/res/menu/pgp_handler_select_folder.xml index c18ede62..c9855ecd 100644 --- a/app/src/main/res/menu/pgp_handler_select_folder.xml +++ b/app/src/main/res/menu/pgp_handler_select_folder.xml @@ -2,7 +2,7 @@ + tools:context="com.zeapo.pwdstore.SelectFolderActivity" >