2020-04-26 15:36:33 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
2021-03-09 22:15:42 +01:00
|
|
|
import android.app.KeyguardManager;
|
2020-04-26 15:36:33 +02:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2021-03-09 22:15:42 +01:00
|
|
|
import android.os.Build;
|
2020-04-26 15:36:33 +02:00
|
|
|
import android.os.Bundle;
|
2020-05-09 16:50:45 +02:00
|
|
|
import android.util.Log;
|
2020-04-26 15:36:33 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
2020-05-09 16:50:45 +02:00
|
|
|
import android.widget.TextView;
|
2020-04-26 15:36:33 +02:00
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2021-03-09 22:15:42 +01:00
|
|
|
import androidx.biometric.BiometricManager;
|
|
|
|
import com.google.android.material.switchmaterial.SwitchMaterial;
|
2020-05-09 16:50:45 +02:00
|
|
|
import org.apache.commons.io.FileUtils;
|
2020-04-26 15:36:33 +02:00
|
|
|
import org.mian.gitnex.R;
|
2021-01-26 16:10:31 +01:00
|
|
|
import org.mian.gitnex.databinding.ActivitySettingsSecurityBinding;
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
2020-05-09 16:50:45 +02:00
|
|
|
import org.mian.gitnex.helpers.Toasty;
|
2020-04-26 15:36:33 +02:00
|
|
|
import org.mian.gitnex.helpers.ssl.MemorizingTrustManager;
|
2020-05-09 16:50:45 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2021-03-09 22:15:42 +01:00
|
|
|
import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
|
|
|
|
import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
|
2020-04-26 15:36:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class SettingsSecurityActivity extends BaseActivity {
|
|
|
|
|
|
|
|
private View.OnClickListener onClickListener;
|
|
|
|
|
2021-06-10 18:03:52 +02:00
|
|
|
private static String[] cacheSizeDataList;
|
2020-05-09 16:50:45 +02:00
|
|
|
private static int cacheSizeDataSelectedChoice = 0;
|
|
|
|
|
2021-06-10 18:03:52 +02:00
|
|
|
private static String[] cacheSizeImagesList;
|
2020-05-09 16:50:45 +02:00
|
|
|
private static int cacheSizeImagesSelectedChoice = 0;
|
|
|
|
|
2020-04-26 15:36:33 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
2020-04-28 15:47:25 +02:00
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
ActivitySettingsSecurityBinding activitySettingsSecurityBinding = ActivitySettingsSecurityBinding.inflate(getLayoutInflater());
|
2021-01-26 18:43:25 +01:00
|
|
|
setContentView(activitySettingsSecurityBinding.getRoot());
|
2021-01-26 16:10:31 +01:00
|
|
|
|
|
|
|
ImageView closeActivity = activitySettingsSecurityBinding.close;
|
2020-04-26 15:36:33 +02:00
|
|
|
|
|
|
|
initCloseListener();
|
|
|
|
closeActivity.setOnClickListener(onClickListener);
|
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
TextView cacheSizeDataSelected = activitySettingsSecurityBinding.cacheSizeDataSelected; // setter for data cache size
|
|
|
|
TextView cacheSizeImagesSelected = activitySettingsSecurityBinding.cacheSizeImagesSelected; // setter for images cache size
|
|
|
|
TextView clearCacheSelected = activitySettingsSecurityBinding.clearCacheSelected; // setter for clear cache
|
2020-05-09 16:50:45 +02:00
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
LinearLayout certsFrame = activitySettingsSecurityBinding.certsFrame;
|
|
|
|
LinearLayout cacheSizeDataFrame = activitySettingsSecurityBinding.cacheSizeDataSelectionFrame;
|
|
|
|
LinearLayout cacheSizeImagesFrame = activitySettingsSecurityBinding.cacheSizeImagesSelectionFrame;
|
|
|
|
LinearLayout clearCacheFrame = activitySettingsSecurityBinding.clearCacheSelectionFrame;
|
2020-05-09 16:50:45 +02:00
|
|
|
|
2021-03-09 22:15:42 +01:00
|
|
|
SwitchMaterial switchBiometric = activitySettingsSecurityBinding.switchBiometric;
|
|
|
|
|
2021-06-10 18:03:52 +02:00
|
|
|
cacheSizeDataList = getResources().getStringArray(R.array.cacheSizeList);
|
|
|
|
cacheSizeImagesList = getResources().getStringArray(R.array.cacheSizeList);
|
|
|
|
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
cacheSizeDataSelected.setText(tinyDB.getString("cacheSizeStr", getString(R.string.cacheSizeDataSelectionSelectedText)));
|
|
|
|
cacheSizeImagesSelected.setText(tinyDB.getString("cacheSizeImagesStr", getString(R.string.cacheSizeImagesSelectionSelectedText)));
|
2020-05-09 16:50:45 +02:00
|
|
|
|
|
|
|
if(cacheSizeDataSelectedChoice == 0) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
cacheSizeDataSelectedChoice = tinyDB.getInt("cacheSizeId");
|
2020-05-09 16:50:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(cacheSizeImagesSelectedChoice == 0) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
cacheSizeImagesSelectedChoice = tinyDB.getInt("cacheSizeImagesId");
|
2020-05-09 16:50:45 +02:00
|
|
|
}
|
|
|
|
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
switchBiometric.setChecked(tinyDB.getBoolean("biometricStatus", false));
|
2021-03-09 22:15:42 +01:00
|
|
|
|
|
|
|
// biometric switcher
|
|
|
|
switchBiometric.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
|
|
|
|
|
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
|
|
|
|
if(isChecked) {
|
|
|
|
|
|
|
|
BiometricManager biometricManager = BiometricManager.from(ctx);
|
|
|
|
KeyguardManager keyguardManager = (KeyguardManager) ctx.getSystemService(Context.KEYGUARD_SERVICE);
|
|
|
|
|
|
|
|
if (!keyguardManager.isDeviceSecure()) {
|
|
|
|
|
|
|
|
switch(biometricManager.canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL)) {
|
|
|
|
|
|
|
|
case BiometricManager.BIOMETRIC_SUCCESS:
|
|
|
|
|
|
|
|
tinyDB.putBoolean("biometricStatus", true);
|
|
|
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
|
|
break;
|
|
|
|
case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
|
|
|
|
case BiometricManager.BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED:
|
|
|
|
case BiometricManager.BIOMETRIC_ERROR_UNSUPPORTED:
|
|
|
|
case BiometricManager.BIOMETRIC_STATUS_UNKNOWN:
|
|
|
|
|
|
|
|
tinyDB.putBoolean("biometricStatus", false);
|
|
|
|
switchBiometric.setChecked(false);
|
|
|
|
Toasty.error(appCtx, getResources().getString(R.string.biometricNotSupported));
|
|
|
|
break;
|
|
|
|
case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
|
|
|
|
|
|
|
|
tinyDB.putBoolean("biometricStatus", false);
|
|
|
|
switchBiometric.setChecked(false);
|
|
|
|
Toasty.error(appCtx, getResources().getString(R.string.biometricNotAvailable));
|
|
|
|
break;
|
|
|
|
case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
|
|
|
|
|
|
|
|
tinyDB.putBoolean("biometricStatus", false);
|
|
|
|
switchBiometric.setChecked(false);
|
|
|
|
Toasty.info(appCtx, getResources().getString(R.string.enrollBiometric));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
tinyDB.putBoolean("biometricStatus", true);
|
|
|
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
tinyDB.putBoolean("biometricStatus", false);
|
|
|
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
tinyDB.putBoolean("biometricStatus", false);
|
2022-03-18 09:56:49 +01:00
|
|
|
Toasty.warning(appCtx, getResources().getString(R.string.biometricNotSupported));
|
2021-03-09 22:15:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2021-12-17 20:56:12 +01:00
|
|
|
activitySettingsSecurityBinding.biometricFrame.setOnClickListener(v -> switchBiometric.setChecked(!switchBiometric.isChecked()));
|
|
|
|
|
2020-05-09 16:50:45 +02:00
|
|
|
// clear cache setter
|
|
|
|
File cacheDir = appCtx.getCacheDir();
|
2020-10-12 20:11:23 +02:00
|
|
|
clearCacheSelected.setText(FileUtils.byteCountToDisplaySize((int) FileUtils.sizeOfDirectory(cacheDir)));
|
2020-05-09 16:50:45 +02:00
|
|
|
|
|
|
|
// clear cache
|
|
|
|
clearCacheFrame.setOnClickListener(v1 -> {
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(SettingsSecurityActivity.this);
|
|
|
|
|
|
|
|
builder.setTitle(getResources().getString(R.string.clearCacheDialogHeader));
|
|
|
|
builder.setMessage(getResources().getString(R.string.clearCacheDialogMessage));
|
|
|
|
builder.setPositiveButton(R.string.menuDeleteText, (dialog, which) -> {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
FileUtils.deleteDirectory(cacheDir);
|
2022-03-27 20:41:20 +02:00
|
|
|
FileUtils.forceMkdir(cacheDir);
|
2020-05-09 16:50:45 +02:00
|
|
|
this.recreate();
|
|
|
|
this.overridePendingTransition(0, 0);
|
|
|
|
}
|
|
|
|
catch (IOException e) {
|
|
|
|
|
|
|
|
Log.e("SettingsSecurity", e.toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
builder.setNeutralButton(R.string.cancelButton, (dialog, which) -> dialog.dismiss());
|
|
|
|
builder.create().show();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// cache size images selection dialog
|
|
|
|
cacheSizeImagesFrame.setOnClickListener(view -> {
|
|
|
|
|
|
|
|
AlertDialog.Builder tsBuilder = new AlertDialog.Builder(SettingsSecurityActivity.this);
|
|
|
|
|
|
|
|
tsBuilder.setTitle(getResources().getString(R.string.cacheSizeImagesDialogHeader));
|
2020-10-29 14:13:19 +01:00
|
|
|
tsBuilder.setCancelable(cacheSizeImagesSelectedChoice != -1);
|
2020-05-09 16:50:45 +02:00
|
|
|
|
|
|
|
tsBuilder.setSingleChoiceItems(cacheSizeImagesList, cacheSizeImagesSelectedChoice, (dialogInterfaceTheme, i) -> {
|
|
|
|
|
|
|
|
cacheSizeImagesSelectedChoice = i;
|
|
|
|
cacheSizeImagesSelected.setText(cacheSizeImagesList[i]);
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("cacheSizeImagesStr", cacheSizeImagesList[i]);
|
|
|
|
tinyDB.putInt("cacheSizeImagesId", i);
|
2020-05-09 16:50:45 +02:00
|
|
|
|
|
|
|
dialogInterfaceTheme.dismiss();
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
2020-05-09 16:50:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
AlertDialog cfDialog = tsBuilder.create();
|
|
|
|
cfDialog.show();
|
|
|
|
});
|
|
|
|
|
|
|
|
// cache size data selection dialog
|
|
|
|
cacheSizeDataFrame.setOnClickListener(view -> {
|
|
|
|
|
|
|
|
AlertDialog.Builder tsBuilder = new AlertDialog.Builder(SettingsSecurityActivity.this);
|
|
|
|
|
|
|
|
tsBuilder.setTitle(getResources().getString(R.string.cacheSizeDataDialogHeader));
|
2020-10-29 14:13:19 +01:00
|
|
|
tsBuilder.setCancelable(cacheSizeDataSelectedChoice != -1);
|
2020-05-09 16:50:45 +02:00
|
|
|
|
|
|
|
tsBuilder.setSingleChoiceItems(cacheSizeDataList, cacheSizeDataSelectedChoice, (dialogInterfaceTheme, i) -> {
|
|
|
|
|
|
|
|
cacheSizeDataSelectedChoice = i;
|
|
|
|
cacheSizeDataSelected.setText(cacheSizeDataList[i]);
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("cacheSizeStr", cacheSizeDataList[i]);
|
|
|
|
tinyDB.putInt("cacheSizeId", i);
|
2020-05-09 16:50:45 +02:00
|
|
|
|
|
|
|
dialogInterfaceTheme.dismiss();
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
2020-05-09 16:50:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
AlertDialog cfDialog = tsBuilder.create();
|
|
|
|
cfDialog.show();
|
|
|
|
});
|
2020-04-26 15:36:33 +02:00
|
|
|
|
|
|
|
// certs deletion
|
|
|
|
certsFrame.setOnClickListener(v1 -> {
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(SettingsSecurityActivity.this);
|
|
|
|
|
|
|
|
builder.setTitle(getResources().getString(R.string.settingsCertsPopupTitle));
|
|
|
|
builder.setMessage(getResources().getString(R.string.settingsCertsPopupMessage));
|
|
|
|
builder.setPositiveButton(R.string.menuDeleteText, (dialog, which) -> {
|
|
|
|
|
2020-04-28 15:47:25 +02:00
|
|
|
appCtx.getSharedPreferences(MemorizingTrustManager.KEYSTORE_NAME, Context.MODE_PRIVATE).edit().remove(MemorizingTrustManager.KEYSTORE_KEY).apply();
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
AppUtil.logout(this);
|
2020-04-26 15:36:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
builder.setNeutralButton(R.string.cancelButton, (dialog, which) -> dialog.dismiss());
|
|
|
|
builder.create().show();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initCloseListener() {
|
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
onClickListener = view -> finish();
|
|
|
|
}
|
2020-04-26 15:36:33 +02:00
|
|
|
}
|