Skip to content

Commit

Permalink
hostel and student list is now fetched from realm
Browse files Browse the repository at this point in the history
* also bumped dependencies
* fixed layout bugs in student list
* NOTE : We're using `Student` class to model student data. So deleted
`ResidentModel`
  • Loading branch information
Rushi98 committed Dec 19, 2018
1 parent 10f4502 commit 56433f9
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 145 deletions.
33 changes: 16 additions & 17 deletions app/build.gradle
Expand Up @@ -47,33 +47,32 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.0-rc01'
implementation 'androidx.legacy:legacy-support-v13:1.0.0-rc01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-rc01'
implementation 'androidx.cardview:cardview:1.0.0-rc01'
implementation 'androidx.recyclerview:recyclerview:1.0.0-rc01'
implementation 'androidx.browser:browser:1.0.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.constraintlayout:constraintlayout-solver:1.1.2'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0-rc01'
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha01'
implementation 'androidx.browser:browser:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.constraintlayout:constraintlayout-solver:1.1.3'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0-alpha01'
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-database:16.0.5'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-storage:16.0.5'
implementation 'com.facebook.fresco:fresco:1.10.0'
implementation 'com.facebook.fresco:webpsupport:1.9.0'
implementation 'io.reactivex.rxjava2:rxjava:2.1.16'
implementation 'me.relex:photodraweeview:1.1.3'
implementation 'com.google.firebase:firebase-ml-vision:17.0.0'
implementation 'com.google.firebase:firebase-ml-vision:18.0.2'
implementation 'com.github.gcacace:signature-pad:1.2.1'
implementation 'com.github.chrisbanes:PhotoView:2.1.4'
def lifecycle_version = "2.0.0-rc01"
def lifecycle_version = "2.0.0"
// ViewModel and LiveData
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
29 changes: 0 additions & 29 deletions app/src/main/java/com/macbitsgoa/prdrive/ResidentModel.java

This file was deleted.

@@ -1,5 +1,6 @@
package com.macbitsgoa.prdrive.activities;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
Expand All @@ -17,10 +18,16 @@
import static com.macbitsgoa.prdrive.StaticHelperClass.finishbtn;
public class MerchActivity extends AppCompatActivity {

// TODO: add necessary arguments to be passed via intent
public static void launchMerch(Context context) {
Intent intent = new Intent(context, MerchActivity.class);
context.startActivity(intent);
}

@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
androidx.appcompat.widget.Toolbar toolbar = null;
androidx.appcompat.widget.Toolbar toolbar;
RecyclerView rv;
setContentView(R.layout.activity_merch);
//Setting up the Finish order button.
Expand Down Expand Up @@ -69,7 +76,3 @@ protected void onCreate (Bundle savedInstanceState) {
}

}




@@ -1,27 +1,44 @@
package com.macbitsgoa.prdrive.activities;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
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 {

public static final String INTENT_KEY_HOSTEL_NAME = ResidentActivity.class.getName() + ".intent.hostelName";

/**
* Use this method to launch this activity correctly.
*
* @param parent from which this is to be launched.
* @param hostelName name of the target hostel.
*/
public static void launchHostel(Context parent, String hostelName) {
Intent intent = new Intent(parent, ResidentActivity.class);
intent.putExtra(INTENT_KEY_HOSTEL_NAME, hostelName);
parent.startActivity(intent);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_resident);

Intent source = getIntent();
final String hostelName = source.getStringExtra(INTENT_KEY_HOSTEL_NAME);
RecyclerView rv;

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


}
}
}
34 changes: 25 additions & 9 deletions app/src/main/java/com/macbitsgoa/prdrive/adapters/HomeAdapter.java
@@ -1,37 +1,53 @@
package com.macbitsgoa.prdrive.adapters;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.macbitsgoa.prdrive.R;
import com.macbitsgoa.prdrive.Student;
import com.macbitsgoa.prdrive.viewholders.HomeViewHolder;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import io.realm.Realm;
import io.realm.RealmQuery;
import io.realm.RealmResults;


public class HomeAdapter extends RecyclerView.Adapter<HomeViewHolder> {


private String hostelNames[] = {"AH1", "AH2", "AH3", "AH4", "AH5", "AH6", "AH7",
"AH8", "AH9", "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "DH1", "DH2"};


private List<String> hostelNames;

public HomeAdapter() {
hostelNames = new ArrayList<>();
Realm realm = Realm.getDefaultInstance();
RealmQuery<Student> query = realm.where(Student.class).distinct("hostel");
RealmResults<Student> results = query.findAll();
for (Student s : results) {
hostelNames.add(s.hostel);
}
realm.close();
}

@NonNull
@Override
public HomeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new HomeViewHolder(View.inflate(parent.getContext(), R.layout.item_format_home, null),
parent.getContext());
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_format_home, parent, false);
return new HomeViewHolder(v);
}

@Override
public void onBindViewHolder(@NonNull HomeViewHolder holder, int position) {
holder.populate(hostelNames[position]);
holder.populate(hostelNames.get(position));
}

@Override
public int getItemCount() {
return hostelNames.length;
return hostelNames.size();
}
}
@@ -1,38 +1,45 @@
package com.macbitsgoa.prdrive.adapters;

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

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

import java.util.List;

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

import static com.macbitsgoa.prdrive.StaticHelperClass.merchModelList;
import io.realm.Realm;
import io.realm.RealmQuery;
import io.realm.RealmResults;

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

public ResidentAdapter(Context ctx) {
this.context = ctx;
private List<Student> students;

public ResidentAdapter(String hostel) {
Realm realm = Realm.getDefaultInstance();
RealmQuery<Student> query = realm.where(Student.class).equalTo("hostel", hostel);
RealmResults<Student> results = query.findAll();
students = realm.copyFromRealm(results);
realm.close();
}

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

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


holder.populate(students.get(position));
}

@Override
public int getItemCount() {
return merchModelList.size();
return students.size();
}
}
@@ -1,8 +1,5 @@
package com.macbitsgoa.prdrive.viewholders;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
Expand All @@ -15,38 +12,32 @@
import com.google.firebase.database.ValueEventListener;
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;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import static com.macbitsgoa.prdrive.StaticHelperClass.hostelname;

public class HomeViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
import static com.macbitsgoa.prdrive.activities.ResidentActivity.launchHostel;

private TextView hostelName;
private Context context;
private Activity activity;
private DatabaseReference databaseReference = FirebaseDatabase
.getInstance().getReference().child(BuildConfig.BUILD_TYPE).child("main").child("orgInfo").child("prdrive-meta");
public class HomeViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

private TextView hostelNameTv;
private DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference().child(BuildConfig.BUILD_TYPE)
.child("main").child("orgInfo").child("prdrive-meta");
private CardView cardView;

public HomeViewHolder(View itemView, Context context) {

public HomeViewHolder(View itemView) {
super(itemView);
CardView cardView;
this.context = context;
this.activity = (Activity) this.context;
hostelName = itemView.findViewById(R.id.ifhometv);
hostelNameTv = itemView.findViewById(R.id.ifhometv);
cardView = itemView.findViewById(R.id.ifhomecard);
cardView.setOnClickListener(this);

}

public void populate(@NonNull final String str) {
hostelName.setText(str);
public void populate(@NonNull final String hostel) {
hostelNameTv.setText(hostel);
cardView.setOnClickListener(this);
}

@Override
Expand All @@ -57,19 +48,17 @@ public void onClick(View view) {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Log.e("data1", dataSnapshot.getKey());
for (DataSnapshot child: dataSnapshot.getChildren()) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
Log.e("data1", child.getKey());
killSwitch[0] = Objects.requireNonNull(child.child("killSwitch").getValue(String.class));
}
if (killSwitch[0].equals("1")) {
Intent intent = new Intent(context, ResidentActivity.class);
hostelname = hostelName.getText().toString();
context.startActivity(intent);
activity.finish();
}
else {
String hostelName = hostelNameTv.getText().toString();
launchHostel(itemView.getContext(), hostelName);
//activity.finish();
} else {
//activity.finish();
Toast.makeText(context, "not allowed", Toast.LENGTH_SHORT).show();
Toast.makeText(itemView.getContext(), "not allowed", Toast.LENGTH_SHORT).show();
}
}

Expand All @@ -78,7 +67,7 @@ public void onCancelled(@NonNull DatabaseError databaseError) {

}
});
Log.e("data", ""+killSwitch[0]);
Log.e("data", "" + killSwitch[0]);

}
}

0 comments on commit 56433f9

Please sign in to comment.