Skip to content

Commit

Permalink
Check block feature added...
Browse files Browse the repository at this point in the history
  • Loading branch information
theMr17 committed Jan 3, 2023
1 parent ee36643 commit ba9fbf8
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void onDataChange(@NonNull DataSnapshot snapshot) {
msg = "Sorry you cannot login, your account has been blocked.";
break;
case "Admin":
allowed = Boolean.parseBoolean(snapshot.child(FirebaseModel.node_isAdmin).getValue().toString());
allowed = Boolean.parseBoolean(snapshot.child(FirebaseModel.node_isAdmin).getValue().toString()) && !(Boolean.parseBoolean(snapshot.child(FirebaseModel.node_isBlocked).getValue().toString()));
msg = "Sorry you are not authorised to enter here...";
break;
case "Super Admin":
Expand Down
46 changes: 40 additions & 6 deletions app/src/main/java/com/mr_17/evira/activity/SplashActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package com.mr_17.evira.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Toast;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.ValueEventListener;
import com.mr_17.evira.R;
import com.mr_17.evira.model.FirebaseModel;

public class SplashActivity extends AppCompatActivity {

Expand All @@ -24,18 +32,44 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void run()
{
Intent intent;
final Intent[] intent = new Intent[1];

if(myAuth.getCurrentUser() == null) {
intent = new Intent(SplashActivity.this, WelcomeActivity.class);
intent[0] = new Intent(SplashActivity.this, WelcomeActivity.class);
intent[0].addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent[0]);
finish();
}
else
{
intent = new Intent(SplashActivity.this, UserDashboardActivity.class);
SharedPreferences sharedPref = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE);;
FirebaseModel.databaseRef_users.child(sharedPref.getString("username", "!@#")).child(FirebaseModel.node_isBlocked).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if(snapshot.exists())
{
if(!Boolean.parseBoolean(snapshot.getValue().toString()))
{
intent[0] = new Intent(SplashActivity.this, UserDashboardActivity.class);
}
else
{
myAuth.signOut();
intent[0] = new Intent(SplashActivity.this, WelcomeActivity.class);
Toast.makeText(SplashActivity.this, "Your account has been blocked by the admin.", Toast.LENGTH_SHORT).show();
}
intent[0].addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent[0]);
finish();
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
}
}, 2000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public class UserDashboardActivity extends AppCompatActivity {

private String type;
private ConstraintLayout adminFeaturesContainer;
private AppCompatButton addProductsButton, viewUserDetailsButton;
private AppCompatTextView adminFeaturesHeading;
private AppCompatButton addProductsButton, viewUserDetailsButton, viewAdminDetailsButton;

private SharedPreferences sharedPref;

Expand All @@ -75,7 +76,14 @@ public void onClick(View view) {
viewUserDetailsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SendToActivity(UsersListActivity.class, true);
SendToActivity(UsersListActivity.class, true, "users");
}
});

viewAdminDetailsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SendToActivity(UsersListActivity.class, true, "admins");
}
});
}
Expand All @@ -87,8 +95,10 @@ private void InitializeFields()
myAuth = FirebaseAuth.getInstance();
type = sharedPref.getString("type", "User");
adminFeaturesContainer = findViewById(R.id.admin_features_container);
adminFeaturesHeading = findViewById(R.id.admin_features_heading);
addProductsButton = findViewById(R.id.add_products_button);
viewUserDetailsButton = findViewById(R.id.view_user_details_button);
viewAdminDetailsButton = findViewById(R.id.view_admin_details_button);

wishingMsg = findViewById(R.id.wishing_msg);
wishingMsg.setText("Good " + GetWishing() + ",");
Expand Down Expand Up @@ -130,6 +140,10 @@ public void onItemSelected(int i) {
adminFeaturesContainer.setVisibility(View.VISIBLE);
break;
case "Super Admin":
adminFeaturesContainer.setVisibility(View.VISIBLE);
adminFeaturesHeading.setText("Super Admin Features");
addProductsButton.setVisibility(View.GONE);
viewAdminDetailsButton.setVisibility(View.VISIBLE);
break;
}
}
Expand Down Expand Up @@ -270,4 +284,18 @@ private void SendToActivity(Class<? extends Activity> activityClass, boolean bac
if (!backEnabled)
finish();
}

private void SendToActivity(Class<? extends Activity> activityClass, boolean backEnabled, String type)
{
Intent intent = new Intent(this, activityClass);
intent.putExtra("type", type);

if (!backEnabled)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

startActivity(intent);

if (!backEnabled)
finish();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ private void InitializeFields()
//aadharURL.setText(getIntent().getStringExtra("aadharURL"));

profileImage = findViewById(R.id.profile_image);
if(!(getIntent().getStringExtra("profilePicURL")).equals(""))
Picasso.get().load(getIntent().getStringExtra("profilePicURL")).into(profileImage);

address = findViewById(R.id.address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,20 @@ public void onDataChange(@NonNull DataSnapshot snapshot) {
DataSnapshot childSnapshot = snapshot.child(username);
//Toast.makeText(UsersListActivity.this, snapshot.child(FirebaseModel.node_firstName).getValue().toString(), Toast.LENGTH_SHORT).show();

if(!Boolean.parseBoolean(childSnapshot.child(FirebaseModel.node_isAdmin).getValue().toString()) && !Boolean.parseBoolean(childSnapshot.child(FirebaseModel.node_isSuperAdmin).getValue().toString())) {
boolean check = false;

switch (getIntent().getStringExtra("type"))
{
case "users":
check = !Boolean.parseBoolean(childSnapshot.child(FirebaseModel.node_isAdmin).getValue().toString()) && !Boolean.parseBoolean(childSnapshot.child(FirebaseModel.node_isSuperAdmin).getValue().toString());
break;
case "admins":
check = Boolean.parseBoolean(childSnapshot.child(FirebaseModel.node_isAdmin).getValue().toString()) && !Boolean.parseBoolean(childSnapshot.child(FirebaseModel.node_isSuperAdmin).getValue().toString());
break;
}


if(check) {
list.add(new UsersListRecyclerViewModel(
childSnapshot.child(FirebaseModel.node_firstName).getValue().toString(),
childSnapshot.child(FirebaseModel.node_lastName).getValue().toString(),
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/layout/activity_user_dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,26 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/add_products_button"/>

<androidx.appcompat.widget.AppCompatButton
android:visibility="gone"
android:id="@+id/view_admin_details_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="25dp"
android:background="@drawable/bg_button_black"
android:fontFamily="@font/poppins_semibold"
android:padding="16dp"
android:text="View Admin Details"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view_user_details_button"/>

</androidx.constraintlayout.widget.ConstraintLayout>

<LinearLayout
Expand Down

0 comments on commit ba9fbf8

Please sign in to comment.