Skip to content

Commit

Permalink
Merge pull request RohitSurwase#5 from RohitSurwase/develop
Browse files Browse the repository at this point in the history
 Added demo app for dynamic expandable RecyclerView
  • Loading branch information
RohitSurwase authored Nov 30, 2017
2 parents 845c1f5 + cf56043 commit 9bf5939
Show file tree
Hide file tree
Showing 21 changed files with 410 additions and 184 deletions.
8 changes: 4 additions & 4 deletions acl-in-android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
compileSdkVersion 26
buildToolsVersion "26.0.2"

defaultConfig {
applicationId "com.rohitss.androidacl"
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"

Expand All @@ -27,7 +27,7 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
4 changes: 2 additions & 2 deletions animations-simplified/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
buildToolsVersion "26.0.2"

defaultConfig {
applicationId "com.rohitss.animationssimplified"
Expand All @@ -27,7 +27,7 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
6 changes: 3 additions & 3 deletions auto-read-sms-otp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.rohitss.autoreadsmsotp"
minSdkVersion 16
Expand All @@ -24,7 +24,7 @@ dependencies {
// androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
// exclude group: 'com.android.support', module: 'support-annotations'
// })
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:design:25.4.0'
// testCompile 'junit:junit:4.12'
}
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
Expand All @@ -15,6 +16,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
22 changes: 12 additions & 10 deletions dynamic-recycler-view/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.rohitss.androiddesignpatterns"
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
Expand All @@ -20,11 +20,13 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile fileTree(include: ['*.jar'], dir: 'libs')
/*androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})*/
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
// testCompile 'junit:junit:4.12'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
}

This file was deleted.

2 changes: 1 addition & 1 deletion dynamic-recycler-view/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.rohitss.dynamicrecycler.MainActivity">
<activity android:name="com.rohitss.dynamicrecycler.DynamicRecyclerActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.rohitss.dynamicrecycler;

import java.io.Serializable;

/**
* <b></b>
* <p>This class is used to </p>
* Created by Rohit.
*/
class DummyChildDataItem implements Serializable {
private String childName;

public String getChildName() {
return childName;
}

public void setChildName(String childName) {
this.childName = childName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.rohitss.dynamicrecycler;

import java.io.Serializable;
import java.util.ArrayList;

/**
* <b></b>
* <p>This class is used to </p>
* Created by Rohit.
*/
class DummyParentDataItem implements Serializable {
private String parentName;
private ArrayList<DummyChildDataItem> childDataItems;

public String getParentName() {
return parentName;
}

public void setParentName(String parentName) {
this.parentName = parentName;
}

public ArrayList<DummyChildDataItem> getChildDataItems() {
return childDataItems;
}

public void setChildDataItems(ArrayList<DummyChildDataItem> childDataItems) {
this.childDataItems = childDataItems;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
package com.rohitss.dynamicrecycler;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;

public class DynamicRecyclerActivity extends AppCompatActivity {
private RecyclerView mRecyclerView;
private Context mContext;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dynamic_recycler);
setContentView(R.layout.activity_dynamic_recycler);
mContext = DynamicRecyclerActivity.this;
mRecyclerView = findViewById(R.id.recyclerView);
RecyclerDataAdapter recyclerDataAdapter = new RecyclerDataAdapter(getDummyDataToPass());
mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
mRecyclerView.setAdapter(recyclerDataAdapter);
mRecyclerView.setHasFixedSize(true);
}

private ArrayList<DummyParentDataItem> getDummyDataToPass() {
ArrayList<DummyParentDataItem> dummyDataItems = new ArrayList<>();
ArrayList<DummyChildDataItem> dummyChildDataItems;
DummyParentDataItem dummyParentDataItem;
DummyChildDataItem dummyChildDataItem;
/////////
dummyParentDataItem = new DummyParentDataItem();
dummyParentDataItem.setParentName("Parent 1");
dummyChildDataItems = new ArrayList<>();
//
dummyChildDataItem = new DummyChildDataItem();
dummyChildDataItem.setChildName("Child Item 1");
dummyChildDataItems.add(dummyChildDataItem);
//
dummyParentDataItem.setChildDataItems(dummyChildDataItems);
dummyDataItems.add(dummyParentDataItem);
////////
dummyParentDataItem = new DummyParentDataItem();
dummyParentDataItem.setParentName("Parent 2");
dummyChildDataItems = new ArrayList<>();
//
dummyChildDataItem = new DummyChildDataItem();
dummyChildDataItem.setChildName("Child Item 1");
dummyChildDataItems.add(dummyChildDataItem);
//
dummyChildDataItem = new DummyChildDataItem();
dummyChildDataItem.setChildName("Child Item 2");
dummyChildDataItems.add(dummyChildDataItem);
//
dummyParentDataItem.setChildDataItems(dummyChildDataItems);
dummyDataItems.add(dummyParentDataItem);
////////
dummyParentDataItem = new DummyParentDataItem();
dummyParentDataItem.setParentName("Parent 3");
dummyChildDataItems = new ArrayList<>();
//
dummyChildDataItem = new DummyChildDataItem();
dummyChildDataItem.setChildName("Child Item 1");
dummyChildDataItems.add(dummyChildDataItem);
//
dummyChildDataItem = new DummyChildDataItem();
dummyChildDataItem.setChildName("Child Item 2");
dummyChildDataItems.add(dummyChildDataItem);
//
dummyChildDataItem = new DummyChildDataItem();
dummyChildDataItem.setChildName("Child Item 3");
dummyChildDataItems.add(dummyChildDataItem);
//
dummyChildDataItem = new DummyChildDataItem();
dummyChildDataItem.setChildName("Child Item 4");
dummyChildDataItems.add(dummyChildDataItem);
//
dummyChildDataItem = new DummyChildDataItem();
dummyChildDataItem.setChildName("Child Item 5");
dummyChildDataItems.add(dummyChildDataItem);
//
dummyParentDataItem.setChildDataItems(dummyChildDataItems);
dummyDataItems.add(dummyParentDataItem);
////////
return dummyDataItems;
}

private class RecyclerDataAdapter extends RecyclerView.Adapter<RecyclerDataAdapter.MyViewHolder> {
private ArrayList<DummyParentDataItem> dummyParentDataItems;

RecyclerDataAdapter(ArrayList<DummyParentDataItem> dummyParentDataItems) {
this.dummyParentDataItems = dummyParentDataItems;
}

@Override
public RecyclerDataAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_parent_child_listing, parent, false);
return new MyViewHolder(itemView);
}

@Override
public void onBindViewHolder(RecyclerDataAdapter.MyViewHolder holder, int position) {
DummyParentDataItem dummyParentDataItem = dummyParentDataItems.get(position);
holder.textView_parentName.setText(dummyParentDataItem.getParentName());
//
int noOfChildTextViews = holder.linearLayout_childItems.getChildCount();
int noOfChild = dummyParentDataItem.getChildDataItems().size();
if (noOfChild < noOfChildTextViews) {
for (int index = noOfChild; index < noOfChildTextViews; index++) {
TextView currentTextView = (TextView) holder.linearLayout_childItems.getChildAt(index);
currentTextView.setVisibility(View.GONE);
}
}
for (int textViewIndex = 0; textViewIndex < noOfChild; textViewIndex++) {
TextView currentTextView = (TextView) holder.linearLayout_childItems.getChildAt(textViewIndex);
currentTextView.setText(dummyParentDataItem.getChildDataItems().get(textViewIndex).getChildName());
/*currentTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(mContext, "" + ((TextView) view).getText().toString(), Toast.LENGTH_SHORT).show();
}
});*/
}
}

@Override
public int getItemCount() {
return dummyParentDataItems.size();
}

class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private Context context;
private TextView textView_parentName;
private LinearLayout linearLayout_childItems;

MyViewHolder(View itemView) {
super(itemView);
context = itemView.getContext();
textView_parentName = itemView.findViewById(R.id.tv_parentName);
linearLayout_childItems = itemView.findViewById(R.id.ll_child_items);
linearLayout_childItems.setVisibility(View.GONE);
int intMaxNoOfChild = 0;
for (int index = 0; index < dummyParentDataItems.size(); index++) {
int intMaxSizeTemp = dummyParentDataItems.get(index).getChildDataItems().size();
if (intMaxSizeTemp > intMaxNoOfChild) intMaxNoOfChild = intMaxSizeTemp;
}
for (int indexView = 0; indexView < intMaxNoOfChild; indexView++) {
TextView textView = new TextView(context);
textView.setId(indexView);
textView.setPadding(0, 20, 0, 20);
textView.setGravity(Gravity.CENTER);
textView.setBackground(ContextCompat.getDrawable(context, R.drawable.background_sub_module_text));
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
textView.setOnClickListener(this);
linearLayout_childItems.addView(textView, layoutParams);
}
textView_parentName.setOnClickListener(this);
}

@Override
public void onClick(View view) {
if (view.getId() == R.id.tv_parentName) {
if (linearLayout_childItems.getVisibility() == View.VISIBLE) {
linearLayout_childItems.setVisibility(View.GONE);
} else {
linearLayout_childItems.setVisibility(View.VISIBLE);
}
} else {
TextView textViewClicked = (TextView) view;
Toast.makeText(context, "" + textViewClicked.getText().toString(), Toast.LENGTH_SHORT).show();
}
}
}
}
}
Loading

0 comments on commit 9bf5939

Please sign in to comment.