-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve MessagesActivity by using RecyclerView
Add MessagesRecyclerViewAdapter, Remove MessageFragment Rename fragment_message to view_message Change some modifiers in GraphView, GraphData
- Loading branch information
Showing
9 changed files
with
137 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/src/main/java/de/jthedroid/whatsappchatanalyzer/GraphData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 0 additions & 46 deletions
46
app/src/main/java/de/jthedroid/whatsappchatanalyzer/MessageFragment.java
This file was deleted.
Oops, something went wrong.
24 changes: 10 additions & 14 deletions
24
app/src/main/java/de/jthedroid/whatsappchatanalyzer/MessagesActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,23 @@ | ||
package de.jthedroid.whatsappchatanalyzer; | ||
|
||
import android.os.Bundle; | ||
import android.support.v4.app.FragmentManager; | ||
import android.support.v4.app.FragmentTransaction; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
|
||
import java.util.Objects; | ||
|
||
public class MessagesActivity extends AppCompatActivity { | ||
public class MessagesActivity extends ThemeMenuActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_messages); | ||
FragmentManager manager = getSupportFragmentManager(); | ||
FragmentTransaction transaction = manager.beginTransaction(); | ||
int msgCount = Objects.requireNonNull(DataStorage.getInstance().chat.getValue()).getMsgCount(); | ||
String tag; | ||
for (int i = 0; i < msgCount; i++) { | ||
tag = "msg" + i; | ||
if (manager.findFragmentByTag(tag) == null) | ||
transaction.add(R.id.linearLayoutMessages, MessageFragment.newInstance(i), tag); | ||
} | ||
transaction.commit(); | ||
RecyclerView recyclerView = findViewById(R.id.recyclerViewMessages); | ||
recyclerView.setHasFixedSize(true); | ||
LinearLayoutManager layoutManager = new LinearLayoutManager(this); | ||
layoutManager.setStackFromEnd(true); | ||
recyclerView.setLayoutManager(layoutManager); | ||
RecyclerView.Adapter adapter = new MessagesRecyclerViewAdapter(Objects.requireNonNull(DataStorage.getInstance().chat.getValue()).getMessages()); | ||
recyclerView.setAdapter(adapter); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
app/src/main/java/de/jthedroid/whatsappchatanalyzer/MessagesRecyclerViewAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package de.jthedroid.whatsappchatanalyzer; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
import java.text.DateFormat; | ||
import java.util.ArrayList; | ||
|
||
public class MessagesRecyclerViewAdapter extends RecyclerView.Adapter { | ||
private final DateFormat dateFormat; | ||
private final ArrayList<Message> messages; | ||
|
||
|
||
MessagesRecyclerViewAdapter(ArrayList<Message> messages) { | ||
this.messages = messages; | ||
dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public MessagesViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { | ||
return new MessagesViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.view_message, viewGroup, false)); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) { | ||
onBindViewHolder((MessagesViewHolder) viewHolder, i); | ||
} | ||
|
||
private void onBindViewHolder(MessagesViewHolder holder, int i) { | ||
Message m = messages.get(i); | ||
holder.tvMessage.setText(m.getMsg()); | ||
holder.tvDate.setText(dateFormat.format(m.getDate())); | ||
Sender s = m.getSender(); | ||
holder.tvSender.setVisibility(s == null ? View.GONE : View.VISIBLE); | ||
if (s != null) holder.tvSender.setText(m.getSender().getName()); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return messages.size(); | ||
} | ||
|
||
public static class MessagesViewHolder extends RecyclerView.ViewHolder { | ||
|
||
final TextView tvMessage, tvSender, tvDate; | ||
|
||
MessagesViewHolder(@NonNull View itemView) { | ||
super(itemView); | ||
tvMessage = itemView.findViewById(R.id.textViewMessage); | ||
tvSender = itemView.findViewById(R.id.textViewSender); | ||
tvDate = itemView.findViewById(R.id.textViewDate); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context="de.jthedroid.whatsappchatanalyzer.MessagesActivity"> | ||
android:layout_height="match_parent"> | ||
|
||
<ScrollView | ||
android:id="@+id/scrollViewMessages" | ||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/recyclerViewMessages" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginEnd="8dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent"> | ||
|
||
<LinearLayout | ||
android:id="@+id/linearLayoutMessages" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" /> | ||
</ScrollView> | ||
|
||
android:scrollbars="vertical" | ||
tools:listitem="@layout/view_message" /> | ||
</android.support.constraint.ConstraintLayout> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<android.support.v7.widget.CardView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="4dp" | ||
android:layout_marginEnd="8dp" | ||
android:layout_marginBottom="4dp"> | ||
|
||
<android.support.constraint.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:id="@+id/textViewSender" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:text="Sender" /> | ||
|
||
<TextView | ||
android:id="@+id/textViewMessage" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginEnd="8dp" | ||
android:textAlignment="center" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/textViewSender" | ||
tools:text="Message" /> | ||
|
||
<TextView | ||
android:id="@+id/textViewDate" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:textAppearance="@style/TextAppearance.AppCompat.Small" | ||
android:textColor="@android:color/darker_gray" | ||
android:textSize="12sp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:text="Date" /> | ||
</android.support.constraint.ConstraintLayout> | ||
</android.support.v7.widget.CardView> | ||
|
||
</FrameLayout> |