-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #546 from OpenSRP/images-and-text-label-view
Implemented dynamic label view for showing list of images and texts
- Loading branch information
Showing
13 changed files
with
345 additions
and
5 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
android-json-form-wizard/src/main/java/com/vijay/jsonwizard/adapter/DynamicLabelAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.vijay.jsonwizard.adapter; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.NonNull; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.vijay.jsonwizard.R; | ||
import com.vijay.jsonwizard.model.DynamicLabelInfo; | ||
import com.vijay.jsonwizard.utils.FormUtils; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
|
||
public class DynamicLabelAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { | ||
private final Context context; | ||
private final ArrayList<DynamicLabelInfo> dynamicLabelInfoList; | ||
|
||
public DynamicLabelAdapter(Context context, ArrayList<DynamicLabelInfo> dynamicLabelInfoList) { | ||
this.context = context; | ||
this.dynamicLabelInfoList = dynamicLabelInfoList; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.dynamic_dialog_row_layout, parent, false); | ||
return new RecyclerViewHolder(itemView); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | ||
final RecyclerViewHolder recyclerViewHolder = (RecyclerViewHolder) holder; | ||
String dynamicLabelTitle = dynamicLabelInfoList.get(position).getDynamicLabelTitle(); | ||
if (StringUtils.isNotBlank(dynamicLabelTitle)) { | ||
recyclerViewHolder.tileTextView.setText(dynamicLabelTitle); | ||
recyclerViewHolder.tileTextView.setVisibility(View.VISIBLE); | ||
} | ||
|
||
String dynamicLabelText = dynamicLabelInfoList.get(position).getDynamicLabelText(); | ||
if (StringUtils.isNotBlank(dynamicLabelText)) { | ||
recyclerViewHolder.descriptionTextView.setText(dynamicLabelText); | ||
recyclerViewHolder.descriptionTextView.setVisibility(View.VISIBLE); | ||
} | ||
|
||
String dynamicLabelImageSrc = dynamicLabelInfoList.get(position).getDynamicLabelImageSrc(); | ||
if (StringUtils.isNotBlank(dynamicLabelImageSrc)) { | ||
try { | ||
recyclerViewHolder.imageViewLabel.setImageDrawable(FormUtils.readImageFromAsset(context, dynamicLabelImageSrc)); | ||
recyclerViewHolder.imageViewLabel.setVisibility(View.VISIBLE); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return dynamicLabelInfoList.size(); | ||
} | ||
|
||
public static class RecyclerViewHolder extends RecyclerView.ViewHolder { | ||
private final TextView descriptionTextView; | ||
private final TextView tileTextView; | ||
private final ImageView imageViewLabel; | ||
|
||
private RecyclerViewHolder(View view) { | ||
super(view); | ||
descriptionTextView = view.findViewById(R.id.descriptionText); | ||
tileTextView = view.findViewById(R.id.labelTitle); | ||
imageViewLabel = view.findViewById(R.id.imageViewLabel); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
android-json-form-wizard/src/main/java/com/vijay/jsonwizard/model/DynamicLabelInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.vijay.jsonwizard.model; | ||
|
||
/** | ||
* Created by Qazi Abubakar | ||
*/ | ||
public class DynamicLabelInfo { | ||
private final String dynamicLabelTitle; | ||
private final String dynamicLabelText; | ||
private final String dynamicLabelImageSrc; | ||
|
||
public DynamicLabelInfo(String dynamicLabelTitle, String dynamicLabelText, String dynamicLabelImageSrc) { | ||
this.dynamicLabelTitle = dynamicLabelTitle; | ||
this.dynamicLabelText = dynamicLabelText; | ||
this.dynamicLabelImageSrc = dynamicLabelImageSrc; | ||
} | ||
|
||
public String getDynamicLabelTitle() { | ||
return dynamicLabelTitle; | ||
} | ||
|
||
public String getDynamicLabelText() { | ||
return dynamicLabelText; | ||
} | ||
|
||
public String getDynamicLabelImageSrc() { | ||
return dynamicLabelImageSrc; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
android-json-form-wizard/src/main/res/layout/dynamic_dialog_row_layout.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<LinearLayout | ||
android:id="@+id/customDialogRowLayout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_margin="@dimen/custom_dialog_margin" | ||
android:orientation="vertical"> | ||
|
||
<com.vijay.jsonwizard.views.CustomTextView | ||
android:id="@+id/labelTitle" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="6dp" | ||
android:gravity="start" | ||
android:textColor="@color/black" | ||
android:textSize="18sp" | ||
android:textStyle="bold" | ||
android:visibility="gone" | ||
tools:text="Here goes the Title!" /> | ||
|
||
<TextView | ||
android:id="@+id/descriptionText" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="6dp" | ||
android:textSize="18sp" | ||
android:visibility="gone" | ||
tools:text="This is where the description must go!" /> | ||
|
||
<ImageView | ||
android:id="@+id/imageViewLabel" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:adjustViewBounds="true" | ||
android:contentDescription="@string/shows_image_on_dialog" | ||
android:scaleType="fitXY" | ||
android:visibility="gone" /> | ||
</LinearLayout> | ||
</LinearLayout> |
51 changes: 51 additions & 0 deletions
51
android-json-form-wizard/src/main/res/layout/native_form_dynamic_dialog.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<RelativeLayout | ||
android:id="@+id/customDialogMainLayout" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="@dimen/custom_dialog_margin" | ||
android:orientation="vertical"> | ||
|
||
<com.vijay.jsonwizard.views.CustomTextView | ||
android:id="@+id/dialogTitle" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentTop="true" | ||
android:layout_marginBottom="10dp" | ||
android:gravity="center" | ||
android:textColor="@color/black" | ||
android:textSize="18sp" | ||
android:textStyle="bold" | ||
android:visibility="gone" | ||
tools:text="Title" /> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/dialogRecyclerView" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_above="@+id/dialogButton" | ||
android:layout_below="@+id/dialogTitle" | ||
android:layout_gravity="center" | ||
android:layout_margin="6dp" | ||
android:overScrollMode="never" | ||
android:visibility="gone" /> | ||
|
||
<android.support.v7.widget.AppCompatButton | ||
android:id="@+id/dialogButton" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentBottom="true" | ||
android:background="@drawable/okay_button" | ||
android:padding="6dp" | ||
android:text="@string/ok" | ||
android:visibility="gone" | ||
android:textAlignment="center" | ||
android:textColor="@color/toaster_note_blue_icon" | ||
android:textStyle="bold" /> | ||
</RelativeLayout> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.