From 01cb35b4aa0eabb7ef3002644d2599f80ba23ee7 Mon Sep 17 00:00:00 2001 From: MHD HAMZA AL OMARI <36658089+OMARIHAMZA@users.noreply.github.com> Date: Mon, 28 Oct 2019 19:10:44 +0200 Subject: [PATCH 1/3] Update README.md --- README.md | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 144 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 183afca..53729ae 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,152 @@ allprojects { Add the dependency: ``` dependencies { - implementation 'com.github.OMARIHAMZA:StoryView:1.0.0-alpha' + implementation 'com.github.OMARIHAMZA:StoryView:1.0.1-alpha' } ``` #### 2. Create the StoryView +You have two options, the first one is to use the same header (what I mean by header is the logo, title and the subtitle) for all the images in the story, or to define a custom header for each image. +Let's start first by creating the stories. + +##### A. Constructing the Stories + + +You have to pass to the library's builder an ArrayList of 'MyStory' where MyStory represents a single story (clearly) and contains the following members: + +* String url (Required/NotNull): The link of the image + +* Date date (Optional/Nullable): The date when the story got posted (If you have the date as a String, use a SimpleDateFormat to parse it into a Date object) + +* String description (Optional/Nullable): The description of the story which gets displayed as shown in the screenshot below: + +![Screenshots](images/screenshot1.jpg) + + +**If you don't want to display a description along with the image just pass the description as null or as an empty String and it will not be displayed.** + +* Example code: + +```java +MyStory currentStory = new MyStory( + "dummy-link", + simpleDateFormat.parse("20-10-2019 10:00:00"), + null + ); ``` - TO BE DOCUMENTED - ``` + +**Another option is to use the second constructor which takes the url and the date only.** +* Example code: + +```java + MyStory currentStory = new MyStory( + "dummy-link", + simpleDateFormat.parse("20-10-2019 10:00:00"), + ); +``` + +Now, lets construct the Stories ArrayList: + +Assume we have an ArrayList of 'Story' where the single 'Story' contains the fields (imageUrl & date): + +```java + +ArrayList data = ....; +... +ArrayList myStories = new ArrayList<>(); + +for(Story story: data){ + myStories.add(new MyStory( + story.getImageUrl(), + story.getDate() + )); +} + +``` + +Simple! Right? + +#### B. Construction the Header(s) + +##### B.1 Option one (The same header for all the images) + +```java +new StoryView.Builder(getSupportFragmentManager()) + .setStoriesList(myStories) // Required + .setStoryDuration(5000) // Default is 2000 Millis (2 Seconds) + .setTitleText("Hamza Al-Omari") // Default is Hidden + .setSubtitleText("Damascus") // Default is Hidden + .setTitleLogoUrl("some-link") // Default is Hidden + .setStoryClickListeners(new StoryClickListeners() { + @Override + public void onDescriptionClickListener(int position) { + //your action + } + + @Override + public void onTitleIconClickListener(int position) { + //your action + } + }) // Optional Listeners + .build() // Must be called before calling show method + .show(); + +``` + +##### B.2 Option two (Custom header for each image) + +This process is similar to the process of constructing the stories list, instead we have to create an ArrayList of 'StoryViewHeaderInfo' which contains the following fields: + +* String title + +* String subtitle + +* String titleIconUrl + +Let's construct the ArrayList: + +Assume the same previous example (the ArrayList of Story) but each story in this list has a different person who posted it. +Now the story contains these additional fields (username: String, userLocation: String, userImageUrl: String) + +```java + +ArrayList headerInfoArrayList = new ArrayList<>(); + +for (Story story : data) { + headerInfoArrayList.add(new StoryViewHeaderInfo( + story.getUsername(), + story.getUserLocation(), + story.getUserImageUrl() + )); + } + +``` + +#### B.3 Finally, pass the ArrayList to the Builder: + +```java +new StoryView.Builder(getSupportFragmentManager()) + .setStoriesList(myStories) // MyStory's ArrayList + .setStoryDuration(5000) // Optional, default is 2000 Millis + .setHeadingInfoList(headerInfoArrayList) // StoryViewHeaderInfo's ArrayList + .setStoryClickListeners(new StoryClickListeners() { + @Override + public void onDescriptionClickListener(int position) { + // your action + } + + @Override + public void onTitleIconClickListener(int position) { + // your action + } + }) // Optional Listeners + .build() // Must be called before show method + .show(); + +``` + +And that's it!! + ## Credit @@ -38,6 +176,9 @@ dependencies { ## Developed By #### Mhd Hamza Al Omari * [LinkedIn](https://www.linkedin.com/in/omarihamza/) +* omarihamza@outlook.com + +Please feel free to suggest any new features to be added to the Library. ## License From a33460dbed11d33c042373eb131b5a7e34783d30 Mon Sep 17 00:00:00 2001 From: MHD HAMZA AL OMARI <36658089+OMARIHAMZA@users.noreply.github.com> Date: Mon, 28 Oct 2019 19:18:03 +0200 Subject: [PATCH 2/3] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 53729ae..5afe4e8 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,9 @@ You have to pass to the library's builder an ArrayList of 'MyStory' where MyStor * String description (Optional/Nullable): The description of the story which gets displayed as shown in the screenshot below: -![Screenshots](images/screenshot1.jpg) - +

+ +

**If you don't want to display a description along with the image just pass the description as null or as an empty String and it will not be displayed.** From 1bd4c6c847098c75e079979d9afecef341412aad Mon Sep 17 00:00:00 2001 From: MHD HAMZA AL OMARI <36658089+OMARIHAMZA@users.noreply.github.com> Date: Mon, 28 Oct 2019 19:30:05 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5afe4e8..6ce8740 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ for (Story story : data) { ``` -#### B.3 Finally, pass the ArrayList to the Builder: +##### B.3 Finally, pass the ArrayList to the Builder: ```java new StoryView.Builder(getSupportFragmentManager())