Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
lbr38 committed Dec 8, 2024
1 parent c03a78e commit 7b25bce
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 140 deletions.
6 changes: 0 additions & 6 deletions android/motionUI/.idea/kotlinc.xml

This file was deleted.

21 changes: 4 additions & 17 deletions android/motionUI/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import java.io.FileInputStream

plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-parcelize'
}

// Ici on importe les secrets à partir d'un fichier dédié (keystore.properties)
Expand All @@ -13,17 +11,16 @@ def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
namespace 'app.motionui.android'
compileSdk 34

signingConfigs {
release {
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
keyPassword keystoreProperties['keyPassword']
keyAlias keystoreProperties['keyAlias']
}
}
}
namespace 'app.motionui.android'
compileSdk 34

defaultConfig {
applicationId "app.motionui.android"
Expand All @@ -46,25 +43,15 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.security:security-crypto:1.1.0-alpha03'
implementation "androidx.core:core-splashscreen:1.0.0"
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.webkit:webkit:1.6.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,6 @@
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.annotation.NonNull;
// WebSocket & Notifications
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import androidx.webkit.WebViewAssetLoader;
import okio.ByteString;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

/**
* MainActivity
Expand All @@ -46,11 +33,6 @@ public class MainActivity extends AppCompatActivity {
private String url;
// private Integer authTry = 0;

// Notification channel
private static final String CHANNEL_ID = "motionUI_notifications";
private static final int NOTIFICATION_ID = 1;
private WebSocket webSocket;

/**
* JavaScript interface to retrieve username and password from the login form when the user submits it and save them in SharedPreferences
*/
Expand Down Expand Up @@ -262,98 +244,13 @@ public void onDownloadStart(String url, String userAgent, String contentDisposit
downloadManager.enqueue(request);
}
});

createNotificationChannel();
connectWebSocket();

/**
* Load motionUI URL in the WebView
*/
webView.loadUrl(url);
}





private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "MotionUI Notifications";
String description = "Channel for MotionUI notifications";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);

NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}

private void showNotification(String title, String message) {
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(title)
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(pendingIntent)
.setAutoCancel(true);

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(NOTIFICATION_ID, builder.build());
}

private void connectWebSocket() {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url("ws://yourserver.com/websocket").build();
webSocket = client.newWebSocket(request, new WebSocketListener() {
@Override
public void onOpen(WebSocket webSocket, okhttp3.Response response) {
// WebSocket connection opened
// TODO debug
showNotification("WS Opened", text);
}

@Override
public void onMessage(WebSocket webSocket, String text) {
// Handle text message
showNotification("New Message", text);
}

@Override
public void onMessage(WebSocket webSocket, ByteString bytes) {
// Handle binary message
showNotification("New Message", bytes.hex());
}

@Override
public void onClosing(WebSocket webSocket, int code, String reason) {
webSocket.close(1000, null);
// WebSocket connection closing
// TODO debug
showNotification("WS Closed", text);
}

@Override
public void onFailure(WebSocket webSocket, Throwable t, okhttp3.Response response) {
// WebSocket connection failed
t.printStackTrace();
// TODO debug
showNotification("WS Failed", text);
}
});

client.dispatcher().executorService().shutdown();
}






/**
* Prevent the back-button from closing the app
*/
Expand Down
Binary file not shown.
15 changes: 1 addition & 14 deletions android/motionUI/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.8.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

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

0 comments on commit 7b25bce

Please sign in to comment.