Search in sources :

Example 1 with DiaryServiceImpl

use of cn.snowt.diary.service.impl.DiaryServiceImpl in project Diary by HibaraAi.

the class LoginActivity method doWhenFirstLogin.

/**
 * 由于第一次使用本程序需要跳转设置登录密码,所以此Activity有逻辑代码
 */
private void doWhenFirstLogin() {
    SharedPreferences sharedPreferences = BaseUtils.getSharedPreference();
    boolean firstUse = sharedPreferences.getBoolean("firstUse", true);
    if (firstUse) {
        // 第一次使用本程序
        // 创建数据库
        LitePal.getDatabase();
        new Thread(new Runnable() {

            @Override
            public void run() {
                // 写入帮助日记
                try {
                    new DiaryServiceImpl().addHelpDiary();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        // 申请存储权限
        applyPermission();
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) DiaryServiceImpl(cn.snowt.diary.service.impl.DiaryServiceImpl)

Example 2 with DiaryServiceImpl

use of cn.snowt.diary.service.impl.DiaryServiceImpl in project Diary by HibaraAi.

the class RecoveryDiaryActivity method findViewAndSetListener.

private void findViewAndSetListener() {
    setSupportActionBar(findViewById(R.id.default_toolbar_inc));
    ActionBar supportActionBar = getSupportActionBar();
    if (null != supportActionBar) {
        supportActionBar.setDisplayHomeAsUpEnabled(true);
        supportActionBar.setTitle("恢复日记");
    }
    loadBackupBtn = findViewById(R.id.re_diary_btn_load_backup);
    loadKeyBtn = findViewById(R.id.re_diary_btn_load_key);
    saveBtn = findViewById(R.id.re_diary_btn_save);
    tipView = findViewById(R.id.re_diary_tip);
    pinKeyView = findViewById(R.id.re_diary_pin);
    loadBackupBtn.setOnClickListener(v -> {
        OpenFile(SELECT_BACKUP_FILE);
        BaseUtils.longTipInCoast(RecoveryDiaryActivity.this, "请选择备份文件");
    });
    loadKeyBtn.setOnClickListener(v -> {
        OpenFile(SELECT_KEY_FILE);
        BaseUtils.longTipInCoast(this, "请选择密钥文件");
    });
    saveBtn.setOnClickListener(v -> {
        String pinKey = pinKeyView.getText().toString();
        if ("".equals(pinKey)) {
            BaseUtils.shortTipInSnack(saveBtn, "没有输入口令,怎么验证? ORz");
        } else {
            // 校验口令
            String pinInMap = (String) map.get(Constant.BACKUP_ARGS_NAME_PIN_KEY);
            boolean isBadPin = (pinInMap == null || !pinInMap.equals(MD5Utils.encrypt(Constant.PASSWORD_PREFIX + pinKey)));
            if (isBadPin) {
                String tipStr = "你提供的口令是错误的呢";
                BaseUtils.shortTipInSnack(tipView, "你提供的口令是错误的呢 QaQ");
                tipView.setText(tipStr);
            } else {
                BaseUtils.longTipInCoast(this, "后台已经在执行恢复日记的后续操作,执行结果将在通知栏告知你");
                new Thread(() -> {
                    DiaryService diaryService = new DiaryServiceImpl();
                    SimpleResult result = diaryService.recoveryDiary(pinKey, privateKey, map);
                    BaseUtils.longTextSysNotice(RecoveryDiaryActivity.this, result.getMsg());
                }).start();
                this.finish();
            }
        }
    });
}
Also used : DiaryService(cn.snowt.diary.service.DiaryService) DiaryServiceImpl(cn.snowt.diary.service.impl.DiaryServiceImpl) SimpleResult(cn.snowt.diary.util.SimpleResult) ActionBar(androidx.appcompat.app.ActionBar)

Aggregations

DiaryServiceImpl (cn.snowt.diary.service.impl.DiaryServiceImpl)2 SharedPreferences (android.content.SharedPreferences)1 ActionBar (androidx.appcompat.app.ActionBar)1 DiaryService (cn.snowt.diary.service.DiaryService)1 SimpleResult (cn.snowt.diary.util.SimpleResult)1