Skip to content

Commit

Permalink
Merge pull request #20 from RocqJones/enhancement/libs-navigators-ui-…
Browse files Browse the repository at this point in the history
…linking

Enhancement | Libs, add navigators & UI linking
  • Loading branch information
RocqJones authored Mar 6, 2024
2 parents a8226f1 + cd37bff commit c87ecae
Show file tree
Hide file tree
Showing 16 changed files with 311 additions and 248 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
.externalNativeBuild
.cxx
local.properties
/.idea/gradle.xml
22 changes: 0 additions & 22 deletions .idea/gradle.xml

This file was deleted.

20 changes: 11 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,19 @@ dependencies {
implementation project(":me-design")
implementation project(":me-logic")

// other dependencies
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
implementation 'androidx.activity:activity-compose:1.8.0'
implementation "androidx.core:core-ktx:$core_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_runtime"
implementation "androidx.activity:activity-compose:$activity_compose"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.compose.material3:material3:1.1.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation "androidx.compose.material3:material3:$material3_version"
// Compose navigation
implementation("androidx.navigation:navigation-compose:$navigation_version")

testImplementation "junit:junit:$junit_version"
androidTestImplementation "androidx.test.ext:junit:$test_junit"
androidTestImplementation "androidx.test.espresso:espresso-core:$test_espresso"
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$test_manifest"
}
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.MeSDK">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
98 changes: 23 additions & 75 deletions app/src/main/java/com/rocqjones/mesdk/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package com.rocqjones.mesdk

import android.content.Intent
import android.content.res.Configuration
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Button
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.rocqjones.me_design.screens.ListActivity
import com.rocqjones.me_design.screens.bottomNavAdaptive.AdaptiveNavActivity
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.rocqjones.me_design.screens.BottomSheetDialogScreen
import com.rocqjones.me_design.screens.EndlessScreen
import com.rocqjones.me_design.screens.HomeScreen
import com.rocqjones.me_design.ui.theme.MeSDKTheme
import com.rocqjones.me_logic.models.Screen

/**
* This is the first launcher screen of the SDK.
Expand All @@ -28,83 +28,34 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
setContent {
MeSDKTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
FirstScreen(
onMoveToListClicked = { navigateToList() },
onMoveToNavClicked = { navigateToAdaptiveUI() }
)
MyAppMain()
}
}
}
}

private fun navigateToAdaptiveUI() {
try {
val b = Intent(this, AdaptiveNavActivity::class.java)
b.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(b)
} catch (e: Exception) {
e.printStackTrace()
}
}

private fun navigateToList() {
try {
val a = Intent(this, ListActivity::class.java)
a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(a)
} catch (e: Exception) {
e.printStackTrace()
}
}
}

@Composable
fun FirstScreen(
onMoveToListClicked: () -> Unit,
onMoveToNavClicked: () -> Unit,
modifier: Modifier = Modifier
) {
/**
* When the button is clicked, should navigate to the respective UI
*/
Column(
modifier = modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
fun MyAppMain() {
val navController = rememberNavController()

NavHost(
navController, startDestination = Screen.HomeScreen.route
) {
val padding = 8.dp
Text(
"Welcome to the Me SDK!",
style = MaterialTheme.typography.headlineMedium,
color =MaterialTheme.colorScheme.secondary,
)
// list
Button(
modifier = Modifier.padding(padding).fillMaxWidth(),
shape = MaterialTheme.shapes.medium,
onClick = onMoveToListClicked // sets the sate to true
) {
Text(
"Endless List",
style = MaterialTheme.typography.bodyLarge
)
composable(Screen.HomeScreen.route) {
HomeScreen(navController)
}

composable(Screen.EndlessScreen.route) {
EndlessScreen(navController)
}

// Adaptive Navigation
Button(
modifier = Modifier.padding(padding).fillMaxWidth(),
shape = MaterialTheme.shapes.medium,
onClick = onMoveToNavClicked // sets the sate to true
) {
Text(
"Adaptive Navigation",
style = MaterialTheme.typography.bodyLarge
)
composable(Screen.BottomSheetDialogScreen.route) {
BottomSheetDialogScreen(navController)
}
}
}
Expand All @@ -123,9 +74,6 @@ fun FirstScreen(
@Composable
fun DefaultPreview() {
MeSDKTheme {
FirstScreen(
onMoveToListClicked = {},
onMoveToNavClicked = {}
) // empty lambda expression means "Do nothing" on click
MyAppMain()
}
}
27 changes: 20 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
buildscript {
ext {
compose_version = '1.5.4' // compose.runtime
compose_compiler = '1.4.4' // Release: https://developer.android.com/jetpack/androidx/releases/compose-kotlin
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
ext.compose_version = '1.5.4' // compose.runtime
ext.compose_compiler = '1.4.4' // Release: https://developer.android.com/jetpack/androidx/releases/compose-kotlin
}

plugins {
id 'com.android.application' version '8.1.2' apply false
id 'com.android.library' version '8.1.2' apply false
id 'com.android.application' version '8.1.4' apply false
id 'com.android.library' version '8.1.4' apply false
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
}

ext {
core_version = '1.12.0'
activity_compose = '1.8.2'
lifecycle_runtime = '2.7.0'
material_version = '1.11.0'
material3_version = '1.2.0'
appcompat_version = '1.6.1'
test_manifest = '1.6.2'
test_espresso = '3.5.1'
test_junit = '1.1.5'
junit_version = '4.13.2'
navigation_version = '2.7.7'
}
29 changes: 14 additions & 15 deletions me-design/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,24 @@ dependencies {
// Me Android SDK - logic
implementation project(":me-logic")

implementation 'androidx.core:core-ktx:1.12.0'
implementation "androidx.core:core-ktx:$core_version"
implementation "androidx.appcompat:appcompat:$appcompat_version"

// other dependencies
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.10.0'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
testImplementation "junit:junit:$junit_version"
androidTestImplementation "androidx.test.ext:junit:$test_junit"
androidTestImplementation "androidx.test.espresso:espresso-core:$test_espresso"
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$test_manifest"

implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
implementation 'androidx.activity:activity-compose:1.8.0'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_runtime"
implementation "androidx.activity:activity-compose:$activity_compose"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.compose.material3:material3:1.1.2'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"

implementation "com.google.android.material:material:$material_version"
implementation "androidx.compose.material3:material3:$material3_version"

// Compose navigation
implementation("androidx.navigation:navigation-compose:$navigation_version")
}
10 changes: 0 additions & 10 deletions me-design/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<activity
android:name=".screens.bottomNavAdaptive.AdaptiveNavActivity"
android:exported="false"
android:label="@string/title_activity_adaptive_nav"
android:theme="@style/Theme.MeSDK" />
<activity
android:name=".screens.ListActivity"
android:exported="false"
android:label="@string/title_activity_list"
android:theme="@style/Theme.MeSDK" />
<activity
android:name=".base.BaseActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import com.rocqjones.me_logic.utils.ToastUtils
*/
abstract class BaseActivity : ComponentActivity() {

private var activityContext: Activity? = null
var toastUtils: ToastUtils? = null
lateinit var activityContext: Activity
lateinit var toastUtils: ToastUtils

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -23,7 +23,7 @@ abstract class BaseActivity : ComponentActivity() {
private fun initialize() {
try {
activityContext = activityContext()
toastUtils = ToastUtils(activityContext!!)
toastUtils = ToastUtils(activityContext)
} catch (e: Exception) {
e.printStackTrace()
}
Expand Down
Loading

0 comments on commit c87ecae

Please sign in to comment.