@ -0,0 +1,192 @@
|
|||||||
|
package eu.faircode.email;
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Safe email.
|
||||||
|
|
||||||
|
Safe email is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
NetGuard is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Copyright 2018 by Marcel Bokhorst (M66B)
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
|
import androidx.recyclerview.widget.DiffUtil;
|
||||||
|
import androidx.recyclerview.widget.ListUpdateCallback;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.ViewHolder> {
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
private List<EntityOperation> all = new ArrayList<>();
|
||||||
|
private List<EntityOperation> filtered = new ArrayList<>();
|
||||||
|
|
||||||
|
private DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.LONG);
|
||||||
|
|
||||||
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
|
View itemView;
|
||||||
|
TextView tvMessage;
|
||||||
|
TextView tvName;
|
||||||
|
TextView tvTime;
|
||||||
|
|
||||||
|
ViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
this.itemView = itemView;
|
||||||
|
tvMessage = itemView.findViewById(R.id.tvMessage);
|
||||||
|
tvName = itemView.findViewById(R.id.tvName);
|
||||||
|
tvTime = itemView.findViewById(R.id.tvTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void wire() {
|
||||||
|
itemView.setOnClickListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unwire() {
|
||||||
|
itemView.setOnClickListener(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindTo(EntityOperation operation) {
|
||||||
|
tvMessage.setText(Long.toString(operation.message));
|
||||||
|
tvName.setText(operation.name);
|
||||||
|
tvTime.setText(df.format(new Date(operation.created)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
int pos = getAdapterPosition();
|
||||||
|
if (pos == RecyclerView.NO_POSITION)
|
||||||
|
return;
|
||||||
|
EntityOperation operation = filtered.get(pos);
|
||||||
|
|
||||||
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
||||||
|
lbm.sendBroadcast(
|
||||||
|
new Intent(ActivityView.ACTION_VIEW_MESSAGE)
|
||||||
|
.putExtra("id", operation.message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AdapterOperation(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
setHasStableIds(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(@NonNull List<EntityOperation> operations) {
|
||||||
|
Log.i(Helper.TAG, "Set operations=" + operations.size());
|
||||||
|
|
||||||
|
all.clear();
|
||||||
|
all.addAll(operations);
|
||||||
|
|
||||||
|
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new MessageDiffCallback(filtered, all));
|
||||||
|
|
||||||
|
filtered.clear();
|
||||||
|
filtered.addAll(all);
|
||||||
|
|
||||||
|
diff.dispatchUpdatesTo(new ListUpdateCallback() {
|
||||||
|
@Override
|
||||||
|
public void onInserted(int position, int count) {
|
||||||
|
Log.i(Helper.TAG, "Inserted @" + position + " #" + count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRemoved(int position, int count) {
|
||||||
|
Log.i(Helper.TAG, "Removed @" + position + " #" + count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMoved(int fromPosition, int toPosition) {
|
||||||
|
Log.i(Helper.TAG, "Moved " + fromPosition + ">" + toPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChanged(int position, int count, Object payload) {
|
||||||
|
Log.i(Helper.TAG, "Changed @" + position + " #" + count);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
diff.dispatchUpdatesTo(AdapterOperation.this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MessageDiffCallback extends DiffUtil.Callback {
|
||||||
|
private List<EntityOperation> prev;
|
||||||
|
private List<EntityOperation> next;
|
||||||
|
|
||||||
|
MessageDiffCallback(List<EntityOperation> prev, List<EntityOperation> next) {
|
||||||
|
this.prev = prev;
|
||||||
|
this.next = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOldListSize() {
|
||||||
|
return prev.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNewListSize() {
|
||||||
|
return next.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
|
||||||
|
EntityOperation a1 = prev.get(oldItemPosition);
|
||||||
|
EntityOperation a2 = next.get(newItemPosition);
|
||||||
|
return a1.id.equals(a2.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
|
||||||
|
EntityOperation a1 = prev.get(oldItemPosition);
|
||||||
|
EntityOperation a2 = next.get(newItemPosition);
|
||||||
|
return a1.equals(a2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(int position) {
|
||||||
|
return filtered.get(position).id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return filtered.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_operation, parent, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||||
|
holder.unwire();
|
||||||
|
|
||||||
|
EntityOperation operation = filtered.get(position);
|
||||||
|
holder.bindTo(operation);
|
||||||
|
|
||||||
|
holder.wire();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
package eu.faircode.email;
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Safe email.
|
||||||
|
|
||||||
|
Safe email is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
NetGuard is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Copyright 2018 by Marcel Bokhorst (M66B)
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.constraintlayout.widget.Group;
|
||||||
|
import androidx.lifecycle.Observer;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
public class FragmentOperations extends FragmentEx {
|
||||||
|
private RecyclerView rvOperation;
|
||||||
|
private ProgressBar pbWait;
|
||||||
|
private Group grpReady;
|
||||||
|
|
||||||
|
private AdapterOperation adapter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.fragment_operations, container, false);
|
||||||
|
|
||||||
|
// Get controls
|
||||||
|
rvOperation = view.findViewById(R.id.rvOperation);
|
||||||
|
pbWait = view.findViewById(R.id.pbWait);
|
||||||
|
grpReady = view.findViewById(R.id.grpReady);
|
||||||
|
|
||||||
|
// Wire controls
|
||||||
|
|
||||||
|
rvOperation.setHasFixedSize(false);
|
||||||
|
LinearLayoutManager llm = new LinearLayoutManager(getContext());
|
||||||
|
rvOperation.setLayoutManager(llm);
|
||||||
|
|
||||||
|
adapter = new AdapterOperation(getContext());
|
||||||
|
rvOperation.setAdapter(adapter);
|
||||||
|
|
||||||
|
// Initialize
|
||||||
|
grpReady.setVisibility(View.GONE);
|
||||||
|
pbWait.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
|
// Observe folders
|
||||||
|
DB.getInstance(getContext()).operation().liveOperations().observe(getViewLifecycleOwner(), new Observer<List<EntityOperation>>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(@Nullable List<EntityOperation> operations) {
|
||||||
|
if (operations != null)
|
||||||
|
adapter.set(operations);
|
||||||
|
|
||||||
|
pbWait.setVisibility(View.GONE);
|
||||||
|
grpReady.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 144 B |
After Width: | Height: | Size: 123 B |
After Width: | Height: | Size: 133 B |
After Width: | Height: | Size: 111 B |
After Width: | Height: | Size: 147 B |
After Width: | Height: | Size: 124 B |
After Width: | Height: | Size: 133 B |
After Width: | Height: | Size: 94 B |
After Width: | Height: | Size: 89 B |
After Width: | Height: | Size: 93 B |
After Width: | Height: | Size: 123 B |
After Width: | Height: | Size: 110 B |
After Width: | Height: | Size: 92 B |
After Width: | Height: | Size: 89 B |
After Width: | Height: | Size: 124 B |
After Width: | Height: | Size: 95 B |
After Width: | Height: | Size: 123 B |
After Width: | Height: | Size: 110 B |
After Width: | Height: | Size: 111 B |
After Width: | Height: | Size: 117 B |
After Width: | Height: | Size: 124 B |
After Width: | Height: | Size: 95 B |
After Width: | Height: | Size: 94 B |
After Width: | Height: | Size: 100 B |
After Width: | Height: | Size: 133 B |
After Width: | Height: | Size: 111 B |
After Width: | Height: | Size: 154 B |
After Width: | Height: | Size: 128 B |
After Width: | Height: | Size: 133 B |
After Width: | Height: | Size: 94 B |
After Width: | Height: | Size: 154 B |
After Width: | Height: | Size: 111 B |
After Width: | Height: | Size: 111 B |
After Width: | Height: | Size: 117 B |
After Width: | Height: | Size: 128 B |
After Width: | Height: | Size: 132 B |
After Width: | Height: | Size: 94 B |
After Width: | Height: | Size: 100 B |
After Width: | Height: | Size: 111 B |
After Width: | Height: | Size: 115 B |
@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M3,13h2v-2L3,11v2zM3,17h2v-2L3,15v2zM3,9h2L5,7L3,7v2zM7,13h14v-2L7,11v2zM7,17h14v-2L7,15v2zM7,7v2h14L21,7L7,7z"/>
|
||||||
|
</vector>
|
@ -0,0 +1,36 @@
|
|||||||
|
<?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"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".ActivityView">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/rvOperation"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:scrollbarStyle="outsideOverlay"
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/pbWait"
|
||||||
|
style="@style/Base.Widget.AppCompat.ProgressBar"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:indeterminate="true"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.Group
|
||||||
|
android:id="@+id/grpReady"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:constraint_referenced_ids="rvOperation" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -0,0 +1,38 @@
|
|||||||
|
<?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:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="3dp"
|
||||||
|
android:layout_marginTop="3dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvMessage"
|
||||||
|
android:layout_width="50dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="6dp"
|
||||||
|
android:text="Msg#"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvName"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="6dp"
|
||||||
|
android:text="Name"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/tvMessage"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvTime"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="6dp"
|
||||||
|
android:text="Time"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|