- Pin lock screen is working
This commit is contained in:
parent
c5f2ff21c7
commit
cb309f1db2
5 changed files with 87 additions and 33 deletions
|
@ -1,36 +1,16 @@
|
|||
package cy.agorise.crystalwallet.activities;
|
||||
|
||||
import android.arch.lifecycle.LifecycleActivity;
|
||||
import android.arch.lifecycle.LiveData;
|
||||
import android.arch.lifecycle.Observer;
|
||||
import android.arch.lifecycle.ViewModelProvider;
|
||||
import android.arch.lifecycle.ViewModelProviders;
|
||||
import android.arch.paging.PagedList;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cy.agorise.crystalwallet.R;
|
||||
import cy.agorise.crystalwallet.dao.CrystalDatabase;
|
||||
import cy.agorise.crystalwallet.models.AccountSeed;
|
||||
import cy.agorise.crystalwallet.models.CryptoCoinBalance;
|
||||
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
|
||||
import cy.agorise.crystalwallet.models.CryptoNetAccount;
|
||||
import cy.agorise.crystalwallet.randomdatagenerators.RandomCryptoCoinBalanceGenerator;
|
||||
import cy.agorise.crystalwallet.randomdatagenerators.RandomCryptoNetAccountGenerator;
|
||||
import cy.agorise.crystalwallet.randomdatagenerators.RandomSeedGenerator;
|
||||
import cy.agorise.crystalwallet.randomdatagenerators.RandomTransactionsGenerator;
|
||||
import cy.agorise.crystalwallet.application.CrystalSecurityMonitor;
|
||||
import cy.agorise.crystalwallet.viewmodels.AccountSeedListViewModel;
|
||||
import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel;
|
||||
import cy.agorise.crystalwallet.views.TransactionListView;
|
||||
|
||||
import static cy.agorise.crystalwallet.R.string.transactions;
|
||||
|
||||
public class IntroActivity extends AppCompatActivity {
|
||||
|
||||
TransactionListViewModel transactionListViewModel;
|
||||
|
@ -41,6 +21,9 @@ public class IntroActivity extends AppCompatActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_intro);
|
||||
|
||||
this.getApplication().registerActivityLifecycleCallbacks(new CrystalSecurityMonitor(this));
|
||||
|
||||
|
||||
//Checks if the user has any seed created
|
||||
AccountSeedListViewModel accountSeedListViewModel = ViewModelProviders.of(this).get(AccountSeedListViewModel.class);
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ import android.widget.Button;
|
|||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
@ -18,9 +20,17 @@ import butterknife.OnTextChanged;
|
|||
import cy.agorise.crystalwallet.R;
|
||||
import cy.agorise.crystalwallet.models.AccountSeed;
|
||||
import cy.agorise.crystalwallet.models.GeneralSetting;
|
||||
import cy.agorise.crystalwallet.util.PasswordManager;
|
||||
import cy.agorise.crystalwallet.viewmodels.AccountSeedViewModel;
|
||||
import cy.agorise.crystalwallet.viewmodels.GeneralSettingListViewModel;
|
||||
|
||||
public class PinRequestActivity extends AppCompatActivity {
|
||||
private String passwordEncrypted;
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
//Do nothing to prevent the user to use the back button
|
||||
}
|
||||
|
||||
@BindView(R.id.etPassword)
|
||||
EditText etPassword;
|
||||
|
@ -30,13 +40,35 @@ public class PinRequestActivity extends AppCompatActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_pin_request);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
GeneralSettingListViewModel generalSettingListViewModel = ViewModelProviders.of(this).get(GeneralSettingListViewModel.class);
|
||||
LiveData<List<GeneralSetting>> generalSettingsLiveData = generalSettingListViewModel.getGeneralSettingList();
|
||||
generalSettingsLiveData.observe(this, new Observer<List<GeneralSetting>>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable List<GeneralSetting> generalSettings) {
|
||||
passwordEncrypted = "";
|
||||
|
||||
if (generalSettings != null){
|
||||
for (GeneralSetting generalSetting:generalSettings) {
|
||||
if (generalSetting.getName().equals(GeneralSetting.SETTING_PASSWORD)){
|
||||
if (!generalSetting.getValue().isEmpty()){
|
||||
passwordEncrypted = generalSetting.getValue();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@OnTextChanged(value = R.id.etPassword,
|
||||
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
|
||||
void afterPasswordChanged(Editable editable) {
|
||||
if (PasswordManager.checkPassword(passwordEncrypted, etPassword.getText().toString())) {
|
||||
this.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,7 +26,5 @@ public class CrystalApplication extends Application {
|
|||
|
||||
Intent intent = new Intent(getApplicationContext(), CrystalWalletService.class);
|
||||
startService(intent);
|
||||
|
||||
registerActivityLifecycleCallbacks(new CrystalSecurityMonitor());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,63 @@
|
|||
package cy.agorise.crystalwallet.application;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import android.app.Application;
|
||||
import android.arch.lifecycle.LiveData;
|
||||
import android.arch.lifecycle.Observer;
|
||||
import android.arch.lifecycle.ViewModelProviders;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cy.agorise.crystalwallet.activities.CreateSeedActivity;
|
||||
import cy.agorise.crystalwallet.activities.PinRequestActivity;
|
||||
import cy.agorise.crystalwallet.models.GeneralSetting;
|
||||
import cy.agorise.crystalwallet.viewmodels.GeneralSettingListViewModel;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 27/1/2018.
|
||||
*/
|
||||
|
||||
class CrystalSecurityMonitor implements Application.ActivityLifecycleCallbacks {
|
||||
public class CrystalSecurityMonitor implements Application.ActivityLifecycleCallbacks {
|
||||
private int numStarted = 0;
|
||||
private String passwordEncrypted;
|
||||
|
||||
public CrystalSecurityMonitor(final FragmentActivity fragmentActivity){
|
||||
GeneralSettingListViewModel generalSettingListViewModel = ViewModelProviders.of(fragmentActivity).get(GeneralSettingListViewModel.class);
|
||||
LiveData<List<GeneralSetting>> generalSettingsLiveData = generalSettingListViewModel.getGeneralSettingList();
|
||||
|
||||
generalSettingsLiveData.observe(fragmentActivity, new Observer<List<GeneralSetting>>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable List<GeneralSetting> generalSettings) {
|
||||
boolean founded = false;
|
||||
passwordEncrypted = "";
|
||||
|
||||
if (generalSettings != null){
|
||||
for (GeneralSetting generalSetting:generalSettings) {
|
||||
if (generalSetting.getName().equals(GeneralSetting.SETTING_PASSWORD)){
|
||||
founded = true;
|
||||
if (!generalSetting.getValue().isEmpty()){
|
||||
passwordEncrypted = generalSetting.getValue();
|
||||
callPasswordRequest(fragmentActivity);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStarted(Activity activity) {
|
||||
if (numStarted == 0) {
|
||||
if ((this.passwordEncrypted != null) && (!this.passwordEncrypted.equals(""))) {
|
||||
callPasswordRequest(activity);
|
||||
}
|
||||
}
|
||||
numStarted++;
|
||||
}
|
||||
|
||||
|
@ -28,15 +65,17 @@ class CrystalSecurityMonitor implements Application.ActivityLifecycleCallbacks {
|
|||
public void onActivityStopped(Activity activity) {
|
||||
numStarted--;
|
||||
if (numStarted == 0) {
|
||||
if ((this.passwordEncrypted != null) && (!this.passwordEncrypted.equals(""))) {
|
||||
callPasswordRequest(activity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void callPasswordRequest(Activity activity){
|
||||
if ((!activity.getIntent().hasExtra("ACTIVITY_TYPE")) || (!activity.getIntent().getStringExtra("ACTIVITY_TYPE").equals("PASSWORD_REQUEST"))) {
|
||||
//Intent intent = new Intent(activity, PinRequestActivity.class);
|
||||
//intent.putExtra("ACTIVITY_TYPE", "PASSWORD_REQUEST");
|
||||
//activity.startActivity(intent);
|
||||
Intent intent = new Intent(activity, PinRequestActivity.class);
|
||||
intent.putExtra("ACTIVITY_TYPE", "PASSWORD_REQUEST");
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,11 @@
|
|||
android:padding="10dp"
|
||||
android:background="@color/colorPrimary"
|
||||
android:text="Enter Pin:"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etPassword"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="numberPassword" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
Loading…
Reference in a new issue