Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/com/kii/world/HelloKii.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package com.kii.world;

import android.app.Application;

import com.kii.cloud.storage.Kii;
import com.kii.cloud.storage.Kii.Site;

Expand Down
17 changes: 10 additions & 7 deletions src/com/kii/world/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import com.kii.cloud.storage.KiiUser;
import com.kii.cloud.storage.callback.KiiUserCallBack;
import com.kii.cloud.storage.exception.app.AppException;

public class LoginActivity extends Activity {

Expand Down Expand Up @@ -66,7 +65,7 @@ public void onLoginCompleted(int token, KiiUser user, Exception e) {

// tell the console and the user it was a success!
Log.v(TAG, "Logged in: " + user.toString());
Toast.makeText(LoginActivity.this, "User authenticated!", Toast.LENGTH_SHORT).show();
showToast("User authenticated!");

// go to the main screen
Intent myIntent = new Intent(LoginActivity.this, MainActivity.class);
Expand All @@ -78,8 +77,8 @@ public void onLoginCompleted(int token, KiiUser user, Exception e) {
else {

// tell the console and the user there was a failure
Log.v(TAG, "Error registering: " + e.getLocalizedMessage());
Toast.makeText(LoginActivity.this, "Error registering: " + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
Log.v(TAG, "Error authenticating: " + e.getLocalizedMessage());
showToast("Error authenticating: " + e.getLocalizedMessage());
}

}
Expand Down Expand Up @@ -115,7 +114,7 @@ public void onRegisterCompleted(int token, KiiUser user, Exception e) {

// tell the console and the user it was a success!
Log.v(TAG, "Registered: " + user.toString());
Toast.makeText(LoginActivity.this, "User registered!", Toast.LENGTH_SHORT).show();
showToast("User registered!");

// go to the next screen
Intent myIntent = new Intent(LoginActivity.this, MainActivity.class);
Expand All @@ -128,7 +127,7 @@ public void onRegisterCompleted(int token, KiiUser user, Exception e) {

// tell the console and the user there was a failure
Log.v(TAG, "Error registering: " + e.getLocalizedMessage());
Toast.makeText(LoginActivity.this, "Error Registering: " + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
showToast("Error registering: " + e.getLocalizedMessage());
}

}
Expand All @@ -137,7 +136,7 @@ public void onRegisterCompleted(int token, KiiUser user, Exception e) {

} catch(Exception e) {
mProgress.cancel();
Toast.makeText(this, "Error signing up: " + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
showToast("Error signing up: " + e.getLocalizedMessage());
}

}
Expand All @@ -155,4 +154,8 @@ public void onCreate(Bundle savedInstanceState) {

}

private void showToast(String message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}

}
29 changes: 18 additions & 11 deletions src/com/kii/world/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
Expand All @@ -49,7 +51,7 @@
import com.kii.cloud.storage.query.KiiQuery;
import com.kii.cloud.storage.query.KiiQueryResult;

public class MainActivity extends Activity {
public class MainActivity extends Activity implements OnItemClickListener {

private static final String TAG = "MainActivity";

Expand Down Expand Up @@ -170,8 +172,8 @@ public void onSaveCompleted(int token, KiiObject o, Exception e) {
if(e == null) {

// tell the console and the user it was a success!
Toast.makeText(MainActivity.this, "Created object", Toast.LENGTH_SHORT).show();
Log.d(TAG, "Created object: " + o.toString());
showToast("Created object");

// insert this object into the beginning of the list adapter
MainActivity.this.mListAdapter.insert(o, 0);
Expand All @@ -182,8 +184,8 @@ public void onSaveCompleted(int token, KiiObject o, Exception e) {
else {

// tell the console and the user there was a failure
Toast.makeText(MainActivity.this, "Error creating object", Toast.LENGTH_SHORT).show();
Log.d(TAG, "Error creating object: " + e.getLocalizedMessage());
showToast("Error creating object" + e.getLocalizedMessage());
}

}
Expand All @@ -203,7 +205,7 @@ private void loadObjects() {

// create an empty KiiQuery (will retrieve all results, sorted by creation date)
KiiQuery query = new KiiQuery(null);
query.sortByAsc("_created");
query.sortByDesc("_created");

// define the bucket to query
KiiBucket bucket = KiiUser.getCurrentUser().bucket(BUCKET_NAME);
Expand All @@ -228,7 +230,7 @@ public void onQueryCompleted(int token, KiiQueryResult<KiiObject> result, Except

// tell the console and the user it was a success!
Log.v(TAG, "Objects loaded: " + result.getResult().toString());
Toast.makeText(MainActivity.this, "Objects loaded", Toast.LENGTH_SHORT).show();
showToast("Objects loaded");

}

Expand All @@ -237,7 +239,7 @@ public void onQueryCompleted(int token, KiiQueryResult<KiiObject> result, Except

// tell the console and the user there was a failure
Log.v(TAG, "Error loading objects: " + e.getLocalizedMessage());
Toast.makeText(MainActivity.this, "Error loading objects: " + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
showToast("Error loading objects: " + e.getLocalizedMessage());
}
}
}, query);
Expand Down Expand Up @@ -268,8 +270,8 @@ public void onDeleteCompleted(int token, Exception e) {
if(e == null) {

// tell the console and the user it was a success!
Toast.makeText(MainActivity.this, "Deleted object", Toast.LENGTH_SHORT).show();
Log.d(TAG, "Deleted object: " + o.toString());
showToast("Deleted object");

// remove the object from the list adapter
MainActivity.this.mListAdapter.remove(o);
Expand All @@ -280,8 +282,8 @@ public void onDeleteCompleted(int token, Exception e) {
else {

// tell the console and the user there was a failure
Toast.makeText(MainActivity.this, "Error deleting object", Toast.LENGTH_SHORT).show();
Log.d(TAG, "Error deleting object: " + e.getLocalizedMessage());
showToast("Error deleting object: " + e.getLocalizedMessage());
}

}
Expand All @@ -292,8 +294,8 @@ public void onDeleteCompleted(int token, Exception e) {
// the user has clicked an item on the list.
// we use this action to possibly delete the tapped object.
// to confirm, we prompt the user with a dialog:
public void onListItemClick(ListView l, View v, final int position, long id) {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, final int arg2, long arg3) {
// build the alert
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Would you like to remove this item?")
Expand All @@ -304,7 +306,7 @@ public void onListItemClick(ListView l, View v, final int position, long id) {
public void onClick(DialogInterface dialog, int id) {

// perform the delete action on the tapped object
MainActivity.this.performDelete(position);
MainActivity.this.performDelete(arg2);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
Expand Down Expand Up @@ -335,6 +337,7 @@ public void onCreate(Bundle savedInstanceState) {
mListAdapter = new ObjectAdapter(this, R.layout.row, new ArrayList<KiiObject>());

mListView = (ListView) this.findViewById(R.id.list);
mListView.setOnItemClickListener(this);

// set it to our view's list
mListView.setAdapter(mListAdapter);
Expand All @@ -344,4 +347,8 @@ public void onCreate(Bundle savedInstanceState) {

}

private void showToast(String message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}

}