Skip to content

Commit

Permalink
RV Setup for New Activity
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshRaj-BITS committed Dec 18, 2018
1 parent 7bac33e commit b96c397
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle
Expand Up @@ -73,6 +73,7 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"

// implementation 'com.google.firebase:firebase-database:16.0.1:15.0.0'
}
apply plugin: 'com.google.gms.google-services'
repositories {
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Expand Up @@ -14,7 +14,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:largeHeap="true">

<activity android:name=".activities.HomeActivity">

Expand Down Expand Up @@ -55,6 +56,9 @@

<activity android:name=".activities.LoginActivity">
</activity>

<activity android:name=".activities.ResidentActivity">
</activity>
<meta-data
android:name="com.google.firebase.ml.vision.DEPENDENCIES"
android:value="barcode" />
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/java/com/macbitsgoa/prdrive/ResidentModel.java
@@ -0,0 +1,29 @@
package com.macbitsgoa.prdrive;

public class ResidentModel {

String name;
String roomNo;

public ResidentModel(String name, String roomNo)
{
this.name= name;
this.roomNo=roomNo;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getRoomNo() {
return roomNo;
}

public void setRoomNo(String roomNo) {
this.roomNo = roomNo;
}
}
Expand Up @@ -54,7 +54,6 @@ protected void onCreate(Bundle savedInstanceState) {

String password;
String prdrive_id;

Button logout_btn;

Realm.init(HomeActivity.this);
Expand Down
@@ -0,0 +1,27 @@
package com.macbitsgoa.prdrive.activities;

import android.app.Activity;
import android.os.Bundle;
import com.macbitsgoa.prdrive.R;
import com.macbitsgoa.prdrive.adapters.ResidentAdapter;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


public class ResidentActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_resident);

RecyclerView rv;

rv = findViewById(R.id.list_rv);
rv.setLayoutManager(new LinearLayoutManager(ResidentActivity.this));
rv.setHasFixedSize(false);
ResidentAdapter residentAdapter = new ResidentAdapter(ResidentActivity.this);
rv.setAdapter(residentAdapter);


}
}
@@ -0,0 +1,38 @@
package com.macbitsgoa.prdrive.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.macbitsgoa.prdrive.R;
import com.macbitsgoa.prdrive.viewholders.ResidentViewHolder;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import static com.macbitsgoa.prdrive.StaticHelperClass.merchModelList;

public class ResidentAdapter extends RecyclerView.Adapter<ResidentViewHolder> {
Context context;

public ResidentAdapter(Context ctx) {
this.context = ctx;
}

@Override
public ResidentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ResidentViewHolder(View.inflate(parent.getContext(), R.layout.item_format_resident, null) ,
parent.getContext());
}

@Override
public void onBindViewHolder(@NonNull ResidentViewHolder holder, int position) {


}

@Override
public int getItemCount() {
return merchModelList.size();
}
}
Expand Up @@ -16,6 +16,7 @@
import com.macbitsgoa.prdrive.BuildConfig;
import com.macbitsgoa.prdrive.R;
import com.macbitsgoa.prdrive.activities.MerchActivity;
import com.macbitsgoa.prdrive.activities.ResidentActivity;

import java.util.Objects;

Expand Down Expand Up @@ -61,7 +62,7 @@ public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
killSwitch[0] = Objects.requireNonNull(child.child("killSwitch").getValue(String.class));
}
if (killSwitch[0].equals("1")) {
Intent intent = new Intent(context, MerchActivity.class);
Intent intent = new Intent(context, ResidentActivity.class);
hostelname = hostelName.getText().toString();
context.startActivity(intent);
activity.finish();
Expand Down
@@ -0,0 +1,39 @@
package com.macbitsgoa.prdrive.viewholders;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;
import com.macbitsgoa.prdrive.R;
import com.macbitsgoa.prdrive.activities.MerchActivity;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;


public class ResidentViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

private Context ctx;
public TextView name;
public TextView roomNo;


public ResidentViewHolder(@NonNull View itemView , Context ctx) {
super(itemView);

CardView cardView;
this.ctx = ctx;
name =itemView.findViewById(R.id.name);
roomNo = itemView.findViewById(R.id.roomNo);
cardView = itemView.findViewById(R.id.cv);
cardView.setOnClickListener(this);
}

@Override
public void onClick(View view) {

Intent i = new Intent(ctx,MerchActivity.class);
ctx.startActivity(i);
//take the activity to merchActivity
}
}
16 changes: 16 additions & 0 deletions app/src/main/res/layout/activity_resident.xml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list_rv"
android:padding="5dp">

</androidx.recyclerview.widget.RecyclerView>

</LinearLayout>
29 changes: 29 additions & 0 deletions app/src/main/res/layout/item_format_resident.xml
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/cv"
android:clickable="true">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="100">

<TextView
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="70" />

<TextView
android:id="@+id/roomNo"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="30" />
</LinearLayout>
</androidx.cardview.widget.CardView>

0 comments on commit b96c397

Please sign in to comment.