Last active
June 20, 2020 20:23
-
-
Save ediljeberson/4bbaa222251e89e3b4f4a9761f061ecd to your computer and use it in GitHub Desktop.
$$Jeberson A_J$$#P.S.R Engineering college#Login using OTP authentication#Intro_slider#Create a new profile#View profile list#Connected with Firebase database#
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
package com.jeberson.internshalla_Task_1; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import androidx.appcompat.app.AppCompatActivity; | |
import com.squareup.picasso.Picasso; | |
import java.text.DateFormat; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.Random; | |
public class detail extends AppCompatActivity { | |
TextView nameDetailTextView,dobDetailTextView,ageDetailTextView,gotraDetailTextView,birthplaceDetailTextView,birthtimeDetailTextView,CityDetailTextView,occupationDetailTextView,mobileDetailTextView,descriptionDetailTextView,dateDetailTextView,categoryDetailTextView; | |
ImageView teacherDetailImageView; | |
private void initializeWidgets(){ | |
nameDetailTextView= findViewById(R.id.nameDetailTextView); | |
dateDetailTextView= findViewById(R.id.dateDetailTextView); | |
dobDetailTextView= findViewById(R.id.dobDetailTextView); | |
ageDetailTextView= findViewById(R.id.ageDetailTextView); | |
birthplaceDetailTextView= findViewById(R.id.birthplaceDetailTextView); | |
birthtimeDetailTextView= findViewById(R.id.birthtimeDetailTextView); | |
CityDetailTextView= findViewById(R.id.CityDetailTextView); | |
descriptionDetailTextView= findViewById(R.id.descriptionDetailTextView); | |
gotraDetailTextView= findViewById(R.id.gotraDetailTextView); | |
occupationDetailTextView= findViewById(R.id.occupationDetailTextView); | |
mobileDetailTextView= findViewById(R.id.mobileDetailTextView); | |
categoryDetailTextView= findViewById(R.id.categoryDetailTextView); | |
teacherDetailImageView=findViewById(R.id.teacherDetailImageView); | |
} | |
private String getDateToday(){ | |
DateFormat dateFormat=new SimpleDateFormat("yyyy/MM/dd"); | |
Date date=new Date(); | |
String today= dateFormat.format(date); | |
return today; | |
} | |
private String getRandomCategory(){ | |
String[] categories={"ZEN","BUDHIST","YOGA"}; | |
Random random=new Random(); | |
int index=random.nextInt(categories.length-1); | |
return categories[index]; | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_detail); | |
initializeWidgets(); | |
//RECEIVE DATA FROM ITEMSACTIVITY VIA INTENT | |
Intent i=this.getIntent(); | |
String name=i.getExtras().getString("NAME_KEY"); | |
String dob=i.getExtras().getString("DOB_KEY"); | |
String age=i.getExtras().getString("AGE_KEY"); | |
String birth_place=i.getExtras().getString("BIRTH_PLACE_KEY"); | |
String birth_time=i.getExtras().getString("BIRTH_TIME_KEY"); | |
String city=i.getExtras().getString("CITY_KEY"); | |
String description=i.getExtras().getString("DESCRIPTION_KEY"); | |
String gotra=i.getExtras().getString("GOTRA_KEY"); | |
String occupation=i.getExtras().getString("OCCUPATION_KEY"); | |
String mobile=i.getExtras().getString("MOBILE_KEY"); | |
String imageURL=i.getExtras().getString("IMAGE_KEY"); | |
//SET RECEIVED DATA TO TEXTVIEWS AND IMAGEVIEWS | |
nameDetailTextView.setText(name); | |
dateDetailTextView.setText(" "+getDateToday()); | |
dobDetailTextView.setText(dob); | |
ageDetailTextView.setText(age); | |
birthplaceDetailTextView.setText(birth_place); | |
birthtimeDetailTextView.setText(birth_time); | |
CityDetailTextView.setText(city); | |
descriptionDetailTextView.setText(description); | |
gotraDetailTextView.setText(gotra); | |
occupationDetailTextView.setText(occupation); | |
mobileDetailTextView.setText(mobile); | |
categoryDetailTextView.setText("CATEGORY: "+getRandomCategory()); | |
Picasso.get() | |
.load(imageURL) | |
.placeholder(R.drawable.placeholder) | |
.fit() | |
.centerCrop() | |
.into(teacherDetailImageView); | |
} | |
} |
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
package com.jeberson.internshalla_Task_1; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.ProgressBar; | |
import android.widget.Toast; | |
import androidx.appcompat.app.AppCompatActivity; | |
import androidx.recyclerview.widget.LinearLayoutManager; | |
import androidx.recyclerview.widget.RecyclerView; | |
import com.google.android.gms.tasks.OnSuccessListener; | |
import com.google.firebase.database.DataSnapshot; | |
import com.google.firebase.database.DatabaseError; | |
import com.google.firebase.database.DatabaseReference; | |
import com.google.firebase.database.FirebaseDatabase; | |
import com.google.firebase.database.ValueEventListener; | |
import com.google.firebase.storage.FirebaseStorage; | |
import com.google.firebase.storage.StorageReference; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class items extends AppCompatActivity implements RecyclerAdapter.OnItemClickListener{ | |
private RecyclerView mRecyclerView; | |
private RecyclerAdapter mAdapter; | |
private ProgressBar mProgressBar; | |
private FirebaseStorage mStorage; | |
private DatabaseReference mDatabaseRef; | |
private ValueEventListener mDBListener; | |
private List<Teacher> mTeachers; | |
private void openDetailActivity(String[] data){ | |
Intent intent = new Intent(this, detail.class); | |
intent.putExtra("NAME_KEY",data[0]); | |
intent.putExtra("DOB_KEY",data[1]); | |
intent.putExtra("AGE_KEY",data[2]); | |
intent.putExtra("BIRTH_PLACE_KEY",data[3]); | |
intent.putExtra("BIRTH_TIME_KEY",data[4]); | |
intent.putExtra("CITY_KEY",data[5]); | |
intent.putExtra("DESCRIPTION_KEY",data[6]); | |
intent.putExtra("GOTRA_KEY",data[7]); | |
intent.putExtra("OCCUPATION_KEY",data[8]); | |
intent.putExtra("MOBILE_KEY",data[9]); | |
intent.putExtra("IMAGE_KEY",data[10]); | |
startActivity(intent); | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate ( savedInstanceState ); | |
setContentView ( R.layout.activity_items ); | |
mRecyclerView = findViewById(R.id.mRecyclerView); | |
mRecyclerView.setHasFixedSize(true); | |
mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); | |
mProgressBar = findViewById(R.id.myDataLoaderProgressBar); | |
mProgressBar.setVisibility(View.VISIBLE); | |
mTeachers = new ArrayList<> (); | |
mAdapter = new RecyclerAdapter (items.this, mTeachers); | |
mRecyclerView.setAdapter(mAdapter); | |
mAdapter.setOnItemClickListener(items.this); | |
mStorage = FirebaseStorage.getInstance(); | |
mDatabaseRef = FirebaseDatabase.getInstance().getReference("teachers_uploads"); | |
mDBListener = mDatabaseRef.addValueEventListener(new ValueEventListener() { | |
@Override | |
public void onDataChange(DataSnapshot dataSnapshot) { | |
mTeachers.clear(); | |
for (DataSnapshot teacherSnapshot : dataSnapshot.getChildren()) { | |
Teacher upload = teacherSnapshot.getValue(Teacher.class); | |
upload.setKey(teacherSnapshot.getKey()); | |
mTeachers.add(upload); | |
} | |
mAdapter.notifyDataSetChanged(); | |
mProgressBar.setVisibility(View.GONE); | |
} | |
@Override | |
public void onCancelled(DatabaseError databaseError) { | |
Toast.makeText(items.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show(); | |
mProgressBar.setVisibility(View.INVISIBLE); | |
} | |
}); | |
} | |
public void onItemClick(int position) { | |
Teacher clickedTeacher=mTeachers.get(position); | |
String[] teacherData={clickedTeacher.getName(),clickedTeacher.getDob(),clickedTeacher.getAge(),clickedTeacher.getBirthplace(),clickedTeacher.getBirthtime(),clickedTeacher.getCity(),clickedTeacher.getDescription(),clickedTeacher.getGotra(),clickedTeacher.getOccupation(),clickedTeacher.getmobile(),clickedTeacher.getImageUrl()}; | |
openDetailActivity(teacherData); | |
} | |
@Override | |
public void onShowItemClick(int position) { | |
Teacher clickedTeacher=mTeachers.get(position); | |
String[] teacherData={clickedTeacher.getName(),clickedTeacher.getDob(),clickedTeacher.getAge(),clickedTeacher.getBirthplace(),clickedTeacher.getBirthtime(),clickedTeacher.getCity(),clickedTeacher.getDescription(),clickedTeacher.getGotra(),clickedTeacher.getOccupation(),clickedTeacher.getmobile(),clickedTeacher.getImageUrl()}; | |
openDetailActivity(teacherData); | |
} | |
@Override | |
public void onDeleteItemClick(int position) { | |
Teacher selectedItem = mTeachers.get(position); | |
final String selectedKey = selectedItem.getKey(); | |
StorageReference imageRef = mStorage.getReferenceFromUrl(selectedItem.getImageUrl()); | |
imageRef.delete().addOnSuccessListener(new OnSuccessListener<Void> () { | |
@Override | |
public void onSuccess(Void aVoid) { | |
mDatabaseRef.child(selectedKey).removeValue(); | |
Toast.makeText(items.this, "Item deleted", Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
} | |
protected void onDestroy() { | |
super.onDestroy(); | |
mDatabaseRef.removeEventListener(mDBListener); | |
} | |
} |
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
package com.jeberson.internshalla_Task_1; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.Toast; | |
import androidx.annotation.NonNull; | |
import androidx.appcompat.app.AppCompatActivity; | |
import com.google.android.gms.tasks.OnCompleteListener; | |
import com.google.android.gms.tasks.Task; | |
import com.google.firebase.FirebaseException; | |
import com.google.firebase.auth.AuthResult; | |
import com.google.firebase.auth.FirebaseAuth; | |
import com.google.firebase.auth.PhoneAuthCredential; | |
import com.google.firebase.auth.PhoneAuthProvider; | |
import java.util.concurrent.TimeUnit; | |
public class login extends AppCompatActivity { | |
Button btnGenerateOTP, btnSignIn; | |
EditText etPhoneNumber, etOTP; | |
String phoneNumber, otp; | |
FirebaseAuth auth; | |
PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallback; | |
private String verificationCode; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_login); | |
findViews(); | |
StartFirebaseLogin(); | |
btnGenerateOTP.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
phoneNumber=etPhoneNumber.getText().toString(); | |
PhoneAuthProvider.getInstance().verifyPhoneNumber( | |
phoneNumber, // Phone number to verify | |
60, // Timeout duration | |
TimeUnit.SECONDS, // Unit of timeout | |
login.this, // Activity (for callback binding) | |
mCallback); // OnVerificationStateChangedCallbacks | |
} | |
}); | |
btnSignIn.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
otp=etOTP.getText().toString(); | |
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationCode, otp); | |
SigninWithPhone(credential); | |
} | |
}); | |
} | |
private void SigninWithPhone(PhoneAuthCredential credential) { | |
auth.signInWithCredential(credential) | |
.addOnCompleteListener(new OnCompleteListener<AuthResult>() { | |
@Override | |
public void onComplete(@NonNull Task<AuthResult> task) { | |
if (task.isSuccessful()) { | |
startActivity(new Intent(login.this,profile.class)); | |
finish(); | |
} else { | |
Toast.makeText(login.this,"Incorrect OTP",Toast.LENGTH_SHORT).show(); | |
} | |
} | |
}); | |
} | |
private void findViews() { | |
btnGenerateOTP= findViewById(R.id.btn_generate_otp); | |
btnSignIn= findViewById(R.id.btn_sign_in); | |
etPhoneNumber= findViewById(R.id.et_phone_number); | |
etOTP= findViewById(R.id.et_otp); | |
} | |
private void StartFirebaseLogin() { | |
auth = FirebaseAuth.getInstance(); | |
mCallback = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() { | |
@Override | |
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) { | |
Toast.makeText(login.this,"verification completed",Toast.LENGTH_SHORT).show(); | |
} | |
@Override | |
public void onVerificationFailed(FirebaseException e) { | |
Toast.makeText(login.this,"verification failed",Toast.LENGTH_SHORT).show(); | |
} | |
@Override | |
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) { | |
super.onCodeSent(s, forceResendingToken); | |
verificationCode = s; | |
Toast.makeText(login.this,"Code sent",Toast.LENGTH_SHORT).show(); | |
} | |
}; | |
} | |
} |
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
package com.jeberson.internshalla_Task_1; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import androidx.appcompat.app.AppCompatActivity; | |
import androidx.appcompat.widget.Toolbar; | |
import android.view.View; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
setSupportActionBar(toolbar); | |
findViewById(R.id.btn_play_again).setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
// We normally won't show the welcome slider again in real app | |
// but this is for testing | |
PrefManager prefManager = new PrefManager(getApplicationContext()); | |
// make first time launch TRUE | |
prefManager.setFirstTimeLaunch(true); | |
startActivity(new Intent(MainActivity.this, WelcomeActivity.class)); | |
finish(); | |
} | |
}); | |
} | |
} |
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
package com.jeberson.internshalla_Task_1; | |
import android.content.Context; | |
import android.content.SharedPreferences; | |
/** | |
* Created by Jeberson A J on 01/05/20. | |
*/ | |
public class PrefManager { | |
SharedPreferences pref; | |
SharedPreferences.Editor editor; | |
Context _context; | |
// shared pref mode | |
int PRIVATE_MODE = 0; | |
// Shared preferences file name | |
private static final String PREF_NAME = ".profile"; | |
private static final String IS_FIRST_TIME_LAUNCH = "IsFirstTimeLaunch"; | |
public PrefManager(Context context) { | |
this._context = context; | |
pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE); | |
editor = pref.edit(); | |
} | |
public void setFirstTimeLaunch(boolean isFirstTime) { | |
editor.putBoolean(IS_FIRST_TIME_LAUNCH, isFirstTime); | |
editor.commit(); | |
} | |
public boolean isFirstTimeLaunch() { | |
return pref.getBoolean(IS_FIRST_TIME_LAUNCH, true); | |
} | |
} |
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
package com.jeberson.internshalla_Task_1; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.ImageButton; | |
import androidx.appcompat.app.AppCompatActivity; | |
public class profile extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate ( savedInstanceState ); | |
setContentView ( R.layout.activity_profile ); | |
Button openTeachersActivityBtn = findViewById(R.id.openTeachersActivityBtn); | |
Button openUploadActivityBtn = findViewById(R.id.openUploadActivityBtn); | |
ImageButton logout = findViewById(R.id.logout); | |
openTeachersActivityBtn.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
Intent i = new Intent(profile.this, items.class); | |
startActivity(i); | |
} | |
}); | |
openUploadActivityBtn.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
Intent i = new Intent(profile.this, upload.class); | |
startActivity(i); | |
} | |
}); | |
logout.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
Intent i = new Intent(profile.this,MainActivity.class); | |
startActivity(i); | |
} | |
}); | |
} | |
} | |
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
package com.jeberson.internshalla_Task_1; | |
import android.content.Context; | |
import android.view.ContextMenu; | |
import android.view.LayoutInflater; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import androidx.recyclerview.widget.RecyclerView; | |
import com.squareup.picasso.Picasso; | |
import java.text.DateFormat; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.List; | |
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.RecyclerViewHolder>{ | |
private Context mContext; | |
private List<Teacher> teachers; | |
private OnItemClickListener mListener; | |
public RecyclerAdapter(Context context, List<Teacher> uploads) { | |
mContext = context; | |
teachers = uploads; | |
} | |
@Override | |
public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
View v = LayoutInflater.from(mContext).inflate(R.layout.row_mode, parent, false); | |
return new RecyclerViewHolder(v); | |
} | |
@Override | |
public void onBindViewHolder(RecyclerViewHolder holder, int position) { | |
Teacher currentTeacher = teachers.get(position); | |
holder.nameTextView.setText(currentTeacher.getName()); | |
holder.ageTextView.setText(currentTeacher.getAge()); | |
holder.dobTextView1.setText(currentTeacher.getDob()); | |
holder.birthplaceTextView.setText(currentTeacher.getBirthplace()); | |
holder.birthtimeTextView.setText(currentTeacher.getBirthtime()); | |
holder.cityTextView.setText(currentTeacher.getCity()); | |
holder.gotraTextView.setText(currentTeacher.getGotra()); | |
holder.occupationTextView.setText(currentTeacher.getOccupation()); | |
holder.mobileTextView.setText(currentTeacher.getmobile()); | |
holder.descriptionTextView.setText(currentTeacher.getDescription()); | |
holder.dateTextView.setText(getDateToday()); | |
Picasso.get() | |
.load(currentTeacher.getImageUrl()) | |
.placeholder(R.drawable.placeholder) | |
.fit() | |
.centerCrop() | |
.into(holder.teacherImageView); | |
} | |
@Override | |
public int getItemCount() { | |
return teachers.size(); | |
} | |
public class RecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, | |
View.OnCreateContextMenuListener, MenuItem.OnMenuItemClickListener { | |
public TextView nameTextView,dobTextView1,ageTextView,birthplaceTextView,birthtimeTextView,cityTextView,gotraTextView,occupationTextView,mobileTextView,descriptionTextView,dateTextView; | |
public ImageView teacherImageView; | |
public RecyclerViewHolder(View itemView) { | |
super(itemView); | |
nameTextView =itemView.findViewById ( R.id.nameTextView ); | |
dobTextView1 =itemView.findViewById ( R.id.dobTextView1 ); | |
ageTextView = itemView.findViewById( R.id.ageTextView); | |
birthplaceTextView =itemView.findViewById ( R.id.birthplaceTextView ); | |
birthtimeTextView =itemView.findViewById ( R.id.birthtimeTextView ); | |
cityTextView =itemView.findViewById ( R.id.cityTextView ); | |
gotraTextView = itemView.findViewById( R.id.gotraTextView); | |
occupationTextView =itemView.findViewById ( R.id.occupationTextView ); | |
mobileTextView =itemView.findViewById ( R.id.mobileTextView ); | |
descriptionTextView = itemView.findViewById(R.id.descriptionTextView); | |
dateTextView = itemView.findViewById( R.id.dateTextView); | |
teacherImageView = itemView.findViewById( R.id.teacherImageView); | |
itemView.setOnClickListener(this); | |
itemView.setOnCreateContextMenuListener(this); | |
} | |
@Override | |
public void onClick(View v) { | |
if (mListener != null) { | |
int position = getAdapterPosition(); | |
if (position != RecyclerView.NO_POSITION) { | |
mListener.onItemClick(position); | |
} | |
} | |
} | |
@Override | |
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { | |
menu.setHeaderTitle("Select Action"); | |
MenuItem showItem = menu.add( Menu.NONE, 1, 1, "Show"); | |
MenuItem deleteItem = menu.add(Menu.NONE, 2, 2, "Delete"); | |
showItem.setOnMenuItemClickListener(this); | |
deleteItem.setOnMenuItemClickListener(this); | |
} | |
@Override | |
public boolean onMenuItemClick(MenuItem item) { | |
if (mListener != null) { | |
int position = getAdapterPosition(); | |
if (position != RecyclerView.NO_POSITION) { | |
switch (item.getItemId()) { | |
case 1: | |
mListener.onShowItemClick(position); | |
return true; | |
case 2: | |
mListener.onDeleteItemClick(position); | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
} | |
public interface OnItemClickListener { | |
void onItemClick(int position); | |
void onShowItemClick(int position); | |
void onDeleteItemClick(int position); | |
} | |
public void setOnItemClickListener(OnItemClickListener listener) { | |
mListener = listener; | |
} | |
private String getDateToday(){ | |
DateFormat dateFormat=new SimpleDateFormat("yyyy/MM/dd"); | |
Date date=new Date(); | |
String today= dateFormat.format(date); | |
return today; | |
} | |
} |
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
package com.jeberson.internshalla_Task_1; | |
import android.content.Intent; | |
import androidx.appcompat.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import com.google.firebase.auth.FirebaseAuth; | |
import com.google.firebase.auth.FirebaseUser; | |
public class signed_in extends AppCompatActivity { | |
TextView tvPhoneNumber; | |
Button btnSignOut; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_signed_in); | |
findViews(); | |
setPhoneNumber(); | |
btnSignOut.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
FirebaseAuth.getInstance().signOut(); | |
startActivity(new Intent(signed_in.this,login.class)); | |
finish(); | |
} | |
}); | |
} | |
private void findViews() { | |
tvPhoneNumber= (TextView) findViewById(R.id.tv_phone_number); | |
btnSignOut= (Button) findViewById(R.id.btn_sign_out); | |
} | |
private void setPhoneNumber(){ | |
FirebaseUser user= FirebaseAuth.getInstance().getCurrentUser(); | |
try { | |
tvPhoneNumber.setText(user.getPhoneNumber()); | |
}catch (Exception e){ | |
Toast.makeText(this,"Phone number not found",Toast.LENGTH_SHORT).show(); | |
} | |
} | |
} |
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
package com.jeberson.internshalla_Task_1; | |
import android.content.Intent; | |
import androidx.appcompat.app.AppCompatActivity; | |
import android.os.Bundle; | |
import java.util.Timer; | |
import java.util.TimerTask; | |
public class splash_screen extends AppCompatActivity { | |
Timer timer; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_splash_screen); | |
timer=new Timer(); | |
timer.schedule(new TimerTask() { | |
@Override | |
public void run() { | |
Intent i = new Intent(splash_screen.this,MainActivity.class); | |
startActivity(i); | |
finish(); | |
} | |
},4000); | |
} | |
} |
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
package com.jeberson.internshalla_Task_1; | |
import com.google.firebase.database.Exclude; | |
public class Teacher { | |
private String name; | |
private String dob; | |
private String birthplace; | |
private String birthtime; | |
private String city; | |
private String occupation; | |
private String mobile; | |
private String gotra; | |
private String age; | |
private String imageURL; | |
private String key; | |
private String description; | |
private int position; | |
public Teacher() { | |
//empty constructor needed | |
} | |
public Teacher (int position){ | |
this.position = position; | |
} | |
public Teacher(String name,String dob, String gotra, String age, String birthplace, String birthtime, String city, String occupation, String mobile, String imageUrl ,String Des) { | |
if (name.trim().equals("")) { | |
name = "No Name"; | |
} | |
if (dob.trim().equals("")) { | |
dob = "No Name"; | |
} | |
if (age.trim().equals("")) { | |
age = "No Name"; | |
} | |
if (birthplace.trim().equals("")) { | |
birthplace = "No Name"; | |
} | |
if (birthtime.trim().equals("")) { | |
birthtime = "No Name"; | |
} | |
if (gotra.trim().equals("")) { | |
gotra = "No Name"; | |
} | |
if (city.trim().equals("")) { | |
city = "No Name"; | |
} | |
if (occupation.trim().equals("")) { | |
occupation = "No Name"; | |
} | |
if (mobile.trim().equals("")) { | |
mobile = "No Name"; | |
} | |
this.name = name; | |
this.dob = dob; | |
this.age = age; | |
this.birthplace = birthplace; | |
this.birthtime = birthtime; | |
this.gotra = gotra; | |
this.city = city; | |
this.occupation = occupation; | |
this.mobile = mobile; | |
this.imageURL = imageUrl; | |
this.description = Des; | |
} | |
public String getDescription() { | |
return description; | |
} | |
public void setDescription(String description) { | |
this.description = description; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public String getDob() { | |
return dob; | |
} | |
public void setDob(String dob) { | |
this.dob = dob; | |
} | |
public String getAge() { | |
return age; | |
} | |
public void setAge(String age) { | |
this.age = age; | |
} | |
public String getBirthplace() { | |
return birthplace; | |
} | |
public void setBirthplace(String birthplace) { | |
this.birthplace = birthplace; | |
} | |
public String getBirthtime() { | |
return birthtime; | |
} | |
public void setBirthtime(String birthtime) { | |
this.birthtime = birthtime; | |
} | |
public String getGotra() { | |
return gotra; | |
} | |
public void setGotra(String gotra) { | |
this.gotra = gotra; | |
} | |
public String getCity() { | |
return city; | |
} | |
public void setCity(String city) { | |
this.city = city; | |
} | |
public String getOccupation() { | |
return occupation; | |
} | |
public void setOccupation(String occupation) { | |
this.occupation = occupation; | |
} | |
public String getmobile() { | |
return mobile; | |
} | |
public void setMobile(String mobile) { | |
this.mobile = mobile; | |
} | |
public String getImageUrl() { | |
return imageURL; | |
} | |
public void setImageUrl(String imageUrl) { | |
this.imageURL = imageUrl; | |
} | |
@Exclude | |
public String getKey() { | |
return key; | |
} | |
@Exclude | |
public void setKey(String key) { | |
this.key = key; | |
} | |
} |
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
package com.jeberson.internshalla_Task_1; | |
import android.content.ContentResolver; | |
import android.content.Intent; | |
import android.net.Uri; | |
import android.os.Build; | |
import android.os.Bundle; | |
import android.os.Handler; | |
import android.view.View; | |
import android.webkit.MimeTypeMap; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.ImageView; | |
import android.widget.ProgressBar; | |
import android.widget.Toast; | |
import androidx.annotation.NonNull; | |
import androidx.annotation.RequiresApi; | |
import androidx.appcompat.app.AppCompatActivity; | |
import com.google.android.gms.tasks.OnFailureListener; | |
import com.google.android.gms.tasks.OnSuccessListener; | |
import com.google.firebase.database.DatabaseReference; | |
import com.google.firebase.database.FirebaseDatabase; | |
import com.google.firebase.storage.FirebaseStorage; | |
import com.google.firebase.storage.OnProgressListener; | |
import com.google.firebase.storage.StorageReference; | |
import com.google.firebase.storage.StorageTask; | |
import com.google.firebase.storage.UploadTask; | |
import com.squareup.picasso.Picasso; | |
import java.util.Objects; | |
public class upload extends AppCompatActivity{ | |
private static final int PICK_IMAGE_REQUEST = 5; | |
private EditText nameEditText; | |
private EditText dobEditText1; | |
private EditText birthplaceEditText1; | |
private EditText birthtimeEdiText1; | |
private EditText cityEditText1; | |
private EditText gotraEditText1; | |
private EditText ageEditText1; | |
private EditText occupationEditText1; | |
private EditText mobileEditText1; | |
private EditText descriptionEditText; | |
private ImageView chosenImageView; | |
private ProgressBar uploadProgressBar; | |
private Uri mImageUri; | |
private StorageReference mStorageRef; | |
private DatabaseReference mDatabaseRef; | |
private StorageTask mUploadTask; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate ( savedInstanceState ); | |
setContentView ( R.layout.activity_upload ); | |
Button chooseImageBtn = findViewById(R.id.button_choose_image); | |
Button uploadBtn = findViewById(R.id.uploadBtn); | |
nameEditText = findViewById(R.id.nameEditText); | |
dobEditText1 = findViewById(R.id.dobEditText1); | |
gotraEditText1 = findViewById(R.id.gotraEditText1); | |
ageEditText1 = findViewById(R.id.ageEditText1); | |
birthplaceEditText1 = findViewById(R.id.birthplaceEditText1); | |
birthtimeEdiText1 = findViewById(R.id.birthtimeEditText1); | |
cityEditText1 = findViewById(R.id.cityEditText1); | |
occupationEditText1 = findViewById(R.id.occupationEditText1); | |
mobileEditText1 = findViewById(R.id.mobileEditText1); | |
descriptionEditText = findViewById ( R.id.descriptionEditText ); | |
chosenImageView = findViewById(R.id.chosenImageView); | |
uploadProgressBar = findViewById(R.id.progress_bar); | |
mStorageRef = FirebaseStorage.getInstance().getReference("teachers_uploads"); | |
mDatabaseRef = FirebaseDatabase.getInstance().getReference("teachers_uploads"); | |
chooseImageBtn.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
openFileChooser(); | |
} | |
}); | |
uploadBtn.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
if (mUploadTask != null && mUploadTask.isInProgress()) { | |
Toast.makeText(upload.this, "An Upload is Still in Progress", Toast.LENGTH_SHORT).show(); | |
} else { | |
uploadFile(); | |
} | |
} | |
}); | |
} | |
private void openFileChooser() { | |
Intent intent = new Intent(); | |
intent.setType("image/*"); | |
intent.setAction(Intent.ACTION_GET_CONTENT); | |
startActivityForResult(intent, PICK_IMAGE_REQUEST); | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK | |
&& data != null && data.getData() != null) { | |
mImageUri = data.getData(); | |
Picasso.get().load(mImageUri).into(chosenImageView); | |
} | |
} | |
private String getFileExtension(Uri uri) { | |
ContentResolver cR = getContentResolver(); | |
MimeTypeMap mime = MimeTypeMap.getSingleton(); | |
return mime.getExtensionFromMimeType(cR.getType(uri)); | |
} | |
private void uploadFile() { | |
if (mImageUri != null) { | |
StorageReference fileReference = mStorageRef.child(System.currentTimeMillis() | |
+ "." + getFileExtension(mImageUri)); | |
uploadProgressBar.setVisibility(View.VISIBLE); | |
uploadProgressBar.setIndeterminate(true); | |
mUploadTask = fileReference.putFile(mImageUri) | |
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot> () { | |
@RequiresApi(api = Build.VERSION_CODES.KITKAT) | |
@Override | |
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { | |
Handler handler = new Handler(); | |
handler.postDelayed(new Runnable() { | |
@Override | |
public void run() { | |
uploadProgressBar.setVisibility(View.VISIBLE); | |
uploadProgressBar.setIndeterminate(false); | |
uploadProgressBar.setProgress(0); | |
} | |
}, 500); | |
Toast.makeText(upload.this, "Teacher Upload successful", Toast.LENGTH_LONG).show(); | |
Teacher upload = new Teacher(nameEditText.getText().toString().trim(),dobEditText1.getText().toString().trim(),gotraEditText1.getText().toString().trim(),ageEditText1.getText().toString().trim(),birthplaceEditText1.getText().toString().trim(), | |
birthtimeEdiText1.getText().toString().trim(),cityEditText1.getText().toString().trim(),occupationEditText1.getText().toString().trim(), | |
mobileEditText1.getText().toString().trim(), | |
Objects.requireNonNull(Objects.requireNonNull(taskSnapshot.getMetadata()).getReference()).getDownloadUrl().toString(), | |
descriptionEditText.getText ().toString ()); | |
String uploadId = mDatabaseRef.push().getKey(); | |
mDatabaseRef.child(uploadId).setValue(upload); | |
uploadProgressBar.setVisibility(View.INVISIBLE); | |
openImagesActivity (); | |
} | |
}) | |
.addOnFailureListener(new OnFailureListener () { | |
@Override | |
public void onFailure(@NonNull Exception e) { | |
uploadProgressBar.setVisibility(View.INVISIBLE); | |
Toast.makeText(upload.this, e.getMessage(), Toast.LENGTH_SHORT).show(); | |
} | |
}) | |
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot> () { | |
@Override | |
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) { | |
double progress = (100.0 * taskSnapshot.getBytesTransferred() / taskSnapshot.getTotalByteCount()); | |
uploadProgressBar.setProgress((int) progress); | |
} | |
}); | |
} else { | |
Toast.makeText(this, "You haven't Selected Any file selected", Toast.LENGTH_SHORT).show(); | |
} | |
} | |
private void openImagesActivity(){ | |
Intent intent = new Intent(this, profile.class); | |
startActivity(intent); | |
} | |
} |
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
package com.jeberson.internshalla_Task_1; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.graphics.Color; | |
import android.os.Build; | |
import android.os.Bundle; | |
import androidx.viewpager.widget.PagerAdapter; | |
import androidx.viewpager.widget.ViewPager; | |
import androidx.appcompat.app.AppCompatActivity; | |
import android.text.Html; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.view.Window; | |
import android.view.WindowManager; | |
import android.widget.Button; | |
import android.widget.LinearLayout; | |
import android.widget.TextView; | |
public class WelcomeActivity extends AppCompatActivity { | |
private ViewPager viewPager; | |
private MyViewPagerAdapter myViewPagerAdapter; | |
private LinearLayout dotsLayout; | |
private TextView[] dots; | |
private int[] layouts; | |
private Button btnSkip, btnNext; | |
private PrefManager prefManager; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
// Checking for first time launch - before calling setContentView() | |
prefManager = new PrefManager(this); | |
if (!prefManager.isFirstTimeLaunch()) { | |
launchHomeScreen(); | |
finish(); | |
} | |
// Making notification bar transparent | |
if (Build.VERSION.SDK_INT >= 21) { | |
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); | |
} | |
setContentView(R.layout.activity_welcome); | |
viewPager = (ViewPager) findViewById(R.id.view_pager); | |
dotsLayout = (LinearLayout) findViewById(R.id.layoutDots); | |
btnSkip = (Button) findViewById(R.id.btn_skip); | |
btnNext = (Button) findViewById(R.id.btn_next); | |
// layouts of all welcome sliders | |
// add few more layouts if you want | |
layouts = new int[]{ | |
R.layout.welcome_slide1, | |
R.layout.welcome_slide2, | |
R.layout.welcome_slide3, | |
R.layout.welcome_slide4}; | |
// adding bottom dots | |
addBottomDots(0); | |
// making notification bar transparent | |
changeStatusBarColor(); | |
myViewPagerAdapter = new MyViewPagerAdapter(); | |
viewPager.setAdapter(myViewPagerAdapter); | |
viewPager.addOnPageChangeListener(viewPagerPageChangeListener); | |
btnSkip.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
launchHomeScreen(); | |
} | |
}); | |
btnNext.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
// checking for last page | |
// if last page home screen will be launched | |
int current = getItem(+1); | |
if (current < layouts.length) { | |
// move to next screen | |
viewPager.setCurrentItem(current); | |
} else { | |
launchHomeScreen(); | |
} | |
} | |
}); | |
} | |
private void addBottomDots(int currentPage) { | |
dots = new TextView[layouts.length]; | |
int[] colorsActive = getResources().getIntArray(R.array.array_dot_active); | |
int[] colorsInactive = getResources().getIntArray(R.array.array_dot_inactive); | |
dotsLayout.removeAllViews(); | |
for (int i = 0; i < dots.length; i++) { | |
dots[i] = new TextView(this); | |
dots[i].setText(Html.fromHtml("•")); | |
dots[i].setTextSize(35); | |
dots[i].setTextColor(colorsInactive[currentPage]); | |
dotsLayout.addView(dots[i]); | |
} | |
if (dots.length > 0) | |
dots[currentPage].setTextColor(colorsActive[currentPage]); | |
} | |
private int getItem(int i) { | |
return viewPager.getCurrentItem() + i; | |
} | |
private void launchHomeScreen() { | |
prefManager.setFirstTimeLaunch(false); | |
startActivity(new Intent(WelcomeActivity.this, login.class)); | |
finish(); | |
} | |
// viewpager change listener | |
ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() { | |
@Override | |
public void onPageSelected(int position) { | |
addBottomDots(position); | |
// changing the next button text 'NEXT' / 'GOT IT' | |
if (position == layouts.length - 1) { | |
// last page. make button text to GOT IT | |
btnNext.setText(getString(R.string.start)); | |
btnSkip.setVisibility(View.GONE); | |
} else { | |
// still pages are left | |
btnNext.setText(getString(R.string.next)); | |
btnSkip.setVisibility(View.VISIBLE); | |
} | |
} | |
@Override | |
public void onPageScrolled(int arg0, float arg1, int arg2) { | |
} | |
@Override | |
public void onPageScrollStateChanged(int arg0) { | |
} | |
}; | |
/** | |
* Making notification bar transparent | |
*/ | |
private void changeStatusBarColor() { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
Window window = getWindow(); | |
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
window.setStatusBarColor(Color.TRANSPARENT); | |
} | |
} | |
/** | |
* View pager adapter | |
*/ | |
public class MyViewPagerAdapter extends PagerAdapter { | |
private LayoutInflater layoutInflater; | |
public MyViewPagerAdapter() { | |
} | |
@Override | |
public Object instantiateItem(ViewGroup container, int position) { | |
layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
View view = layoutInflater.inflate(layouts[position], container, false); | |
container.addView(view); | |
return view; | |
} | |
@Override | |
public int getCount() { | |
return layouts.length; | |
} | |
@Override | |
public boolean isViewFromObject(View view, Object obj) { | |
return view == obj; | |
} | |
@Override | |
public void destroyItem(ViewGroup container, int position, Object object) { | |
View view = (View) object; | |
container.removeView(view); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment