Skip to content

Commit

Permalink
Feat: Change Passcode
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsh4shank committed Jun 2, 2021
1 parent 6c3892a commit f5a367a
Show file tree
Hide file tree
Showing 19 changed files with 174 additions and 66 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ ext {
flipTableVersion = '1.0.1'
butterKnifeVersion = '8.0.1'
mifosPasscodeVersion = '0.3.0'
preference = '1.1.0'

}
2 changes: 2 additions & 0 deletions mifosng-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ dependencies {

//card view
implementation 'androidx.cardview:cardview:1.0.0'
//preferences
implementation "androidx.preference:preference:$preference"
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import com.mifos.mifosxdroid.online.DashboardActivity
* Created by mayankjindal on 22/07/17.
*/
class SettingsActivity : MifosBaseActivity() {
public override fun onCreate(savedInstanceState: Bundle?) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_toolbar_container)
setToolbarTitle(getString(R.string.settings))
showBackButton()
fragmentManager.beginTransaction()
.replace(R.id.container, SettingsFragment())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import com.mifos.mifosxdroid.dialogfragments.syncsurveysdialog.SyncSurveysDialog
import com.mifos.utils.FragmentConstants
import com.mifos.utils.LanguageHelper
import com.mifos.utils.ThemeHelper
import android.preference.Preference
import android.preference.PreferenceScreen

import com.mifos.mifosxdroid.passcode.PassCodeActivity
import com.mifos.mobile.passcode.utils.PasscodePreferencesHelper
import com.mifos.utils.Constants

/**
* Created by mayankjindal on 22/07/17.
Expand All @@ -20,6 +26,16 @@ class SettingsFragment : PreferenceFragment(), SharedPreferences.OnSharedPrefere
var mEnableSyncSurvey: SwitchPreference? = null
private lateinit var languages: Array<String>
private var languageCallback: LanguageCallback? = null
var preference: Preference? = null

companion object {
fun newInstance(): SettingsFragment {
val fragment = SettingsFragment()
val args = Bundle()
fragment.arguments = args
return fragment
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -56,6 +72,25 @@ class SettingsFragment : PreferenceFragment(), SharedPreferences.OnSharedPrefere
Toast.makeText(activity, "Switched to ${themeOption.toString()} Mode", Toast.LENGTH_SHORT).show()
true
}

when (preference?.key) {
getString(R.string.password) -> {
// TODO("create changePasswordActivity and implement the logic for password change")
}
getString(R.string.passcode) -> {
activity?.let {
val passCodePreferencesHelper = PasscodePreferencesHelper(activity)
val currPassCode = passCodePreferencesHelper.passCode
passCodePreferencesHelper.savePassCode("")
val intent = Intent(it, PassCodeActivity::class.java).apply {
putExtra(Constants.CURR_PASSWORD, currPassCode)
putExtra(Constants.IS_TO_UPDATE_PASS_CODE, true)
}
preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this)
startActivity(intent)
}
}
}
}

override fun onPause() {
Expand All @@ -76,12 +111,25 @@ class SettingsFragment : PreferenceFragment(), SharedPreferences.OnSharedPrefere
fun updateNavDrawer()
}

companion object {
fun newInstance(): SettingsFragment {
val fragment = SettingsFragment()
val args = Bundle()
fragment.arguments = args
return fragment
override fun onPreferenceTreeClick(preferenceScreen: PreferenceScreen?, preference: Preference?): Boolean {
when (preference?.key) {
getString(R.string.password) -> {
// TODO("create changePasswordActivity and implement the logic for password change")
}

getString(R.string.passcode) -> {
activity?.let {
val passCodePreferencesHelper = PasscodePreferencesHelper(activity)
val currPassCode = passCodePreferencesHelper.passCode
passCodePreferencesHelper.savePassCode("")
val intent = Intent(it, PassCodeActivity::class.java).apply {
putExtra(Constants.CURR_PASSWORD, currPassCode)
putExtra(Constants.IS_TO_UPDATE_PASS_CODE, true)
}
startActivity(intent)
}
}
}
return super.onPreferenceTreeClick(preferenceScreen, preference)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,18 @@ class CheckerTaskFilterDialogFragment : DialogFragment(), MFDatePicker.OnDatePic

private fun setOnClickListeners() {
tv_from_date.setOnClickListener {
datePickerFromDate.show(activity?.supportFragmentManager,
FragmentConstants.DFRAG_DATE_PICKER)
activity?.supportFragmentManager?.let { it1 ->
datePickerFromDate.show(it1,
FragmentConstants.DFRAG_DATE_PICKER)
}
mCurrentDateView = tv_from_date
}

tv_to_date.setOnClickListener {
datePickerToDate.show(activity?.supportFragmentManager,
FragmentConstants.DFRAG_DATE_PICKER)
activity?.supportFragmentManager?.let { it1 ->
datePickerToDate.show(it1,
FragmentConstants.DFRAG_DATE_PICKER)
}
mCurrentDateView = tv_to_date
}

Expand All @@ -105,7 +109,7 @@ class CheckerTaskFilterDialogFragment : DialogFragment(), MFDatePicker.OnDatePic
)
mOnInputSelected.sendInput(fromDateTimeStamp, toDateTimeStamp,
selectedAction, selectedEntity, resourceId)
dialog.dismiss()
dialog?.dismiss()
}
}

Expand Down Expand Up @@ -139,7 +143,7 @@ class CheckerTaskFilterDialogFragment : DialogFragment(), MFDatePicker.OnDatePic
})
}

override fun onAttach(context: Context?) {
override fun onAttach(context: Context) {
super.onAttach(context)
try {
mOnInputSelected = targetFragment as OnInputSelected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_dashboard);

ButterKnife.bind(this);
//runJobs();
replaceFragment(new SearchFragment(), false, R.id.container);

// setup navigation drawer and Navigation Toggle click and Offline Mode SwitchButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView {
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
try {
// When an Image is picked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class IndividualCollectionSheetFragment : MifosBaseFragment() {
viewPager!!.adapter = adapter
}

internal inner class ViewPagerAdapter(manager: FragmentManager?) : FragmentPagerAdapter(manager) {
internal inner class ViewPagerAdapter(manager: FragmentManager?) : FragmentPagerAdapter(manager!!) {
private val mFragmentList: MutableList<Fragment> = ArrayList()
private val mFragmentTitleList: MutableList<String> = ArrayList()
override fun getItem(position: Int): Fragment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,15 @@ class CreateNewClientFragment : ProgressableFragment(), OnDatePickListener, Crea
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE
&& resultCode == Activity.RESULT_OK) {
createClientWithImage = true
ivClientImage!!.setImageBitmap(BitmapFactory.decodeFile(ClientImageFile!!.absolutePath))
} else if (requestCode == PICK_IMAGE_ACTIVITY_REQUEST_CODE
&& resultCode == Activity.RESULT_OK) {
createClientWithImage = true
pickedImageUri = data.data
pickedImageUri = data?.data
val filePath = arrayOf(MediaStore.Images.Media.DATA)
val c = activity!!.contentResolver.query(pickedImageUri, filePath,
null, null, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class DataTableDataFragment : MifosBaseFragment(), DataTableActionListener, Data
return super.onOptionsItemSelected(item)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
Constants.DIALOG_FRAGMENT -> if (resultCode == Activity.RESULT_OK) {
mDataTableDataPresenter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ class SignatureFragment : MifosBaseFragment(), SignatureMvpView, BottomNavigatio
startActivityForResult(intentDocument, FILE_SELECT_CODE)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
FILE_SELECT_CODE -> if (resultCode == Activity.RESULT_OK) {
val uri = data.data
val uri = data?.data
val filePath = FileUtils.getPathReal(activity, uri)
if (filePath != null) {
signatureFile = File(filePath)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.mifos.mifosxdroid.passcode;

import android.content.Intent
import android.os.Bundle
import android.view.View
import com.mifos.mifosxdroid.R
import com.mifos.mifosxdroid.SplashScreenActivity
import com.mifos.mifosxdroid.core.util.Toaster
import com.mifos.mifosxdroid.online.DashboardActivity
import com.mifos.mobile.passcode.MifosPassCodeActivity
import com.mifos.mobile.passcode.utils.EncryptionUtil
import com.mifos.mobile.passcode.utils.PasscodePreferencesHelper
import com.mifos.utils.Constants

class PassCodeActivity : MifosPassCodeActivity() {
private var currPassCode: String? = null
private var isToUpdatePassCode: Boolean = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
intent?.let {
currPassCode = it.getStringExtra(Constants.CURR_PASSWORD)
isToUpdatePassCode = it.getBooleanExtra(Constants.IS_TO_UPDATE_PASS_CODE, false)
}
}

override fun showToaster(view: View?, msg: Int) {
Toaster.show(view, msg, Toaster.SHORT)
}
override fun startLoginActivity() {
startActivity(Intent(this, SplashScreenActivity::class.java))
finish()
}
override fun getLogo(): Int {
return R.drawable.mifos_logo
}
override fun getEncryptionType(): Int {
return EncryptionUtil.FINERACT_CN
}
override fun startNextActivity() {
startActivity(Intent(this, DashboardActivity::class.java))
}

override fun onBackPressed() {
super.onBackPressed()
if (isToUpdatePassCode && !currPassCode.isNullOrEmpty()) {
PasscodePreferencesHelper(this).apply {
savePassCode(currPassCode)
}
}
finish()
}
}
2 changes: 2 additions & 0 deletions mifosng-android/src/main/java/com/mifos/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,6 @@ public class Constants {
public static final String R_OVERDUE_X = "R_overdueX";
public static final String R_OVERDUE_Y = "R_overdueY";
public static final String ACTION_REPORT = "report";
public static final String CURR_PASSWORD = "currentPassword";
public static final String IS_TO_UPDATE_PASS_CODE = "updatePassCode";
}
10 changes: 10 additions & 0 deletions mifosng-android/src/main/res/drawable/ic_dark_mode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,3c-4.97,0 -9,4.03 -9,9s4.03,9 9,9s9,-4.03 9,-9c0,-0.46 -0.04,-0.92 -0.1,-1.36c-0.98,1.37 -2.58,2.26 -4.4,2.26c-2.98,0 -5.4,-2.42 -5.4,-5.4c0,-1.81 0.89,-3.42 2.26,-4.4C12.92,3.04 12.46,3 12,3L12,3z"/>
</vector>
10 changes: 10 additions & 0 deletions mifosng-android/src/main/res/drawable/ic_lang.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M5,17v2h14v-2L5,17zM9.5,12.8h5l0.9,2.2h2.1L12.75,4h-1.5L6.5,15h2.1l0.9,-2.2zM12,5.98L13.87,11h-3.74L12,5.98z"/>
</vector>
10 changes: 10 additions & 0 deletions mifosng-android/src/main/res/drawable/ic_passcode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM15.1,8L8.9,8L8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2z"/>
</vector>
4 changes: 4 additions & 0 deletions mifosng-android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -898,4 +898,8 @@
</string-array>


<string name="passcode">Passcode</string>
<string name="change_passcode">Change Passcode</string>
<string name="change_app_passcode">Change App Passcode</string>

</resources>
9 changes: 8 additions & 1 deletion mifosng-android/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@
android:summary="@string/lang_change_description"
android:key="@string/language_type"
android:defaultValue="en"
android:icon="@drawable/ic_lang"
android:entries="@array/language_option"
android:entryValues="@array/languages_value" />


<ListPreference
android:title="@string/dark_mode"
android:key="@string/mode_key"
android:defaultValue="light"
android:icon="@drawable/ic_dark_mode"
android:entries="@array/dark_mode_entries"
android:entryValues="@array/dark_mode_values" />
<Preference
android:key="@string/passcode"
android:persistent="false"
android:icon="@drawable/ic_passcode"
android:summary="@string/change_app_passcode"
android:title="@string/change_passcode"/>
</PreferenceScreen>

0 comments on commit f5a367a

Please sign in to comment.