diff --git a/build.gradle b/build.gradle index 5c0b2700fff..431b2eb2229 100644 --- a/build.gradle +++ b/build.gradle @@ -25,5 +25,6 @@ ext { flipTableVersion = '1.0.1' butterKnifeVersion = '8.0.1' mifosPasscodeVersion = '0.3.0' + preference = '1.1.0' } \ No newline at end of file diff --git a/mifosng-android/build.gradle b/mifosng-android/build.gradle index ccbdaa80cc7..3a53f1567e6 100755 --- a/mifosng-android/build.gradle +++ b/mifosng-android/build.gradle @@ -254,6 +254,8 @@ dependencies { //card view implementation 'androidx.cardview:cardview:1.0.0' + //preferences + implementation "androidx.preference:preference:$preference" } /* diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/SettingsActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/SettingsActivity.kt index 344fa379a56..a6ce1e65cf5 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/SettingsActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/SettingsActivity.kt @@ -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()) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/SettingsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/SettingsFragment.kt index 3e3adf32165..6bfc4ebe4e6 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/SettingsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/SettingsFragment.kt @@ -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. @@ -20,6 +26,16 @@ class SettingsFragment : PreferenceFragment(), SharedPreferences.OnSharedPrefere var mEnableSyncSurvey: SwitchPreference? = null private lateinit var languages: Array 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) @@ -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() { @@ -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) } } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/checkertaskfilterdialog/CheckerTaskFilterDialogFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/checkertaskfilterdialog/CheckerTaskFilterDialogFragment.kt index 830748e4188..08e82fe21eb 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/checkertaskfilterdialog/CheckerTaskFilterDialogFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/checkertaskfilterdialog/CheckerTaskFilterDialogFragment.kt @@ -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 } @@ -105,7 +109,7 @@ class CheckerTaskFilterDialogFragment : DialogFragment(), MFDatePicker.OnDatePic ) mOnInputSelected.sendInput(fromDateTimeStamp, toDateTimeStamp, selectedAction, selectedEntity, resourceId) - dialog.dismiss() + dialog?.dismiss() } } @@ -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 diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/DashboardActivity.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/DashboardActivity.java index bd2edc62e9d..2fbbfd97211 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/DashboardActivity.java +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/DashboardActivity.java @@ -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 diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsFragment.kt index 0424fff11cd..9cb47c682eb 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsFragment.kt @@ -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 diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt index 77058ec6440..9f93d6006e5 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt @@ -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 = ArrayList() private val mFragmentTitleList: MutableList = ArrayList() override fun getItem(position: Int): Fragment { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientFragment.kt index 8660bc21e6e..1eefac03dc4 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientFragment.kt @@ -487,7 +487,7 @@ 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 @@ -495,7 +495,7 @@ class CreateNewClientFragment : ProgressableFragment(), OnDatePickListener, Crea } 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) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataFragment.kt index a82b34421b1..c0316143697 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataFragment.kt @@ -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 diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/sign/SignatureFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/sign/SignatureFragment.kt index 6541323afdb..e10264792cb 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/sign/SignatureFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/sign/SignatureFragment.kt @@ -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) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/passcode/PassCodeActivity.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/passcode/PassCodeActivity.java deleted file mode 100644 index 2ef5c758853..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/passcode/PassCodeActivity.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.mifos.mifosxdroid.passcode; - -import android.content.Intent; -import android.view.View; -import android.widget.Toast; - -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; - -public class PassCodeActivity extends MifosPassCodeActivity { - - @Override - public int getLogo() { - return R.drawable.mifos_logo; - } - - @Override - public void startNextActivity() { - Toast.makeText(this, R.string.Log_in_success, Toast.LENGTH_SHORT).show(); - startActivity(new Intent(this, DashboardActivity.class)); - } - - @Override - public void startLoginActivity() { - Intent i = new Intent(PassCodeActivity.this, SplashScreenActivity.class); - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - startActivity(i); - finish(); - } - - @Override - public void showToaster(View view, int msg) { - Toaster.show(view, msg); - } - - @Override - public int getEncryptionType() { - return EncryptionUtil.ANDROID_CLIENT; - } - -} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/passcode/PassCodeActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/passcode/PassCodeActivity.kt new file mode 100644 index 00000000000..d6cae066009 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/passcode/PassCodeActivity.kt @@ -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() + } +} diff --git a/mifosng-android/src/main/java/com/mifos/utils/Constants.java b/mifosng-android/src/main/java/com/mifos/utils/Constants.java index 35481e5a7e5..14982a62ff4 100755 --- a/mifosng-android/src/main/java/com/mifos/utils/Constants.java +++ b/mifosng-android/src/main/java/com/mifos/utils/Constants.java @@ -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"; } diff --git a/mifosng-android/src/main/res/drawable/ic_dark_mode.xml b/mifosng-android/src/main/res/drawable/ic_dark_mode.xml new file mode 100644 index 00000000000..e5391167c40 --- /dev/null +++ b/mifosng-android/src/main/res/drawable/ic_dark_mode.xml @@ -0,0 +1,10 @@ + + + diff --git a/mifosng-android/src/main/res/drawable/ic_lang.xml b/mifosng-android/src/main/res/drawable/ic_lang.xml new file mode 100644 index 00000000000..79b414cd870 --- /dev/null +++ b/mifosng-android/src/main/res/drawable/ic_lang.xml @@ -0,0 +1,10 @@ + + + diff --git a/mifosng-android/src/main/res/drawable/ic_passcode.xml b/mifosng-android/src/main/res/drawable/ic_passcode.xml new file mode 100644 index 00000000000..d6191026a48 --- /dev/null +++ b/mifosng-android/src/main/res/drawable/ic_passcode.xml @@ -0,0 +1,10 @@ + + + diff --git a/mifosng-android/src/main/res/values/strings.xml b/mifosng-android/src/main/res/values/strings.xml index 3e252f8c1f2..81542ac9500 100755 --- a/mifosng-android/src/main/res/values/strings.xml +++ b/mifosng-android/src/main/res/values/strings.xml @@ -898,4 +898,8 @@ + Passcode + Change Passcode + Change App Passcode + diff --git a/mifosng-android/src/main/res/xml/preferences.xml b/mifosng-android/src/main/res/xml/preferences.xml index cd242bf53ff..80903b31b41 100644 --- a/mifosng-android/src/main/res/xml/preferences.xml +++ b/mifosng-android/src/main/res/xml/preferences.xml @@ -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" /> - + \ No newline at end of file