|
@@ -1,22 +1,16 @@
|
|
|
package com.drinkertea.test2smack;
|
|
|
|
|
|
-import androidx.appcompat.app.AppCompatActivity;
|
|
|
-import androidx.core.app.NotificationCompat;
|
|
|
-import androidx.core.app.NotificationManagerCompat;
|
|
|
-import androidx.core.app.TaskStackBuilder;
|
|
|
-
|
|
|
-import android.app.Notification;
|
|
|
-import android.app.NotificationChannel;
|
|
|
-import android.app.NotificationManager;
|
|
|
-import android.app.PendingIntent;
|
|
|
import android.content.Intent;
|
|
|
import android.graphics.Color;
|
|
|
-import android.graphics.Typeface;
|
|
|
-import android.icu.text.SymbolTable;
|
|
|
-import android.os.Build;
|
|
|
+import android.graphics.drawable.GradientDrawable;
|
|
|
import android.os.Bundle;
|
|
|
+
|
|
|
+import androidx.fragment.app.Fragment;
|
|
|
+
|
|
|
import android.os.Handler;
|
|
|
+import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
@@ -24,27 +18,24 @@ import org.jivesoftware.smack.chat2.Chat;
|
|
|
import org.jivesoftware.smack.chat2.IncomingChatMessageListener;
|
|
|
import org.jivesoftware.smack.packet.Message;
|
|
|
import org.jivesoftware.smack.packet.Presence;
|
|
|
-import org.jivesoftware.smack.roster.Roster;
|
|
|
-import org.jivesoftware.smack.roster.RosterEntry;
|
|
|
import org.jivesoftware.smack.roster.RosterListener;
|
|
|
import org.jxmpp.jid.EntityBareJid;
|
|
|
import org.jxmpp.jid.Jid;
|
|
|
import org.jxmpp.jid.impl.JidCreate;
|
|
|
-import org.jxmpp.stringprep.XmppStringprepException;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.Timer;
|
|
|
import java.util.TimerTask;
|
|
|
+
|
|
|
class FishNameComparator implements Comparator<ChatItem>
|
|
|
{
|
|
|
public int compare(ChatItem left, ChatItem right) {
|
|
|
return right.status.compareTo(left.status);
|
|
|
}
|
|
|
}
|
|
|
-public class ChatsList extends AppCompatActivity {
|
|
|
+public class BlankFragment extends Fragment {
|
|
|
|
|
|
LinearLayout linearLayout;
|
|
|
final Handler handler = new Handler();
|
|
@@ -52,25 +43,29 @@ public class ChatsList extends AppCompatActivity {
|
|
|
TimerTask timerTask = new TimerTask() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- handler.post(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- try {
|
|
|
- generateChatsList();
|
|
|
- }catch (Exception ex){
|
|
|
- System.out.println(ex.getMessage());
|
|
|
+ handler.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ generateChatsList();
|
|
|
+ }catch (Exception ex){
|
|
|
+ System.out.println(ex.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
+ private View view;
|
|
|
@Override
|
|
|
- protected void onCreate(Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- setContentView(R.layout.activity_chats_list);
|
|
|
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
+ Bundle savedInstanceState) {
|
|
|
+ view = inflater.inflate(R.layout.fragment_blank, container, false);
|
|
|
+ init();
|
|
|
+ return view;
|
|
|
|
|
|
- linearLayout = (LinearLayout) findViewById(R.id.chatsListLayout);
|
|
|
+ }
|
|
|
+ public void init(){
|
|
|
+ linearLayout = (LinearLayout) view.findViewById(R.id.chatsListLayout);
|
|
|
XMPPClass.GenerateChatList();
|
|
|
generateChatsList();
|
|
|
runMessageListener();
|
|
@@ -81,10 +76,11 @@ public class ChatsList extends AppCompatActivity {
|
|
|
linearLayout.removeAllViews();
|
|
|
Collections.sort(XMPPClass.chatItems, new FishNameComparator());
|
|
|
for (ChatItem chatItem : XMPPClass.chatItems){
|
|
|
- TextView Name = new TextView(this);
|
|
|
- TextView Status = new TextView(this);
|
|
|
- TextView NewMessage = new TextView(this);
|
|
|
- LinearLayout Container = new LinearLayout(this);
|
|
|
+
|
|
|
+ TextView Name = new TextView(view.getContext());
|
|
|
+ TextView Status = new TextView(view.getContext());
|
|
|
+ TextView NewMessage = new TextView(view.getContext());
|
|
|
+ LinearLayout Container = new LinearLayout(view.getContext());
|
|
|
|
|
|
Name.setTextColor(Color.parseColor("#000000"));
|
|
|
Name.setTextSize(16);
|
|
@@ -117,8 +113,12 @@ public class ChatsList extends AppCompatActivity {
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
|
|
|
layoutParams.setMargins(55, 15, 55, 15);
|
|
|
+ layoutParams.height = 195;
|
|
|
Container.setLayoutParams(layoutParams);
|
|
|
-
|
|
|
+ GradientDrawable border = new GradientDrawable();
|
|
|
+ border.setColor(Color.parseColor("#ffffff"));
|
|
|
+ border.setStroke(5, Color.parseColor("#0081FF"));
|
|
|
+ Container.setBackgroundDrawable(border);
|
|
|
LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
|
|
@@ -126,7 +126,7 @@ public class ChatsList extends AppCompatActivity {
|
|
|
Name.setLayoutParams(textParams);
|
|
|
Status.setLayoutParams(textParams);
|
|
|
NewMessage.setLayoutParams(textParams);
|
|
|
- Container.setBackgroundColor(Color.parseColor("#C0C0C0"));
|
|
|
+ //Container.setBackgroundColor(Color.parseColor("#C0C0C0"));
|
|
|
Container.addView(Name);
|
|
|
Container.addView(Status);
|
|
|
Container.addView(NewMessage);
|
|
@@ -136,7 +136,7 @@ public class ChatsList extends AppCompatActivity {
|
|
|
try {
|
|
|
XMPPClass.chatJid = JidCreate.entityBareFrom(chatItem.jid);
|
|
|
chatItem.message = null;
|
|
|
- Intent intent = new Intent(ChatsList.this, ChatActivity.class);
|
|
|
+ Intent intent = new Intent(view.getContext(), ChatActivity.class);
|
|
|
startActivity(intent);
|
|
|
}catch (Exception ex){
|
|
|
|
|
@@ -146,7 +146,7 @@ public class ChatsList extends AppCompatActivity {
|
|
|
});
|
|
|
linearLayout.addView(Container);
|
|
|
}
|
|
|
- timer.schedule(timerTask, 0, 10000);
|
|
|
+ timer.schedule(timerTask, 0, 15000);
|
|
|
}
|
|
|
|
|
|
public void runMessageListener(){
|
|
@@ -192,4 +192,5 @@ public class ChatsList extends AppCompatActivity {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
}
|