Skip to content

Commit

Permalink
Initial undo log work
Browse files Browse the repository at this point in the history
  • Loading branch information
rtreffer committed Jul 8, 2014
1 parent 8977439 commit 4657c28
Show file tree
Hide file tree
Showing 15 changed files with 279 additions and 87 deletions.
25 changes: 16 additions & 9 deletions AndroidManifest.xml
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.measite.contactmerger"
android:versionCode="4"
android:versionName="1.0.3">
android:versionCode="5"
android:versionName="1.1.0" >

<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Expand All @@ -15,30 +15,37 @@
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light"
android:largeHeap="true"
>
android:theme="@android:style/Theme.Holo.Light" >
<activity android:name="com.tundem.aboutlibraries.ui.LibsActivity" />
<activity
android:name="de.measite.contactmerger.MergeActivity"
android:name=".MergeActivity"
android:label="@string/title_activity_merge" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service
android:name="de.measite.contactmerger.AnalyzerService"
android:enabled="true"/>
<receiver android:name="de.measite.contactmerger.AnalyzeReceiver">
android:name=".AnalyzerService"
android:enabled="true" />

<receiver android:name=".AnalyzeReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>

<activity
android:name=".LogActivity"
android:label="@string/title_activity_log" >
</activity>
</application>

</manifest>
Binary file added art/ExplainMerge.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added art/ExplainMerge.xcf
Binary file not shown.
Binary file added res/drawable/explain_merge.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions res/layout/action_list_item.xml
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:paddingRight="5dip"
android:paddingTop="2dip"
android:paddingBottom="2dip"
>

<TextView
android:text="Action"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="20sp"
android:gravity="center_vertical|left"
android:ellipsize="end"
/>

<ImageView
android:layout_width="40dip"
android:layout_height="40dip"
android:adjustViewBounds="false"
android:src="@android:drawable/ic_menu_revert"
/>

</LinearLayout>
43 changes: 43 additions & 0 deletions res/layout/log.xml
@@ -0,0 +1,43 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- Top bar for progress -->
<ProgressBar
android:id="@+id/analyze_progress"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_height="3dip"
android:layout_margin="0dip"
android:padding="0dip"
android:layout_width="match_parent"
android:visibility="gone"
/>

<ViewSwitcher
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/no_actions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20sp"
android:textSize="20sp"
android:gravity="center"
android:lines="1"
android:text="No logged actions"
/>

<ListView
android:id="@+id/action_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@android:color/transparent"
android:dividerHeight="0dip"
android:background="#ffffff"
android:paddingBottom="2dip"
/>
</ViewSwitcher>
</LinearLayout>
49 changes: 37 additions & 12 deletions res/layout/merge.xml
Expand Up @@ -3,10 +3,9 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
>

<!-- Top bar for progress, invisible (but not gone) -->
<!-- Top bar for progress -->
<ProgressBar
android:id="@+id/analyze_progress"
style="@android:style/Widget.ProgressBar.Horizontal"
Expand All @@ -24,17 +23,42 @@
android:layout_height="match_parent"
>

<!-- Dummy text -->
<TextView
android:id="@+id/load_text"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20sp"
android:textSize="20sp"
android:gravity="center"
android:lines="3"
android:text="Analyzing your contacts.\nThis can take a few minutes.\n"
/>
android:layout_height="fill_parent"
android:orientation="vertical"
>
<!-- Dummy text -->
<TextView
android:id="@+id/load_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20sp"
android:textSize="20sp"
android:gravity="center"
android:lines="3"
android:layout_weight="0.2"
android:text="Analyzing your contacts.\nThis can take a few minutes.\n"
/>
<ImageView
android:layout_margin="20dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:layout_weight="1"
android:src="@drawable/explain_merge"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_weight="0.2"
android:gravity="center"
android:lines="2"
android:text="See the action log for undo."
/>
</LinearLayout>

<ViewSwitcher
android:id="@+id/switcher_list"
Expand All @@ -50,6 +74,7 @@
android:divider="@android:color/transparent"
android:dividerHeight="0dip"
android:background="#ffffff"
android:paddingBottom="2dip"
/>

<!-- Dummy text -->
Expand Down
11 changes: 9 additions & 2 deletions res/menu/merge.xml
Expand Up @@ -4,14 +4,21 @@
>

<item
android:id="@+id/analyze_now"
android:id="@+id/action_log"
android:orderInCategory="100"
android:icon="@android:drawable/ic_menu_agenda"
android:showAsAction="ifRoom|withText"
android:title="@string/action_log"/>

<item
android:id="@+id/analyze_now"
android:orderInCategory="200"
android:showAsAction="never"
android:title="@string/analyze_now"/>

<item
android:id="@+id/about"
android:orderInCategory="200"
android:orderInCategory="300"
android:showAsAction="never"
android:title="@string/about"/>

Expand Down
13 changes: 8 additions & 5 deletions res/values/strings.xml
Expand Up @@ -3,12 +3,15 @@

<string name="app_name">Contact Merger</string>
<string name="title_activity_merge">Contact Merger</string>

<string name="fa_check">&#xf00c;</string>
<string name="fa_times">&#xf00d;</string>
<string name="fa_ban">&#xf05e;</string>
<string name="fa_plus">&#xf067;</string>
<string name="fa_check"></string>
<string name="fa_times"></string>
<string name="fa_ban"></string>
<string name="fa_plus"></string>
<string name="analyze_now">Analyze</string>
<string name="about">About</string>
<string name="action_log">Action log</string>
<string name="title_activity_log">LogActivity</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>

</resources>
36 changes: 36 additions & 0 deletions src/de/measite/contactmerger/LogActivity.java
@@ -0,0 +1,36 @@
package de.measite.contactmerger;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import de.measite.contactmerger.R;

public class LogActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.log);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.log, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
4 changes: 2 additions & 2 deletions src/de/measite/contactmerger/contacts/ContactDataMapper.java
Expand Up @@ -284,7 +284,7 @@ public int[] getContactIDs() {
private final static String[] CONTACT_OF_RAW_CONTACT_PROJECTION =
new String[]{RawContacts.CONTACT_ID};

public int getContactByRawContactID(int id) {
public int getContactByRawContactID(long id) {
int result = 0;
try {
Cursor cursor = provider.query(
Expand All @@ -307,7 +307,7 @@ public int getContactByRawContactID(int id) {
return result;
}

public Contact getContactById(int id, boolean rawContacts, boolean metadata) {
public Contact getContactById(long id, boolean rawContacts, boolean metadata) {
Contact contact = null;

if (cache != null) {
Expand Down
50 changes: 29 additions & 21 deletions src/de/measite/contactmerger/log/Database.java
Expand Up @@ -7,6 +7,7 @@
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import android.provider.ContactsContract;
import android.util.Log;

/**
* Action log database, will allow undo operations.
Expand All @@ -18,25 +19,30 @@ public MyDatabaseHelper(Context context) {
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE actionlog(" +
"_id INTEGER PRIMARY KEY," +
"timestamp INTEGER," +
"description TEXT" +
"actiontype INTEGER" +
"undone INTEGER" +
")"
);
db.execSQL("CREATE TABLE actionchanges(" +
"_id INTEGER PRIMARY KEY," +
"actionLogId INTEGER," +
"rawContact1 INTEGER," +
"rawContact2 INTEGER," +
"oldValue INTEGER," +
"newValue INTEGER" +
")"
);
db.execSQL("CREATE INDEX actions_by_time ON actionlog ( timestamp DESC );");
db.execSQL("CREATE INDEX changes_by_action ON actionchanges ( actionLogId ASC );");
try {
db.execSQL("CREATE TABLE actionlog(" +
"_id INTEGER PRIMARY KEY," +
"timestamp INTEGER," +
"description TEXT," +
"actiontype INTEGER," +
"undone INTEGER" +
")"
);
db.execSQL("CREATE TABLE actionchanges(" +
"_id INTEGER PRIMARY KEY," +
"actionLogId INTEGER," +
"rawContact1 INTEGER," +
"rawContact2 INTEGER," +
"oldValue INTEGER," +
"newValue INTEGER" +
")"
);
db.execSQL("CREATE INDEX actions_by_time ON actionlog ( timestamp DESC );");
db.execSQL("CREATE INDEX changes_by_action ON actionchanges ( actionLogId ASC );");
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Expand All @@ -55,8 +61,8 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
private final static Uri URI = Uri.parse("content://" + Database.class.getCanonicalName() + "/actions");

public static class Change {
public int rawContactId1;
public int rawContactId2;
public long rawContactId1;
public long rawContactId2;
public int oldValue;
public int newValue;
}
Expand All @@ -68,6 +74,7 @@ public static synchronized long log(Context context, String description, Change

if (changes.length == 0) {
// we need an action in this case 0.o
Log.d("ActionDatabase", "log without actions: " + description);
return -1;
}

Expand All @@ -84,6 +91,7 @@ public static synchronized long log(Context context, String description, Change
values.put("timestamp", now);
values.put("actiontype", 1);
values.put("undone", false);
values.put("description", description);

long id = db.insert("actionlog", null, values);

Expand Down

0 comments on commit 4657c28

Please sign in to comment.