Skip to content

Commit

Permalink
Replace git.enabled with a preference
Browse files Browse the repository at this point in the history
Added for #24 under Settings / App / Developer options.
  • Loading branch information
nevenz committed Nov 20, 2021
1 parent 4f676c6 commit 7c5ccf6
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 9 deletions.
2 changes: 0 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ android {
buildConfigField "String", "DROPBOX_APP_KEY", gradle.ext.appProperties.getProperty("dropbox.app_key", '""')
resValue "string", "dropbox_app_key_schema", gradle.ext.appProperties.getProperty("dropbox.app_key_schema", '')

buildConfigField "boolean", "IS_GIT_ENABLED", gradle.ext.appProperties.getProperty("git.enabled", 'false')

javaCompileOptions {
annotationProcessorOptions {
arguments = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,12 @@ public static void dropboxToken(Context context, String value) {
* Git Sync
*/

public static boolean gitIsEnabled(Context context) {
return getDefaultSharedPreferences(context).getBoolean(
context.getResources().getString(R.string.pref_key_git_is_enabled),
context.getResources().getBoolean(R.bool.pref_default_git_is_enabled));
}

public static String gitAuthor(Context context) {
return getStateSharedPreferences(context).getString("pref_key_git_author", null);
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/orgzly/android/repos/RepoFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.orgzly.android.repos
import android.content.Context
import com.orgzly.BuildConfig
import com.orgzly.android.data.DbRepoBookRepository
import com.orgzly.android.prefs.AppPreferences
import javax.inject.Inject
import javax.inject.Singleton

Expand Down Expand Up @@ -30,7 +31,7 @@ class RepoFactory @Inject constructor(
type == RepoType.WEBDAV.id ->
WebdavRepo.getInstance(repoWithProps)

type == RepoType.GIT.id && BuildConfig.IS_GIT_ENABLED ->
type == RepoType.GIT.id && AppPreferences.gitIsEnabled(context) ->
GitRepo.getInstance(repoWithProps, context)

else ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.orgzly.BuildConfig
import com.orgzly.R
import com.orgzly.android.App
import com.orgzly.android.db.entity.Repo
import com.orgzly.android.prefs.AppPreferences
import com.orgzly.android.repos.RepoFactory
import com.orgzly.android.repos.RepoType
import com.orgzly.android.ui.CommonActivity
Expand Down Expand Up @@ -107,7 +108,7 @@ class ReposActivity : CommonActivity(), AdapterView.OnItemClickListener, Activit
}

binding.activityReposGit.let { button ->
if (BuildConfig.IS_GIT_ENABLED) {
if (AppPreferences.gitIsEnabled(this)) {
button.setOnClickListener {
startRepoActivity(R.id.repos_options_menu_item_new_git)
}
Expand Down Expand Up @@ -157,7 +158,7 @@ class ReposActivity : CommonActivity(), AdapterView.OnItemClickListener, Activit
newRepos.removeItem(R.id.repos_options_menu_item_new_dropbox)
}

if (!BuildConfig.IS_GIT_ENABLED) {
if (!AppPreferences.gitIsEnabled(App.getAppContext())) {
newRepos.removeItem(R.id.repos_options_menu_item_new_git)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ class SettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedP
"prefs_screen_org_file_format" to R.xml.prefs_screen_org_file_format, // Sub-screen
"prefs_screen_org_mode_tags_indent" to R.xml.prefs_screen_org_mode_tags_indent, // Sub-screen
"prefs_screen_widget" to R.xml.prefs_screen_widget, // Sub-screen
"prefs_screen_developer" to R.xml.prefs_screen_developer, // Sub-screen
"prefs_screen_app" to R.xml.prefs_screen_app
)

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/prefs_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@
<bool name="pref_default_widget_display_book_name" translatable="false">false</bool>

<!-- Git preferences -->
<string name="pref_key_git_is_enabled" translatable="false">pref_key_git_is_enabled</string>
<bool name="pref_default_git_is_enabled" translatable="false">false</bool>
<string name="pref_key_git_author" traslatable="false">pref_key_git_author</string>
<string name="pref_key_git_email" traslatable="false">pref_key_git_email</string>
<string name="pref_key_git_https_username" translatable="false">pref_key_git_https_username</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -700,4 +700,8 @@

<string name="prepend">Prepend</string>
<string name="insert_new_note_at_beginning">Insert new note at beginning</string>

<string name="developer_options">Developer options</string>
<string name="git_repository_type">Git repository type</string>
<string name="in_development">In development</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/xml/prefs_screen_app.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
android:title="@string/clear_database"
android:summary="@string/clear_database_summary" />

<androidx.preference.PreferenceScreen
android:key="prefs_screen_developer"
android:title="@string/developer_options">
</androidx.preference.PreferenceScreen>

<Preference
android:key="@string/pref_key_version"
android:title="@string/version"
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/xml/prefs_screen_developer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>

<androidx.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/developer_options">

<SwitchPreference
android:key="@string/pref_key_git_is_enabled"
android:title="@string/git_repository_type"
android:summary="@string/in_development"
android:defaultValue="@bool/pref_default_git_is_enabled" />

</androidx.preference.PreferenceScreen>
5 changes: 1 addition & 4 deletions sample.app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,4 @@ dropbox.app_key_schema = "db-appkey"
# Use org-java from local directory instead of the Maven repository.
# If you are working on org-java project, this can make development process easier.
# Don't forget to sync project with Gradle files (in Android Studio) if you change this value.
# org_java_directory = ../org-java

# Enable buttons for creating Git repository
# git.enabled = true
# org_java_directory = ../org-java

0 comments on commit 7c5ccf6

Please sign in to comment.