diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d0d5b632..985eced2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -220,6 +220,7 @@ + diff --git a/app/src/main/java/com/etesync/syncadapter/model/SyncEntry.java b/app/src/main/java/com/etesync/syncadapter/model/SyncEntry.java index 449d7a04..5087ba1a 100644 --- a/app/src/main/java/com/etesync/syncadapter/model/SyncEntry.java +++ b/app/src/main/java/com/etesync/syncadapter/model/SyncEntry.java @@ -4,9 +4,11 @@ import com.etesync.syncadapter.GsonHelper; import com.etesync.syncadapter.journalmanager.Crypto; import com.etesync.syncadapter.journalmanager.JournalEntryManager; +import java.io.Serializable; + import lombok.Getter; -public class SyncEntry { +public class SyncEntry implements Serializable { @Getter private String content; @Getter diff --git a/app/src/main/java/com/etesync/syncadapter/ui/JournalItemActivity.java b/app/src/main/java/com/etesync/syncadapter/ui/JournalItemActivity.java new file mode 100644 index 00000000..ae339860 --- /dev/null +++ b/app/src/main/java/com/etesync/syncadapter/ui/JournalItemActivity.java @@ -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 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(); + } +} diff --git a/app/src/main/java/com/etesync/syncadapter/ui/journalviewer/ListEntriesFragment.java b/app/src/main/java/com/etesync/syncadapter/ui/journalviewer/ListEntriesFragment.java index f75e1819..cf58a41b 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/journalviewer/ListEntriesFragment.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/journalviewer/ListEntriesFragment.java @@ -13,7 +13,6 @@ import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.ListFragment; -import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; 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.JournalEntity; import com.etesync.syncadapter.model.JournalModel; +import com.etesync.syncadapter.model.SyncEntry; +import com.etesync.syncadapter.ui.JournalItemActivity; import java.util.List; @@ -81,9 +82,7 @@ public class ListEntriesFragment extends ListFragment implements AdapterView.OnI @Override public void onItemClick(AdapterView parent, View view, int position, long id) { EntryEntity entry = (EntryEntity) getListAdapter().getItem(position); - new AlertDialog.Builder(getActivity()) - .setTitle("Raw dump") - .setMessage("Action: " + entry.getContent().getAction().toString() + "\nIntegrity: " + entry.getUid() + "\n" + entry.getContent().getContent()).show(); + startActivity(JournalItemActivity.newIntent(getContext(), info, entry.getContent())); } class EntriesListAdapter extends ArrayAdapter { @@ -91,20 +90,6 @@ public class ListEntriesFragment extends ListFragment implements AdapterView.OnI 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 @NonNull 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 CollectionInfo info = journalEntity.getInfo(); - String fullContent = entryEntity.getContent().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; - } + setJournalEntryView(v, info, entryEntity.getContent()); 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> { @Override diff --git a/app/src/main/res/layout/journal_item_activity.xml b/app/src/main/res/layout/journal_item_activity.xml new file mode 100644 index 00000000..f770361e --- /dev/null +++ b/app/src/main/res/layout/journal_item_activity.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bea03001..a66f79b0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -128,6 +128,9 @@ Remove member 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. + + Journal Item + EteSync permissions Calendar permissions