Make buttons disappear due to user roles (kotlin) [closed] - android

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Is it possible to make a button disappear in my app when a user is a viewer? I have 3 types of users (viewer, editor and admin) and I want the same layout for the 3 of them but, the viewer cannot have access to some buttons. Is it possible to make the buttons disappear or should I make the exact same layouts but without the buttons? Thanks!
edit
here's a screenshot of firebase database

The roles are stored in realtime database so you would have to first read that and then hide the buttons based on the role. Right now you are comparing the UID of user with the role "Viewer" - if(FirebaseAuth.getInstance().currentUser!!.uid == "Viewer")
val user = Firebase.auth.currentUser
val uid = user.uid
mDatabase.child("users").child(uid).child("Role").get().addOnSuccessListener {
Log.i("firebase", "Got role ${it.value}")
if (it.value == "Viewer") {
newDashButton.visibility = View.GONE
}
}.addOnFailureListener{
Log.e("firebase", "Error getting data", it)
}

Related

How do I see all my data that has been read in Cloud Firestore? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have successfully read all my user data into cloud firestore but unable to see all my data in one go.
As you can see in the screen capture, "Sara" has been read. Beforehand, "Mira" and "Kiena" has also been read.
How do I see "Mira" and "Kiena" together with "Sara" in one screen? I want to see all the data that has been read in Cloud Firestore.
I need to have all this as a record for my thesis.
I set the user data with this code:
private DocumentReference mDocRef = FirebaseFirestore.getInstance().document("sampleData/userdata");
You need to add this
SetOptions.merge()
inside the set function in your code
what is happening now is that firestore takes a key = name and values = sara/mira/etc and keeps overriding the values since the key is the same, but when you use the merge options it will not override and will display all in a list
It looks like you're setting the user data with something like:
db.collection("sampleData").document("userData").set(...)
Any time you execute this code, you're overwriting whatever data already exists in userData.
If you want to create a new document each time you run the code, do:
db.collection("sampleData").add(...)
This will generate a new document with a unique ID each time you execute it.
If the document needs to be associated with the current user from Firebase Authentication, you'll want to use the user's UID as the document name. That'd look like this:
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
db.collection("sampleData").document(uid).set(...)

Firebase Android showing and modify element per single User [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm making this android app using Firebase where I have some books and every user user can set them as read or reading.
I don't know how to do it since Firebase is noSQL and there are no Relations between entities.
There are these three activities: in the first one the user can see all the books and eventually set one as read or reading, in the second there are only books marked ad read and in the third the books marked as reading.
They must be separated, every user has its own.
How can I do this using Firebase realtime database and storage?
I'd likely create two top-level nodes, for the two types that you have:
Users
Books
And then create two additional top-level nodes for the relations between these:
UserBooks - which is where we tie each user to their books, and track their reading status.
BookUsers - which ties each book to the users. You only need this if you want to show the users for a specific book, but I typically recommend adding it right away.
So a simple model like this could look like:
Users: {
"uidOfFio": { ... },
"uidOfPuf": { ... }
},
Books: {
"idOfBook1": { ... },
"idOfBook2": { ... }
},
UserBooks: {
"uidOfFio": {
"idOfBook1": "Read",
"idOfBook2": "Reading"
},
"uidOfPuf": {
"idOfBook1": "Reading",
}
},
BookUsers: {
"idOfBook1": {
"uidOfFio": "Read",
"uidOfPuf": "Reading"
},
"idOfBook2": {
"uidOfFio": "Reading"
},
}
For more on this, I recommend reading:
Many to Many relationship in Firebase
Firebase query if child of child contains a value

assigning a unique id for button [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
suppose there exist a form and has two button ,i want one button to get disabled until all parameter is filled by user while other Enabled,for users to navigate to back panel.Is there exist a function to assign unique id to buttons?
Edit1: Tried to disable one of the button,until all the text-form field in the page is touched by users,once user enters all the required parameters ,then the button gets enabled!
You don't need a unique id for that
FlatButton(Text('foo'), onPressed: areAllParametersFilled ? _onFooPressed : null),
FlatButton(Text('bar'), onPressed: !areAllParametersFilled ? _onBarPressed : null),

How to use spinner to store values to Firebase? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am creating a Classified application, I am stuck at Post Activity, where the user needs to select the Category to post their products. Below is the rough sketch for Post Activity.
Firebase Database Structure :
How to let the user select the Category from the Category list and based on that Category the item/products needs to be saved under that Structure.
For example : If the user needs to post an Advertisement for Audi, he will select "Cars" from the spinner list and that info(image,price,name) should be saved under "Cars" structure in the Firebase Database. Any help would be appreciated, I need to know the logic behind this:
You can get spinner text like this.
Spinner spinner = (Spinner)findViewById(R.id.spinner);
String text = spinner.getSelectedItem().toString();
After you got selected text you can set DatabaseReference location.
databaseReference = FirebaseDatabase.getInstance().getReference().child("All Categories").child(text);

search text in a website programmatically [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
i want my app to search a specific website(from an url) for a specific text and give me the 3 chars after that text or to search for a pattern with a placeholder and give me the first matching string. Is that possible? There is no need to display the website.
Once you download the page using something like HTTPUrlConnection, you can use a regex with your search term
Pattern p = Pattern.compile("specific text(\w\w\w)");
Matcher m = p.matcher(site_text);
boolean b = m.matches();
The three \w will be captured in a group for you to use if there's a match.

Categories

Resources