Skip to content

Commit

Permalink
Completed save, load, list functionality for xwiki Documents.
Browse files Browse the repository at this point in the history
Refactored Document Services and seperated conserns of remote services
and local services.
  • Loading branch information
sasinda committed Jul 7, 2012
1 parent f9d31c6 commit 45de346
Show file tree
Hide file tree
Showing 93 changed files with 4,901 additions and 2,841 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ atlassian-ide-plugin.xml
.fbprefs
bin
gen
.settings/*

# Automatically generated by WTP
/*/src/main/java/META-INF/
Expand Down
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
*
* See the NOTICE file distributed with this work for additional
Expand Down Expand Up @@ -47,8 +46,8 @@
<module>xwiki-rest-model</module>
<module>xwiki-android-rest</module>
<module>xwiki-android-core</module>
<module>xwiki-android-components</module>
<module>xwiki-android-client</module>
<module>xwiki-android-components</module>
<module>xwiki-android-client</module>
<module>xwiki-android-test-rest</module>
<module>xwiki-android-tests-instrumentation</module>
</modules>
Expand Down
1 change: 1 addition & 0 deletions xwiki-android-client/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<!-- blog -->
<activity android:name=".blog.BlogPrefernces" android:label="Blog App Preferences"/>
<activity android:name=".blog.EditPostActivity" android:label="Blog App Preferences"/>
<activity android:name=".blog.LoadSavedPostsActivity" android:label="Blog App Preferences"/>

<!-- activities from UI comp lib -->
<activity android:name="org.xwiki.android.components.login.LoginActivity"></activity>
Expand Down
34 changes: 34 additions & 0 deletions xwiki-android-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,40 @@
<type>apklib</type>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.j256.ormlite</groupId>
<artifactId>ormlite-core</artifactId>
<type>jar</type>
<version>4.40</version>
</dependency>
<dependency>
<groupId>com.j256.ormlite</groupId>
<artifactId>ormlite-android</artifactId>
<type>jar</type>
<version>4.40</version>
</dependency>
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<type>jar</type>
<version>2.6</version>
<exclusions>
<!-- StAX is not available on Android -->
<exclusion>
<artifactId>stax</artifactId>
<groupId>stax</groupId>
</exclusion>
<exclusion>
<artifactId>stax-api</artifactId>
<groupId>stax</groupId>
</exclusion>
<!-- Provided by Android -->
<exclusion>
<artifactId>xpp3</artifactId>
<groupId>xpp3</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

Expand Down
59 changes: 59 additions & 0 deletions xwiki-android-client/res/layout/blog_editor_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/et_blog_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" >

<requestFocus />
</EditText>

</TableRow>

<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Category"
android:textAppearance="?android:attr/textAppearanceMedium" />
<AutoCompleteTextView
android:id="@+id/actv_blog_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="AutoCompleteTextView" />

</TableRow>
<Button
android:id="@+id/btn_blog_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK" />

</TableLayout>
Expand Down
2 changes: 1 addition & 1 deletion xwiki-android-client/res/layout/blogeditor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:orientation="vertical" >

<EditText
android:id="@+id/editText1"
android:id="@+id/etBlogPost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.83"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data)
url = data.getExtras().getString(LoginActivity.INTENT_EXTRA_GET_URL);
Log.d("data", "username=" + username + " password=" + password + " url=" + url);
//start xwiki launch pad
Intent intent=new Intent(this.getApplicationContext(),IconLaunchPad.class);
Intent intent=new Intent(this,IconLaunchPad.class);
startActivityForResult(intent, REQUEST_CODE_LAUNCHPAD);
} else {
finish();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
package org.xwiki.android.client.blog;

import java.io.Serializable;
import java.util.List;

import org.xwiki.android.blog.svc.BlogDocument;
import org.xwiki.android.client.R;
import org.xwiki.android.components.login.LoginActivity;
import org.xwiki.android.context.XWikiApplicationContext;
import org.xwiki.android.context.XWikiApplicationContextAPI;
import org.xwiki.android.fileStore.FSDocumentReference;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class EditPostActivity extends Activity implements OnClickListener {

private static final int REQUEST_CODE_LOADSAVEDPOSTS=0;

private Button btnSave,btnLoad,btnPost,btnPublish;
private BlogDocument mydoc;
private BlogDocument.BlogDocumentRemoteCallbacks myRmtClbks;
private EditText etPost;
private String title;
private String category;

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

etPost=(EditText) findViewById(R.id.etBlogPost);
btnSave=(Button) findViewById(R.id.btnSave);
btnLoad=(Button) findViewById(R.id.btnLoad);
btnPost=(Button) findViewById(R.id.btnPost);
Expand All @@ -25,18 +50,98 @@ protected void onCreate(Bundle savedInstanceState) {
btnLoad.setOnClickListener(this);
btnPost.setOnClickListener(this);
btnPublish.setOnClickListener(this);

//show dialog to get page name, category

showDialog();
mydoc=new BlogDocument("xwiki", "Blog", title);


}


private void showDialog(){
final Dialog dialog = new Dialog(this);
dialog.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
dialog.setTitle("New Blog Post");
LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dialogView = li.inflate(R.layout.blog_editor_dialog, null);
dialog.setContentView(dialogView);
dialog.show();

Button okBtn = (Button) dialogView.findViewById(R.id.btn_blog_ok);
final EditText etTitle=(EditText) dialogView.findViewById(R.id.et_blog_title);
final AutoCompleteTextView actvCategory=(AutoCompleteTextView) dialogView.findViewById(R.id.actv_blog_category);

okBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
title=etTitle.getText().toString();
category=actvCategory.getText().toString();
if(title==null || category==null || title.equals("") || category.equals("")){
Toast.makeText(getBaseContext(), "Please fill data",
Toast.LENGTH_LONG).show();
}else{
dialog.dismiss();
}
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(resultCode==RESULT_OK){
if(requestCode==REQUEST_CODE_LOADSAVEDPOSTS){
etPost.setText(mydoc.getContent());
}
}

}

public void onClick(View v) {
if (v.getId()==R.id.btnSave) {


if (v.getId()==R.id.btnSave) {
mydoc.setContent(etPost.getText().toString());
mydoc.save();

}else if(v.getId()==R.id.btnLoad){

Intent i=new Intent(this,LoadSavedPostsActivity.class);
XWikiApplicationContextAPI ctx=(XWikiApplicationContextAPI) getApplication();
ctx.put("blgDoc", mydoc);
startActivityForResult(i,REQUEST_CODE_LOADSAVEDPOSTS);

}else if(v.getId()==R.id.btnPost){

final ProgressDialog myProgressDialog;
myProgressDialog =ProgressDialog.show(this, "Posting", "Please wait...", true);
myRmtClbks=mydoc.new BlogDocumentRemoteCallbacks() {
@Override
public void onBlogPostSent(boolean success) {
myProgressDialog.dismiss();
finish();
}
};
mydoc.setContent(etPost.getText().toString());
mydoc.post(myRmtClbks);

}else if(v.getId()==R.id.btnPublish){

final ProgressDialog myProgressDialog;
myProgressDialog =ProgressDialog.show(this, "Publishing", "Please wait...", true);
myRmtClbks=mydoc.new BlogDocumentRemoteCallbacks(){
@Override
public void onBlogPostSent(boolean success) {
myProgressDialog.dismiss();
finish();
}
};
mydoc.setContent(etPost.getText().toString());
mydoc.publish(myRmtClbks);
}

}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.xwiki.android.client.blog;

import java.util.List;

import org.xwiki.android.blog.svc.BlogDocument;
import org.xwiki.android.blog.svc.BlogDocument.BlogDocumentLocalCallbacks;
import org.xwiki.android.context.XWikiApplicationContext;
import org.xwiki.android.context.XWikiApplicationContextAPI;
import org.xwiki.android.fileStore.FSDocumentReference;
import org.xwiki.android.xmodel.svc.DocumentSvc;
import org.xwiki.android.xmodel.svc.DocumentSvcImpl;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class LoadSavedPostsActivity extends ListActivity
{
private LoadSavedPostsActivity activityCtx;

private BlogDocumentLocalCallbacks clbk;

private BlogDocument doc;

private List<FSDocumentReference> refList;

private ProgressDialog myProgressDialog;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
DocumentSvc svc = new DocumentSvcImpl();
activityCtx = this;
XWikiApplicationContextAPI ctx=(XWikiApplicationContext)getApplicationContext();
doc = (BlogDocument) ctx.pop("blgDoc");
init();
doc.listBlogDocuments(clbk);

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
FSDocumentReference fsref = refList.get(position);
myProgressDialog = ProgressDialog.show(this, "loading", "Please wait...", true);
doc.load(fsref, clbk);
}

private void init()
{
clbk = doc.new BlogDocumentLocalCallbacks()
{

@Override
public void onListingComplete(List<FSDocumentReference> rslts)
{
refList = rslts;
String[] list = new String[rslts.size()];
int i = 0;
for (FSDocumentReference rslt : rslts) {
list[i++] = rslt.getPageName();
}

ArrayAdapter<String> adapter =
new ArrayAdapter<String>(activityCtx, android.R.layout.simple_list_item_1, list);
setListAdapter(adapter);
}

@Override
public void onBlogPostLoaded()
{
myProgressDialog.dismiss();
setResult(RESULT_OK);
finish();
}
};

}
}
Loading

0 comments on commit 45de346

Please sign in to comment.