Skip to content

Commit 15d7c76

Browse files
authored
Fix Stats Update and Add Database Migration (#62)
1 parent 441c3f2 commit 15d7c76

File tree

6 files changed

+91
-68
lines changed

6 files changed

+91
-68
lines changed

README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
- [Install](#Install)
1818
- [Setup](#Setup)
19+
- [Usage](#Usage)
1920
- [Features](#Features)
2021
- [Planned](#Planned)
2122
- [Known Issues](#Known-Issues)
23+
- [Troubleshooting](#Troubleshooting)
2224
- [Screenshots](#Screenshots)
2325
- [Development](#Development)
2426
- [Android Studio](#Android-Studio)
@@ -43,9 +45,11 @@ Screenshots can be found on the website: https://django-files.github.io/android/
4345

4446
## Install
4547

46-
> [!TIP]
48+
> [!IMPORTANT]
4749
> Google Play is starting Closed Testing. To be included contact us on [Discord](https://discord.gg/wXy6m2X8wY).
4850
51+
_If you are unsure how to install, [Obtainium](https://github.com/ImranR98/Obtainium) is highly recommended..._
52+
4953
<a title="Get on GitHub" href="https://github.com/django-files/android-client/releases/latest/download/app-release.apk">
5054
<img alt="GitHub" height="76" src="https://raw.githubusercontent.com/smashedr/repo-images/refs/heads/master/android/get/github.png"></a>
5155
<a title="Get onObtainium" href="https://apps.obtainium.imranr.dev/redirect?r=obtainium://add/https://github.com/django-files/android-client">
@@ -81,24 +85,30 @@ For more information, see [Release through a website](https://developer.android.
8185

8286
### Setup
8387

88+
You can log in via password, OAuth, or QR Code.
89+
90+
#### QR Code Authentication
91+
8492
1. [Install](#Install) and open the app on your device.
8593
2. Go to the Django Files User Settings, and
8694
- Scan the QR Code with your Phone
8795
- Click the link from your Phone
8896
3. Done.
8997

90-
or
98+
#### Normal Login
9199

92100
1. [Install](#Install) and open the app on your device.
93101
2. Enter the URL to your Django Files server.
94102
3. Log in as you normally would on the website.
95103
4. Done.
96104

105+
### Usage
106+
97107
To use, share or open any file and choose the Django Files app.
98108
The app will then upload the file to your Django Files server.
99109
Additionally, the URL is copied to the clipboard and the preview show in the app.
100110

101-
> [!NOTE]
111+
> [!TIP]
102112
> Swipe from the left to access the Android menu.
103113
104114
## Features
@@ -114,10 +124,15 @@ Additionally, the URL is copied to the clipboard and the preview show in the app
114124
### Planned
115125

116126
- File Upload
117-
- Add More Upload Options
127+
- Add Custom Upload Options
128+
- Add Default Upload Options
118129
- File List
130+
- Download Manager
131+
- Album Filter Dropdown
132+
- List or Grid Display Option
119133
- Response Caching for Infinite Scroll
120134
- File List Preview
135+
- Media Swiper
121136
- File Options
122137
- PDF Previews
123138

@@ -127,7 +142,13 @@ Additionally, the URL is copied to the clipboard and the preview show in the app
127142
- Uploading files from the website works; however, taking picture/recording does not.
128143
- Logging out and deleting servers may have some unexpected results, but should work.
129144

130-
Note: If the app gets in a bad state, clear the app data or reinstall the application.
145+
### Troubleshooting
146+
147+
Try these steps in order:
148+
149+
1. Fully close the app and re-open it again.
150+
2. Clear the cache storage in App Settings.
151+
3. Clear the App Data or re-install.
131152

132153
For more planned features you can check out the internal [TODO.md](TODO.md).
133154

app/src/main/java/com/djangofiles/djangofiles/db/ServerDao.kt

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import androidx.room.Query
1111
import androidx.room.Room
1212
import androidx.room.RoomDatabase
1313
import androidx.room.Upsert
14-
import androidx.room.migration.Migration
15-
import androidx.sqlite.db.SupportSQLiteDatabase
14+
15+
//import androidx.room.migration.Migration
16+
//import androidx.sqlite.db.SupportSQLiteDatabase
1617

1718

1819
@Dao
@@ -35,6 +36,9 @@ interface ServerDao {
3536
@Upsert
3637
fun addOrUpdate(server: Server)
3738

39+
@Query("UPDATE server SET size = :size, count = :count, shorts = :shorts, humanSize = :humanSize WHERE url = :url")
40+
fun updateStats(url: String, size: Long, count: Int, shorts: Int, humanSize: String)
41+
3842
@Query("UPDATE server SET active = 1 WHERE url = :url")
3943
fun activate(url: String)
4044

@@ -55,22 +59,22 @@ data class Server(
5559
)
5660

5761

58-
@Database(entities = [Server::class], version = 2)
62+
@Database(entities = [Server::class], version = 3)
5963
abstract class ServerDatabase : RoomDatabase() {
6064
abstract fun serverDao(): ServerDao
6165

6266
companion object {
6367
@Volatile
6468
private var instance: ServerDatabase? = null
6569

66-
private val MIGRATION_1_2 = object : Migration(1, 2) {
67-
override fun migrate(database: SupportSQLiteDatabase) {
68-
database.execSQL("ALTER TABLE Server ADD COLUMN size INTEGER")
69-
database.execSQL("ALTER TABLE Server ADD COLUMN count INTEGER")
70-
database.execSQL("ALTER TABLE Server ADD COLUMN shorts INTEGER")
71-
database.execSQL("ALTER TABLE Server ADD COLUMN humanSize TEXT")
72-
}
73-
}
70+
//private val MIGRATION_1_2 = object : Migration(1, 2) {
71+
// override fun migrate(database: SupportSQLiteDatabase) {
72+
// database.execSQL("ALTER TABLE Server ADD COLUMN size INTEGER")
73+
// database.execSQL("ALTER TABLE Server ADD COLUMN count INTEGER")
74+
// database.execSQL("ALTER TABLE Server ADD COLUMN shorts INTEGER")
75+
// database.execSQL("ALTER TABLE Server ADD COLUMN humanSize TEXT")
76+
// }
77+
//}
7478

7579
fun getInstance(context: Context): ServerDatabase =
7680
instance ?: synchronized(this) {
@@ -79,8 +83,8 @@ abstract class ServerDatabase : RoomDatabase() {
7983
ServerDatabase::class.java,
8084
"server-database"
8185
)
82-
//.fallbackToDestructiveMigration(true) // Destructive Operation
83-
.addMigrations(MIGRATION_1_2)
86+
//.addMigrations(MIGRATION_1_2)
87+
.fallbackToDestructiveMigration(true) // Destructive Operation
8488
.build().also { instance = it }
8589
}
8690
}

app/src/main/java/com/djangofiles/djangofiles/ui/files/FilesFragment.kt

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class FilesFragment : Fragment() {
7777
Log.d("File[onCreateView]", "savedInstanceState: ${savedInstanceState?.size()}")
7878

7979
//enterTransition = Slide(Gravity.END)
80-
returnTransition = Slide(Gravity.END)
80+
//returnTransition = Slide(Gravity.END)
8181

8282
_binding = FragmentFilesBinding.inflate(inflater, container, false)
8383
val root: View = binding.root
@@ -90,6 +90,30 @@ class FilesFragment : Fragment() {
9090
_binding = null
9191
}
9292

93+
//override fun onStart() {
94+
// Log.d("File[onStart]", "ON START")
95+
// super.onStart()
96+
// val request = NetworkRequest.Builder().build()
97+
// connectivityManager.registerNetworkCallback(request, networkCallback)
98+
//}
99+
100+
//override fun onStop() {
101+
// Log.d("File[onStop]", "ON STOP")
102+
// super.onStop()
103+
// connectivityManager.unregisterNetworkCallback(networkCallback)
104+
//}
105+
106+
override fun onPause() {
107+
Log.d("File[onPause]", "ON PAUSE")
108+
super.onPause()
109+
}
110+
111+
override fun onResume() {
112+
Log.d("File[onResume]", "ON RESUME")
113+
super.onResume()
114+
checkMetered()
115+
}
116+
93117
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
94118
super.onViewCreated(view, savedInstanceState)
95119
//Log.d("File[onViewCreated]", "savedInstanceState: ${savedInstanceState?.size()}")
@@ -499,7 +523,7 @@ class FilesFragment : Fragment() {
499523
}
500524
}
501525
Log.d("loadingSpinner", "loadingSpinner: View.GONE")
502-
binding.loadingSpinner.visibility = View.GONE
526+
_binding?.loadingSpinner?.visibility = View.GONE
503527
if (errorCount > 5) {
504528
atEnd = true
505529
viewModel.atEnd.value = atEnd
@@ -510,30 +534,6 @@ class FilesFragment : Fragment() {
510534
}
511535
}
512536

513-
//override fun onStart() {
514-
// Log.d("File[onStart]", "ON START")
515-
// super.onStart()
516-
// val request = NetworkRequest.Builder().build()
517-
// connectivityManager.registerNetworkCallback(request, networkCallback)
518-
//}
519-
520-
//override fun onStop() {
521-
// Log.d("File[onStop]", "ON STOP")
522-
// super.onStop()
523-
// connectivityManager.unregisterNetworkCallback(networkCallback)
524-
//}
525-
526-
override fun onPause() {
527-
Log.d("File[onPause]", "ON PAUSE")
528-
super.onPause()
529-
}
530-
531-
override fun onResume() {
532-
Log.d("File[onResume]", "ON RESUME")
533-
super.onResume()
534-
checkMetered()
535-
}
536-
537537
private fun checkMetered(metered: Boolean? = null) {
538538
Log.d("File[checkMetered]", "checkMetered")
539539
val previewMetered = metered ?: preferences.getBoolean("file_preview_metered", false)

app/src/main/java/com/djangofiles/djangofiles/ui/login/AuthorizeFragment.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class AuthorizeFragment : Fragment() {
3636
private var _binding: FragmentAuthorizeBinding? = null
3737
private val binding get() = _binding!!
3838

39+
private val navController by lazy { findNavController() }
3940
private val preferences by lazy { PreferenceManager.getDefaultSharedPreferences(requireContext()) }
4041

4142
override fun onCreate(savedInstanceState: Bundle?) {
@@ -144,19 +145,18 @@ class AuthorizeFragment : Fragment() {
144145
Toast.makeText(requireContext(), "Login Successful", Toast.LENGTH_LONG).show()
145146
withContext(Dispatchers.Main) {
146147
Log.d("Authorize[addServerBtn]", "navigate: nav_item_home")
147-
findNavController().navigate(
148-
R.id.nav_item_home, null, NavOptions.Builder()
149-
.setPopUpTo(R.id.nav_item_authorize, true)
148+
navController.navigate(
149+
navController.graph.startDestinationId, null, NavOptions.Builder()
150+
.setPopUpTo(navController.graph.id, true)
150151
.build()
151152
)
152153
}
153154
}
154155
}
155156

156-
157157
binding.gotoLoginBtn.setOnClickListener {
158158
Log.d("Authorize[gotoLoginBtn]", "setOnClickListener")
159-
findNavController().navigate(R.id.nav_item_login)
159+
navController.navigate(R.id.nav_item_login)
160160
}
161161
}
162162

app/src/main/java/com/djangofiles/djangofiles/work/DailyWorker.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import androidx.preference.PreferenceManager
99
import androidx.work.CoroutineWorker
1010
import androidx.work.WorkerParameters
1111
import com.djangofiles.djangofiles.ServerApi
12-
import com.djangofiles.djangofiles.db.Server
1312
import com.djangofiles.djangofiles.db.ServerDao
1413
import com.djangofiles.djangofiles.db.ServerDatabase
1514
import com.djangofiles.djangofiles.ui.files.getAlbums
@@ -96,14 +95,13 @@ suspend fun Context.updateStats(): Boolean {
9695
Log.d("updateStats", "stats: $stats")
9796
if (stats != null) {
9897
val dao: ServerDao = ServerDatabase.getInstance(this).serverDao()
99-
dao.addOrUpdate(
100-
Server(
101-
url = savedUrl,
102-
size = stats.size,
103-
count = stats.count,
104-
shorts = stats.shorts,
105-
humanSize = stats.humanSize,
106-
)
98+
// TODO: Add a helper function for this...
99+
dao.updateStats(
100+
url = savedUrl,
101+
size = stats.size,
102+
count = stats.count,
103+
shorts = stats.shorts,
104+
humanSize = stats.humanSize,
107105
)
108106
Log.d("updateStats", "dao.addOrUpdate: DONE")
109107

gradle/libs.versions.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ coreKtx = "1.16.0"
66
junit = "4.13.2"
77
junitVersion = "1.2.1"
88
espressoCore = "3.6.1"
9-
appcompat = "1.7.0"
9+
appcompat = "1.7.1"
1010
material = "1.12.0"
1111

1212
activity = "1.10.1"
1313
preferenceKtx = "1.2.1"
14-
lifecycleLivedataKtx = "2.9.0"
15-
lifecycleViewmodelKtx = "2.9.0"
16-
navigationFragmentKtx = "2.9.0"
17-
navigationUiKtx = "2.9.0"
14+
lifecycleLivedataKtx = "2.9.1"
15+
lifecycleViewmodelKtx = "2.9.1"
16+
navigationFragmentKtx = "2.9.1"
17+
navigationUiKtx = "2.9.1"
1818
swiperefreshlayout = "1.1.0"
19-
workRuntimeKtx = "2.10.1"
19+
workRuntimeKtx = "2.10.2"
2020

21-
googleServices = "4.4.2"
22-
firebaseBom = "33.14.0"
23-
crashlyticsPlugin = "3.0.3"
21+
googleServices = "4.4.3"
22+
firebaseBom = "33.16.0"
23+
crashlyticsPlugin = "3.0.4"
2424

2525
okhttp = "4.12.0"
2626
retrofit = "3.0.0"
2727
moshiKotlinCodegen = "1.15.2"
28-
room = "2.7.1"
28+
room = "2.7.2"
2929
glide = "5.0.0-rc01"
3030
media3 = "1.7.1"
3131

0 commit comments

Comments
 (0)