Skip to content

Commit

Permalink
Adaptive SDK v1.0.0-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitrisFuturae committed Jun 21, 2023
0 parents commit 38ce06f
Show file tree
Hide file tree
Showing 40 changed files with 1,168 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.iml
.gradle
.DS_Store
/local.properties
/.idea
/build
/captures
.externalNativeBuild
.cxx
local.properties
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Futurae Adaptive SDK

This is the Futurae adaptive SDK for Android. The Adaptive SDK is a data collection SDK that can be used stand-alone or together with Futurae SDK.

### Installation
In your application `build.gradle` file add:
```
repositories {
maven {
url "https://artifactory.futurae.com/artifactory/futurae-mobile"
credentials {
username = "anonymous"
password = ""
}
}
}
...
dependencies {
implementation 'com.futurae.sdk:adaptive:x.x.x'
}
```
### User guide

For usage instructions together with [Futurae SDK](https://github.com/Futurae-Technologies/android-sdk) please refer to the [Futurae adaptive SDK guide](https://www.futurae.com/docs/guide/futurae-sdks/mobile-sdk/).
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
54 changes: 54 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.kapt'
}

android {
namespace 'com.futurae.adaptivedemo'
compileSdk 33

defaultConfig {
applicationId "com.futurae.adaptivedemo"
minSdk 23
targetSdk 33
versionCode 1
versionName "1.0.0-alpha"
}

buildFeatures {
viewBinding = true
}

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

dependencies {
implementation 'com.futurae.sdk:adaptive:1.0.0-alpha'
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
implementation 'androidx.activity:activity-compose:1.7.2'
implementation "androidx.appcompat:appcompat:1.6.1"
implementation "androidx.activity:activity-ktx:1.7.2"
implementation "androidx.fragment:fragment-ktx:1.6.0"
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation "com.google.android.material:material:1.9.0"
implementation "com.jakewharton.timber:timber:5.0.1"
implementation "com.google.code.gson:gson:2.9.1"
}
21 changes: 21 additions & 0 deletions app/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
50 changes: 50 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<!-- START - Adaptive Permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<!-- Backwards compatibility permissions for bluetooth. Uncomment when bump targetSdk to 31 -->
<uses-permission
android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />
<!-- END - Adaptive Permissions -->

<application
android:name=".AdaptiveApp"
android:allowBackup="false"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Futurae"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.Futurae">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>
14 changes: 14 additions & 0 deletions app/src/main/java/com/futurae/adaptivedemo/AdaptiveApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.futurae.adaptivedemo

import android.app.Application
import com.futurae.sdk.adaptive.AdaptiveSDK
import timber.log.Timber

class AdaptiveApp : Application() {

override fun onCreate() {
super.onCreate()
AdaptiveSDK.INSTANCE.init(this)
Timber.plant(Timber.DebugTree())
}
}
79 changes: 79 additions & 0 deletions app/src/main/java/com/futurae/adaptivedemo/CollectionsActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.futurae.adaptivedemo

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.futurae.adaptivedemo.databinding.ActivityCollectionsBinding
import com.futurae.adaptivedemo.databinding.ItemCollectionBinding
import com.futurae.sdk.adaptive.AdaptiveDbHelper
import com.futurae.sdk.adaptive.model.AdaptiveCollection
import com.google.gson.GsonBuilder
import kotlinx.coroutines.launch
import java.text.DateFormat
import java.util.Calendar

class CollectionsActivity : AppCompatActivity() {

private val collectionsAdapter = CollectionsAdapter()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityCollectionsBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.recyclerView.apply {
layoutManager = LinearLayoutManager(this@CollectionsActivity)
adapter = collectionsAdapter
}

lifecycleScope.launch {
AdaptiveDbHelper.INSTANCE.allCollections.collect {
collectionsAdapter.submitList(it.toList())
}
}

}
}

class CollectionsAdapter : ListAdapter<AdaptiveCollection, CollectionViewHolder>(
object : DiffUtil.ItemCallback<AdaptiveCollection>() {
override fun areItemsTheSame(oldItem: AdaptiveCollection, newItem: AdaptiveCollection): Boolean {
return oldItem.timestamp == newItem.timestamp
}

override fun areContentsTheSame(oldItem: AdaptiveCollection, newItem: AdaptiveCollection): Boolean {
return oldItem == newItem
}
}
) {

private val dateFormat = DateFormat.getDateInstance()
private val gson = GsonBuilder().setLenient().create()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CollectionViewHolder {
return CollectionViewHolder(
ItemCollectionBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
)
}

override fun onBindViewHolder(holder: CollectionViewHolder, position: Int) {
val collection = getItem(position)
val calendar = Calendar.getInstance().apply {
timeInMillis = collection.timestamp * 1000
}
holder.binding.titleTextView.text = dateFormat.format(calendar.time)
holder.binding.subtitleTextView.text = gson.toJson(collection)
}

}

class CollectionViewHolder(val binding: ItemCollectionBinding) : RecyclerView.ViewHolder(binding.root)

0 comments on commit 38ce06f

Please sign in to comment.