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

Feature dark mode #256

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ android {
applicationId "org.secfirst.umbrella"
minSdkVersion 16
compileSdkVersion 28
targetSdkVersion 28
targetSdkVersion 31
versionCode 56
versionName "1.0.32"
multiDexEnabled true
Expand Down Expand Up @@ -89,6 +89,9 @@ dependencies {
implementation "org.apache.commons:commons-text:$commonsText"
implementation "org.apache.commons:commons-lang3:$commonsLang"

//Material Design for Light/ Dark mode
implementation "com.google.android.material:material:$material_version"


//Framework for replacing fragments
implementation "com.bluelinelabs:conductor:$conductor_version"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
package="org.secfirst.umbrella">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.webkit.WebResourceError
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import kotlinx.android.synthetic.main.segment_detail.*
import kotlinx.android.synthetic.main.web_view.*
import org.secfirst.umbrella.R
import org.secfirst.umbrella.feature.base.view.BaseController
Expand Down Expand Up @@ -86,9 +87,10 @@ class WebViewController(bundle: Bundle) : BaseController(bundle) {

private fun setUpToolbar() {
webViewToolbar?.let {
mainActivity.setSupportActionBar(it)
it.title = markdownView.title
/*mainActivity.setSupportActionBar(it)
mainActivity.supportActionBar?.setDisplayShowHomeEnabled(true)
mainActivity.supportActionBar?.setDisplayHomeAsUpEnabled(true)
mainActivity.supportActionBar?.setDisplayHomeAsUpEnabled(true)*/
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package org.secfirst.umbrella.data.database

import com.raizlabs.android.dbflow.annotation.Database

@Database(version = AppDatabase.VERSION,
generatedClassSeparator = "_",
foreignKeyConstraintsEnforced = true)
@Database(
version = AppDatabase.VERSION,
generatedClassSeparator = "_",
foreignKeyConstraintsEnforced = true
)

object AppDatabase {

Expand Down
100 changes: 51 additions & 49 deletions app/src/main/java/org/secfirst/umbrella/data/database/BaseDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ interface BaseDao {
fun initDatabase(userToken: String) {

val dbConfig = FlowConfig.Builder(UmbrellaApplication.instance)
.addDatabaseConfig(DatabaseConfig
.Builder(AppDatabase::class.java)
.databaseName(AppDatabase.NAME)
.openHelper { databaseDefinition, helperListener ->
SQLCipherHelperImpl(databaseDefinition, helperListener, userToken)
}.build())
.build()
.addDatabaseConfig(DatabaseConfig
.Builder(AppDatabase::class.java)
.databaseName(AppDatabase.NAME)
.openHelper { databaseDefinition, helperListener ->
SQLCipherHelperImpl(databaseDefinition, helperListener, userToken)
}.build()
)
.build()
FlowManager.init(dbConfig)
}

fun changeDatabaseAccess(userToken: String): Boolean {
return try {
FlowManager.getWritableDatabase(AppDatabase.NAME).execSQL("PRAGMA rekey = '$userToken';")
FlowManager.getWritableDatabase(AppDatabase.NAME)
.execSQL("PRAGMA rekey = '$userToken';")
true
} catch (exception: Exception) {
Log.e("test", "Error when try to change the password. ${exception.message}")
Expand All @@ -51,68 +53,68 @@ interface BaseDao {
fun isDatabaseOK() = FlowManager.getDatabase(AppDatabase.NAME).isDatabaseIntegrityOk

suspend fun saveModules(modules: List<Module>) =
withContext(ioContext) { modelAdapter<Module>().updateAll(modules) }
withContext(ioContext) { modelAdapter<Module>().updateAll(modules) }

suspend fun saveSubjects(subjects: List<Subject>) =
withContext(ioContext) { modelAdapter<Subject>().saveAll(subjects) }
withContext(ioContext) { modelAdapter<Subject>().saveAll(subjects) }

suspend fun saveDifficulties(difficulties: List<Difficulty>) =
withContext(ioContext) { modelAdapter<Difficulty>().saveAll(difficulties) }
withContext(ioContext) { modelAdapter<Difficulty>().saveAll(difficulties) }

suspend fun saveMarkdowns(markdowns: List<Markdown>) =
withContext(ioContext) { modelAdapter<Markdown>().saveAll(markdowns) }
withContext(ioContext) { modelAdapter<Markdown>().saveAll(markdowns) }

suspend fun saveChecklists(checklists: List<Checklist>) =
withContext(ioContext) { modelAdapter<Checklist>().saveAll(checklists) }
withContext(ioContext) { modelAdapter<Checklist>().saveAll(checklists) }


suspend fun getModule(id: String) =
withContext(ioContext) {
SQLite.select()
.from(Module::class.java)
.where(Module_Table.id.`is`(id))
.querySingle()
}
withContext(ioContext) {
SQLite.select()
.from(Module::class.java)
.where(Module_Table.id.`is`(id))
.querySingle()
}

suspend fun getSubject(id: String) =
withContext(ioContext) {
SQLite.select()
.from(Subject::class.java)
.where(Subject_Table.id.`is`(id))
.querySingle()
}
withContext(ioContext) {
SQLite.select()
.from(Subject::class.java)
.where(Subject_Table.id.`is`(id))
.querySingle()
}

suspend fun getDifficulty(id: String) =
withContext(ioContext) {
SQLite.select()
.from(Difficulty::class.java)
.where(Difficulty_Table.id.`is`(id))
.querySingle()
}
withContext(ioContext) {
SQLite.select()
.from(Difficulty::class.java)
.where(Difficulty_Table.id.`is`(id))
.querySingle()
}

suspend fun getChecklist(id: String) =
withContext(ioContext) {
SQLite.select()
.from(Checklist::class.java)
.where(Checklist_Table.id.`is`(id))
.querySingle()
}
withContext(ioContext) {
SQLite.select()
.from(Checklist::class.java)
.where(Checklist_Table.id.`is`(id))
.querySingle()
}

suspend fun getMarkdown(id: String) =
withContext(ioContext) {
SQLite.select()
.from(Markdown::class.java)
.where(Markdown_Table.id.`is`(id))
.querySingle()
}
withContext(ioContext) {
SQLite.select()
.from(Markdown::class.java)
.where(Markdown_Table.id.`is`(id))
.querySingle()
}

suspend fun getForm(id: String) =
withContext(ioContext) {
SQLite.select()
.from(Form::class.java)
.where(Form_Table.path.`is`(id))
.querySingle()
}
withContext(ioContext) {
SQLite.select()
.from(Form::class.java)
.where(Form_Table.path.`is`(id))
.querySingle()
}

suspend fun saveForms(forms: List<Form>) {
withContext(ioContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import org.secfirst.umbrella.data.database.AppDatabase.DEFAULT


class SQLCipherHelperImpl(
databaseDefinition: DatabaseDefinition,
databaseHelperListener: DatabaseHelperListener?,
private val userToken: String? = null) : SQLCipherOpenHelper(databaseDefinition, databaseHelperListener) {
databaseDefinition: DatabaseDefinition,
databaseHelperListener: DatabaseHelperListener?,
private val userToken: String? = null
) : SQLCipherOpenHelper(databaseDefinition, databaseHelperListener) {

override fun getCipherSecret(): String {
return userToken ?: DEFAULT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ interface AccountDao : BaseDao {

suspend fun getAllFeedSource(): List<FeedSource> = withContext(ioContext) {
SQLite.select()
.from(FeedSource::class.java)
.queryList()
.from(FeedSource::class.java)
.queryList()
}

suspend fun getFeedLocation() = withContext(ioContext) {
SQLite.select()
.from(FeedLocation::class.java)
.querySingle()
.from(FeedLocation::class.java)
.querySingle()
}

suspend fun deleteMainContent(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ interface AccountRepo {

suspend fun saveFeedLocation(feedLocation: FeedLocation)

suspend fun wipeMainContent() : Boolean
suspend fun wipeMainContent(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ class AccountRepository @Inject constructor(private val accountDao: AccountDao)

override suspend fun changeToken(userToken: String) = accountDao.changeDatabaseAccess(userToken)

override suspend fun saveFeedLocation(feedLocation: FeedLocation) = accountDao.saveFeedLocation(feedLocation)
override suspend fun saveFeedLocation(feedLocation: FeedLocation) =
accountDao.saveFeedLocation(feedLocation)

override suspend fun saveAllFeedSources(feedSources: List<FeedSource>) = accountDao.saveAllFeedSource(feedSources)
override suspend fun saveAllFeedSources(feedSources: List<FeedSource>) =
accountDao.saveAllFeedSource(feedSources)

override suspend fun getFeedLocation() = accountDao.getFeedLocation()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ interface ChecklistDao {
suspend fun deleteChecklist(checklist: Checklist) {
withContext(ioContext) {
SQLite.delete()
.from(Checklist::class.java)
.where(Checklist_Table.id.`is`(checklist.id))
.execute()
.from(Checklist::class.java)
.where(Checklist_Table.id.`is`(checklist.id))
.execute()
}
}

Expand All @@ -49,80 +49,80 @@ interface ChecklistDao {

suspend fun getChecklist(checklistId: String): Checklist? = withContext(ioContext) {
SQLite.select()
.from(Checklist::class.java)
.where(Checklist_Table.id.`is`(checklistId))
.querySingle()
.from(Checklist::class.java)
.where(Checklist_Table.id.`is`(checklistId))
.querySingle()
}

suspend fun getAllChecklistFavorite(): List<Checklist> = withContext(ioContext) {
SQLite.select()
.from(Checklist::class.java)
.where(Checklist_Table.favorite.`is`(true))
.and(Checklist_Table.pathways.`is`(false))
.queryList()
.from(Checklist::class.java)
.where(Checklist_Table.favorite.`is`(true))
.and(Checklist_Table.pathways.`is`(false))
.queryList()
}

suspend fun getChecklistCount(): Long = withContext(ioContext) {
SQLite.select()
.from(Checklist::class.java)
.queryList().size.toLong()
.from(Checklist::class.java)
.queryList().size.toLong()
}

suspend fun getAllChecklist(): List<Checklist> = withContext(ioContext) {
SQLite.select()
.from(Checklist::class.java)
.queryList()
.from(Checklist::class.java)
.queryList()
}

suspend fun getAllPathways(): List<Checklist> = withContext(ioContext) {
SQLite.select()
.from(Checklist::class.java)
.where(Checklist_Table.pathways.`is`(true))
.queryList()
.from(Checklist::class.java)
.where(Checklist_Table.pathways.`is`(true))
.queryList()
}

suspend fun getFavoritePathways() : List<Checklist> = withContext(ioContext){
suspend fun getFavoritePathways(): List<Checklist> = withContext(ioContext) {
SQLite.select()
.from(Checklist::class.java)
.where(Checklist_Table.pathways.`is`(true))
.and(Checklist_Table.favorite.`is`(true))
.queryList()
.from(Checklist::class.java)
.where(Checklist_Table.pathways.`is`(true))
.and(Checklist_Table.favorite.`is`(true))
.queryList()
}

suspend fun getSubjectById(subjectId: String) = withContext(ioContext) {
SQLite.select()
.from(Subject::class.java)
.where(Subject_Table.id.`is`(subjectId))
.querySingle()
.from(Subject::class.java)
.where(Subject_Table.id.`is`(subjectId))
.querySingle()
}

suspend fun getDifficultyById(difficultyId: String): Difficulty? = withContext(ioContext) {
SQLite.select()
.from(Difficulty::class.java)
.where(Difficulty_Table.id.`is`(difficultyId))
.querySingle()
.from(Difficulty::class.java)
.where(Difficulty_Table.id.`is`(difficultyId))
.querySingle()
}

suspend fun getAllChecklistInProgress(): List<Checklist> = withContext(ioContext) {
SQLite.select()
.from(Checklist::class.java)
.where(Checklist_Table.progress.greaterThanOrEq(1))
.and(Checklist_Table.favorite.`is`(false))
.queryList()
.from(Checklist::class.java)
.where(Checklist_Table.progress.greaterThanOrEq(1))
.and(Checklist_Table.favorite.`is`(false))
.queryList()
}

suspend fun getAllCustomChecklistInProgress(): List<Checklist> = withContext(ioContext) {
SQLite.select()
.from(Checklist::class.java)
.where(Checklist_Table.custom.`is`(true))
.queryList()
.from(Checklist::class.java)
.where(Checklist_Table.custom.`is`(true))
.queryList()
}

suspend fun getModuleByName(moduleName: String): Module? = withContext(ioContext) {
SQLite.select()
.from(Module::class.java)
.where(Module_Table.rootDir.`is`(moduleName))
.querySingle()
.from(Module::class.java)
.where(Module_Table.rootDir.`is`(moduleName))
.querySingle()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ interface ChecklistRepo {

suspend fun loadAllPathways(): List<Checklist>

suspend fun loadFavoritePathways() : List<Checklist>
suspend fun loadFavoritePathways(): List<Checklist>
}
Loading