Merge branch 'master' into legacy

legacy
sh123 2022-07-21 11:12:19 +03:00
commit fa5ec85254
12 zmienionych plików z 200 dodań i 24 usunięć

Wyświetl plik

@ -1,9 +1,12 @@
package com.radio.codec2talkie.storage.log;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
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,9 @@ public class LogItemActivity extends AppCompatActivity {
_groupName = (String)bundle.get("groupName");
}
if (_groupName == null) {
logItemGroupRecyclerView.setVisibility(View.GONE);
findViewById(R.id.log_item_textview).setVisibility(View.GONE);
findViewById(R.id.log_item_group_textview).setVisibility(View.GONE);
_logItemViewModel.getAllData().observe(this, adapter::submitList);
setTitle(R.string.aprs_log_view_title);
} else {
@ -60,6 +84,14 @@ public class LogItemActivity extends AppCompatActivity {
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if (_groupName != null) {
menu.findItem(R.id.log_view_menu_stations).setVisible(false);
}
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
@ -72,6 +104,11 @@ public class LogItemActivity extends AppCompatActivity {
else if (itemId == R.id.log_view_menu_clear) {
deleteAll();
return true;
} else if (itemId == R.id.log_view_menu_stations) {
Intent logItemIntent = new Intent(this, LogItemActivity.class);
logItemIntent.putExtra("groupName", getString(R.string.log_view_station_history));
startActivity(logItemIntent);
return true;
}
return super.onOptionsItemSelected(item);
}

Wyświetl plik

@ -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")

Wyświetl plik

@ -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);
}
}
}

Wyświetl plik

@ -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);
}
}

Wyświetl plik

@ -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) {

Wyświetl plik

@ -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) {

Wyświetl plik

@ -7,16 +7,41 @@
android:layout_height="match_parent"
tools:context=".storage.log.LogItemActivity">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/log_item_group_textview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="@string/log_item_group_textview_title"
android:padding="4dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/log_item_group_recyclerview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:padding="4dp"
android:scrollbars="vertical"
app:layout_constraintHeight_percent="0.5"
app:layout_constraintTop_toBottomOf="@+id/log_item_group_textview"
tools:listitem="@layout/activity_log_view_group_item" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/log_item_textview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:padding="4dp"
android:text="@string/log_item_textview_title"
app:layout_constraintTop_toBottomOf="@+id/log_item_group_recyclerview"/>
<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:padding="4dp"
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_textview"
tools:listitem="@layout/activity_log_view_item" />
</androidx.constraintlayout.widget.ConstraintLayout>

Wyświetl plik

@ -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>

Wyświetl plik

@ -11,7 +11,7 @@
android:id="@+id/message_groups_recyclerview"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="8dp"
android:padding="4dp"
android:scrollbars="vertical"
app:layout_constraintBottom_toTopOf="@+id/messages_send_to"
app:layout_constraintEnd_toEndOf="parent"

Wyświetl plik

@ -10,7 +10,7 @@
android:id="@+id/message_recyclerview"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="8dp"
android:padding="4dp"
android:scrollbars="vertical"
app:layout_constraintBottom_toTopOf="@+id/messages_send"
app:layout_constraintEnd_toEndOf="parent"

Wyświetl plik

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/log_view_menu_stations"
android:title="@string/log_view_menu_stations" />
<item
android:id="@+id/log_view_menu_clear"
android:title="@string/log_view_menu_clear" />

Wyświetl plik

@ -249,7 +249,7 @@
<string name="app_service_notif_text_ptt_ready">Connected to the TNC, ready for PTT</string>
<string name="app_service_notif_text_tracking">APRS tracking is active</string>
<string name="app_service_notif_connection_lost">Disconnected from the TNC, click to reconnect</string>
<string name="aprs_log_view_title">APRS raw log</string>
<string name="aprs_log_view_title">APRS log</string>
<string name="log_view_menu_clear">Clear log</string>
<string name="tracking_label">&#127937;</string>
<string name="app_notifications_voice_enable_title">Enable incoming notifications</string>
@ -284,4 +284,8 @@
<string name="log_item_activity_delete_all_title">This will remove everything from the log. Are you sure?</string>
<string name="log_item_activity_delete_group_title">This will remove log for %s. Are you sure?</string>
<string name="messages_group_activity_delete_group_confirmation_title">This will remove all messages from %s. Are you sure?</string>
<string name="log_item_textview_title">Station history</string>
<string name="log_item_group_textview_title">Station SSIDS</string>
<string name="log_view_menu_stations">View stations</string>
<string name="log_view_station_history">Station history</string>
</resources>