Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
BlazeCodeDev committed Nov 27, 2022
2 parents 06ec6c7 + a107ba8 commit 222b3ca
Show file tree
Hide file tree
Showing 37 changed files with 968 additions and 6 deletions.
14 changes: 11 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ plugins {
}

android {
namespace 'com.blazecode.tsviewer'
compileSdk 33

defaultConfig {
applicationId "com.blazecode.tsviewer"
minSdk 26
targetSdk 33
versionCode 6
versionName "1.3"
versionCode 7
versionName "1.4"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -29,6 +30,9 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.debug
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
Expand All @@ -40,7 +44,6 @@ android {
buildFeatures {
viewBinding true
}
namespace 'com.blazecode.tsviewer'
}

dependencies {
Expand All @@ -61,6 +64,7 @@ dependencies {

//COROUTINES
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.6.4'

//WORK MANAGER
implementation 'androidx.work:work-runtime-ktx:2.7.1'
Expand Down Expand Up @@ -94,4 +98,8 @@ dependencies {

//KLAXON FOR PARSING JSON
implementation 'com.beust:klaxon:5.6'

//WEAR INTEGRATION
wearApp project(':wear')
implementation 'com.google.android.gms:play-services-wearable:18.0.0'
}
13 changes: 13 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:label="@string/app_name"
android:theme="@style/Theme.TSViewer.NoActionBar">
<intent-filter>
Expand All @@ -33,6 +34,18 @@
</intent-filter>
</activity>

<!-- Wear -->
<service android:name=".util.wear.WearableListenerService"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<data
android:host="*"
android:pathPrefix="/start-activity"
android:scheme="wear" />
</intent-filter>
</service>

<!-- QUICK SETTINGS TILE -->
<service
android:name=".util.tile.ClientTileService"
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/com/blazecode/tsviewer/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.blazecode.tsviewer.util.updater.GitHubUpdater
import com.blazecode.tsviewer.util.updater.UpdateCheckWorker
import com.google.android.material.snackbar.Snackbar
import com.mikepenz.aboutlibraries.LibsBuilder
import kotlinx.coroutines.*
import timber.log.Timber
import java.util.concurrent.TimeUnit
import kotlin.coroutines.EmptyCoroutineContext
Expand Down Expand Up @@ -79,6 +80,10 @@ class MainActivity : AppCompatActivity() {
val autoUpdateMenuItem = binding.toolbar.menu.findItem(R.id.action_update_check)
autoUpdateMenuItem.isChecked = preferences.getBoolean("autoUpdateCheck", true)

// SYNC WITH WEARABLE
val syncWearableMenuItem = binding.toolbar.menu.findItem(R.id.action_sync_wearable)
syncWearableMenuItem.isChecked = preferences.getBoolean("syncWearable", false)

// DEBUG AUTO UPDATE CHECK
val debugAutoUpdateMenuItem = binding.toolbar.menu.findItem(R.id.action_update_check_debug)
debugAutoUpdateMenuItem.isChecked = preferences.getBoolean("debugUpdateCheck", false)
Expand Down Expand Up @@ -125,6 +130,12 @@ class MainActivity : AppCompatActivity() {
return@setOnMenuItemClickListener true
}

R.id.action_sync_wearable -> {
syncWearableMenuItem.isChecked = !syncWearableMenuItem.isChecked
setSyncWearable(syncWearableMenuItem.isChecked)
return@setOnMenuItemClickListener true
}

R.id.action_update_check_debug -> {
debugAutoUpdateMenuItem.isChecked = !debugAutoUpdateMenuItem.isChecked
setDebugUpdateCheck(debugAutoUpdateMenuItem.isChecked)
Expand Down Expand Up @@ -276,6 +287,12 @@ class MainActivity : AppCompatActivity() {
editor.commit()
}

private fun setSyncWearable(isEnabled: Boolean){
val editor : SharedPreferences.Editor = preferences.edit()
editor.putBoolean("syncWearable", isEnabled)
editor.commit()
}

private fun setDebugUpdateCheck(isEnabled: Boolean) {
val editor : SharedPreferences.Editor = preferences.edit()
editor.putBoolean("debugUpdateCheck", isEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.blazecode.tsviewer.util.database.UserCountDAO
import com.blazecode.tsviewer.util.database.UserCountDatabase
import com.blazecode.tsviewer.util.notification.ClientNotificationManager
import com.blazecode.tsviewer.util.tile.TileManager
import com.blazecode.tsviewer.util.wear.WearDataManager
import com.github.theholywaffle.teamspeak3.api.wrapper.Client


Expand All @@ -35,6 +36,7 @@ class ClientsWorker(private val context: Context, workerParameters: WorkerParame
val connectionManager = ConnectionManager(context)
val clientNotificationManager = ClientNotificationManager(context)
val tileManager = TileManager(context)
val wearDataManager = WearDataManager(context)
val errorHandler = ErrorHandler(context)

lateinit var db: UserCountDatabase
Expand All @@ -48,6 +50,7 @@ class ClientsWorker(private val context: Context, workerParameters: WorkerParame
private var PORT : Int = 0
private var RUN_ONLY_WIFI : Boolean = true
private var DEMO_MODE : Boolean = false
private var SYNC_WEARABLE : Boolean = false

private var clientList = mutableListOf<Client>()
private var clientListNames = mutableListOf<String>()
Expand Down Expand Up @@ -76,6 +79,7 @@ class ClientsWorker(private val context: Context, workerParameters: WorkerParame
else
extractNames()

if(SYNC_WEARABLE) wearDataManager.sendClientList(clientListNames)
clientNotificationManager.post(clientListNames)
writeClients(clientListNames)
}
Expand Down Expand Up @@ -154,6 +158,7 @@ class ClientsWorker(private val context: Context, workerParameters: WorkerParame
INCLUDE_QUERY_CLIENTS = preferences.getBoolean("includeQuery", false)
RUN_ONLY_WIFI = preferences.getBoolean("run_only_wifi", true)
DEMO_MODE = preferences.getBoolean("demoMode", false)
SYNC_WEARABLE = preferences.getBoolean("syncWearable", false)
loadEncryptedPreferences()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
*
* * Copyright (c) BlazeCode / Ralf Lehmann, 2022.
*
*/

package com.blazecode.tsviewer.util.wear

import android.content.Context
import com.google.android.gms.wearable.PutDataMapRequest
import com.google.android.gms.wearable.Wearable

class WearDataManager(val context: Context) {

private val dataClient by lazy { Wearable.getDataClient(context) }

companion object {
private const val CLIENTS_PATH = "/clients"
private const val CLIENT_LIST_KEY = "clientlist"
private const val TIME_MILLIS = "timeMillis"
}

fun sendClientList(clientList: MutableList<String>) {
var clientArray: Array<String> = arrayOf()
for (client in clientList) {
clientArray += client
}

val request = PutDataMapRequest.create(CLIENTS_PATH).apply {
dataMap.putStringArray(CLIENT_LIST_KEY, clientArray)
dataMap.putLong(TIME_MILLIS, System.currentTimeMillis())
}
.asPutDataRequest()
.setUrgent()

val result = dataClient.putDataItem(request)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
*
* * Copyright (c) BlazeCode / Ralf Lehmann, 2022.
*
*/

package com.blazecode.tsviewer.util.wear

import android.content.Intent
import com.blazecode.tsviewer.MainActivity
import com.google.android.gms.wearable.DataEventBuffer
import com.google.android.gms.wearable.DataMapItem
import com.google.android.gms.wearable.WearableListenerService

class WearableListenerService: WearableListenerService() {

companion object {
const val LAUNCH_PATH = "/start-activity"
private const val LAUNCH_KEY = "startActivity"
}

override fun onDataChanged(dataEvents: DataEventBuffer) {
super.onDataChanged(dataEvents)

dataEvents.forEach { event ->
event.dataItem.also { item ->
if (item.uri.path!!.compareTo(LAUNCH_PATH) == 0) {
DataMapItem.fromDataItem(item).dataMap.apply {

this@WearableListenerService.startActivity(
Intent(this@WearableListenerService, MainActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
)
}
}
}
}
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
android:title="@string/check_updates"
android:checkable="true"/>

<item
android:id="@+id/action_sync_wearable"
android:title="@string/sync_wearable"
android:checkable="true"/>

<item
android:id="@+id/action_update_check_debug"
android:visible="false"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<string name="licenses">Open Source Licenses</string>
<string name="send_email">Send E-Mail</string>
<string name="check_updates">Auto check for updates</string>
<string name="sync_wearable">Sync with Wearable</string>

<!-- GRAPH -->
<string name="not_enough_data">Not enough data collected</string>
Expand Down
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
buildscript {
ext {
ABOUT_LIBRARIES_VERSION = "10.4.0"
compose_version = '1.4.0-alpha02'
wear_compose_version = '1.1.0-rc01'
}
repositories {
google()
Expand All @@ -18,8 +20,8 @@ buildscript {
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"

//ABOUT LIBRARIES
classpath "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:$ABOUT_LIBRARIES_VERSION"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#Thu Dec 02 15:53:30 CET 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ dependencyResolutionManagement {
}
rootProject.name = "TSViewer"
include ':app'
include ':wear'
1 change: 1 addition & 0 deletions wear/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
77 changes: 77 additions & 0 deletions wear/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-parcelize'
}

android {
namespace 'com.blazecode.tsviewer'
compileSdkVersion 33

defaultConfig {
applicationId "com.blazecode.tsviewer"
minSdkVersion 26
targetSdkVersion 30
versionCode 1
versionName "1.0"
vectorDrawables {
useSupportLibrary true
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.debug
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.1.1'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.9.0'
implementation 'com.google.android.gms:play-services-wearable:18.0.0'
implementation 'androidx.percentlayout:percentlayout:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.wear.compose:compose-material:$wear_compose_version"
implementation "androidx.wear.compose:compose-foundation:$wear_compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.6.1'
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"

// COMPLICATIONS
implementation "androidx.wear.watchface:watchface-complications-data-source-ktx:1.1.1"

//DATA STORE
implementation("androidx.datastore:datastore-preferences:1.0.0")

// NAVIGATION
implementation("androidx.navigation:navigation-compose:2.5.3")
implementation "com.google.accompanist:accompanist-navigation-animation:0.27.0"
}
Loading

0 comments on commit 222b3ca

Please sign in to comment.