Skip to content

Commit

Permalink
app: introduce 1.1.6
Browse files Browse the repository at this point in the history
- UI improvements
- Ability to use SDCard
- Ability to share content
- Code cleanup
- Minor fixes & improvements
  • Loading branch information
verNANDo57 committed Aug 29, 2022
1 parent 20dd1d4 commit c7a3e94
Show file tree
Hide file tree
Showing 60 changed files with 843 additions and 189 deletions.
13 changes: 6 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "com.verNANDo57.rulebook_educational"
minSdkVersion 22
targetSdk 32
versionCode 115
versionName '1.1.5'
versionCode 116
versionName '1.1.6'
multiDexEnabled true
}

Expand Down Expand Up @@ -46,14 +46,13 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.preference:preference-ktx:1.2.0'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.21'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
}
repositories {
mavenCentral()
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,19 @@
android:fullBackupContent="true"
android:supportsRtl="true"
android:requestLegacyExternalStorage="true"
tools:targetApi="q"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|navigation">
tools:targetApi="s"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|navigation"
android:dataExtractionRules="@xml/data_extraction_rules">
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.verNANDo57.rulebook_educational.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths">
</meta-data>
</provider>
<activity
android:name="com.verNANDo57.rulebook_educational.SplashScreenActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|navigation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void onClick(DialogInterface dialog, int which) {
* android.permission.MANAGE_EXTERNAL_STORAGE
*/
public void checkPermission() {
//Check if android version is Android 11 or higher
// Check if android version is Android 11 or higher
if (Build.VERSION.SDK_INT >= 30) {
//Check if storage permission already granted
if (!Environment.isExternalStorageManager()) {
Expand All @@ -136,7 +136,7 @@ public void checkPermission() {
builder.setTitle(getString(R.string.app_warning));
builder.setMessage(getString(R.string.app_storageAccess_warning));
builder.setIcon(R.drawable.ic_warning);
builder.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener(){
builder.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//GoToSettings Intent
Expand All @@ -154,7 +154,7 @@ public void onClick(DialogInterface dialog, int which) {
alert.show();
}
//Otherwise...
//Check if android version is Android 10 or lower
// Check if android version is Android 10 or lower
} else if (Build.VERSION.SDK_INT >= 23) {
//Check if storage permission already granted
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
Expand Down Expand Up @@ -208,4 +208,4 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Author: VerNANDo57 <[email protected]>
*/

package com.verNANDo57.rulebook_educational.app;

import android.content.Intent;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCaller;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContract;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class CustomActivityResult<Input, Result> {
/**
* Register activity result using a {@link ActivityResultContract} and an in-place activity result callback like
* the default approach. You can still customise callback using {@link #launch(Object, OnActivityResult)}.
*/
@NonNull
public static <Input, Result> CustomActivityResult<Input, Result> registerForActivityResult(
@NonNull ActivityResultCaller caller,
@NonNull ActivityResultContract<Input, Result> contract,
@Nullable OnActivityResult<Result> onActivityResult) {
return new CustomActivityResult<>(caller, contract, onActivityResult);
}

/**
* Same as {@link #registerForActivityResult(ActivityResultCaller, ActivityResultContract, OnActivityResult)} except
* the last argument is set to {@code null}.
*/
@NonNull
public static <Input, Result> CustomActivityResult<Input, Result> registerForActivityResult(
@NonNull ActivityResultCaller caller,
@NonNull ActivityResultContract<Input, Result> contract) {
return registerForActivityResult(caller, contract, null);
}

/**
* Specialised method for launching new activities.
*/
@NonNull
public static CustomActivityResult<Intent, ActivityResult> registerActivityForResult(
@NonNull ActivityResultCaller caller) {
return registerForActivityResult(caller, new ActivityResultContracts.StartActivityForResult());
}

/**
* Callback interface
*/
public interface OnActivityResult<O> {
/**
* Called after receiving a result from the target activity
*/
void onActivityResult(O result);
}

private final ActivityResultLauncher<Input> launcher;
@Nullable
private OnActivityResult<Result> onActivityResult;

private CustomActivityResult(@NonNull ActivityResultCaller caller,
@NonNull ActivityResultContract<Input, Result> contract,
@Nullable OnActivityResult<Result> onActivityResult) {
this.onActivityResult = onActivityResult;
this.launcher = caller.registerForActivityResult(contract, this::callOnActivityResult);
}

public void setOnActivityResult(@Nullable OnActivityResult<Result> onActivityResult) {
this.onActivityResult = onActivityResult;
}

/**
* Launch activity, same as {@link ActivityResultLauncher#launch(Object)} except that it allows a callback
* executed after receiving a result from the target activity.
*/
public void launch(Input input, @Nullable OnActivityResult<Result> onActivityResult) {
if (onActivityResult != null) {
this.onActivityResult = onActivityResult;
}
launcher.launch(input);
}

/**
* Same as {@link #launch(Object, OnActivityResult)} with last parameter set to {@code null}.
*/
public void launch(Input input) {
launch(input, this.onActivityResult);
}

private void callOnActivityResult(Result result) {
if (onActivityResult != null) onActivityResult.onActivityResult(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,4 @@ public static void undoBookmarkDeletion(Context context) {
Log.e(LOG_TAG, context.getResources().getString(R.string.app_error_file_rename));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,37 @@
import android.content.DialogInterface;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.ContextCompat;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreferenceCompat;

import com.verNANDo57.rulebook_educational.extradata.R;
import com.verNANDo57.rulebook_educational.rules.Constants;
import com.verNANDo57.rulebook_educational.utils.AppUtils;

import java.io.File;

public class AppSettingsFragment extends PreferenceFragmentCompat
{
RulebookApplicationSharedPreferences preferences;
private RulebookApplicationSharedPreferences preferences;

public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
preferences = new RulebookApplicationSharedPreferences(requireContext());
setPreferencesFromResource(R.xml.preferences, rootKey);

//Interface
androidx.preference.Preference darktheme_switch = findPreference(PreferenceKeys.DARK_THEME_PREF);
assert darktheme_switch != null;
darktheme_switch.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
// Interface
androidx.preference.Preference darktheme_switch_pref = findPreference(PreferenceKeys.DARK_THEME_PREF);
assert darktheme_switch_pref != null;
darktheme_switch_pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
public boolean onPreferenceClick(@NonNull Preference preference) {
// setup the alert builder
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
builder.setTitle(getString(R.string.app_darkTheme_switch_summary));
// add a list
String[] options = {
getString(R.string.app_darkTheme_mode_no),
getString(R.string.app_darkTheme_mode_yes),
getString(R.string.app_darkTheme_mode_followSystem),
getString(R.string.app_darkTheme_mode_battery)};

int checkedItem = 0; // Dark mode: NO
if (preferences.loadRulebookDarkModeBooleanState() == AppCompatDelegate.MODE_NIGHT_YES) {
Expand All @@ -50,7 +49,7 @@ public boolean onPreferenceClick(Preference preference) {
}

//Pass the array list in Alert dialog
builder.setSingleChoiceItems(options, checkedItem, new DialogInterface.OnClickListener() {
builder.setSingleChoiceItems(getResources().getStringArray(R.array.darkmode_modes), checkedItem, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
Expand Down Expand Up @@ -86,25 +85,65 @@ public void onClick(DialogInterface dialogInterface, int i) {
builder.setIcon(AppCompatResources.getDrawable(requireContext(), R.drawable.app_themeengine_icon));
builder.create();
builder.show();
return true;
return false;
}
});

androidx.preference.SwitchPreferenceCompat statusbar_enable = (SwitchPreferenceCompat) findPreference(PreferenceKeys.STATUSBAR_PREF);
assert statusbar_enable != null;
statusbar_enable.setChecked(preferences.loadRulebookStatusBarBooleanState());
statusbar_enable.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
androidx.preference.SwitchPreferenceCompat statusbar_enable_pref = findPreference(PreferenceKeys.STATUSBAR_PREF);
assert statusbar_enable_pref != null;
statusbar_enable_pref.setChecked(preferences.loadRulebookStatusBarBooleanState());
statusbar_enable_pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue.toString().equals("true")){
preferences.setRulebookStatusBarBooleanState(true);
} else {
preferences.setRulebookStatusBarBooleanState(false);
}
return true;
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
preferences.setRulebookStatusBarBooleanState(newValue.toString().equals("true"));
return false;
}
});

androidx.preference.Preference noticePreference = findPreference(PreferenceKeys.NOTICE_PREF);
// Functionality
androidx.preference.SwitchPreferenceCompat use_sdcard_pref = findPreference(PreferenceKeys.USE_SDCARD_PREF);
assert use_sdcard_pref != null;
if (!AppUtils.checkIfSDCardExists()) {
use_sdcard_pref.setEnabled(false);
preferences.setRulebookUseSDCardBooleanState(false);
}
use_sdcard_pref.setChecked(preferences.loadRulebookUseSDCardBooleanState());
use_sdcard_pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
preferences.setRulebookUseSDCardBooleanState(newValue.toString().equals("true"));
return false;
}
});

androidx.preference.Preference delete_all_data = findPreference(PreferenceKeys.DELETE_ALL_DATA);
assert delete_all_data != null;
delete_all_data.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(@NonNull Preference preference) {
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(requireContext());
builder.setTitle(getString(R.string.app_warning));
builder.setIcon(ContextCompat.getDrawable(requireContext(), R.drawable.app_delete_forever));
builder.setMessage(getString(R.string.are_you_sure));
builder.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AppUtils.removeFolderRecursive(new File(AppUtils.getStorageAbsolutePath(requireContext(), false) + Constants.RULEBOOK_APP_DIRECTORY));
if (AppUtils.checkIfSDCardExists()) {
AppUtils.removeFolderRecursive(new File(AppUtils.getStorageAbsolutePath(requireContext(), true) + Constants.RULEBOOK_APP_DIRECTORY));
}
}
});
builder.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
androidx.appcompat.app.AlertDialog alert = builder.create();
alert.show();
return false;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
package com.verNANDo57.rulebook_educational.preferences;

public interface PreferenceKeys {
String DARK_THEME_PREF = "darktheme_switch";
String STATUSBAR_PREF = "statusbar_enable";
String NOTICE_PREF = "app_reboot_from_prefs";
String DARK_THEME_PREF = "darktheme_switch_pref";
String STATUSBAR_PREF = "statusbar_enable_pref";
String NOTICE_PREF = "notice_pref";
String USE_SDCARD_PREF = "use_sdcard_pref";
String DELETE_ALL_DATA = "delete_all_data";
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
import androidx.appcompat.app.AppCompatDelegate;

public class RulebookApplicationSharedPreferences {
SharedPreferences RulebookSharedPreferences;
private final SharedPreferences RulebookSharedPreferences;

public static String PREFS_FILE_NAME = "rulebookprefs";
public static String DARK_MODE = "dark_mode";
public static String STATUS_BAR_STATE_BOOLEAN = "status_bar";
public static String RULEBOOK_LAUNCHED_FOR_THE_FIRST_TIME_STATE_BOOLEAN = "launched_for_the_first_time";
private static final String PREFS_FILE_NAME = "rulebookprefs";
private static final String DARK_MODE = "dark_mode";
private static final String STATUS_BAR_STATE_BOOLEAN = "status_bar";
private static final String RULEBOOK_LAUNCHED_FOR_THE_FIRST_TIME_STATE_BOOLEAN = "launched_for_the_first_time";
private static final String USE_SDCARD = "use_sdcard";

public RulebookApplicationSharedPreferences(Context context) {
RulebookSharedPreferences = context.getSharedPreferences(PREFS_FILE_NAME, Context.MODE_PRIVATE);
Expand All @@ -37,6 +38,11 @@ public void setRulebookIsLaunchedForTheFirstTimeBooleanState(Boolean state){
editor.putBoolean(RULEBOOK_LAUNCHED_FOR_THE_FIRST_TIME_STATE_BOOLEAN, state);
editor.apply();
}
public void setRulebookUseSDCardBooleanState(Boolean state){
SharedPreferences.Editor editor= RulebookSharedPreferences.edit();
editor.putBoolean(USE_SDCARD, state);
editor.apply();
}

//These methods will load
public int loadRulebookDarkModeBooleanState (){
Expand All @@ -48,4 +54,7 @@ public Boolean loadRulebookStatusBarBooleanState (){
public Boolean loadRulebookIsLaunchedForTheFirstTimeBooleanState (){
return RulebookSharedPreferences.getBoolean(RULEBOOK_LAUNCHED_FOR_THE_FIRST_TIME_STATE_BOOLEAN, true);
}
public Boolean loadRulebookUseSDCardBooleanState (){
return RulebookSharedPreferences.getBoolean(USE_SDCARD, false);
}
}
Loading

0 comments on commit c7a3e94

Please sign in to comment.