Added Direct message

This commit is contained in:
NudeDude 2018-08-20 13:29:41 +02:00
parent 9e0c406d64
commit 56a05a4de1
7 changed files with 60 additions and 52 deletions

View File

@ -6,6 +6,7 @@ import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
@ -292,30 +293,30 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
}
if (!isHome && (mode == ACTION_FOLLOW || mode == ACTION_BLOCK || mode == ACTION_MUTE || mode == GET_INF)) {
Toolbar tool = connect.findViewById(R.id.profile_toolbar);
if(tool.getMenu().size() >= 2) {
MenuItem followIcon = tool.getMenu().getItem(1);
MenuItem blockIcon = tool.getMenu().getItem(2);
MenuItem muteIcon = tool.getMenu().getItem(3);
if (isFollowing) {
followIcon.setIcon(R.drawable.follow_enabled);
followIcon.setTitle(R.string.unfollow);
} else {
followIcon.setIcon(R.drawable.follow);
followIcon.setTitle(R.string.follow);
}
if (isBlocked) {
blockIcon.setTitle(R.string.unblock);
followIcon.setVisible(false);
} else {
blockIcon.setTitle(R.string.block);
followIcon.setVisible(true);
}
if (isMuted) {
muteIcon.setTitle(R.string.unmute);
} else {
muteIcon.setTitle(R.string.mute);
}
Menu m = tool.getMenu();
MenuItem followIcon = m.findItem(R.id.profile_follow);
MenuItem blockIcon = m.findItem(R.id.profile_block);
MenuItem muteIcon = m.findItem(R.id.profile_mute);
if (isFollowing) {
followIcon.setIcon(R.drawable.follow_enabled);
followIcon.setTitle(R.string.unfollow);
} else {
followIcon.setIcon(R.drawable.follow);
followIcon.setTitle(R.string.follow);
}
if (isBlocked) {
blockIcon.setTitle(R.string.unblock);
followIcon.setVisible(false);
} else {
blockIcon.setTitle(R.string.block);
followIcon.setVisible(true);
}
if (isMuted) {
muteIcon.setTitle(R.string.unmute);
} else {
muteIcon.setTitle(R.string.mute);
}
}
}
}

View File

@ -57,27 +57,15 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MessageH
@NonNull
public MessageHolder onCreateViewHolder(@NonNull final ViewGroup parent, int index) {
@Override
public MessageHolder onCreateViewHolder(@NonNull final ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_dm, parent, false);
MessageHolder item = new MessageHolder(v);
Message message = messages.get(index);
TwitterUser sender = message.sender;
String name = '@' + sender.username + ' ' + sender.screenname;
String time = stringTime(message.time);
item.message.setText(message.message);
item.username.setText(name);
item.createdAt.setText(time);
if (loadImage)
Picasso.get().load(sender.profileImg + "_mini").into(item.profile_img);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RecyclerView rv = (RecyclerView) parent;
int position = rv.getChildLayoutPosition(v);
mListener.onSeleted(position);
mListener.onSelected(position);
}
});
return new MessageHolder(v);
@ -86,7 +74,17 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MessageH
@Override
public void onBindViewHolder(@NonNull MessageHolder vh, int index) {
Message message = messages.get(index);
TwitterUser sender = message.sender;
String name = sender.username + ' ' + sender.screenname;
String time = stringTime(message.time);
vh.message.setText(message.message);
vh.username.setText(name);
vh.createdAt.setText(time);
if (loadImage)
Picasso.get().load(sender.profileImg + "_mini").into(vh.profile_img);
}
private String stringTime(long mills) {
@ -115,7 +113,7 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MessageH
public interface OnItemSelected {
void onSeleted(int pos);
void onSelected(int pos);
}
class MessageHolder extends ViewHolder {

View File

@ -32,6 +32,7 @@ public class DirectMessage extends AppCompatActivity implements OnItemSelected,
dmList = findViewById(R.id.messagelist);
dmList.setLayoutManager(new LinearLayoutManager(this));
dmList.setHasFixedSize(true);
refresh.setRefreshing(true);
refresh.setOnRefreshListener(this);
@ -52,7 +53,7 @@ public class DirectMessage extends AppCompatActivity implements OnItemSelected,
}
@Override
public void onSeleted(int index) {
public void onSelected(int index) {
}
@Override

View File

@ -1,19 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/dm_profileImg"
<android.support.v7.widget.CardView
android:layout_width="@dimen/profile_small"
android:layout_height="@dimen/profile_small"
android:contentDescription="@string/profile_image" />
android:layout_marginEnd="10dp"
app:cardCornerRadius="5dp">
<ImageView
android:id="@+id/dm_profileImg"
android:layout_width="@dimen/profile_small"
android:layout_height="@dimen/profile_small"
android:contentDescription="@string/profile_image" />
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
@ -24,12 +33,14 @@
android:id="@+id/dm_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="11sp" />
<TextView
android:id="@+id/dm_time"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:singleLine="true"
android:textSize="11sp" />
</LinearLayout>
</LinearLayout>
@ -37,6 +48,7 @@
<TextView
android:id="@+id/dm_message"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:layout_marginTop="5dp" />
</LinearLayout>

View File

@ -7,10 +7,7 @@
<android.support.v7.widget.Toolbar
android:id="@+id/dm_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/bar_wide"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme" />
android:layout_height="@dimen/bar_wide" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/dm_reload"

View File

@ -10,7 +10,6 @@
android:background="@android:color/transparent">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">

View File

@ -62,5 +62,5 @@
<string name="unmute">Stummschaltung aufheben</string>
<string name="muted">stummgeschaltet!</string>
<string name="unmuted">Stummschaltung aufgehoben!</string>
<string name="directmessage">Direkt Message</string>
<string name="directmessage">Direktnachrichten</string>
</resources>