-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
213 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
kotlin/PlanesAndroid/app/src/main/java/com/planes/android/deleteuser/DeleteUserFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.planes.android.deleteuser | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.ContextThemeWrapper | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import com.planes.android.ApplicationScreens | ||
import com.planes.android.MainActivity | ||
import com.planes.android.R | ||
import com.planes.android.creategame.CreateGameSettingsGlobal | ||
import com.planes.android.creategame.CreateGameStates | ||
import com.planes.android.databinding.FragmentDeleteUserBinding | ||
import com.planes.multiplayer_engine.MultiplayerRoundJava | ||
import com.planes.multiplayer_engine.commobj.SimpleRequestNotConnectedToGameCommObj | ||
import com.planes.multiplayer_engine.responses.DeleteUserResponse | ||
import io.reactivex.Observable | ||
import retrofit2.Response | ||
|
||
class DeleteUserFragment: Fragment() { | ||
public lateinit var binding: FragmentDeleteUserBinding | ||
private lateinit var m_LogoutCommObj: SimpleRequestNotConnectedToGameCommObj<DeleteUserResponse> | ||
public var m_MultiplayerRound = MultiplayerRoundJava() | ||
public var m_CreateGameSettingsService = CreateGameSettingsGlobal() | ||
public lateinit var m_Context: Context | ||
|
||
override fun onAttach(context: Context) { | ||
super.onAttach(context) | ||
m_Context = context | ||
m_MultiplayerRound.createPlanesRound() | ||
m_CreateGameSettingsService.createPreferencesService() | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
binding = FragmentDeleteUserBinding.inflate(inflater, container, false) | ||
val username = m_MultiplayerRound.getUsername() | ||
|
||
binding.settingsData = DeleteUserViewModel( | ||
username, | ||
m_Context | ||
) | ||
|
||
if (activity is MainActivity) { | ||
(activity as MainActivity).setActionBarTitle(getString(R.string.delete_user)) | ||
(activity as MainActivity).setCurrentFragmentId(ApplicationScreens.DeleteUser) | ||
(activity as MainActivity).updateOptionsMenu() | ||
} | ||
|
||
val deleteUserButton = binding.deleteuser | ||
|
||
deleteUserButton.setOnClickListener { performDeleteUser() } | ||
if (username.isEmpty()) | ||
deleteUserButton.isEnabled = false | ||
|
||
return binding.root | ||
} | ||
|
||
override fun onGetLayoutInflater(savedInstanceState: Bundle?): LayoutInflater { | ||
if (activity is MainActivity) | ||
return super.onGetLayoutInflater(savedInstanceState) | ||
|
||
val inflater = super.onGetLayoutInflater(savedInstanceState) | ||
val contextThemeWrapper: Context = ContextThemeWrapper(requireContext(), R.style.MyAppTheme) | ||
return inflater.cloneInContext(contextThemeWrapper) | ||
} | ||
|
||
private fun createObservable() : Observable<Response<DeleteUserResponse>> { | ||
return m_MultiplayerRound.deactivateUser(m_MultiplayerRound.getUsername(), m_MultiplayerRound.getUserId().toString()) | ||
} | ||
public fun performDeleteUser() { | ||
|
||
//TODO: update instrumented tests | ||
m_LogoutCommObj = SimpleRequestNotConnectedToGameCommObj(::createObservable, | ||
getString(R.string.error_deleteuser), getString(R.string.unknownerror), getString(R.string.validation_user_not_loggedin), | ||
::receiveDeleteUserStatus, ::finalizeDeleteUserSuccessful, requireActivity()) | ||
|
||
m_LogoutCommObj.makeRequest() | ||
} | ||
|
||
fun receiveDeleteUserStatus(response: DeleteUserResponse): String { | ||
var errorString = "" | ||
if (!response.m_Deactivated) | ||
errorString = getString(R.string.error_deleteuser) | ||
return errorString | ||
} | ||
|
||
fun finalizeDeleteUserSuccessful() { | ||
m_MultiplayerRound.setUserData("", "", "") | ||
m_MultiplayerRound.resetGameData() | ||
m_MultiplayerRound.initRound() | ||
|
||
m_CreateGameSettingsService.createGameState = CreateGameStates.NotSubmitted | ||
m_CreateGameSettingsService.gameName = "" | ||
|
||
if (!this::binding.isInitialized) | ||
return | ||
|
||
binding.deleteuser.isEnabled = false | ||
binding.settingsData!!.m_LoginStatus = m_Context.resources.getString(R.string.nouser) | ||
binding.settingsData!!.m_Username = "" | ||
binding.invalidateAll() | ||
|
||
if (activity is MainActivity) | ||
(activity as MainActivity).setUsernameDrawerMenuMultiplayer() | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
kotlin/PlanesAndroid/app/src/main/java/com/planes/android/deleteuser/DeleteUserViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.planes.android.deleteuser | ||
|
||
import android.content.Context | ||
import androidx.lifecycle.ViewModel | ||
import com.planes.android.R | ||
import java.lang.ref.WeakReference | ||
|
||
class DeleteUserViewModel(var username: String, context: Context) : ViewModel() { | ||
|
||
var m_Username: String | ||
var m_LoginStatus: String | ||
var m_Context: WeakReference<Context> | ||
|
||
init { | ||
m_Context = WeakReference(context) | ||
m_Username = username | ||
m_LoginStatus = if (m_Username.isEmpty()) | ||
m_Context.get()!!.resources.getString(R.string.nouser) | ||
else | ||
m_Context.get()!!.resources.getString(R.string.userloggedin) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...anesAndroid/app/src/main/java/com/planes/multiplayer_engine/requests/DeleteUserRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.planes.multiplayer_engine.requests | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
class DeleteUserRequest ( | ||
@SerializedName("userId") | ||
override var m_UserId: String, | ||
|
||
@SerializedName("userName") | ||
override var m_UserName: String | ||
): BasisRequest(m_UserName, m_UserId); |
8 changes: 8 additions & 0 deletions
8
...esAndroid/app/src/main/java/com/planes/multiplayer_engine/responses/DeleteUserResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.planes.multiplayer_engine.responses | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
class DeleteUserResponse ( | ||
@SerializedName("deactivated") | ||
var m_Deactivated: Boolean | ||
) |
44 changes: 44 additions & 0 deletions
44
kotlin/PlanesAndroid/app/src/main/res/layout/fragment_delete_user.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
<data> | ||
<variable name="settingsData" type="com.planes.android.deleteuser.DeleteUserViewModel"/> | ||
</data> | ||
<RelativeLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@drawable/background"> | ||
<RelativeLayout | ||
android:id="@+id/deleteuser_root" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerInParent="true"> | ||
|
||
<TextView | ||
android:id="@+id/deleteuser_state" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentTop="true" | ||
android:textSize="20dp" | ||
style="@style/CustomTextViewStyle" | ||
android:text="@={settingsData.m_LoginStatus}"/> | ||
<TextView | ||
android:id="@+id/deleteuser_username" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_toRightOf="@+id/deleteuser_state" | ||
android:textSize="20dp" | ||
android:layout_marginLeft="10dp" | ||
style="@style/CustomTextViewStyle" | ||
android:text="@={settingsData.m_Username}" /> | ||
<Button | ||
android:id="@+id/deleteuser" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@+id/deleteuser_username" | ||
android:layout_alignRight="@+id/deleteuser_username" | ||
style="@style/ButtonColor" | ||
android:text="@string/logout"/> | ||
</RelativeLayout> | ||
</RelativeLayout> | ||
</layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters