kopia lustrzana https://github.com/sh123/codec2_talkie
Hub like log grouping
rodzic
85c5255a22
commit
2367e46094
|
@ -2,8 +2,11 @@ package com.radio.codec2talkie.storage.log;
|
|||
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
@ -27,17 +30,35 @@ public class LogItemActivity extends AppCompatActivity {
|
|||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
RecyclerView recyclerView = findViewById(R.id.log_item_recyclerview);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
_logItemViewModel = new ViewModelProvider(this).get(LogItemViewModel.class);
|
||||
|
||||
// log items
|
||||
RecyclerView logItemRecyclerView = findViewById(R.id.log_item_recyclerview);
|
||||
logItemRecyclerView.setHasFixedSize(true);
|
||||
|
||||
final LogItemAdapter adapter = new LogItemAdapter(new LogItemAdapter.LogItemDiff());
|
||||
recyclerView.setAdapter(adapter);
|
||||
logItemRecyclerView.setAdapter(adapter);
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
|
||||
linearLayoutManager.setStackFromEnd(true);
|
||||
recyclerView.setLayoutManager(linearLayoutManager);
|
||||
recyclerView.addItemDecoration(new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL));
|
||||
logItemRecyclerView.setLayoutManager(linearLayoutManager);
|
||||
logItemRecyclerView.addItemDecoration(new DividerItemDecoration(logItemRecyclerView.getContext(), DividerItemDecoration.VERTICAL));
|
||||
|
||||
_logItemViewModel = new ViewModelProvider(this).get(LogItemViewModel.class);
|
||||
// log groups
|
||||
RecyclerView logItemGroupRecyclerView = findViewById(R.id.log_item_group_recyclerview);
|
||||
logItemGroupRecyclerView.setHasFixedSize(true);
|
||||
|
||||
final LogItemGroupAdapter adapterGroup = new LogItemGroupAdapter(new LogItemGroupAdapter.LogItemGroupDiff());
|
||||
adapterGroup.setClickListener(v -> {
|
||||
TextView itemView = v.findViewById(R.id.log_view_group_item_title);
|
||||
_groupName = itemView.getText().toString();
|
||||
_logItemViewModel.getData(_groupName).observe(this, adapter::submitList);
|
||||
setTitle(_groupName);
|
||||
});
|
||||
logItemGroupRecyclerView.setAdapter(adapterGroup);
|
||||
LinearLayoutManager linearLayoutManagerGroup = new LinearLayoutManager(this);
|
||||
logItemGroupRecyclerView.setLayoutManager(linearLayoutManagerGroup);
|
||||
logItemGroupRecyclerView.addItemDecoration(new DividerItemDecoration(logItemGroupRecyclerView.getContext(), DividerItemDecoration.VERTICAL));
|
||||
|
||||
_logItemViewModel.getGroups().observe(this, adapterGroup::submitList);
|
||||
|
||||
// launch with filter if group name is provided
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
|
@ -46,6 +67,7 @@ public class LogItemActivity extends AppCompatActivity {
|
|||
_groupName = (String)bundle.get("groupName");
|
||||
}
|
||||
if (_groupName == null) {
|
||||
logItemGroupRecyclerView.setVisibility(View.GONE);
|
||||
_logItemViewModel.getAllData().observe(this, adapter::submitList);
|
||||
setTitle(R.string.aprs_log_view_title);
|
||||
} else {
|
||||
|
|
|
@ -19,10 +19,10 @@ public interface LogItemDao {
|
|||
@Query("SELECT srcCallsign from LogItem GROUP BY srcCallsign")
|
||||
LiveData<List<String>> getGroups();
|
||||
|
||||
@Query("SELECT * FROM LogItem ORDER by timestampEpoch ASC")
|
||||
@Query("SELECT * FROM LogItem ORDER by timestampEpoch DESC")
|
||||
LiveData<List<LogItem>> getAllLogItems();
|
||||
|
||||
@Query("SELECT * FROM LogItem WHERE srcCallsign = :srcCallsign ORDER BY timestampEpoch ASC")
|
||||
@Query("SELECT * FROM LogItem WHERE srcCallsign = :srcCallsign ORDER BY timestampEpoch DESC")
|
||||
LiveData<List<LogItem>> getLogItems(String srcCallsign);
|
||||
|
||||
@Query("DELETE FROM LogItem WHERE srcCallsign = :srcCallsign")
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package com.radio.codec2talkie.storage.log;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.ListAdapter;
|
||||
|
||||
public class LogItemGroupAdapter extends ListAdapter<String, LogItemGroupHolder> {
|
||||
|
||||
private View.OnClickListener _clickListener;
|
||||
|
||||
public LogItemGroupAdapter(@NonNull DiffUtil.ItemCallback<String> diffCallback) {
|
||||
super(diffCallback);
|
||||
}
|
||||
|
||||
public void setClickListener(View.OnClickListener clickListener) {
|
||||
_clickListener = clickListener;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public LogItemGroupHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
return LogItemGroupHolder.create(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(LogItemGroupHolder holder, int position) {
|
||||
String current = getItem(position);
|
||||
holder.itemView.setOnClickListener(_clickListener);
|
||||
holder.bind(current);
|
||||
}
|
||||
|
||||
static class LogItemGroupDiff extends DiffUtil.ItemCallback<String> {
|
||||
|
||||
@Override
|
||||
public boolean areItemsTheSame(@NonNull String oldItem, @NonNull String newItem) {
|
||||
return oldItem.equals(newItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsTheSame(@NonNull String oldItem, @NonNull String newItem) {
|
||||
return oldItem.equals(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.radio.codec2talkie.storage.log;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.radio.codec2talkie.R;
|
||||
|
||||
public class LogItemGroupHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private final TextView _logItemViewTitle;
|
||||
private final TextView _logItemViewMessage;
|
||||
|
||||
private LogItemGroupHolder(View itemView) {
|
||||
super(itemView);
|
||||
_logItemViewTitle = itemView.findViewById(R.id.log_view_group_item_title);
|
||||
_logItemViewMessage = itemView.findViewById(R.id.log_view_group_item_message);
|
||||
}
|
||||
|
||||
public void bind(String groupName) {
|
||||
_logItemViewTitle.setText(groupName);
|
||||
}
|
||||
|
||||
static LogItemGroupHolder create(ViewGroup parent) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.activity_log_view_group_item, parent, false);
|
||||
return new LogItemGroupHolder(view);
|
||||
}
|
||||
}
|
|
@ -29,10 +29,7 @@ public class LogItemRepository {
|
|||
public LiveData<List<String>> getGroups() { return _logItemGroups; }
|
||||
|
||||
public LiveData<List<LogItem>> getLogItems(String groupName) {
|
||||
if (_logItemGroupLiveData == null) {
|
||||
_logItemGroupLiveData = _logItemDao.getLogItems(groupName);
|
||||
}
|
||||
return _logItemGroupLiveData;
|
||||
return _logItemDao.getLogItems(groupName);
|
||||
}
|
||||
|
||||
public void insertLogItem(LogItem logItem) {
|
||||
|
|
|
@ -15,11 +15,13 @@ public class LogItemViewModel extends AndroidViewModel {
|
|||
private final LogItemRepository _logItemRepository;
|
||||
private final LiveData<List<LogItem>> _logItemLiveData;
|
||||
private LiveData<List<LogItem>> _logItemGroupLiveData;
|
||||
private final LiveData<List<String>> _logItemGroups;
|
||||
|
||||
public LogItemViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
_logItemRepository = new LogItemRepository(application);
|
||||
_logItemLiveData = _logItemRepository.getAllLogItems();
|
||||
_logItemGroups = _logItemRepository.getGroups();
|
||||
}
|
||||
|
||||
public LiveData<List<LogItem>> getAllData() {
|
||||
|
@ -27,11 +29,11 @@ public class LogItemViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public LiveData<List<LogItem>> getData(String groupName) {
|
||||
if (_logItemGroupLiveData == null)
|
||||
_logItemGroupLiveData = _logItemRepository.getLogItems(groupName);
|
||||
return _logItemGroupLiveData;
|
||||
return _logItemRepository.getLogItems(groupName);
|
||||
}
|
||||
|
||||
public LiveData<List<String>> getGroups() { return _logItemGroups; }
|
||||
|
||||
public void deleteAllLogItems() { _logItemRepository.deleteAllLogItems(); }
|
||||
|
||||
public void deleteLogItems(String groupName) {
|
||||
|
|
|
@ -7,16 +7,24 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context=".storage.log.LogItemActivity">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/log_item_group_recyclerview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:padding="5dp"
|
||||
android:scrollbars="vertical"
|
||||
app:layout_constraintHeight_percent="0.33"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:listitem="@layout/activity_log_view_group_item" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/log_item_recyclerview"
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:padding="5dp"
|
||||
android:scrollbars="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/log_item_group_recyclerview"
|
||||
tools:listitem="@layout/activity_log_view_item" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/activity_log_view_item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/log_view_group_item_title"
|
||||
style="@style/log_item_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:lines="1"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/log_view_group_item_message"
|
||||
style="@style/log_item_message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:lines="1"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/log_view_group_item_title" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Ładowanie…
Reference in New Issue