-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2ada080
Showing
44 changed files
with
1,283 additions
and
0 deletions.
There are no files selected for viewing
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,10 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
/build |
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,37 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
defaultConfig { | ||
applicationId "com.example.niket.swipelefttoremoverecyclerview" | ||
minSdkVersion 22 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
|
||
implementation 'com.android.support.constraint:constraint-layout:1.1.3' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
implementation 'com.android.support:design:28.0.0' | ||
implementation 'com.android.support:recyclerview-v7:28.0.0' | ||
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1' | ||
// glide image library | ||
implementation 'com.github.bumptech.glide:glide:3.7.0' | ||
|
||
// volley http library | ||
implementation 'com.android.volley:volley:1.0.0' | ||
implementation 'com.google.code.gson:gson:2.6.2' | ||
} |
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
...oidTest/java/com/example/niket/swipelefttoremoverecyclerview/ExampleInstrumentedTest.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,26 @@ | ||
package com.example.niket.swipelefttoremoverecyclerview; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.example.niket.swipelefttoremoverecyclerview", appContext.getPackageName()); | ||
} | ||
} |
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,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.niket.swipelefttoremoverecyclerview"> | ||
|
||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<application | ||
android:name=".MyApplication" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme.NoActionBar"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
80 changes: 80 additions & 0 deletions
80
app/src/main/java/com/example/niket/swipelefttoremoverecyclerview/CartListAdapter.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.example.niket.swipelefttoremoverecyclerview; | ||
|
||
import android.content.Context; | ||
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.RelativeLayout; | ||
import android.widget.TextView; | ||
|
||
import com.bumptech.glide.Glide; | ||
|
||
import java.util.List; | ||
|
||
public class CartListAdapter extends RecyclerView.Adapter<CartListAdapter.MyViewHolder> { | ||
private Context context; | ||
private List<Item> cartList; | ||
|
||
public class MyViewHolder extends RecyclerView.ViewHolder { | ||
public TextView name, description, price; | ||
public ImageView thumbnail; | ||
public RelativeLayout viewBackground, viewForeground; | ||
|
||
public MyViewHolder(View view) { | ||
super(view); | ||
name = view.findViewById(R.id.name); | ||
description = view.findViewById(R.id.description); | ||
price = view.findViewById(R.id.price); | ||
thumbnail = view.findViewById(R.id.thumbnail); | ||
viewBackground = view.findViewById(R.id.view_background); | ||
viewForeground = view.findViewById(R.id.view_foreground); | ||
} | ||
} | ||
|
||
|
||
public CartListAdapter(Context context, List<Item> cartList) { | ||
this.context = context; | ||
this.cartList = cartList; | ||
} | ||
|
||
@Override | ||
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
View itemView = LayoutInflater.from(parent.getContext()) | ||
.inflate(R.layout.cart_list_item, parent, false); | ||
|
||
return new MyViewHolder(itemView); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(MyViewHolder holder, final int position) { | ||
final Item item = cartList.get(position); | ||
holder.name.setText(item.getName()); | ||
holder.description.setText(item.getDescription()); | ||
holder.price.setText("₹" + item.getPrice()); | ||
|
||
Glide.with(context) | ||
.load(item.getThumbnail()) | ||
.into(holder.thumbnail); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return cartList.size(); | ||
} | ||
|
||
public void removeItem(int position) { | ||
cartList.remove(position); | ||
// notify the item removed by position | ||
// to perform recycler view delete animations | ||
// NOTE: don't call notifyDataSetChanged() | ||
notifyItemRemoved(position); | ||
} | ||
|
||
public void restoreItem(Item item, int position) { | ||
cartList.add(position, item); | ||
// notify item added by position | ||
notifyItemInserted(position); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
app/src/main/java/com/example/niket/swipelefttoremoverecyclerview/Item.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,52 @@ | ||
package com.example.niket.swipelefttoremoverecyclerview; | ||
|
||
public class Item { | ||
int id; | ||
String name; | ||
String description; | ||
double price; | ||
String thumbnail; | ||
|
||
public Item() { | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
public double getPrice() { | ||
return price; | ||
} | ||
|
||
public void setPrice(double price) { | ||
this.price = price; | ||
} | ||
|
||
public String getThumbnail() { | ||
return thumbnail; | ||
} | ||
|
||
public void setThumbnail(String thumbnail) { | ||
this.thumbnail = thumbnail; | ||
} | ||
} |
Oops, something went wrong.