mirror of
https://github.com/etesync/android
synced 2025-02-02 19:01:06 +00:00
Journal item: view journal item in a separate activity.
This change makes clicking on journal items in the list to show in a separate activity. At the moment it just makes for a slightly nicer presentation. In the future we would change it to show the data in a nice formatted way instead of a raw dump of the vObject.
This commit is contained in:
parent
889eede699
commit
e6ba52074a
@ -220,6 +220,7 @@
|
|||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".ui.ViewCollectionActivity"/>
|
<activity android:name=".ui.ViewCollectionActivity"/>
|
||||||
<activity android:name=".ui.CollectionMembersActivity"/>
|
<activity android:name=".ui.CollectionMembersActivity"/>
|
||||||
|
<activity android:name=".ui.JournalItemActivity"/>
|
||||||
<activity android:name=".ui.importlocal.ImportActivity"/>
|
<activity android:name=".ui.importlocal.ImportActivity"/>
|
||||||
<activity android:name=".ui.AccountSettingsActivity"/>
|
<activity android:name=".ui.AccountSettingsActivity"/>
|
||||||
<activity android:name=".ui.CreateCollectionActivity"/>
|
<activity android:name=".ui.CreateCollectionActivity"/>
|
||||||
|
@ -4,9 +4,11 @@ import com.etesync.syncadapter.GsonHelper;
|
|||||||
import com.etesync.syncadapter.journalmanager.Crypto;
|
import com.etesync.syncadapter.journalmanager.Crypto;
|
||||||
import com.etesync.syncadapter.journalmanager.JournalEntryManager;
|
import com.etesync.syncadapter.journalmanager.JournalEntryManager;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
public class SyncEntry {
|
public class SyncEntry implements Serializable {
|
||||||
@Getter
|
@Getter
|
||||||
private String content;
|
private String content;
|
||||||
@Getter
|
@Getter
|
||||||
|
@ -0,0 +1,101 @@
|
|||||||
|
package com.etesync.syncadapter.ui;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.etesync.syncadapter.App;
|
||||||
|
import com.etesync.syncadapter.Constants;
|
||||||
|
import com.etesync.syncadapter.R;
|
||||||
|
import com.etesync.syncadapter.model.CollectionInfo;
|
||||||
|
import com.etesync.syncadapter.model.JournalEntity;
|
||||||
|
import com.etesync.syncadapter.model.SyncEntry;
|
||||||
|
import com.etesync.syncadapter.resource.LocalCalendar;
|
||||||
|
|
||||||
|
import io.requery.Persistable;
|
||||||
|
import io.requery.sql.EntityDataStore;
|
||||||
|
|
||||||
|
import static com.etesync.syncadapter.ui.journalviewer.ListEntriesFragment.setJournalEntryView;
|
||||||
|
|
||||||
|
public class JournalItemActivity extends BaseActivity implements Refreshable {
|
||||||
|
private static final String KEY_SYNC_ENTRY = "syncEntry";
|
||||||
|
private JournalEntity journalEntity;
|
||||||
|
protected CollectionInfo info;
|
||||||
|
private SyncEntry syncEntry;
|
||||||
|
|
||||||
|
public static Intent newIntent(Context context, CollectionInfo info, SyncEntry syncEntry) {
|
||||||
|
Intent intent = new Intent(context, JournalItemActivity.class);
|
||||||
|
intent.putExtra(Constants.KEY_COLLECTION_INFO, info);
|
||||||
|
intent.putExtra(KEY_SYNC_ENTRY, syncEntry);
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refresh() {
|
||||||
|
EntityDataStore<Persistable> data = ((App) getApplicationContext()).getData();
|
||||||
|
|
||||||
|
journalEntity = JournalEntity.fetch(data, info.getServiceEntity(data), info.uid);
|
||||||
|
if ((journalEntity == null) || journalEntity.isDeleted()) {
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
info = journalEntity.getInfo();
|
||||||
|
|
||||||
|
setTitle(R.string.journal_item_title);
|
||||||
|
|
||||||
|
final View colorSquare = findViewById(R.id.color);
|
||||||
|
if (info.type == CollectionInfo.Type.CALENDAR) {
|
||||||
|
if (info.color != null) {
|
||||||
|
colorSquare.setBackgroundColor(info.color);
|
||||||
|
} else {
|
||||||
|
colorSquare.setBackgroundColor(LocalCalendar.defaultColor);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
colorSquare.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
final TextView title = (TextView) findViewById(R.id.display_name);
|
||||||
|
title.setText(info.displayName);
|
||||||
|
|
||||||
|
final TextView desc = (TextView) findViewById(R.id.description);
|
||||||
|
desc.setText(info.description);
|
||||||
|
|
||||||
|
final TextView content = (TextView) findViewById(R.id.content);
|
||||||
|
content.setText(syncEntry.getContent());
|
||||||
|
|
||||||
|
setJournalEntryView(findViewById(R.id.journal_list_item), info, syncEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
setContentView(R.layout.journal_item_activity);
|
||||||
|
|
||||||
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
|
info = (CollectionInfo) getIntent().getExtras().getSerializable(Constants.KEY_COLLECTION_INFO);
|
||||||
|
syncEntry = (SyncEntry) getIntent().getExtras().getSerializable(KEY_SYNC_ENTRY);
|
||||||
|
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
// We refresh before this, so we don't refresh the list before it was fully created.
|
||||||
|
if (savedInstanceState == null) {
|
||||||
|
/*
|
||||||
|
listFragment = CollectionMembersListFragment.newInstance(account, info);
|
||||||
|
getSupportFragmentManager().beginTransaction()
|
||||||
|
.add(R.id.list_entries_container, listFragment)
|
||||||
|
.commit();
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,6 @@ import android.os.AsyncTask;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.ListFragment;
|
import android.support.v4.app.ListFragment;
|
||||||
import android.support.v7.app.AlertDialog;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -28,6 +27,8 @@ import com.etesync.syncadapter.model.CollectionInfo;
|
|||||||
import com.etesync.syncadapter.model.EntryEntity;
|
import com.etesync.syncadapter.model.EntryEntity;
|
||||||
import com.etesync.syncadapter.model.JournalEntity;
|
import com.etesync.syncadapter.model.JournalEntity;
|
||||||
import com.etesync.syncadapter.model.JournalModel;
|
import com.etesync.syncadapter.model.JournalModel;
|
||||||
|
import com.etesync.syncadapter.model.SyncEntry;
|
||||||
|
import com.etesync.syncadapter.ui.JournalItemActivity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -81,9 +82,7 @@ public class ListEntriesFragment extends ListFragment implements AdapterView.OnI
|
|||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
EntryEntity entry = (EntryEntity) getListAdapter().getItem(position);
|
EntryEntity entry = (EntryEntity) getListAdapter().getItem(position);
|
||||||
new AlertDialog.Builder(getActivity())
|
startActivity(JournalItemActivity.newIntent(getContext(), info, entry.getContent()));
|
||||||
.setTitle("Raw dump")
|
|
||||||
.setMessage("Action: " + entry.getContent().getAction().toString() + "\nIntegrity: " + entry.getUid() + "\n" + entry.getContent().getContent()).show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class EntriesListAdapter extends ArrayAdapter<EntryEntity> {
|
class EntriesListAdapter extends ArrayAdapter<EntryEntity> {
|
||||||
@ -91,20 +90,6 @@ public class ListEntriesFragment extends ListFragment implements AdapterView.OnI
|
|||||||
super(context, R.layout.journal_viewer_list_item);
|
super(context, R.layout.journal_viewer_list_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLine(String content, String prefix) {
|
|
||||||
if (content == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
int start = content.indexOf(prefix);
|
|
||||||
if (start >= 0) {
|
|
||||||
int end = content.indexOf("\n", start);
|
|
||||||
content = content.substring(start + prefix.length(), end);
|
|
||||||
} else {
|
|
||||||
content = null;
|
|
||||||
}
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public View getView(int position, View v, @NonNull ViewGroup parent) {
|
public View getView(int position, View v, @NonNull ViewGroup parent) {
|
||||||
@ -117,39 +102,62 @@ public class ListEntriesFragment extends ListFragment implements AdapterView.OnI
|
|||||||
|
|
||||||
// FIXME: hacky way to make it show sensible info
|
// FIXME: hacky way to make it show sensible info
|
||||||
CollectionInfo info = journalEntity.getInfo();
|
CollectionInfo info = journalEntity.getInfo();
|
||||||
String fullContent = entryEntity.getContent().getContent();
|
setJournalEntryView(v, info, entryEntity.getContent());
|
||||||
String prefix;
|
|
||||||
if (info.type == CollectionInfo.Type.CALENDAR) {
|
|
||||||
prefix = "SUMMARY:";
|
|
||||||
} else {
|
|
||||||
prefix = "FN:";
|
|
||||||
}
|
|
||||||
String content = getLine(fullContent, prefix);
|
|
||||||
content = (content != null) ? content : entryEntity.getUid().substring(0, 20);
|
|
||||||
tv.setText(content);
|
|
||||||
|
|
||||||
tv = (TextView) v.findViewById(R.id.description);
|
|
||||||
content = getLine(fullContent, "UID:");
|
|
||||||
content = "UID: " + ((content != null) ? content : "Not found");
|
|
||||||
tv.setText(content);
|
|
||||||
|
|
||||||
ImageView action = (ImageView) v.findViewById(R.id.action);
|
|
||||||
switch (entryEntity.getContent().getAction()) {
|
|
||||||
case ADD:
|
|
||||||
action.setImageResource(R.drawable.action_add);
|
|
||||||
break;
|
|
||||||
case CHANGE:
|
|
||||||
action.setImageResource(R.drawable.action_change);
|
|
||||||
break;
|
|
||||||
case DELETE:
|
|
||||||
action.setImageResource(R.drawable.action_delete);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getLine(String content, String prefix) {
|
||||||
|
if (content == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int start = content.indexOf(prefix);
|
||||||
|
if (start >= 0) {
|
||||||
|
int end = content.indexOf("\n", start);
|
||||||
|
content = content.substring(start + prefix.length(), end);
|
||||||
|
} else {
|
||||||
|
content = null;
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setJournalEntryView(View v, CollectionInfo info, SyncEntry syncEntry) {
|
||||||
|
|
||||||
|
TextView tv = (TextView) v.findViewById(R.id.title);
|
||||||
|
|
||||||
|
// FIXME: hacky way to make it show sensible info
|
||||||
|
String fullContent = syncEntry.getContent();
|
||||||
|
String prefix;
|
||||||
|
if (info.type == CollectionInfo.Type.CALENDAR) {
|
||||||
|
prefix = "SUMMARY:";
|
||||||
|
} else {
|
||||||
|
prefix = "FN:";
|
||||||
|
}
|
||||||
|
String content = getLine(fullContent, prefix);
|
||||||
|
content = (content != null) ? content : "Not found";
|
||||||
|
tv.setText(content);
|
||||||
|
|
||||||
|
tv = (TextView) v.findViewById(R.id.description);
|
||||||
|
content = getLine(fullContent, "UID:");
|
||||||
|
content = "UID: " + ((content != null) ? content : "Not found");
|
||||||
|
tv.setText(content);
|
||||||
|
|
||||||
|
ImageView action = (ImageView) v.findViewById(R.id.action);
|
||||||
|
switch (syncEntry.getAction()) {
|
||||||
|
case ADD:
|
||||||
|
action.setImageResource(R.drawable.action_add);
|
||||||
|
break;
|
||||||
|
case CHANGE:
|
||||||
|
action.setImageResource(R.drawable.action_change);
|
||||||
|
break;
|
||||||
|
case DELETE:
|
||||||
|
action.setImageResource(R.drawable.action_delete);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class JournalFetch extends AsyncTask<Void, Void, List<EntryEntity>> {
|
private class JournalFetch extends AsyncTask<Void, Void, List<EntryEntity>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
30
app/src/main/res/layout/journal_item_activity.xml
Normal file
30
app/src/main/res/layout/journal_item_activity.xml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/collection_header"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/activity_margin" />
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/journal_list_item"
|
||||||
|
layout="@layout/journal_viewer_list_item"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/activity_margin"
|
||||||
|
android:textIsSelectable="true" />
|
||||||
|
</ScrollView>
|
||||||
|
</LinearLayout>
|
@ -128,6 +128,9 @@
|
|||||||
<string name="collection_members_remove_title">Remove member</string>
|
<string name="collection_members_remove_title">Remove member</string>
|
||||||
<string name="collection_members_remove">Would you like to revoke %s\'s access?\nPlease be advised that a malicious user would potentially be able to retain access to encryption keys. Please refer to the FAQ for more information.</string>
|
<string name="collection_members_remove">Would you like to revoke %s\'s access?\nPlease be advised that a malicious user would potentially be able to retain access to encryption keys. Please refer to the FAQ for more information.</string>
|
||||||
|
|
||||||
|
<!-- JournalItemActivity -->
|
||||||
|
<string name="journal_item_title">Journal Item</string>
|
||||||
|
|
||||||
<!-- PermissionsActivity -->
|
<!-- PermissionsActivity -->
|
||||||
<string name="permissions_title">EteSync permissions</string>
|
<string name="permissions_title">EteSync permissions</string>
|
||||||
<string name="permissions_calendar">Calendar permissions</string>
|
<string name="permissions_calendar">Calendar permissions</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user