Skip to content

Commit

Permalink
User details & block feature added...
Browse files Browse the repository at this point in the history
  • Loading branch information
theMr17 committed Jan 3, 2023
1 parent 155e3dd commit ee36643
Show file tree
Hide file tree
Showing 10 changed files with 1,006 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
android:supportsRtl="true"
android:theme="@style/Theme.Evira"
tools:targetApi="31">
<activity
android:name=".activity.UserDetailsActivity"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".activity.UsersListActivity"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".activity.CartActivity"
android:exported="false">
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/mr_17/evira/activity/ImageActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ private void SetImage(String type)
case "panPic":
ref = FirebaseModel.databaseRef_users.child(sharedPreferences.getString("username", "!@#")).child(FirebaseModel.node_panPic);
break;
case "userAadharPic":
ref = FirebaseModel.databaseRef_users.child(getIntent().getStringExtra("username")).child(FirebaseModel.node_aadharPic);
break;
case "userPanPic":
ref = FirebaseModel.databaseRef_users.child(getIntent().getStringExtra("username")).child(FirebaseModel.node_panPic);
break;
}

ref.addListenerForSingleValueEvent(new ValueEventListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ public void onClick(View view) {
SendToActivity(AddProductsActivity.class, true);
}
});

viewUserDetailsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SendToActivity(UsersListActivity.class, true);
}
});
}

private void InitializeFields()
Expand Down
166 changes: 166 additions & 0 deletions app/src/main/java/com/mr_17/evira/activity/UserDetailsActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package com.mr_17.evira.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.appcompat.widget.Toolbar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

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;
import com.squareup.picasso.Picasso;

import de.hdodenhof.circleimageview.CircleImageView;

public class UserDetailsActivity extends AppCompatActivity
{
private Toolbar toolbar;

private AppCompatTextView firstName;
private AppCompatTextView lastName;
private AppCompatTextView username;
private AppCompatTextView emailAddress;
private AppCompatTextView phoneNumber;
private AppCompatTextView panNumber;
private AppCompatTextView panURL;
private AppCompatTextView aadharNumber;
private AppCompatTextView aadharURL;
private CircleImageView profileImage;
private AppCompatTextView address;

private AppCompatButton blockButton;
private AppCompatButton unblockButton;
private boolean isBlocked;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_details);

InitializeFields();

aadharURL.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url = getIntent().getStringExtra("aadharURL");

if(url.equals(""))
Toast.makeText(UserDetailsActivity.this, "Aadhar Pic not uploaded by user.", Toast.LENGTH_SHORT).show();
else
SendToImageActivity(ImageActivity.class, true, "Aadhar Image", "userAadharPic");
}
});

panURL.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url = getIntent().getStringExtra("panURL");

if(url.equals(""))
Toast.makeText(UserDetailsActivity.this, "Pan Pic not uploaded by user.", Toast.LENGTH_SHORT).show();
else
SendToImageActivity(ImageActivity.class, true, "Pan Image", "userPanPic");
}
});

blockButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FirebaseModel.databaseRef_users.child(username.getText().toString()).child(FirebaseModel.node_isBlocked).setValue("true");
blockButton.setVisibility(View.GONE);
unblockButton.setVisibility(View.VISIBLE);
Toast.makeText(UserDetailsActivity.this, "The user has been blocked.", Toast.LENGTH_SHORT).show();
}
});

unblockButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FirebaseModel.databaseRef_users.child(username.getText().toString()).child(FirebaseModel.node_isBlocked).setValue("false");
blockButton.setVisibility(View.VISIBLE);
unblockButton.setVisibility(View.GONE);
Toast.makeText(UserDetailsActivity.this, "The user has been unblocked.", Toast.LENGTH_SHORT).show();
}
});
}

private void InitializeFields()
{
firstName = findViewById(R.id.first_name);
firstName.setText(getIntent().getStringExtra("firstName"));

lastName = findViewById(R.id.last_name);
lastName.setText(getIntent().getStringExtra("lastName"));

username = findViewById(R.id.username);
username.setText(getIntent().getStringExtra("username"));

emailAddress = findViewById(R.id.email);
emailAddress.setText(getIntent().getStringExtra("email"));

phoneNumber = findViewById(R.id.phone);
phoneNumber.setText(getIntent().getStringExtra("phone"));

panNumber = findViewById(R.id.pan_number);
panNumber.setText(getIntent().getStringExtra("panNum").equals("") ? "N/A" : getIntent().getStringExtra("panNum"));

panURL = findViewById(R.id.pan_view);
//panURL.setText(getIntent().getStringExtra("panURL"));

aadharNumber = findViewById(R.id.aadhar_number);
aadharNumber.setText(getIntent().getStringExtra("aadharNum").equals("") ? "N/A" : getIntent().getStringExtra("aadharNum"));

aadharURL = findViewById(R.id.aadhar_view);
//aadharURL.setText(getIntent().getStringExtra("aadharURL"));

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

address = findViewById(R.id.address);
address.setText(getIntent().getStringExtra("address"));

toolbar = findViewById(R.id.toolbar);
toolbar.setTitle(firstName.getText().toString() + " " + lastName.getText().toString());

blockButton = findViewById(R.id.block_button);
unblockButton = findViewById(R.id.unblock_button);

if(getIntent().getBooleanExtra("isBlocked", false))
{
unblockButton.setVisibility(View.VISIBLE);
}
else
{
blockButton.setVisibility(View.VISIBLE);
}
}





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

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

startActivity(intent);

if (!backEnabled)
finish();
}
}
132 changes: 132 additions & 0 deletions app/src/main/java/com/mr_17/evira/activity/UsersListActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package com.mr_17.evira.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.google.android.material.progressindicator.LinearProgressIndicator;
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.adapter.CartListRecyclerViewAdapter;
import com.mr_17.evira.adapter.UsersListRecyclerViewAdapter;
import com.mr_17.evira.model.FirebaseModel;
import com.mr_17.evira.model.ProductsListRecyclerViewModel;
import com.mr_17.evira.model.UsersListRecyclerViewModel;

import java.util.ArrayList;

public class UsersListActivity extends AppCompatActivity {

private RecyclerView recyclerView;
private ArrayList<UsersListRecyclerViewModel> list;
private UsersListRecyclerViewAdapter.RecyclerViewClickListener listener;
UsersListRecyclerViewAdapter adapter;

private Toolbar toolbar;
private LinearProgressIndicator progressIndicator;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_users_list);

InitializeFields();
InitializeCategoryRecyclerView();
}

private void InitializeFields()
{
toolbar = findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onBackPressed();
}
});
progressIndicator = findViewById(R.id.loading_bar);
}

private void InitializeCategoryRecyclerView()
{
SetOnClickListener();

recyclerView = findViewById(R.id.recycler_view);
list = new ArrayList<>();

adapter = new UsersListRecyclerViewAdapter(list, this, listener);
recyclerView.setAdapter(adapter);
FirebaseModel.databaseRef_users.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for(DataSnapshot d: snapshot.getChildren())
{
String username = d.getKey();
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())) {
list.add(new UsersListRecyclerViewModel(
childSnapshot.child(FirebaseModel.node_firstName).getValue().toString(),
childSnapshot.child(FirebaseModel.node_lastName).getValue().toString(),
childSnapshot.child(FirebaseModel.node_username).getValue().toString(),
childSnapshot.child(FirebaseModel.node_email).getValue().toString(),
childSnapshot.child(FirebaseModel.node_phone).getValue().toString(),
childSnapshot.child(FirebaseModel.node_pan).getValue().toString(),
childSnapshot.child(FirebaseModel.node_panPic).exists() ? childSnapshot.child(FirebaseModel.node_panPic).getValue().toString() : "",
childSnapshot.child(FirebaseModel.node_aadhar).getValue().toString(),
childSnapshot.child(FirebaseModel.node_aadharPic).exists() ? childSnapshot.child(FirebaseModel.node_aadharPic).getValue().toString() : "",
childSnapshot.child(FirebaseModel.node_profilePic).exists() ? childSnapshot.child(FirebaseModel.node_profilePic).getValue().toString() : "",
childSnapshot.child(FirebaseModel.node_address).getValue().toString(),
Boolean.parseBoolean(childSnapshot.child(FirebaseModel.node_isBlocked).getValue().toString()),
Boolean.parseBoolean(childSnapshot.child(FirebaseModel.node_isAdmin).getValue().toString()),
Boolean.parseBoolean(childSnapshot.child(FirebaseModel.node_isSuperAdmin).getValue().toString())
));

GridLayoutManager gridLayoutManager = new GridLayoutManager(UsersListActivity.this, 1);
recyclerView.setLayoutManager(gridLayoutManager);
}
}
progressIndicator.setVisibility(View.GONE);
}

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

}
});
}

private void SetOnClickListener()
{
listener = new UsersListRecyclerViewAdapter.RecyclerViewClickListener() {
@Override
public void onClick(View v, int position)
{
Intent intent = new Intent(UsersListActivity.this, UserDetailsActivity.class);
intent.putExtra("firstName", list.get(position).getFirstName());
intent.putExtra("lastName", list.get(position).getLastName());
intent.putExtra("username", list.get(position).getUsername());
intent.putExtra("email", list.get(position).getEmailAddress());
intent.putExtra("phone", list.get(position).getPhoneNumber());
intent.putExtra("panNum", list.get(position).getPanNumber());
intent.putExtra("panURL", list.get(position).getPanURL());
intent.putExtra("aadharNum", list.get(position).getAadharNumber());
intent.putExtra("aadharURL", list.get(position).getAadharURL());
intent.putExtra("profilePicURL", list.get(position).getProfilePicURL());
intent.putExtra("address", list.get(position).getAddress());
intent.putExtra("isBlocked", list.get(position).isBlocked());
startActivity(intent);
}
};
}
}
Loading

0 comments on commit ee36643

Please sign in to comment.