Skip to content

Commit

Permalink
Merge v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
acmpo6ou committed May 10, 2021
2 parents 1ca1692 + e294d2f commit 73e4dc9
Show file tree
Hide file tree
Showing 14 changed files with 267 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ android {
applicationId "com.acmpo6ou.myaccounts"
minSdkVersion 26
targetSdkVersion 30
versionCode 6
versionName "1.2.2"
versionCode 7
versionName "1.3.0"
setProperty("archivesBaseName", "myaccounts") // name will be myaccounts-release.apk

testInstrumentationRunner "com.acmpo6ou.myaccounts.HiltTestRunner"
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@
android:supportsRtl="true"
android:theme="@style/Theme.MyAccounts">

<service
android:name="MyAccountsBoard"
android:label="MyAccounts Board"
android:permission="android.permission.BIND_INPUT_METHOD">
<intent-filter>
<action android:name="android.view.InputMethod" />
</intent-filter>
<meta-data android:name="android.view.im"
android:resource="@xml/method" />
</service>

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/acmpo6ou/myaccounts/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ open class MainActivity : SuperActivity(), MainActivityI {
checkStoragePermission()
}

private val permissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestPermission()) {
}

private fun checkStoragePermission() {
val isGranted = checkCallingOrSelfPermission(permission.WRITE_EXTERNAL_STORAGE)
if (isGranted != PackageManager.PERMISSION_GRANTED)
requestPermissions(arrayOf(permission.WRITE_EXTERNAL_STORAGE), 300)
permissionLauncher.launch(permission.WRITE_EXTERNAL_STORAGE)
}

override fun onNavigationItemSelected(item: MenuItem): Boolean {
Expand Down
52 changes: 52 additions & 0 deletions app/src/main/java/com/acmpo6ou/myaccounts/MyAccountsBoard.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2020-2021. Bohdan Kolvakh
* This file is part of MyAccounts.
*
* MyAccounts is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MyAccounts is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

package com.acmpo6ou.myaccounts

import android.inputmethodservice.InputMethodService
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.Button
import android.widget.TextView
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class MyAccountsBoard : InputMethodService() {

@Inject
lateinit var app: MyApp

@Inject
lateinit var inputManager: InputMethodManager

override fun onCreateInputView(): View {
val view = layoutInflater.inflate(R.layout.myaccounts_board, null)
val pasteButton = view.findViewById<Button>(R.id.pastePassword)

val noPassword = view.findViewById<TextView>(R.id.noPassword)
noPassword.visibility = if (app.password.isEmpty()) View.VISIBLE else View.GONE

pasteButton.setOnClickListener {
currentInputConnection.commitText(app.password, 1)
inputManager.showInputMethodPicker()
}
return view
}
}
3 changes: 3 additions & 0 deletions app/src/main/java/com/acmpo6ou/myaccounts/MyApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ open class MyApp : Application() {
// Because resources from MainActivity are correctly translated.
open lateinit var res: Resources

// Used by MyAccountsBoard service to safely copy and paste password
var password = ""

// path to directory that contains src folder
open val ACCOUNTS_DIR get() = getExternalFilesDir(null)?.path + "/"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@ package com.acmpo6ou.myaccounts.account.display_account

import android.annotation.SuppressLint
import android.app.Activity
import android.content.ComponentName
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.provider.Settings
import android.provider.Settings.ACTION_INPUT_METHOD_SETTINGS
import android.view.LayoutInflater
import android.view.MotionEvent.ACTION_DOWN
import android.view.MotionEvent.ACTION_UP
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.TextView
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.acmpo6ou.myaccounts.MyApp
import com.acmpo6ou.myaccounts.R
import com.acmpo6ou.myaccounts.account.accounts_activity.AccountsActivityI
import com.acmpo6ou.myaccounts.database.databases_list.Account
Expand All @@ -59,6 +64,12 @@ class DisplayAccountFragment : Fragment(), DisplayAccountFragmentI {
@Inject
lateinit var accountsActivity: AccountsActivityI

@Inject
lateinit var app: MyApp

@Inject
lateinit var inputManager: InputMethodManager

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -109,11 +120,69 @@ class DisplayAccountFragment : Fragment(), DisplayAccountFragmentI {
true
}

if (account.attachedFiles.isEmpty()) {
b.attachedFilesLabel.visibility = View.GONE
// listener to hide/display FAB when scrolling, so that the FAB doesn't prevent from
// reading possibly long comment
b.scrollView.setOnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
val dy = scrollY - oldScrollY
if (dy > 0) {
b.copyPassword.hide()
} else if (dy < 0) {
b.copyPassword.show()
}
}

if (account.attachedFiles.isEmpty()) b.attachedFilesLabel.visibility = View.GONE

b.copyPassword.setOnClickListener {
checkBoardEnabled()
showChangeInputMethodDialog()
app.password = account.password
passwordCopied()
}
}

/**
* Checks whether MyAccountsBoard service is enabled in settings by user.
* If it isn't goes to input method settings to allow user to enable the service.
*/
private fun checkBoardEnabled() {
val isGranted = inputManager
.enabledInputMethodList
.any { it.packageName == context?.packageName }

if (!isGranted) {
Intent(ACTION_INPUT_METHOD_SETTINGS).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(this)
}
}
}

/**
* Displays InputMethodPicker dialog for user to chose MyAccountsBoard as current keyboard
* if it isn't already current.
*/
private fun showChangeInputMethodDialog() {
val defaultIME = Settings.Secure.getString(
context?.contentResolver,
Settings.Secure.DEFAULT_INPUT_METHOD
)
val defaultInputMethod = ComponentName.unflattenFromString(defaultIME)?.packageName
if (defaultInputMethod != context?.packageName) inputManager.showInputMethodPicker()
}

/**
* Displays snackbar saying that password is copied.
*/
private fun passwordCopied() {
Snackbar.make(
b.displayAccountLayout,
R.string.copied, Snackbar.LENGTH_LONG
)
.setAction("HIDE") {}
.show()
}

private val saveFileLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.acmpo6ou.myaccounts.account.display_account

import android.content.Context
import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity
import com.acmpo6ou.myaccounts.R
import dagger.Binds
Expand Down Expand Up @@ -55,4 +56,9 @@ object DisplayAccountModule {
.fragments.first()
as DisplayAccountFragment
}

@Provides
@FragmentScoped
fun inputMethodManager(@ActivityContext activity: Context): InputMethodManager =
activity.getSystemService(InputMethodManager::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2020-2021. Bohdan Kolvakh
* This file is part of MyAccounts.
*
* MyAccounts is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MyAccounts is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

package com.acmpo6ou.myaccounts.core

import android.content.Context
import android.view.inputmethod.InputMethodManager
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ServiceComponent
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.android.scopes.ServiceScoped

@Module
@InstallIn(ServiceComponent::class)
object MyAccountsBoardModule {
@Provides
@ServiceScoped
fun inputMethodManager(@ApplicationContext app: Context): InputMethodManager =
app.getSystemService(InputMethodManager::class.java)
}
12 changes: 11 additions & 1 deletion app/src/main/res/layout/fragment_display_account.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,15 @@

</LinearLayout>
</androidx.core.widget.NestedScrollView>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/copyPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="16dp"
android:backgroundTint="@color/green"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_copy"
app:tint="@color/white" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
51 changes: 51 additions & 0 deletions app/src/main/res/layout/myaccounts_board.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2020-2021. Bohdan Kolvakh
~ This file is part of MyAccounts.
~
~ MyAccounts is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ MyAccounts is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
~
-->

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#333"
android:minHeight="250dp">

<Button
android:id="@+id/pastePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#1ED760"
android:text="@string/paste_password"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/noPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/you_didn_t_copy_the_password"
android:textColor="@color/red"
android:textSize="22sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pastePassword"
app:layout_constraintVertical_bias="0.13" />
</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/raw/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<h4>v1.3.0</h4>
<p> • added the ability to safely copy password</p>
<br/>

<h4>v1.2.2</h4>
<p> • fix max size of comment field in create/edit account form</p>
<br/>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@
<string name="remove">Вилучити</string>
<string name="attach_file">Прикріпити файл</string>
<string name="error_loading">Помилка завантаження прикріплених файлів!</string>
<string name="paste_password">Вставити пароль</string>
<string name="you_didn_t_copy_the_password">Пароль не скопійовано!</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,6 @@
<string name="remove">Remove</string>
<string name="attach_file">Attach file</string>
<string name="error_loading">Error loading attached files!</string>
<string name="paste_password">Paste password</string>
<string name="you_didn_t_copy_the_password">You didn\'t copy the password!</string>
</resources>
9 changes: 9 additions & 0 deletions app/src/main/res/xml/method.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<input-method
xmlns:android="http://schemas.android.com/apk/res/android">

<subtype
android:label="MyAccounts Board"
android:imeSubtypeMode="keyboard"/>

</input-method>

0 comments on commit 73e4dc9

Please sign in to comment.