FINAL PROJEK PEMROGRAMAN MOBILE 2 TI16B-MUHAMMAD ALI HASANI

FINAL PROJEK
“Aplikasi Les-in AJA”
Disusun oleh:

Syamsul falah                           16.11.0029

Muhammad Aris nur Aziz      16.11.0046

Linatun Masrohah                   16.11.0055

ZaenurRochman                      16.11.0068

Yahya Dani Lisharyanto         16.11.0070

Muhammad Ali Hasani           16.11.0071

Muhammad Yunus                  16.11.0076

Sofyan Fathur Rohim              16.11.0082

Hamid Ashari                           16.11.0086

Asep Tri Wibowo                     16.11.0091

Firmansah Putra                      16.11.0093

PROGRAM TEKNIK INFORMATIKA
SEKOLAH TINGGI MANAJEMEN INFORMATIKA DAN KOMPUTER
AMIKOM PURWOKERTO
PURWOKERTO
2019

 

Deskripsi dari Final Projek Kami

Aplikasi Les-in AJA merupakan aplikasi untuk pencarian guru les. Aplikasi ini dibagi menjadi 2 versi, yaitu versi user (orang tua) dan versi guru. Aplikasi ini berlatar belakangkan dari permasalahan orang tua yang kesulitan dalam mencari guru les yang tepat dan sesuai dengan apa yang dibutuhkan anaknya. Dan juga permasalahan yang dialami oleh guru ketika ingin menambah penghasilan diluar jam sekolah. Pada aplikasi Les-in AJA versi user (orang tua) terdapat 2 kategori utama dalam pencarian gurunya yaitu dengan kategori jenjang Pendidikan dan mata pelajaran. Fitur utama dari aplikasi Les-in AJA versi user (orang tua) yaitu dapat mencari berdasarkan beberapa kondisi. Kemudian pada aplikasi Les-in AJA versi guru terdapat fitur untuk memperbaharui informasi data diri dan program bimbel yang akan ditawarkan.

 

Source Code penting dalam aplikasi

1. Source Code Login

mAuth.signInWithEmailAndPassword(email_login.text.toString(), password_login.text.toString())
    .addOnCompleteListener(this@LoginActivity) { task ->
        login_progress.setVisibility(View.GONE)
        if (!task.isSuccessful) {
            // there was an error
            if (password_login.text.length < 6) {
password_login.setError(getString(R.string.minimum_password))
            } else {
                Toast.makeText(this@LoginActivity, getString(R.string.auth_failed), Toast.LENGTH_LONG).show()
            }
        } else {
            val user = mAuth.currentUser
            val intent:Intent
            if (!user!!.isEmailVerified) {
                intent = Intent(this@LoginActivity, VerificationActivity::class.java)
            } else {
                intent = Intent(this@LoginActivity, MainActivity::class.java)
            }
            startActivity(intent)
            finish()
        }
}

Login dengan authentication email aktif,terdapat percabangan ketika email user belum terverifikasi maka akan dilempar ke verifikasi activity.

private fun verifyEmail() {
    val user = auth.currentUser
    user!!.sendEmailVerification().addOnCompleteListener(this) { task ->
        if (task.isSuccessful) {
            Toast.makeText(applicationContext, "Verification email sent to " + user!!.email!!, Toast.LENGTH_SHORT).show()
        } else {
            Log.e("TAG", "sendEmailVerification failed!", task.exception)
            Toast.makeText(applicationContext, "Failed to send verification email.", Toast.LENGTH_SHORT).show()
        }
    }
}

Kemudian kami menggunakan salah satu fitur firebase yaitu verifikasi email, supaya data yang ada benar benar valid.

private fun firebaseAuthWithGoogle(account: GoogleSignInAccount) {
    val credential = GoogleAuthProvider.getCredential(account.idToken, null)
    mAuth.signInWithCredential(credential)
        .addOnCompleteListener(this) { task ->
            if (task.isSuccessful) {
                // Sign in success, update UI with the signed-in user's information
                val nama = account.displayName
                val email = account.email
                val db = FirebaseDatabase.getInstance()
                val ref = db.reference.child("guru") ref.orderByChild("email").equalTo(email).addValueEventListener(object : ValueEventListener {
                    override fun onDataChange(dataSnapshot: DataSnapshot) {
                        if (dataSnapshot.exists()) {
                            startActivity(Intent(this@LoginActivity, MainActivity::class.java))
                            Toast.makeText(
                                applicationContext,
                                "Selamat Datang Kembali " + nama!!,
                                Toast.LENGTH_LONG
                            ).show()
                            finish()
                        } else {
                            ref.push()
                                .setValue(GuruModel(nama!!, email!!,"","","","","","","", PenGuruModel("","",""),
                                    BimbelModel("","","")
                                )).addOnSuccessListener(this@LoginActivity) {
                                Log.d("TAG", "signInWithCredential:success")
                                startActivity(Intent(this@LoginActivity, MainActivity::class.java))
                                Toast.makeText(applicationContext, "Selamat Datang " + nama!!, Toast.LENGTH_LONG)
                                    .show()
                                finish()
                            }
                        }
                    }
                    override fun onCancelled(databaseError: DatabaseError) {
                    }
                })
            } else {
                // If sign in fails, display a message to the user.
                Log.w("TAG", "signInWithCredential:failure", task.exception)
                Toast.makeText(this@LoginActivity, "Aut Fail", Toast.LENGTH_SHORT).show()
                //updateUI(null);
            }
            // ...
        }
}

Login menggunakan Firabase Google Authentication, jadi selain dapat login dengan email, pengguna dapat login menggunakan Google Authentication.

2. Source Code Register

auth.createUserWithEmailAndPassword(Email, Password)
    .addOnCompleteListener(this@RegisterActivity, OnCompleteListener { task ->
            Toast.makeText(this@RegisterActivity, "Registrasi berhasil " + task.isSuccessful, Toast.LENGTH_SHORT)
                .show()
            progressBar.visibility = View.GONE
            // If sign in fails, display a message to the user. If sign in succeeds
            // the auth state listener will be notified and logic to handle the
            // signed in user can be handled in the listener.
            if (!task.isSuccessful) {
                Toast.makeText(
                    this@RegisterActivity, "Authentication failed." + task.exception!!,
                    Toast.LENGTH_SHORT
                ).show()
            } else {
                verifyEmail()
                startActivity(Intent(this@RegisterActivity, VerificationActivity::class.java))
                finish()
            }
        })
//String getUserID = auth.getCurrentUser().getUid();
val db = FirebaseDatabase.getInstance()
val getReference: DatabaseReference
getReference = db.reference
getReference.child("guru").push()
    .setValue(GuruModel(name,Email,Password,"","","","","","", PenGuruModel("","",""), BimbelModel("","",""))).addOnSuccessListener(this@RegisterActivity){
    email_reg.setText("")
    password_reg.setText("")
    Nama.setText("")
}

Register disini user menambahkan data email dan nama dan dimasukkan database yang kemudian dikirim email verifikasi ke akun yang tadi dibuat dan baru bisa masuk.

3. Source Code Profile

Pada menu ini terdapat 3 tab info yaitu Info Personal , Riwayat Pendidikan, Program Bimbingan belajar yang menggunakan Fragment dan Tab Layout:

tablayout1.setTabGravity(TabLayout.GRAVITY_FILL)
tablayout1.addTab(tablayout1.newTab().setText("Info Personal"))

tablayout1.addTab(tablayout1.newTab().setText("Riwayat Pendidikan"))
tablayout1.addTab(tablayout1.newTab().setText("Program Bimbel"))
var adapter = TabGuru(supportFragmentManager, tablayout1.getTabCount())
viewpager1.setAdapter(adapter)
viewpager1.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tablayout1))
tablayout1.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
    override fun onTabSelected(tab: TabLayout.Tab) {
        viewpager1.setCurrentItem(tab.position)
    }
    override fun onTabUnselected(tab: TabLayout.Tab) {
    }
    override fun onTabReselected(tab: TabLayout.Tab) {
    }
})

Pada masing masing fragment terdapat pengambilan data profil dari database untuk masing masing Info personal, riwayat pendidikan, dan program bimbingan belajar

fun getUserData(){
    if (this.auth.currentUser != null) {
        val email = auth.currentUser!!.email.toString()
        val ref = FirebaseDatabase.getInstance().reference.child("guru")
        ref.orderByChild("email").equalTo(email).addValueEventListener(object : ValueEventListener {
            override fun onDataChange(dataSnapshot: DataSnapshot) {
                for (datas in dataSnapshot.children) {
                    val nama = datas.child("nama").value.toString()
                    val alamat = datas.child("alamat").value.toString()
                    val bimbel = datas.child("programbimbel").child("nama").value.toString()
                    nmguru.text = "" + nama
                    emailguru.setText(auth!!.currentUser!!.getEmail())
                    almguru.setText(alamat)
                    nmbimbel.text = "" + bimbel
                    nhpguru.text = datas.child("nohp").value.toString()
                    //                    Toast.makeText(getApplicationContext(),nama,Toast.LENGTH_LONG).show();
                }
            }
            override fun onCancelled(databaseError: DatabaseError) {
Toast.makeText(context,databaseError.message,Toast.LENGTH_LONG).show()
            }
        })
    }else{
        Toast.makeText(context,"error",Toast.LENGTH_LONG).show()
    }
}

fun getUserData(){
    if (this.auth.currentUser != null) {
        val email = auth.currentUser!!.email.toString()
        val ref = FirebaseDatabase.getInstance().reference.child("guru")
        ref.orderByChild("email").equalTo(email).addValueEventListener(object : ValueEventListener {
            override fun onDataChange(dataSnapshot: DataSnapshot) {
                for (datas in dataSnapshot.children) {

                    sd.text = datas.child("pendidikan").child("sd").value.toString()
                    smp.text = datas.child("pendidikan").child("smp").value.toString()
                    sma.text = datas.child("pendidikan").child("sma").value.toString()
                    s1.text = datas.child("pendidikan").child("s1").value.toString()
                }
            }
            override fun onCancelled(databaseError: DatabaseError) {
                Toast.makeText(context,databaseError.message, Toast.LENGTH_LONG).show()
            }
        })
    }else{
        Toast.makeText(context,"error", Toast.LENGTH_LONG).show()
    }
}
fun getUserData(){
    if (this.auth.currentUser != null) {
        val email = auth.currentUser!!.email.toString()
        val ref = FirebaseDatabase.getInstance().reference.child("guru")

ref.orderByChild("email").equalTo(email).addValueEventListener(object : ValueEventListener {
            override fun onDataChange(dataSnapshot: DataSnapshot) {
                for (datas in dataSnapshot.children) {
                    bimbelname.text = datas.child("programbimbel").child("nama").value.toString()
                    descbimbel.text = datas.child("programbimbel").child("deskripsi").value.toString()
                    mapel.text = datas.child("mapel").getValue().toString()
                    kelas.text = datas.child("kelas").getValue().toString()
                    biaya.text = datas.child("programbimbel").child("biaya").value.toString()
                }
            }
            override fun onCancelled(databaseError: DatabaseError) {
                Toast.makeText(context,databaseError.message, Toast.LENGTH_LONG).show()
            }
        })
    }else{
        Toast.makeText(context,"error", Toast.LENGTH_LONG).show()
    }
}

4. Source Code Mencari Guru

Untuk mencari guru kami menggunakan beberapa query sesuai dengan input user dan kategori yang dipilih oleh user :

tag = bundle.getString("tage");
        tage = bundle.getString("tag");
        jp = bundle.getString("jp");
        mpl = bundle.getString("mpl");
        parentReference = FirebaseDatabase.getInstance().getReference().child("guru");

        parentReference.keepSynced(true);
        Query query = null;
        switch (tag){
            case "1":
                query = parentReference.orderByChild("jp").equalTo(tage);
                break;
            case "2":
                query = parentReference.orderByChild("mapel").equalTo(tage);
                break;
            case "3":
//                Toast.makeText(getApplicationContext(),jp+"_"+mpl,Toast.LENGTH_LONG).show();
                query = parentReference.orderByChild("jenjang_mapel").equalTo(jp+"_"+mpl);
        }
        recyclerView = findViewById(R.id.resultrv);
        linearLayoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(linearLayoutManager)
        FirebaseRecyclerOptions personsOptions = new FirebaseRecyclerOptions.Builder().setQuery(query, GuruModel.class).build();
        mFirebaseAdapter = new FirebaseRecyclerAdapter(personsOptions) {
            @Override
            protected void onBindViewHolder(@NonNull final ResultActivity.ViewHolder holder, int position, @NonNull final GuruModel model) {
                holder.nama.setText(model.getNama());
                holder.alamat.setText(model.getAlamat());
                holder.nohp.setText(model.getNohp());
                holder.cv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(ResultActivity.this,GuruActivity.class);
                        Bundle bundle1 = new Bundle();
                        bundle1.putString("nama",model.getNama());
                        bundle1.putString("email",model.getEmail());
                        bundle1.putString("alamat",model.getAlamat());
                        bundle1.putString("nohp",model.getNohp());
                        intent.putExtras(bundle1);
                        startActivity(intent);
                    }
                });
            }
            @NonNull
            @Override
            public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
                View view = LayoutInflater.from(viewGroup.getContext())
                        .inflate(R.layout.guru_item, viewGroup, false);
                return new ResultActivity.ViewHolder(view);
            }
        };
        recyclerView.setAdapter(mFirebaseAdapter);

Link Video Youtube Projek kami

Referensi untuk final projek kami

https://medium.com/@kalifardy56/mengenal-jenis-layout-android-studio-335a63666ff7
https://www.okedroid.com/2015/12/cara-agar-aplikasi-android-mendukung-multi-screen.html
https://blog.dicoding.com/tips-membuat-tampilan-aplikasi-android-yang-responsive-scrollview/
https://medium.com/@namakulinux/belajar-menyambungkan-aplikasi-android-ke-firebase-7d4ebf8fc6c9
https://medium.com/@ahmadariffaizin/cara-gampang-mendapatkan-sha1-key-di-android-studio-311e6950af91
https://medium.com/@eijaz/getting-started-with-tablayout-in-android-kotlin-bb7e21783761 (kotlin)
https://medium.com/@erthru/implementasi-recyclerview-cardview-di-kotlin-268b8d896075 (kotlin)
https://www.wildantechnoart.net/2018/04/crud-firebase-realtime-database-menembahkan-firebase-ke-project-android.html (firebase)
https://www.google.com/search?q=login+firebase+auth&oq=login+firebase+authe&aqs=chrome.1.69i57j0l5.10388j0j4&sourceid=chrome&ie=UTF-8 (firebase authentication)
https://medium.com/@efebu/firebase-email-verification-for-android-30b5dcef5e7 (verify firebase akun)