正在查看: Clash Legends v0.0.1 应用的 LudoChatActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Clash Legends v0.0.1 应用的 LudoChatActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.clash.legends.ui.activities;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.clash.legends.models.ChatData;
import com.clash.legends.models.CurrentUser;
import com.clash.legends.utils.AllConstants;
import com.clash.legends.utils.UserLocalStore;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.messaging.FirebaseMessaging;
import com.squareup.picasso.Picasso;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
public class LudoChatActivity extends AppCompatActivity {
ImageView back;
FirebaseDatabase database;
SharedPreferences fbkey;
LinearLayout ll;
RequestQueue mQueue;
EditText msgEt;
DatabaseReference myRef;
ImageView receiverIvTitle;
TextView receiverNameTitle;
String receiverPlayerId;
JsonObjectRequest request;
ScrollView scrollview;
LinearLayout send;
CurrentUser user;
UserLocalStore userLocalStore;
String ludoID = "";
List<ChatData> list = new ArrayList();
String senderImg = "";
String receiverImg = "";
String senderName = "";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(2131558454);
Intent intent = getIntent();
this.ludoID = intent.getStringExtra("AUTO_ID");
this.senderImg = intent.getStringExtra("SENDER_IMG");
this.receiverImg = intent.getStringExtra("RECEIVER_IMG");
this.senderName = intent.getStringExtra("SENDER_NAME");
this.receiverPlayerId = intent.getStringExtra("RECEIVER_PLAYER_ID");
SharedPreferences sharedPreferences = getSharedPreferences("SMINFO", 0);
this.fbkey = sharedPreferences;
Log.d("HEADERS", sharedPreferences.getString("firebase_key", "key"));
UserLocalStore userLocalStore = new UserLocalStore(this);
this.userLocalStore = userLocalStore;
this.user = userLocalStore.getLoggedInUser();
ImageView imageView = (ImageView) findViewById(2131361996);
this.back = imageView;
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
LudoChatActivity.this.m82x1e43d6b5(view);
}
});
this.receiverIvTitle = (ImageView) findViewById(2131363127);
TextView textView = (TextView) findViewById(2131363128);
this.receiverNameTitle = textView;
textView.setText("Chat - " + intent.getStringExtra("RECEIVER_NAME"));
if (!TextUtils.equals(this.receiverImg, "") && !TextUtils.equals(this.receiverImg, "null")) {
Picasso.get().load(this.receiverImg).placeholder(2131230869).fit().into(this.receiverIvTitle);
}
this.scrollview = (ScrollView) findViewById(2131362120);
this.ll = (LinearLayout) findViewById(2131362121);
this.msgEt = (EditText) findViewById(2131362742);
this.send = (LinearLayout) findViewById(2131363324);
FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
this.database = firebaseDatabase;
this.myRef = firebaseDatabase.getReference("chat").child(this.ludoID).child("messages");
RequestQueue newRequestQueue = Volley.newRequestQueue(getApplicationContext());
this.mQueue = newRequestQueue;
newRequestQueue.getCache().clear();
this.myRef.addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
try {
LudoChatActivity.this.ll.removeAllViews();
LudoChatActivity.this.list = new ArrayList();
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
Log.d("Register", "Value is: " + postSnapshot.getChildren());
ChatData data = (ChatData) postSnapshot.getValue(ChatData.class);
LudoChatActivity.this.list.add(data);
}
LudoChatActivity ludoChatActivity = LudoChatActivity.this;
ludoChatActivity.addToLL(ludoChatActivity.list);
} catch (Exception e) {
e.printStackTrace();
}
}
public void onCancelled(DatabaseError error) {
Log.w("chat", "Failed to read value.", error.toException());
}
});
this.send.setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
LudoChatActivity.this.m83xfed7cd4(view);
}
});
}
void m82x1e43d6b5(View v) {
onBackPressed();
}
void m83xfed7cd4(View v) {
String msg = this.msgEt.getText().toString().trim();
if (TextUtils.equals(msg, "")) {
return;
}
String id = this.myRef.push().getKey();
ChatData data = new ChatData(id, msg, this.user.getMemberid());
this.myRef.child(id).setValue(data);
SharedPreferences sp = getApplicationContext().getSharedPreferences("Notification", 0);
String switchstatus = sp.getString("switch", "on");
if (TextUtils.equals(switchstatus, "on")) {
getTokenForNotification(this.receiverPlayerId);
}
this.msgEt.setText("");
}
private void getTokenForNotification(final String playerId) {
FirebaseMessaging.getInstance().getToken().addOnSuccessListener(new OnSuccessListener() {
public final void onSuccess(Object obj) {
LudoChatActivity.this.m81x97c77db7(playerId, (String) obj);
}
});
}
void m81x97c77db7(String playerId, String token) {
prepNotification(playerId);
}
private void prepNotification(String token) {
JSONObject jSONObject = new JSONObject();
JSONObject to = new JSONObject();
JSONObject data = new JSONObject();
try {
String name = this.user.getFirstName() + " " + this.user.getLastName();
data.put("title", "Received new message from " + name);
data.put("body", "Received new message from " + name);
to.put("token", token);
to.put("data", data);
jSONObject.put("message", to);
if (token != null) {
sentNotification(jSONObject);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
private void sentNotification(JSONObject to) {
JsonObjectRequest request = new JsonObjectRequest(1, "https://fcm.googleapis.com/v1/projects/battle-league-19ddf/messages:send", to, new Response.Listener() {
public final void onResponse(Object obj) {
LudoChatActivity.lambda$sentNotification$3((JSONObject) obj);
}
}, new Response.ErrorListener() {
public final void onErrorResponse(VolleyError volleyError) {
volleyError.printStackTrace();
}
}) {
public Map<String, String> getHeaders() {
Map<String, String> map = new HashMap<>();
try {
String tkn = LudoChatActivity.this.getAccessToken();
map.put("Authorization", "Bearer " + tkn);
} catch (IOException e) {
e.printStackTrace();
}
map.put("Content-Type", "application/json");
return map;
}
public String getBodyContentType() {
return "application/json";
}
};
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
request.setRetryPolicy(new DefaultRetryPolicy(30000, 1, 1.0f));
requestQueue.add(request);
}
static void lambda$sentNotification$3(JSONObject response) {
}
public String getAccessToken() throws IOException {
InputStream inputStream = getResources().openRawResource(2131820548);
GoogleCredentials googleCredential = GoogleCredentials.fromStream(inputStream).createScoped(Arrays.asList(AllConstants.SCOPES));
googleCredential.refresh();
Log.i("TAGggg", "getAccessToken: " + googleCredential.toString());
return googleCredential.getAccessToken().getTokenValue();
}
public void addToLL(List<ChatData> list) {
this.ll.removeAllViews();
for (int i = 0; i < list.size(); i++) {
ChatData data = list.get(i);
View view = getLayoutInflater().inflate(2131558552, (ViewGroup) null);
TextView tv = (TextView) view.findViewById(2131362743);
ImageView senderiv = (ImageView) view.findViewById(2131363322);
ImageView receiveriv = (ImageView) view.findViewById(2131363125);
CardView sendercv = view.findViewById(2131363323);
CardView receivercv = view.findViewById(2131363126);
LinearLayout mainChatLl = (LinearLayout) view.findViewById(2131362676);
if (TextUtils.equals(data.getSenderId(), this.user.getMemberid())) {
mainChatLl.setGravity(5);
receivercv.setVisibility(4);
if (!TextUtils.equals(this.senderImg, "") && !TextUtils.equals(this.senderImg, "null")) {
Picasso.get().load(this.senderImg).placeholder(2131230869).fit().into(senderiv);
}
} else {
mainChatLl.setGravity(3);
sendercv.setVisibility(4);
if (!TextUtils.equals(this.receiverImg, "") && !TextUtils.equals(this.receiverImg, "null")) {
Picasso.get().load(this.receiverImg).placeholder(2131230869).fit().into(receiveriv);
}
}
tv.setText(data.getMsg());
this.ll.addView(view);
this.scrollview.post(new Runnable() {
@Override
public final void run() {
LudoChatActivity.this.m80x3f8eb449();
}
});
}
}
void m80x3f8eb449() {
this.scrollview.fullScroll(130);
}
}