Skip to content

Commit b76f7fb

Browse files
author
Sourav Das
committed
Initial commit
0 parents  commit b76f7fb

32 files changed

+634
-0
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 29
5+
buildToolsVersion "29.0.3"
6+
7+
defaultConfig {
8+
applicationId "com.sourav.story"
9+
minSdkVersion 22
10+
targetSdkVersion 29
11+
versionCode 1
12+
versionName "1.0"
13+
14+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15+
}
16+
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
24+
}
25+
26+
dependencies {
27+
implementation fileTree(dir: 'libs', include: ['*.jar'])
28+
29+
implementation 'androidx.appcompat:appcompat:1.0.2'
30+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
31+
testImplementation 'junit:junit:4.12'
32+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
33+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
34+
//Recycler View
35+
implementation "androidx.recyclerview:recyclerview:1.1.0"
36+
implementation "androidx.recyclerview:recyclerview-selection:1.1.0-rc01"
37+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.sourav.story;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
25+
assertEquals("com.sourav.story", appContext.getPackageName());
26+
}
27+
}

app/src/main/AndroidManifest.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.sourav.story">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.sourav.story;
2+
3+
import androidx.annotation.NonNull;
4+
import androidx.appcompat.app.AppCompatActivity;
5+
import androidx.recyclerview.widget.LinearLayoutManager;
6+
import androidx.recyclerview.widget.RecyclerView;
7+
8+
import android.os.Bundle;
9+
import android.view.MotionEvent;
10+
import android.widget.Toast;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
15+
public class MainActivity extends AppCompatActivity implements OnRVClickListner{
16+
private List<StoryData> story = new ArrayList<>();
17+
18+
@Override
19+
protected void onCreate(Bundle savedInstanceState) {
20+
super.onCreate(savedInstanceState);
21+
setContentView(R.layout.activity_main);
22+
getData();
23+
}
24+
25+
private void getData() {
26+
story.add(new StoryData("1", "1","1"));
27+
story.add(new StoryData("2","2","2"));
28+
story.add(new StoryData("3","3","3"));
29+
story.add(new StoryData("4","4","4"));
30+
initRview();
31+
}
32+
33+
private void initRview() {
34+
RecyclerView recyclerView = findViewById(R.id.recyclerView);
35+
NewAdapter newAdapter = new NewAdapter(this, story);
36+
recyclerView.setAdapter(newAdapter);
37+
recyclerView.setLayoutManager(new LinearLayoutManager(this));
38+
recyclerView.setItemViewCacheSize(0);
39+
newAdapter.setOnClick(MainActivity.this);
40+
41+
}
42+
43+
@Override
44+
public void onClick(int pos) {
45+
Toast.makeText(this, "Clicked at pos "+ pos ,Toast.LENGTH_SHORT).show();
46+
}
47+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.sourav.story;
2+
3+
import android.content.Context;
4+
import android.util.Log;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.widget.FrameLayout;
9+
import android.widget.RelativeLayout;
10+
import android.widget.TextView;
11+
12+
import androidx.annotation.NonNull;
13+
import androidx.recyclerview.widget.RecyclerView;
14+
15+
import java.util.List;
16+
17+
public class NewAdapter extends RecyclerView.Adapter<NewAdapter.ViewHolder> {
18+
private List<StoryData> data;
19+
private Context mContext;
20+
private OnRVClickListner listner;
21+
22+
public NewAdapter(Context mContext, List<StoryData> data) {
23+
this.data = data;
24+
this.mContext = mContext;
25+
}
26+
27+
@NonNull
28+
@Override
29+
public NewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
30+
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.recycler_list, viewGroup, false);
31+
ViewHolder holder = new ViewHolder(view);
32+
return holder;
33+
}
34+
35+
@Override
36+
public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
37+
Log.d("RV", "onBindViewHolder: size" + data.size());
38+
Log.d("RV", "onBindViewHolder: Called");
39+
Log.d("RV", "onBindViewHolder: Value of i " + i);
40+
StoryData story = data.get(i);
41+
viewHolder.title.setText(story.getBody());
42+
viewHolder.time.setText(story.getTime());
43+
viewHolder.date.setText(story.getDate());
44+
viewHolder.parent.setOnClickListener(new View.OnClickListener() {
45+
@Override
46+
public void onClick(View v) {
47+
listner.onClick(i);
48+
}
49+
});
50+
}
51+
52+
@Override
53+
public int getItemCount() {
54+
return data.size();
55+
}
56+
57+
class ViewHolder extends RecyclerView.ViewHolder {
58+
TextView title;
59+
TextView time;
60+
TextView date;
61+
RelativeLayout parent;
62+
ViewHolder(@NonNull View itemView) {
63+
super(itemView);
64+
title = itemView.findViewById(R.id.listBody);
65+
time = itemView.findViewById(R.id.listTime);
66+
date = itemView.findViewById(R.id.listDate);
67+
parent = itemView.findViewById(R.id.parentLayout);
68+
}
69+
}
70+
71+
public void setOnClick(OnRVClickListner onClick){
72+
listner = onClick;
73+
}
74+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.sourav.story;
2+
3+
public interface OnRVClickListner {
4+
void onClick(int pos);
5+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.sourav.story;
2+
3+
public class StoryData {
4+
private String uniqueID;
5+
private String time;
6+
private String Date;
7+
private String body;
8+
private long timestamp;
9+
10+
public StoryData(String uniqueID, String time, String date, String body, long timestamp) {
11+
this.uniqueID = uniqueID;
12+
this.time = time;
13+
Date = date;
14+
this.body = body;
15+
this.timestamp = timestamp;
16+
}
17+
18+
public StoryData(String time, String date, String body) {
19+
this.time = time;
20+
Date = date;
21+
this.body = body;
22+
}
23+
24+
public String getUniqueID() {
25+
return uniqueID;
26+
}
27+
28+
public void setUniqueID(String uniqueID) {
29+
this.uniqueID = uniqueID;
30+
}
31+
32+
public String getTime() {
33+
return time;
34+
}
35+
36+
public void setTime(String time) {
37+
this.time = time;
38+
}
39+
40+
public String getDate() {
41+
return Date;
42+
}
43+
44+
public void setDate(String date) {
45+
Date = date;
46+
}
47+
48+
public String getBody() {
49+
return body;
50+
}
51+
52+
public void setBody(String body) {
53+
this.body = body;
54+
}
55+
56+
public long getTimestamp() {
57+
return timestamp;
58+
}
59+
60+
public void setTimestamp(long timestamp) {
61+
this.timestamp = timestamp;
62+
}
63+
}

0 commit comments

Comments
 (0)