use of com.firebase.ui.storage.images.FirebaseImageLoader in project BORED by invent2017.
the class StoryFragment method loadStoryDetails.
private void loadStoryDetails(Bundle storyDetails) {
final String storyKey = storyDetails.getString("key");
if (storyKey != null) {
mViewsRef = FirebaseDatabase.getInstance().getReference().child("stories").child(storyKey).child("Views");
mVotesRef = FirebaseDatabase.getInstance().getReference().child("stories").child(storyKey).child("Votes");
mDataRef.child("stories").child(storyKey).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String uri = dataSnapshot.child("URI").getValue(String.class);
String caption = dataSnapshot.child("Caption").getValue(String.class);
boolean isFeatured = dataSnapshot.child("Featured").getValue(boolean.class);
if (isFeatured) {
featuredText.setText(R.string.featured_story);
}
if (uri != null && caption != null) {
StorageReference mStorageRef = FirebaseStorage.getInstance().getReferenceFromUrl(uri);
// Load story image into image view.
Glide.with(getActivity()).using(new FirebaseImageLoader()).load(mStorageRef).into(imageView);
storyCaption.setText(caption);
}
int storyDay = dataSnapshot.child("DateTime").child("date").getValue(Integer.class);
int storyMonth = 1 + dataSnapshot.child("DateTime").child("month").getValue(Integer.class);
int storyYear = 1900 + dataSnapshot.child("DateTime").child("year").getValue(Integer.class);
DateCreator storyDateCreator = new DateCreator(storyDay, storyMonth, storyYear);
dateText.setText(storyDateCreator.getDateString());
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(getContext(), "Failed to load story data.", Toast.LENGTH_SHORT).show();
}
});
mDataRef.child("stories").child(storyKey).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot != null) {
int votes = 0;
if (dataSnapshot.child("Votes").getValue() != null) {
votes = dataSnapshot.child("Votes").getValue(Integer.class);
}
storyVotes = votes;
voteNumber.setText(String.format(new Locale("en", "US"), "%d", votes));
// added this for views lel
int views = 0;
if (dataSnapshot.child("Views").getValue() != null) {
views = dataSnapshot.child("Views").getValue(Integer.class);
}
storyViews = views;
viewNumber.setText(String.format(new Locale("en", "US"), "%d", views));
} else {
voteNumber.setText(String.format(new Locale("en", "US"), "%d", 0));
viewNumber.setText(String.format(new Locale("en", "US"), "%d", 0));
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("Story does not exist.").setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent i = new Intent(getActivity(), MapsActivityCurrentPlace.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
});
builder.create();
}
}
use of com.firebase.ui.storage.images.FirebaseImageLoader in project BORED by invent2017.
the class UserStoryListAdapter method getView.
@Override
public View getView(final int i, View view, ViewGroup viewGroup) {
if (view == null) {
view = LayoutInflater.from(context).inflate(R.layout.user_story_row, viewGroup, false);
}
ViewHolder viewHolder = (ViewHolder) view.getTag();
if (viewHolder == null) {
viewHolder = new ViewHolder();
viewHolder.linearLayout = (LinearLayout) view.findViewById(R.id.story_row);
viewHolder.imageView = (ImageView) view.findViewById(R.id.my_story_image);
viewHolder.captionText = (TextView) view.findViewById(R.id.my_story_caption);
viewHolder.viewsNumber = (TextView) view.findViewById(R.id.views_number);
viewHolder.votesNumber = (TextView) view.findViewById(R.id.votes_number);
}
viewHolder.linearLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showStoryDetails(storyKeys.get(i));
}
});
String storyKey = storyKeys.get(i);
String storyUri = dataSnapshot.child(storyKey).child("URI").getValue(String.class);
StorageReference mStorageRef = FirebaseStorage.getInstance().getReferenceFromUrl(storyUri);
Glide.with(context).using(new FirebaseImageLoader()).load(mStorageRef).into(viewHolder.imageView);
String storyCaption = dataSnapshot.child(storyKey).child("Caption").getValue(String.class);
if (storyCaption == null) {
viewHolder.captionText.setText("");
} else {
if (storyCaption.length() > 12) {
storyCaption = storyCaption.substring(0, 8) + "...";
}
viewHolder.captionText.setText(storyCaption);
}
int views = dataSnapshot.child(storyKey).child("Views").getValue(Integer.class);
viewHolder.viewsNumber.setText(Integer.toString(views));
int votes = dataSnapshot.child(storyKey).child("Votes").getValue(Integer.class);
viewHolder.votesNumber.setText(Integer.toString(votes));
return view;
}
use of com.firebase.ui.storage.images.FirebaseImageLoader in project HikingApp by wickhama.
the class ImageTemp method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_temp);
imageContainer = findViewById(R.id.imageButtonTest);
uploadImage = (Button) findViewById(R.id.uploadImageTest);
mAuth = FirebaseAuth.getInstance();
currentUser = mAuth.getCurrentUser();
/**
* Anonymous Auth Again -- this will not be needed later as we should move this to a launch
* activity.
*/
mAuth.signInAnonymously().addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
System.out.println("***Anonymous User Authentication successful.");
FirebaseUser user = mAuth.getCurrentUser();
} else {
// If sign in fails, display a message to the user.
System.out.println("***Anonymous User Authentication failed.");
}
// ...
}
});
/**
* Getting images from the gallery.
*/
uploadImage = (Button) findViewById(R.id.uploadImageTest);
addImage = (ImageButton) findViewById(R.id.imageButtonTest);
addImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
startActivityForResult(galleryIntent, GALLERY_CODE);
}
});
/**
* UPLOADING images to Firebase Storage.
*/
uploadImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (imageUri != null) {
// added for UUID
String path = "images/" + UUID.randomUUID() + ".jpg";
storageRef = storage.getReference();
imageRef = storageRef.child(path);
uploadTask = storageRef.putFile(imageUri);
imageRef.getName().equals(imageRef.getName());
imageRef.getPath().equals(imageRef.getPath());
Uri file = imageUri;
// Sets path with UUID
imageRef = storageRef.child(path);
saveInternal(imageUri);
uploadTask = imageRef.putFile(file);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getApplicationContext(), "File Upload Failure.", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(getApplicationContext(), "File Upload Success.", Toast.LENGTH_LONG).show();
// This will be needed when saving to the Trail object
/*
Uri downloadUrl = taskSnapshot.getDownloadUrl();
String url = downloadUrl.toString();
*/
}
});
}
}
});
/**
* DOWNLOADING from Firebase Storage
*/
// Hardcoded to get things working.
String url = "https://firebasestorage.googleapis.com/v0/b/arctrails-b1a84.appspot.com/o/" + "images%2F20e1ee59-1fe1-4a05-82e8-9f40845ba6d5.jpg?alt=media&token=3b43df3d-1546-" + "4143-a8ae-2be667857cb5";
StorageReference displayRef = storage.getReferenceFromUrl(url);
ImageView displayImage = (ImageView) findViewById(R.id.photoHolder);
Glide.with(ImageTemp.this).using(new FirebaseImageLoader()).load(displayRef).into(displayImage);
}
use of com.firebase.ui.storage.images.FirebaseImageLoader in project HikingApp by wickhama.
the class Database method getImageUrl.
// Called from DownloadDataActivity, this returns a working URL from the Trail Image.
public void getImageUrl(Trail trail, final ImageView displayImage, Context context) {
if (trail.getMetadata().hasImage()) {
storageRef = storage.getReference();
imageRef = storageRef.child("images/" + trail.getMetadata().getId() + ".jpg");
Glide.with(context).using(new FirebaseImageLoader()).load(imageRef).into(displayImage);
}
}
use of com.firebase.ui.storage.images.FirebaseImageLoader in project BORED by invent2017.
the class ShowStory method loadStoryDetails.
private void loadStoryDetails(Bundle storyDetails) {
final String storyKey = storyDetails.getString("key");
if (storyKey != null) {
mViewsRef = FirebaseDatabase.getInstance().getReference().child("stories").child(storyKey).child("Views");
mVotesRef = FirebaseDatabase.getInstance().getReference().child("stories").child(storyKey).child("Votes");
mDataRef.child("stories").child(storyKey).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
String uri = dataSnapshot.child("URI").getValue(String.class);
String caption = dataSnapshot.child("Caption").getValue(String.class);
boolean isFeatured = dataSnapshot.child("Featured").getValue(boolean.class);
if (isFeatured) {
featuredText.setText(R.string.featured_story);
}
if (uri != null && caption != null) {
StorageReference mStorageRef = FirebaseStorage.getInstance().getReferenceFromUrl(uri);
// Load story image into image view.
Glide.with(ShowStory.this).using(new FirebaseImageLoader()).load(mStorageRef).into(imageView);
storyCaption.setText(caption);
}
int storyDay = dataSnapshot.child("DateTime").child("date").getValue(Integer.class);
int storyMonth = 1 + dataSnapshot.child("DateTime").child("month").getValue(Integer.class);
int storyYear = 1900 + dataSnapshot.child("DateTime").child("year").getValue(Integer.class);
DateCreator storyDateCreator = new DateCreator(storyDay, storyMonth, storyYear);
dateText.setText(storyDateCreator.getDateString());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(ShowStory.this, "Failed to load story data.", Toast.LENGTH_SHORT).show();
}
});
mDataRef.child("stories").child(storyKey).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot != null) {
int votes = 0;
if (dataSnapshot.child("Votes").getValue() != null) {
votes = dataSnapshot.child("Votes").getValue(Integer.class);
}
storyVotes = votes;
voteNumber.setText(String.format(new Locale("en", "US"), "%d", votes));
// added this for views lel
int views = 0;
if (dataSnapshot.child("Views").getValue() != null) {
views = dataSnapshot.child("Views").getValue(Integer.class);
}
storyViews = views;
viewNumber.setText(String.format(new Locale("en", "US"), "%d", views));
} else {
voteNumber.setText(String.format(new Locale("en", "US"), "%d", 0));
viewNumber.setText(String.format(new Locale("en", "US"), "%d", 0));
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setMessage("Story does not exist.").setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent i = new Intent(ShowStory.this, MapsActivityCurrentPlace.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
});
builder.create();
}
}
Aggregations