Skip to content

Commit 6ea993d

Browse files
authored
Merge messages into main
Merge Messages feature
2 parents 4db5a11 + a628680 commit 6ea993d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3777
-459
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ apikeys.properties
1515
.cxx
1616
local.properties
1717
/node_modules
18-
/app/release
18+
/app/release
19+
/.idea/discord.xml

app/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212
applicationId "de.koenidv.sph"
1313
minSdkVersion 23
1414
targetSdkVersion 30
15-
versionCode 125
16-
versionName "1.2.2"
15+
versionCode 130
16+
versionName "1.3-dev"
1717

1818
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1919
}
@@ -68,6 +68,8 @@ dependencies {
6868
implementation 'com.afollestad.material-dialogs:datetime:3.2.1'
6969
implementation 'com.reddit:indicator-fast-scroll:1.3.0'
7070
implementation files('libs/rhino.jar')
71+
implementation 'com.facebook.shimmer:shimmer:0.5.0'
72+
implementation 'com.github.bumptech.glide:glide:4.12.0'
7173

7274
testImplementation 'junit:junit:4.13.1'
7375
androidTestImplementation 'androidx.test.ext:junit:1.1.2'

app/src/main/java/de/koenidv/sph/MainActivity.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,21 @@ import com.google.android.play.core.install.model.AppUpdateType
2828
import com.google.android.play.core.install.model.InstallStatus
2929
import com.google.android.play.core.install.model.UpdateAvailability
3030
import com.google.android.play.core.tasks.Task
31+
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
3132
import de.koenidv.sph.database.ChangesDb
33+
import de.koenidv.sph.database.FunctionTilesDb
3234
import de.koenidv.sph.debugging.Debugger
3335
import de.koenidv.sph.networking.NetworkManager
36+
import de.koenidv.sph.objects.FunctionTile
3437
import de.koenidv.sph.ui.OnboardingActivity
3538
import de.koenidv.sph.ui.OptionsSheet
3639

3740
// Created by koenidv on 05.12.2020.
3841

3942
class MainActivity : AppCompatActivity() {
4043

44+
lateinit var swipeRefresh: SwipeRefreshLayout
45+
4146
override fun onResume() {
4247
ChangesDb.instance!!.removeOld()
4348
super.onResume()
@@ -127,7 +132,7 @@ class MainActivity : AppCompatActivity() {
127132
/*
128133
* Pull to refresh
129134
*/
130-
val swipeRefresh = findViewById<SwipeRefreshLayout>(R.id.swipeRefresh)
135+
swipeRefresh = findViewById<SwipeRefreshLayout>(R.id.swipeRefresh)
131136
swipeRefresh.setOnRefreshListener {
132137
navController.currentDestination?.id?.let { destination ->
133138
// If destination is known, let network manager handle the refreshing
@@ -162,6 +167,14 @@ class MainActivity : AppCompatActivity() {
162167
}
163168
}
164169

170+
/*
171+
* Hide messages tab if messages are not supported
172+
*/
173+
if (!FirebaseRemoteConfig.getInstance().getBoolean("messages_enabled") ||
174+
!FunctionTilesDb.getInstance().supports(FunctionTile.FEATURE_MESSAGES)) {
175+
navView.menu.findItem(R.id.nav_messages).isVisible = false
176+
}
177+
165178
// Save theme color to use somewhere without application context
166179
// Get theme color
167180
val typedValue = TypedValue()
@@ -204,6 +217,11 @@ class MainActivity : AppCompatActivity() {
204217
return navController.navigateUp() || super.onSupportNavigateUp()
205218
}
206219

220+
override fun onSaveInstanceState(outState: Bundle) {
221+
SphPlanner.saveCache()
222+
super.onSaveInstanceState(outState)
223+
}
224+
207225
companion object {
208226
/**
209227
* Prompt user to use AutoSPH if he hasn't accepted this before

app/src/main/java/de/koenidv/sph/SphPlanner.kt

Lines changed: 101 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,30 @@ package de.koenidv.sph
22

33
import android.app.Application
44
import android.content.Context
5+
import android.content.SharedPreferences
6+
import android.widget.Toast
57
import com.androidnetworking.AndroidNetworking
68
import com.facebook.stetho.Stetho
79
import com.facebook.stetho.okhttp3.StethoInterceptor
810
import com.google.firebase.analytics.FirebaseAnalytics
911
import com.google.firebase.ktx.Firebase
1012
import com.google.firebase.remoteconfig.ktx.remoteConfig
13+
import com.google.gson.Gson
14+
import com.google.gson.reflect.TypeToken
1115
import de.koenidv.sph.database.CoursesDb
16+
import de.koenidv.sph.database.FunctionTilesDb
17+
import de.koenidv.sph.database.UsersDb
1218
import de.koenidv.sph.networking.CookieStore
19+
import de.koenidv.sph.networking.Holidays
20+
import de.koenidv.sph.networking.Messages
21+
import de.koenidv.sph.networking.NetworkManager
22+
import de.koenidv.sph.objects.FunctionTile
23+
import kotlinx.coroutines.CoroutineScope
24+
import kotlinx.coroutines.Dispatchers
25+
import kotlinx.coroutines.launch
1326
import okhttp3.OkHttpClient
27+
import java.util.*
28+
1429

1530
// Created by koenidv on 05.12.2020.
1631
class SphPlanner : Application() {
@@ -33,11 +48,31 @@ class SphPlanner : Application() {
3348

3449
// Set application tag for Log
3550
const val TAG = "SPH-Planner"
51+
52+
lateinit var prefs: SharedPreferences
53+
lateinit var cacheprefs: SharedPreferences
54+
55+
/**
56+
* Store some processed values from the db in sharedprefs
57+
*/
58+
fun saveCache() {
59+
// Users
60+
if (cacheprefs.getLong("users_time", 0) == 0L) {
61+
cacheprefs.edit().putLong("users_time", Date().time).apply()
62+
}
63+
if (cacheprefs.getString("users_locale", "") != Locale.getDefault().language) {
64+
cacheprefs.edit().putString("users_locale", Locale.getDefault().language).apply()
65+
}
66+
cacheprefs.edit().putString("users_cache", Gson().toJson(UsersDb.cache)).apply()
67+
}
3668
}
3769

3870
override fun onCreate() {
3971
super.onCreate()
4072

73+
prefs = getSharedPreferences("sharedPrefs", Context.MODE_PRIVATE)
74+
cacheprefs = getSharedPreferences("cache", Context.MODE_PRIVATE)
75+
4176
// Apply default remote configs
4277
Firebase.remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults)
4378

@@ -53,38 +88,78 @@ class SphPlanner : Application() {
5388
.build()
5489
AndroidNetworking.initialize(applicationContext(), okHttpClient)
5590

91+
upgrade()
92+
93+
CoroutineScope(Dispatchers.IO).launch {
94+
// Store some processed values from the db in sharedprefs
95+
// Only restore if not older than a week and same locale
96+
if (Date().time - cacheprefs.getLong("users_time", 0) <
97+
7 * 24 * 360 * 1000 &&
98+
cacheprefs.getString("users_locale", "") ==
99+
Locale.getDefault().language) {
100+
101+
val userstype = object : TypeToken<Map<String, Map<String, String>>>() {}.type
102+
UsersDb.cache = Gson().fromJson(
103+
cacheprefs.getString("users_cache", ""), userstype)
104+
}
105+
}
106+
}
56107

57-
// Upgrade from previous version
108+
// Upgrade from previous version
109+
private fun upgrade() {
58110
val prefs = getSharedPreferences("sharedPrefs", Context.MODE_PRIVATE)
59-
// Upgrade to 120 if user is signed in
60-
if (prefs.getBoolean("introComplete", false) &&
61-
prefs.getInt("appVersion", 0) < 120) {
62-
63-
// Set new analytics properties
64-
val analytics = FirebaseAnalytics.getInstance(this)
65-
// Log school id GA as user property
66-
analytics.setUserProperty(
67-
"school",
68-
prefs.getString("schoolid", "0")!!)
69-
// Log an school course id example to GA
70-
analytics.setUserProperty(
71-
"courseIdExample",
72-
CoursesDb.getInstance().gmbIdExample)
73-
74-
// Attachments were moved to files/attachments/
75-
// Delete all attachments in the old directory, but keep Firebase files
76-
val files = filesDir.listFiles()
77-
if (files != null) {
78-
for (f in files) {
79-
if (!f.name.startsWith("generate") &&
80-
!f.name.startsWith("Persisted") &&
81-
!f.name.startsWith("frc")) {
82-
f.delete()
111+
112+
if (prefs.getBoolean("introComplete", false)) {
113+
114+
// 120: GA props
115+
if (prefs.getInt("appVersion", 0) < 120) {
116+
// Set new analytics properties
117+
val analytics = FirebaseAnalytics.getInstance(this)
118+
// Log school id GA as user property
119+
analytics.setUserProperty(
120+
"school",
121+
prefs.getString("schoolid", "0")!!)
122+
// Log an school course id example to GA
123+
analytics.setUserProperty(
124+
"courseIdExample",
125+
CoursesDb.getInstance().gmbIdExample)
126+
127+
// Attachments were moved to files/attachments/
128+
// Delete all attachments in the old directory, but keep Firebase files
129+
val files = filesDir.listFiles()
130+
if (files != null) {
131+
for (f in files) {
132+
if (!f.name.startsWith("generate") &&
133+
!f.name.startsWith("Persisted") &&
134+
!f.name.startsWith("frc")) {
135+
f.delete()
136+
}
83137
}
84138
}
139+
140+
prefs.edit().putInt("appVersion", 120).apply()
85141
}
86142

87-
prefs.edit().putInt("appVersion", 120).apply()
143+
// 130: Messages, holidays
144+
if (prefs.getInt("appVersion", 0) < 130) {
145+
if (FunctionTilesDb.getInstance().supports(FunctionTile.FEATURE_MESSAGES)) {
146+
Toast.makeText(this, R.string.upgrading_messages, Toast.LENGTH_LONG).show()
147+
NetworkManager().getOwnUserId {
148+
Messages().fetch(archived = true) {
149+
Holidays().fetch {
150+
Toast.makeText(this, R.string.done, Toast.LENGTH_LONG).show()
151+
prefs.edit().putInt("appVersion", 130).apply()
152+
}
153+
}
154+
}
155+
} else {
156+
NetworkManager().getOwnUserId {
157+
Messages().fetch {
158+
prefs.edit().putInt("appVersion", 130).apply()
159+
}
160+
}
161+
}
162+
}
88163
}
89164
}
90165

0 commit comments

Comments
 (0)