Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Game Client Android
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
22
Issues
22
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Akamu
Game Client Android
Commits
374a6c4e
Commit
374a6c4e
authored
Nov 24, 2020
by
Niklas Fix
🎓
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move fetch settings to login and remove from App.java
parent
71343379
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
63 deletions
+62
-63
app/src/main/java/de/akamu/tudarmstadt/App.java
app/src/main/java/de/akamu/tudarmstadt/App.java
+1
-23
app/src/main/java/de/akamu/tudarmstadt/features/login/LoginActivity.kt
...java/de/akamu/tudarmstadt/features/login/LoginActivity.kt
+9
-0
app/src/main/java/de/akamu/tudarmstadt/features/login/LoginContract.kt
...java/de/akamu/tudarmstadt/features/login/LoginContract.kt
+10
-1
app/src/main/java/de/akamu/tudarmstadt/features/login/LoginPresenter.kt
...ava/de/akamu/tudarmstadt/features/login/LoginPresenter.kt
+42
-19
app/src/main/java/de/akamu/tudarmstadt/util/SettingsPresenter.kt
.../main/java/de/akamu/tudarmstadt/util/SettingsPresenter.kt
+0
-20
No files found.
app/src/main/java/de/akamu/tudarmstadt/App.java
View file @
374a6c4e
package
de.akamu.tudarmstadt
;
import
android.app.Application
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.util.Log
;
import
androidx.appcompat.app.AppCompatDelegate
;
import
androidx.preference.PreferenceManager
;
import
com.yariksoffice.lingver.Lingver
;
import
org.jetbrains.annotations.NotNull
;
import
org.json.JSONObject
;
import
java.util.Locale
;
import
java.util.Objects
;
import
de.akamu.tudarmstadt.data.settings.SettingsDataSource
;
import
de.akamu.tudarmstadt.data.settings.SettingsDataSourceImpl
;
import
de.akamu.tudarmstadt.interactors.SettingsInteractor
;
import
de.akamu.tudarmstadt.model.MyObjectBox
;
import
de.akamu.tudarmstadt.util.Constants
;
import
de.akamu.tudarmstadt.util.SettingsPresenter
;
import
io.objectbox.BoxStore
;
/**
...
...
@@ -29,12 +20,11 @@ import io.objectbox.BoxStore;
* application state. It provides access to the ObjectBox database
* and the global settings.
*/
public
class
App
extends
Application
implements
SettingsDataSource
.
FetchSettingsCallback
{
public
class
App
extends
Application
{
private
final
String
TAG
=
"App"
;
private
BoxStore
boxStore
;
SettingsPresenter
settingsPresenter
;
@Override
public
void
onCreate
()
{
...
...
@@ -51,8 +41,6 @@ public class App extends Application implements SettingsDataSource.FetchSettings
AppCompatDelegate
.
setDefaultNightMode
(
AppCompatDelegate
.
MODE_NIGHT_YES
);
}
boxStore
=
MyObjectBox
.
builder
().
androidContext
(
App
.
this
).
build
();
settingsPresenter
=
new
SettingsPresenter
(
new
SettingsInteractor
(
new
SettingsDataSourceImpl
()));
settingsPresenter
.
fetchSettings
(
this
);
}
/**
...
...
@@ -61,14 +49,4 @@ public class App extends Application implements SettingsDataSource.FetchSettings
public
BoxStore
getBoxStore
()
{
return
boxStore
;
}
@Override
public
void
onFetchSettingsSuccess
(
@NotNull
JSONObject
settings
)
{
System
.
out
.
println
(
"Settings fetched successfully."
);
}
@Override
public
void
onFetchSettingsFailed
(
@NotNull
String
reason
)
{
System
.
out
.
println
(
"Fetching settings failed: "
+
reason
);
}
}
\ No newline at end of file
app/src/main/java/de/akamu/tudarmstadt/features/login/LoginActivity.kt
View file @
374a6c4e
...
...
@@ -17,6 +17,7 @@ import de.akamu.tudarmstadt.util.AppUserUtil
import
de.akamu.tudarmstadt.util.Constants
import
de.akamu.tudarmstadt.util.Extensions.Companion.toast
import
kotlinx.android.synthetic.main.activity_login.*
import
org.json.JSONObject
class
LoginActivity
:
BaseActivity
(),
LoginContract
.
View
{
...
...
@@ -124,6 +125,14 @@ class LoginActivity : BaseActivity(), LoginContract.View {
}
}
override
fun
onFetchSettingsSuccess
(
settings
:
JSONObject
)
{
println
(
"Settings fetched successfully."
)
}
override
fun
onFetchSettingsFailed
(
reason
:
String
)
{
println
(
"Fetching settings failed: $reason"
)
}
override
fun
handleUnauthorizedEvent
()
{
//Don't handle unauthorized event
}
...
...
app/src/main/java/de/akamu/tudarmstadt/features/login/LoginContract.kt
View file @
374a6c4e
...
...
@@ -2,9 +2,11 @@ package de.akamu.tudarmstadt.features.login
import
de.akamu.tudarmstadt.BasePresenter
import
de.akamu.tudarmstadt.BaseView
import
de.akamu.tudarmstadt.data.settings.SettingsDataSource
import
de.akamu.tudarmstadt.features.login.LoginContract.Presenter
import
de.akamu.tudarmstadt.features.login.LoginContract.View
import
de.akamu.tudarmstadt.model.User
import
org.json.JSONObject
/**
* Specifies the contract between the [View] and the [Presenter]
...
...
@@ -37,6 +39,10 @@ interface LoginContract {
fun
getLoginToken
()
:
String
fun
getAppUser
()
:
User
?
fun
onFetchSettingsSuccess
(
settings
:
JSONObject
)
fun
onFetchSettingsFailed
(
reason
:
String
)
}
interface
Presenter
:
BasePresenter
{
...
...
@@ -48,6 +54,9 @@ interface LoginContract {
fun
attemptLogin
(
username
:
String
,
password
:
String
)
/** Start the [SignupActivity] **/
fun
startSignup
();
fun
startSignup
()
/** Fetches the settings for the app from server **/
fun
fetchSettings
()
}
}
\ No newline at end of file
app/src/main/java/de/akamu/tudarmstadt/features/login/LoginPresenter.kt
View file @
374a6c4e
...
...
@@ -4,17 +4,22 @@ import androidx.preference.PreferenceManager
import
de.akamu.tudarmstadt.api.AkamuFirebase
import
de.akamu.tudarmstadt.api.V2API
import
de.akamu.tudarmstadt.data.login.LoginDataSource
import
de.akamu.tudarmstadt.data.settings.SettingsDataSource
import
de.akamu.tudarmstadt.data.settings.SettingsDataSourceImpl
import
de.akamu.tudarmstadt.interactors.SettingsInteractor
import
de.akamu.tudarmstadt.model.User
import
de.akamu.tudarmstadt.util.Constants
import
org.json.JSONObject
class
LoginPresenter
(
private
val
interactor
:
LoginInteractor
,
var
view
:
LoginContract
.
View
?)
:
LoginContract
.
Presenter
{
class
LoginPresenter
(
private
val
interactor
:
LoginInteractor
,
var
view
:
LoginContract
.
View
?)
:
LoginContract
.
Presenter
{
init
{
view
?.
presenter
=
this
}
override
fun
autoLogin
()
{
if
(
view
?.
getLoginToken
()
!=
""
&&
view
?.
getAppUser
()
!=
null
)
{
if
(
view
?.
getLoginToken
()
!=
""
&&
view
?.
getAppUser
()
!=
null
)
{
V2API
.
setToken
(
view
?.
getLoginToken
())
view
?.
isLoggedIn
(
true
,
view
?.
getAppUser
()
!!
)
}
...
...
@@ -24,23 +29,27 @@ class LoginPresenter(private val interactor: LoginInteractor, var view: LoginCon
view
?.
showProgress
(
true
)
AkamuFirebase
.
loadFirebaseToken
(
object
:
AkamuFirebase
.
GetFirebaseTokenCallback
{
override
fun
onGetFirebaseTokenSuccess
(
firebaseToken
:
String
)
{
interactor
.
login
(
username
,
password
,
firebaseToken
,
object
:
LoginDataSource
.
LoginCallback
{
override
fun
onLoginSuccess
(
appUser
:
User
,
loginToken
:
String
)
{
view
?.
saveLoginToken
(
loginToken
)
view
?.
isLoggedIn
(
true
,
appUser
)
view
?.
showProgress
(
false
)
}
override
fun
onLoginFailed
(
message
:
String
)
{
view
?.
showLoginFailed
()
view
?.
showProgress
(
false
)
}
override
fun
onLoginCancelled
()
{
view
?.
showLoginCancelled
()
view
?.
showProgress
(
false
)
}
})
interactor
.
login
(
username
,
password
,
firebaseToken
,
object
:
LoginDataSource
.
LoginCallback
{
override
fun
onLoginSuccess
(
appUser
:
User
,
loginToken
:
String
)
{
view
?.
saveLoginToken
(
loginToken
)
view
?.
isLoggedIn
(
true
,
appUser
)
view
?.
showProgress
(
false
)
}
override
fun
onLoginFailed
(
message
:
String
)
{
view
?.
showLoginFailed
()
view
?.
showProgress
(
false
)
}
override
fun
onLoginCancelled
()
{
view
?.
showLoginCancelled
()
view
?.
showProgress
(
false
)
}
})
}
override
fun
onGetFirebaseTokenFail
(
error
:
String
)
{
...
...
@@ -50,6 +59,20 @@ class LoginPresenter(private val interactor: LoginInteractor, var view: LoginCon
})
}
override
fun
fetchSettings
()
{
val
settingsInteractor
=
SettingsInteractor
(
SettingsDataSourceImpl
())
settingsInteractor
.
fetchSettings
(
object
:
SettingsDataSource
.
FetchSettingsCallback
{
override
fun
onFetchSettingsSuccess
(
settings
:
JSONObject
)
{
view
?.
onFetchSettingsSuccess
(
settings
)
}
override
fun
onFetchSettingsFailed
(
reason
:
String
)
{
view
?.
onFetchSettingsFailed
(
reason
)
}
})
}
override
fun
startSignup
()
{
view
?.
navigateToSignup
()
}
...
...
app/src/main/java/de/akamu/tudarmstadt/util/SettingsPresenter.kt
deleted
100644 → 0
View file @
71343379
package
de.akamu.tudarmstadt.util
import
de.akamu.tudarmstadt.data.settings.SettingsDataSource
import
de.akamu.tudarmstadt.interactors.SettingsInteractor
import
org.json.JSONObject
class
SettingsPresenter
(
var
settingsInteractor
:
SettingsInteractor
)
{
fun
fetchSettings
(
callback
:
SettingsDataSource
.
FetchSettingsCallback
)
{
settingsInteractor
.
fetchSettings
(
object
:
SettingsDataSource
.
FetchSettingsCallback
{
override
fun
onFetchSettingsSuccess
(
settings
:
JSONObject
)
{
callback
.
onFetchSettingsSuccess
(
settings
)
}
override
fun
onFetchSettingsFailed
(
reason
:
String
)
{
callback
.
onFetchSettingsFailed
(
reason
)
}
})
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment