Skip to content

Commit 0578d4c

Browse files
authored
Cleanup (#1)
1 parent d211b10 commit 0578d4c

File tree

7 files changed

+73
-49
lines changed

7 files changed

+73
-49
lines changed

app/build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ dependencies {
4343
implementation(libs.androidx.core.ktx)
4444
implementation(libs.androidx.appcompat)
4545
implementation(libs.material)
46-
implementation(libs.androidx.constraintlayout)
47-
implementation(libs.androidx.navigation.fragment.ktx)
48-
implementation(libs.androidx.navigation.ui.ktx)
4946
testImplementation(libs.junit)
5047
androidTestImplementation(libs.androidx.junit)
5148
androidTestImplementation(libs.androidx.espresso.core)

app/src/main/AndroidManifest.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
<?xml version="1.0" encoding="utf-8"?>
21
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
32
xmlns:tools="http://schemas.android.com/tools">
43

5-
<uses-permission android:name="android.permission.INTERNET" />
6-
74
<application
85
android:allowBackup="true"
96
android:dataExtractionRules="@xml/data_extraction_rules"
@@ -25,12 +22,21 @@
2522
<category android:name="android.intent.category.LAUNCHER" />
2623
</intent-filter>
2724

25+
<!-- Intent filter for single file sharing -->
2826
<intent-filter>
2927
<action android:name="android.intent.action.SEND" />
3028
<category android:name="android.intent.category.DEFAULT" />
3129
<data android:mimeType="*/*" />
3230
</intent-filter>
3331

32+
<!-- Intent filter for multiple file sharing -->
33+
<intent-filter>
34+
<action android:name="android.intent.action.SEND_MULTIPLE" />
35+
<category android:name="android.intent.category.DEFAULT" />
36+
<data android:mimeType="*/*" />
37+
</intent-filter>
38+
39+
<!-- Intent filter for view actions -->
3440
<intent-filter>
3541
<action android:name="android.intent.action.VIEW" />
3642

@@ -40,6 +46,7 @@
4046
<data android:mimeType="*/*" />
4147
</intent-filter>
4248

49+
<!-- Intent filter for deep links -->
4350
<intent-filter>
4451
<action android:name="android.intent.action.VIEW" />
4552

@@ -53,4 +60,6 @@
5360

5461
</application>
5562

63+
<uses-permission android:name="android.permission.INTERNET" />
64+
5665
</manifest>

app/src/main/java/com/djangofiles/djangofiles/MainActivity.kt

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.content.ClipboardManager
66
import android.content.DialogInterface
77
import android.content.Intent
88
import android.net.Uri
9+
import android.os.Build
910
import android.os.Bundle
1011
import android.provider.OpenableColumns
1112
import android.util.Log
@@ -53,15 +54,15 @@ class MainActivity : AppCompatActivity() {
5354
binding = ActivityMainBinding.inflate(layoutInflater)
5455
setContentView(binding.root)
5556

56-
webView = findViewById(R.id.webview)
57+
webView = binding.webview
5758
webView.settings.domStorageEnabled = true
5859
webView.settings.javaScriptEnabled = true
5960
webView.settings.userAgentString = "DjangoFiles Android"
6061
webView.addJavascriptInterface(WebAppInterface(this), "Android")
6162
webView.setWebViewClient(MyWebViewClient())
6263

6364
ViewCompat.setOnApplyWindowInsetsListener(
64-
findViewById(R.id.main)
65+
binding.main
6566
) { v: View, insets: WindowInsetsCompat ->
6667
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
6768
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
@@ -90,7 +91,6 @@ class MainActivity : AppCompatActivity() {
9091
}
9192

9293
private fun handleIntent(intent: Intent) {
93-
// TODO: Need to do some serious debugging on intent handling...
9494
val uri = intent.data
9595
Log.d("handleIntent", "uri: $uri")
9696

@@ -158,29 +158,61 @@ class MainActivity : AppCompatActivity() {
158158
} else if (Intent.ACTION_SEND == action && mimeType != null) {
159159
Log.d("handleIntent", "ACTION_SEND")
160160
if ("text/plain" == mimeType) {
161+
val sharedText: String? = intent.getStringExtra(Intent.EXTRA_TEXT)
162+
if (sharedText != null) {
163+
Log.d("handleIntent", "Received text/plain: $sharedText")
164+
if (sharedText.startsWith("content://")) {
165+
val fileUri = Uri.parse(sharedText)
166+
Log.d("handleIntent", "Received URI: $fileUri")
167+
} else {
168+
Log.d("handleIntent", "Received text/plain: $sharedText")
169+
}
170+
}
171+
val preferences = getSharedPreferences(PREFS_NAME, MODE_PRIVATE)
172+
val savedUrl = preferences.getString(URL_KEY, null)
173+
Log.d("handleIntent", "savedUrl: ${savedUrl}/paste/")
174+
webView.loadUrl("${savedUrl}/paste/")
161175
Toast.makeText(
162176
this,
163177
this.getString(R.string.tst_not_implemented),
164178
Toast.LENGTH_SHORT
165179
).show()
166180
} else {
167-
val fileUri = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)
181+
// val fileUri = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)
182+
val fileUri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
183+
intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri::class.java)
184+
} else {
185+
@Suppress("DEPRECATION")
186+
intent.getParcelableExtra(Intent.EXTRA_STREAM)
187+
}
168188
if (fileUri != null) {
169189
processSharedFile(fileUri)
190+
} else {
191+
Log.w("handleIntent", "URI is NULL")
170192
}
171193
}
172194
} else if (Intent.ACTION_SEND_MULTIPLE == action) {
173195
Log.d("handleIntent", "ACTION_SEND_MULTIPLE")
174-
val fileUris = intent.getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM)
196+
// val fileUris = intent.getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM)
197+
val fileUris = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
198+
intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM, Uri::class.java)
199+
} else {
200+
@Suppress("DEPRECATION")
201+
intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM)
202+
}
175203
if (fileUris != null) {
176204
for (fileUri in fileUris) {
177205
processSharedFile(fileUri)
178206
}
207+
} else {
208+
Log.w("handleIntent", "URI is NULL")
179209
}
210+
} else {
211+
Toast.makeText(this, "Unknown Intent!", Toast.LENGTH_SHORT).show()
212+
Log.w("handleIntent", "All Intent Types Processed. No Match!")
180213
}
181214
}
182215

183-
184216
private fun showSettingsDialog() {
185217
val preferences = getSharedPreferences(PREFS_NAME, MODE_PRIVATE)
186218
val savedUrl = preferences.getString(URL_KEY, null)

app/src/main/java/com/djangofiles/djangofiles/WebAppInterface.kt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,30 @@ import android.webkit.JavascriptInterface
66
import android.widget.Toast
77

88
class WebAppInterface
9-
internal constructor(var mContext: Context) {
9+
internal constructor(private var context: Context) {
10+
companion object {
11+
private const val PREFS_NAME = "AppPreferences"
12+
private const val TOKEN_KEY = "auth_token"
13+
}
14+
1015
@JavascriptInterface
1116
fun showToast(toast: String?) {
12-
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show()
17+
Toast.makeText(context, toast, Toast.LENGTH_SHORT).show()
1318
}
1419

1520
@JavascriptInterface
1621
fun receiveAuthToken(authToken: String) {
1722
Log.d("receiveAuthToken", "Received auth token: $authToken")
18-
Log.d("receiveAuthToken", "PREFS_NAME: $PREFS_NAME")
19-
val preferences = mContext.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
20-
Log.d("receiveAuthToken", "TOKEN_KEY: $TOKEN_KEY")
21-
preferences.edit().putString(TOKEN_KEY, authToken).apply()
22-
// SharedPreferences.Editor editor = preferences.edit();
23-
// editor.putString(TOKEN_KEY, authToken);
24-
// editor.apply();
25-
Log.d("receiveAuthToken", "Auth Token Saved.")
26-
}
2723

28-
companion object {
29-
private const val PREFS_NAME = "AppPreferences"
30-
private const val TOKEN_KEY = "auth_token"
24+
val preferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
25+
val currentToken = preferences.getString(TOKEN_KEY, null)
26+
27+
if (currentToken != authToken) {
28+
preferences.edit().putString(TOKEN_KEY, authToken).apply()
29+
Log.d("receiveAuthToken", "Auth Token Updated.")
30+
} else {
31+
Log.d("receiveAuthToken", "Auth Token Not Changes.")
32+
}
3133
}
34+
3235
}
Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout
3-
xmlns:android="http://schemas.android.com/apk/res/android"
4-
xmlns:tools="http://schemas.android.com/tools"
5-
xmlns:app="http://schemas.android.com/apk/res-auto"
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
63
android:id="@+id/main"
74
android:layout_width="match_parent"
8-
android:layout_height="match_parent"
9-
tools:context=".MainActivity">
5+
android:layout_height="match_parent">
106

117
<WebView
128
android:id="@+id/webview"
13-
android:layout_width="0dp"
14-
android:layout_height="0dp"
15-
android:layout_marginTop="16dp"
16-
app:layout_constraintBottom_toBottomOf="parent"
17-
app:layout_constraintStart_toStartOf="parent"
18-
app:layout_constraintEnd_toEndOf="parent"
19-
app:layout_constraintTop_toTopOf="parent" />
20-
21-
</androidx.constraintlayout.widget.ConstraintLayout>
9+
android:layout_width="match_parent"
10+
android:layout_height="match_parent" />
11+
</FrameLayout>

app/src/main/res/values/themes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<resources xmlns:tools="http://schemas.android.com/tools">
1+
<resources>
22
<!-- Base application theme. -->
33
<style name="Base.Theme.djangofiles" parent="Theme.Material3.DayNight.NoActionBar">
44
<!-- Customize your light theme here. -->

gradle/libs.versions.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ junitVersion = "1.2.1"
77
espressoCore = "3.6.1"
88
appcompat = "1.7.0"
99
material = "1.12.0"
10-
constraintlayout = "2.2.1"
11-
navigationFragmentKtx = "2.6.0"
12-
navigationUiKtx = "2.6.0"
1310

1411
[libraries]
1512
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@@ -18,11 +15,7 @@ androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "j
1815
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
1916
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
2017
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
21-
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
22-
androidx-navigation-fragment-ktx = { group = "androidx.navigation", name = "navigation-fragment-ktx", version.ref = "navigationFragmentKtx" }
23-
androidx-navigation-ui-ktx = { group = "androidx.navigation", name = "navigation-ui-ktx", version.ref = "navigationUiKtx" }
2418

2519
[plugins]
2620
android-application = { id = "com.android.application", version.ref = "agp" }
2721
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
28-

0 commit comments

Comments
 (0)