Skip to content

Commit

Permalink
Merge pull request #175 from SecUSo/development
Browse files Browse the repository at this point in the history
V2.0.1
  • Loading branch information
coderPaddyS authored Sep 20, 2024
2 parents 160da0d + b22491e commit bda8af5
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 103 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/android-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Android Emulator Tests
on: [ push, pull_request ]

jobs:
check-if-tests-exist:
runs-on: ubuntu-latest
outputs:
status: ${{ steps.check-androidTest.outputs.NOT_EMPTY }}
min-sdk-version: ${{ steps.get-sdk-version.outputs.MIN_SDK_VERSION }}
target-sdk-version: ${{ steps.get-sdk-version.outputs.TARGET_SDK_VERSION }}
app-id: ${{ steps.get-app-id.outputs.APP_ID }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: "recursive"
- name: Check if androidTest folder is not empty
run: |
echo "NOT_EMPTY=$([ "$(ls -A app/src/androidTest)" ] && echo 'true' || echo 'false')"
echo "NOT_EMPTY=$([ "$(ls -A app/src/androidTest)" ] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
id: check-androidTest
- name: Get min and target sdk
if: steps.check-androidTest.outputs.NOT_EMPTY == 'true'
id: get-sdk-version
run: |
echo "MIN_SDK_VERSION=$(cat app/build.gradle | grep minSdkVersion | rev | cut -d' ' -f 1 | rev)" >> $GITHUB_OUTPUT
echo "TARGET_SDK_VERSION=$(cat app/build.gradle | grep targetSdkVersion | rev | cut -d' ' -f 1 | rev)" >> $GITHUB_OUTPUT
- name: Get app ID
id: get-app-id
run: |
echo "APP_ID=$(cat app/build.gradle | grep applicationId | rev | cut -d' ' -f 1 | rev | tr -d '"')" >> $GITHUB_OUTPUT
test:
needs: check-if-tests-exist
if: needs.check-if-tests-exist.outputs.status == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
api-level: [34, "${{ needs.check-if-tests-exist.outputs.min-sdk-version }}", "${{ needs.check-if-tests-exist.outputs.target-sdk-version }}"]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Gradle cache
uses: gradle/gradle-build-action@v3

- name: AVD cache
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}

- name: Set up JDK environment
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.api-level >= 30 && 'google_apis' || 'default' }}
arch: ${{ matrix.api-level < 21 && 'x86' || 'x86_64' }}
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."

- name: Run connected tests
uses: ReactiveCircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.api-level >= 30 && 'google_apis' || 'default' }}
arch: ${{ matrix.api-level < 21 && 'x86' || 'x86_64' }}
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: |
adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}} || true
adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.test || true
adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.androidTest || true
chmod +x gradlew
./gradlew :app:connectedCheck --stacktrace
adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}} || true
adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.test || true
adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.androidTest || true
2 changes: 1 addition & 1 deletion .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Changelog Generation

on:
release:
types: [released]
types: [published]
workflow_dispatch:

jobs:
Expand Down
57 changes: 26 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,32 @@
name: Continuous integration

name: Continuous Integration
on: [push, pull_request]

jobs:
test:
name: Unit Tests
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: "recursive"

- name: Set up JDK environment
uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: 17

- name: Make gradlew executable
run: chmod +x ./gradlew

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Run local unit tests
run: bash ./gradlew test --stacktrace
- name: Android Test Report
uses: asadmansr/[email protected]

#androidTest:
# name: Instrumented Tests
# runs-on: macOS-latest
# steps:
# - uses: actions/checkout@v2
# with:
# submodules: 'recursive'
# - name: Set up JDK 1.8
# uses: actions/setup-java@v1
# with:
# java-version: 1.8
# - name: Make gradlew executable
# run: chmod +x ./gradlew
# - name: Run Instrumented Tests
# uses: reactivecircus/android-emulator-runner@v1
# with:
# api-level: 29
# arch: x86
# disable-animations: true
# script: ./gradlew connectedAndroidTest --stacktrace

apk:
name: Build APK
build:
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -68,5 +45,23 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Build debug APK
run: ./gradlew assembleDebug
- name: Run lint check
run: bash ./gradlew lint

- name: Upload lint result
uses: actions/upload-artifact@v4
with:
name: lint-results-debug
path: app/build/reports/lint-results-debug.html

- name: Build the app
run: bash ./gradlew build --stacktrace

- name: Build debug apk
run: bash ./gradlew assembleDebug

- name: Upload debug apk
uses: actions/upload-artifact@v4
with:
name: debug-apk
path: app/build/outputs/apk/debug/*.apk
9 changes: 7 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
minSdkVersion 21
compileSdk 34
targetSdkVersion 34
versionCode 19
versionName "2.0.0"
versionCode 20
versionName "2.0.1"
}

applicationVariants.configureEach { variant ->
Expand Down Expand Up @@ -58,6 +58,10 @@ android {
jvmTarget = JavaVersion.VERSION_17.toString()
}

lint {
lintConfig = file("lint.xml")
}

room {
schemaDirectory "$projectDir/schemas"
}
Expand All @@ -82,6 +86,7 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1'
implementation 'com.github.bumptech.glide:glide:4.11.0'

def work_version = "2.8.1"
implementation "androidx.work:work-runtime:$work_version"
Expand Down
10 changes: 10 additions & 0 deletions app/lint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<!-- Disable the NotificationPermission check for glide -->
<issue id="NotificationPermission">
<ignore regexp="com.bumptech.glide.request.target.NotificationTarget" />
</issue>

<!-- Set the severity of missing translations to warning instead of error -->
<issue id="MissingTranslation" severity="warning" />
</lint>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.secuso.privacyfriendlynotes.ui

import android.os.Bundle
import androidx.preference.PreferenceManager
import android.view.ContextThemeWrapper
import android.view.Menu
import android.view.MenuItem
Expand All @@ -24,6 +23,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -43,7 +43,7 @@ import org.secuso.privacyfriendlynotes.ui.main.MainActivityViewModel
class RecycleActivity : AppCompatActivity() {
private val mainActivityViewModel: MainActivityViewModel by lazy { ViewModelProvider(this)[MainActivityViewModel::class.java] }
private val searchView: SearchView by lazy { findViewById(R.id.searchViewFilterRecycle) }
private val adapter: NoteAdapter by lazy { NoteAdapter(mainActivityViewModel, true) }
private val adapter: NoteAdapter by lazy { NoteAdapter(this, mainActivityViewModel, true) }
private val trashedNotes by lazy {
mainActivityViewModel.trashedNotes.flowWithLifecycle(lifecycle, Lifecycle.State.STARTED).stateIn(lifecycleScope, SharingStarted.Lazily, listOf())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@
*/
package org.secuso.privacyfriendlynotes.ui.adapter

import android.app.Activity
import android.graphics.Color
import android.preference.PreferenceManager
import android.text.Html
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.content.res.AppCompatResources
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import org.secuso.privacyfriendlynotes.R
import org.secuso.privacyfriendlynotes.room.DbContract
import org.secuso.privacyfriendlynotes.room.model.Note
import org.secuso.privacyfriendlynotes.ui.main.MainActivityViewModel
import org.secuso.privacyfriendlynotes.ui.util.DarkModeUtil
import java.io.File

/**
* Adapter that provides a binding for notes
Expand All @@ -36,6 +40,7 @@ import org.secuso.privacyfriendlynotes.ui.util.DarkModeUtil
* @see org.secuso.privacyfriendlynotes.ui.RecycleActivity
*/
class NoteAdapter(
private val activity: Activity,
private val mainActivityViewModel: MainActivityViewModel,
var colorCategory: Boolean,
) : RecyclerView.Adapter<NoteAdapter.NoteHolder>() {
Expand All @@ -62,7 +67,8 @@ class NoteAdapter(
holder.textViewTitle.text = currentNote.name
holder.textViewDescription.text = ""
val pref = PreferenceManager.getDefaultSharedPreferences(holder.itemView.context)
holder.textViewDescription.visibility = if (pref.getBoolean("settings_show_preview", true)) View.VISIBLE else View.GONE
val showPreview = pref.getBoolean("settings_show_preview", true)
holder.textViewDescription.visibility = if (showPreview) View.VISIBLE else View.GONE
holder.textViewExtraText.visibility = View.GONE
holder.textViewExtraText.text = null
holder.imageViewcategory.visibility = View.GONE
Expand Down Expand Up @@ -94,45 +100,50 @@ class NoteAdapter(
}
}

when (currentNote.type) {
DbContract.NoteEntry.TYPE_TEXT -> {
holder.textViewDescription.text = Html.fromHtml(currentNote.content)
holder.textViewDescription.maxLines = 3
}
when (currentNote.type) {
DbContract.NoteEntry.TYPE_TEXT -> {
if (showPreview) {
holder.textViewDescription.text = Html.fromHtml(currentNote.content)
holder.textViewDescription.maxLines = 3
}
}

DbContract.NoteEntry.TYPE_AUDIO -> {
holder.imageViewcategory.visibility = View.VISIBLE
holder.imageViewcategory.setImageResource(R.drawable.ic_mic_icon_24dp)
}
DbContract.NoteEntry.TYPE_AUDIO -> {
holder.imageViewcategory.visibility = View.VISIBLE
holder.imageViewcategory.setImageResource(R.drawable.ic_mic_icon_24dp)
}

DbContract.NoteEntry.TYPE_SKETCH -> {
holder.imageViewcategory.visibility = View.VISIBLE
holder.imageViewcategory.setBackgroundColor(run {
val value = TypedValue()
holder.itemView.context.theme.resolveAttribute(R.attr.colorSurfaceVariantLight, value, true)
value.data
})
if (pref.getBoolean("settings_show_preview", true)) {
val bitmap = mainActivityViewModel.sketchPreview(currentNote, 200)
if (bitmap != null) {
holder.imageViewcategory.setImageBitmap(mainActivityViewModel.sketchPreview(currentNote, 200))
DbContract.NoteEntry.TYPE_SKETCH -> {
holder.imageViewcategory.visibility = View.VISIBLE
if (showPreview) {
holder.imageViewcategory.setBackgroundColor(run {
val value = TypedValue()
holder.itemView.context.theme.resolveAttribute(R.attr.colorSurfaceVariantLight, value, true)
value.data
})
holder.imageViewcategory.minimumHeight = 200; holder.imageViewcategory.minimumWidth = 200
Glide.with(activity).load(File("${activity.application.filesDir.path}/sketches${currentNote.content}"))
.placeholder(AppCompatResources.getDrawable(activity, R.drawable.ic_photo_icon_24dp))
.into(holder.imageViewcategory)
} else {
holder.imageViewcategory.setImageResource(R.drawable.ic_photo_icon_24dp)
}
} else {
holder.imageViewcategory.setImageResource(R.drawable.ic_photo_icon_24dp)
}
}

DbContract.NoteEntry.TYPE_CHECKLIST -> {
val preview = mainActivityViewModel.checklistPreview(currentNote)
holder.textViewExtraText.text = "${preview.filter { it.first }.count()}/${preview.size}"
holder.textViewExtraText.visibility = View.VISIBLE
holder.imageViewcategory.visibility = View.GONE
holder.textViewDescription.text = preview.take(3).joinToString(System.lineSeparator()) { it.second }
holder.textViewDescription.maxLines = 3
DbContract.NoteEntry.TYPE_CHECKLIST -> {
holder.imageViewcategory.visibility = View.GONE
holder.textViewExtraText.visibility = View.VISIBLE

if (showPreview) {
val preview = mainActivityViewModel.checklistPreview(currentNote)
holder.textViewExtraText.text = "${preview.filter { it.first }.count()}/${preview.size}"
holder.textViewDescription.text = preview.take(3).joinToString(System.lineSeparator()) { it.second }
holder.textViewDescription.maxLines = 3
} else {
holder.textViewExtraText.text = "-/-"
}
}
}
}

// if the Description is empty, don't show it
if (holder.textViewDescription.text.toString().isEmpty()) {
Expand Down
Loading

0 comments on commit bda8af5

Please sign in to comment.