Skip to content

Commit

Permalink
fixed issue with images not showing up and optimized somethings
Browse files Browse the repository at this point in the history
  • Loading branch information
darshanbhatta committed Apr 22, 2019
1 parent bb05e01 commit 38745fe
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 79 deletions.
155 changes: 82 additions & 73 deletions NoTixBus/app/src/main/java/ml/coppellcoders/notixbus/QRScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,94 +89,103 @@ public void onQRCodeRead(String text, PointF[] points) {
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String guestName = dataSnapshot.child("guestname").getValue().toString();
String imageSrc = dataSnapshot.child("faceimg").getValue().toString();
String event = dataSnapshot.child("name").getValue().toString();
String time = dataSnapshot.child("time").getValue().toString();
String numTickets = dataSnapshot.child("quant").getValue().toString();
String prevHash = dataSnapshot.child("previousHash").getValue().toString();
String[] monthNames = new String[12];
monthNames[0] = "Jan";
monthNames[1] = "Feb";
monthNames[2] = "Mar";
monthNames[3] = "Apr";
monthNames[4] = "May";
monthNames[5] = "Jun";
monthNames[6] = "Jul";
monthNames[7] = "Aug";
monthNames[8] = "Sep";
monthNames[9] = "Oct";
monthNames[10] = "Nov";
monthNames[11] = "Dec";
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(Long.parseLong(time));
int mMonth = calendar.get(Calendar.MONTH);
int mDay = calendar.get(Calendar.DAY_OF_MONTH);
String date = monthNames[mMonth] + " " + mDay;
View view = getLayoutInflater().inflate(R.layout.attendee_info, null);
cancel = view.findViewById(R.id.attendee_cancel);
name = view.findViewById(R.id.attendee_name);
image = view.findViewById(R.id.attendee_image);
eventName = view.findViewById(R.id.attendee_event_name);
eventTime = view.findViewById(R.id.attendee_event_time);
eventTickets = view.findViewById(R.id.attendee_event_tickets);
ImageView scanVerified = view.findViewById(R.id.scan_verified);
if(dialog==null || !dialog.isShowing()) {
dialog = new AlertDialog.Builder(QRScanner.this)
.setView(view)
.create();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
name.setText(guestName);
image.setImageBitmap(decodeBase64(imageSrc));
eventName.setText(event);
eventTime.setText(date);
eventTickets.setText(numTickets + " ticket(s)");
myRefBlock.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
Log.e("err", dataSnapshot.toString());
if(!dataSnapshot.getKey().equals(ticket)&&!dataSnap){
hash = dataSnapshot.child("hash").getValue().toString();
if(hash.equals(prevHash)){
scanVerified.setBackgroundResource(R.drawable.blockchain_true);
if(!imageSrc.equals("0")){
String event = dataSnapshot.child("name").getValue().toString();
String time = dataSnapshot.child("time").getValue().toString();
String numTickets = dataSnapshot.child("quant").getValue().toString();
String prevHash = dataSnapshot.child("previousHash").getValue().toString();
String[] monthNames = new String[12];
monthNames[0] = "Jan";
monthNames[1] = "Feb";
monthNames[2] = "Mar";
monthNames[3] = "Apr";
monthNames[4] = "May";
monthNames[5] = "Jun";
monthNames[6] = "Jul";
monthNames[7] = "Aug";
monthNames[8] = "Sep";
monthNames[9] = "Oct";
monthNames[10] = "Nov";
monthNames[11] = "Dec";
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(Long.parseLong(time));
int mMonth = calendar.get(Calendar.MONTH);
int mDay = calendar.get(Calendar.DAY_OF_MONTH);
String date = monthNames[mMonth] + " " + mDay;
View view = getLayoutInflater().inflate(R.layout.attendee_info, null);
cancel = view.findViewById(R.id.attendee_cancel);
name = view.findViewById(R.id.attendee_name);
image = view.findViewById(R.id.attendee_image);
eventName = view.findViewById(R.id.attendee_event_name);
eventTime = view.findViewById(R.id.attendee_event_time);
eventTickets = view.findViewById(R.id.attendee_event_tickets);
ImageView scanVerified = view.findViewById(R.id.scan_verified);
if(dialog==null || !dialog.isShowing()) {
dialog = new AlertDialog.Builder(QRScanner.this)
.setView(view)
.create();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
name.setText(guestName);
image.setImageBitmap(decodeBase64(imageSrc));
eventName.setText(event);
eventTime.setText(date);
eventTickets.setText(numTickets + " ticket(s)");
myRefBlock.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
Log.e("err", dataSnapshot.getKey());
if(!dataSnapshot.getKey().equals(ticket)){
hash = dataSnapshot.child("hash").getValue().toString();
}else{
scanVerified.setBackgroundResource(R.drawable.blockchain_false);
if(hash.equals(prevHash)){
System.out.println("worka "+hash + " " + prevHash);

scanVerified.setBackgroundResource(R.drawable.blockchain_true);
}else{
System.out.println("worka "+hash + " F " + prevHash);
scanVerified.setBackgroundResource(R.drawable.blockchain_false);
}
myRefBlock.removeEventListener(this);

}
}else{
dataSnap = true;
}
}

@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

}
}

@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {

}
}

@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

}
}

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

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}

}
});
});

myRef.removeEventListener(this);
dialog.show();

dialog.show();

}
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,14 @@ public void onClick(View view) {
}
}
});
System.out.println(previousHash + "\n" + faces.child("previousHash").getValue().toString());
if(previousHash.equals(faces.child("previousHash").getValue().toString())){
alert_verified.setBackgroundResource(R.drawable.blockchain_true);
if(previousHash.equals(faces.child("previousHash").getValue().toString())){
System.out.println("worka "+previousHash + " " + faces.child("previousHash").getValue().toString());

alert_verified.setBackgroundResource(R.drawable.blockchain_true);
}else{
alert_verified.setBackgroundResource(R.drawable.blockchain_false);
System.out.println("worka "+previousHash + " F " + faces.child("previousHash").getValue().toString());

alert_verified.setBackgroundResource(R.drawable.blockchain_false);

}
Log.e("QR Code Data: ", children.getKey() + "[" + faces.getKey());
Expand Down Expand Up @@ -276,7 +279,7 @@ public void onClick(View view) {
hideImageView();
}
}

myRef.removeEventListener(this);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion NoTixBus/app/src/main/res/layout/attendee_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/blockchain"
android:background="@drawable/blockchain_true"
android:layout_marginTop="10dp"
android:id="@+id/scan_verified"
/>
Expand Down
Binary file modified notix.xd
Binary file not shown.

0 comments on commit 38745fe

Please sign in to comment.