Review fixes

Signed-off-by: Aditya Wasan <adityawasan55@gmail.com>
This commit is contained in:
Aditya Wasan 2020-09-14 23:00:12 +05:30
parent 929584c5c7
commit 7d7e7c3a9a
8 changed files with 117 additions and 98 deletions

View file

@ -33,7 +33,7 @@
android:label="@string/app_name" />
<activity
android:name="com.zeapo.pwdstore.ui.onboarding.activity.OnboardingActivity"
android:name=".ui.onboarding.activity.OnboardingActivity"
android:configChanges="orientation|screenSize" />
<activity

View file

@ -2,6 +2,7 @@
* Copyright © 2019-2020 The Android Password Store Authors. All Rights Reserved.
* SPDX-License-Identifier: GPL-3.0-only
*/
package com.zeapo.pwdstore.ui.onboarding.fragments
import android.os.Bundle

View file

@ -20,10 +20,7 @@ import androidx.annotation.RequiresApi
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.commit
import androidx.preference.PreferenceManager
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKey
@ -43,16 +40,24 @@ import org.eclipse.jgit.revwalk.RevCommit
const val OPENPGP_PROVIDER = "org.sufficientlysecure.keychain"
fun Int.clearFlag(flag: Int): Int = this and flag.inv()
fun Int.clearFlag(flag: Int): Int {
return this and flag.inv()
}
infix fun Int.hasFlag(flag: Int): Boolean = this and flag == flag
infix fun Int.hasFlag(flag: Int): Boolean {
return this and flag == flag
}
fun String.splitLines(): Array<String> =
split("\n".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
fun String.splitLines(): Array<String> {
return split("\n".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
}
fun String.base64(): String = Base64.encodeToString(encodeToByteArray(), Base64.NO_WRAP)
fun String.base64(): String {
return Base64.encodeToString(encodeToByteArray(), Base64.NO_WRAP)
}
val Context.clipboard get() = getSystemService<ClipboardManager>()
val Context.clipboard
get() = getSystemService<ClipboardManager>()
fun FragmentActivity.snackbar(
view: View = findViewById(android.R.id.content),
@ -131,14 +136,9 @@ suspend fun FragmentActivity.commitChange(
}.execute()
}
fun FragmentActivity.isPermissionGranted(permission: String): Boolean =
ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED
fun Fragment.isPermissionGranted(permission: String): Boolean =
ContextCompat.checkSelfPermission(requireActivity(), permission) == PackageManager.PERMISSION_GRANTED
fun Fragment.finish() = requireActivity().finish()
fun FragmentActivity.isPermissionGranted(permission: String): Boolean {
return ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED
}
/**
* Extension function for [AlertDialog] that requests focus for the
@ -188,39 +188,3 @@ val RevCommit.time: Date
val epochMilliseconds = epochSeconds * 1000
return Date(epochMilliseconds)
}
fun FragmentManager.performTransaction(destinationFragment: Fragment, @IdRes containerViewId: Int = android.R.id.content) {
this.commit {
beginTransaction()
setCustomAnimations(
R.animator.slide_in_left,
R.animator.slide_out_left,
R.animator.slide_in_right,
R.animator.slide_out_right)
replace(containerViewId, destinationFragment)
}
}
fun FragmentManager.performTransactionWithBackStack(destinationFragment: Fragment, @IdRes containerViewId: Int = android.R.id.content) {
this.commit {
beginTransaction()
addToBackStack(destinationFragment.tag)
setCustomAnimations(
R.animator.slide_in_left,
R.animator.slide_out_left,
R.animator.slide_in_right,
R.animator.slide_out_right)
replace(containerViewId, destinationFragment)
}
}
fun FragmentManager.performSharedElementTransaction(destinationFragment: Fragment, views: List<View>, @IdRes containerViewId: Int = android.R.id.content) {
this.commit {
beginTransaction()
for (view in views) {
addSharedElement(view, view.transitionName)
}
addToBackStack(destinationFragment.tag)
replace(containerViewId, destinationFragment)
}
}

View file

@ -0,0 +1,52 @@
package com.zeapo.pwdstore.utils
import android.content.pm.PackageManager
import android.view.View
import androidx.annotation.IdRes
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.commit
import com.zeapo.pwdstore.R
fun Fragment.isPermissionGranted(permission: String): Boolean {
return ContextCompat.checkSelfPermission(requireActivity(), permission) == PackageManager.PERMISSION_GRANTED
}
fun Fragment.finish() = requireActivity().finish()
fun FragmentManager.performTransaction(destinationFragment: Fragment, @IdRes containerViewId: Int = android.R.id.content) {
this.commit {
beginTransaction()
setCustomAnimations(
R.animator.slide_in_left,
R.animator.slide_out_left,
R.animator.slide_in_right,
R.animator.slide_out_right)
replace(containerViewId, destinationFragment)
}
}
fun FragmentManager.performTransactionWithBackStack(destinationFragment: Fragment, @IdRes containerViewId: Int = android.R.id.content) {
this.commit {
beginTransaction()
addToBackStack(destinationFragment.tag)
setCustomAnimations(
R.animator.slide_in_left,
R.animator.slide_out_left,
R.animator.slide_in_right,
R.animator.slide_out_right)
replace(containerViewId, destinationFragment)
}
}
fun FragmentManager.performSharedElementTransaction(destinationFragment: Fragment, views: List<View>, @IdRes containerViewId: Int = android.R.id.content) {
this.commit {
beginTransaction()
for (view in views) {
addSharedElement(view, view.transitionName)
}
addToBackStack(destinationFragment.tag)
replace(containerViewId, destinationFragment)
}
}

View file

@ -1,8 +1,8 @@
<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="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/colorPrimary"
android:orientation="vertical">
@ -24,12 +24,12 @@
android:layout_centerHorizontal="true"
android:layout_marginStart="16dp"
android:text="@string/app_name"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline5"
android:textColor="@color/color_control_normal"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@id/app_icon"
app:layout_constraintStart_toEndOf="@id/app_icon"
app:layout_constraintTop_toTopOf="@+id/app_icon"
app:layout_constraintBottom_toBottomOf="@id/app_icon"/>
app:layout_constraintTop_toTopOf="@+id/app_icon" />
<TextView
android:id="@+id/repo_type"
@ -37,26 +37,26 @@
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:text="@string/select_n_repository_type"
android:textStyle="bold"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline4"
android:textColor="@color/color_control_normal"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="@id/app_icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_icon" />
<TextView
android:id="@+id/tv_repo_type_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="16dp"
android:text="@string/select_repo_type_text"
android:textStyle="bold"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
android:textColor="@color/color_control_normal"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="@id/repo_type"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/repo_type"
app:layout_constraintTop_toBottomOf="@id/repo_type" />
<com.google.android.material.button.MaterialButton
@ -68,8 +68,8 @@
android:maxWidth="300dp"
android:minWidth="100dp"
android:text="@string/clone_remote_repo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/create_local"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<com.google.android.material.button.MaterialButton
@ -77,11 +77,11 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="128dp"
android:minWidth="100dp"
android:maxWidth="300dp"
android:minWidth="100dp"
android:text="@string/create_local_repo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@id/clone_remote"
app:layout_constraintEnd_toEndOf="@id/clone_remote" />
app:layout_constraintEnd_toEndOf="@id/clone_remote"
app:layout_constraintStart_toStartOf="@id/clone_remote" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,8 +1,8 @@
<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="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/colorPrimary"
android:orientation="vertical">
@ -24,12 +24,12 @@
android:layout_centerHorizontal="true"
android:layout_marginStart="16dp"
android:text="@string/app_name"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline5"
android:textColor="@color/color_control_normal"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@id/app_icon"
app:layout_constraintStart_toEndOf="@id/app_icon"
app:layout_constraintTop_toTopOf="@+id/app_icon"
app:layout_constraintBottom_toBottomOf="@id/app_icon"/>
app:layout_constraintTop_toTopOf="@+id/app_icon" />
<TextView
android:id="@+id/repo_location"
@ -37,9 +37,11 @@
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:text="@string/repository_n_location"
android:textStyle="bold"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline4"
android:textColor="@color/color_control_normal"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="@id/app_icon"
app:layout_constraintTop_toBottomOf="@id/app_icon" />
@ -47,14 +49,14 @@
android:id="@+id/repo_location_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="16dp"
android:text="@string/location_dialog_create_text"
android:textStyle="bold"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
android:textColor="@color/color_control_normal"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="@id/repo_location"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/repo_location"
app:layout_constraintTop_toBottomOf="@id/repo_location" />
<com.google.android.material.button.MaterialButton
@ -66,8 +68,8 @@
android:maxWidth="300dp"
android:minWidth="100dp"
android:text="@string/location_hidden"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/sdcard"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<com.google.android.material.button.MaterialButton
@ -75,11 +77,11 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="128dp"
android:minWidth="100dp"
android:maxWidth="300dp"
android:minWidth="100dp"
android:text="@string/location_sdcard"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@id/hidden"
app:layout_constraintEnd_toEndOf="@id/hidden" />
app:layout_constraintEnd_toEndOf="@id/hidden"
app:layout_constraintStart_toStartOf="@id/hidden" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,8 +1,8 @@
<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="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/colorPrimary"
android:orientation="vertical">
@ -10,28 +10,28 @@
android:id="@+id/app_icon"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@mipmap/ic_launcher"
android:contentDescription="@string/app_icon_hint"
android:src="@mipmap/ic_launcher"
android:transitionName="transition_first_app_icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_centerHorizontal="true"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:layout_marginTop="16dp"
android:text="@string/app_name"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline5"
android:textColor="@color/color_control_normal"
android:textStyle="bold"
android:transitionName="transition_first_run_app_name"
app:layout_constraintTop_toBottomOf="@+id/app_icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
app:layout_constraintTop_toBottomOf="@+id/app_icon" />
<com.google.android.material.button.MaterialButton
@ -39,13 +39,13 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:minWidth="100dp"
android:maxWidth="300dp"
android:text="@string/let_s_go"
android:layout_marginTop="48dp"
app:layout_constraintTop_toBottomOf="@id/app_name"
android:layout_marginEnd="16dp"
android:maxWidth="300dp"
android:minWidth="100dp"
android:text="@string/let_s_go"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
app:layout_constraintTop_toBottomOf="@id/app_name" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -77,7 +77,7 @@
<string name="clone">Clone from server</string>
<string name="initialize">Use local directory</string>
<string name="location_dialog_title">Repository location</string>
<string name="location_dialog_create_text">Select where to create your password repository</string>
<string name="location_dialog_create_text">Select where do you want to create your password repository</string>
<string name="location_sdcard">SD-Card</string>
<string name="location_hidden">Hidden (Preferred)</string>
<string name="external_repository_dialog_title">Choose where to store the passwords</string>