diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..7643783
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..b86273d
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml
new file mode 100644
index 0000000..b268ef3
--- /dev/null
+++ b/.idea/deploymentTargetSelector.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
new file mode 100644
index 0000000..6d0ee1c
--- /dev/null
+++ b/.idea/kotlinc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 24cdfad..6088e83 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -36,11 +36,14 @@ android {
}
buildFeatures {
compose = true
+ viewBinding = true
}
}
dependencies {
-
+ implementation("com.squareup.okhttp3:okhttp:4.9.3")
+ implementation(libs.okhttp)
+ implementation(libs.kotlin.stdlib)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
@@ -49,6 +52,7 @@ dependencies {
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
+ implementation(libs.androidx.appcompat)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 7908767..692ffb6 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -2,6 +2,10 @@
+
+
+
+
@@ -23,7 +26,7 @@
-
+
diff --git a/app/src/main/java/org/seanandroid/mealieurlshare/MainActivity.kt b/app/src/main/java/org/seanandroid/mealieurlshare/MainActivity.kt
index 4ca90eb..cea521d 100644
--- a/app/src/main/java/org/seanandroid/mealieurlshare/MainActivity.kt
+++ b/app/src/main/java/org/seanandroid/mealieurlshare/MainActivity.kt
@@ -1,47 +1,31 @@
package org.seanandroid.mealieurlshare
import android.os.Bundle
-import androidx.activity.ComponentActivity
-import androidx.activity.compose.setContent
-import androidx.activity.enableEdgeToEdge
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.padding
-import androidx.compose.material3.Scaffold
-import androidx.compose.material3.Text
-import androidx.compose.runtime.Composable
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.tooling.preview.Preview
-import org.seanandroid.mealieurlshare.ui.theme.MealieURLShareTheme
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import org.seanandroid.mealieurlshare.databinding.ActivityMainBinding
+
+class MainActivity : AppCompatActivity() {
+
+ private lateinit var binding: ActivityMainBinding
-class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- enableEdgeToEdge()
- setContent {
- MealieURLShareTheme {
- Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
- Greeting(
- name = "Android",
- modifier = Modifier.padding(innerPadding)
- )
- }
+ binding = ActivityMainBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+
+ binding.saveButton.setOnClickListener {
+ val url = binding.urlEditText.text.toString()
+ val token = binding.tokenEditText.text.toString()
+ // Save URL and TOKEN in SharedPreferences
+ val sharedPreferences = getSharedPreferences("app_prefs", MODE_PRIVATE)
+ with(sharedPreferences.edit()) {
+ putString("url", url)
+ putString("token", token)
+ apply()
}
+ // Show a Toast message to confirm saving
+ Toast.makeText(this, "URL and TOKEN saved", Toast.LENGTH_SHORT).show()
}
}
}
-
-@Composable
-fun Greeting(name: String, modifier: Modifier = Modifier) {
- Text(
- text = "Hello $name!",
- modifier = modifier
- )
-}
-
-@Preview(showBackground = true)
-@Composable
-fun GreetingPreview() {
- MealieURLShareTheme {
- Greeting("Android")
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/org/seanandroid/mealieurlshare/ShareActivity.kt b/app/src/main/java/org/seanandroid/mealieurlshare/ShareActivity.kt
new file mode 100644
index 0000000..ac42eb4
--- /dev/null
+++ b/app/src/main/java/org/seanandroid/mealieurlshare/ShareActivity.kt
@@ -0,0 +1,109 @@
+package org.seanandroid.mealieurlshare
+
+import android.app.NotificationChannel
+import android.app.NotificationManager
+import android.content.Intent
+import android.os.Bundle
+import android.os.Handler
+import android.os.Looper
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import androidx.core.app.NotificationCompat
+import okhttp3.Call
+import okhttp3.Callback
+import okhttp3.FormBody
+import okhttp3.OkHttpClient
+import okhttp3.Request
+import okhttp3.Response
+import java.io.IOException
+
+class ShareActivity : AppCompatActivity() {
+
+ private val client = OkHttpClient()
+ private lateinit var handler: Handler
+ private var isRequestRunning = false
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ // Get the shared preferences
+ val sharedPreferences = getSharedPreferences("app_prefs", MODE_PRIVATE)
+ val url = sharedPreferences.getString("url", null)
+ val token = sharedPreferences.getString("token", null)
+
+ // Get the shared text
+ val sharedText = intent.getStringExtra(Intent.EXTRA_TEXT)
+
+ if (url != null && token != null && sharedText != null) {
+ sendPostRequest(url, token, sharedText)
+ } else {
+ Toast.makeText(this, "URL or TOKEN not set", Toast.LENGTH_SHORT).show()
+ finish()
+ }
+ }
+
+ private fun sendPostRequest(url: String, token: String, sharedText: String) {
+ isRequestRunning = true
+ val fullUrl = "$url/api/recipe/create/url"
+ val requestBody = FormBody.Builder()
+ .add("data", sharedText)
+ .build()
+
+ val request = Request.Builder()
+ .url(fullUrl)
+ .addHeader("Authorization", "Bearer $token")
+ .post(requestBody)
+ .build()
+
+ handler = Handler(Looper.getMainLooper())
+ handler.postDelayed({
+ if (isRequestRunning) {
+ isRequestRunning = false
+ sendNotification("Request timed out")
+ finish()
+ }
+ }, 30000) // 30 seconds timeout
+
+ client.newCall(request).enqueue(object : Callback {
+ override fun onFailure(call: Call, e: IOException) {
+ isRequestRunning = false
+ sendNotification("Request failed: ${e.message}")
+ finish()
+ }
+
+ override fun onResponse(call: Call, response: Response) {
+ isRequestRunning = false
+ if (response.isSuccessful) {
+ sendNotification("Request successful!")
+ } else {
+ sendNotification("Request failed: ${response.message}")
+ }
+ finish()
+ }
+ })
+ }
+
+ private fun sendNotification(message: String) {
+ val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
+ val channelId = "mealie_url_share_channel"
+
+ // Create the notification channel for Android O and above
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
+ val channel = NotificationChannel(
+ channelId,
+ "Mealie URL Share Notifications",
+ NotificationManager.IMPORTANCE_DEFAULT
+ )
+ notificationManager.createNotificationChannel(channel)
+ }
+
+ val notification = NotificationCompat.Builder(this, channelId)
+ .setContentTitle("Mealie URL Share")
+ .setContentText(message)
+ //.setSmallIcon(R.drawable.ic_notification) // Replace with your notification icon
+ .setAutoCancel(true)
+ .build()
+
+ notificationManager.notify(1, notification)
+ }
+}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..084e52e
--- /dev/null
+++ b/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 60cfe30..975a2fd 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -8,6 +8,7 @@ espressoCore = "3.5.1"
lifecycleRuntimeKtx = "2.6.1"
activityCompose = "1.8.0"
composeBom = "2024.04.01"
+appcompat = "1.7.0"
[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@@ -24,6 +25,9 @@ androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-toolin
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
+androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
+kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib" }
+okhttp = { module = "com.squareup.okhttp3:okhttp" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }