diff --git a/.gitignore b/.gitignore index 6435c40ddb..a62020a161 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea # From https://github.com/github/gitignore/blob/master/Android.gitignore 2014-01-14 # built application files diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000000..96cc43efa6 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/Team_X.xml b/.idea/copyright/Team_X.xml new file mode 100644 index 0000000000..c7dc2d0229 --- /dev/null +++ b/.idea/copyright/Team_X.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000000..0c2081026a --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000000..7ac24c777f --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000..3d21c78839 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..c15affbaa2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000000..7f68460d8b --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..35eb1ddfbb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000000..31ca61ecd7 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,3106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1484876478349 + + + 1487294966958 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Team X + + + + + + + + \ No newline at end of file diff --git a/allclasses-frame.html b/allclasses-frame.html new file mode 100644 index 0000000000..f82060f18a --- /dev/null +++ b/allclasses-frame.html @@ -0,0 +1,36 @@ + + + + + +All Classes + + + + + +

All Classes

+
+ +
+ + diff --git a/allclasses-noframe.html b/allclasses-noframe.html new file mode 100644 index 0000000000..cbf92dce5c --- /dev/null +++ b/allclasses-noframe.html @@ -0,0 +1,36 @@ + + + + + +All Classes + + + + + +

All Classes

+
+ +
+ + diff --git a/app/app.iml b/app/app.iml deleted file mode 100644 index db23a3c322..0000000000 --- a/app/app.iml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 1cc9ef1961..854ffcff8a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,4 @@ apply plugin: 'com.android.application' - android { compileSdkVersion 18 buildToolsVersion "22.0.1" @@ -21,3 +20,9 @@ android { } } } + +dependencies { + compile 'com.jayway.android.robotium:robotium-solo:5.6.3' + compile 'com.android.support:appcompat-v7:18.0.0' + compile files('src/include/jest-droid-2.0.1-SNAPSHOT.jar') +} \ No newline at end of file diff --git a/app/src/androidTest/java/ca/ualberta/cs/lonelytwitter/LonelyTwitterActivityTest.java b/app/src/androidTest/java/ca/ualberta/cs/lonelytwitter/LonelyTwitterActivityTest.java index 495680650f..d1ecdf26f7 100644 --- a/app/src/androidTest/java/ca/ualberta/cs/lonelytwitter/LonelyTwitterActivityTest.java +++ b/app/src/androidTest/java/ca/ualberta/cs/lonelytwitter/LonelyTwitterActivityTest.java @@ -2,20 +2,83 @@ import android.app.Activity; import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; +import android.widget.EditText; +import android.widget.ListView; + +import com.robotium.solo.Solo; import junit.framework.TestCase; /** * Created by wz on 14/09/15. */ -public class LonelyTwitterActivityTest extends ActivityInstrumentationTestCase2 { +public class LonelyTwitterActivityTest extends ActivityInstrumentationTestCase2 { + + private Solo solo; public LonelyTwitterActivityTest() { super(ca.ualberta.cs.lonelytwitter.LonelyTwitterActivity.class); } + public void setUp() throws Exception{ + solo = new Solo(getInstrumentation(), getActivity()); + + } + + public void testStart() throws Exception { Activity activity = getActivity(); + } + + public void testTweet(){ + solo.assertCurrentActivity("Wrong Activity!", LonelyTwitterActivity.class); + + solo.clickOnButton("Clear"); + solo.enterText((EditText) solo.getView(R.id.body), "Test Tweet!"); + + solo.clickOnButton("Save"); + + solo.clearEditText((EditText) solo.getView(R.id.body)); + assertTrue(solo.waitForText("Test Tweet!")); + + solo.clickOnButton("Clear"); + + assertFalse(solo.searchText("Test Tweet!")); } + + public void testClickTweetList(){ + LonelyTwitterActivity activity = (LonelyTwitterActivity)solo.getCurrentActivity(); + + solo.assertCurrentActivity("Wrong Activity!", LonelyTwitterActivity.class); + + solo.clickOnButton("Clear"); + solo.enterText((EditText) solo.getView(R.id.body), "Test Tweet!"); + + solo.clickOnButton("Save"); + + assertTrue(solo.waitForText("Test Tweet!")); + + final ListView oldTweetsList = activity.getOldTweetsList(); + Tweet tweet = (Tweet) oldTweetsList.getItemAtPosition(0); + assertEquals("Test Tweet!", tweet.getMessage()); + + solo.clickInList(0); + + solo.assertCurrentActivity("Wrong Activity", EditTweetActivity.class); + assertTrue(solo.waitForText("Test Tweet!")); + + solo.goBack(); + solo.assertCurrentActivity("Wrong Activity", LonelyTwitterActivity.class); + + } + + + @Override + public void tearDown() throws Exception { + solo.finishOpenedActivities(); + } + + } \ No newline at end of file diff --git a/app/src/androidTest/java/ca/ualberta/cs/lonelytwitter/TweetListTest.java b/app/src/androidTest/java/ca/ualberta/cs/lonelytwitter/TweetListTest.java new file mode 100644 index 0000000000..d1a7432b31 --- /dev/null +++ b/app/src/androidTest/java/ca/ualberta/cs/lonelytwitter/TweetListTest.java @@ -0,0 +1,77 @@ +package ca.ualberta.cs.lonelytwitter; + +import android.test.ActivityInstrumentationTestCase2; + +/** + * Created by cdkushni on 2/16/17. + */ + +public class TweetListTest extends ActivityInstrumentationTestCase2 { + public TweetListTest() { + super(LonelyTwitterActivity.class); + } + + + public void testAddTweet() { + TweetList tweets = new TweetList(); + NormalTweet tweet = new NormalTweet("some tweet"); + if (tweets.hasTweet(tweet)) { + throw new IllegalArgumentException(); + } + tweets.add(tweet); + assertTrue(tweets.hasTweet(tweet)); + } + + public void testHasTweet() { + TweetList tweets = new TweetList(); + NormalTweet tweet = new NormalTweet("some tweet"); + //assertFalse(tweets.hasTweet(tweet)); + tweets.add(tweet); + assertTrue(tweets.hasTweet(tweet)); + } + + public void testGetTweets() { + TweetList tweets = new TweetList(); + NormalTweet tweet = new NormalTweet("some tweet"); + NormalTweet tweet2 = new NormalTweet("some tweet next"); + + tweets.add(tweet); + tweets.add(tweet2); + TweetList returnedTweets = tweets.getTweets(); + assertEquals(returnedTweets.getTweet(0), tweets.getTweet(0)); + assertEquals(returnedTweets.getTweet(0).getDate(), tweets.getTweet(0).getDate()); + assertEquals(returnedTweets.getTweet(1).getDate(), tweets.getTweet(1).getDate()); + } + + public void testGetCount() { + TweetList tweets = new TweetList(); + NormalTweet tweet = new NormalTweet("some tweet"); + NormalTweet tweet2 = new NormalTweet("some tweet next"); + + tweets.add(tweet); + tweets.add(tweet2); + int returnedCount = tweets.getCount(); + assertEquals(returnedCount, 2); + } + + public void testGetTweet() { + TweetList tweets = new TweetList(); + NormalTweet tweet = new NormalTweet("some tweet"); + + tweets.add(tweet); + NormalTweet returnedTweet = tweets.getTweet(0); + assertEquals(returnedTweet.getMessage(), tweet.getMessage()); + assertEquals(returnedTweet.getDate(), tweet.getDate()); + } + + public void testDeleteTweet() { + TweetList tweets = new TweetList(); + NormalTweet tweet = new NormalTweet("some tweet"); + + tweets.add(tweet); + tweets.delete(tweet); + assertFalse(tweets.hasTweet(tweet)); + } + + +} diff --git a/app/src/include/jest-droid-2.0.1-SNAPSHOT.jar b/app/src/include/jest-droid-2.0.1-SNAPSHOT.jar new file mode 100644 index 0000000000..6bd0dc8f9e Binary files /dev/null and b/app/src/include/jest-droid-2.0.1-SNAPSHOT.jar differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 271f52eb7b..4cf9da016f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,22 +2,28 @@ + android:versionName="1.0"> + + + + + + android:label="@string/app_name"> + android:label="@string/app_name"> + \ No newline at end of file diff --git a/app/src/main/java/ca/ualberta/cs/lonelytwitter/AngryMood.java b/app/src/main/java/ca/ualberta/cs/lonelytwitter/AngryMood.java new file mode 100644 index 0000000000..d08457c4ce --- /dev/null +++ b/app/src/main/java/ca/ualberta/cs/lonelytwitter/AngryMood.java @@ -0,0 +1,42 @@ +package ca.ualberta.cs.lonelytwitter; + +import java.util.Date; + +/** + * This is a child of currentmood that is an angry mood + * It has a private string representing it's mood set to "Angry" + * It inherits from CurrentMood and will use getMoodString() to return "Angry" + * + * @author Colin Kushniruk + * @version 1.0.1 + * @since 1.0 + */ +public class AngryMood extends CurrentMood{ + private String moodString = "Angry"; + + /** + * Instantiates a new Angry mood. + */ + public AngryMood(){ + super(); + } + + /** + * Instantiates a new Angry mood. + * + * @param date the date + */ + public AngryMood(Date date){ + super(date); + } + + /** + * the inherited abstract getMoodString is used to + * return the "Angry" mood string here. + * @return moodString + */ + public String getMoodString(){ + return moodString; + } + +} diff --git a/app/src/main/java/ca/ualberta/cs/lonelytwitter/CurrentMood.java b/app/src/main/java/ca/ualberta/cs/lonelytwitter/CurrentMood.java new file mode 100644 index 0000000000..a59d662494 --- /dev/null +++ b/app/src/main/java/ca/ualberta/cs/lonelytwitter/CurrentMood.java @@ -0,0 +1,59 @@ +package ca.ualberta.cs.lonelytwitter; + +import java.util.Date; + +/** + * Current Mood is a default mood class to represent a mood + * that can be used for a tweet message. + * It has a date associated along with getters and setters for such. + * It also has a abstract getMoodString to use for it's children. + * + * @author Colin Kushniruk + * @version 1.0.1 + * @since 1.0 + */ +public abstract class CurrentMood { + private Date date; + + /** + * Instantiates a new Current mood. + */ + public CurrentMood(){ + this.date = new Date(); + } + + /** + * Instantiates a new Current mood. + * + * @param date the date + */ + public CurrentMood(Date date){ + this.date = date; + } + + /** + * Gets date. + * + * @return the date + */ + public Date getDate() { + return date; + } + + /** + * Sets date. + * + * @param date the date + */ + public void setDate(Date date) { + this.date = date; + } + + /** + * Gets mood string. + * + * @return the mood string + */ + public abstract String getMoodString(); + +} diff --git a/app/src/main/java/ca/ualberta/cs/lonelytwitter/EditTweetActivity.java b/app/src/main/java/ca/ualberta/cs/lonelytwitter/EditTweetActivity.java new file mode 100644 index 0000000000..356943ba23 --- /dev/null +++ b/app/src/main/java/ca/ualberta/cs/lonelytwitter/EditTweetActivity.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2017. Team X. CMPUT301. University of Alberta. All Rights Reserved. + * You may use, distribute or modify this code under terms and conditions of the Code of Student Behaviour at the University of Alberta. + * You can find a copy of the license in the project. Otherwise please contact contact@uab.ca + */ + +package ca.ualberta.cs.lonelytwitter; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.EditText; +import android.widget.ListView; +import android.widget.TextView; + +import com.robotium.solo.Solo; + +public class EditTweetActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_edit_tweet); + + Intent in = getIntent(); + Bundle bun = in.getExtras(); + TextView Textv = (TextView) findViewById(R.id.textView); + + if(bun!=null){ + String j =(String) bun.get("Index"); + Textv.setText(j); + } + + + } +} diff --git a/app/src/main/java/ca/ualberta/cs/lonelytwitter/ElasticsearchTweetController.java b/app/src/main/java/ca/ualberta/cs/lonelytwitter/ElasticsearchTweetController.java new file mode 100644 index 0000000000..6ba686bf01 --- /dev/null +++ b/app/src/main/java/ca/ualberta/cs/lonelytwitter/ElasticsearchTweetController.java @@ -0,0 +1,107 @@ +package ca.ualberta.cs.lonelytwitter; + +import android.os.AsyncTask; +import android.util.Log; + +import com.searchly.jestdroid.DroidClientConfig; +import com.searchly.jestdroid.JestClientFactory; +import com.searchly.jestdroid.JestDroidClient; + +import java.util.ArrayList; +import java.util.List; + +import io.searchbox.core.DocumentResult; +import io.searchbox.core.Index; +import io.searchbox.core.Search; +import io.searchbox.core.SearchResult; + +/** + * Created by romansky on 10/20/16. + */ +public class ElasticsearchTweetController { + private static JestDroidClient client; + + // TODO we need a function which adds tweets to elastic search + public static class AddTweetsTask extends AsyncTask { + + @Override + protected Void doInBackground(NormalTweet... tweets) { + verifySettings(); + + for (NormalTweet tweet : tweets) { + Index index = new Index.Builder(tweet).index("testing").type("tweet").build(); + + try { + // where is the client? + DocumentResult result = client.execute(index); + if (result.isSucceeded()){ + tweet.setId(result.getId()); + } + else { + Log.i("Error", "Elasticsearch was not able to add the tweet"); + } + } + catch (Exception e) { + Log.i("Error", "The application failed to build and send the tweets"); + } + + } + return null; + } + } + + // TODO we need a function which gets tweets from elastic search + public static class GetTweetsTask extends AsyncTask> { + @Override + protected ArrayList doInBackground(String... search_parameters) { + verifySettings(); + + ArrayList tweets = new ArrayList(); + + String query = "{\n \"query\" : {\n \"term\" : { \"message\" : \"" + search_parameters[0] +"\" }\n }\n}"; + + // TODO Build the query + if (search_parameters[0] == ""){ + query = ""; + } + System.out.print(query); + Search search = new Search.Builder(query) + .addIndex("testing") + .addType("tweet") + .build(); + + try { + // TODO get the results of the query + SearchResult result = client.execute(search); + if (result.isSucceeded()){ + List foundTweets = result.getSourceAsObjectList(NormalTweet.class); + tweets.addAll(foundTweets); + } + else { + Log.i("Error", "The search query failed to find any tweets that matched"); + } + + + } + catch (Exception e) { + Log.i("Error", "Something went wrong when we tried to communicate with the elasticsearch server!"); + } + + return tweets; + } + } + + + + + public static void verifySettings() { + if (client == null) { + DroidClientConfig.Builder builder = new DroidClientConfig.Builder("http://cmput301.softwareprocess.es:8080"); + DroidClientConfig config = builder.build(); + + JestClientFactory factory = new JestClientFactory(); + factory.setDroidClientConfig(config); + client = (JestDroidClient) factory.getObject(); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/ca/ualberta/cs/lonelytwitter/ImportantTweet.java b/app/src/main/java/ca/ualberta/cs/lonelytwitter/ImportantTweet.java new file mode 100644 index 0000000000..b80c375e50 --- /dev/null +++ b/app/src/main/java/ca/ualberta/cs/lonelytwitter/ImportantTweet.java @@ -0,0 +1,15 @@ +package ca.ualberta.cs.lonelytwitter; + +public class ImportantTweet extends Tweet{ + + public ImportantTweet(String message){ + super(message); + } + + @Override + public Boolean isImportant(){ + return Boolean.TRUE; + } + + +} diff --git a/app/src/main/java/ca/ualberta/cs/lonelytwitter/LonelyTwitterActivity.java b/app/src/main/java/ca/ualberta/cs/lonelytwitter/LonelyTwitterActivity.java index cd5feb6966..fce36f2a31 100644 --- a/app/src/main/java/ca/ualberta/cs/lonelytwitter/LonelyTwitterActivity.java +++ b/app/src/main/java/ca/ualberta/cs/lonelytwitter/LonelyTwitterActivity.java @@ -6,25 +6,41 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Date; import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.View; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + public class LonelyTwitterActivity extends Activity { + private LonelyTwitterActivity activity = this; + private static final String FILENAME = "file.sav"; private EditText bodyText; private ListView oldTweetsList; - - /** Called when the activity is first created. */ + private ArrayList tweetList = new ArrayList(); + private ArrayAdapter adapter; + + public ListView getOldTweetsList(){ + return oldTweetsList; + } + + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -32,6 +48,7 @@ public void onCreate(Bundle savedInstanceState) { bodyText = (EditText) findViewById(R.id.body); Button saveButton = (Button) findViewById(R.id.save); + Button clearButton = (Button) findViewById(R.id.clear); oldTweetsList = (ListView) findViewById(R.id.oldTweetsList); saveButton.setOnClickListener(new View.OnClickListener() { @@ -39,57 +56,107 @@ public void onCreate(Bundle savedInstanceState) { public void onClick(View v) { setResult(RESULT_OK); String text = bodyText.getText().toString(); - saveInFile(text, new Date(System.currentTimeMillis())); - finish(); + NormalTweet newTweet = new NormalTweet(text); + tweetList.add(newTweet); + adapter.notifyDataSetChanged(); + //saveInFile(); // TODO replace this with elastic search + ElasticsearchTweetController.AddTweetsTask addTweetsTask = new ElasticsearchTweetController.AddTweetsTask(); + addTweetsTask.execute(newTweet); + } + }); + + clearButton.setOnClickListener(new View.OnClickListener() { + + public void onClick(View v) { + setResult(RESULT_OK); + tweetList.clear(); + deleteFile("file.sav"); + adapter.notifyDataSetChanged(); + + /* + ElasticsearchTweetController.GetTweetsTask getTweetsTask = new ElasticsearchTweetController.GetTweetsTask(); + String text = bodyText.getText().toString(); + getTweetsTask.execute(text); + try { + tweetList = getTweetsTask.get(); + } catch (Exception e) { + Log.i("Error", "Failed to find search term in the async object"); + } + adapter.clear(); + adapter.addAll(tweetList); + adapter.notifyDataSetChanged();*/ } }); + + oldTweetsList.setOnItemClickListener(new AdapterView.OnItemClickListener() { + public void onItemClick(AdapterView adapterView, View view, int i, long l) { + Intent intent = new Intent(activity, EditTweetActivity.class); + + final ListView oldTweetsList = activity.getOldTweetsList(); + Tweet tweet = (Tweet) oldTweetsList.getItemAtPosition(i); + String s = tweet.getMessage(); + intent.putExtra("Index", s); + startActivity(intent); + } + }); + + } @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); - String[] tweets = loadFromFile(); - ArrayAdapter adapter = new ArrayAdapter(this, - R.layout.list_item, tweets); + //loadFromFile(); // TODO replace this with elastic search + + ElasticsearchTweetController.GetTweetsTask getTweetsTask = new ElasticsearchTweetController.GetTweetsTask(); + getTweetsTask.execute(""); + + try { + tweetList = getTweetsTask.get(); + } catch (Exception e) { + Log.i("Error", "Failed to get the tweets out of the async object"); + } + + adapter = new ArrayAdapter(this, + R.layout.list_item, tweetList); oldTweetsList.setAdapter(adapter); } - private String[] loadFromFile() { - ArrayList tweets = new ArrayList(); + + private void loadFromFile() { try { FileInputStream fis = openFileInput(FILENAME); BufferedReader in = new BufferedReader(new InputStreamReader(fis)); - String line = in.readLine(); - while (line != null) { - tweets.add(line); - line = in.readLine(); - } - + Gson gson = new Gson(); + //Code taken from http://stackoverflow.com/questions/12384064/gson-convert-from-json-to-a-typed-arraylistt Sept.22,2016 + Type listType = new TypeToken>(){}.getType(); + tweetList = gson.fromJson(in, listType); } catch (FileNotFoundException e) { // TODO Auto-generated catch block - e.printStackTrace(); + tweetList = new ArrayList(); } catch (IOException e) { // TODO Auto-generated catch block - e.printStackTrace(); + throw new RuntimeException(); } - return tweets.toArray(new String[tweets.size()]); } - - private void saveInFile(String text, Date date) { + + + private void saveInFile() { try { - FileOutputStream fos = openFileOutput(FILENAME, - Context.MODE_APPEND); - fos.write(new String(date.toString() + " | " + text) - .getBytes()); - fos.close(); + + FileOutputStream fos = openFileOutput(FILENAME,0); + OutputStreamWriter writer = new OutputStreamWriter(fos); + Gson gson = new Gson(); + gson.toJson(tweetList, writer); + writer.flush(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block - e.printStackTrace(); + throw new RuntimeException(); } catch (IOException e) { // TODO Auto-generated catch block - e.printStackTrace(); + throw new RuntimeException(); } } } \ No newline at end of file diff --git a/app/src/main/java/ca/ualberta/cs/lonelytwitter/NormalTweet.java b/app/src/main/java/ca/ualberta/cs/lonelytwitter/NormalTweet.java new file mode 100644 index 0000000000..bed2a0c93f --- /dev/null +++ b/app/src/main/java/ca/ualberta/cs/lonelytwitter/NormalTweet.java @@ -0,0 +1,13 @@ +package ca.ualberta.cs.lonelytwitter; + +public class NormalTweet extends Tweet { + + public NormalTweet(String message) { + super(message); + } + + @Override + public Boolean isImportant() { + return Boolean.FALSE; + } +} diff --git a/app/src/main/java/ca/ualberta/cs/lonelytwitter/PensiveMood.java b/app/src/main/java/ca/ualberta/cs/lonelytwitter/PensiveMood.java new file mode 100644 index 0000000000..18f4736810 --- /dev/null +++ b/app/src/main/java/ca/ualberta/cs/lonelytwitter/PensiveMood.java @@ -0,0 +1,43 @@ +package ca.ualberta.cs.lonelytwitter; + +import java.util.Date; + +/** + * This is a child of currentmood that is an pensive mood + * It has a private string representing it's mood set to "Pensive" + * It inherits from CurrentMood and will use getMoodString() to return "Pensive" + * + * @author Colin Kushniruk + * @version 1.0.1 + * @since 1.0 + */ +public class PensiveMood extends CurrentMood{ + private String moodString = "Pensive"; + + /** + * Instantiates a new Pensive mood. + */ + public PensiveMood(){ + super(); + } + + /** + * Instantiates a new Pensive mood. + * + * @param date the date + */ + public PensiveMood(Date date){ + super(date); + } + + /** + * the inherited abstract getMoodString is used to + * return the "Pensive" mood string here. + * @return + */ + public String getMoodString(){ + return moodString; + } + + +} diff --git a/app/src/main/java/ca/ualberta/cs/lonelytwitter/TestClass.java b/app/src/main/java/ca/ualberta/cs/lonelytwitter/TestClass.java new file mode 100644 index 0000000000..0296db674a --- /dev/null +++ b/app/src/main/java/ca/ualberta/cs/lonelytwitter/TestClass.java @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2017. Team X. CMPUT301. University of Alberta. All Rights Reserved. + * You may use, distribute or modify this code under terms and conditions of the Code of Student Behaviour at the University of Alberta. + * You can find a copy of the license in the project. Otherwise please contact contact@uab.ca + */ + +package ca.ualberta.cs.lonelytwitter; + +/** + * Created by cdkushni on 2/2/17. + */ +public class TestClass { +} diff --git a/app/src/main/java/ca/ualberta/cs/lonelytwitter/Tweet.java b/app/src/main/java/ca/ualberta/cs/lonelytwitter/Tweet.java new file mode 100644 index 0000000000..78ec80fced --- /dev/null +++ b/app/src/main/java/ca/ualberta/cs/lonelytwitter/Tweet.java @@ -0,0 +1,59 @@ +package ca.ualberta.cs.lonelytwitter; + +import java.util.Date; + +import io.searchbox.annotations.JestId; + +public abstract class Tweet implements Tweetable { + private String message; + private Date date; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @JestId + private String id; + + public Tweet(String message){ + this.message = message; + this.date = new Date(); + } + + public Tweet(String message, Date date){ + this.message = message; + this.date = date; + } + + @Override + public String toString(){ + return message; + } + + public abstract Boolean isImportant(); + + + public void setMessage(String message) throws TweetTooLongException { + if (message.length() > 140){ + //Do Something! + throw new TweetTooLongException(); + } + this.message = message; + } + + public void setDate(Date date) { + this.date = date; + } + + public String getMessage() { + return message; + } + + public Date getDate() { + return date; + } +} diff --git a/app/src/main/java/ca/ualberta/cs/lonelytwitter/TweetList.java b/app/src/main/java/ca/ualberta/cs/lonelytwitter/TweetList.java new file mode 100644 index 0000000000..e771d35dba --- /dev/null +++ b/app/src/main/java/ca/ualberta/cs/lonelytwitter/TweetList.java @@ -0,0 +1,48 @@ +package ca.ualberta.cs.lonelytwitter; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + +/** + * Created by cdkushni on 2/16/17. + */ + +public class TweetList { + private ArrayList tweets = new ArrayList(); + + public void add(NormalTweet tweet) { + tweets.add(tweet); + } + + public boolean hasTweet(NormalTweet tweet) { + return tweets.contains(tweet); + } + + public NormalTweet getTweet(int index) { + //return new NormalTweet("not the tweet"); + return tweets.get(index); + } + + public void delete(NormalTweet tweet) { + tweets.remove(tweet); + } + public TweetList getTweets() { + TweetList returnList = new TweetList(); + ArrayList tweetsTemp = tweets; + Collections.sort(tweetsTemp, new Comparator() { + public int compare(NormalTweet t1, NormalTweet t2) { + return t1.getDate().compareTo(t2.getDate()); + } + }); + + for (int i = 0; i < tweetsTemp.size(); i++) { + returnList.add(tweetsTemp.get(i)); + } + return returnList; + } + + public int getCount() { + return tweets.size(); + } +} diff --git a/app/src/main/java/ca/ualberta/cs/lonelytwitter/TweetTooLongException.java b/app/src/main/java/ca/ualberta/cs/lonelytwitter/TweetTooLongException.java new file mode 100644 index 0000000000..0c8da86488 --- /dev/null +++ b/app/src/main/java/ca/ualberta/cs/lonelytwitter/TweetTooLongException.java @@ -0,0 +1,5 @@ +package ca.ualberta.cs.lonelytwitter; + +public class TweetTooLongException extends Exception{ + +} diff --git a/app/src/main/java/ca/ualberta/cs/lonelytwitter/Tweetable.java b/app/src/main/java/ca/ualberta/cs/lonelytwitter/Tweetable.java new file mode 100644 index 0000000000..cff18f45f7 --- /dev/null +++ b/app/src/main/java/ca/ualberta/cs/lonelytwitter/Tweetable.java @@ -0,0 +1,11 @@ +package ca.ualberta.cs.lonelytwitter; + + +import java.util.Date; + +public interface Tweetable { + public String getMessage(); + + public Date getDate(); + +} diff --git a/app/src/main/java/ca/ualberta/cs/lonelytwitter/package-info.java b/app/src/main/java/ca/ualberta/cs/lonelytwitter/package-info.java new file mode 100644 index 0000000000..f72a675649 --- /dev/null +++ b/app/src/main/java/ca/ualberta/cs/lonelytwitter/package-info.java @@ -0,0 +1,4 @@ +/** + * Test package documentation. + */ +package ca.ualberta.cs.lonelytwitter; \ No newline at end of file diff --git a/app/src/main/java/ca/ualberta/cs/lonelytwitter/package.html b/app/src/main/java/ca/ualberta/cs/lonelytwitter/package.html new file mode 100644 index 0000000000..0d255752f7 --- /dev/null +++ b/app/src/main/java/ca/ualberta/cs/lonelytwitter/package.html @@ -0,0 +1,14 @@ + + + + +This is a sample package that provides classes for LonelyTwitter application. +

+ New Paragraph +

+ + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_edit_tweet.xml b/app/src/main/res/layout/activity_edit_tweet.xml new file mode 100644 index 0000000000..6f5b6fea1b --- /dev/null +++ b/app/src/main/res/layout/activity_edit_tweet.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/app/src/main/res/layout/main.xml b/app/src/main/res/layout/main.xml index c2eec36e46..a356fd3219 100644 --- a/app/src/main/res/layout/main.xml +++ b/app/src/main/res/layout/main.xml @@ -35,7 +35,7 @@ android:id="@+id/clear" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="@string/clear" /> + android:text="Clear" />