package app.nepaliapp.bscfree;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
public class Buy extends AppCompatActivity {
Button message, Monthly, Yearly;
TextView textView1;
FirebaseAuth mAuth;
String userID, money1;
public static String MyVariable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_server);
message = findViewById(R.id.Topup);
Monthly = findViewById(R.id.monthly);
Yearly = findViewById(R.id.yearly);
textView1 = findViewById(R.id.amount);
mAuth = FirebaseAuth.getInstance();
userID = mAuth.getUid();
FirebaseFirestore.getInstance().collection("users")
.document(userID)
.get()
.addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
MyVariable = documentSnapshot.get("money").toString();
textView1.setText(MyVariable);
}
});
message.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
gotoUrl("https://m.me/101442208871937");
}
private void gotoUrl(String s) {
Uri uri = Uri.parse(s);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
});
Monthly.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int num;
num = Integer.getInteger(MyVariable);
if (num == 10 ){
startActivity(new Intent(Buy.this,Actionable.class));
}
}
});
Yearly.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
}
}
The main thing up here is that I want to create a new variable that will get the value from money1 in the upper code and want to use it in my entire activity. Which will help me reduce my read operation in firebase. As I need one for show points and another to subtract. So please help me, I didn't got the text in my money, So please help for This Thank you.