Skip to content

Commit

Permalink
Merge pull request #108 from nextcloud/82-sample-app
Browse files Browse the repository at this point in the history
feat(sample): Add minimal sample app (#82)
  • Loading branch information
AndyScherzinger authored Apr 20, 2023
2 parents 76574bb + a0ca524 commit 03b4905
Show file tree
Hide file tree
Showing 22 changed files with 737 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 6 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,16 @@
Add the dependency to the `build.gradle` file of your app, replace `X.X.X` with the [latest available version](https://github.com/nextcloud/android-common/releases).

```
implementation 'com.github.nextcloud:android-common:X.X.X'
implementation 'com.github.nextcloud.android-common:ui:X.X.X'
```

### Theming

```java
// Define your MaterialSchemes and ColorUtil
final var schemes = MaterialSchemes.Companion.fromColor(color); // color should be fetched from the server capabilities
final var utils = new ColorUtil(context);

// Use them to instantiate ThemUtils you need
final var platform = new AndroidViewThemeUtils(schemes, colorUtil);
final var material = new MaterialViewThemeUtils(schemes, colorUtil);
final var androidx = new AndroidXViewThemeUtils(schemes, this.platform);
final var dialog = new DialogViewThemeUtils(schemes);

// Use the methods of the ThemeUtils to apply the actual theme:
material.themeTabLayout(tabLayout);
```
See `Sample` app → `UiFragment` for a basic usage sample.

## Known users

- [Nextcloud files](https://github.com/nextcloud/android)
- [Nextcloud talk](https://github.com/nextcloud/talk-android/)
- [Nextcloud notes](https://github.com/nextcloud/notes-android) ([Planned](https://github.com/nextcloud/notes-android/issues/1648#issuecomment-1403223962))
- [Nextcloud Files](https://github.com/nextcloud/android)
- [Nextcloud Talk](https://github.com/nextcloud/talk-android/)
- [Nextcloud Notes](https://github.com/nextcloud/notes-android)
- [Nextcloud Deck](https://github.com/stefan-niedermann/nextcloud-deck)
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ plugins {
id "org.jetbrains.kotlin.kapt" version "$kotlinVersion" apply false
id "com.diffplug.spotless" version "6.18.0" apply false
id 'io.gitlab.arturbosch.detekt' version '1.22.0' apply false
id 'com.android.application' version '7.4.0' apply false
}

task clean(type: Delete) {
Expand Down
1 change: 1 addition & 0 deletions sample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
50 changes: 50 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
namespace 'com.nextcloud.android.common.sample'
compileSdk 33

defaultConfig {
applicationId "com.nextcloud.android.common.sample"
minSdk 26
targetSdk 33
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
implementation project(path: ':ui')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
21 changes: 21 additions & 0 deletions sample/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
41 changes: 41 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Nextcloud Android Common Library
~
~ Copyright (C) 2023 Nextcloud GmbH
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Androidcommon">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Nextcloud Android Common Library
*
* Copyright (C) 2023 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.nextcloud.android.common.sample

import android.graphics.Color
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import com.nextcloud.android.common.sample.databinding.ActivityMainBinding
import com.nextcloud.android.common.ui.color.ColorUtil
import com.nextcloud.android.common.ui.theme.MaterialSchemes
import com.nextcloud.android.common.ui.theme.utils.AndroidViewThemeUtils
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.android.common.ui.theme.utils.MaterialViewThemeUtils

class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

val mainViewModel = ViewModelProvider(this)[MainViewModel::class.java]

// Color should be fetched from the server capabilities or another proper source
binding.btn.setOnClickListener { v ->
try {
mainViewModel.color.value = Color.parseColor("#${binding.color.text}")
} catch (_: java.lang.IllegalArgumentException) {
Toast.makeText(
this,
"#${binding.color.text} is not a valid color.",
Toast.LENGTH_SHORT
).show()
}
}

mainViewModel.color.observe(this) { applyTheme(it) }
}

private fun applyTheme(color: Int) {
// Define your MaterialSchemes and ColorUtil
val schemes = MaterialSchemes.Companion.fromColor(color)
val colorUtil = ColorUtil(this)

// Use them to instantiate ThemUtils you need
val platform = AndroidViewThemeUtils(schemes, colorUtil)
val material = MaterialViewThemeUtils(schemes, colorUtil)
// val androidx = AndroidXViewThemeUtils(schemes, platform)
// val dialog = DialogViewThemeUtils(schemes)

// Use the methods of the ThemeUtils to apply the actual theme.
// For a consistent User Experience it is necessary to apply the theme to *every* UI element
platform.colorViewBackground(binding.container, ColorRole.SURFACE)
platform.colorTextView(binding.headlineLib, ColorRole.PRIMARY)
platform.colorTextView(binding.headlineModuleUi, ColorRole.SECONDARY)
platform.themeStatusBar(this)
material.colorTextInputLayout(binding.colorTil)
material.themeExtendedFAB(binding.btn)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Nextcloud Android Common Library
*
* Copyright (C) 2023 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.nextcloud.android.common.sample

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class MainViewModel : ViewModel() {

val color = MutableLiveData<Int>()
}
Loading

0 comments on commit 03b4905

Please sign in to comment.