summaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/SelectFolderActivity.kt
blob: 4d8475df8f5792c6fbf997c7ac79b9fed5cf6414 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
 * SPDX-License-Identifier: GPL-3.0-only
 */
package com.zeapo.pwdstore

import android.app.Activity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentManager
import com.zeapo.pwdstore.utils.PasswordRepository

// TODO more work needed, this is just an extraction from PgpHandler

class SelectFolderActivity : AppCompatActivity() {
    private lateinit var passwordList: SelectFolderFragment

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

        setContentView(R.layout.select_folder_layout)

        val fragmentManager = supportFragmentManager
        val fragmentTransaction = fragmentManager.beginTransaction()

        passwordList = SelectFolderFragment()
        val args = Bundle()
        args.putString(PasswordStore.REQUEST_ARG_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()
    }
}