kopia lustrzana https://github.com/sh123/codec2_talkie
Messaging update
rodzic
eab0193232
commit
450818d5e3
|
@ -5,13 +5,18 @@ import android.view.MenuItem;
|
|||
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.radio.codec2talkie.R;
|
||||
import com.radio.codec2talkie.storage.message.group.MessageGroupAdapter;
|
||||
import com.radio.codec2talkie.storage.message.group.MessageGroupViewModel;
|
||||
|
||||
public class MessageItemActivity extends AppCompatActivity {
|
||||
|
||||
private MessageGroupViewModel _messageGroupViewModel;
|
||||
private MessageItemViewModel _messageViewModel;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -20,6 +25,17 @@ public class MessageItemActivity extends AppCompatActivity {
|
|||
setTitle(R.string.messages_view_title);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
RecyclerView recyclerView = findViewById(R.id.message_recyclerview);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
final MessageItemAdapter adapter = new MessageItemAdapter(new MessageItemAdapter.MessageItemDiff());
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
recyclerView.addItemDecoration(new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL));
|
||||
|
||||
String groupName = (String) getIntent().getExtras().get("groupName");
|
||||
_messageViewModel = new ViewModelProvider(this).get(MessageItemViewModel.class);
|
||||
_messageViewModel.getMessages(groupName).observe(this, adapter::submitList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,18 +18,20 @@ public class MessageItemHolder extends RecyclerView.ViewHolder {
|
|||
|
||||
private MessageItemHolder(View itemView) {
|
||||
super(itemView);
|
||||
messageItemViewTitle = itemView.findViewById(R.id.log_view_item_title);
|
||||
messageItemViewMessage = itemView.findViewById(R.id.log_view_item_message);
|
||||
messageItemViewTitle = itemView.findViewById(R.id.message_view_item_name);
|
||||
messageItemViewMessage = itemView.findViewById(R.id.message_item_message);
|
||||
}
|
||||
|
||||
public void bind(long timestamp, String srcCallsign, String text) {
|
||||
messageItemViewTitle.setText("");
|
||||
messageItemViewMessage.setText("");
|
||||
messageItemViewTitle.setText(String.format("%s %s",
|
||||
DateTools.epochToIso8601(timestamp),
|
||||
srcCallsign));
|
||||
messageItemViewMessage.setText(text);
|
||||
}
|
||||
|
||||
static MessageItemHolder create(ViewGroup parent) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.activity_log_view_item, parent, false);
|
||||
R.layout.activity_message_view_item, parent, false);
|
||||
return new MessageItemHolder(view);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.radio.codec2talkie.storage.message.group;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -21,7 +22,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
import com.radio.codec2talkie.R;
|
||||
import com.radio.codec2talkie.app.AppService;
|
||||
|
||||
public class MessageGroupActivity extends AppCompatActivity {
|
||||
public class MessageGroupActivity extends AppCompatActivity implements ServiceConnection, View.OnClickListener {
|
||||
|
||||
private static final String TAG = MessageGroupActivity.class.getSimpleName();
|
||||
|
||||
|
@ -33,13 +34,15 @@ public class MessageGroupActivity extends AppCompatActivity {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.i(TAG, "onCreate()");
|
||||
bindAppService();
|
||||
|
||||
setContentView(R.layout.activity_message_groups_view);
|
||||
setTitle(R.string.messages_group_view_title);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
Button sendToButton = findViewById(R.id.messages_send_to);
|
||||
sendToButton.setOnClickListener(_onSendToButtonListener);
|
||||
sendToButton.setOnClickListener(this);
|
||||
|
||||
RecyclerView recyclerView = findViewById(R.id.message_groups_recyclerview);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
|
@ -50,8 +53,6 @@ public class MessageGroupActivity extends AppCompatActivity {
|
|||
|
||||
_messageGroupViewModel = new ViewModelProvider(this).get(MessageGroupViewModel.class);
|
||||
_messageGroupViewModel.getGroups().observe(this, adapter::submitList);
|
||||
|
||||
bindAppService();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,11 +62,6 @@ public class MessageGroupActivity extends AppCompatActivity {
|
|||
unbindAppService();
|
||||
}
|
||||
|
||||
private final View.OnClickListener _onSendToButtonListener = v -> {
|
||||
MessageGroupDialogSendTo dialogSendTo = new MessageGroupDialogSendTo(MessageGroupActivity.this, _appService);
|
||||
dialogSendTo.show();
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
|
@ -79,27 +75,30 @@ public class MessageGroupActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
private void bindAppService() {
|
||||
if (!bindService(new Intent(this, AppService.class), _appServiceConnection, Context.BIND_AUTO_CREATE)) {
|
||||
if (!bindService(new Intent(this, AppService.class), this, Context.BIND_AUTO_CREATE)) {
|
||||
Log.e(TAG, "Service does not exists or no access");
|
||||
}
|
||||
}
|
||||
|
||||
private void unbindAppService() {
|
||||
unbindService(_appServiceConnection);
|
||||
unbindService(this);
|
||||
}
|
||||
|
||||
private final ServiceConnection _appServiceConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||
Log.i(TAG, "Connected to app service");
|
||||
_appService = ((AppService.AppServiceBinder)service).getService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||
Log.i(TAG, "Connected to app service");
|
||||
_appService = ((AppService.AppServiceBinder)service).getService();
|
||||
}
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName className) {
|
||||
Log.i(TAG, "Disconnected from app service");
|
||||
_appService = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName className) {
|
||||
Log.i(TAG, "Disconnected from app service");
|
||||
_appService = null;
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MessageGroupDialogSendTo dialogSendTo = new MessageGroupDialogSendTo(MessageGroupActivity.this, _appService);
|
||||
dialogSendTo.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.radio.codec2talkie.storage.message.group;
|
||||
|
||||
import android.util.Log;
|
||||
import android.content.Intent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -9,6 +9,7 @@ import android.widget.TextView;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.radio.codec2talkie.R;
|
||||
import com.radio.codec2talkie.storage.message.MessageItemActivity;
|
||||
|
||||
public class MessageGroupHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
|
||||
|
@ -34,6 +35,9 @@ public class MessageGroupHolder extends RecyclerView.ViewHolder implements View.
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Log.i("---", "onClick:" + messageGroupsViewItemName.getText());
|
||||
String groupName = messageGroupsViewItemName.getText().toString();
|
||||
Intent messagesIntent = new Intent(v.getContext(), MessageItemActivity.class);
|
||||
messagesIntent.putExtra("groupName", groupName);
|
||||
v.getContext().startActivity(messagesIntent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
tools:context=".storage.message.MessageItemActivity">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/message_groups_recyclerview"
|
||||
android:id="@+id/message_recyclerview"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:padding="8dp"
|
||||
|
@ -18,14 +18,14 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="1.0"
|
||||
tools:listitem="@layout/activity_message_groups_view_item" />
|
||||
tools:listitem="@layout/activity_message_view_item" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatEditText
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toStartOf="@+id/messages_send"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/message_groups_recyclerview" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/message_recyclerview" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/messages_send"
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
style="@style/message_item_txt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:lines="3"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/message_view_item_name" />
|
||||
|
||||
|
|
|
@ -46,6 +46,6 @@
|
|||
<item name="android:paddingLeft">4dp</item>
|
||||
<item name="android:background">@android:color/white</item>
|
||||
<item name="android:textColor">@color/grey</item>
|
||||
<item name="android:textAppearance">@android:style/TextAppearance.DeviceDefault.Small</item>
|
||||
<item name="android:textAppearance">@android:style/TextAppearance.DeviceDefault.Medium</item>
|
||||
</style>
|
||||
</resources>
|
Ładowanie…
Reference in New Issue