Last active
August 5, 2024 17:11
-
-
Save AhmedMaad/486854b95aa6e8201fbf4fdaf728861a to your computer and use it in GitHub Desktop.
Internship Form using XML
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:id="@+id/main" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="#1e2940" | |
android:padding="16dp" | |
tools:context=".FormActivity"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginStart="8dp" | |
android:text="Internship Form" | |
android:textColor="@color/white" | |
android:textSize="24sp" | |
android:textStyle="bold" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="32dp" | |
android:text="Name" | |
android:textColor="#DBDAF1" /> | |
<EditText | |
android:id="@+id/name_et" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:backgroundTint="@color/white" | |
android:inputType="textPersonName" | |
android:textColor="@color/white" | |
android:textColorHint="@color/white" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="32dp" | |
android:text="Email" | |
android:textColor="#DBDAF1" /> | |
<EditText | |
android:id="@+id/email_et" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:backgroundTint="@color/white" | |
android:inputType="textEmailAddress" | |
android:textColor="@color/white" | |
android:textColorHint="@color/white" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="16dp" | |
android:text="Phone No." | |
android:textColor="#DBDAF1" /> | |
<EditText | |
android:id="@+id/phone_et" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:backgroundTint="@color/white" | |
android:inputType="phone" | |
android:textColor="@color/white" | |
android:textColorHint="@color/white" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="16dp" | |
android:text="LinkedIn Link" | |
android:textColor="#DBDAF1" /> | |
<EditText | |
android:id="@+id/linkedin_et" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:backgroundTint="@color/white" | |
android:inputType="textUri" | |
android:textColor="@color/white" | |
android:textColorHint="@color/white" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="16dp" | |
android:text="GitHub Link" | |
android:textColor="#DBDAF1" /> | |
<EditText | |
android:id="@+id/github_et" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:backgroundTint="@color/white" | |
android:inputType="textUri" | |
android:textColor="@color/white" | |
android:textColorHint="@color/white" /> | |
<Button | |
android:id="@+id/submit_btn" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="32dp" | |
android:backgroundTint="@color/white" | |
android:text="Submit" | |
android:textColor="#1e2940" /> | |
<ProgressBar | |
android:id="@+id/progress" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:layout_marginVertical="16dp" | |
android:visibility="invisible" | |
tools:visibility="visible" /> | |
</LinearLayout> | |
</ScrollView> |
This file contains hidden or 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
package com.maad.profileapp | |
import android.os.Bundle | |
import android.widget.Toast | |
import androidx.activity.enableEdgeToEdge | |
import androidx.appcompat.app.AppCompatActivity | |
import androidx.core.view.ViewCompat | |
import androidx.core.view.WindowInsetsCompat | |
import androidx.core.view.isVisible | |
import com.google.firebase.firestore.DocumentReference | |
import com.google.firebase.firestore.FirebaseFirestore | |
import com.google.firebase.firestore.ktx.firestore | |
import com.google.firebase.ktx.Firebase | |
import com.maad.profileapp.databinding.ActivityFormBinding | |
class FormActivity : AppCompatActivity() { | |
private lateinit var db: FirebaseFirestore | |
private lateinit var binding: ActivityFormBinding | |
private var name = "" | |
private var email = "" | |
private var linkedin = "" | |
private var github = "" | |
private var phoneNo = "" | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
enableEdgeToEdge() | |
binding = ActivityFormBinding.inflate(layoutInflater) | |
setContentView(binding.root) | |
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -> | |
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) | |
val scale = resources.displayMetrics.density | |
val px = (16 * scale + 0.5f).toInt() | |
v.setPadding( | |
systemBars.left + px, | |
systemBars.top + px, | |
systemBars.right + px, | |
systemBars.bottom + px | |
) | |
insets | |
} | |
db = Firebase.firestore | |
binding.submitBtn.setOnClickListener { | |
name = binding.nameEt.text.toString() | |
email = binding.emailEt.text.toString() | |
linkedin = binding.linkedinEt.text.toString() | |
github = binding.githubEt.text.toString() | |
phoneNo = binding.phoneEt.text.toString() | |
binding.progress.isVisible = true | |
uploadProfile() | |
} | |
} | |
private fun uploadProfile() { | |
val user = User(name, email, phoneNo, linkedin, github) | |
db | |
.collection("users") | |
.add(user) | |
.addOnSuccessListener { | |
updateId(it) | |
} | |
} | |
private fun updateId(docRef: DocumentReference) { | |
docRef.update("id", docRef.id).addOnSuccessListener { | |
binding.progress.isVisible = false | |
Toast.makeText(this, "Submitted!", Toast.LENGTH_SHORT).show() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment