Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oppia-1310 - BuildConfig settings in App class removed #1305

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import androidx.work.testing.TestListenableWorkerBuilder;
import androidx.work.testing.WorkManagerTestInitHelper;

import org.digitalcampus.mobile.learning.BuildConfig;
import org.digitalcampus.mobile.learning.R;
import org.digitalcampus.oppia.application.App;
import org.digitalcampus.oppia.di.AppComponent;
Expand Down Expand Up @@ -117,7 +118,7 @@ public void doesNotshowNotificationIfNoUserIsLoggedIn() throws Exception {

when(user.getUsername()).thenReturn(null);

givenThereAreSomeCourses(App.DOWNLOAD_COURSES_DISPLAY - 1);
givenThereAreSomeCourses(BuildConfig.DOWNLOAD_COURSES_DISPLAY - 1);

coursesChecksWorkerManager.checkNoCoursesInstalled();

Expand All @@ -135,7 +136,7 @@ public void showsNotificationIfCoursesLessThanConfiguredParameter() throws Excep

when(user.getUsername()).thenReturn("test_user");

givenThereAreSomeCourses(App.DOWNLOAD_COURSES_DISPLAY - 1);
givenThereAreSomeCourses(BuildConfig.DOWNLOAD_COURSES_DISPLAY - 1);

coursesChecksWorkerManager.checkNoCoursesInstalled();

Expand All @@ -154,7 +155,7 @@ public void doesNotshowNotificationIfCoursesEqualThanConfiguredParameter() throw

when(user.getUsername()).thenReturn("test_user");

givenThereAreSomeCourses(App.DOWNLOAD_COURSES_DISPLAY);
givenThereAreSomeCourses(BuildConfig.DOWNLOAD_COURSES_DISPLAY);

coursesChecksWorkerManager.checkNoCoursesInstalled();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ public void onResume() {
registerReceiver(gamificationReceiver, broadcastFilter);

//We check if the user session time has expired to log him out
if (App.SESSION_EXPIRATION_ENABLED) {
if (BuildConfig.SESSION_EXPIRATION_ENABLED) {
SharedPreferences prefsReload = PreferenceManager.getDefaultSharedPreferences(this);
long now = System.currentTimeMillis() / 1000;
long lastTimeActive = prefsReload.getLong(PrefsActivity.LAST_ACTIVE_TIME, now);
long timePassed = now - lastTimeActive;

prefsReload.edit().putLong(PrefsActivity.LAST_ACTIVE_TIME, now).apply();
if (timePassed > App.SESSION_EXPIRATION_TIMEOUT) {
if (timePassed > BuildConfig.SESSION_EXPIRATION_TIMEOUT) {
Log.d(TAG, "Session timeout (passed " + timePassed + " seconds), logging out");
logoutAndRestartApp();
}
Expand All @@ -249,7 +249,7 @@ public void onResume() {
@Override
public void onPause() {
super.onPause();
if (App.SESSION_EXPIRATION_ENABLED) {
if (BuildConfig.SESSION_EXPIRATION_ENABLED) {
long now = System.currentTimeMillis() / 1000;
PreferenceManager
.getDefaultSharedPreferences(this).edit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public boolean onCreateOptionsMenu(Menu menu) {

// CONFIGURATIONS
private void configureUserOptions() {
boolean logoutVisible = getPrefs().getBoolean(PrefsActivity.PREF_LOGOUT_ENABLED, App.MENU_ALLOW_LOGOUT);
boolean logoutVisible = getPrefs().getBoolean(PrefsActivity.PREF_LOGOUT_ENABLED, BuildConfig.MENU_ALLOW_LOGOUT);
bindingHeader.btnLogout.setVisibility(logoutVisible ? View.VISIBLE : View.GONE);
if (!logoutVisible) {
setupProfileOptionsView(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.content.SharedPreferences;
import android.text.TextUtils;

import org.digitalcampus.mobile.learning.BuildConfig;
import org.digitalcampus.mobile.learning.R;
import org.digitalcampus.oppia.activity.PrefsActivity;
import org.digitalcampus.oppia.fragments.PasswordDialogFragment;
Expand Down Expand Up @@ -84,13 +85,13 @@ public boolean isActionProtected(int actionId) {
if(testForzeActionProtected()) return getTestActionProtectedValue();

switch (actionId){
case R.id.course_context_delete: return App.ADMIN_PROTECT_COURSE_DELETE;
case R.id.course_context_reset: return App.ADMIN_PROTECT_COURSE_RESET;
case R.id.course_context_update_activity: return App.ADMIN_PROTECT_COURSE_UPDATE;
case R.id.menu_download: return App.ADMIN_PROTECT_COURSE_INSTALL;
case R.id.menu_settings: return App.ADMIN_PROTECT_SETTINGS;
case R.id.menu_sync: return App.ADMIN_PROTECT_ACTIVITY_SYNC;
case R.id.action_export_activity: return App.ADMIN_PROTECT_ACTIVITY_EXPORT;
case R.id.course_context_delete: return BuildConfig.ADMIN_PROTECT_COURSE_DELETE;
case R.id.course_context_reset: return BuildConfig.ADMIN_PROTECT_COURSE_RESET;
case R.id.course_context_update_activity: return BuildConfig.ADMIN_PROTECT_COURSE_UPDATE;
case R.id.menu_download: return BuildConfig.ADMIN_PROTECT_COURSE_INSTALL;
case R.id.menu_settings: return BuildConfig.ADMIN_PROTECT_SETTINGS;
case R.id.menu_sync: return BuildConfig.ADMIN_PROTECT_ACTIVITY_SYNC;
case R.id.action_export_activity: return BuildConfig.ADMIN_PROTECT_ACTIVITY_EXPORT;

default: return false;
}
Expand All @@ -112,15 +113,15 @@ public boolean isPreferenceProtected(String preferenceKey) {

switch (preferenceKey){

case PrefsActivity.PREF_SERVER: return App.ADMIN_PROTECT_SERVER;
case PrefsActivity.PREF_ADVANCED_SCREEN: return App.ADMIN_PROTECT_ADVANCED_SETTINGS;
case PrefsActivity.PREF_SECURITY_SCREEN: return App.ADMIN_PROTECT_SECURITY_SETTINGS;
case PrefsActivity.PREF_SERVER: return BuildConfig.ADMIN_PROTECT_SERVER;
case PrefsActivity.PREF_ADVANCED_SCREEN: return BuildConfig.ADMIN_PROTECT_ADVANCED_SETTINGS;
case PrefsActivity.PREF_SECURITY_SCREEN: return BuildConfig.ADMIN_PROTECT_SECURITY_SETTINGS;

case PrefsActivity.PREF_DISABLE_NOTIFICATIONS: return App.ADMIN_PROTECT_NOTIFICATIONS;
case PrefsActivity.PREF_COURSES_REMINDER_ENABLED: return App.ADMIN_PROTECT_ENABLE_REMINDER_NOTIFICATIONS;
case PrefsActivity.PREF_COURSES_REMINDER_INTERVAL: return App.ADMIN_PROTECT_REMINDER_INTERVAL;
case PrefsActivity.PREF_COURSES_REMINDER_DAYS: return App.ADMIN_PROTECT_REMINDER_DAYS;
case PrefsActivity.PREF_COURSES_REMINDER_TIME: return App.ADMIN_PROTECT_REMINDER_TIME;
case PrefsActivity.PREF_DISABLE_NOTIFICATIONS: return BuildConfig.ADMIN_PROTECT_NOTIFICATIONS;
case PrefsActivity.PREF_COURSES_REMINDER_ENABLED: return BuildConfig.ADMIN_PROTECT_ENABLE_REMINDER_NOTIFICATIONS;
case PrefsActivity.PREF_COURSES_REMINDER_INTERVAL: return BuildConfig.ADMIN_PROTECT_REMINDER_INTERVAL;
case PrefsActivity.PREF_COURSES_REMINDER_DAYS: return BuildConfig.ADMIN_PROTECT_REMINDER_DAYS;
case PrefsActivity.PREF_COURSES_REMINDER_TIME: return BuildConfig.ADMIN_PROTECT_REMINDER_TIME;

default: return false;
}
Expand Down
57 changes: 11 additions & 46 deletions app/src/main/java/org/digitalcampus/oppia/application/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import android.util.Log;

import androidx.multidex.MultiDex;
import androidx.preference.PreferenceManager;
import androidx.room.Room;
import androidx.work.Constraints;
import androidx.work.ExistingPeriodicWorkPolicy;
import androidx.work.ExistingWorkPolicy;
import androidx.work.NetworkType;
import androidx.work.OneTimeWorkRequest;
import androidx.work.PeriodicWorkRequest;
import androidx.work.WorkManager;

import org.digitalcampus.mobile.learning.BuildConfig;
import org.digitalcampus.mobile.learning.R;
import org.digitalcampus.oppia.activity.PrefsActivity;
Expand All @@ -48,16 +58,6 @@
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import androidx.multidex.MultiDex;
import androidx.preference.PreferenceManager;
import androidx.room.Room;
import androidx.work.Constraints;
import androidx.work.ExistingPeriodicWorkPolicy;
import androidx.work.ExistingWorkPolicy;
import androidx.work.NetworkType;
import androidx.work.OneTimeWorkRequest;
import androidx.work.PeriodicWorkRequest;
import androidx.work.WorkManager;
import io.github.inflationx.calligraphy3.CalligraphyConfig;
import io.github.inflationx.calligraphy3.CalligraphyInterceptor;
import io.github.inflationx.viewpump.ViewPump;
Expand All @@ -71,34 +71,8 @@ public class App extends Application {
public static final String PRE_INSTALL_COURSES_DIR = "www/preload/courses"; // don't include leading or trailing slash
public static final String PRE_INSTALL_MEDIA_DIR = "www/preload/media"; // don't include leading or trailing slash

// admin security settings
public static final boolean ADMIN_PROTECT_SETTINGS = BuildConfig.ADMIN_PROTECT_SETTINGS;
public static final boolean ADMIN_PROTECT_ADVANCED_SETTINGS = BuildConfig.ADMIN_PROTECT_ADVANCED_SETTINGS;
public static final boolean ADMIN_PROTECT_SECURITY_SETTINGS = BuildConfig.ADMIN_PROTECT_SECURITY_SETTINGS;
public static final boolean ADMIN_PROTECT_SERVER = BuildConfig.ADMIN_PROTECT_SERVER;
public static final boolean ADMIN_PROTECT_COURSE_DELETE = BuildConfig.ADMIN_PROTECT_COURSE_DELETE;
public static final boolean ADMIN_PROTECT_COURSE_RESET = BuildConfig.ADMIN_PROTECT_COURSE_RESET;
public static final boolean ADMIN_PROTECT_COURSE_INSTALL = BuildConfig.ADMIN_PROTECT_COURSE_INSTALL;
public static final boolean ADMIN_PROTECT_COURSE_UPDATE = BuildConfig.ADMIN_PROTECT_COURSE_UPDATE;
public static final boolean ADMIN_PROTECT_ACTIVITY_SYNC = BuildConfig.ADMIN_PROTECT_ACTIVITY_SYNC;
public static final boolean ADMIN_PROTECT_ACTIVITY_EXPORT = BuildConfig.ADMIN_PROTECT_ACTIVITY_EXPORT;

public static final boolean ADMIN_PROTECT_NOTIFICATIONS = BuildConfig.ADMIN_PROTECT_NOTIFICATIONS;
public static final boolean ADMIN_PROTECT_ENABLE_REMINDER_NOTIFICATIONS = BuildConfig.ADMIN_PROTECT_ENABLE_REMINDER_NOTIFICATIONS;
public static final boolean ADMIN_PROTECT_REMINDER_INTERVAL = BuildConfig.ADMIN_PROTECT_REMINDER_INTERVAL;
public static final boolean ADMIN_PROTECT_REMINDER_DAYS = BuildConfig.ADMIN_PROTECT_REMINDER_DAYS;
public static final boolean ADMIN_PROTECT_REMINDER_TIME = BuildConfig.ADMIN_PROTECT_REMINDER_TIME;

// tracker metadata settings
public static final boolean METADATA_INCLUDE_NETWORK = BuildConfig.METADATA_INCLUDE_NETWORK;
public static final boolean METADATA_INCLUDE_APP_INSTANCE_ID = BuildConfig.METADATA_INCLUDE_APP_INSTANCE_ID;
public static final boolean METADATA_INCLUDE_MANUFACTURER_MODEL = BuildConfig.METADATA_INCLUDE_MANUFACTURER_MODEL;
public static final boolean METADATA_INCLUDE_WIFI_ON = BuildConfig.METADATA_INCLUDE_WIFI_ON;
public static final boolean METADATA_INCLUDE_NETWORK_CONNECTED = BuildConfig.METADATA_INCLUDE_NETWORK_CONNECTED;
public static final boolean METADATA_INCLUDE_BATTERY_LEVEL = BuildConfig.METADATA_INCLUDE_BATTERY_LEVEL;

// general other settings
public static final int DOWNLOAD_COURSES_DISPLAY = BuildConfig.DOWNLOAD_COURSES_DISPLAY; //this no of courses must be displayed for the 'download more courses' option to disappear
public static final int USERNAME_MIN_CHARACTERS = 4;
public static final int PASSWORD_MIN_LENGTH = 6;
public static final int PAGE_READ_TIME = 3;
Expand All @@ -115,15 +89,6 @@ public class App extends Application {
public static final boolean DEFAULT_DISPLAY_COMPLETED = true;
public static final boolean DEFAULT_DISPLAY_PROGRESS_BAR = true;

public static final boolean MENU_ALLOW_COURSE_DOWNLOAD = BuildConfig.MENU_ALLOW_COURSE_DOWNLOAD;
public static final boolean MENU_ALLOW_LANGUAGE = BuildConfig.MENU_ALLOW_LANGUAGE;
public static final boolean MENU_ALLOW_SETTINGS = BuildConfig.MENU_ALLOW_SETTINGS;
public static final boolean MENU_ALLOW_SYNC = BuildConfig.MENU_ALLOW_SYNC;
public static final boolean MENU_ALLOW_LOGOUT = BuildConfig.MENU_ALLOW_LOGOUT;

public static final boolean SESSION_EXPIRATION_ENABLED = BuildConfig.SESSION_EXPIRATION_ENABLED; // whether to force users to be logged out after inactivity
public static final int SESSION_EXPIRATION_TIMEOUT = BuildConfig.SESSION_EXPIRATION_TIMEOUT; // no seconds before user is logged out for inactivity

public static final int MAX_TRACKER_SUBMIT = 10;
public static final String[] SUPPORTED_MEDIA_TYPES = {"video/m4v", "video/mp4", "audio/mpeg", "video/3gp", "video/3gpp"}; //NOSONAR

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import org.digitalcampus.mobile.learning.BuildConfig;
import org.digitalcampus.mobile.learning.R;
import org.digitalcampus.mobile.learning.databinding.FragmentCoursesListBinding;
import org.digitalcampus.oppia.activity.CourseIndexActivity;
Expand Down Expand Up @@ -172,7 +173,7 @@ private void displayCourses() {
courses.addAll(coursesRepository.getCourses(getActivity()));
CourseUtils.refreshStatuses(prefs, courses, null);

if (courses.size() < App.DOWNLOAD_COURSES_DISPLAY) {
if (courses.size() < BuildConfig.DOWNLOAD_COURSES_DISPLAY) {
displayDownloadSection();
} else {
binding.manageCoursesText.setText(R.string.no_courses);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;

import org.digitalcampus.mobile.learning.BuildConfig;
import org.digitalcampus.mobile.learning.R;
import org.digitalcampus.oppia.activity.DownloadActivity;
import org.digitalcampus.oppia.activity.PrefsActivity;
Expand Down Expand Up @@ -113,7 +114,7 @@ public void checkNoCoursesInstalled() {
}

List<Course> courses = coursesRepository.getCourses(context);
if (courses.size() < App.DOWNLOAD_COURSES_DISPLAY) {
if (courses.size() < BuildConfig.DOWNLOAD_COURSES_DISPLAY) {

NotificationCompat.Builder mBuilder = OppiaNotificationUtils.getBaseBuilder(context, true);
mBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import androidx.preference.PreferenceManager;

import android.telephony.TelephonyManager;

import org.digitalcampus.mobile.learning.BuildConfig;
import org.digitalcampus.oppia.activity.PrefsActivity;
import org.digitalcampus.oppia.application.App;
import org.json.JSONException;
Expand Down Expand Up @@ -109,22 +111,22 @@ public JSONObject getMetaData(JSONObject json) throws JSONException {
json = new JSONObject();
}

if (prefs.getBoolean(getMetadataPref(PrefsActivity.PREF_METADATA_NETWORK), App.METADATA_INCLUDE_NETWORK)) {
if (prefs.getBoolean(getMetadataPref(PrefsActivity.PREF_METADATA_NETWORK), BuildConfig.METADATA_INCLUDE_NETWORK)) {
json.put("network", this.getNetworkProvider());
}
if (prefs.getBoolean(getMetadataPref(PrefsActivity.PREF_METADATA_APP_INSTANCE_ID), App.METADATA_INCLUDE_APP_INSTANCE_ID)) {
if (prefs.getBoolean(getMetadataPref(PrefsActivity.PREF_METADATA_APP_INSTANCE_ID), BuildConfig.METADATA_INCLUDE_APP_INSTANCE_ID)) {
json.put("appInstanceId", this.getAppInstanceId());
}
if (prefs.getBoolean(getMetadataPref(PrefsActivity.PREF_METADATA_MANUFACTURER_MODEL), App.METADATA_INCLUDE_MANUFACTURER_MODEL)) {
if (prefs.getBoolean(getMetadataPref(PrefsActivity.PREF_METADATA_MANUFACTURER_MODEL), BuildConfig.METADATA_INCLUDE_MANUFACTURER_MODEL)) {
json.put("manufacturermodel", this.getManufacturerModel());
}
if (prefs.getBoolean(getMetadataPref(PrefsActivity.PREF_METADATA_WIFI_ON), App.METADATA_INCLUDE_WIFI_ON)) {
if (prefs.getBoolean(getMetadataPref(PrefsActivity.PREF_METADATA_WIFI_ON), BuildConfig.METADATA_INCLUDE_WIFI_ON)) {
json.put("wifion", ConnectionUtils.isOnWifi(ctx));
}
if (prefs.getBoolean(getMetadataPref(PrefsActivity.PREF_METADATA_NETWORK_CONNECTED), App.METADATA_INCLUDE_NETWORK_CONNECTED)) {
if (prefs.getBoolean(getMetadataPref(PrefsActivity.PREF_METADATA_NETWORK_CONNECTED), BuildConfig.METADATA_INCLUDE_NETWORK_CONNECTED)) {
json.put("netconnected", ConnectionUtils.isNetworkConnected(ctx));
}
if (prefs.getBoolean(getMetadataPref(PrefsActivity.PREF_METADATA_BATTERY_LEVEL), App.METADATA_INCLUDE_BATTERY_LEVEL)) {
if (prefs.getBoolean(getMetadataPref(PrefsActivity.PREF_METADATA_BATTERY_LEVEL), BuildConfig.METADATA_INCLUDE_BATTERY_LEVEL)) {
json.put("battery", this.getBatteryLevel());
}
return json;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import com.google.android.material.navigation.NavigationView;

import org.digitalcampus.mobile.learning.BuildConfig;
import org.digitalcampus.mobile.learning.R;
import org.digitalcampus.oppia.activity.AboutActivity;
import org.digitalcampus.oppia.activity.ActivityLogActivity;
Expand Down Expand Up @@ -119,10 +120,11 @@ public void onPrepareOptionsMenu(Integer currentOption, Map<Integer, MenuOption>
}

SharedPreferences prefs = drawerAct.getPrefs();
itemSettings.setVisible(App.MENU_ALLOW_SETTINGS);
itemCourseDownload.setVisible(prefs.getBoolean(PrefsActivity.PREF_DOWNLOAD_ENABLED, App.MENU_ALLOW_COURSE_DOWNLOAD));
itemLanguageDialog.setVisible(customOptions.containsKey(R.id.menu_language) && prefs.getBoolean(PrefsActivity.PREF_CHANGE_LANGUAGE_ENABLED, App.MENU_ALLOW_LANGUAGE));
itemSync.setVisible(App.MENU_ALLOW_SYNC);
itemSettings.setVisible(BuildConfig.MENU_ALLOW_SETTINGS);
itemCourseDownload.setVisible(prefs.getBoolean(PrefsActivity.PREF_DOWNLOAD_ENABLED, BuildConfig.MENU_ALLOW_COURSE_DOWNLOAD));
itemLanguageDialog.setVisible(customOptions.containsKey(R.id.menu_language)
&& prefs.getBoolean(PrefsActivity.PREF_CHANGE_LANGUAGE_ENABLED, BuildConfig.MENU_ALLOW_LANGUAGE));
itemSync.setVisible(BuildConfig.MENU_ALLOW_SYNC);
}

public void onPostCreate() {
Expand Down
6 changes: 6 additions & 0 deletions oppia-default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ MENU_ALLOW_LOGOUT=true
MENU_ALLOW_EDIT_PROFILE=true
MENU_ALLOW_CHANGE_PASSWORD=true
MENU_ALLOW_LANGUAGE=true

# This no of courses must be displayed for the 'download more courses' option to disappear
DOWNLOAD_COURSES_DISPLAY=1

START_COURSEINDEX_COLLAPSED=false
Expand All @@ -86,7 +88,11 @@ METADATA_INCLUDE_BATTERY_LEVEL=true
######### Other functionalities ################
OFFLINE_REGISTER_ENABLED=true
DELETE_ACCOUNT_ENABLED=true

# Whether to force users to be logged out after inactivity
SESSION_EXPIRATION_ENABLED=false

# No seconds before user is logged out for inactivity
SESSION_EXPIRATION_TIMEOUT=600

SHOW_COURSE_DESCRIPTION=false
Expand Down