Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register page #8

Merged
merged 4 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ dependencies {

implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("com.google.android.material:material:1.12.0-beta01")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.kizitonwose.calendar:view:2.5.0")
implementation("androidx.annotation:annotation:1.6.0")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.6.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1")
implementation("androidx.activity:activity:1.8.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:targetSandboxVersion="1">

<!-- Required for API -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -19,10 +18,9 @@
android:theme="@style/Theme.Material3.Light.NoActionBar"
tools:targetApi="31">
<activity
android:name=".ui.login.LoginActivity"
android:name=".ui.login.AuthActivity"
android:exported="true"
android:label="@string/title_activity_login">

android:windowSoftInputMode="adjustResize|stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@ class LoginDataSource {
try {
// handle loggedInUser authentication
val credentials = RegisterRequest(username, email, password, deviceName)
// Log.i(TAG, credentials.toString())
Log.i(TAG, credentials.toString())
val response: Response<RegisterResponse> = apiServiceNoAuth.register(credentials)
// Log.d(TAG, response.toString())
Log.d(TAG, response.toString())
// Log.d(TAG, response.body().toString())
return if (response.isSuccessful) {
// Log.i(TAG, response.body().toString())
Log.i(TAG, response.body().toString())
// TODO: use real login credentials and save token

// TODO: `LoginResponse(token=null, status=404, message=Not Found!!!)` still logins user
// val fakeUser = LoggedInUser(java.util.UUID.randomUUID().toString(), "Jane Doe")
val registerResponse: RegisterResponse = response.body()!!
Result.Success(registerResponse)
} else {
Result.Error(IOException("Error logging in"))
Result.Error(IOException("Error Registering"))
}
// return Result.Error(IOException("Function not implemented"))
} catch (e: Throwable) {
Log.d(TAG, e.message.toString())
return Result.Error(IOException("Error logging in", e))
return Result.Error(IOException("Error Registering", e))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.example.sharedcalendar.ui.login

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.example.sharedcalendar.R

class AuthenticationPagerAdapter(
fragmentManager: FragmentManager,
lifecycle: Lifecycle
) : FragmentStateAdapter(fragmentManager, lifecycle) {

private val fragmentList: ArrayList<Fragment> = ArrayList()

override fun getItemCount(): Int {
return fragmentList.size
}

override fun createFragment(position: Int): Fragment {
return fragmentList[position]
}

fun addFragment(fragment: Fragment) {
fragmentList.add(fragment)
}
}

class AuthActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_auth)

val viewPager = findViewById<ViewPager2>(R.id.viewPager)

val pagerAdapter = AuthenticationPagerAdapter(supportFragmentManager, lifecycle)
pagerAdapter.addFragment(LoginFragment())
pagerAdapter.addFragment(RegisterFragment())

viewPager.adapter = pagerAdapter
}
}
Loading